name: Sylvan
card_text: Once per turn: You can excavate a number of cards from the top of your Deck, equal to the number of cards your opponent controls, send any excavated Plant-Type monsters to the Graveyard, also place the other cards on the bottom of your Deck in any order. If this card is excavated from the Deck and sent to the Graveyard by a card effect: You can target up to 5 "Sylvan" cards in your Graveyard, except "Sylvan Lotuswain"; place them on the bottom of your Deck in any order.
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)
  	--deck
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DECKDES)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--todeck
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 2))
  	e2:SetCategory(CATEGORY_TODECK)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetCondition(s.tdcon)
  	e2:SetTarget(s.tdtg)
  	e2:SetOperation(s.tdop)
  	c:RegisterEffect(e2)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local ac = Duel.GetFieldGroupCount(tp, 0, LOCATION_ONFIELD)
  		return ac > 0 and Duel.IsPlayerCanDiscardDeck(tp, ac)
  	end
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local ac = Duel.GetFieldGroupCount(tp, 0, LOCATION_ONFIELD)
  	if ac == 0 or not Duel.IsPlayerCanDiscardDeck(tp, ac) then
  		return
  	end
  	Duel.ConfirmDecktop(tp, ac)
  	local g = Duel.GetDecktopGroup(tp, ac)
  	local sg = g:Filter(Card.IsRace, nil, RACE_PLANT)
  	if sg:GetCount() > 0 then
  		Duel.DisableShuffleCheck()
  		Duel.SendtoGrave(sg, REASON_EFFECT + REASON_REVEAL)
  	end
  	ac = ac - sg:GetCount()
  	if ac > 0 then
  		Duel.SortDecktop(tp, tp, ac)
  		for i = 1, ac do
  			local mg = Duel.GetDecktopGroup(tp, 1)
  			Duel.MoveSequence(mg:GetFirst(), SEQ_DECKBOTTOM)
  		end
  	end
  end
  function s.tdcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsPreviousLocation(LOCATION_DECK) and c:IsReason(REASON_REVEAL)
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and not c:IsCode(id) and c:IsAbleToDeck()
  end
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 5, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, g:GetCount(), 0, 0)
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local sg = g:Filter(Card.IsRelateToEffect, nil, e)
  	if sg:GetCount() > 0 then
  		Duel.SendtoDeck(sg, nil, SEQ_DECKTOP, REASON_EFFECT)
  		local og = Duel.GetOperatedGroup()
  		local ct = og:FilterCount(Card.IsLocation, nil, LOCATION_DECK)
  		if ct == 0 then
  			return
  		end
  		Duel.SortDecktop(tp, tp, ct)
  		for i = 1, ct do
  			local mg = Duel.GetDecktopGroup(tp, 1)
  			Duel.MoveSequence(mg:GetFirst(), SEQ_DECKBOTTOM)
  		end
  	end
  end
  
  
source_text: Sylvan
  Once per turn: You can excavate a number of cards from the top of your Deck, equal to the number of cards your opponent controls, send any excavated Plant-Type monsters to the Graveyard, also place the other cards on the bottom of your Deck in any order. If this card is excavated from the Deck and sent to the Graveyard by a card effect: You can target up to 5 "Sylvan" cards in your Graveyard, except "Sylvan Lotuswain"; place them on the bottom of your Deck in any order.
target_text: -- Sylvan
  local SETCARD_ID_0 = 0x90 --Sylvan
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--deck
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DECKDES)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--todeck
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 2))
  	e2:SetCategory(CATEGORY_TODECK)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetCondition(s.tdcon)
  	e2:SetTarget(s.tdtg)
  	e2:SetOperation(s.tdop)
  	c:RegisterEffect(e2)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local ac = Duel.GetFieldGroupCount(tp, 0, LOCATION_ONFIELD)
  		return ac > 0 and Duel.IsPlayerCanDiscardDeck(tp, ac)
  	end
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local ac = Duel.GetFieldGroupCount(tp, 0, LOCATION_ONFIELD)
  	if ac == 0 or not Duel.IsPlayerCanDiscardDeck(tp, ac) then
  		return
  	end
  	Duel.ConfirmDecktop(tp, ac)
  	local g = Duel.GetDecktopGroup(tp, ac)
  	local sg = g:Filter(Card.IsRace, nil, RACE_PLANT)
  	if sg:GetCount() > 0 then
  		Duel.DisableShuffleCheck()
  		Duel.SendtoGrave(sg, REASON_EFFECT + REASON_REVEAL)
  	end
  	ac = ac - sg:GetCount()
  	if ac > 0 then
  		Duel.SortDecktop(tp, tp, ac)
  		for i = 1, ac do
  			local mg = Duel.GetDecktopGroup(tp, 1)
  			Duel.MoveSequence(mg:GetFirst(), SEQ_DECKBOTTOM)
  		end
  	end
  end
  function s.tdcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsPreviousLocation(LOCATION_DECK) and c:IsReason(REASON_REVEAL)
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and not c:IsCode(id) and c:IsAbleToDeck()
  end
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 5, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, g:GetCount(), 0, 0)
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local sg = g:Filter(Card.IsRelateToEffect, nil, e)
  	if sg:GetCount() > 0 then
  		Duel.SendtoDeck(sg, nil, SEQ_DECKTOP, REASON_EFFECT)
  		local og = Duel.GetOperatedGroup()
  		local ct = og:FilterCount(Card.IsLocation, nil, LOCATION_DECK)
  		if ct == 0 then
  			return
  		end
  		Duel.SortDecktop(tp, tp, ct)
  		for i = 1, ct do
  			local mg = Duel.GetDecktopGroup(tp, 1)
  			Duel.MoveSequence(mg:GetFirst(), SEQ_DECKBOTTOM)
  		end
  	end
  end
  
  