name: Magical
card_text: When this card is activated: You can add 1 "Aleister the Invoker" from your Deck to your hand. The activation of your cards and effects that include an effect that Fusion Summons a Fusion Monster cannot be negated, also your opponent's cards and effects cannot activate when a monster is Fusion Summoned this way. You can only activate 1 "Magical Meltdown" per turn.
external_ids: local CARD_ID_0 = 86120751 --Aleister the Invoker
  
lua: local CARD_ID_0 = 86120751 --Aleister the Invoker
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--inactivatable
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_CANNOT_INACTIVATE)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetValue(s.efilter)
  	c:RegisterEffect(e2)
  	--act limit
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e3:SetRange(LOCATION_FZONE)
  	e3:SetCondition(s.limcon)
  	e3:SetOperation(s.limop)
  	c:RegisterEffect(e3)
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e5:SetRange(LOCATION_FZONE)
  	e5:SetCode(EVENT_CHAIN_END)
  	e5:SetOperation(s.limop2)
  	c:RegisterEffect(e5)
  end
  function s.thfilter(c)
  	return c:IsCode(CARD_ID_0) and c:IsAbleToHand()
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	if g:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local sg = g:Select(tp, 1, 1, nil)
  		Duel.SendtoHand(sg, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, sg)
  	end
  end
  function s.efilter(e, ct)
  	local p = e:GetHandlerPlayer()
  	local te, tp = Duel.GetChainInfo(ct, CHAININFO_TRIGGERING_EFFECT, CHAININFO_TRIGGERING_PLAYER)
  	return p == tp and te:IsHasCategory(CATEGORY_FUSION_SUMMON)
  end
  function s.limfilter(c, tp)
  	return c:IsSummonPlayer(tp) and c:IsSummonType(SUMMON_TYPE_FUSION) and c:GetSpecialSummonInfo(SUMMON_INFO_REASON_EFFECT):IsHasCategory(CATEGORY_FUSION_SUMMON)
  end
  function s.limcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.limfilter, 1, nil, tp)
  end
  function s.limop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetCurrentChain() == 0 then
  		Duel.SetChainLimitTillChainEnd(s.chainlm)
  	elseif Duel.GetCurrentChain() == 1 then
  		e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1)
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e1:SetCode(EVENT_CHAINING)
  		e1:SetOperation(s.resetop)
  		Duel.RegisterEffect(e1, tp)
  		local e2 = e1:Clone()
  		e2:SetCode(EVENT_BREAK_EFFECT)
  		e2:SetReset(RESET_CHAIN)
  		Duel.RegisterEffect(e2, tp)
  	end
  end
  function s.resetop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():ResetFlagEffect(id)
  	e:Reset()
  end
  function s.limop2(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetHandler():GetFlagEffect(id) ~= 0 then
  		Duel.SetChainLimitTillChainEnd(s.chainlm)
  	end
  	e:GetHandler():ResetFlagEffect(id)
  end
  function s.chainlm(e, rp, tp)
  	return tp == rp
  end
  
  
source_text: Magical
  When this card is activated: You can add 1 "Aleister the Invoker" from your Deck to your hand. The activation of your cards and effects that include an effect that Fusion Summons a Fusion Monster cannot be negated, also your opponent's cards and effects cannot activate when a monster is Fusion Summoned this way. You can only activate 1 "Magical Meltdown" per turn.
target_text: -- Magical
  local CARD_ID_0 = 86120751 --Aleister the Invoker
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--inactivatable
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_CANNOT_INACTIVATE)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetValue(s.efilter)
  	c:RegisterEffect(e2)
  	--act limit
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e3:SetRange(LOCATION_FZONE)
  	e3:SetCondition(s.limcon)
  	e3:SetOperation(s.limop)
  	c:RegisterEffect(e3)
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e5:SetRange(LOCATION_FZONE)
  	e5:SetCode(EVENT_CHAIN_END)
  	e5:SetOperation(s.limop2)
  	c:RegisterEffect(e5)
  end
  function s.thfilter(c)
  	return c:IsCode(CARD_ID_0) and c:IsAbleToHand()
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	if g:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local sg = g:Select(tp, 1, 1, nil)
  		Duel.SendtoHand(sg, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, sg)
  	end
  end
  function s.efilter(e, ct)
  	local p = e:GetHandlerPlayer()
  	local te, tp = Duel.GetChainInfo(ct, CHAININFO_TRIGGERING_EFFECT, CHAININFO_TRIGGERING_PLAYER)
  	return p == tp and te:IsHasCategory(CATEGORY_FUSION_SUMMON)
  end
  function s.limfilter(c, tp)
  	return c:IsSummonPlayer(tp) and c:IsSummonType(SUMMON_TYPE_FUSION) and c:GetSpecialSummonInfo(SUMMON_INFO_REASON_EFFECT):IsHasCategory(CATEGORY_FUSION_SUMMON)
  end
  function s.limcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.limfilter, 1, nil, tp)
  end
  function s.limop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetCurrentChain() == 0 then
  		Duel.SetChainLimitTillChainEnd(s.chainlm)
  	elseif Duel.GetCurrentChain() == 1 then
  		e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1)
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e1:SetCode(EVENT_CHAINING)
  		e1:SetOperation(s.resetop)
  		Duel.RegisterEffect(e1, tp)
  		local e2 = e1:Clone()
  		e2:SetCode(EVENT_BREAK_EFFECT)
  		e2:SetReset(RESET_CHAIN)
  		Duel.RegisterEffect(e2, tp)
  	end
  end
  function s.resetop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():ResetFlagEffect(id)
  	e:Reset()
  end
  function s.limop2(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetHandler():GetFlagEffect(id) ~= 0 then
  		Duel.SetChainLimitTillChainEnd(s.chainlm)
  	end
  	e:GetHandler():ResetFlagEffect(id)
  end
  function s.chainlm(e, rp, tp)
  	return tp == rp
  end
  
  