name: Amazement
card_text: During your Main Phase, you can activate 1 "Attraction" Trap the turn it was Set. During the End Phase: You can send 1 "Attraction" Trap you control equipped to a monster to the GY, then target 1 of your "Attraction" Traps, with a different name, that is banished or in your GY; Set that card. You can only use each effect of "Amazement Precious Park" once per turn.
external_ids: local SETCARD_ID_0 = 0x15c --Attraction
  
lua: local SETCARD_ID_0 = 0x15c --Attraction
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e0 = Effect.CreateEffect(c)
  	e0:SetType(EFFECT_TYPE_ACTIVATE)
  	e0:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e0)
  	--Trap activate in set turn
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 1))
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_TRAP_ACT_IN_SET_TURN)
  	e1:SetProperty(EFFECT_FLAG_SET_AVAILABLE)
  	e1:SetRange(LOCATION_FZONE)
  	e1:SetTargetRange(LOCATION_SZONE, 0)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.actcon)
  	e1:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	c:RegisterEffect(e1)
  	--set
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_PHASE + PHASE_END)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCost(s.cost)
  	e2:SetTarget(s.target)
  	e2:SetOperation(s.activate)
  	c:RegisterEffect(e2)
  end
  function s.actcon(e)
  	local ph = Duel.GetCurrentPhase()
  	return Duel.GetTurnPlayer() == e:GetHandlerPlayer() and (ph == PHASE_MAIN1 or ph == PHASE_MAIN2)
  end
  function s.filter(c, tp)
  	return c:IsFaceup()
  		and c:IsSetCard(SETCARD_ID_0)
  		and c:IsType(TYPE_TRAP)
  		and c:GetEquipTarget()
  		and c:IsAbleToGraveAsCost()
  		and Duel.GetSZoneCount(tp, c) > 0
  		and Duel.IsExistingTarget(s.setfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, nil, c:GetCode())
  end
  function s.setfilter(c, code)
  	return (c:IsFaceup() or c:IsLocation(LOCATION_GRAVE)) and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_TRAP) and not c:IsCode(code) and c:IsSSetable(true)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(100)
  	if chk == 0 then
  		return true
  	end
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE + LOCATION_REMOVED) and chkc:IsControler(tp) and s.setfilter(chkc, e:GetLabel())
  	end
  	if chk == 0 then
  		if e:GetLabel() ~= 100 then
  			return false
  		end
  		e:SetLabel(0)
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_SZONE, 0, 1, nil, tp)
  	end
  	e:SetLabel(0)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_SZONE, 0, 1, 1, nil, tp)
  	Duel.SendtoGrave(g, REASON_COST)
  	local code = g:GetFirst():GetCode()
  	e:SetLabel(code)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local sg = Duel.SelectTarget(tp, s.setfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, 1, nil, code)
  	if sg:GetFirst():IsLocation(LOCATION_GRAVE) then
  		Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, sg, 1, 0, 0)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SSet(tp, tc)
  	end
  end
  
  
source_text: Amazement
  During your Main Phase, you can activate 1 "Attraction" Trap the turn it was Set. During the End Phase: You can send 1 "Attraction" Trap you control equipped to a monster to the GY, then target 1 of your "Attraction" Traps, with a different name, that is banished or in your GY; Set that card. You can only use each effect of "Amazement Precious Park" once per turn.
target_text: -- Amazement
  local SETCARD_ID_0 = 0x15c --Attraction
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e0 = Effect.CreateEffect(c)
  	e0:SetType(EFFECT_TYPE_ACTIVATE)
  	e0:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e0)
  	--Trap activate in set turn
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 1))
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_TRAP_ACT_IN_SET_TURN)
  	e1:SetProperty(EFFECT_FLAG_SET_AVAILABLE)
  	e1:SetRange(LOCATION_FZONE)
  	e1:SetTargetRange(LOCATION_SZONE, 0)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.actcon)
  	e1:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	c:RegisterEffect(e1)
  	--set
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_PHASE + PHASE_END)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCost(s.cost)
  	e2:SetTarget(s.target)
  	e2:SetOperation(s.activate)
  	c:RegisterEffect(e2)
  end
  function s.actcon(e)
  	local ph = Duel.GetCurrentPhase()
  	return Duel.GetTurnPlayer() == e:GetHandlerPlayer() and (ph == PHASE_MAIN1 or ph == PHASE_MAIN2)
  end
  function s.filter(c, tp)
  	return c:IsFaceup()
  		and c:IsSetCard(SETCARD_ID_0)
  		and c:IsType(TYPE_TRAP)
  		and c:GetEquipTarget()
  		and c:IsAbleToGraveAsCost()
  		and Duel.GetSZoneCount(tp, c) > 0
  		and Duel.IsExistingTarget(s.setfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, nil, c:GetCode())
  end
  function s.setfilter(c, code)
  	return (c:IsFaceup() or c:IsLocation(LOCATION_GRAVE)) and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_TRAP) and not c:IsCode(code) and c:IsSSetable(true)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(100)
  	if chk == 0 then
  		return true
  	end
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE + LOCATION_REMOVED) and chkc:IsControler(tp) and s.setfilter(chkc, e:GetLabel())
  	end
  	if chk == 0 then
  		if e:GetLabel() ~= 100 then
  			return false
  		end
  		e:SetLabel(0)
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_SZONE, 0, 1, nil, tp)
  	end
  	e:SetLabel(0)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_SZONE, 0, 1, 1, nil, tp)
  	Duel.SendtoGrave(g, REASON_COST)
  	local code = g:GetFirst():GetCode()
  	e:SetLabel(code)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local sg = Duel.SelectTarget(tp, s.setfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, 1, nil, code)
  	if sg:GetFirst():IsLocation(LOCATION_GRAVE) then
  		Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, sg, 1, 0, 0)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SSet(tp, tc)
  	end
  end
  
  