name: Incredible
card_text: If your opponent controls more monsters than you do, you can Special Summon this card (from your hand). You can only Special Summon "Incredible Ecclesia, the Virtuous" once per turn this way. You can only use each of the following effects of "Incredible Ecclesia, the Virtuous" once per turn. During the Main Phase (Quick Effect): You can Tribute this card; Special Summon 1 "Swordsoul" monster or 1 "Fallen of Albaz" from your hand or Deck. During the End Phase, if a Fusion Monster(s) was sent to your GY this turn: Add this card from the GY to your hand.
external_ids: local CARD_ID_0 = 55273561 --Incredible Ecclesia, the Virtuous
  local CARD_ID_2 = 68468459 --Fallen of Albaz
  local SETCARD_ID_0 = 0x16b --Swordsoul
  
lua: local CARD_ID_0 = 55273561 --Incredible Ecclesia, the Virtuous
  local CARD_ID_2 = 68468459 --Fallen of Albaz
  local SETCARD_ID_0 = 0x16b --Swordsoul
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_2)
  	--special summon self
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_SPSUMMON_PROC)
  	e1:SetProperty(EFFECT_FLAG_UNCOPYABLE)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.sspcon)
  	c:RegisterEffect(e1)
  	--special summon other monsters
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_MAIN_END)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.spcon)
  	e2:SetCost(s.spcost)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--grave to hand
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_TOHAND)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_PHASE + PHASE_END)
  	e3:SetCountLimit(1, id + 2)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCondition(s.thcon)
  	e3:SetTarget(s.thtg)
  	e3:SetOperation(s.thop)
  	c:RegisterEffect(e3)
  	if not s.global_check then
  		s.global_check = true
  		local ge1 = Effect.CreateEffect(c)
  		ge1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge1:SetCode(EVENT_TO_GRAVE)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  	end
  end
  function s.sspcon(e, c)
  	if c == nil then
  		return true
  	end
  	return Duel.GetLocationCount(c:GetControler(), LOCATION_MZONE) > 0 and Duel.GetFieldGroupCount(c:GetControler(), LOCATION_MZONE, 0) < Duel.GetFieldGroupCount(c:GetControler(), 0, LOCATION_MZONE)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCurrentPhase() == PHASE_MAIN1 or Duel.GetCurrentPhase() == PHASE_MAIN2
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsReleasable()
  	end
  	Duel.Release(e:GetHandler(), REASON_COST)
  end
  function s.spfilter(c, e, tp)
  	return (c:IsSetCard(SETCARD_ID_0) or c:IsCode(CARD_ID_2)) and c:IsType(TYPE_MONSTER) 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.GetMZoneCount(tp, e:GetHandler()) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.checkfilter(c, tp)
  	return c:IsType(TYPE_FUSION) and c:IsControler(tp)
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	if eg:IsExists(s.checkfilter, 1, nil, 0) then
  		Duel.RegisterFlagEffect(0, id, RESET_PHASE + PHASE_END, 0, 1)
  	end
  	if eg:IsExists(s.checkfilter, 1, nil, 1) then
  		Duel.RegisterFlagEffect(1, id, RESET_PHASE + PHASE_END, 0, 1)
  	end
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetFlagEffect(tp, id) ~= 0
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToHand()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, e:GetHandler(), 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SendtoHand(c, nil, REASON_EFFECT)
  	end
  end
  
  
source_text: Incredible
  If your opponent controls more monsters than you do, you can Special Summon this card (from your hand). You can only Special Summon "Incredible Ecclesia, the Virtuous" once per turn this way. You can only use each of the following effects of "Incredible Ecclesia, the Virtuous" once per turn. During the Main Phase (Quick Effect): You can Tribute this card; Special Summon 1 "Swordsoul" monster or 1 "Fallen of Albaz" from your hand or Deck. During the End Phase, if a Fusion Monster(s) was sent to your GY this turn: Add this card from the GY to your hand.
target_text: -- Incredible
  local CARD_ID_0 = 55273561 --Incredible Ecclesia, the Virtuous
  local CARD_ID_2 = 68468459 --Fallen of Albaz
  local SETCARD_ID_0 = 0x16b --Swordsoul
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_2)
  	--special summon self
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_SPSUMMON_PROC)
  	e1:SetProperty(EFFECT_FLAG_UNCOPYABLE)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.sspcon)
  	c:RegisterEffect(e1)
  	--special summon other monsters
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_MAIN_END)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.spcon)
  	e2:SetCost(s.spcost)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--grave to hand
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_TOHAND)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_PHASE + PHASE_END)
  	e3:SetCountLimit(1, id + 2)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCondition(s.thcon)
  	e3:SetTarget(s.thtg)
  	e3:SetOperation(s.thop)
  	c:RegisterEffect(e3)
  	if not s.global_check then
  		s.global_check = true
  		local ge1 = Effect.CreateEffect(c)
  		ge1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge1:SetCode(EVENT_TO_GRAVE)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  	end
  end
  function s.sspcon(e, c)
  	if c == nil then
  		return true
  	end
  	return Duel.GetLocationCount(c:GetControler(), LOCATION_MZONE) > 0 and Duel.GetFieldGroupCount(c:GetControler(), LOCATION_MZONE, 0) < Duel.GetFieldGroupCount(c:GetControler(), 0, LOCATION_MZONE)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCurrentPhase() == PHASE_MAIN1 or Duel.GetCurrentPhase() == PHASE_MAIN2
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsReleasable()
  	end
  	Duel.Release(e:GetHandler(), REASON_COST)
  end
  function s.spfilter(c, e, tp)
  	return (c:IsSetCard(SETCARD_ID_0) or c:IsCode(CARD_ID_2)) and c:IsType(TYPE_MONSTER) 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.GetMZoneCount(tp, e:GetHandler()) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.checkfilter(c, tp)
  	return c:IsType(TYPE_FUSION) and c:IsControler(tp)
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	if eg:IsExists(s.checkfilter, 1, nil, 0) then
  		Duel.RegisterFlagEffect(0, id, RESET_PHASE + PHASE_END, 0, 1)
  	end
  	if eg:IsExists(s.checkfilter, 1, nil, 1) then
  		Duel.RegisterFlagEffect(1, id, RESET_PHASE + PHASE_END, 0, 1)
  	end
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetFlagEffect(tp, id) ~= 0
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToHand()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, e:GetHandler(), 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SendtoHand(c, nil, REASON_EFFECT)
  	end
  end
  
  