Commit 60f3468c authored by GuGu's avatar GuGu

Update Exlink.lua

parent d09f956c
Pipeline #33475 passed with stage
in 13 seconds
Exlink = Exlink or {}
--extra link
function Exlink.AddLinkProcedure(c,f,min,max,mattg,matval,loc1,loc2,count,code,gf)
local e1=Effect.CreateEffect(c)
e1:SetDescription(1166)
e1:SetType(EFFECT_TYPE_FIELD)
e1:SetCode(EFFECT_SPSUMMON_PROC)
e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
e1:SetRange(LOCATION_EXTRA)
if max==nil then max=c:GetLink() end
e1:SetCondition(Exlink.LinkCondition(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:SetValue(SUMMON_TYPE_LINK)
c:RegisterEffect(e1)
--extra material
if mattg and matval and (loc1 or loc2) then
local e2=Effect.CreateEffect(c)
e2:SetType(EFFECT_TYPE_FIELD)
e2:SetProperty(EFFECT_FLAG_UNCOPYABLE+EFFECT_FLAG_IGNORE_IMMUNE+EFFECT_FLAG_SET_AVAILABLE)
e2:SetCode(EFFECT_EXTRA_LINK_MATERIAL)
e2:SetRange(LOCATION_EXTRA)
if count then
if code==nil then code=c:GetOriginalCode() end
e2:SetCountLimit(count,code)
end
e2:SetLabel(404)
e2:SetTarget(Exlink.exmattg(mattg))
e2:SetTargetRange(loc1,loc2)
e2:SetValue(Exlink.exmatval(matval))
c:RegisterEffect(e2)
end
return e1
end
function Exlink.LConditionFilter(c,f,lc,e)
return (c:IsFaceup() or not c:IsOnField() or e:IsHasProperty(EFFECT_FLAG_SET_AVAILABLE))
and c:IsCanBeLinkMaterial(lc) and (not f or f(c))
end
function Exlink.LExtraFilter(c,f,lc,tp)
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
local le={c:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)}
for _,te in pairs(le) do
local tf=te:GetValue()
local related,valid=tf(te,lc,nil,c,tp)
if related and valid then return true end
end
return false
end
function Exlink.LExtraFilter2(c,f,lc,tp)
if not c:IsCanBeLinkMaterial(lc) or f and not f(c) then return false end
local le={c:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)}
for _,te in pairs(le) do
local tf=te:GetValue()
local label=te:GetLabel()
local related,valid=tf(te,lc,nil,c,tp)
if related and valid and label and label==404 then return true end
end
return false
end
function Exlink.GetLinkCount(c)
if c:IsType(TYPE_LINK) and c:GetLink()>1 then
return 1+0x10000*c:GetLink()
else return 1 end
end
function Exlink.GetLinkMaterials(tp,f,lc,e,loc1,loc2)
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 mg3=Duel.GetMatchingGroup(Exlink.LExtraFilter2,tp,loc1,loc2,nil,f,lc,tp)
if mg2:GetCount()>0 then mg:Merge(mg2) end
if mg3:GetCount()>0 then mg:Merge(mg3) end
return mg
end
function Exlink.LCheckOtherMaterial(c,mg,lc,tp)
local le={c:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)}
local res1=false
local res2=true
for _,te in pairs(le) do
local f=te:GetValue()
local related,valid=f(te,lc,mg,c,tp)
if related then res2=false end
if related and valid then res1=true end
end
return res1 or res2
end
function Exlink.LUncompatibilityFilter(c,sg,lc,tp)
local mg=sg:Filter(aux.TRUE,c)
return not Exlink.LCheckOtherMaterial(c,mg,lc,tp)
end
function Exlink.LCheckGoal(sg,tp,lc,gf,lmat)
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 not sg:IsExists(Exlink.LUncompatibilityFilter,1,nil,sg,lc,tp)
and (not lmat or sg:IsContains(lmat))
end
function Exlink.LExtraMaterialCount(mg,lc,tp)
for tc in aux.Next(mg) do
local le={tc:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)}
for _,te in pairs(le) do
local sg=mg:Filter(aux.TRUE,tc)
local f=te:GetValue()
local related,valid=f(te,lc,sg,tc,tp)
if related and valid then
te:UseCountLimit(tp)
end
end
end
end
function Exlink.LinkCondition(f,minc,maxc,loc1,loc2,gf)
return function(e,c,og,lmat,min,max)
if c==nil then return true end
if c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end
local minc=minc
local maxc=maxc
if min then
if min>minc then minc=min end
if max<maxc then maxc=max end
if minc>maxc then return false end
end
local tp=c:GetControler()
local mg=nil
if og then
mg=og:Filter(Exlink.LConditionFilter,nil,f,c,e)
else
mg=Exlink.GetLinkMaterials(tp,f,c,e,loc1,loc2)
end
if lmat~=nil then
if not Exlink.LConditionFilter(lmat,f,c,e) then return false end
mg:AddCard(lmat)
end
local fg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_LMATERIAL)
if fg:IsExists(Auxiliary.MustMaterialCounterFilter,1,nil,mg) then return false end
Duel.SetSelectedCard(fg)
return mg:CheckSubGroup(Exlink.LCheckGoal,minc,maxc,tp,c,gf,lmat)
end
end
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)
local minc=minc
local maxc=maxc
if min then
if min>minc then minc=min end
if max<maxc then maxc=max end
if minc>maxc then return false end
end
local mg=nil
if og then
mg=og:Filter(Exlink.LConditionFilter,nil,f,c,e)
else
mg=Exlink.GetLinkMaterials(tp,f,c,e,loc1,loc2)
end
if lmat~=nil then
if not Exlink.LConditionFilter(lmat,f,c,e) then return false end
mg:AddCard(lmat)
end
local fg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_LMATERIAL)
Duel.SetSelectedCard(fg)
Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_LMATERIAL)
local cancel=Duel.IsSummonCancelable()
local sg=mg:SelectSubGroup(tp,Exlink.LCheckGoal,cancel,minc,maxc,tp,c,gf,lmat)
if sg then
sg:KeepAlive()
e:SetLabelObject(sg)
return true
else return false end
end
end
function Exlink.LinkOperation(f,minc,maxc,loc1,loc2,gf)
return function(e,tp,eg,ep,ev,re,r,rp,c,og,lmat,min,max)
local g=e:GetLabelObject()
c:SetMaterial(g)
Exlink.LExtraMaterialCount(g,c,tp)
Duel.SendtoGrave(g,REASON_MATERIAL+REASON_LINK)
g:DeleteGroup()
end
end
function Exlink.exmattg(mattg)
return function(e,c)
return mattg(e,c)
end
end
function Exlink.exmatval(matval)
return function(e,lc,mg,c,tp)
return matval(e,lc,mg,c,tp)
end
Exlink = Exlink or {}
--extra link
function Exlink.AddLinkProcedure(c,f,min,max,mattg,matval,loc1,loc2,count,code,gf)
local e1=Effect.CreateEffect(c)
e1:SetDescription(1166)
e1:SetType(EFFECT_TYPE_FIELD)
e1:SetCode(EFFECT_SPSUMMON_PROC)
e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
e1:SetRange(LOCATION_EXTRA)
if max==nil then max=c:GetLink() end
e1:SetCondition(Exlink.LinkCondition(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:SetValue(SUMMON_TYPE_LINK)
c:RegisterEffect(e1)
--extra material
if mattg and matval and (loc1 or loc2) then
local e2=Effect.CreateEffect(c)
e2:SetType(EFFECT_TYPE_FIELD)
e2:SetProperty(EFFECT_FLAG_UNCOPYABLE+EFFECT_FLAG_IGNORE_IMMUNE+EFFECT_FLAG_SET_AVAILABLE)
e2:SetCode(EFFECT_EXTRA_LINK_MATERIAL)
e2:SetRange(LOCATION_EXTRA)
if count then
if code==nil then code=c:GetOriginalCode() end
e2:SetCountLimit(count,code)
end
e2:SetLabel(404)
e2:SetTarget(Exlink.exmattg(mattg))
e2:SetTargetRange(loc1,loc2)
e2:SetValue(Exlink.exmatval(matval))
c:RegisterEffect(e2)
end
return e1
end
function Exlink.LConditionFilter(c,f,lc,e)
return (c:IsFaceup() or not c:IsOnField() or e:IsHasProperty(EFFECT_FLAG_SET_AVAILABLE))
and c:IsCanBeLinkMaterial(lc) and (not f or f(c))
end
function Exlink.LExtraFilter(c,f,lc,tp)
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
local le={c:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)}
for _,te in pairs(le) do
local tf=te:GetValue()
local related,valid=tf(te,lc,nil,c,tp)
if related and valid then return true end
end
return false
end
function Exlink.LExtraFilter2(c,f,lc,tp)
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)}
for _,te in pairs(le) do
local tf=te:GetValue()
local label=te:GetLabel()
local related,valid=tf(te,lc,nil,c,tp)
if related and valid and label and label==404 then return true end
end
return false
end
function Exlink.GetLinkCount(c)
if c:IsType(TYPE_LINK) and c:GetLink()>1 then
return 1+0x10000*c:GetLink()
else return 1 end
end
function Exlink.GetLinkMaterials(tp,f,lc,e,loc1,loc2)
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 mg3=Duel.GetMatchingGroup(Exlink.LExtraFilter2,tp,loc1,loc2,nil,f,lc,tp)
if mg2:GetCount()>0 then mg:Merge(mg2) end
if mg3:GetCount()>0 then mg:Merge(mg3) end
return mg
end
function Exlink.LCheckOtherMaterial(c,mg,lc,tp)
local le={c:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)}
local res1=false
local res2=true
for _,te in pairs(le) do
local f=te:GetValue()
local related,valid=f(te,lc,mg,c,tp)
if related then res2=false end
if related and valid then res1=true end
end
return res1 or res2
end
function Exlink.LUncompatibilityFilter(c,sg,lc,tp)
local mg=sg:Filter(aux.TRUE,c)
return not Exlink.LCheckOtherMaterial(c,mg,lc,tp)
end
function Exlink.LCheckGoal(sg,tp,lc,gf,lmat)
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 not sg:IsExists(Exlink.LUncompatibilityFilter,1,nil,sg,lc,tp)
and (not lmat or sg:IsContains(lmat))
end
function Exlink.LExtraMaterialCount(mg,lc,tp)
for tc in aux.Next(mg) do
local le={tc:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)}
for _,te in pairs(le) do
local sg=mg:Filter(aux.TRUE,tc)
local f=te:GetValue()
local related,valid=f(te,lc,sg,tc,tp)
if related and valid then
te:UseCountLimit(tp)
end
end
end
end
function Exlink.LinkCondition(f,minc,maxc,loc1,loc2,gf)
return function(e,c,og,lmat,min,max)
if c==nil then return true end
if c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end
local minc=minc
local maxc=maxc
if min then
if min>minc then minc=min end
if max<maxc then maxc=max end
if minc>maxc then return false end
end
local tp=c:GetControler()
local mg=nil
if og then
mg=og:Filter(Exlink.LConditionFilter,nil,f,c,e)
else
mg=Exlink.GetLinkMaterials(tp,f,c,e,loc1,loc2)
end
if lmat~=nil then
if not Exlink.LConditionFilter(lmat,f,c,e) then return false end
mg:AddCard(lmat)
end
local fg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_LMATERIAL)
if fg:IsExists(Auxiliary.MustMaterialCounterFilter,1,nil,mg) then return false end
Duel.SetSelectedCard(fg)
return mg:CheckSubGroup(Exlink.LCheckGoal,minc,maxc,tp,c,gf,lmat)
end
end
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)
local minc=minc
local maxc=maxc
if min then
if min>minc then minc=min end
if max<maxc then maxc=max end
if minc>maxc then return false end
end
local mg=nil
if og then
mg=og:Filter(Exlink.LConditionFilter,nil,f,c,e)
else
mg=Exlink.GetLinkMaterials(tp,f,c,e,loc1,loc2)
end
if lmat~=nil then
if not Exlink.LConditionFilter(lmat,f,c,e) then return false end
mg:AddCard(lmat)
end
local fg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_LMATERIAL)
Duel.SetSelectedCard(fg)
Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_LMATERIAL)
local cancel=Duel.IsSummonCancelable()
local sg=mg:SelectSubGroup(tp,Exlink.LCheckGoal,cancel,minc,maxc,tp,c,gf,lmat)
if sg then
sg:KeepAlive()
e:SetLabelObject(sg)
return true
else return false end
end
end
function Exlink.LinkOperation(f,minc,maxc,loc1,loc2,gf)
return function(e,tp,eg,ep,ev,re,r,rp,c,og,lmat,min,max)
local g=e:GetLabelObject()
c:SetMaterial(g)
Exlink.LExtraMaterialCount(g,c,tp)
Duel.SendtoGrave(g,REASON_MATERIAL+REASON_LINK)
g:DeleteGroup()
end
end
function Exlink.exmattg(mattg)
return function(e,c)
return mattg(e,c)
end
end
function Exlink.exmatval(matval)
return function(e,lc,mg,c,tp)
return matval(e,lc,mg,c,tp)
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