name: Crealtar,
card_text: You can Ritual Summon this card with "Impcantation Inception". During the Main Phase (Quick Effect): You can reveal this card in your hand; discard 1 card, then Special Summon "Impcantation" monsters from your GY whose total Levels equal 10, but shuffle them into the Deck during the End Phase. You can only use this effect of "Crealtar, the Impcantation Originator" once per turn. Non-Ritual "Impcantation" monsters you control gain 2000 ATK, but their effects are negated.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x117 --Impcantation
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x117 --Impcantation
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_HANDES + CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetHintTiming(0, TIMING_MAIN_END)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.spcon)
  	e1:SetCost(s.spcost)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--disable
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(s.atktg)
  	e2:SetCode(EFFECT_DISABLE)
  	c:RegisterEffect(e2)
  	--attack
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_UPDATE_ATTACK)
  	e3:SetValue(2000)
  	c:RegisterEffect(e3)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local ph = Duel.GetCurrentPhase()
  	return ph == PHASE_MAIN1 or ph == PHASE_MAIN2
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return not e:GetHandler():IsPublic()
  	end
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.spcheck(g)
  	return g:GetSum(Card.GetLevel) == 10
  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 ft <= 0 or Duel.GetFieldGroupCount(tp, LOCATION_HAND, 0) < 1 then
  			return false
  		end
  		if ft > 1 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  			ft = 1
  		end
  		local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_GRAVE, 0, nil, e, tp)
  		return g:CheckSubGroup(s.spcheck, 1, ft)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.DiscardHand(tp, nil, 1, 1, REASON_EFFECT + REASON_DISCARD) > 0 then
  		local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  		if ft <= 0 then
  			return
  		end
  		if ft > 1 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  			ft = 1
  		end
  		local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_GRAVE, 0, nil, e, tp)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local sg = g:SelectSubGroup(tp, s.spcheck, false, 1, ft)
  		if sg then
  			local c = e:GetHandler()
  			local fid = c:GetFieldID()
  			local tc = sg:GetFirst()
  			while tc do
  				Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP)
  				tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1, fid)
  				tc = sg:GetNext()
  			end
  			Duel.SpecialSummonComplete()
  			sg:KeepAlive()
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  			e1:SetCode(EVENT_PHASE + PHASE_END)
  			e1:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  			e1:SetCountLimit(1)
  			e1:SetLabel(fid)
  			e1:SetLabelObject(sg)
  			e1:SetCondition(s.retcon)
  			e1:SetOperation(s.retop)
  			Duel.RegisterEffect(e1, tp)
  		end
  	end
  end
  function s.retfilter(c, fid)
  	return c:GetFlagEffectLabel(id) == fid
  end
  function s.retcon(e, tp, eg, ep, ev, re, r, rp)
  	local g = e:GetLabelObject()
  	if not g:IsExists(s.retfilter, 1, nil, e:GetLabel()) then
  		g:DeleteGroup()
  		e:Reset()
  		return false
  	else
  		return true
  	end
  end
  function s.retop(e, tp, eg, ep, ev, re, r, rp)
  	local g = e:GetLabelObject()
  	local tg = g:Filter(s.retfilter, nil, e:GetLabel())
  	Duel.SendtoDeck(tg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  end
  function s.atktg(e, c)
  	return c:IsSetCard(SETCARD_ID_0) and not c:IsType(TYPE_RITUAL)
  end
  
  
source_text: Crealtar,
  You can Ritual Summon this card with "Impcantation Inception". During the Main Phase (Quick Effect): You can reveal this card in your hand; discard 1 card, then Special Summon "Impcantation" monsters from your GY whose total Levels equal 10, but shuffle them into the Deck during the End Phase. You can only use this effect of "Crealtar, the Impcantation Originator" once per turn. Non-Ritual "Impcantation" monsters you control gain 2000 ATK, but their effects are negated.
target_text: -- Crealtar,
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x117 --Impcantation
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_HANDES + CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetHintTiming(0, TIMING_MAIN_END)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.spcon)
  	e1:SetCost(s.spcost)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--disable
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(s.atktg)
  	e2:SetCode(EFFECT_DISABLE)
  	c:RegisterEffect(e2)
  	--attack
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_UPDATE_ATTACK)
  	e3:SetValue(2000)
  	c:RegisterEffect(e3)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local ph = Duel.GetCurrentPhase()
  	return ph == PHASE_MAIN1 or ph == PHASE_MAIN2
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return not e:GetHandler():IsPublic()
  	end
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.spcheck(g)
  	return g:GetSum(Card.GetLevel) == 10
  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 ft <= 0 or Duel.GetFieldGroupCount(tp, LOCATION_HAND, 0) < 1 then
  			return false
  		end
  		if ft > 1 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  			ft = 1
  		end
  		local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_GRAVE, 0, nil, e, tp)
  		return g:CheckSubGroup(s.spcheck, 1, ft)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.DiscardHand(tp, nil, 1, 1, REASON_EFFECT + REASON_DISCARD) > 0 then
  		local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  		if ft <= 0 then
  			return
  		end
  		if ft > 1 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  			ft = 1
  		end
  		local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_GRAVE, 0, nil, e, tp)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local sg = g:SelectSubGroup(tp, s.spcheck, false, 1, ft)
  		if sg then
  			local c = e:GetHandler()
  			local fid = c:GetFieldID()
  			local tc = sg:GetFirst()
  			while tc do
  				Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP)
  				tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1, fid)
  				tc = sg:GetNext()
  			end
  			Duel.SpecialSummonComplete()
  			sg:KeepAlive()
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  			e1:SetCode(EVENT_PHASE + PHASE_END)
  			e1:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  			e1:SetCountLimit(1)
  			e1:SetLabel(fid)
  			e1:SetLabelObject(sg)
  			e1:SetCondition(s.retcon)
  			e1:SetOperation(s.retop)
  			Duel.RegisterEffect(e1, tp)
  		end
  	end
  end
  function s.retfilter(c, fid)
  	return c:GetFlagEffectLabel(id) == fid
  end
  function s.retcon(e, tp, eg, ep, ev, re, r, rp)
  	local g = e:GetLabelObject()
  	if not g:IsExists(s.retfilter, 1, nil, e:GetLabel()) then
  		g:DeleteGroup()
  		e:Reset()
  		return false
  	else
  		return true
  	end
  end
  function s.retop(e, tp, eg, ep, ev, re, r, rp)
  	local g = e:GetLabelObject()
  	local tg = g:Filter(s.retfilter, nil, e:GetLabel())
  	Duel.SendtoDeck(tg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  end
  function s.atktg(e, c)
  	return c:IsSetCard(SETCARD_ID_0) and not c:IsType(TYPE_RITUAL)
  end
  
  