Skip to content

Commit c56eece

Browse files
committed
Xyz proc: Add count limit support to EFFECT_DOUBLE_XYZ_MATERIAL
Also reapply 27b135c
1 parent 2f1b833 commit c56eece

File tree

3 files changed

+50
-78
lines changed

3 files changed

+50
-78
lines changed

official/c81096431.lua

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
--ドレイク・シャーク
22
--Drake Shark
33
--scripted by Naim
4-
local EFFECT_DOUBLE_XYZ_MATERIAL=511001225 --to be removed when the procedure is updated
54
local s,id=GetID()
65
function s.initial_effect(c)
76
--Special Summon this card if it is added to the hand, except by drawing it
@@ -21,8 +20,8 @@ function s.initial_effect(c)
2120
e2:SetType(EFFECT_TYPE_SINGLE)
2221
e2:SetCode(EFFECT_DOUBLE_XYZ_MATERIAL)
2322
e2:SetValue(1)
24-
e2:SetCondition(function(e) return not Duel.HasFlagEffect(e:GetHandlerPlayer(),id) end)
25-
e2:SetOperation(function(e,c,matg) return c:IsAttribute(ATTRIBUTE_WATER) and c.minxyzct and c.minxyzct>=3 and matg:FilterCount(s.drakesharkhoptfilter,nil)<2 end)
23+
e2:SetCountLimit(1,{id,1})
24+
e2:SetOperation(function(e,c) return c.minxyzct and c.minxyzct>=3 and c:IsAttribute(ATTRIBUTE_WATER) end)
2625
c:RegisterEffect(e2)
2726
--Provide an effect to a "Shark Drake" Xyz Monster that this card as Xyz material
2827
local e3=Effect.CreateEffect(c)
@@ -35,27 +34,8 @@ function s.initial_effect(c)
3534
e3:SetTarget(s.attachtg)
3635
e3:SetOperation(s.attachop)
3736
c:RegisterEffect(e3)
38-
--HOPT workaround for having already used the double material effect earlier in that turn
39-
aux.GlobalCheck(s,function()
40-
local ge1=Effect.CreateEffect(c)
41-
ge1:SetType(EFFECT_TYPE_FIELD)
42-
ge1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_SET_AVAILABLE+EFFECT_FLAG_IGNORE_RANGE)
43-
ge1:SetCode(EFFECT_MATERIAL_CHECK)
44-
ge1:SetValue(s.valcheck)
45-
Duel.RegisterEffect(ge1,0)
46-
end)
4737
end
4838
s.listed_series={SET_SHARK_DRAKE}
49-
function s.drakesharkhoptfilter(c)
50-
return c:IsCode(id) and c:IsHasEffect(EFFECT_DOUBLE_XYZ_MATERIAL)
51-
end
52-
function s.valcheck(e,c)
53-
if not (c:IsType(TYPE_XYZ) and c:IsAttribute(ATTRIBUTE_WATER) and c.minxyzct and c.minxyzct>=3) then return end
54-
local g=c:GetMaterial()
55-
if #g<c.minxyzct and g:IsExists(s.drakesharkhoptfilter,1,nil) then
56-
Duel.RegisterFlagEffect(c:GetControler(),id,RESET_PHASE|PHASE_END,0,1)
57-
end
58-
end
5939
function s.sptg(e,tp,eg,ep,ev,re,r,rp,chk)
6040
local c=e:GetHandler()
6141
if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0
@@ -84,4 +64,4 @@ function s.attachop(e,tp,eg,ep,ev,re,r,rp)
8464
if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) and c:IsType(TYPE_XYZ) then
8565
Duel.Overlay(c,tc)
8666
end
87-
end
67+
end

pre-release/c101208009.lua

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
--紋章獣グリフォン
22
--Heraldic Beast Gryphon
33
--scripted by Naim
4-
local EFFECT_DOUBLE_XYZ_MATERIAL=511001225 --to be removed when the procedure is updated
54
local s,id=GetID()
65
function s.initial_effect(c)
76
--Special Summon this card from your hand
@@ -20,18 +19,9 @@ function s.initial_effect(c)
2019
e2:SetType(EFFECT_TYPE_SINGLE)
2120
e2:SetCode(EFFECT_DOUBLE_XYZ_MATERIAL)
2221
e2:SetValue(1)
23-
e2:SetCondition(function(e) return not Duel.HasFlagEffect(e:GetHandlerPlayer(),id) end)
24-
e2:SetOperation(function(e,c,matg) return c:IsSetCard(SET_NUMBER) and c.minxyzct and c.minxyzct>=3 and matg:FilterCount(s.gryphonhoptfilter,nil)<2 end)
22+
e2:SetCountLimit(1,{id,1})
23+
e2:SetOperation(function(e,c) return c.minxyzct and c.minxyzct>=3 and c:IsSetCard(SET_NUMBER) end)
2524
c:RegisterEffect(e2)
26-
--HOPT workaround for having already used the double material effect earlier in that turn
27-
aux.GlobalCheck(s,function()
28-
local ge1=Effect.CreateEffect(c)
29-
ge1:SetType(EFFECT_TYPE_FIELD)
30-
ge1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_SET_AVAILABLE+EFFECT_FLAG_IGNORE_RANGE)
31-
ge1:SetCode(EFFECT_MATERIAL_CHECK)
32-
ge1:SetValue(s.valcheck)
33-
Duel.RegisterEffect(ge1,0)
34-
end)
3525
end
3626
s.listed_series={SET_HERALDIC_BEAST}
3727
s.listed_names={id}
@@ -76,13 +66,3 @@ function s.spop(e,tp,eg,ep,ev,re,r,rp)
7666
e2:SetReset(RESET_PHASE|PHASE_END)
7767
Duel.RegisterEffect(e2,tp)
7868
end
79-
function s.gryphonhoptfilter(c)
80-
return c:IsCode(id) and c:IsHasEffect(EFFECT_DOUBLE_XYZ_MATERIAL)
81-
end
82-
function s.valcheck(e,c)
83-
if not (c:IsType(TYPE_XYZ) and c:IsSetCard(SET_NUMBER) and c.minxyzct and c.minxyzct>=3) then return end
84-
local g=c:GetMaterial()
85-
if #g<c.minxyzct and g:IsExists(s.gryphonhoptfilter,1,nil) then
86-
Duel.RegisterFlagEffect(c:GetControler(),id,RESET_PHASE|PHASE_END,0,1)
87-
end
88-
end

proc_xyz.lua

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ function Xyz.SubMatFilter(c,lv,xyz,tp)
110110
end
111111
return true
112112
end
113-
function Xyz.CheckValidMultiXyzMaterial(effs,xyz)
113+
function Xyz.CheckValidMultiXyzMaterial(effs,xyz,matg)
114114
for i,te in ipairs(effs) do
115115
local tgf=te:GetOperation()
116-
if not tgf or tgf(te,xyz) then return true end
116+
if not tgf or tgf(te,xyz,matg) then return true end
117117
end
118118
return false
119119
end
@@ -224,15 +224,16 @@ function Xyz.RecursionChk(c,mg,xyz,tp,min,max,minc,maxc,sg,matg,ct,matct,mustbem
224224
if mg:IsExists(Xyz.RecursionChk,1,sg,mg,xyz,tp,min,max,minc,maxc,sg,matg,xct,xmatct,mustbemat,exchk,f,mustg,lv,eqmg,equips_inverse) then return true end
225225
if not mustbemat then
226226
local retchknum={}
227-
for i,te in ipairs({c:GetCardEffect(EFFECT_DOUBLE_XYZ_MATERIAL)}) do
227+
for i,te in ipairs({c:IsHasEffect(EFFECT_DOUBLE_XYZ_MATERIAL,tp)}) do
228228
local tgf=te:GetOperation()
229229
local val=te:GetValue()
230-
if val>0 and not retchknum[val] and (not maxc or xmatct+val<=maxc) and (not tgf or tgf(te,xyz)) then
230+
if val>0 and not retchknum[val] and (not maxc or xmatct+val<=maxc) and (not tgf or tgf(te,xyz,matg)) then
231231
retchknum[val]=true
232-
if (xct+val>=min and xmatct+val>=minc and Xyz.CheckMaterialSet(matg,xyz,tp,exchk,mustg,lv))
233-
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
234-
return true
235-
end
232+
te:UseCountLimit(tp)
233+
local chk=(xct+val>=min and xmatct+val>=minc and Xyz.CheckMaterialSet(matg,xyz,tp,exchk,mustg,lv))
234+
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)
235+
te:RestoreCountLimit(tp)
236+
if chk then return true end
236237
end
237238
end
238239
end
@@ -345,7 +346,7 @@ function Xyz.Target(f,lv,minc,maxc,mustbemat,exchk)
345346
min=min or 0
346347
local matg=Group.CreateGroup()
347348
local sg=Group.CreateGroup()
348-
local tab={}
349+
local multiXyzSelectedCards={}
349350
local finishable=false
350351
while true do
351352
local ct=#matg
@@ -365,37 +366,46 @@ function Xyz.Target(f,lv,minc,maxc,mustbemat,exchk)
365366
if equips_inverse and equips_inverse[sc] then
366367
mg:Merge(equips_inverse[sc])
367368
end
368-
local multiXyz={sc:GetCardEffect(EFFECT_DOUBLE_XYZ_MATERIAL)}
369-
if #multiXyz>0 and Xyz.CheckValidMultiXyzMaterial(multiXyz,c) and ct<minc then
369+
local multiXyz={sc:IsHasEffect(EFFECT_DOUBLE_XYZ_MATERIAL,tp)}
370+
if #multiXyz>0 and Xyz.CheckValidMultiXyzMaterial(multiXyz,c,matg) and ct<minc then
370371
matg:AddCard(sc)
371372
local multi={}
372-
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
373-
table.insert(multi,1)
373+
if mg:IsExists(Xyz.RecursionChk,1,sg,mg,c,tp,min,max,minc,maxc,sg,matg,ct+1,matct+1,mustbemat,exchk,f,mustg,lv,eqmg,equips_inverse) then
374+
multi[1]={}
374375
end
375-
local eff={sc:GetCardEffect(EFFECT_DOUBLE_XYZ_MATERIAL)}
376-
for i=1,#eff do
377-
local te=eff[i]
376+
for i=1,#multiXyz do
377+
local te=multiXyz[i]
378378
local tgf=te:GetOperation()
379379
local val=te:GetValue()
380-
if val>0 and (not tgf or tgf(te,c)) then
380+
if val>0 and (not tgf or tgf(te,c,matg)) then
381381
local newCount=matct+1+val
382-
if (minc<=newCount and newCount<=maxc)
383-
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
384-
table.insert(multi,1+val)
382+
te:UseCountLimit(tp)
383+
local chk=(minc<=newCount and newCount<=maxc)
384+
or mg:IsExists(Xyz.RecursionChk,1,sg,mg,c,tp,min,max,minc,maxc,sg,matg,ct+1,newCount,mustbemat,exchk,f,mustg,lv,eqmg,equips_inverse)
385+
if chk then
386+
if not multi[1+val] then
387+
multi[1+val]={}
388+
end
389+
table.insert(multi[1+val],te)
385390
end
391+
te:RestoreCountLimit(tp)
386392
end
387393
end
388-
if #multi==1 then
389-
if multi[1]>1 then
390-
extra_mats=extra_mats+multi[1]-1
391-
tab[sc]=multi[1]
394+
local availableNumbers={}
395+
for k in ipairs(multi) do
396+
table.insert(availableNumbers,k)
397+
end
398+
if #availableNumbers>0 then
399+
local chosen=availableNumbers[1]
400+
if #availableNumbers~=1 then
401+
Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_XMATERIAL)
402+
chosen=Duel.AnnounceNumber(tp,availableNumbers)
392403
end
393-
else
394-
Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_XMATERIAL)
395-
local num=Duel.AnnounceNumber(tp,table.unpack(multi))
396-
if num>1 then
397-
extra_mats=extra_mats+num-1
398-
tab[sc]=num
404+
if chosen>1 then
405+
local eff=multi[chosen][1]
406+
extra_mats=extra_mats+chosen-1
407+
eff:UseCountLimit(tp)
408+
multiXyzSelectedCards[sc]={eff,chosen}
399409
end
400410
end
401411
elseif sc:IsHasEffect(EFFECT_ORICHALCUM_CHAIN) then
@@ -416,9 +426,11 @@ function Xyz.Target(f,lv,minc,maxc,mustbemat,exchk)
416426
extra_mats=extra_mats-1
417427
else
418428
matg:RemoveCard(sc)
419-
local num=tab[sc]
420-
if num then
421-
tab[sc]=nil
429+
local multiXyzSelection=multiXyzSelectedCards[sc]
430+
if multiXyzSelection then
431+
multiXyzSelectedCards[sc]=nil
432+
local eff,num=table.unpack(multiXyzSelection)
433+
eff:RestoreCountLimit(tp)
422434
extra_mats=extra_mats-(num-1)
423435
end
424436
end

0 commit comments

Comments
 (0)