name: Invocation
card_text: Fusion Summon 1 Fusion Monster from your Extra Deck, using monsters from your hand as material. If Summoning an "Invoked" Fusion Monster this way, you can also banish monsters from your field and/or either player's GY as material. If this card is in your GY: You can target 1 of your banished "Aleister the Invoker"; shuffle this card into the Deck, and if you do, add that monster to your hand. You can only use this effect of "Invocation" once per turn.
external_ids: local CARD_ID_0 = 86120751 --Aleister the Invoker
  local SETCARD_ID_0 = 0xf4 --Invoked
  
lua: local CARD_ID_0 = 86120751 --Aleister the Invoker
  local SETCARD_ID_0 = 0xf4 --Invoked
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = FusionSpell.CreateSummonEffect(c, {
  		pre_select_mat_location = s.pre_select_mat_location,
  		pre_select_mat_opponent_location = s.pre_select_mat_opponent_location,
  		mat_operation_code_map = {
  			{ [LOCATION_GRAVE | LOCATION_ONFIELD] = FusionSpell.FUSION_OPERATION_BANISH },
  			{ [0xff] = FusionSpell.FUSION_OPERATION_GRAVE },
  		},
  		extra_target = s.extra_target,
  	})
  	e1:SetDescription(aux.Stringid(id, 0))
  	c:RegisterEffect(e1)
  	--to deck
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TODECK + CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.tdtg)
  	e2:SetOperation(s.tdop)
  	c:RegisterEffect(e2)
  end
  
  function s.pre_select_mat_location(tc, tp)
  	local res = LOCATION_HAND
  	if tc:IsSetCard(SETCARD_ID_0) then
  		res = res | LOCATION_MZONE | LOCATION_GRAVE
  	end
  	return res
  end
  
  function s.pre_select_mat_opponent_location(tc, tp)
  	local res = 0
  	if tc:IsSetCard(SETCARD_ID_0) then
  		res = res | LOCATION_GRAVE
  	end
  	return res
  end
  
  function s.extra_target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, nil, 1, 0, LOCATION_MZONE + LOCATION_GRAVE)
  end
  
  function s.thfilter(c)
  	return c:IsFaceup() and c:IsCode(CARD_ID_0) and c:IsAbleToHand()
  end
  
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_REMOVED) and chkc:IsControler(tp) and s.thfilter(chkc)
  	end
  	if chk == 0 then
  		return e:GetHandler():IsAbleToDeck() and Duel.IsExistingTarget(s.thfilter, tp, LOCATION_REMOVED, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local g = Duel.SelectTarget(tp, s.thfilter, tp, LOCATION_REMOVED, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, e:GetHandler(), 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
  end
  
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and Duel.SendtoDeck(c, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) ~= 0 and tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  
  
source_text: Invocation
  Fusion Summon 1 Fusion Monster from your Extra Deck, using monsters from your hand as material. If Summoning an "Invoked" Fusion Monster this way, you can also banish monsters from your field and/or either player's GY as material. If this card is in your GY: You can target 1 of your banished "Aleister the Invoker"; shuffle this card into the Deck, and if you do, add that monster to your hand. You can only use this effect of "Invocation" once per turn.
target_text: -- Invocation
  local CARD_ID_0 = 86120751 --Aleister the Invoker
  local SETCARD_ID_0 = 0xf4 --Invoked
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = FusionSpell.CreateSummonEffect(c, {
  		pre_select_mat_location = s.pre_select_mat_location,
  		pre_select_mat_opponent_location = s.pre_select_mat_opponent_location,
  		mat_operation_code_map = {
  			{ [LOCATION_GRAVE | LOCATION_ONFIELD] = FusionSpell.FUSION_OPERATION_BANISH },
  			{ [0xff] = FusionSpell.FUSION_OPERATION_GRAVE },
  		},
  		extra_target = s.extra_target,
  	})
  	e1:SetDescription(aux.Stringid(id, 0))
  	c:RegisterEffect(e1)
  	--to deck
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TODECK + CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.tdtg)
  	e2:SetOperation(s.tdop)
  	c:RegisterEffect(e2)
  end
  
  function s.pre_select_mat_location(tc, tp)
  	local res = LOCATION_HAND
  	if tc:IsSetCard(SETCARD_ID_0) then
  		res = res | LOCATION_MZONE | LOCATION_GRAVE
  	end
  	return res
  end
  
  function s.pre_select_mat_opponent_location(tc, tp)
  	local res = 0
  	if tc:IsSetCard(SETCARD_ID_0) then
  		res = res | LOCATION_GRAVE
  	end
  	return res
  end
  
  function s.extra_target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, nil, 1, 0, LOCATION_MZONE + LOCATION_GRAVE)
  end
  
  function s.thfilter(c)
  	return c:IsFaceup() and c:IsCode(CARD_ID_0) and c:IsAbleToHand()
  end
  
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_REMOVED) and chkc:IsControler(tp) and s.thfilter(chkc)
  	end
  	if chk == 0 then
  		return e:GetHandler():IsAbleToDeck() and Duel.IsExistingTarget(s.thfilter, tp, LOCATION_REMOVED, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local g = Duel.SelectTarget(tp, s.thfilter, tp, LOCATION_REMOVED, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, e:GetHandler(), 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
  end
  
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and Duel.SendtoDeck(c, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) ~= 0 and tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  
  