name: Blackwing
card_text: You can send this card from your hand or field to the GY; place 1 "Black Feather Whirlwind" from your Deck face-up in your Spell & Trap Zone. If a "Blackwing" Synchro Monster(s) or "Black-Winged Dragon" is Special Summoned to your field, while this card is in your GY (except during the Damage Step): You can banish this card, then target 1 "Blackwing" monster in your GY; add it to your hand, then take 700 damage. You can only use each effect of "Blackwing - Shamal the Sandstorm" once per turn.
external_ids: local CARD_ID_1 = 9012916 --Black-Winged Dragon
  local CARD_ID_2 = 7602800 --Black Feather Whirlwind
  local SETCARD_ID_0 = 0x33 --Blackwing
  
lua: local CARD_ID_1 = 9012916 --Black-Winged Dragon
  local CARD_ID_2 = 7602800 --Black Feather Whirlwind
  local SETCARD_ID_0 = 0x33 --Blackwing
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_1)
  	--same effect send this card to grave and spsummon another card check
  	local e0 = aux.AddThisCardInGraveAlreadyCheck(c)
  	--set
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_HAND + LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.tfcost)
  	e1:SetTarget(s.tftg)
  	e1:SetOperation(s.tfop)
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOHAND + CATEGORY_DAMAGE)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetLabelObject(e0)
  	e2:SetCondition(s.thcon)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  end
  function s.tfcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToGraveAsCost()
  	end
  	Duel.SendtoGrave(e:GetHandler(), REASON_COST)
  end
  function s.tffilter(c, tp)
  	return c:IsCode(CARD_ID_2) and not c:IsForbidden() and c:CheckUniqueOnField(tp)
  end
  function s.tftg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and Duel.IsExistingMatchingCard(s.tffilter, tp, LOCATION_DECK, 0, 1, nil, tp)
  	end
  end
  function s.tfop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_SZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  	local tc = Duel.SelectMatchingCard(tp, s.tffilter, tp, LOCATION_DECK, 0, 1, 1, nil, tp):GetFirst()
  	if tc then
  		Duel.MoveToField(tc, tp, tp, LOCATION_SZONE, POS_FACEUP, true)
  	end
  end
  function s.cfilter(c, tp, se)
  	return c:IsFaceup() and ((c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SYNCHRO)) or c:IsCode(CARD_ID_1)) and c:IsControler(tp) and (se == nil or c:GetReasonEffect() ~= se)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	local se = e:GetLabelObject():GetLabelObject()
  	return eg:IsExists(s.cfilter, 1, nil, tp, se)
  end
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and s.thfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.thfilter, tp, LOCATION_GRAVE, 0, 1, e:GetHandler())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectTarget(tp, s.thfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, tp, 700)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.SendtoHand(tc, nil, REASON_EFFECT) > 0 then
  		Duel.BreakEffect()
  		Duel.Damage(tp, 700, REASON_EFFECT)
  	end
  end
  
  
source_text: Blackwing
  You can send this card from your hand or field to the GY; place 1 "Black Feather Whirlwind" from your Deck face-up in your Spell & Trap Zone. If a "Blackwing" Synchro Monster(s) or "Black-Winged Dragon" is Special Summoned to your field, while this card is in your GY (except during the Damage Step): You can banish this card, then target 1 "Blackwing" monster in your GY; add it to your hand, then take 700 damage. You can only use each effect of "Blackwing - Shamal the Sandstorm" once per turn.
target_text: -- Blackwing
  local CARD_ID_1 = 9012916 --Black-Winged Dragon
  local CARD_ID_2 = 7602800 --Black Feather Whirlwind
  local SETCARD_ID_0 = 0x33 --Blackwing
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_1)
  	--same effect send this card to grave and spsummon another card check
  	local e0 = aux.AddThisCardInGraveAlreadyCheck(c)
  	--set
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_HAND + LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.tfcost)
  	e1:SetTarget(s.tftg)
  	e1:SetOperation(s.tfop)
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOHAND + CATEGORY_DAMAGE)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetLabelObject(e0)
  	e2:SetCondition(s.thcon)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  end
  function s.tfcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToGraveAsCost()
  	end
  	Duel.SendtoGrave(e:GetHandler(), REASON_COST)
  end
  function s.tffilter(c, tp)
  	return c:IsCode(CARD_ID_2) and not c:IsForbidden() and c:CheckUniqueOnField(tp)
  end
  function s.tftg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and Duel.IsExistingMatchingCard(s.tffilter, tp, LOCATION_DECK, 0, 1, nil, tp)
  	end
  end
  function s.tfop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_SZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  	local tc = Duel.SelectMatchingCard(tp, s.tffilter, tp, LOCATION_DECK, 0, 1, 1, nil, tp):GetFirst()
  	if tc then
  		Duel.MoveToField(tc, tp, tp, LOCATION_SZONE, POS_FACEUP, true)
  	end
  end
  function s.cfilter(c, tp, se)
  	return c:IsFaceup() and ((c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SYNCHRO)) or c:IsCode(CARD_ID_1)) and c:IsControler(tp) and (se == nil or c:GetReasonEffect() ~= se)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	local se = e:GetLabelObject():GetLabelObject()
  	return eg:IsExists(s.cfilter, 1, nil, tp, se)
  end
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and s.thfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.thfilter, tp, LOCATION_GRAVE, 0, 1, e:GetHandler())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectTarget(tp, s.thfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, tp, 700)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.SendtoHand(tc, nil, REASON_EFFECT) > 0 then
  		Duel.BreakEffect()
  		Duel.Damage(tp, 700, REASON_EFFECT)
  	end
  end
  
  