name: Ritual
card_text: 1 "Ritual Beast Tamer" monster + 1 "Spiritual Beast" monster
  Must be Special Summoned (from your Extra Deck) by banishing the above cards you control, and cannot be Special Summoned by other ways. (You do not use "Polymerization".) If this card attacks, it is unaffected by other cards' effects until the end of the Damage Step. During either player's turn: You can return this card you control to the Extra Deck, then target 2 of your banished monsters (1 "Ritual Beast Tamer" monster and 1 "Spiritual Beast" monster); Special Summon them in Defense Position.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x20b5 --Spiritual
  local SETCARD_ID_1 = 0x10b5 --Ritual
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x20b5 --Spiritual
  local SETCARD_ID_1 = 0x10b5 --Ritual
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--fusion material
  	c:EnableReviveLimit()
  	aux.AddFusionProcFun2(c, aux.FilterBoolFunction(Card.IsFusionSetCard, SETCARD_ID_1), aux.FilterBoolFunction(Card.IsFusionSetCard, SETCARD_ID_1), true)
  	aux.AddContactFusionProcedure(c, Card.IsAbleToRemoveAsCost, LOCATION_MZONE, 0, Duel.Remove, POS_FACEUP, REASON_COST)
  	--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)
  	c:RegisterEffect(e1)
  	--immune
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCode(EFFECT_IMMUNE_EFFECT)
  	e3:SetCondition(s.immcon)
  	e3:SetValue(s.efilter)
  	c:RegisterEffect(e3)
  	--special summon
  	local e4 = Effect.CreateEffect(c)
  	e4:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e4:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e4:SetType(EFFECT_TYPE_QUICK_O)
  	e4:SetCode(EVENT_FREE_CHAIN)
  	e4:SetHintTiming(0, TIMING_END_PHASE)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCost(s.spcost)
  	e4:SetTarget(s.sptg)
  	e4:SetOperation(s.spop)
  	c:RegisterEffect(e4)
  end
  function s.immcon(e)
  	return Duel.GetAttacker() == e:GetHandler()
  end
  function s.efilter(e, te)
  	return te:GetOwner() ~= e:GetOwner()
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToExtraAsCost()
  	end
  	Duel.SendtoDeck(e:GetHandler(), nil, SEQ_DECKTOP, REASON_COST)
  end
  function s.filter1(c, e, tp)
  	return c:IsFaceup()
  		and c:IsSetCard(SETCARD_ID_1)
  		and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  		and Duel.IsExistingTarget(s.filter2, tp, LOCATION_REMOVED, 0, 1, c, e, tp)
  end
  function s.filter2(c, e, tp)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_1) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) and Duel.GetMZoneCount(tp, e:GetHandler()) > 1 and Duel.IsExistingTarget(s.filter1, tp, LOCATION_REMOVED, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g1 = Duel.SelectTarget(tp, s.filter1, tp, LOCATION_REMOVED, 0, 1, 1, nil, e, tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g2 = Duel.SelectTarget(tp, s.filter2, tp, LOCATION_REMOVED, 0, 1, 1, g1:GetFirst(), e, tp)
  	g1:Merge(g2)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g1, 2, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		ft = 1
  	end
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if g:GetCount() == 0 then
  		return
  	end
  	if g:GetCount() <= ft then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
  	else
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local sg = g:Select(tp, ft, ft, nil)
  		Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
  		g:Sub(sg)
  		Duel.SendtoGrave(g, REASON_RULE)
  	end
  end
  
  
source_text: Ritual
  1 "Ritual Beast Tamer" monster + 1 "Spiritual Beast" monster
  Must be Special Summoned (from your Extra Deck) by banishing the above cards you control, and cannot be Special Summoned by other ways. (You do not use "Polymerization".) If this card attacks, it is unaffected by other cards' effects until the end of the Damage Step. During either player's turn: You can return this card you control to the Extra Deck, then target 2 of your banished monsters (1 "Ritual Beast Tamer" monster and 1 "Spiritual Beast" monster); Special Summon them in Defense Position.
target_text: -- Ritual
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x20b5 --Spiritual
  local SETCARD_ID_1 = 0x10b5 --Ritual
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--fusion material
  	c:EnableReviveLimit()
  	aux.AddFusionProcFun2(c, aux.FilterBoolFunction(Card.IsFusionSetCard, SETCARD_ID_1), aux.FilterBoolFunction(Card.IsFusionSetCard, SETCARD_ID_1), true)
  	aux.AddContactFusionProcedure(c, Card.IsAbleToRemoveAsCost, LOCATION_MZONE, 0, Duel.Remove, POS_FACEUP, REASON_COST)
  	--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)
  	c:RegisterEffect(e1)
  	--immune
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCode(EFFECT_IMMUNE_EFFECT)
  	e3:SetCondition(s.immcon)
  	e3:SetValue(s.efilter)
  	c:RegisterEffect(e3)
  	--special summon
  	local e4 = Effect.CreateEffect(c)
  	e4:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e4:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e4:SetType(EFFECT_TYPE_QUICK_O)
  	e4:SetCode(EVENT_FREE_CHAIN)
  	e4:SetHintTiming(0, TIMING_END_PHASE)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCost(s.spcost)
  	e4:SetTarget(s.sptg)
  	e4:SetOperation(s.spop)
  	c:RegisterEffect(e4)
  end
  function s.immcon(e)
  	return Duel.GetAttacker() == e:GetHandler()
  end
  function s.efilter(e, te)
  	return te:GetOwner() ~= e:GetOwner()
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToExtraAsCost()
  	end
  	Duel.SendtoDeck(e:GetHandler(), nil, SEQ_DECKTOP, REASON_COST)
  end
  function s.filter1(c, e, tp)
  	return c:IsFaceup()
  		and c:IsSetCard(SETCARD_ID_1)
  		and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  		and Duel.IsExistingTarget(s.filter2, tp, LOCATION_REMOVED, 0, 1, c, e, tp)
  end
  function s.filter2(c, e, tp)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_1) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) and Duel.GetMZoneCount(tp, e:GetHandler()) > 1 and Duel.IsExistingTarget(s.filter1, tp, LOCATION_REMOVED, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g1 = Duel.SelectTarget(tp, s.filter1, tp, LOCATION_REMOVED, 0, 1, 1, nil, e, tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g2 = Duel.SelectTarget(tp, s.filter2, tp, LOCATION_REMOVED, 0, 1, 1, g1:GetFirst(), e, tp)
  	g1:Merge(g2)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g1, 2, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		ft = 1
  	end
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if g:GetCount() == 0 then
  		return
  	end
  	if g:GetCount() <= ft then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
  	else
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local sg = g:Select(tp, ft, ft, nil)
  		Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
  		g:Sub(sg)
  		Duel.SendtoGrave(g, REASON_RULE)
  	end
  end
  
  