name: Simorgh,
card_text: Your opponent cannot target this Tribute Summoned card with Spell/Trap Cards or effects. You can only use each of the following effects of "Simorgh, Lord of the Storm" once per turn.
  ● When a Spell/Trap Card or effect is activated (Quick Effect): You can Tribute 1 WIND Winged Beast monster, then target 1 card your opponent controls; shuffle it into the Deck.
  ● When a Winged Beast monster you control is destroyed by battle while this card is in your GY: You can add this card to your hand.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--cannot be target
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCondition(s.tgcon)
  	e1:SetValue(s.tgval)
  	c:RegisterEffect(e1)
  	--todeck
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_TODECK)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCode(EVENT_CHAINING)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.tdcon)
  	e2:SetCost(s.tdcost)
  	e2:SetTarget(s.tdtg)
  	e2:SetOperation(s.tdop)
  	c:RegisterEffect(e2)
  	--tohand
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_TOHAND)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_BATTLE_DESTROYED)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(s.thcon)
  	e3:SetTarget(s.thtg)
  	e3:SetOperation(s.thop)
  	c:RegisterEffect(e3)
  end
  function s.tgcon(e)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_ADVANCE)
  end
  function s.tgval(e, re, rp)
  	return rp == 1 - e:GetHandlerPlayer() and re:IsActiveType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.tdcon(e, tp, eg, ep, ev, re, r, rp)
  	return re:IsActiveType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.costfilter(c, tp)
  	return c:IsRace(RACE_WINDBEAST) and c:IsAttribute(ATTRIBUTE_WIND) and (c:IsControler(tp) or c:IsFaceup())
  end
  function s.tdcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckReleaseGroup(tp, s.costfilter, 1, nil, tp)
  	end
  	local sg = Duel.SelectReleaseGroup(tp, s.costfilter, 1, 1, nil, tp)
  	Duel.Release(sg, REASON_COST)
  end
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and chkc:IsControler(1 - tp) and chkc:IsAbleToDeck()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsAbleToDeck, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, Card.IsAbleToDeck, tp, 0, LOCATION_ONFIELD, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, 1, 0, 0)
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SendtoDeck(tc, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsRace(RACE_WINDBEAST) and c:IsPreviousControler(tp)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, e:GetHandler(), tp)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToHand()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, e:GetHandler(), 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SendtoHand(c, nil, REASON_EFFECT)
  	end
  end
  
  
source_text: Simorgh,
  Your opponent cannot target this Tribute Summoned card with Spell/Trap Cards or effects. You can only use each of the following effects of "Simorgh, Lord of the Storm" once per turn.
  ● When a Spell/Trap Card or effect is activated (Quick Effect): You can Tribute 1 WIND Winged Beast monster, then target 1 card your opponent controls; shuffle it into the Deck.
  ● When a Winged Beast monster you control is destroyed by battle while this card is in your GY: You can add this card to your hand.
target_text: -- Simorgh,
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--cannot be target
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCondition(s.tgcon)
  	e1:SetValue(s.tgval)
  	c:RegisterEffect(e1)
  	--todeck
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_TODECK)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCode(EVENT_CHAINING)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.tdcon)
  	e2:SetCost(s.tdcost)
  	e2:SetTarget(s.tdtg)
  	e2:SetOperation(s.tdop)
  	c:RegisterEffect(e2)
  	--tohand
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_TOHAND)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_BATTLE_DESTROYED)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(s.thcon)
  	e3:SetTarget(s.thtg)
  	e3:SetOperation(s.thop)
  	c:RegisterEffect(e3)
  end
  function s.tgcon(e)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_ADVANCE)
  end
  function s.tgval(e, re, rp)
  	return rp == 1 - e:GetHandlerPlayer() and re:IsActiveType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.tdcon(e, tp, eg, ep, ev, re, r, rp)
  	return re:IsActiveType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.costfilter(c, tp)
  	return c:IsRace(RACE_WINDBEAST) and c:IsAttribute(ATTRIBUTE_WIND) and (c:IsControler(tp) or c:IsFaceup())
  end
  function s.tdcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckReleaseGroup(tp, s.costfilter, 1, nil, tp)
  	end
  	local sg = Duel.SelectReleaseGroup(tp, s.costfilter, 1, 1, nil, tp)
  	Duel.Release(sg, REASON_COST)
  end
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and chkc:IsControler(1 - tp) and chkc:IsAbleToDeck()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsAbleToDeck, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, Card.IsAbleToDeck, tp, 0, LOCATION_ONFIELD, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, 1, 0, 0)
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SendtoDeck(tc, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsRace(RACE_WINDBEAST) and c:IsPreviousControler(tp)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, e:GetHandler(), tp)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToHand()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, e:GetHandler(), 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SendtoHand(c, nil, REASON_EFFECT)
  	end
  end
  
  