name: Dual
card_text: During the Main Phase: Banish 1 "Dual Avatar" Spell/Trap from your GY, except "Dual Avatar Compact"; this card's effect becomes that Spell/Trap's effect when that card is activated. You can only activate 1 "Dual Avatar Compact" per turn.
external_ids: local SETCARD_ID_0 = 0x14f --Dual
  
lua: local SETCARD_ID_0 = 0x14f --Dual
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--copy spell
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetHintTiming(TIMING_MAIN_END)
  	e1:SetCondition(s.condition)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCurrentPhase() == PHASE_MAIN1 or Duel.GetCurrentPhase() == PHASE_MAIN2
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(1)
  	return true
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and not c:IsCode(id) and c:IsType(TYPE_SPELL + TYPE_TRAP) and c:CheckActivateEffect(false, true, false) ~= nil
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chk == 0 then
  		if e:GetLabel() == 0 then
  			return false
  		end
  		e:SetLabel(0)
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	e:SetLabel(0)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	local te, ceg, cep, cev, cre, cr, crp = g:GetFirst():CheckActivateEffect(false, true, true)
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  	e:SetProperty(te:GetProperty())
  	local tg = te:GetTarget()
  	if tg then
  		tg(e, tp, ceg, cep, cev, cre, cr, crp, 1)
  	end
  	te:SetLabelObject(e:GetLabelObject())
  	e:SetLabelObject(te)
  	Duel.ClearOperationInfo(0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local te = e:GetLabelObject()
  	if not te then
  		return
  	end
  	e:SetLabelObject(te:GetLabelObject())
  	local op = te:GetOperation()
  	if op then
  		op(e, tp, eg, ep, ev, re, r, rp)
  	end
  end
  
  
source_text: Dual
  During the Main Phase: Banish 1 "Dual Avatar" Spell/Trap from your GY, except "Dual Avatar Compact"; this card's effect becomes that Spell/Trap's effect when that card is activated. You can only activate 1 "Dual Avatar Compact" per turn.
target_text: -- Dual
  local SETCARD_ID_0 = 0x14f --Dual
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--copy spell
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetHintTiming(TIMING_MAIN_END)
  	e1:SetCondition(s.condition)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCurrentPhase() == PHASE_MAIN1 or Duel.GetCurrentPhase() == PHASE_MAIN2
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(1)
  	return true
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and not c:IsCode(id) and c:IsType(TYPE_SPELL + TYPE_TRAP) and c:CheckActivateEffect(false, true, false) ~= nil
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chk == 0 then
  		if e:GetLabel() == 0 then
  			return false
  		end
  		e:SetLabel(0)
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	e:SetLabel(0)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	local te, ceg, cep, cev, cre, cr, crp = g:GetFirst():CheckActivateEffect(false, true, true)
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  	e:SetProperty(te:GetProperty())
  	local tg = te:GetTarget()
  	if tg then
  		tg(e, tp, ceg, cep, cev, cre, cr, crp, 1)
  	end
  	te:SetLabelObject(e:GetLabelObject())
  	e:SetLabelObject(te)
  	Duel.ClearOperationInfo(0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local te = e:GetLabelObject()
  	if not te then
  		return
  	end
  	e:SetLabelObject(te:GetLabelObject())
  	local op = te:GetOperation()
  	if op then
  		op(e, tp, eg, ep, ev, re, r, rp)
  	end
  end
  
  