@@ -148,6 +148,7 @@ function Xyz.RecursionChk(c,mg,xyz,tp,min,max,minc,maxc,sg,matg,ct,matct,mustbem
148148 addToMatg = true
149149 end
150150 local xmatct = matct + 1
151+ if (max and xct > max ) or (maxc ~= infToken and xmatct > maxc ) then mg :Merge (rg ) return false end
151152 for i ,f in ipairs ({c :GetCardEffect (EFFECT_XYZ_MAT_RESTRICTION )}) do
152153 if matg :IsExists (Auxiliary .HarmonizingMagFilter ,1 ,c ,f ,f :GetValue ()) then
153154 mg :Merge (rg )
@@ -165,14 +166,13 @@ function Xyz.RecursionChk(c,mg,xyz,tp,min,max,minc,maxc,sg,matg,ct,matct,mustbem
165166 end
166167 end
167168 end
168- if (max and xct > max ) or (maxc ~= infToken and xmatct > maxc ) then mg :Merge (rg ) return false end
169169 if addToMatg then
170170 matg :AddCard (c )
171171 end
172172 sg :AddCard (c )
173173 local eqg = nil
174174 local res = (function ()
175- if (xct >= minc ) and Xyz .CheckMaterialSet (matg ,xyz ,tp ,exchk ,mustg ,lv ) then return true end
175+ if (xct >= min and xmatct >= minc ) and Xyz .CheckMaterialSet (matg ,xyz ,tp ,exchk ,mustg ,lv ) then return true end
176176 if equips_inverse then
177177 eqg = equips_inverse [c ]
178178 if eqg then
@@ -187,7 +187,7 @@ function Xyz.RecursionChk(c,mg,xyz,tp,min,max,minc,maxc,sg,matg,ct,matct,mustbem
187187 local val = te :GetValue ()
188188 if val > 0 and not retchknum [val ] and (not maxc or xmatct + val <= maxc ) and (not tgf or tgf (te ,xyz )) then
189189 retchknum [val ]= true
190- if (xct + val >= minc and Xyz .CheckMaterialSet (matg ,xyz ,tp ,exchk ,mustg ,lv ))
190+ if (xct + val >= min and xmatct + val >= minc and Xyz .CheckMaterialSet (matg ,xyz ,tp ,exchk ,mustg ,lv ))
191191 or mg :IsExists (Xyz .RecursionChk ,1 ,sg ,mg ,xyz ,tp ,min ,max ,minc ,maxc ,sg ,matg ,xct ,xmatct + val ,mustbemat ,exchk ,f ,mustg ,lv ,eqmg ,equips_inverse ) then
192192 return true
193193 end
@@ -364,10 +364,10 @@ function Xyz.Target(f,lv,minc,maxc,mustbemat,exchk)
364364 mg :Merge (equips_inverse [sc ])
365365 end
366366 local multiXyz = {sc :GetCardEffect (EFFECT_DOUBLE_XYZ_MATERIAL )}
367- if # multiXyz > 0 and Xyz .CheckValidMultiXyzMaterial (effs ,c ) and ct < minc then
367+ if # multiXyz > 0 and Xyz .CheckValidMultiXyzMaterial (multiXyz ,c ) and ct < minc then
368368 matg :AddCard (sc )
369369 local multi = {}
370- if mg :IsExists (Xyz .RecursionChk ,1 ,sg ,mg ,c ,tp ,minc ,maxc ,sg ,matg ,ct ,mustbemat ,exchk ,f ,mustg ,lv ) then
370+ if mg :IsExists (Xyz .RecursionChk ,1 ,sg ,mg ,c ,tp ,min , max , minc ,maxc ,sg ,matg ,ct ,matct , mustbemat ,exchk ,f ,mustg ,lv , eqmg , equips_inverse ) then
371371 table.insert (multi ,1 )
372372 end
373373 local eff = {sc :GetCardEffect (EFFECT_DOUBLE_XYZ_MATERIAL )}
@@ -376,22 +376,23 @@ function Xyz.Target(f,lv,minc,maxc,mustbemat,exchk)
376376 local tgf = te :GetOperation ()
377377 local val = te :GetValue ()
378378 if val > 0 and (not tgf or tgf (te ,c )) then
379- if minc <= ct + val and ct + val <= maxc
380- or mg :IsExists (Xyz .RecursionChk ,1 ,sg ,mg ,c ,tp ,minc ,maxc ,sg ,matg ,ct + val ,mustbemat ,exchk ,f ,mustg ,lv ) then
379+ local newCount = matct + 1 + val
380+ if (minc <= newCount and newCount <= maxc )
381+ or mg :IsExists (Xyz .RecursionChk ,1 ,sg ,mg ,c ,tp ,min ,max ,minc ,maxc ,sg ,matg ,ct ,newCount ,mustbemat ,exchk ,f ,mustg ,lv ,eqmg ,equips_inverse ) then
381382 table.insert (multi ,1 + val )
382383 end
383384 end
384385 end
385386 if # multi == 1 then
386387 if multi [1 ]> 1 then
387- extra_mats = extra_mats + multi [1 ]
388+ extra_mats = extra_mats + multi [1 ]- 1
388389 tab [sc ]= multi [1 ]
389390 end
390391 else
391392 Duel .Hint (HINT_SELECTMSG ,tp ,HINTMSG_XMATERIAL )
392393 local num = Duel .AnnounceNumber (tp ,table.unpack (multi ))
393394 if num > 1 then
394- extra_mats = extra_mats + num
395+ extra_mats = extra_mats + num - 1
395396 tab [sc ]= num
396397 end
397398 end
@@ -401,22 +402,27 @@ function Xyz.Target(f,lv,minc,maxc,mustbemat,exchk)
401402 matg :AddCard (sc )
402403 end
403404 else
404- sg :RemoveCard (sc )
405405 if equips_inverse and equips_inverse [sc ] then
406- mg :Sub (equips_inverse [sc ])
407- end
408- if not sc :IsHasEffect (EFFECT_ORICHALCUM_CHAIN ) then
409- matg :RemoveCard (sc )
406+ local equips = equips_inverse [sc ]
407+ if sg :Includes (equips ) then
408+ goto continue
409+ end
410+ mg :Sub (equips )
410411 end
411- local num = tab [sc ]
412- if num then
413- tab [sc ]= nil
414- matct = matct - num
412+ sg :RemoveCard (sc )
413+ if sc :IsHasEffect (EFFECT_ORICHALCUM_CHAIN ) then
414+ extra_mats = extra_mats - 1
415415 else
416- matct = matct - 1
416+ matg :RemoveCard (sc )
417+ local num = tab [sc ]
418+ if num then
419+ tab [sc ]= nil
420+ extra_mats = extra_mats - (num - 1 )
421+ end
417422 end
418423 end
419424 finishable =# matg >= minc and Xyz .CheckMaterialSet (matg ,c ,tp ,exchk ,mustg ,lv )
425+ :: continue::
420426 end
421427 sg :KeepAlive ()
422428 e :SetLabelObject (sg )
@@ -477,7 +483,9 @@ function Xyz.Target2(alterf,op)
477483 oc = mustg :GetFirst ()
478484 else
479485 Duel .Hint (HINT_SELECTMSG ,tp ,HINTMSG_XMATERIAL )
480- oc = mg :FilterSelect (tp ,Xyz .AlterFilter ,1 ,1 ,cancelable ,nil ,alterf ,c ,e ,tp ,op ):GetFirst ()
486+ local ocg = mg :FilterSelect (tp ,Xyz .AlterFilter ,1 ,1 ,cancelable ,nil ,alterf ,c ,e ,tp ,op )
487+ if not ocg then return false end
488+ oc = ocg :GetFirst ()
481489 end
482490 if not oc then return false end
483491 local ok = true
0 commit comments