--Miracle Matter --Scripted by Zerry function c19251410.initial_effect(c) --Add MSF local e1=Effect.CreateEffect(c) e1:SetDescription(aux.Stringid(29596581,0)) e1:SetCategory(CATEGORY_TOHAND) e1:SetType(EFFECT_TYPE_IGNITION) e1:SetRange(LOCATION_HAND) e1:SetCountLimit(1,19251410) e1:SetCost(c19251410.cost) e1:SetTarget(c19251410.target) e1:SetOperation(c19251410.operation) c:RegisterEffect(e1) --Fusion local e2=Effect.CreateEffect(c) e2:SetCategory(CATEGORY_REMOVE+CATEGORY_SPECIAL_SUMMON+CATEGORY_FUSION_SUMMON) e2:SetType(EFFECT_TYPE_QUICK_O) e2:SetCode(EVENT_FREE_CHAIN) e2:SetRange(LOCATION_GRAVE) e2:SetCountLimit(1,19251510) e2:SetCondition(c19251410.condition) e2:SetCost(c19251410.fcost) e2:SetTarget(c19251410.ftg) e2:SetOperation(c19251410.fop) c:RegisterEffect(e2) end function c19251410.cost(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return e:GetHandler():IsDiscardable() end Duel.SendtoGrave(e:GetHandler(),REASON_COST+REASON_DISCARD) end function c19251410.filter(c) return c:IsCode(36484016) and c:IsAbleToHand() end function c19251410.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chk==0 then return Duel.IsExistingMatchingCard(c19251410.filter,tp,LOCATION_GRAVE+LOCATION_DECK,0,1,nil) end Duel.SetOperationInfo(0,CATEGORY_TOHAND,nil,1,tp,LOCATION_GRAVE+LOCATION_DECK) end function c19251410.operation(e,tp,eg,ep,ev,re,r,rp,chk) Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND) local g=Duel.SelectMatchingCard(tp,aux.NecroValleyFilter(c19251410.filter),tp,LOCATION_GRAVE+LOCATION_DECK,0,1,1,nil) if g:GetCount()>0 then Duel.SendtoHand(g,nil,REASON_EFFECT) Duel.ConfirmCards(1-tp,g) end end function c19251410.condition(e,tp,eg,ep,ev,re,r,rp) return Duel.GetTurnPlayer()~=tp end function c19251410.cfilter(c) return c:IsCode(36484016) and c:IsAbleToGraveAsCost() end function c19251410.fcost(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return e:GetHandler():IsAbleToRemoveAsCost() and Duel.IsExistingMatchingCard(c19251410.cfilter,tp,LOCATION_HAND,0,1,e:GetHandler()) end Duel.Remove(e:GetHandler(),POS_FACEUP,REASON_COST) Duel.DiscardHand(tp,c19251410.cfilter,1,1,REASON_COST,e:GetHandler()) end function c19251410.filter0(c) return c:IsOnField() and c:IsAbleToRemove() end function c19251410.filter1(c,e) return c:IsOnField() and c:IsAbleToRemove() and not c:IsImmuneToEffect(e) end function c19251410.filter2(c,e,tp,m,f,chkf) if not (c:IsType(TYPE_FUSION) and c:IsRace(RACE_PSYCHO) and aux.IsMaterialListType(c,TYPE_SYNCHRO) and (not f or f(c)) and c:IsCanBeSpecialSummoned(e,SUMMON_TYPE_FUSION,tp,false,false)) then return false end aux.FCheckAdditional=c.synchro_fusion_check or c19251410.fcheck local res=c:CheckFusionMaterial(m,nil,chkf) aux.FCheckAdditional=nil return res end function c19251410.filter4(c) return c:IsType(TYPE_MONSTER) and c:IsCanBeFusionMaterial() and c:IsAbleToRemove() end function c19251410.fcheck(tp,sg,fc) return sg:IsExists(Card.IsFusionType,1,nil,TYPE_SYNCHRO) end function c19251410.ftg(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then local chkf=tp local mg1=Duel.GetFusionMaterial(tp):Filter(c19251410.filter0,nil) local mg2=Duel.GetMatchingGroup(c19251410.filter4,tp,LOCATION_GRAVE,0,nil) mg1:Merge(mg2) local res=Duel.IsExistingMatchingCard(c19251410.filter2,tp,LOCATION_EXTRA,0,1,nil,e,tp,mg1,nil,chkf) if not res then local ce=Duel.GetChainMaterial(tp) if ce~=nil then local fgroup=ce:GetTarget() local mg3=fgroup(ce,e,tp) local mf=ce:GetValue() res=Duel.IsExistingMatchingCard(c19251410.filter2,tp,LOCATION_EXTRA,0,1,nil,e,tp,mg3,mf,chkf) end end return res end Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_EXTRA) Duel.SetOperationInfo(0,CATEGORY_REMOVE,nil,1,tp,LOCATION_ONFIELD+LOCATION_GRAVE) end function c19251410.fop(e,tp,eg,ep,ev,re,r,rp) local chkf=tp local mg1=Duel.GetFusionMaterial(tp):Filter(c19251410.filter1,nil,e) local mg2=Duel.GetMatchingGroup(c19251410.filter4,tp,LOCATION_GRAVE,0,nil) mg1:Merge(mg2) local sg1=Duel.GetMatchingGroup(c19251410.filter2,tp,LOCATION_EXTRA,0,nil,e,tp,mg1,nil,chkf) local mg3=nil local sg2=nil local ce=Duel.GetChainMaterial(tp) if ce~=nil then local fgroup=ce:GetTarget() mg3=fgroup(ce,e,tp) local mf=ce:GetValue() sg2=Duel.GetMatchingGroup(c19251410.filter2,tp,LOCATION_EXTRA,0,nil,e,tp,mg3,mf,chkf) end if sg1:GetCount()>0 or (sg2~=nil and sg2:GetCount()>0) then local sg=sg1:Clone() if sg2 then sg:Merge(sg2) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local tg=sg:Select(tp,1,1,nil) local tc=tg:GetFirst() aux.FCheckAdditional=tc.synchro_fusion_check or c19251410.fcheck if sg1:IsContains(tc) and (sg2==nil or not sg2:IsContains(tc) or not Duel.SelectYesNo(tp,ce:GetDescription())) then local mat1=Duel.SelectFusionMaterial(tp,tc,mg1,nil,chkf) tc:SetMaterial(mat1) Duel.Remove(mat1,POS_FACEUP,REASON_EFFECT+REASON_MATERIAL+REASON_FUSION) Duel.BreakEffect() Duel.SpecialSummon(tc,SUMMON_TYPE_FUSION,tp,tp,false,false,POS_FACEUP) else local mat2=Duel.SelectFusionMaterial(tp,tc,mg3,nil,chkf) local fop=ce:GetOperation() fop(ce,e,tp,tc,mat2) end tc:CompleteProcedure() end aux.FCheckAdditional=nil end