name: Arrive
card_text: When this card is activated: Place 1 Level 1 Dragon monster from your hand or Deck on top of the Deck. Neither player can return "Stardust Dragon", or a Synchro Monster that lists "Stardust Dragon" in its text, from the field to the Extra Deck. If a Synchro Monster(s) is Special Summoned (except during the Damage Step): You can apply 1 of these effects, but you cannot apply that same effect of "Arrive in Light" again this turn.
  ● Draw 1 card.
  ● Special Summon 1 Tuner from your hand.
external_ids: local CARD_ID_0 = 44508094 --Stardust Dragon
  
lua: local CARD_ID_0 = 44508094 --Stardust Dragon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--to deck
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TODECK)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--cannot to deck
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_CANNOT_TO_DECK)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetTargetRange(1, 1)
  	e2:SetTarget(s.tdlimit)
  	c:RegisterEffect(e2)
  	--apply
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_DRAW + CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCondition(s.opcon)
  	e3:SetTarget(s.optg)
  	e3:SetOperation(s.opop)
  	c:RegisterEffect(e3)
  end
  function s.tdfilter(c)
  	return c:IsRace(RACE_DRAGON) and c:IsLevel(1) and (c:IsAbleToDeck() or c:IsLocation(LOCATION_DECK))
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.tdfilter, tp, LOCATION_DECK + LOCATION_HAND, 0, 1, nil)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.GetMatchingGroup(s.tdfilter, tp, LOCATION_DECK + LOCATION_HAND, 0, nil)
  	if #g > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  		local tc = g:Select(tp, 1, 1, nil):GetFirst()
  		if tc:IsLocation(LOCATION_DECK) then
  			Duel.ShuffleDeck(tp)
  			Duel.MoveSequence(tc, SEQ_DECKTOP)
  			Duel.ConfirmDecktop(tp, 1)
  		else
  			Duel.ConfirmCards(1 - tp, tc)
  			Duel.SendtoDeck(tc, nil, SEQ_DECKTOP, REASON_EFFECT)
  		end
  	end
  end
  function s.tdlimit(e, c)
  	return (c:IsCode(CARD_ID_0) or c:IsType(TYPE_SYNCHRO) and aux.IsCodeListed(c, CARD_ID_0)) and c:IsOnField()
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsType(TYPE_SYNCHRO)
  end
  function s.opcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil)
  end
  function s.spfilter(c, e, tp)
  	return c:IsType(TYPE_TUNER) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.optg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local b1 = Duel.IsPlayerCanDraw(tp, 1) and Duel.GetFlagEffect(tp, id) == 0
  	local b2 = Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND, 0, 1, nil, e, tp) and Duel.GetFlagEffect(tp, id + 1) == 0
  	if chk == 0 then
  		return b1 or b2
  	end
  end
  function s.opop(e, tp, eg, ep, ev, re, r, rp)
  	local b1 = Duel.IsPlayerCanDraw(tp, 1) and Duel.GetFlagEffect(tp, id) == 0
  	local b2 = Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND, 0, 1, nil, e, tp) and Duel.GetFlagEffect(tp, id + 1) == 0
  	local op = 0
  	if b1 and b2 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1), aux.Stringid(id, 2))
  	elseif b1 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1))
  	elseif b2 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 2)) + 1
  	else
  		return
  	end
  	if op == 0 then
  		Duel.Draw(tp, 1, REASON_EFFECT)
  		Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1)
  	else
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND, 0, 1, 1, nil, e, tp)
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  		Duel.RegisterFlagEffect(tp, id + 1, RESET_PHASE + PHASE_END, 0, 1)
  	end
  end
  
  
source_text: Arrive
  When this card is activated: Place 1 Level 1 Dragon monster from your hand or Deck on top of the Deck. Neither player can return "Stardust Dragon", or a Synchro Monster that lists "Stardust Dragon" in its text, from the field to the Extra Deck. If a Synchro Monster(s) is Special Summoned (except during the Damage Step): You can apply 1 of these effects, but you cannot apply that same effect of "Arrive in Light" again this turn.
  ● Draw 1 card.
  ● Special Summon 1 Tuner from your hand.
target_text: -- Arrive
  local CARD_ID_0 = 44508094 --Stardust Dragon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--to deck
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TODECK)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--cannot to deck
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_CANNOT_TO_DECK)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetTargetRange(1, 1)
  	e2:SetTarget(s.tdlimit)
  	c:RegisterEffect(e2)
  	--apply
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_DRAW + CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCondition(s.opcon)
  	e3:SetTarget(s.optg)
  	e3:SetOperation(s.opop)
  	c:RegisterEffect(e3)
  end
  function s.tdfilter(c)
  	return c:IsRace(RACE_DRAGON) and c:IsLevel(1) and (c:IsAbleToDeck() or c:IsLocation(LOCATION_DECK))
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.tdfilter, tp, LOCATION_DECK + LOCATION_HAND, 0, 1, nil)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.GetMatchingGroup(s.tdfilter, tp, LOCATION_DECK + LOCATION_HAND, 0, nil)
  	if #g > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  		local tc = g:Select(tp, 1, 1, nil):GetFirst()
  		if tc:IsLocation(LOCATION_DECK) then
  			Duel.ShuffleDeck(tp)
  			Duel.MoveSequence(tc, SEQ_DECKTOP)
  			Duel.ConfirmDecktop(tp, 1)
  		else
  			Duel.ConfirmCards(1 - tp, tc)
  			Duel.SendtoDeck(tc, nil, SEQ_DECKTOP, REASON_EFFECT)
  		end
  	end
  end
  function s.tdlimit(e, c)
  	return (c:IsCode(CARD_ID_0) or c:IsType(TYPE_SYNCHRO) and aux.IsCodeListed(c, CARD_ID_0)) and c:IsOnField()
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsType(TYPE_SYNCHRO)
  end
  function s.opcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil)
  end
  function s.spfilter(c, e, tp)
  	return c:IsType(TYPE_TUNER) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.optg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local b1 = Duel.IsPlayerCanDraw(tp, 1) and Duel.GetFlagEffect(tp, id) == 0
  	local b2 = Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND, 0, 1, nil, e, tp) and Duel.GetFlagEffect(tp, id + 1) == 0
  	if chk == 0 then
  		return b1 or b2
  	end
  end
  function s.opop(e, tp, eg, ep, ev, re, r, rp)
  	local b1 = Duel.IsPlayerCanDraw(tp, 1) and Duel.GetFlagEffect(tp, id) == 0
  	local b2 = Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND, 0, 1, nil, e, tp) and Duel.GetFlagEffect(tp, id + 1) == 0
  	local op = 0
  	if b1 and b2 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1), aux.Stringid(id, 2))
  	elseif b1 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1))
  	elseif b2 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 2)) + 1
  	else
  		return
  	end
  	if op == 0 then
  		Duel.Draw(tp, 1, REASON_EFFECT)
  		Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1)
  	else
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND, 0, 1, 1, nil, e, tp)
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  		Duel.RegisterFlagEffect(tp, id + 1, RESET_PHASE + PHASE_END, 0, 1)
  	end
  end
  
  