name: Sylvan
card_text: When this card is Normal Summoned: You can choose either 1 or 2, then excavate that many cards from the top of your Deck, 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 1 monster on the field; destroy that target.
lua: 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_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 2))
  	e2:SetCategory(CATEGORY_DESTROY)
  	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.descon)
  	e2:SetTarget(s.destg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDiscardDeck(tp, 1)
  	end
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	if not Duel.IsPlayerCanDiscardDeck(tp, 1) then
  		return
  	end
  	local ct = Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0)
  	if ct == 0 then
  		return
  	end
  	local ac = 1
  	if ct > 1 then
  		Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 1))
  		ac = Duel.AnnounceNumber(tp, 1, 2)
  	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.descon(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.destg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(aux.TRUE, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, aux.TRUE, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.Destroy(tc, REASON_EFFECT)
  	end
  end
  
  
source_text: Sylvan
  When this card is Normal Summoned: You can choose either 1 or 2, then excavate that many cards from the top of your Deck, 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 1 monster on the field; destroy that target.
target_text: -- 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_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 2))
  	e2:SetCategory(CATEGORY_DESTROY)
  	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.descon)
  	e2:SetTarget(s.destg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDiscardDeck(tp, 1)
  	end
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	if not Duel.IsPlayerCanDiscardDeck(tp, 1) then
  		return
  	end
  	local ct = Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0)
  	if ct == 0 then
  		return
  	end
  	local ac = 1
  	if ct > 1 then
  		Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 1))
  		ac = Duel.AnnounceNumber(tp, 1, 2)
  	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.descon(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.destg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(aux.TRUE, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, aux.TRUE, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.Destroy(tc, REASON_EFFECT)
  	end
  end
  
  