name: Sylvan
card_text: Place 1 card from your hand on either the top or bottom of the Deck, and if you do, Special Summon 1 "Sylvan" monster from your hand or Graveyard. It is unaffected by other card effects this turn. Place it on either the top or bottom of the Deck during the End Phase.
external_ids: local SETCARD_ID_0 = 0x90 --Sylvan
  
lua: local SETCARD_ID_0 = 0x90 --Sylvan
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TODECK + CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c, e, tp)
  	return c:IsAbleToDeck() and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, c, e, tp)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_HAND, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 1, tp, LOCATION_HAND)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_GRAVE)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_HAND, 0, 1, 1, nil, e, tp)
  	local tc = g:GetFirst()
  	if tc then
  		local opt = Duel.SelectOption(tp, aux.Stringid(id, 0), aux.Stringid(id, 1))
  		Duel.SendtoDeck(g, nil, opt, REASON_EFFECT)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local sg = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, 1, tc, e, tp)
  		local sc = sg:GetFirst()
  		if sc then
  			Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  			e1:SetRange(LOCATION_MZONE)
  			e1:SetCountLimit(1)
  			e1:SetCode(EVENT_PHASE + PHASE_END)
  			e1:SetOperation(s.tdop)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			sc:RegisterEffect(e1)
  			local e2 = Effect.CreateEffect(e:GetHandler())
  			e2:SetType(EFFECT_TYPE_SINGLE)
  			e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  			e2:SetRange(LOCATION_MZONE)
  			e2:SetCode(EFFECT_IMMUNE_EFFECT)
  			e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			e2:SetValue(s.efilter)
  			sc:RegisterEffect(e2)
  		end
  	end
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsExtraDeckMonster() or Duel.SelectOption(tp, aux.Stringid(id, 0), aux.Stringid(id, 1)) == 0 then
  		Duel.SendtoDeck(c, nil, SEQ_DECKTOP, REASON_EFFECT)
  	else
  		Duel.SendtoDeck(c, nil, SEQ_DECKBOTTOM, REASON_EFFECT)
  	end
  end
  function s.efilter(e, te)
  	return te:GetOwner() ~= e:GetOwner()
  end
  
  
source_text: Sylvan
  Place 1 card from your hand on either the top or bottom of the Deck, and if you do, Special Summon 1 "Sylvan" monster from your hand or Graveyard. It is unaffected by other card effects this turn. Place it on either the top or bottom of the Deck during the End Phase.
target_text: -- Sylvan
  local SETCARD_ID_0 = 0x90 --Sylvan
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TODECK + CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c, e, tp)
  	return c:IsAbleToDeck() and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, c, e, tp)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_HAND, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 1, tp, LOCATION_HAND)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_GRAVE)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_HAND, 0, 1, 1, nil, e, tp)
  	local tc = g:GetFirst()
  	if tc then
  		local opt = Duel.SelectOption(tp, aux.Stringid(id, 0), aux.Stringid(id, 1))
  		Duel.SendtoDeck(g, nil, opt, REASON_EFFECT)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local sg = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, 1, tc, e, tp)
  		local sc = sg:GetFirst()
  		if sc then
  			Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  			e1:SetRange(LOCATION_MZONE)
  			e1:SetCountLimit(1)
  			e1:SetCode(EVENT_PHASE + PHASE_END)
  			e1:SetOperation(s.tdop)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			sc:RegisterEffect(e1)
  			local e2 = Effect.CreateEffect(e:GetHandler())
  			e2:SetType(EFFECT_TYPE_SINGLE)
  			e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  			e2:SetRange(LOCATION_MZONE)
  			e2:SetCode(EFFECT_IMMUNE_EFFECT)
  			e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			e2:SetValue(s.efilter)
  			sc:RegisterEffect(e2)
  		end
  	end
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsExtraDeckMonster() or Duel.SelectOption(tp, aux.Stringid(id, 0), aux.Stringid(id, 1)) == 0 then
  		Duel.SendtoDeck(c, nil, SEQ_DECKTOP, REASON_EFFECT)
  	else
  		Duel.SendtoDeck(c, nil, SEQ_DECKBOTTOM, REASON_EFFECT)
  	end
  end
  function s.efilter(e, te)
  	return te:GetOwner() ~= e:GetOwner()
  end
  
  