name: Blackwing
card_text: 1 "Blackwing" Tuner + 1+ non-Tuner monsters
  Cannot be destroyed by battle, and you take no battle damage from attacks involving this card. At the end of the Damage Step, if this card attacked a monster: You can place 1 Wedge Counter on that monster (max. 1). You can remove all Wedge Counters from your opponent's monsters; the ATK and DEF of those monsters that had Wedge Counters become 0 until the end of this turn.
external_ids: local SETCARD_ID_0 = 0x33 --Blackwing
  local COUNTER_ID_0 = 0x1002 --Wedge
  
lua: local SETCARD_ID_0 = 0x33 --Blackwing
  local COUNTER_ID_0 = 0x1002 --Wedge
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--synchro summon
  	aux.AddSynchroProcedure(c, aux.FilterBoolFunction(Card.IsSetCard, SETCARD_ID_0), aux.NonTuner(nil), 1)
  	c:EnableReviveLimit()
  	--
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_AVOID_BATTLE_DAMAGE)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--counter
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_COUNTER)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_DAMAGE_STEP_END)
  	e3:SetCondition(s.ctcon)
  	e3:SetOperation(s.ctop)
  	c:RegisterEffect(e3)
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_ATKCHANGE + CATEGORY_DEFCHANGE)
  	e4:SetType(EFFECT_TYPE_IGNITION)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCost(s.atkcost)
  	e4:SetOperation(s.atkop)
  	c:RegisterEffect(e4)
  end
  function s.ctcon(e, tp, eg, ep, ev, re, r, rp)
  	local atg = Duel.GetAttackTarget()
  	return aux.dsercon(e, tp, eg, ep, ev, re, r, rp)
  		and Duel.GetAttacker() == e:GetHandler()
  		and atg
  		and atg:IsRelateToBattle()
  		and atg:GetCounter(COUNTER_ID_0) == 0
  		and atg:IsCanAddCounter(COUNTER_ID_0, 1)
  end
  function s.ctop(e, tp, eg, ep, ev, re, r, rp)
  	local atg = Duel.GetAttackTarget()
  	if atg:IsRelateToBattle() then
  		atg:AddCounter(COUNTER_ID_0, 1)
  	end
  end
  function s.filter(c)
  	return c:GetCounter(COUNTER_ID_0) > 0
  end
  function s.atkcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(s.filter, tp, 0, LOCATION_MZONE, nil)
  	local t = g:GetFirst()
  	while t do
  		t:RemoveCounter(tp, COUNTER_ID_0, t:GetCounter(COUNTER_ID_0), REASON_COST)
  		t = g:GetNext()
  	end
  	Duel.SetTargetCard(g)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local t = g:GetFirst()
  	while t do
  		if t:IsRelateToEffect(e) then
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  			e1:SetValue(0)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			t:RegisterEffect(e1)
  			local e2 = Effect.CreateEffect(c)
  			e2:SetType(EFFECT_TYPE_SINGLE)
  			e2:SetCode(EFFECT_SET_DEFENSE_FINAL)
  			e2:SetValue(0)
  			e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			t:RegisterEffect(e2)
  		end
  		t = g:GetNext()
  	end
  end
  
  
source_text: Blackwing
  1 "Blackwing" Tuner + 1+ non-Tuner monsters
  Cannot be destroyed by battle, and you take no battle damage from attacks involving this card. At the end of the Damage Step, if this card attacked a monster: You can place 1 Wedge Counter on that monster (max. 1). You can remove all Wedge Counters from your opponent's monsters; the ATK and DEF of those monsters that had Wedge Counters become 0 until the end of this turn.
target_text: -- Blackwing
  local SETCARD_ID_0 = 0x33 --Blackwing
  local COUNTER_ID_0 = 0x1002 --Wedge
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--synchro summon
  	aux.AddSynchroProcedure(c, aux.FilterBoolFunction(Card.IsSetCard, SETCARD_ID_0), aux.NonTuner(nil), 1)
  	c:EnableReviveLimit()
  	--
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_AVOID_BATTLE_DAMAGE)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--counter
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_COUNTER)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_DAMAGE_STEP_END)
  	e3:SetCondition(s.ctcon)
  	e3:SetOperation(s.ctop)
  	c:RegisterEffect(e3)
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_ATKCHANGE + CATEGORY_DEFCHANGE)
  	e4:SetType(EFFECT_TYPE_IGNITION)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCost(s.atkcost)
  	e4:SetOperation(s.atkop)
  	c:RegisterEffect(e4)
  end
  function s.ctcon(e, tp, eg, ep, ev, re, r, rp)
  	local atg = Duel.GetAttackTarget()
  	return aux.dsercon(e, tp, eg, ep, ev, re, r, rp)
  		and Duel.GetAttacker() == e:GetHandler()
  		and atg
  		and atg:IsRelateToBattle()
  		and atg:GetCounter(COUNTER_ID_0) == 0
  		and atg:IsCanAddCounter(COUNTER_ID_0, 1)
  end
  function s.ctop(e, tp, eg, ep, ev, re, r, rp)
  	local atg = Duel.GetAttackTarget()
  	if atg:IsRelateToBattle() then
  		atg:AddCounter(COUNTER_ID_0, 1)
  	end
  end
  function s.filter(c)
  	return c:GetCounter(COUNTER_ID_0) > 0
  end
  function s.atkcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(s.filter, tp, 0, LOCATION_MZONE, nil)
  	local t = g:GetFirst()
  	while t do
  		t:RemoveCounter(tp, COUNTER_ID_0, t:GetCounter(COUNTER_ID_0), REASON_COST)
  		t = g:GetNext()
  	end
  	Duel.SetTargetCard(g)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local t = g:GetFirst()
  	while t do
  		if t:IsRelateToEffect(e) then
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  			e1:SetValue(0)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			t:RegisterEffect(e1)
  			local e2 = Effect.CreateEffect(c)
  			e2:SetType(EFFECT_TYPE_SINGLE)
  			e2:SetCode(EFFECT_SET_DEFENSE_FINAL)
  			e2:SetValue(0)
  			e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			t:RegisterEffect(e2)
  		end
  		t = g:GetNext()
  	end
  end
  
  