Skip to content

Commit e316311

Browse files
authored
Add Fusion.SummonEffect and handle new parameter in EFFECT_FUSION_MATERIAL (#1164)
EFFECT_FUSION_MATERIAL now has an extra parameter consisting of the effect that is performing the summon of that specific fusion monster, which is then put in the global variable Fusion.SummonEffect to be used by other scripts
1 parent f4584df commit e316311

File tree

1 file changed

+38
-17
lines changed

1 file changed

+38
-17
lines changed

proc_fusion.lua

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ if not Fusion then
66
Fusion = aux.FusionProcedure
77
end
88

9+
--The current reason effect that corresponds to the effect that is performing the fusion summon
10+
Fusion.SummonEffect=nil
11+
local function returnAndClearSummonEffect(value)
12+
Fusion.SummonEffect=nil
13+
return value
14+
end
15+
916
function Fusion.ParseMaterialTable(tab,mat)
1017
local named_mats={}
1118
local tmp_extramat_func=function(c,fc,sub,sub2,mg,sg,tp,contact,sumtype) return (sub2 and c:IsHasEffect(511002961)) end
@@ -81,14 +88,15 @@ function Fusion.ConditionMix(insf,sub,...)
8188
--gc:Material already used
8289
--chkf: check field, default:PLAYER_NONE
8390
local funs={...}
84-
return function(e,g,gc,chkfnf)
91+
return function(e,g,gc,chkfnf,summonEff)
8592
local mustg=nil
8693
local c=e:GetHandler()
8794
local tp=c:GetControler()
8895
if g==nil then
8996
mustg=Auxiliary.GetMustBeMaterialGroup(tp,g,tp,c,nil,REASON_FUSION)
9097
return insf and #mustg==0
9198
end
99+
Fusion.SummonEffect=summonEff
92100
local chkf=chkfnf&0xff
93101
local notfusion=(chkfnf&FUSPROC_NOTFUSION)~=0
94102
local contact=(chkfnf&FUSPROC_CONTACTFUS)~=0
@@ -104,20 +112,23 @@ function Fusion.ConditionMix(insf,sub,...)
104112
local mg=g:Filter(Fusion.ConditionFilterMix,c,c,sub,sub,contact,sumtype,matcheck,tp,table.unpack(funs))
105113
mustg=Auxiliary.GetMustBeMaterialGroup(tp,g,tp,c,mg,REASON_FUSION)
106114
if contact then mustg:Clear() end
107-
if not mg:Includes(mustg) or mustg:IsExists(aux.NOT(Card.IsCanBeFusionMaterial),1,nil,c,sumtype) then return false end
115+
if not mg:Includes(mustg) or mustg:IsExists(aux.NOT(Card.IsCanBeFusionMaterial),1,nil,c,sumtype) then return returnAndClearSummonEffect(false) end
108116
if gc then
109117
if gc:IsExists(aux.NOT(Card.IsCanBeFusionMaterial),1,nil,c,sumtype)
110-
or gc:IsExists(aux.NOT(Fusion.ConditionFilterMix),1,nil,c,sub,sub,contact,sumtype,matcheck,tp,table.unpack(funs)) then return false end
118+
or gc:IsExists(aux.NOT(Fusion.ConditionFilterMix),1,nil,c,sub,sub,contact,sumtype,matcheck,tp,table.unpack(funs)) then
119+
return returnAndClearSummonEffect(false)
120+
end
111121
mustg:Merge(gc)
112122
end
113123
local sg=Group.CreateGroup()
114124
mg:Merge(mustg)
115-
return mg:IsExists(Fusion.SelectMix,1,nil,tp,mg,sg,mustg,c,sub,sub,contact,sumtype,chkf,table.unpack(funs))
125+
return returnAndClearSummonEffect(mg:IsExists(Fusion.SelectMix,1,nil,tp,mg,sg,mustg,c,sub,sub,contact,sumtype,chkf,table.unpack(funs)))
116126
end
117127
end
118128
function Fusion.OperationMix(insf,sub,...)
119129
local funs={...}
120-
return function(e,tp,eg,ep,ev,re,r,rp,gc,chkfnf)
130+
return function(e,tp,eg,ep,ev,re,r,rp,gc,chkfnf,summonEff)
131+
Fusion.SummonEffect=summonEff
121132
local chkf=chkfnf&0xff
122133
local c=e:GetHandler()
123134
local tp=c:GetControler()
@@ -171,6 +182,7 @@ function Fusion.OperationMix(insf,sub,...)
171182
end
172183
if sfhchk then Duel.ShuffleHand(tp) end
173184
Duel.SetFusionMaterial(sg)
185+
Fusion.SummonEffect=nil
174186
end
175187
end
176188
function Fusion.ConditionFilterMix(c,fc,sub,sub2,contact,sumtype,matcheck,tp,...)
@@ -298,14 +310,15 @@ function Fusion.AddProcMixRep(c,sub,insf,fun1,minc,maxc,...)
298310
end
299311
function Fusion.ConditionMixRep(insf,sub,fun1,minc,maxc,...)
300312
local funs={...}
301-
return function(e,g,gc,chkfnf)
313+
return function(e,g,gc,chkfnf,summonEff)
302314
local mustg=nil
303315
local c=e:GetHandler()
304316
local tp=c:GetControler()
305317
if g==nil then
306318
if not insf then return false end
307319
return #(Auxiliary.GetMustBeMaterialGroup(tp,g,tp,c,nil,REASON_FUSION))==0
308320
end
321+
Fusion.SummonEffect=summonEff
309322
local chkf=chkfnf&0xff
310323
local notfusion=(chkfnf&FUSPROC_NOTFUSION)~=0
311324
local contact=(chkfnf&FUSPROC_CONTACTFUS)~=0
@@ -321,20 +334,23 @@ function Fusion.ConditionMixRep(insf,sub,fun1,minc,maxc,...)
321334
if contact then mustg:Clear() end
322335
local sub=not listedmats and (sub or notfusion) and not contact
323336
local mg=g:Filter(Fusion.ConditionFilterMix,c,c,sub,sub,contact,sumtype,matcheck,tp,fun1,table.unpack(funs))
324-
if not mg:Includes(mustg) or mustg:IsExists(aux.NOT(Card.IsCanBeFusionMaterial),1,nil,c,sumtype) then return false end
337+
if not mg:Includes(mustg) or mustg:IsExists(aux.NOT(Card.IsCanBeFusionMaterial),1,nil,c,sumtype) then return returnAndClearSummonEffect(false) end
325338
if gc then
326339
if gc:IsExists(aux.NOT(Card.IsCanBeFusionMaterial),1,nil,c,sumtype)
327-
or gc:IsExists(aux.NOT(Fusion.ConditionFilterMix),1,nil,c,sub,sub,contact,sumtype,matcheck,tp,fun1,table.unpack(funs))then return false end
340+
or gc:IsExists(aux.NOT(Fusion.ConditionFilterMix),1,nil,c,sub,sub,contact,sumtype,matcheck,tp,fun1,table.unpack(funs)) then
341+
return returnAndClearSummonEffect(false)
342+
end
328343
mustg:Merge(gc)
329344
end
330345
local sg=Group.CreateGroup()
331346
mg:Merge(mustg)
332-
return mg:IsExists(Fusion.SelectMixRep,1,nil,tp,mg,sg,mustg,c,sub,sub,contact,sumtype,chkf,fun1,minc,maxc,table.unpack(funs))
347+
return returnAndClearSummonEffect(mg:IsExists(Fusion.SelectMixRep,1,nil,tp,mg,sg,mustg,c,sub,sub,contact,sumtype,chkf,fun1,minc,maxc,table.unpack(funs)))
333348
end
334349
end
335350
function Fusion.OperationMixRep(insf,sub,fun1,minc,maxc,...)
336351
local funs={...}
337-
return function(e,tp,eg,ep,ev,re,r,rp,gc,chkfnf)
352+
return function(e,tp,eg,ep,ev,re,r,rp,gc,chkfnf,summonEff)
353+
Fusion.SummonEffect=summonEff
338354
local chkf=chkfnf&0xff
339355
local c=e:GetHandler()
340356
local tp=c:GetControler()
@@ -354,7 +370,7 @@ function Fusion.OperationMixRep(insf,sub,fun1,minc,maxc,...)
354370
local mg=eg:Filter(Fusion.ConditionFilterMix,c,c,sub,sub,contact,sumtype,matcheck,tp,fun1,table.unpack(funs))
355371
local mustg=Auxiliary.GetMustBeMaterialGroup(tp,eg,tp,c,mg,REASON_FUSION)
356372
if contact then mustg:Clear() end
357-
if not mg:Includes(mustg) or mustg:IsExists(aux.NOT(Card.IsCanBeFusionMaterial),1,nil,c,sumtype) then return false end
373+
if not mg:Includes(mustg) or mustg:IsExists(aux.NOT(Card.IsCanBeFusionMaterial),1,nil,c,sumtype) then return returnAndClearSummonEffect(false) end
358374
if gc then
359375
mustg:Merge(gc)
360376
end
@@ -384,6 +400,7 @@ function Fusion.OperationMixRep(insf,sub,fun1,minc,maxc,...)
384400
end
385401
if sfhchk then Duel.ShuffleHand(tp) end
386402
Duel.SetFusionMaterial(sg)
403+
Fusion.SummonEffect=nil
387404
end
388405
end
389406
function Fusion.CheckMixRep(sg,g,fc,sub,sub2,contact,sumtype,chkf,tp,fun1,minc,maxc,fun2,...)
@@ -587,11 +604,13 @@ function Fusion.ConditionMixRepUnfix(insf,sub,minc,maxc,...)
587604
--gc:Material already used
588605
--chkf: check field, default:PLAYER_NONE
589606
local funs={...}
590-
return function(e,g,gc,chkfnf)
607+
return function(e,g,gc,chkfnf,summonEff)
591608
local mustg=nil
592609
if g==nil then
593610
mustg=Auxiliary.GetMustBeMaterialGroup(tp,g,tp,c,nil,REASON_FUSION)
594-
return insf and #mustg==0 end
611+
return insf and #mustg==0
612+
end
613+
Fusion.SummonEffect=summonEff
595614
local chkf=chkfnf&0xff
596615
local c=e:GetHandler()
597616
local tp=c:GetControler()
@@ -609,19 +628,20 @@ function Fusion.ConditionMixRepUnfix(insf,sub,minc,maxc,...)
609628
local mg=g:Filter(Fusion.ConditionFilterMixRepUnfix,c,c,sub,sub,contact,sumtype,tp,table.unpack(funs))
610629
mustg=Auxiliary.GetMustBeMaterialGroup(tp,g,tp,c,mg,REASON_FUSION)
611630
if contact then mustg:Clear() end
612-
if not mg:Includes(mustg) or mustg:IsExists(aux.NOT(Card.IsCanBeFusionMaterial),1,nil,c,sumtype) then return false end
631+
if not mg:Includes(mustg) or mustg:IsExists(aux.NOT(Card.IsCanBeFusionMaterial),1,nil,c,sumtype) then return returnAndClearSummonEffect(false) end
613632
if gc then
614-
if gc:IsExists(aux.NOT(Card.IsCanBeFusionMaterial),1,nil,c,sumtype) then return false end
633+
if gc:IsExists(aux.NOT(Card.IsCanBeFusionMaterial),1,nil,c,sumtype) then return returnAndClearSummonEffect(false) end
615634
mustg:Merge(gc)
616635
end
617636
local sg=Group.CreateGroup()
618637
mg:Merge(mustg)
619-
return mg:IsExists(Fusion.SelectMixRepUnfix,1,nil,tp,mg,sg,mustg,c,sub,sub,minc,maxc,chkf,table.unpack(funs))
638+
return returnAndClearSummonEffect(mg:IsExists(Fusion.SelectMixRepUnfix,1,nil,tp,mg,sg,mustg,c,sub,sub,minc,maxc,chkf,table.unpack(funs)))
620639
end
621640
end
622641
function Fusion.OperationMixRepUnfix(insf,sub,minc,maxc,...)
623642
local funs={...}
624-
return function(e,tp,eg,ep,ev,re,r,rp,gc,chkfnf)
643+
return function(e,tp,eg,ep,ev,re,r,rp,gc,chkfnf,summonEff)
644+
Fusion.SummonEffect=summonEff
625645
local chkf=chkfnf&0xff
626646
local c=e:GetHandler()
627647
local tp=c:GetControler()
@@ -679,6 +699,7 @@ function Fusion.OperationMixRepUnfix(insf,sub,minc,maxc,...)
679699
end
680700
if sfhchk then Duel.ShuffleHand(tp) end
681701
Duel.SetFusionMaterial(sg)
702+
Fusion.SummonEffect=nil
682703
end
683704
end
684705
function Fusion.ConditionFilterMixRepUnfix(c,fc,sub,sub,contact,sumtype,tp,...)

0 commit comments

Comments
 (0)