name: Until
card_text: Excavate cards from the top of your Deck, equal to the number of "Noble Arms" Equip Spells you control, and if you do, add 1 of them to your hand, also place the remaining cards on top of your Deck in any order. You can banish this card from your GY, except the turn this card was sent to the GY; Special Summon from your Deck, 1 "Noble Knight" monster with a different name from the cards you control or in your GY. You can only use this effect of "Until Noble Arms are Needed Once Again" once per turn.
external_ids: local SETCARD_ID_0 = 0x207a --Noble
  local SETCARD_ID_1 = 0x107a --Noble
  
lua: local SETCARD_ID_0 = 0x207a --Noble
  local SETCARD_ID_1 = 0x107a --Noble
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetHintTiming(0, TIMING_END_PHASE)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(aux.exccon)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsType(TYPE_EQUIP) and c:IsSetCard(SETCARD_ID_1)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ct = Duel.GetMatchingGroupCount(s.filter, tp, LOCATION_ONFIELD, 0, nil)
  	if chk == 0 then
  		return ct > 0 and Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) >= ct
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local ct = Duel.GetMatchingGroupCount(s.filter, tp, LOCATION_ONFIELD, 0, nil)
  	if ct == 0 then
  		return
  	end
  	Duel.ConfirmDecktop(tp, ct)
  	local g = Duel.GetDecktopGroup(tp, ct)
  	if #g == 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local sg = g:Select(tp, 1, 1, nil)
  	Duel.DisableShuffleCheck()
  	if Duel.SendtoHand(sg, nil, REASON_EFFECT) ~= 0 then
  		Duel.ConfirmCards(1 - tp, sg)
  		ct = ct - 1
  	end
  	Duel.ShuffleHand(tp)
  	if ct > 0 then
  		Duel.SortDecktop(tp, tp, ct)
  	end
  end
  function s.eqfilter(c, cd)
  	return c:IsCode(cd) and (c:IsFaceup() or not c:IsOnField())
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_1) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and not Duel.IsExistingMatchingCard(s.eqfilter, tp, LOCATION_ONFIELD + LOCATION_GRAVE, 0, 1, nil, c:GetCode())
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) < 1 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if #g > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Until
  Excavate cards from the top of your Deck, equal to the number of "Noble Arms" Equip Spells you control, and if you do, add 1 of them to your hand, also place the remaining cards on top of your Deck in any order. You can banish this card from your GY, except the turn this card was sent to the GY; Special Summon from your Deck, 1 "Noble Knight" monster with a different name from the cards you control or in your GY. You can only use this effect of "Until Noble Arms are Needed Once Again" once per turn.
target_text: -- Until
  local SETCARD_ID_0 = 0x207a --Noble
  local SETCARD_ID_1 = 0x107a --Noble
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetHintTiming(0, TIMING_END_PHASE)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(aux.exccon)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsType(TYPE_EQUIP) and c:IsSetCard(SETCARD_ID_1)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ct = Duel.GetMatchingGroupCount(s.filter, tp, LOCATION_ONFIELD, 0, nil)
  	if chk == 0 then
  		return ct > 0 and Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) >= ct
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local ct = Duel.GetMatchingGroupCount(s.filter, tp, LOCATION_ONFIELD, 0, nil)
  	if ct == 0 then
  		return
  	end
  	Duel.ConfirmDecktop(tp, ct)
  	local g = Duel.GetDecktopGroup(tp, ct)
  	if #g == 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local sg = g:Select(tp, 1, 1, nil)
  	Duel.DisableShuffleCheck()
  	if Duel.SendtoHand(sg, nil, REASON_EFFECT) ~= 0 then
  		Duel.ConfirmCards(1 - tp, sg)
  		ct = ct - 1
  	end
  	Duel.ShuffleHand(tp)
  	if ct > 0 then
  		Duel.SortDecktop(tp, tp, ct)
  	end
  end
  function s.eqfilter(c, cd)
  	return c:IsCode(cd) and (c:IsFaceup() or not c:IsOnField())
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_1) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and not Duel.IsExistingMatchingCard(s.eqfilter, tp, LOCATION_ONFIELD + LOCATION_GRAVE, 0, 1, nil, c:GetCode())
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) < 1 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if #g > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  