name: Impcantation
card_text: This card can be used to Ritual Summon any Ritual Monster. You must also Tribute "Impcantation" monsters from your hand or field whose total Levels equal or exceed the Level of the Ritual Monster you Ritual Summon. If this card is in your GY: You can send 1 "Impcantation" card from your hand or face-up field to the GY, except "Impcantation Inception"; Special Summon 1 "Impcantation" monster from your Deck, then add this card from the GY to your hand. You can only use this effect of "Impcantation Inception" once per turn.
external_ids: local SETCARD_ID_0 = 0x117 --Impcantation
  
lua: local SETCARD_ID_0 = 0x117 --Impcantation
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = aux.AddRitualProcGreater2(c, nil, nil, nil, s.mfilter, true)
  	e1:SetDescription(aux.Stringid(id, 0))
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id)
  	e2:SetCost(s.thcost)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  end
  function s.mfilter(c)
  	return c:IsSetCard(SETCARD_ID_0)
  end
  function s.cfilter(c, tp)
  	return (c:IsFaceup() or c:IsLocation(LOCATION_HAND)) and c:IsSetCard(SETCARD_ID_0) and not c:IsCode(id) and Duel.GetMZoneCount(tp, c) > 0 and c:IsAbleToGraveAsCost()
  end
  function s.thcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_HAND + LOCATION_ONFIELD, 0, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_HAND + LOCATION_ONFIELD, 0, 1, 1, nil, tp)
  	Duel.SendtoGrave(g, REASON_COST)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsAbleToHand() and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, c, 1, 0, 0)
  end
  function s.thop(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_DECK, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 and Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP) > 0 then
  		local c = e:GetHandler()
  		if c:IsRelateToEffect(e) then
  			Duel.BreakEffect()
  			Duel.SendtoHand(c, nil, REASON_EFFECT)
  		end
  	end
  end
  
  
source_text: Impcantation
  This card can be used to Ritual Summon any Ritual Monster. You must also Tribute "Impcantation" monsters from your hand or field whose total Levels equal or exceed the Level of the Ritual Monster you Ritual Summon. If this card is in your GY: You can send 1 "Impcantation" card from your hand or face-up field to the GY, except "Impcantation Inception"; Special Summon 1 "Impcantation" monster from your Deck, then add this card from the GY to your hand. You can only use this effect of "Impcantation Inception" once per turn.
target_text: -- Impcantation
  local SETCARD_ID_0 = 0x117 --Impcantation
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = aux.AddRitualProcGreater2(c, nil, nil, nil, s.mfilter, true)
  	e1:SetDescription(aux.Stringid(id, 0))
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id)
  	e2:SetCost(s.thcost)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  end
  function s.mfilter(c)
  	return c:IsSetCard(SETCARD_ID_0)
  end
  function s.cfilter(c, tp)
  	return (c:IsFaceup() or c:IsLocation(LOCATION_HAND)) and c:IsSetCard(SETCARD_ID_0) and not c:IsCode(id) and Duel.GetMZoneCount(tp, c) > 0 and c:IsAbleToGraveAsCost()
  end
  function s.thcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_HAND + LOCATION_ONFIELD, 0, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_HAND + LOCATION_ONFIELD, 0, 1, 1, nil, tp)
  	Duel.SendtoGrave(g, REASON_COST)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsAbleToHand() and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, c, 1, 0, 0)
  end
  function s.thop(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_DECK, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 and Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP) > 0 then
  		local c = e:GetHandler()
  		if c:IsRelateToEffect(e) then
  			Duel.BreakEffect()
  			Duel.SendtoHand(c, nil, REASON_EFFECT)
  		end
  	end
  end
  
  