name: Black
card_text: Once per turn, if you Special Summon a DARK Synchro Monster from the Extra Deck (except during the Damage Step): You can target 1 of your "Blackwing" monsters, or "Black-Winged Dragon", that is banished or in your GY, with less ATK than that Special Summoned monster; Special Summon it. Once per turn, if a DARK monster you control would be destroyed by battle or card effect, you can remove 1 Black Feather Counter from your field instead.
external_ids: local CARD_ID_0 = 9012916 --Black-Winged Dragon
  local SETCARD_ID_0 = 0x33 --Blackwing
  local COUNTER_ID_0 = 0x10 --Black
  
lua: local CARD_ID_0 = 9012916 --Black-Winged Dragon
  local SETCARD_ID_0 = 0x33 --Blackwing
  local COUNTER_ID_0 = 0x10 --Black
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--destroy replace
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_DESTROY_REPLACE)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCountLimit(1)
  	e3:SetTarget(s.reptg)
  	e3:SetValue(s.repval)
  	e3:SetOperation(s.repop)
  	c:RegisterEffect(e3)
  end
  function s.cfilter(c, tp)
  	return c:IsSummonPlayer(tp) and c:IsType(TYPE_SYNCHRO) and c:IsAttribute(ATTRIBUTE_DARK) and c:IsPreviousLocation(LOCATION_EXTRA)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:FilterCount(s.cfilter, nil, tp) > 0
  end
  function s.spfilter(c, e, tp, atk)
  	return (c:IsSetCard(SETCARD_ID_0) or c:IsCode(CARD_ID_0)) and c:GetAttack() < atk and (not c:IsLocation(LOCATION_REMOVED) or c:IsFaceup()) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local _, atk = eg:Filter(s.cfilter, nil, tp):GetMaxGroup(Card.GetAttack)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE + LOCATION_REMOVED) and s.spfilter(chkc, e, tp, atk)
  	end
  	if chk == 0 then
  		return atk and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.spfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, nil, e, tp, atk)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.spfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, 1, nil, e, tp, atk)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup() and c:IsLocation(LOCATION_MZONE) and c:IsAttribute(ATTRIBUTE_DARK) and c:IsControler(tp) and c:IsReason(REASON_BATTLE + REASON_EFFECT) and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return eg:IsExists(s.repfilter, 1, nil, tp) and Duel.IsCanRemoveCounter(tp, 1, 0, COUNTER_ID_0, 1, REASON_EFFECT)
  	end
  	return Duel.SelectEffectYesNo(tp, e:GetHandler(), 96)
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.RemoveCounter(tp, 1, 0, COUNTER_ID_0, 1, REASON_EFFECT)
  end
  
  
source_text: Black
  Once per turn, if you Special Summon a DARK Synchro Monster from the Extra Deck (except during the Damage Step): You can target 1 of your "Blackwing" monsters, or "Black-Winged Dragon", that is banished or in your GY, with less ATK than that Special Summoned monster; Special Summon it. Once per turn, if a DARK monster you control would be destroyed by battle or card effect, you can remove 1 Black Feather Counter from your field instead.
target_text: -- Black
  local CARD_ID_0 = 9012916 --Black-Winged Dragon
  local SETCARD_ID_0 = 0x33 --Blackwing
  local COUNTER_ID_0 = 0x10 --Black
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--destroy replace
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_DESTROY_REPLACE)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCountLimit(1)
  	e3:SetTarget(s.reptg)
  	e3:SetValue(s.repval)
  	e3:SetOperation(s.repop)
  	c:RegisterEffect(e3)
  end
  function s.cfilter(c, tp)
  	return c:IsSummonPlayer(tp) and c:IsType(TYPE_SYNCHRO) and c:IsAttribute(ATTRIBUTE_DARK) and c:IsPreviousLocation(LOCATION_EXTRA)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:FilterCount(s.cfilter, nil, tp) > 0
  end
  function s.spfilter(c, e, tp, atk)
  	return (c:IsSetCard(SETCARD_ID_0) or c:IsCode(CARD_ID_0)) and c:GetAttack() < atk and (not c:IsLocation(LOCATION_REMOVED) or c:IsFaceup()) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local _, atk = eg:Filter(s.cfilter, nil, tp):GetMaxGroup(Card.GetAttack)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE + LOCATION_REMOVED) and s.spfilter(chkc, e, tp, atk)
  	end
  	if chk == 0 then
  		return atk and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.spfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, nil, e, tp, atk)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.spfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, 1, nil, e, tp, atk)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup() and c:IsLocation(LOCATION_MZONE) and c:IsAttribute(ATTRIBUTE_DARK) and c:IsControler(tp) and c:IsReason(REASON_BATTLE + REASON_EFFECT) and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return eg:IsExists(s.repfilter, 1, nil, tp) and Duel.IsCanRemoveCounter(tp, 1, 0, COUNTER_ID_0, 1, REASON_EFFECT)
  	end
  	return Duel.SelectEffectYesNo(tp, e:GetHandler(), 96)
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.RemoveCounter(tp, 1, 0, COUNTER_ID_0, 1, REASON_EFFECT)
  end
  
  