name: Blackwing
card_text: Shuffle 2 of your "Blackwing" monsters (1 Tuner and 1 non-Tuner) that are banished and/or in your GY into the Deck/Extra Deck; Special Summon 1 "Blackwing" Synchro Monster or "Black-Winged Dragon" from your Extra Deck whose Level equals the total Levels of those 2 monsters. (This is treated as a Synchro Summon.) If you control 2 or more "Blackwing" monsters, you can activate this card from your hand. You can only activate 1 "Blackwing - Twin Shadow" per turn.
external_ids: local CARD_ID_0 = 9012916 --Black-Winged Dragon
  local SETCARD_ID_0 = 0x33 --Blackwing
  
lua: local CARD_ID_0 = 9012916 --Black-Winged Dragon
  local SETCARD_ID_0 = 0x33 --Blackwing
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--act in hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_TRAP_ACT_IN_HAND)
  	e2:SetCondition(s.handcon)
  	c:RegisterEffect(e2)
  end
  function s.confilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.handcon(e)
  	return Duel.IsExistingMatchingCard(s.confilter, e:GetHandlerPlayer(), LOCATION_MZONE, 0, 2, nil)
  end
  function s.tdfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:GetLevel() > 0 and c:IsAbleToDeckOrExtraAsCost() and (c:IsFaceup() or c:IsLocation(LOCATION_GRAVE))
  end
  function s.fselect(g, e, tp)
  	return aux.gffcheck(g, Card.IsType, TYPE_TUNER, aux.NOT(Card.IsType), TYPE_TUNER) and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, g:GetSum(Card.GetLevel))
  end
  function s.spfilter(c, e, tp, lv)
  	return (c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SYNCHRO) or c:IsCode(CARD_ID_0))
  		and c:IsLevel(lv)
  		and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0
  		and c:IsCanBeSpecialSummoned(e, SUMMON_TYPE_SYNCHRO, tp, false, false)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(100)
  	local g = Duel.GetMatchingGroup(s.tdfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, nil)
  	if chk == 0 then
  		return g:CheckSubGroup(s.fselect, 2, 2, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local sg = g:SelectSubGroup(tp, s.fselect, false, 2, 2, e, tp)
  	e:SetLabel(sg:GetSum(Card.GetLevel))
  	Duel.HintSelection(sg)
  	Duel.SendtoDeck(sg, nil, SEQ_DECKSHUFFLE, REASON_COST)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		if e:GetLabel() ~= 100 then
  			return false
  		end
  		e:SetLabel(0)
  		return aux.MustMaterialCheck(nil, tp, EFFECT_MUST_BE_SMATERIAL)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	if not aux.MustMaterialCheck(nil, tp, EFFECT_MUST_BE_SMATERIAL) then
  		return
  	end
  	local lv = e:GetLabel()
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local tc = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp, lv):GetFirst()
  	if tc then
  		tc:SetMaterial(nil)
  		if Duel.SpecialSummon(tc, SUMMON_TYPE_SYNCHRO, tp, tp, false, false, POS_FACEUP) > 0 then
  			tc:CompleteProcedure()
  		end
  	end
  end
  
  
source_text: Blackwing
  Shuffle 2 of your "Blackwing" monsters (1 Tuner and 1 non-Tuner) that are banished and/or in your GY into the Deck/Extra Deck; Special Summon 1 "Blackwing" Synchro Monster or "Black-Winged Dragon" from your Extra Deck whose Level equals the total Levels of those 2 monsters. (This is treated as a Synchro Summon.) If you control 2 or more "Blackwing" monsters, you can activate this card from your hand. You can only activate 1 "Blackwing - Twin Shadow" per turn.
target_text: -- Blackwing
  local CARD_ID_0 = 9012916 --Black-Winged Dragon
  local SETCARD_ID_0 = 0x33 --Blackwing
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--act in hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_TRAP_ACT_IN_HAND)
  	e2:SetCondition(s.handcon)
  	c:RegisterEffect(e2)
  end
  function s.confilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.handcon(e)
  	return Duel.IsExistingMatchingCard(s.confilter, e:GetHandlerPlayer(), LOCATION_MZONE, 0, 2, nil)
  end
  function s.tdfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:GetLevel() > 0 and c:IsAbleToDeckOrExtraAsCost() and (c:IsFaceup() or c:IsLocation(LOCATION_GRAVE))
  end
  function s.fselect(g, e, tp)
  	return aux.gffcheck(g, Card.IsType, TYPE_TUNER, aux.NOT(Card.IsType), TYPE_TUNER) and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, g:GetSum(Card.GetLevel))
  end
  function s.spfilter(c, e, tp, lv)
  	return (c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SYNCHRO) or c:IsCode(CARD_ID_0))
  		and c:IsLevel(lv)
  		and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0
  		and c:IsCanBeSpecialSummoned(e, SUMMON_TYPE_SYNCHRO, tp, false, false)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(100)
  	local g = Duel.GetMatchingGroup(s.tdfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, nil)
  	if chk == 0 then
  		return g:CheckSubGroup(s.fselect, 2, 2, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local sg = g:SelectSubGroup(tp, s.fselect, false, 2, 2, e, tp)
  	e:SetLabel(sg:GetSum(Card.GetLevel))
  	Duel.HintSelection(sg)
  	Duel.SendtoDeck(sg, nil, SEQ_DECKSHUFFLE, REASON_COST)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		if e:GetLabel() ~= 100 then
  			return false
  		end
  		e:SetLabel(0)
  		return aux.MustMaterialCheck(nil, tp, EFFECT_MUST_BE_SMATERIAL)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	if not aux.MustMaterialCheck(nil, tp, EFFECT_MUST_BE_SMATERIAL) then
  		return
  	end
  	local lv = e:GetLabel()
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local tc = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp, lv):GetFirst()
  	if tc then
  		tc:SetMaterial(nil)
  		if Duel.SpecialSummon(tc, SUMMON_TYPE_SYNCHRO, tp, tp, false, false, POS_FACEUP) > 0 then
  			tc:CompleteProcedure()
  		end
  	end
  end
  
  