name: Annihilator
card_text: You can target 1 card you control and 1 card your opponent controls; destroy them, and if you destroyed a face-up Fiend monster(s) by this effect, this card gains ATK equal to half the Fiend monster(s)'s original ATK, until the end of this turn. You can only use this effect of "Annihilator Archfiend" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--destroy
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_ATKCHANGE + CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.destg)
  	e1:SetOperation(s.desop)
  	c:RegisterEffect(e1)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(aux.TRUE, tp, LOCATION_ONFIELD, 0, 1, nil) and Duel.IsExistingTarget(aux.TRUE, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g1 = Duel.SelectTarget(tp, aux.TRUE, tp, LOCATION_ONFIELD, 0, 1, 1, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g2 = Duel.SelectTarget(tp, aux.TRUE, tp, 0, LOCATION_ONFIELD, 1, 1, nil)
  	g1:Merge(g2)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g1, 2, 0, 0)
  end
  function s.atkfilter(c)
  	return c:IsPreviousPosition(POS_FACEUP) and bit.band(c:GetPreviousRaceOnField(), RACE_FIEND) ~= 0
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if tg:GetCount() > 0 and Duel.Destroy(tg, REASON_EFFECT) ~= 0 and c:IsFaceup() and c:IsRelateToEffect(e) then
  		local og = Duel.GetOperatedGroup()
  		local ag = og:Filter(s.atkfilter, nil)
  		local atk = ag:GetSum(Card.GetTextAttack) / 2
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetValue(atk)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE + RESET_PHASE + PHASE_END)
  		c:RegisterEffect(e1)
  	end
  end
  
  
source_text: Annihilator
  You can target 1 card you control and 1 card your opponent controls; destroy them, and if you destroyed a face-up Fiend monster(s) by this effect, this card gains ATK equal to half the Fiend monster(s)'s original ATK, until the end of this turn. You can only use this effect of "Annihilator Archfiend" once per turn.
target_text: -- Annihilator
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--destroy
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_ATKCHANGE + CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.destg)
  	e1:SetOperation(s.desop)
  	c:RegisterEffect(e1)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(aux.TRUE, tp, LOCATION_ONFIELD, 0, 1, nil) and Duel.IsExistingTarget(aux.TRUE, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g1 = Duel.SelectTarget(tp, aux.TRUE, tp, LOCATION_ONFIELD, 0, 1, 1, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g2 = Duel.SelectTarget(tp, aux.TRUE, tp, 0, LOCATION_ONFIELD, 1, 1, nil)
  	g1:Merge(g2)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g1, 2, 0, 0)
  end
  function s.atkfilter(c)
  	return c:IsPreviousPosition(POS_FACEUP) and bit.band(c:GetPreviousRaceOnField(), RACE_FIEND) ~= 0
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if tg:GetCount() > 0 and Duel.Destroy(tg, REASON_EFFECT) ~= 0 and c:IsFaceup() and c:IsRelateToEffect(e) then
  		local og = Duel.GetOperatedGroup()
  		local ag = og:Filter(s.atkfilter, nil)
  		local atk = ag:GetSum(Card.GetTextAttack) / 2
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetValue(atk)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE + RESET_PHASE + PHASE_END)
  		c:RegisterEffect(e1)
  	end
  end
  
  