name: Gladiator
card_text: "Gladiator Beast Bestiari" + 1 "Gladiator Beast" monster
  Must first be Special Summoned (from your Extra Deck) by shuffling the above cards you control into the Deck. (You do not use "Polymerization".) When this card is Special Summoned: You can target up to 2 cards on the field; destroy those targets. At the end of the Battle Phase, if this card battled: You can return it to the Extra Deck; Special Summon 2 "Gladiator Beast" monsters from your Deck, except "Gladiator Beast Bestiari".
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 41470137 --Gladiator Beast Bestiari
  local SETCARD_ID_0 = 0x1019 --Gladiator
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 41470137 --Gladiator Beast Bestiari
  local SETCARD_ID_0 = 0x1019 --Gladiator
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--fusion material
  	c:EnableReviveLimit()
  	aux.AddFusionProcCodeFun(c, CARD_ID_1, aux.FilterBoolFunction(Card.IsFusionSetCard, SETCARD_ID_0), 1, true, true)
  	aux.AddContactFusionProcedure(c, s.cfilter, LOCATION_ONFIELD, 0, aux.ContactFusionSendToDeck(c))
  	--spsummon condition
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	e1:SetValue(s.splimit)
  	c:RegisterEffect(e1)
  	--destroy
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_DESTROY)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP)
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e3:SetTarget(s.destg)
  	e3:SetOperation(s.desop)
  	c:RegisterEffect(e3)
  	--special summon
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_PHASE + PHASE_BATTLE)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCondition(s.spcon)
  	e4:SetCost(s.spcost)
  	e4:SetTarget(s.sptg)
  	e4:SetOperation(s.spop)
  	c:RegisterEffect(e4)
  end
  function s.splimit(e, se, sp, st)
  	return e:GetHandler():GetLocation() ~= LOCATION_EXTRA
  end
  function s.cfilter(c)
  	return (c:IsFusionCode(CARD_ID_1) or c:IsFusionSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER)) and c:IsAbleToDeckOrExtraAsCost()
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(aux.TRUE, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, aux.TRUE, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 2, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local tg = g:Filter(Card.IsRelateToEffect, nil, e)
  	if tg:GetCount() > 0 then
  		Duel.Destroy(tg, REASON_EFFECT)
  	end
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetBattledGroupCount() > 0
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsAbleToExtraAsCost()
  	end
  	Duel.SendtoDeck(c, nil, SEQ_DECKTOP, REASON_COST)
  end
  function s.filter(c, e, tp)
  	return not c:IsCode(CARD_ID_1) and c:IsSetCard(SETCARD_ID_0) 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 ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  		if e:GetHandler():GetSequence() < 5 then
  			ft = ft + 1
  		end
  		return ft > 1 and not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 2, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 2, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		return
  	end
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) < 2 then
  		return
  	end
  	local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_DECK, 0, nil, e, tp)
  	if g:GetCount() >= 2 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local sg = g:Select(tp, 2, 2, nil)
  		local tc = sg:GetFirst()
  		Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP)
  		tc:RegisterFlagEffect(tc:GetOriginalCode(), RESET_EVENT + RESETS_STANDARD + RESET_DISABLE, 0, 0)
  		tc = sg:GetNext()
  		Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP)
  		tc:RegisterFlagEffect(tc:GetOriginalCode(), RESET_EVENT + RESETS_STANDARD + RESET_DISABLE, 0, 0)
  		Duel.SpecialSummonComplete()
  	end
  end
  
  
source_text: Gladiator
  "Gladiator Beast Bestiari" + 1 "Gladiator Beast" monster
  Must first be Special Summoned (from your Extra Deck) by shuffling the above cards you control into the Deck. (You do not use "Polymerization".) When this card is Special Summoned: You can target up to 2 cards on the field; destroy those targets. At the end of the Battle Phase, if this card battled: You can return it to the Extra Deck; Special Summon 2 "Gladiator Beast" monsters from your Deck, except "Gladiator Beast Bestiari".
target_text: -- Gladiator
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 41470137 --Gladiator Beast Bestiari
  local SETCARD_ID_0 = 0x1019 --Gladiator
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--fusion material
  	c:EnableReviveLimit()
  	aux.AddFusionProcCodeFun(c, CARD_ID_1, aux.FilterBoolFunction(Card.IsFusionSetCard, SETCARD_ID_0), 1, true, true)
  	aux.AddContactFusionProcedure(c, s.cfilter, LOCATION_ONFIELD, 0, aux.ContactFusionSendToDeck(c))
  	--spsummon condition
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	e1:SetValue(s.splimit)
  	c:RegisterEffect(e1)
  	--destroy
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_DESTROY)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP)
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e3:SetTarget(s.destg)
  	e3:SetOperation(s.desop)
  	c:RegisterEffect(e3)
  	--special summon
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_PHASE + PHASE_BATTLE)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCondition(s.spcon)
  	e4:SetCost(s.spcost)
  	e4:SetTarget(s.sptg)
  	e4:SetOperation(s.spop)
  	c:RegisterEffect(e4)
  end
  function s.splimit(e, se, sp, st)
  	return e:GetHandler():GetLocation() ~= LOCATION_EXTRA
  end
  function s.cfilter(c)
  	return (c:IsFusionCode(CARD_ID_1) or c:IsFusionSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER)) and c:IsAbleToDeckOrExtraAsCost()
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(aux.TRUE, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, aux.TRUE, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 2, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local tg = g:Filter(Card.IsRelateToEffect, nil, e)
  	if tg:GetCount() > 0 then
  		Duel.Destroy(tg, REASON_EFFECT)
  	end
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetBattledGroupCount() > 0
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsAbleToExtraAsCost()
  	end
  	Duel.SendtoDeck(c, nil, SEQ_DECKTOP, REASON_COST)
  end
  function s.filter(c, e, tp)
  	return not c:IsCode(CARD_ID_1) and c:IsSetCard(SETCARD_ID_0) 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 ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  		if e:GetHandler():GetSequence() < 5 then
  			ft = ft + 1
  		end
  		return ft > 1 and not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 2, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 2, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		return
  	end
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) < 2 then
  		return
  	end
  	local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_DECK, 0, nil, e, tp)
  	if g:GetCount() >= 2 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local sg = g:Select(tp, 2, 2, nil)
  		local tc = sg:GetFirst()
  		Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP)
  		tc:RegisterFlagEffect(tc:GetOriginalCode(), RESET_EVENT + RESETS_STANDARD + RESET_DISABLE, 0, 0)
  		tc = sg:GetNext()
  		Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP)
  		tc:RegisterFlagEffect(tc:GetOriginalCode(), RESET_EVENT + RESETS_STANDARD + RESET_DISABLE, 0, 0)
  		Duel.SpecialSummonComplete()
  	end
  end
  
  