forked from YGOProjectUnderground/CardScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproc_link_ext.lua
More file actions
112 lines (112 loc) · 3.42 KB
/
proc_link_ext.lua
File metadata and controls
112 lines (112 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
function Link.CheckRecursive(c,tp,sg,mg,lc,minc,maxc,f,specialchk,og,emt,filt)
if #sg>maxc then return false end
filt=filt or {}
local rg=Group.CreateGroup()
--c has the link limit
if c:IsHasEffect(CUSTOM_LINK_MAT_RESTRICTION) then
local eff={c:GetCardEffect(CUSTOM_LINK_MAT_RESTRICTION)}
for i,f in ipairs(eff) do
if sg:IsExists(Auxiliary.HarmonizingMagFilter,1,c,f,f:GetValue()) then
mg:Merge(rg)
return false
end
local sg2=mg:Filter(Auxiliary.HarmonizingMagFilter,nil,f,f:GetValue())
rg:Merge(sg2)
mg:Sub(sg2)
end
end
--A card in the selected group has the link limit
local g2=sg:Filter(Card.IsHasEffect,nil,CUSTOM_LINK_MAT_RESTRICTION)
for tc in aux.Next(g2) do
local eff={tc:GetCardEffect(CUSTOM_LINK_MAT_RESTRICTION)}
for i,f in ipairs(eff) do
if Auxiliary.HarmonizingMagFilter(c,f,f:GetValue()) then
mg:Merge(rg)
return false
end
end
end
sg:AddCard(c)
for _,filt in ipairs(filt) do
if not filt[2](c,filt[3],tp,sg,mg,lc,filt[1],1) then
sg:RemoveCard(c)
return false
end
end
if not og:IsContains(c) then
res=aux.CheckValidExtra(c,tp,sg,mg,lc,emt,filt)
if not res then
sg:RemoveCard(c)
return false
end
end
local res=Link.CheckGoal(tp,sg,lc,minc,f,specialchk,filt)
or (#sg<maxc and mg:IsExists(Link.CheckRecursive,1,sg,tp,sg,mg,lc,minc,maxc,f,specialchk,og,emt,{table.unpack(filt)}))
sg:RemoveCard(c)
return res
end
function Link.CheckRecursive2(c,tp,sg,sg2,secondg,mg,lc,minc,maxc,f,specialchk,og,emt,filt)
if #sg>maxc then return false end
local rg=Group.CreateGroup()
--c has the link limit
if c:IsHasEffect(CUSTOM_LINK_MAT_RESTRICTION) then
local eff={c:GetCardEffect(CUSTOM_LINK_MAT_RESTRICTION)}
for i,f in ipairs(eff) do
if sg:IsExists(Auxiliary.HarmonizingMagFilter,1,c,f,f:GetValue()) then
mg:Merge(rg)
return false
end
local sg3=mg:Filter(Auxiliary.HarmonizingMagFilter,nil,f,f:GetValue())
rg:Merge(sg3)
mg:Sub(sg3)
end
end
--A card in the selected group has the fusion lmit
local g2=sg:Filter(Card.IsHasEffect,nil,CUSTOM_LINK_MAT_RESTRICTION)
for tc in aux.Next(g2) do
local eff={tc:GetCardEffect(CUSTOM_LINK_MAT_RESTRICTION)}
for i,f in ipairs(eff) do
if Auxiliary.HarmonizingMagFilter(c,f,f:GetValue()) then
mg:Merge(rg)
return false
end
end
end
sg:AddCard(c)
for _,filt in ipairs(filt) do
if not filt[2](c,filt[3],tp,sg,mg,lc,filt[1],1) then
sg:RemoveCard(c)
return false
end
end
if not og:IsContains(c) then
res=aux.CheckValidExtra(c,tp,sg,mg,lc,emt,filt)
if not res then
sg:RemoveCard(c)
return false
end
end
if #(sg2-sg)==0 then
if secondg and #secondg>0 then
local res=secondg:IsExists(Link.CheckRecursive,1,sg,tp,sg,mg,lc,minc,maxc,f,specialchk,og,emt,{table.unpack(filt)})
sg:RemoveCard(c)
return res
else
local res=Link.CheckGoal(tp,sg,lc,minc,f,specialchk,{table.unpack(filt)})
sg:RemoveCard(c)
return res
end
end
local res=Link.CheckRecursive2((sg2-sg):GetFirst(),tp,sg,sg2,secondg,mg,lc,minc,maxc,f,specialchk,og,emt,filt)
sg:RemoveCard(c)
return res
end
function Link.CheckGoal(tp,sg,lc,minc,f,specialchk,filt)
for _,filt in ipairs(filt) do
if not sg:IsExists(filt[2],1,nil,filt[3],tp,sg,Group.CreateGroup(),lc,filt[1],1) then
return false
end
end
return #sg>=minc and sg:CheckWithSumEqual(Link.GetLinkCount,lc:GetLink(),#sg,#sg)
and (not specialchk or specialchk(sg,lc,SUMMON_TYPE_LINK|MATERIAL_LINK,tp)) and Duel.GetLocationCountFromEx(tp,tp,sg,lc)>0
end