name: Mirror
card_text: When an opponent's monster declares an attack targeting a face-up "Elemental HERO" monster you control: Switch control of the opponent's attacking monster with the targeted monster you control, then calculate damage. Control of both monsters switches back during the End Phase.
external_ids: local SETCARD_ID_0 = 0x3008 --Elemental
  
lua: local SETCARD_ID_0 = 0x3008 --Elemental
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_CONTROL)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	local at = Duel.GetAttackTarget()
  	return Duel.GetTurnPlayer() ~= tp and at and at:IsFaceup() and at:IsSetCard(SETCARD_ID_0)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local a = Duel.GetAttacker()
  	local at = Duel.GetAttackTarget()
  	if chk == 0 then
  		return a:IsOnField()
  			and a:IsAbleToChangeControler()
  			and Duel.GetMZoneCount(1 - tp, a, 1 - tp, LOCATION_REASON_CONTROL) > 0
  			and at:IsOnField()
  			and at:IsAbleToChangeControler()
  			and Duel.GetMZoneCount(tp, at, tp, LOCATION_REASON_CONTROL) > 0
  	end
  	local g = Group.FromCards(a, at)
  	Duel.SetTargetCard(g)
  	Duel.SetOperationInfo(0, CATEGORY_CONTROL, g, 2, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local a = Duel.GetAttacker()
  	local at = Duel.GetAttackTarget()
  	if a:IsRelateToEffect(e) and a:IsAttackable() and at:IsRelateToEffect(e) then
  		if Duel.SwapControl(a, at, RESET_PHASE + PHASE_END, 1) then
  			Duel.CalculateDamage(a, at)
  		end
  	end
  end
  
  
source_text: Mirror
  When an opponent's monster declares an attack targeting a face-up "Elemental HERO" monster you control: Switch control of the opponent's attacking monster with the targeted monster you control, then calculate damage. Control of both monsters switches back during the End Phase.
target_text: -- Mirror
  local SETCARD_ID_0 = 0x3008 --Elemental
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_CONTROL)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	local at = Duel.GetAttackTarget()
  	return Duel.GetTurnPlayer() ~= tp and at and at:IsFaceup() and at:IsSetCard(SETCARD_ID_0)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local a = Duel.GetAttacker()
  	local at = Duel.GetAttackTarget()
  	if chk == 0 then
  		return a:IsOnField()
  			and a:IsAbleToChangeControler()
  			and Duel.GetMZoneCount(1 - tp, a, 1 - tp, LOCATION_REASON_CONTROL) > 0
  			and at:IsOnField()
  			and at:IsAbleToChangeControler()
  			and Duel.GetMZoneCount(tp, at, tp, LOCATION_REASON_CONTROL) > 0
  	end
  	local g = Group.FromCards(a, at)
  	Duel.SetTargetCard(g)
  	Duel.SetOperationInfo(0, CATEGORY_CONTROL, g, 2, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local a = Duel.GetAttacker()
  	local at = Duel.GetAttackTarget()
  	if a:IsRelateToEffect(e) and a:IsAttackable() and at:IsRelateToEffect(e) then
  		if Duel.SwapControl(a, at, RESET_PHASE + PHASE_END, 1) then
  			Duel.CalculateDamage(a, at)
  		end
  	end
  end
  
  