name: Rescue
card_text: You can shuffle this card you control into the Deck; Special Summon monster(s) from your Deck, except "Rescue Ferret", whose total Levels equal 6, to your zone(s) a Link Monster(s) points to, but those Summoned monsters have their effects negated, also destroy them during the End Phase. You can only use this effect of "Rescue Ferret" once per turn.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.spcost)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToDeckAsCost()
  	end
  	Duel.SendtoDeck(e:GetHandler(), nil, SEQ_DECKSHUFFLE, REASON_COST)
  end
  function s.spfilter(c, e, tp)
  	return c:GetLevel() > 0 and not c:IsCode(id) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local zone = Duel.GetLinkedZone(tp)
  		local ct = Duel.GetLocationCount(tp, LOCATION_MZONE, tp, LOCATION_REASON_TOFIELD, zone)
  		local seq = e:GetHandler():GetSequence()
  		if seq < 5 and bit.extract(zone, seq) ~= 0 then
  			ct = ct + 1
  		end
  		if ct <= 0 then
  			return false
  		end
  		if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  			ct = 1
  		end
  		local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_DECK, 0, nil, e, tp)
  		return g:CheckWithSumEqual(Card.GetLevel, 6, 1, ct)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local zone = Duel.GetLinkedZone(tp)
  	local ct = Duel.GetLocationCount(tp, LOCATION_MZONE, tp, LOCATION_REASON_TOFIELD, zone)
  	if ct <= 0 then
  		return
  	end
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		ct = 1
  	end
  	local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_DECK, 0, nil, e, tp)
  	if g:CheckWithSumEqual(Card.GetLevel, 6, 1, ct) then
  		local fid = c:GetFieldID()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local sg = g:SelectWithSumEqual(tp, Card.GetLevel, 6, 1, ct)
  		local tc = sg:GetFirst()
  		while tc do
  			Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP, zone)
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_DISABLE)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e1)
  			local e2 = Effect.CreateEffect(c)
  			e2:SetType(EFFECT_TYPE_SINGLE)
  			e2:SetCode(EFFECT_DISABLE_EFFECT)
  			e2:SetValue(RESET_TURN_SET)
  			e2:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e2)
  			tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1, fid)
  			tc = sg:GetNext()
  		end
  		Duel.SpecialSummonComplete()
  		sg:KeepAlive()
  		local e3 = Effect.CreateEffect(c)
  		e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e3:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  		e3:SetCode(EVENT_PHASE + PHASE_END)
  		e3:SetCountLimit(1)
  		e3:SetLabel(fid)
  		e3:SetLabelObject(sg)
  		e3:SetCondition(s.descon)
  		e3:SetOperation(s.desop)
  		Duel.RegisterEffect(e3, tp)
  	end
  end
  function s.desfilter(c, fid)
  	return c:GetFlagEffectLabel(id) == fid
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local g = e:GetLabelObject()
  	if not g:IsExists(s.desfilter, 1, nil, e:GetLabel()) then
  		g:DeleteGroup()
  		e:Reset()
  		return false
  	else
  		return true
  	end
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local g = e:GetLabelObject()
  	local tg = g:Filter(s.desfilter, nil, e:GetLabel())
  	Duel.Destroy(tg, REASON_EFFECT)
  end
  
  
source_text: Rescue
  You can shuffle this card you control into the Deck; Special Summon monster(s) from your Deck, except "Rescue Ferret", whose total Levels equal 6, to your zone(s) a Link Monster(s) points to, but those Summoned monsters have their effects negated, also destroy them during the End Phase. You can only use this effect of "Rescue Ferret" once per turn.
target_text: -- Rescue
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.spcost)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToDeckAsCost()
  	end
  	Duel.SendtoDeck(e:GetHandler(), nil, SEQ_DECKSHUFFLE, REASON_COST)
  end
  function s.spfilter(c, e, tp)
  	return c:GetLevel() > 0 and not c:IsCode(id) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local zone = Duel.GetLinkedZone(tp)
  		local ct = Duel.GetLocationCount(tp, LOCATION_MZONE, tp, LOCATION_REASON_TOFIELD, zone)
  		local seq = e:GetHandler():GetSequence()
  		if seq < 5 and bit.extract(zone, seq) ~= 0 then
  			ct = ct + 1
  		end
  		if ct <= 0 then
  			return false
  		end
  		if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  			ct = 1
  		end
  		local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_DECK, 0, nil, e, tp)
  		return g:CheckWithSumEqual(Card.GetLevel, 6, 1, ct)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local zone = Duel.GetLinkedZone(tp)
  	local ct = Duel.GetLocationCount(tp, LOCATION_MZONE, tp, LOCATION_REASON_TOFIELD, zone)
  	if ct <= 0 then
  		return
  	end
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		ct = 1
  	end
  	local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_DECK, 0, nil, e, tp)
  	if g:CheckWithSumEqual(Card.GetLevel, 6, 1, ct) then
  		local fid = c:GetFieldID()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local sg = g:SelectWithSumEqual(tp, Card.GetLevel, 6, 1, ct)
  		local tc = sg:GetFirst()
  		while tc do
  			Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP, zone)
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_DISABLE)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e1)
  			local e2 = Effect.CreateEffect(c)
  			e2:SetType(EFFECT_TYPE_SINGLE)
  			e2:SetCode(EFFECT_DISABLE_EFFECT)
  			e2:SetValue(RESET_TURN_SET)
  			e2:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e2)
  			tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1, fid)
  			tc = sg:GetNext()
  		end
  		Duel.SpecialSummonComplete()
  		sg:KeepAlive()
  		local e3 = Effect.CreateEffect(c)
  		e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e3:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  		e3:SetCode(EVENT_PHASE + PHASE_END)
  		e3:SetCountLimit(1)
  		e3:SetLabel(fid)
  		e3:SetLabelObject(sg)
  		e3:SetCondition(s.descon)
  		e3:SetOperation(s.desop)
  		Duel.RegisterEffect(e3, tp)
  	end
  end
  function s.desfilter(c, fid)
  	return c:GetFlagEffectLabel(id) == fid
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local g = e:GetLabelObject()
  	if not g:IsExists(s.desfilter, 1, nil, e:GetLabel()) then
  		g:DeleteGroup()
  		e:Reset()
  		return false
  	else
  		return true
  	end
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local g = e:GetLabelObject()
  	local tg = g:Filter(s.desfilter, nil, e:GetLabel())
  	Duel.Destroy(tg, REASON_EFFECT)
  end
  
  