Commit 60f3468c authored by GuGu's avatar GuGu

Update Exlink.lua

parent d09f956c
Pipeline #33475 passed with stage
in 13 seconds
Exlink = Exlink or {} Exlink = Exlink or {}
--extra link --extra link
function Exlink.AddLinkProcedure(c,f,min,max,mattg,matval,loc1,loc2,count,code,gf) function Exlink.AddLinkProcedure(c,f,min,max,mattg,matval,loc1,loc2,count,code,gf)
local e1=Effect.CreateEffect(c) local e1=Effect.CreateEffect(c)
e1:SetDescription(1166) e1:SetDescription(1166)
e1:SetType(EFFECT_TYPE_FIELD) e1:SetType(EFFECT_TYPE_FIELD)
e1:SetCode(EFFECT_SPSUMMON_PROC) e1:SetCode(EFFECT_SPSUMMON_PROC)
e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE) e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
e1:SetRange(LOCATION_EXTRA) e1:SetRange(LOCATION_EXTRA)
if max==nil then max=c:GetLink() end if max==nil then max=c:GetLink() end
e1:SetCondition(Exlink.LinkCondition(f,min,max,loc1,loc2,gf)) e1:SetCondition(Exlink.LinkCondition(f,min,max,loc1,loc2,gf))
e1:SetTarget(Exlink.LinkTarget(f,min,max,loc1,loc2,gf)) e1:SetTarget(Exlink.LinkTarget(f,min,max,loc1,loc2,gf))
e1:SetOperation(Exlink.LinkOperation(f,min,max,loc1,loc2,gf)) e1:SetOperation(Exlink.LinkOperation(f,min,max,loc1,loc2,gf))
e1:SetValue(SUMMON_TYPE_LINK) e1:SetValue(SUMMON_TYPE_LINK)
c:RegisterEffect(e1) c:RegisterEffect(e1)
--extra material --extra material
if mattg and matval and (loc1 or loc2) then if mattg and matval and (loc1 or loc2) then
local e2=Effect.CreateEffect(c) local e2=Effect.CreateEffect(c)
e2:SetType(EFFECT_TYPE_FIELD) e2:SetType(EFFECT_TYPE_FIELD)
e2:SetProperty(EFFECT_FLAG_UNCOPYABLE+EFFECT_FLAG_IGNORE_IMMUNE+EFFECT_FLAG_SET_AVAILABLE) e2:SetProperty(EFFECT_FLAG_UNCOPYABLE+EFFECT_FLAG_IGNORE_IMMUNE+EFFECT_FLAG_SET_AVAILABLE)
e2:SetCode(EFFECT_EXTRA_LINK_MATERIAL) e2:SetCode(EFFECT_EXTRA_LINK_MATERIAL)
e2:SetRange(LOCATION_EXTRA) e2:SetRange(LOCATION_EXTRA)
if count then if count then
if code==nil then code=c:GetOriginalCode() end if code==nil then code=c:GetOriginalCode() end
e2:SetCountLimit(count,code) e2:SetCountLimit(count,code)
end end
e2:SetLabel(404) e2:SetLabel(404)
e2:SetTarget(Exlink.exmattg(mattg)) e2:SetTarget(Exlink.exmattg(mattg))
e2:SetTargetRange(loc1,loc2) e2:SetTargetRange(loc1,loc2)
e2:SetValue(Exlink.exmatval(matval)) e2:SetValue(Exlink.exmatval(matval))
c:RegisterEffect(e2) c:RegisterEffect(e2)
end end
return e1 return e1
end end
function Exlink.LConditionFilter(c,f,lc,e) function Exlink.LConditionFilter(c,f,lc,e)
return (c:IsFaceup() or not c:IsOnField() or e:IsHasProperty(EFFECT_FLAG_SET_AVAILABLE)) return (c:IsFaceup() or not c:IsOnField() or e:IsHasProperty(EFFECT_FLAG_SET_AVAILABLE))
and c:IsCanBeLinkMaterial(lc) and (not f or f(c)) and c:IsCanBeLinkMaterial(lc) and (not f or f(c))
end end
function Exlink.LExtraFilter(c,f,lc,tp) function Exlink.LExtraFilter(c,f,lc,tp)
if c:IsOnField() and c:IsFacedown() then return false end if c:IsOnField() and c:IsFacedown() then return false end
if not c:IsCanBeLinkMaterial(lc) or f and not f(c) then return false end if not c:IsCanBeLinkMaterial(lc) or f and not f(c) then return false end
local le={c:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)} local le={c:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)}
for _,te in pairs(le) do for _,te in pairs(le) do
local tf=te:GetValue() local tf=te:GetValue()
local related,valid=tf(te,lc,nil,c,tp) local related,valid=tf(te,lc,nil,c,tp)
if related and valid then return true end if related and valid then return true end
end end
return false return false
end end
function Exlink.LExtraFilter2(c,f,lc,tp) function Exlink.LExtraFilter2(c,f,lc,tp)
if not c:IsCanBeLinkMaterial(lc) or f and not f(c) then return false end if not ((c:IsType(TYPE_SPELL+TYPE_TRAP) and not c:IsOnField()) or c:IsCanBeLinkMaterial(lc)) or f and not f(c) then return false end
local le={c:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)} local le={c:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)}
for _,te in pairs(le) do for _,te in pairs(le) do
local tf=te:GetValue() local tf=te:GetValue()
local label=te:GetLabel() local label=te:GetLabel()
local related,valid=tf(te,lc,nil,c,tp) local related,valid=tf(te,lc,nil,c,tp)
if related and valid and label and label==404 then return true end if related and valid and label and label==404 then return true end
end end
return false return false
end end
function Exlink.GetLinkCount(c) function Exlink.GetLinkCount(c)
if c:IsType(TYPE_LINK) and c:GetLink()>1 then if c:IsType(TYPE_LINK) and c:GetLink()>1 then
return 1+0x10000*c:GetLink() return 1+0x10000*c:GetLink()
else return 1 end else return 1 end
end end
function Exlink.GetLinkMaterials(tp,f,lc,e,loc1,loc2) function Exlink.GetLinkMaterials(tp,f,lc,e,loc1,loc2)
local mg=Duel.GetMatchingGroup(Exlink.LConditionFilter,tp,LOCATION_MZONE,0,nil,f,lc,e) local mg=Duel.GetMatchingGroup(Exlink.LConditionFilter,tp,LOCATION_MZONE,0,nil,f,lc,e)
local mg2=Duel.GetMatchingGroup(Exlink.LExtraFilter,tp,LOCATION_HAND+LOCATION_SZONE,LOCATION_ONFIELD,nil,f,lc,tp) local mg2=Duel.GetMatchingGroup(Exlink.LExtraFilter,tp,LOCATION_HAND+LOCATION_SZONE,LOCATION_ONFIELD,nil,f,lc,tp)
local mg3=Duel.GetMatchingGroup(Exlink.LExtraFilter2,tp,loc1,loc2,nil,f,lc,tp) local mg3=Duel.GetMatchingGroup(Exlink.LExtraFilter2,tp,loc1,loc2,nil,f,lc,tp)
if mg2:GetCount()>0 then mg:Merge(mg2) end if mg2:GetCount()>0 then mg:Merge(mg2) end
if mg3:GetCount()>0 then mg:Merge(mg3) end if mg3:GetCount()>0 then mg:Merge(mg3) end
return mg return mg
end end
function Exlink.LCheckOtherMaterial(c,mg,lc,tp) function Exlink.LCheckOtherMaterial(c,mg,lc,tp)
local le={c:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)} local le={c:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)}
local res1=false local res1=false
local res2=true local res2=true
for _,te in pairs(le) do for _,te in pairs(le) do
local f=te:GetValue() local f=te:GetValue()
local related,valid=f(te,lc,mg,c,tp) local related,valid=f(te,lc,mg,c,tp)
if related then res2=false end if related then res2=false end
if related and valid then res1=true end if related and valid then res1=true end
end end
return res1 or res2 return res1 or res2
end end
function Exlink.LUncompatibilityFilter(c,sg,lc,tp) function Exlink.LUncompatibilityFilter(c,sg,lc,tp)
local mg=sg:Filter(aux.TRUE,c) local mg=sg:Filter(aux.TRUE,c)
return not Exlink.LCheckOtherMaterial(c,mg,lc,tp) return not Exlink.LCheckOtherMaterial(c,mg,lc,tp)
end end
function Exlink.LCheckGoal(sg,tp,lc,gf,lmat) function Exlink.LCheckGoal(sg,tp,lc,gf,lmat)
return sg:CheckWithSumEqual(Exlink.GetLinkCount,lc:GetLink(),#sg,#sg) return sg:CheckWithSumEqual(Exlink.GetLinkCount,lc:GetLink(),#sg,#sg)
and Duel.GetLocationCountFromEx(tp,tp,sg,lc)>0 and (not gf or gf(sg,lc,tp)) and Duel.GetLocationCountFromEx(tp,tp,sg,lc)>0 and (not gf or gf(sg,lc,tp))
and not sg:IsExists(Exlink.LUncompatibilityFilter,1,nil,sg,lc,tp) and not sg:IsExists(Exlink.LUncompatibilityFilter,1,nil,sg,lc,tp)
and (not lmat or sg:IsContains(lmat)) and (not lmat or sg:IsContains(lmat))
end end
function Exlink.LExtraMaterialCount(mg,lc,tp) function Exlink.LExtraMaterialCount(mg,lc,tp)
for tc in aux.Next(mg) do for tc in aux.Next(mg) do
local le={tc:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)} local le={tc:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)}
for _,te in pairs(le) do for _,te in pairs(le) do
local sg=mg:Filter(aux.TRUE,tc) local sg=mg:Filter(aux.TRUE,tc)
local f=te:GetValue() local f=te:GetValue()
local related,valid=f(te,lc,sg,tc,tp) local related,valid=f(te,lc,sg,tc,tp)
if related and valid then if related and valid then
te:UseCountLimit(tp) te:UseCountLimit(tp)
end end
end end
end end
end end
function Exlink.LinkCondition(f,minc,maxc,loc1,loc2,gf) function Exlink.LinkCondition(f,minc,maxc,loc1,loc2,gf)
return function(e,c,og,lmat,min,max) return function(e,c,og,lmat,min,max)
if c==nil then return true end if c==nil then return true end
if c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end if c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end
local minc=minc local minc=minc
local maxc=maxc local maxc=maxc
if min then if min then
if min>minc then minc=min end if min>minc then minc=min end
if max<maxc then maxc=max end if max<maxc then maxc=max end
if minc>maxc then return false end if minc>maxc then return false end
end end
local tp=c:GetControler() local tp=c:GetControler()
local mg=nil local mg=nil
if og then if og then
mg=og:Filter(Exlink.LConditionFilter,nil,f,c,e) mg=og:Filter(Exlink.LConditionFilter,nil,f,c,e)
else else
mg=Exlink.GetLinkMaterials(tp,f,c,e,loc1,loc2) mg=Exlink.GetLinkMaterials(tp,f,c,e,loc1,loc2)
end end
if lmat~=nil then if lmat~=nil then
if not Exlink.LConditionFilter(lmat,f,c,e) then return false end if not Exlink.LConditionFilter(lmat,f,c,e) then return false end
mg:AddCard(lmat) mg:AddCard(lmat)
end end
local fg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_LMATERIAL) local fg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_LMATERIAL)
if fg:IsExists(Auxiliary.MustMaterialCounterFilter,1,nil,mg) then return false end if fg:IsExists(Auxiliary.MustMaterialCounterFilter,1,nil,mg) then return false end
Duel.SetSelectedCard(fg) Duel.SetSelectedCard(fg)
return mg:CheckSubGroup(Exlink.LCheckGoal,minc,maxc,tp,c,gf,lmat) return mg:CheckSubGroup(Exlink.LCheckGoal,minc,maxc,tp,c,gf,lmat)
end end
end end
function Exlink.LinkTarget(f,minc,maxc,loc1,loc2,gf) function Exlink.LinkTarget(f,minc,maxc,loc1,loc2,gf)
return function(e,tp,eg,ep,ev,re,r,rp,chk,c,og,lmat,min,max) return function(e,tp,eg,ep,ev,re,r,rp,chk,c,og,lmat,min,max)
local minc=minc local minc=minc
local maxc=maxc local maxc=maxc
if min then if min then
if min>minc then minc=min end if min>minc then minc=min end
if max<maxc then maxc=max end if max<maxc then maxc=max end
if minc>maxc then return false end if minc>maxc then return false end
end end
local mg=nil local mg=nil
if og then if og then
mg=og:Filter(Exlink.LConditionFilter,nil,f,c,e) mg=og:Filter(Exlink.LConditionFilter,nil,f,c,e)
else else
mg=Exlink.GetLinkMaterials(tp,f,c,e,loc1,loc2) mg=Exlink.GetLinkMaterials(tp,f,c,e,loc1,loc2)
end end
if lmat~=nil then if lmat~=nil then
if not Exlink.LConditionFilter(lmat,f,c,e) then return false end if not Exlink.LConditionFilter(lmat,f,c,e) then return false end
mg:AddCard(lmat) mg:AddCard(lmat)
end end
local fg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_LMATERIAL) local fg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_LMATERIAL)
Duel.SetSelectedCard(fg) Duel.SetSelectedCard(fg)
Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_LMATERIAL) Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_LMATERIAL)
local cancel=Duel.IsSummonCancelable() local cancel=Duel.IsSummonCancelable()
local sg=mg:SelectSubGroup(tp,Exlink.LCheckGoal,cancel,minc,maxc,tp,c,gf,lmat) local sg=mg:SelectSubGroup(tp,Exlink.LCheckGoal,cancel,minc,maxc,tp,c,gf,lmat)
if sg then if sg then
sg:KeepAlive() sg:KeepAlive()
e:SetLabelObject(sg) e:SetLabelObject(sg)
return true return true
else return false end else return false end
end end
end end
function Exlink.LinkOperation(f,minc,maxc,loc1,loc2,gf) function Exlink.LinkOperation(f,minc,maxc,loc1,loc2,gf)
return function(e,tp,eg,ep,ev,re,r,rp,c,og,lmat,min,max) return function(e,tp,eg,ep,ev,re,r,rp,c,og,lmat,min,max)
local g=e:GetLabelObject() local g=e:GetLabelObject()
c:SetMaterial(g) c:SetMaterial(g)
Exlink.LExtraMaterialCount(g,c,tp) Exlink.LExtraMaterialCount(g,c,tp)
Duel.SendtoGrave(g,REASON_MATERIAL+REASON_LINK) Duel.SendtoGrave(g,REASON_MATERIAL+REASON_LINK)
g:DeleteGroup() g:DeleteGroup()
end end
end end
function Exlink.exmattg(mattg) function Exlink.exmattg(mattg)
return function(e,c) return function(e,c)
return mattg(e,c) return mattg(e,c)
end end
end end
function Exlink.exmatval(matval) function Exlink.exmatval(matval)
return function(e,lc,mg,c,tp) return function(e,lc,mg,c,tp)
return matval(e,lc,mg,c,tp) return matval(e,lc,mg,c,tp)
end end
end end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment