name: SPYRAL
card_text: Once per turn: You can add 1 "SPYRAL MISSION" card from your Deck to your hand. If this card is sent from the field to the GY: You can add 1 "SPYRAL Resort" and 1 "SPYRAL" monster from your Deck to your hand, except "SPYRAL Master Plan". You can only use this effect of "SPYRAL Master Plan" once per turn.
external_ids: local CARD_ID_0 = 54631665 --SPYRAL Resort
  local SETCARD_ID_0 = 0x20ee --SPYRAL
  local SETCARD_ID_1 = 0xee --SPYRAL
  
lua: local CARD_ID_0 = 54631665 --SPYRAL Resort
  local SETCARD_ID_0 = 0x20ee --SPYRAL
  local SETCARD_ID_1 = 0xee --SPYRAL
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--search
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1)
  	e1:SetTarget(s.thtg1)
  	e1:SetOperation(s.thop1)
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.thcon2)
  	e2:SetTarget(s.thtg2)
  	e2:SetOperation(s.thop2)
  	c:RegisterEffect(e2)
  end
  function s.thfilter1(c)
  	return c:IsSetCard(SETCARD_ID_1) and c:IsAbleToHand()
  end
  function s.thtg1(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter1, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop1(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter1, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  function s.thcon2(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsPreviousLocation(LOCATION_ONFIELD)
  end
  function s.thfilter2(c, tp)
  	return c:IsCode(CARD_ID_0) and c:IsAbleToHand() and Duel.IsExistingMatchingCard(s.thfilter3, tp, LOCATION_DECK, 0, 1, c)
  end
  function s.thfilter3(c)
  	return c:IsSetCard(SETCARD_ID_1) and c:IsType(TYPE_MONSTER) and not c:IsCode(id) and c:IsAbleToHand()
  end
  function s.thtg2(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter2, tp, LOCATION_DECK, 0, 1, nil, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop2(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g1 = Duel.SelectMatchingCard(tp, s.thfilter2, tp, LOCATION_DECK, 0, 1, 1, nil, tp)
  	if g1:GetCount() > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local g2 = Duel.SelectMatchingCard(tp, s.thfilter3, tp, LOCATION_DECK, 0, 1, 1, g1:GetFirst())
  		g1:Merge(g2)
  		Duel.SendtoHand(g1, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g1)
  	end
  end
  
  
source_text: SPYRAL
  Once per turn: You can add 1 "SPYRAL MISSION" card from your Deck to your hand. If this card is sent from the field to the GY: You can add 1 "SPYRAL Resort" and 1 "SPYRAL" monster from your Deck to your hand, except "SPYRAL Master Plan". You can only use this effect of "SPYRAL Master Plan" once per turn.
target_text: -- SPYRAL
  local CARD_ID_0 = 54631665 --SPYRAL Resort
  local SETCARD_ID_0 = 0x20ee --SPYRAL
  local SETCARD_ID_1 = 0xee --SPYRAL
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--search
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1)
  	e1:SetTarget(s.thtg1)
  	e1:SetOperation(s.thop1)
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.thcon2)
  	e2:SetTarget(s.thtg2)
  	e2:SetOperation(s.thop2)
  	c:RegisterEffect(e2)
  end
  function s.thfilter1(c)
  	return c:IsSetCard(SETCARD_ID_1) and c:IsAbleToHand()
  end
  function s.thtg1(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter1, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop1(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter1, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  function s.thcon2(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsPreviousLocation(LOCATION_ONFIELD)
  end
  function s.thfilter2(c, tp)
  	return c:IsCode(CARD_ID_0) and c:IsAbleToHand() and Duel.IsExistingMatchingCard(s.thfilter3, tp, LOCATION_DECK, 0, 1, c)
  end
  function s.thfilter3(c)
  	return c:IsSetCard(SETCARD_ID_1) and c:IsType(TYPE_MONSTER) and not c:IsCode(id) and c:IsAbleToHand()
  end
  function s.thtg2(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter2, tp, LOCATION_DECK, 0, 1, nil, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop2(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g1 = Duel.SelectMatchingCard(tp, s.thfilter2, tp, LOCATION_DECK, 0, 1, 1, nil, tp)
  	if g1:GetCount() > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local g2 = Duel.SelectMatchingCard(tp, s.thfilter3, tp, LOCATION_DECK, 0, 1, 1, g1:GetFirst())
  		g1:Merge(g2)
  		Duel.SendtoHand(g1, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g1)
  	end
  end
  
  