name: Ultimate
card_text: Banish 7 "Fire Formation" Spell/Trap Cards from your Graveyard; Special Summon as many "Fire Fist" monsters as possible from your Graveyard, then you can Set "Fire Formation" Spell/Trap Cards directly from your Deck, except "Ultimate Fire Formation - Seito", up to the number of monsters Special Summoned by this effect.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x79 --Fire
  local SETCARD_ID_1 = 0x7c --Fire
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x79 --Fire
  local SETCARD_ID_1 = 0x7c --Fire
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCost(s.spcost)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c)
  	return c:IsSetCard(SETCARD_ID_1) and c:IsType(TYPE_SPELL + TYPE_TRAP) and c:IsAbleToRemoveAsCost()
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_GRAVE, 0, 7, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_GRAVE, 0, 7, 7, nil)
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  end
  function s.filter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_1) 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
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.sfilter(c)
  	return c:IsSetCard(SETCARD_ID_1) and not c:IsCode(id) and c:IsType(TYPE_SPELL + TYPE_TRAP) and c:IsSSetable()
  end
  function s.fselect(g, ft)
  	local fc = g:FilterCount(Card.IsType, nil, TYPE_FIELD)
  	return fc <= 1 and #g - fc <= ft
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	local tg = Duel.GetMatchingGroup(s.filter, tp, LOCATION_GRAVE, 0, nil, e, tp)
  	if ft <= 0 or tg:GetCount() == 0 then
  		return
  	end
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		ft = 1
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = tg:Select(tp, ft, ft, nil)
  	local ct = Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	if ct > 0 then
  		local ft2 = Duel.GetLocationCount(tp, LOCATION_SZONE)
  		local sg = Duel.GetMatchingGroup(s.sfilter, tp, LOCATION_DECK, 0, nil)
  		if sg:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  			local setg = sg:SelectSubGroup(tp, s.fselect, false, 1, math.min(ct, ft2 + 1), ft2)
  			Duel.SSet(tp, setg)
  		end
  	end
  end
  
  
source_text: Ultimate
  Banish 7 "Fire Formation" Spell/Trap Cards from your Graveyard; Special Summon as many "Fire Fist" monsters as possible from your Graveyard, then you can Set "Fire Formation" Spell/Trap Cards directly from your Deck, except "Ultimate Fire Formation - Seito", up to the number of monsters Special Summoned by this effect.
target_text: -- Ultimate
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x79 --Fire
  local SETCARD_ID_1 = 0x7c --Fire
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCost(s.spcost)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c)
  	return c:IsSetCard(SETCARD_ID_1) and c:IsType(TYPE_SPELL + TYPE_TRAP) and c:IsAbleToRemoveAsCost()
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_GRAVE, 0, 7, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_GRAVE, 0, 7, 7, nil)
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  end
  function s.filter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_1) 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
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.sfilter(c)
  	return c:IsSetCard(SETCARD_ID_1) and not c:IsCode(id) and c:IsType(TYPE_SPELL + TYPE_TRAP) and c:IsSSetable()
  end
  function s.fselect(g, ft)
  	local fc = g:FilterCount(Card.IsType, nil, TYPE_FIELD)
  	return fc <= 1 and #g - fc <= ft
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	local tg = Duel.GetMatchingGroup(s.filter, tp, LOCATION_GRAVE, 0, nil, e, tp)
  	if ft <= 0 or tg:GetCount() == 0 then
  		return
  	end
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		ft = 1
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = tg:Select(tp, ft, ft, nil)
  	local ct = Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	if ct > 0 then
  		local ft2 = Duel.GetLocationCount(tp, LOCATION_SZONE)
  		local sg = Duel.GetMatchingGroup(s.sfilter, tp, LOCATION_DECK, 0, nil)
  		if sg:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  			local setg = sg:SelectSubGroup(tp, s.fselect, false, 1, math.min(ct, ft2 + 1), ft2)
  			Duel.SSet(tp, setg)
  		end
  	end
  end
  
  