8c706ff713 2023-10-14 1: --Gemini Summon
8c706ff713 2023-10-14 2: function Auxiliary.IsDualState(effect)
8c706ff713 2023-10-14 3: local c=effect:GetHandler()
8c706ff713 2023-10-14 4: return not c:IsDisabled() and c:IsDualState()
8c706ff713 2023-10-14 5: end
8c706ff713 2023-10-14 6: function Auxiliary.IsNotDualState(effect)
8c706ff713 2023-10-14 7: local c=effect:GetHandler()
8c706ff713 2023-10-14 8: return c:IsDisabled() or not c:IsDualState()
8c706ff713 2023-10-14 9: end
8c706ff713 2023-10-14 10: function Auxiliary.DualNormalCondition(effect)
8c706ff713 2023-10-14 11: local c=effect:GetHandler()
8c706ff713 2023-10-14 12: return c:IsFaceup() and not c:IsDualState()
8c706ff713 2023-10-14 13: end
8c706ff713 2023-10-14 14: function Auxiliary.EnableDualAttribute(c)
8c706ff713 2023-10-14 15: local e1=Effect.CreateEffect(c)
8c706ff713 2023-10-14 16: e1:SetType(EFFECT_TYPE_SINGLE)
8c706ff713 2023-10-14 17: e1:SetCode(EFFECT_DUAL_SUMMONABLE)
8c706ff713 2023-10-14 18: c:RegisterEffect(e1)
8c706ff713 2023-10-14 19: local e2=Effect.CreateEffect(c)
8c706ff713 2023-10-14 20: e2:SetType(EFFECT_TYPE_SINGLE)
8c706ff713 2023-10-14 21: e2:SetCode(EFFECT_ADD_TYPE)
8c706ff713 2023-10-14 22: e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE+EFFECT_FLAG_IGNORE_IMMUNE)
8c706ff713 2023-10-14 23: e2:SetRange(LOCATION_MZONE+LOCATION_GRAVE)
8c706ff713 2023-10-14 24: e2:SetCondition(aux.DualNormalCondition)
8c706ff713 2023-10-14 25: e2:SetValue(TYPE_NORMAL)
8c706ff713 2023-10-14 26: c:RegisterEffect(e2)
8c706ff713 2023-10-14 27: local e3=e2:Clone()
8c706ff713 2023-10-14 28: e3:SetCode(EFFECT_REMOVE_TYPE)
8c706ff713 2023-10-14 29: e3:SetValue(TYPE_EFFECT)
8c706ff713 2023-10-14 30: c:RegisterEffect(e3)
8c706ff713 2023-10-14 31: end
8c706ff713 2023-10-14 32:
8c706ff713 2023-10-14 33: --Synchro Summon
8c706ff713 2023-10-14 34: function Auxiliary.Tuner(f,...)
8c706ff713 2023-10-14 35: local ext_params={...}
8c706ff713 2023-10-14 36: return function(target,syncard)
8c706ff713 2023-10-14 37: return target:IsTuner(syncard) and (not f or f(target,table.unpack(ext_params)))
8c706ff713 2023-10-14 38: end
8c706ff713 2023-10-14 39: end
8c706ff713 2023-10-14 40: function Auxiliary.NonTuner(f,...)
8c706ff713 2023-10-14 41: local ext_params={...}
8c706ff713 2023-10-14 42: return function(target,syncard)
8c706ff713 2023-10-14 43: return target:IsNotTuner(syncard) and (not f or f(target,table.unpack(ext_params)))
8c706ff713 2023-10-14 44: end
8c706ff713 2023-10-14 45: end
8c706ff713 2023-10-14 46: --Synchro monster, 1 tuner + min to max monsters
8c706ff713 2023-10-14 47: function Auxiliary.AddSynchroProcedure(c,f1,f2,minc,maxc)
8c706ff713 2023-10-14 48: if maxc==nil then maxc=99 end
8c706ff713 2023-10-14 49: local e1=Effect.CreateEffect(c)
8c706ff713 2023-10-14 50: e1:SetDescription(1164)
8c706ff713 2023-10-14 51: e1:SetType(EFFECT_TYPE_FIELD)
8c706ff713 2023-10-14 52: e1:SetCode(EFFECT_SPSUMMON_PROC)
8c706ff713 2023-10-14 53: e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
8c706ff713 2023-10-14 54: e1:SetRange(LOCATION_EXTRA)
8c706ff713 2023-10-14 55: e1:SetCondition(Auxiliary.SynCondition(f1,f2,minc,maxc))
8c706ff713 2023-10-14 56: e1:SetTarget(Auxiliary.SynTarget(f1,f2,minc,maxc))
8c706ff713 2023-10-14 57: e1:SetOperation(Auxiliary.SynOperation(f1,f2,minc,maxc))
8c706ff713 2023-10-14 58: e1:SetValue(SUMMON_TYPE_SYNCHRO)
8c706ff713 2023-10-14 59: c:RegisterEffect(e1)
8c706ff713 2023-10-14 60: end
8c706ff713 2023-10-14 61: function Auxiliary.SynCondition(f1,f2,minc,maxc)
8c706ff713 2023-10-14 62: return function(e,c,smat,mg,min,max)
8c706ff713 2023-10-14 63: if c==nil then return true end
8c706ff713 2023-10-14 64: if c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end
8c706ff713 2023-10-14 65: local minc=minc
8c706ff713 2023-10-14 66: local maxc=maxc
8c706ff713 2023-10-14 67: if min then
8c706ff713 2023-10-14 68: if min>minc then minc=min end
8c706ff713 2023-10-14 69: if max<maxc then maxc=max end
8c706ff713 2023-10-14 70: if minc>maxc then return false end
8c706ff713 2023-10-14 71: end
8c706ff713 2023-10-14 72: if smat and smat:IsTuner(c) and (not f1 or f1(smat)) then
8c706ff713 2023-10-14 73: return Duel.CheckTunerMaterial(c,smat,f1,f2,minc,maxc,mg) end
8c706ff713 2023-10-14 74: return Duel.CheckSynchroMaterial(c,f1,f2,minc,maxc,smat,mg)
8c706ff713 2023-10-14 75: end
8c706ff713 2023-10-14 76: end
8c706ff713 2023-10-14 77: function Auxiliary.SynTarget(f1,f2,minc,maxc)
8c706ff713 2023-10-14 78: return function(e,tp,eg,ep,ev,re,r,rp,chk,c,smat,mg,min,max)
8c706ff713 2023-10-14 79: local minc=minc
8c706ff713 2023-10-14 80: local maxc=maxc
8c706ff713 2023-10-14 81: if min then
8c706ff713 2023-10-14 82: if min>minc then minc=min end
8c706ff713 2023-10-14 83: if max<maxc then maxc=max end
8c706ff713 2023-10-14 84: if minc>maxc then return false end
8c706ff713 2023-10-14 85: end
8c706ff713 2023-10-14 86: local g=nil
8c706ff713 2023-10-14 87: if smat and smat:IsTuner(c) and (not f1 or f1(smat)) then
8c706ff713 2023-10-14 88: g=Duel.SelectTunerMaterial(c:GetControler(),c,smat,f1,f2,minc,maxc,mg)
8c706ff713 2023-10-14 89: else
8c706ff713 2023-10-14 90: g=Duel.SelectSynchroMaterial(c:GetControler(),c,f1,f2,minc,maxc,smat,mg)
8c706ff713 2023-10-14 91: end
8c706ff713 2023-10-14 92: if g then
8c706ff713 2023-10-14 93: g:KeepAlive()
8c706ff713 2023-10-14 94: e:SetLabelObject(g)
8c706ff713 2023-10-14 95: return true
8c706ff713 2023-10-14 96: else return false end
8c706ff713 2023-10-14 97: end
8c706ff713 2023-10-14 98: end
8c706ff713 2023-10-14 99: function Auxiliary.SynOperation(f1,f2,minct,maxc)
8c706ff713 2023-10-14 100: return function(e,tp,eg,ep,ev,re,r,rp,c,smat,mg,min,max)
8c706ff713 2023-10-14 101: local g=e:GetLabelObject()
8c706ff713 2023-10-14 102: c:SetMaterial(g)
8c706ff713 2023-10-14 103: Duel.SendtoGrave(g,REASON_MATERIAL+REASON_SYNCHRO)
8c706ff713 2023-10-14 104: g:DeleteGroup()
8c706ff713 2023-10-14 105: end
8c706ff713 2023-10-14 106: end
8c706ff713 2023-10-14 107: --Synchro monster, 1 tuner + 1 monster
8c706ff713 2023-10-14 108: --backward compatibility
8c706ff713 2023-10-14 109: function Auxiliary.AddSynchroProcedure2(c,f1,f2)
8c706ff713 2023-10-14 110: Auxiliary.AddSynchroProcedure(c,f1,f2,1,1)
8c706ff713 2023-10-14 111: end
8c706ff713 2023-10-14 112: --Synchro monster, f1~f3 each 1 MONSTER + f4 min to max monsters
8c706ff713 2023-10-14 113: function Auxiliary.AddSynchroMixProcedure(c,f1,f2,f3,f4,minc,maxc,gc)
8c706ff713 2023-10-14 114: local e1=Effect.CreateEffect(c)
8c706ff713 2023-10-14 115: e1:SetDescription(1164)
8c706ff713 2023-10-14 116: e1:SetType(EFFECT_TYPE_FIELD)
8c706ff713 2023-10-14 117: e1:SetCode(EFFECT_SPSUMMON_PROC)
8c706ff713 2023-10-14 118: e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
8c706ff713 2023-10-14 119: e1:SetRange(LOCATION_EXTRA)
8c706ff713 2023-10-14 120: e1:SetCondition(Auxiliary.SynMixCondition(f1,f2,f3,f4,minc,maxc,gc))
8c706ff713 2023-10-14 121: e1:SetTarget(Auxiliary.SynMixTarget(f1,f2,f3,f4,minc,maxc,gc))
8c706ff713 2023-10-14 122: e1:SetOperation(Auxiliary.SynMixOperation(f1,f2,f3,f4,minc,maxc,gc))
8c706ff713 2023-10-14 123: e1:SetValue(SUMMON_TYPE_SYNCHRO)
8c706ff713 2023-10-14 124: c:RegisterEffect(e1)
8c706ff713 2023-10-14 125: end
8c706ff713 2023-10-14 126: function Auxiliary.SynMaterialFilter(c,syncard)
8c706ff713 2023-10-14 127: return c:IsFaceupEx() and c:IsCanBeSynchroMaterial(syncard)
8c706ff713 2023-10-14 128: end
8c706ff713 2023-10-14 129: function Auxiliary.SynLimitFilter(c,f,e,syncard)
8c706ff713 2023-10-14 130: return f and not f(e,c,syncard)
8c706ff713 2023-10-14 131: end
8c706ff713 2023-10-14 132: function Auxiliary.GetSynchroLevelFlowerCardian(c)
8c706ff713 2023-10-14 133: return 2
8c706ff713 2023-10-14 134: end
8c706ff713 2023-10-14 135: function Auxiliary.GetSynMaterials(tp,syncard)
8c706ff713 2023-10-14 136: local mg=Duel.GetSynchroMaterial(tp):Filter(Auxiliary.SynMaterialFilter,nil,syncard)
8c706ff713 2023-10-14 137: if mg:IsExists(Card.GetHandSynchro,1,nil) then
8c706ff713 2023-10-14 138: local mg2=Duel.GetMatchingGroup(Card.IsCanBeSynchroMaterial,tp,LOCATION_HAND,0,nil,syncard)
8c706ff713 2023-10-14 139: if mg2:GetCount()>0 then mg:Merge(mg2) end
8c706ff713 2023-10-14 140: end
8c706ff713 2023-10-14 141: return mg
8c706ff713 2023-10-14 142: end
8c706ff713 2023-10-14 143: function Auxiliary.SynMixCondition(f1,f2,f3,f4,minc,maxc,gc)
8c706ff713 2023-10-14 144: return function(e,c,smat,mg1,min,max)
8c706ff713 2023-10-14 145: if c==nil then return true end
8c706ff713 2023-10-14 146: if c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end
8c706ff713 2023-10-14 147: local minc=minc
8c706ff713 2023-10-14 148: local maxc=maxc
8c706ff713 2023-10-14 149: if min then
8c706ff713 2023-10-14 150: if min>minc then minc=min end
8c706ff713 2023-10-14 151: if max<maxc then maxc=max end
8c706ff713 2023-10-14 152: if minc>maxc then return false end
8c706ff713 2023-10-14 153: end
8c706ff713 2023-10-14 154: if smat and not smat:IsCanBeSynchroMaterial(c) then return false end
8c706ff713 2023-10-14 155: local tp=c:GetControler()
8c706ff713 2023-10-14 156: local mg
8c706ff713 2023-10-14 157: local mgchk=false
8c706ff713 2023-10-14 158: if mg1 then
8c706ff713 2023-10-14 159: mg=mg1
8c706ff713 2023-10-14 160: mgchk=true
8c706ff713 2023-10-14 161: else
8c706ff713 2023-10-14 162: mg=Auxiliary.GetSynMaterials(tp,c)
8c706ff713 2023-10-14 163: end
8c706ff713 2023-10-14 164: if smat~=nil then mg:AddCard(smat) end
8c706ff713 2023-10-14 165: return mg:IsExists(Auxiliary.SynMixFilter1,1,nil,f1,f2,f3,f4,minc,maxc,c,mg,smat,gc,mgchk)
8c706ff713 2023-10-14 166: end
8c706ff713 2023-10-14 167: end
8c706ff713 2023-10-14 168: function Auxiliary.SynMixTarget(f1,f2,f3,f4,minc,maxc,gc)
8c706ff713 2023-10-14 169: return function(e,tp,eg,ep,ev,re,r,rp,chk,c,smat,mg1,min,max)
8c706ff713 2023-10-14 170: local minc=minc
8c706ff713 2023-10-14 171: local maxc=maxc
8c706ff713 2023-10-14 172: if min then
8c706ff713 2023-10-14 173: if min>minc then minc=min end
8c706ff713 2023-10-14 174: if max<maxc then maxc=max end
8c706ff713 2023-10-14 175: if minc>maxc then return false end
8c706ff713 2023-10-14 176: end
8c706ff713 2023-10-14 177: ::SynMixTargetSelectStart::
8c706ff713 2023-10-14 178: local g=Group.CreateGroup()
8c706ff713 2023-10-14 179: local mg
8c706ff713 2023-10-14 180: local mgchk=false
8c706ff713 2023-10-14 181: if mg1 then
8c706ff713 2023-10-14 182: mg=mg1
8c706ff713 2023-10-14 183: mgchk=true
8c706ff713 2023-10-14 184: else
8c706ff713 2023-10-14 185: mg=Auxiliary.GetSynMaterials(tp,c)
8c706ff713 2023-10-14 186: end
8c706ff713 2023-10-14 187: if smat~=nil then mg:AddCard(smat) end
8c706ff713 2023-10-14 188: local c1
8c706ff713 2023-10-14 189: local c2
8c706ff713 2023-10-14 190: local c3
8c706ff713 2023-10-14 191: local cancel=Duel.IsSummonCancelable()
8c706ff713 2023-10-14 192: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SMATERIAL)
8c706ff713 2023-10-14 193: c1=mg:Filter(Auxiliary.SynMixFilter1,nil,f1,f2,f3,f4,minc,maxc,c,mg,smat,gc,mgchk):SelectUnselect(g,tp,false,cancel,1,1)
8c706ff713 2023-10-14 194: if not c1 then return false end
8c706ff713 2023-10-14 195: g:AddCard(c1)
8c706ff713 2023-10-14 196: if f2 then
8c706ff713 2023-10-14 197: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SMATERIAL)
8c706ff713 2023-10-14 198: c2=mg:Filter(Auxiliary.SynMixFilter2,g,f2,f3,f4,minc,maxc,c,mg,smat,c1,gc,mgchk):SelectUnselect(g,tp,false,cancel,1,1)
8c706ff713 2023-10-14 199: if not c2 then return false end
8c706ff713 2023-10-14 200: if g:IsContains(c2) then goto SynMixTargetSelectStart end
8c706ff713 2023-10-14 201: g:AddCard(c2)
8c706ff713 2023-10-14 202: if f3 then
8c706ff713 2023-10-14 203: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SMATERIAL)
8c706ff713 2023-10-14 204: c3=mg:Filter(Auxiliary.SynMixFilter3,g,f3,f4,minc,maxc,c,mg,smat,c1,c2,gc,mgchk):SelectUnselect(g,tp,false,cancel,1,1)
8c706ff713 2023-10-14 205: if not c3 then return false end
8c706ff713 2023-10-14 206: if g:IsContains(c3) then goto SynMixTargetSelectStart end
8c706ff713 2023-10-14 207: g:AddCard(c3)
8c706ff713 2023-10-14 208: end
8c706ff713 2023-10-14 209: end
8c706ff713 2023-10-14 210: local g4=Group.CreateGroup()
8c706ff713 2023-10-14 211: for i=0,maxc-1 do
8c706ff713 2023-10-14 212: local mg2=mg:Clone()
8c706ff713 2023-10-14 213: if f4 then
8c706ff713 2023-10-14 214: mg2=mg2:Filter(f4,g,c,c1,c2,c3)
8c706ff713 2023-10-14 215: else
8c706ff713 2023-10-14 216: mg2:Sub(g)
8c706ff713 2023-10-14 217: end
8c706ff713 2023-10-14 218: local cg=mg2:Filter(Auxiliary.SynMixCheckRecursive,g4,tp,g4,mg2,i,minc,maxc,c,g,smat,gc,mgchk)
8c706ff713 2023-10-14 219: if cg:GetCount()==0 then break end
8c706ff713 2023-10-14 220: local finish=Auxiliary.SynMixCheckGoal(tp,g4,minc,i,c,g,smat,gc,mgchk)
8c706ff713 2023-10-14 221: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SMATERIAL)
8c706ff713 2023-10-14 222: local c4=cg:SelectUnselect(g+g4,tp,finish,cancel,minc,maxc)
8c706ff713 2023-10-14 223: if not c4 then
8c706ff713 2023-10-14 224: if finish then break
8c706ff713 2023-10-14 225: else return false end
8c706ff713 2023-10-14 226: end
8c706ff713 2023-10-14 227: if g:IsContains(c4) or g4:IsContains(c4) then goto SynMixTargetSelectStart end
8c706ff713 2023-10-14 228: g4:AddCard(c4)
8c706ff713 2023-10-14 229: end
8c706ff713 2023-10-14 230: g:Merge(g4)
8c706ff713 2023-10-14 231: if g:GetCount()>0 then
8c706ff713 2023-10-14 232: g:KeepAlive()
8c706ff713 2023-10-14 233: e:SetLabelObject(g)
8c706ff713 2023-10-14 234: return true
8c706ff713 2023-10-14 235: else return false end
8c706ff713 2023-10-14 236: end
8c706ff713 2023-10-14 237: end
8c706ff713 2023-10-14 238: function Auxiliary.SynMixOperation(f1,f2,f3,f4,minct,maxc,gc)
8c706ff713 2023-10-14 239: return function(e,tp,eg,ep,ev,re,r,rp,c,smat,mg,min,max)
8c706ff713 2023-10-14 240: local g=e:GetLabelObject()
8c706ff713 2023-10-14 241: c:SetMaterial(g)
8c706ff713 2023-10-14 242: Duel.SendtoGrave(g,REASON_MATERIAL+REASON_SYNCHRO)
8c706ff713 2023-10-14 243: g:DeleteGroup()
8c706ff713 2023-10-14 244: end
8c706ff713 2023-10-14 245: end
8c706ff713 2023-10-14 246: function Auxiliary.SynMixFilter1(c,f1,f2,f3,f4,minc,maxc,syncard,mg,smat,gc,mgchk)
8c706ff713 2023-10-14 247: return (not f1 or f1(c,syncard)) and mg:IsExists(Auxiliary.SynMixFilter2,1,c,f2,f3,f4,minc,maxc,syncard,mg,smat,c,gc,mgchk)
8c706ff713 2023-10-14 248: end
8c706ff713 2023-10-14 249: function Auxiliary.SynMixFilter2(c,f2,f3,f4,minc,maxc,syncard,mg,smat,c1,gc,mgchk)
8c706ff713 2023-10-14 250: if f2 then
8c706ff713 2023-10-14 251: return f2(c,syncard,c1)
8c706ff713 2023-10-14 252: and (mg:IsExists(Auxiliary.SynMixFilter3,1,Group.FromCards(c1,c),f3,f4,minc,maxc,syncard,mg,smat,c1,c,gc,mgchk)
8c706ff713 2023-10-14 253: or minc==0 and Auxiliary.SynMixFilter4(c,nil,1,1,syncard,mg,smat,c1,nil,nil,gc,mgchk))
8c706ff713 2023-10-14 254: else
8c706ff713 2023-10-14 255: return mg:IsExists(Auxiliary.SynMixFilter4,1,c1,f4,minc,maxc,syncard,mg,smat,c1,nil,nil,gc,mgchk)
8c706ff713 2023-10-14 256: end
8c706ff713 2023-10-14 257: end
8c706ff713 2023-10-14 258: function Auxiliary.SynMixFilter3(c,f3,f4,minc,maxc,syncard,mg,smat,c1,c2,gc,mgchk)
8c706ff713 2023-10-14 259: if f3 then
8c706ff713 2023-10-14 260: return f3(c,syncard,c1,c2)
8c706ff713 2023-10-14 261: and (mg:IsExists(Auxiliary.SynMixFilter4,1,Group.FromCards(c1,c2,c),f4,minc,maxc,syncard,mg,smat,c1,c2,c,gc,mgchk)
8c706ff713 2023-10-14 262: or minc==0 and Auxiliary.SynMixFilter4(c,nil,1,1,syncard,mg,smat,c1,c2,nil,gc,mgchk))
8c706ff713 2023-10-14 263: else
8c706ff713 2023-10-14 264: return mg:IsExists(Auxiliary.SynMixFilter4,1,Group.FromCards(c1,c2),f4,minc,maxc,syncard,mg,smat,c1,c2,nil,gc,mgchk)
8c706ff713 2023-10-14 265: end
8c706ff713 2023-10-14 266: end
8c706ff713 2023-10-14 267: function Auxiliary.SynMixFilter4(c,f4,minc,maxc,syncard,mg1,smat,c1,c2,c3,gc,mgchk)
8c706ff713 2023-10-14 268: if f4 and not f4(c,syncard,c1,c2,c3) then return false end
8c706ff713 2023-10-14 269: local sg=Group.FromCards(c1,c)
8c706ff713 2023-10-14 270: sg:AddCard(c1)
8c706ff713 2023-10-14 271: if c2 then sg:AddCard(c2) end
8c706ff713 2023-10-14 272: if c3 then sg:AddCard(c3) end
8c706ff713 2023-10-14 273: local mg=mg1:Clone()
8c706ff713 2023-10-14 274: if f4 then
8c706ff713 2023-10-14 275: mg=mg:Filter(f4,sg,syncard,c1,c2,c3)
8c706ff713 2023-10-14 276: else
8c706ff713 2023-10-14 277: mg:Sub(sg)
8c706ff713 2023-10-14 278: end
8c706ff713 2023-10-14 279: return Auxiliary.SynMixCheck(mg,sg,minc-1,maxc-1,syncard,smat,gc,mgchk)
8c706ff713 2023-10-14 280: end
8c706ff713 2023-10-14 281: function Auxiliary.SynMixCheck(mg,sg1,minc,maxc,syncard,smat,gc,mgchk)
8c706ff713 2023-10-14 282: local tp=syncard:GetControler()
8c706ff713 2023-10-14 283: local sg=Group.CreateGroup()
8c706ff713 2023-10-14 284: if minc<=0 and Auxiliary.SynMixCheckGoal(tp,sg1,0,0,syncard,sg,smat,gc,mgchk) then return true end
8c706ff713 2023-10-14 285: if maxc==0 then return false end
8c706ff713 2023-10-14 286: return mg:IsExists(Auxiliary.SynMixCheckRecursive,1,nil,tp,sg,mg,0,minc,maxc,syncard,sg1,smat,gc,mgchk)
8c706ff713 2023-10-14 287: end
8c706ff713 2023-10-14 288: function Auxiliary.SynMixCheckRecursive(c,tp,sg,mg,ct,minc,maxc,syncard,sg1,smat,gc,mgchk)
8c706ff713 2023-10-14 289: sg:AddCard(c)
8c706ff713 2023-10-14 290: ct=ct+1
8c706ff713 2023-10-14 291: local res=Auxiliary.SynMixCheckGoal(tp,sg,minc,ct,syncard,sg1,smat,gc,mgchk)
8c706ff713 2023-10-14 292: or (ct<maxc and mg:IsExists(Auxiliary.SynMixCheckRecursive,1,sg,tp,sg,mg,ct,minc,maxc,syncard,sg1,smat,gc,mgchk))
8c706ff713 2023-10-14 293: sg:RemoveCard(c)
8c706ff713 2023-10-14 294: ct=ct-1
8c706ff713 2023-10-14 295: return res
8c706ff713 2023-10-14 296: end
8c706ff713 2023-10-14 297: -- the material is in hand and don't has extra synchro material effect itself
8c706ff713 2023-10-14 298: -- that mean some other tuner added it as material
8c706ff713 2023-10-14 299: function Auxiliary.SynMixHandFilter(c,tp,syncard)
8c706ff713 2023-10-14 300: if not c:IsLocation(LOCATION_HAND) then return false end
8c706ff713 2023-10-14 301: local le={c:IsHasEffect(EFFECT_EXTRA_SYNCHRO_MATERIAL,tp)}
8c706ff713 2023-10-14 302: for _,te in pairs(le) do
8c706ff713 2023-10-14 303: local tf=te:GetValue()
8c706ff713 2023-10-14 304: if Auxiliary.GetValueType(tf)=="function" then
8c706ff713 2023-10-14 305: if tf(te,syncard) then return false end
8c706ff713 2023-10-14 306: else
8c706ff713 2023-10-14 307: if tf~=0 then return false end
8c706ff713 2023-10-14 308: end
8c706ff713 2023-10-14 309: end
8c706ff713 2023-10-14 310: return true
8c706ff713 2023-10-14 311: end
8c706ff713 2023-10-14 312: function Auxiliary.SynMixCheckGoal(tp,sg,minc,ct,syncard,sg1,smat,gc,mgchk)
8c706ff713 2023-10-14 313: if ct<minc then return false end
8c706ff713 2023-10-14 314: local g=sg:Clone()
8c706ff713 2023-10-14 315: g:Merge(sg1)
8c706ff713 2023-10-14 316: if Duel.GetLocationCountFromEx(tp,tp,g,syncard)<=0 then return false end
8c706ff713 2023-10-14 317: if gc and not gc(g) then return false end
8c706ff713 2023-10-14 318: if smat and not g:IsContains(smat) then return false end
8c706ff713 2023-10-14 319: if not Auxiliary.MustMaterialCheck(g,tp,EFFECT_MUST_BE_SMATERIAL) then return false end
8c706ff713 2023-10-14 320: if not g:CheckWithSumEqual(Card.GetSynchroLevel,syncard:GetLevel(),g:GetCount(),g:GetCount(),syncard)
8c706ff713 2023-10-14 321: and (not g:IsExists(Card.IsHasEffect,1,nil,89818984)
8c706ff713 2023-10-14 322: or not g:CheckWithSumEqual(Auxiliary.GetSynchroLevelFlowerCardian,syncard:GetLevel(),g:GetCount(),g:GetCount(),syncard))
8c706ff713 2023-10-14 323: then return false end
8c706ff713 2023-10-14 324: local hg=g:Filter(Auxiliary.SynMixHandFilter,nil,tp,syncard)
8c706ff713 2023-10-14 325: local hct=hg:GetCount()
8c706ff713 2023-10-14 326: if hct>0 and not mgchk then
8c706ff713 2023-10-14 327: local found=false
8c706ff713 2023-10-14 328: for c in aux.Next(g) do
8c706ff713 2023-10-14 329: local he,hf,hmin,hmax=c:GetHandSynchro()
8c706ff713 2023-10-14 330: if he then
8c706ff713 2023-10-14 331: found=true
8c706ff713 2023-10-14 332: if hf and hg:IsExists(Auxiliary.SynLimitFilter,1,c,hf,he,syncard) then return false end
8c706ff713 2023-10-14 333: if (hmin and hct<hmin) or (hmax and hct>hmax) then return false end
8c706ff713 2023-10-14 334: end
8c706ff713 2023-10-14 335: end
8c706ff713 2023-10-14 336: if not found then return false end
8c706ff713 2023-10-14 337: end
8c706ff713 2023-10-14 338: for c in aux.Next(g) do
8c706ff713 2023-10-14 339: local le,lf,lloc,lmin,lmax=c:GetTunerLimit()
8c706ff713 2023-10-14 340: if le then
8c706ff713 2023-10-14 341: local lct=g:GetCount()-1
8c706ff713 2023-10-14 342: if lloc then
8c706ff713 2023-10-14 343: local llct=g:FilterCount(Card.IsLocation,c,lloc)
8c706ff713 2023-10-14 344: if llct~=lct then return false end
8c706ff713 2023-10-14 345: end
8c706ff713 2023-10-14 346: if lf and g:IsExists(Auxiliary.SynLimitFilter,1,c,lf,le,syncard) then return false end
8c706ff713 2023-10-14 347: if (lmin and lct<lmin) or (lmax and lct>lmax) then return false end
8c706ff713 2023-10-14 348: end
8c706ff713 2023-10-14 349: end
8c706ff713 2023-10-14 350: return true
8c706ff713 2023-10-14 351: end
8c706ff713 2023-10-14 352: --Checking Tune Magician
8c706ff713 2023-10-14 353: function Auxiliary.TuneMagicianFilter(c,e)
8c706ff713 2023-10-14 354: local f=e:GetValue()
8c706ff713 2023-10-14 355: return f(e,c)
8c706ff713 2023-10-14 356: end
8c706ff713 2023-10-14 357: function Auxiliary.TuneMagicianCheckX(c,sg,ecode)
8c706ff713 2023-10-14 358: local eset={c:IsHasEffect(ecode)}
8c706ff713 2023-10-14 359: for _,te in pairs(eset) do
8c706ff713 2023-10-14 360: if sg:IsExists(Auxiliary.TuneMagicianFilter,1,c,te) then return true end
8c706ff713 2023-10-14 361: end
8c706ff713 2023-10-14 362: return false
8c706ff713 2023-10-14 363: end
8c706ff713 2023-10-14 364: function Auxiliary.TuneMagicianCheckAdditionalX(ecode)
8c706ff713 2023-10-14 365: return function(g)
8c706ff713 2023-10-14 366: return not g:IsExists(Auxiliary.TuneMagicianCheckX,1,nil,g,ecode)
8c706ff713 2023-10-14 367: end
8c706ff713 2023-10-14 368: end
8c706ff713 2023-10-14 369:
8c706ff713 2023-10-14 370: --Xyz Summon
8c706ff713 2023-10-14 371: function Auxiliary.XyzAlterFilter(c,alterf,xyzc,e,tp,alterop)
8c706ff713 2023-10-14 372: return alterf(c,e,tp,xyzc) and c:IsCanBeXyzMaterial(xyzc) and Duel.GetLocationCountFromEx(tp,tp,c,xyzc)>0
8c706ff713 2023-10-14 373: and Auxiliary.MustMaterialCheck(c,tp,EFFECT_MUST_BE_XMATERIAL) and (not alterop or alterop(e,tp,0,c))
8c706ff713 2023-10-14 374: end
8c706ff713 2023-10-14 375: --Xyz monster, lv k*n
8c706ff713 2023-10-14 376: function Auxiliary.AddXyzProcedure(c,f,lv,ct,alterf,alterdesc,maxct,alterop)
8c706ff713 2023-10-14 377: local e1=Effect.CreateEffect(c)
8c706ff713 2023-10-14 378: e1:SetDescription(1165)
8c706ff713 2023-10-14 379: e1:SetType(EFFECT_TYPE_FIELD)
8c706ff713 2023-10-14 380: e1:SetCode(EFFECT_SPSUMMON_PROC)
8c706ff713 2023-10-14 381: e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
8c706ff713 2023-10-14 382: e1:SetRange(LOCATION_EXTRA)
8c706ff713 2023-10-14 383: if not maxct then maxct=ct end
8c706ff713 2023-10-14 384: if alterf then
8c706ff713 2023-10-14 385: e1:SetCondition(Auxiliary.XyzConditionAlter(f,lv,ct,maxct,alterf,alterdesc,alterop))
8c706ff713 2023-10-14 386: e1:SetTarget(Auxiliary.XyzTargetAlter(f,lv,ct,maxct,alterf,alterdesc,alterop))
8c706ff713 2023-10-14 387: e1:SetOperation(Auxiliary.XyzOperationAlter(f,lv,ct,maxct,alterf,alterdesc,alterop))
8c706ff713 2023-10-14 388: else
8c706ff713 2023-10-14 389: e1:SetCondition(Auxiliary.XyzCondition(f,lv,ct,maxct))
8c706ff713 2023-10-14 390: e1:SetTarget(Auxiliary.XyzTarget(f,lv,ct,maxct))
8c706ff713 2023-10-14 391: e1:SetOperation(Auxiliary.XyzOperation(f,lv,ct,maxct))
8c706ff713 2023-10-14 392: end
8c706ff713 2023-10-14 393: e1:SetValue(SUMMON_TYPE_XYZ)
8c706ff713 2023-10-14 394: c:RegisterEffect(e1)
8c706ff713 2023-10-14 395: end
8c706ff713 2023-10-14 396: --Xyz Summon(normal)
8c706ff713 2023-10-14 397: function Auxiliary.XyzCondition(f,lv,minc,maxc)
8c706ff713 2023-10-14 398: --og: use special material
8c706ff713 2023-10-14 399: return function(e,c,og,min,max)
8c706ff713 2023-10-14 400: if c==nil then return true end
8c706ff713 2023-10-14 401: if c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end
8c706ff713 2023-10-14 402: local tp=c:GetControler()
8c706ff713 2023-10-14 403: local minc=minc
8c706ff713 2023-10-14 404: local maxc=maxc
8c706ff713 2023-10-14 405: if min then
8c706ff713 2023-10-14 406: if min>minc then minc=min end
8c706ff713 2023-10-14 407: if max<maxc then maxc=max end
8c706ff713 2023-10-14 408: if minc>maxc then return false end
8c706ff713 2023-10-14 409: end
8c706ff713 2023-10-14 410: return Duel.CheckXyzMaterial(c,f,lv,minc,maxc,og)
8c706ff713 2023-10-14 411: end
8c706ff713 2023-10-14 412: end
8c706ff713 2023-10-14 413: function Auxiliary.XyzTarget(f,lv,minc,maxc)
8c706ff713 2023-10-14 414: return function(e,tp,eg,ep,ev,re,r,rp,chk,c,og,min,max)
8c706ff713 2023-10-14 415: if og and not min then
8c706ff713 2023-10-14 416: return true
8c706ff713 2023-10-14 417: end
8c706ff713 2023-10-14 418: local minc=minc
8c706ff713 2023-10-14 419: local maxc=maxc
8c706ff713 2023-10-14 420: if min then
8c706ff713 2023-10-14 421: if min>minc then minc=min end
8c706ff713 2023-10-14 422: if max<maxc then maxc=max end
8c706ff713 2023-10-14 423: end
8c706ff713 2023-10-14 424: local g=Duel.SelectXyzMaterial(tp,c,f,lv,minc,maxc,og)
8c706ff713 2023-10-14 425: if g then
8c706ff713 2023-10-14 426: g:KeepAlive()
8c706ff713 2023-10-14 427: e:SetLabelObject(g)
8c706ff713 2023-10-14 428: return true
8c706ff713 2023-10-14 429: else return false end
8c706ff713 2023-10-14 430: end
8c706ff713 2023-10-14 431: end
8c706ff713 2023-10-14 432: function Auxiliary.XyzOperation(f,lv,minc,maxc)
8c706ff713 2023-10-14 433: return function(e,tp,eg,ep,ev,re,r,rp,c,og,min,max)
8c706ff713 2023-10-14 434: if og and not min then
8c706ff713 2023-10-14 435: local sg=Group.CreateGroup()
8c706ff713 2023-10-14 436: local tc=og:GetFirst()
8c706ff713 2023-10-14 437: while tc do
8c706ff713 2023-10-14 438: local sg1=tc:GetOverlayGroup()
8c706ff713 2023-10-14 439: sg:Merge(sg1)
8c706ff713 2023-10-14 440: tc=og:GetNext()
8c706ff713 2023-10-14 441: end
8c706ff713 2023-10-14 442: Duel.SendtoGrave(sg,REASON_RULE)
8c706ff713 2023-10-14 443: c:SetMaterial(og)
8c706ff713 2023-10-14 444: Duel.Overlay(c,og)
8c706ff713 2023-10-14 445: else
8c706ff713 2023-10-14 446: local mg=e:GetLabelObject()
8c706ff713 2023-10-14 447: local sg=Group.CreateGroup()
8c706ff713 2023-10-14 448: local tc=mg:GetFirst()
8c706ff713 2023-10-14 449: while tc do
8c706ff713 2023-10-14 450: local sg1=tc:GetOverlayGroup()
8c706ff713 2023-10-14 451: sg:Merge(sg1)
8c706ff713 2023-10-14 452: tc=mg:GetNext()
8c706ff713 2023-10-14 453: end
8c706ff713 2023-10-14 454: Duel.SendtoGrave(sg,REASON_RULE)
8c706ff713 2023-10-14 455: c:SetMaterial(mg)
8c706ff713 2023-10-14 456: Duel.Overlay(c,mg)
8c706ff713 2023-10-14 457: mg:DeleteGroup()
8c706ff713 2023-10-14 458: end
8c706ff713 2023-10-14 459: end
8c706ff713 2023-10-14 460: end
8c706ff713 2023-10-14 461: --Xyz summon(alterf)
8c706ff713 2023-10-14 462: function Auxiliary.XyzConditionAlter(f,lv,minc,maxc,alterf,alterdesc,alterop)
8c706ff713 2023-10-14 463: return function(e,c,og,min,max)
8c706ff713 2023-10-14 464: if c==nil then return true end
8c706ff713 2023-10-14 465: if c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end
8c706ff713 2023-10-14 466: local tp=c:GetControler()
8c706ff713 2023-10-14 467: local mg=nil
8c706ff713 2023-10-14 468: if og then
8c706ff713 2023-10-14 469: mg=og
8c706ff713 2023-10-14 470: else
8c706ff713 2023-10-14 471: mg=Duel.GetFieldGroup(tp,LOCATION_MZONE,0)
8c706ff713 2023-10-14 472: end
8c706ff713 2023-10-14 473: if (not min or min<=1) and mg:IsExists(Auxiliary.XyzAlterFilter,1,nil,alterf,c,e,tp,alterop) then
8c706ff713 2023-10-14 474: return true
8c706ff713 2023-10-14 475: end
8c706ff713 2023-10-14 476: local minc=minc
8c706ff713 2023-10-14 477: local maxc=maxc
8c706ff713 2023-10-14 478: if min then
8c706ff713 2023-10-14 479: if min>minc then minc=min end
8c706ff713 2023-10-14 480: if max<maxc then maxc=max end
8c706ff713 2023-10-14 481: if minc>maxc then return false end
8c706ff713 2023-10-14 482: end
8c706ff713 2023-10-14 483: return Duel.CheckXyzMaterial(c,f,lv,minc,maxc,og)
8c706ff713 2023-10-14 484: end
8c706ff713 2023-10-14 485: end
8c706ff713 2023-10-14 486: function Auxiliary.XyzTargetAlter(f,lv,minc,maxc,alterf,alterdesc,alterop)
8c706ff713 2023-10-14 487: return function(e,tp,eg,ep,ev,re,r,rp,chk,c,og,min,max)
8c706ff713 2023-10-14 488: if og and not min then
8c706ff713 2023-10-14 489: return true
8c706ff713 2023-10-14 490: end
8c706ff713 2023-10-14 491: local minc=minc
8c706ff713 2023-10-14 492: local maxc=maxc
8c706ff713 2023-10-14 493: if min then
8c706ff713 2023-10-14 494: if min>minc then minc=min end
8c706ff713 2023-10-14 495: if max<maxc then maxc=max end
8c706ff713 2023-10-14 496: end
8c706ff713 2023-10-14 497: local mg=nil
8c706ff713 2023-10-14 498: if og then
8c706ff713 2023-10-14 499: mg=og
8c706ff713 2023-10-14 500: else
8c706ff713 2023-10-14 501: mg=Duel.GetFieldGroup(tp,LOCATION_MZONE,0)
8c706ff713 2023-10-14 502: end
8c706ff713 2023-10-14 503: local altg=mg:Filter(Auxiliary.XyzAlterFilter,nil,alterf,c,e,tp,alterop)
8c706ff713 2023-10-14 504: local b1=Duel.CheckXyzMaterial(c,f,lv,minc,maxc,og)
8c706ff713 2023-10-14 505: local b2=(not min or min<=1) and #altg>0
8c706ff713 2023-10-14 506: local g=nil
8c706ff713 2023-10-14 507: local cancel=Duel.IsSummonCancelable()
8c706ff713 2023-10-14 508: if b2 and (not b1 or Duel.SelectYesNo(tp,alterdesc)) then
8c706ff713 2023-10-14 509: e:SetLabel(1)
8c706ff713 2023-10-14 510: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_XMATERIAL)
8c706ff713 2023-10-14 511: local tc=altg:SelectUnselect(nil,tp,false,cancel,1,1)
8c706ff713 2023-10-14 512: if tc then
8c706ff713 2023-10-14 513: g=Group.FromCards(tc)
8c706ff713 2023-10-14 514: if alterop then alterop(e,tp,1,tc) end
8c706ff713 2023-10-14 515: end
8c706ff713 2023-10-14 516: else
8c706ff713 2023-10-14 517: e:SetLabel(0)
8c706ff713 2023-10-14 518: g=Duel.SelectXyzMaterial(tp,c,f,lv,minc,maxc,og)
8c706ff713 2023-10-14 519: end
8c706ff713 2023-10-14 520: if g then
8c706ff713 2023-10-14 521: g:KeepAlive()
8c706ff713 2023-10-14 522: e:SetLabelObject(g)
8c706ff713 2023-10-14 523: return true
8c706ff713 2023-10-14 524: else return false end
8c706ff713 2023-10-14 525: end
8c706ff713 2023-10-14 526: end
8c706ff713 2023-10-14 527: function Auxiliary.XyzOperationAlter(f,lv,minc,maxc,alterf,alterdesc,alterop)
8c706ff713 2023-10-14 528: return function(e,tp,eg,ep,ev,re,r,rp,c,og,min,max)
8c706ff713 2023-10-14 529: if og and not min then
8c706ff713 2023-10-14 530: local sg=Group.CreateGroup()
8c706ff713 2023-10-14 531: local tc=og:GetFirst()
8c706ff713 2023-10-14 532: while tc do
8c706ff713 2023-10-14 533: local sg1=tc:GetOverlayGroup()
8c706ff713 2023-10-14 534: sg:Merge(sg1)
8c706ff713 2023-10-14 535: tc=og:GetNext()
8c706ff713 2023-10-14 536: end
8c706ff713 2023-10-14 537: Duel.SendtoGrave(sg,REASON_RULE)
8c706ff713 2023-10-14 538: c:SetMaterial(og)
8c706ff713 2023-10-14 539: Duel.Overlay(c,og)
8c706ff713 2023-10-14 540: else
8c706ff713 2023-10-14 541: local mg=e:GetLabelObject()
8c706ff713 2023-10-14 542: if e:GetLabel()==1 then
8c706ff713 2023-10-14 543: local mg2=mg:GetFirst():GetOverlayGroup()
8c706ff713 2023-10-14 544: if mg2:GetCount()~=0 then
8c706ff713 2023-10-14 545: Duel.Overlay(c,mg2)
8c706ff713 2023-10-14 546: end
8c706ff713 2023-10-14 547: else
8c706ff713 2023-10-14 548: local sg=Group.CreateGroup()
8c706ff713 2023-10-14 549: local tc=mg:GetFirst()
8c706ff713 2023-10-14 550: while tc do
8c706ff713 2023-10-14 551: local sg1=tc:GetOverlayGroup()
8c706ff713 2023-10-14 552: sg:Merge(sg1)
8c706ff713 2023-10-14 553: tc=mg:GetNext()
8c706ff713 2023-10-14 554: end
8c706ff713 2023-10-14 555: Duel.SendtoGrave(sg,REASON_RULE)
8c706ff713 2023-10-14 556: end
8c706ff713 2023-10-14 557: c:SetMaterial(mg)
8c706ff713 2023-10-14 558: Duel.Overlay(c,mg)
8c706ff713 2023-10-14 559: mg:DeleteGroup()
8c706ff713 2023-10-14 560: end
8c706ff713 2023-10-14 561: end
8c706ff713 2023-10-14 562: end
8c706ff713 2023-10-14 563: function Auxiliary.AddXyzProcedureLevelFree(c,f,gf,minc,maxc,alterf,alterdesc,alterop)
8c706ff713 2023-10-14 564: local e1=Effect.CreateEffect(c)
8c706ff713 2023-10-14 565: e1:SetDescription(1165)
8c706ff713 2023-10-14 566: e1:SetType(EFFECT_TYPE_FIELD)
8c706ff713 2023-10-14 567: e1:SetCode(EFFECT_SPSUMMON_PROC)
8c706ff713 2023-10-14 568: e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
8c706ff713 2023-10-14 569: e1:SetRange(LOCATION_EXTRA)
8c706ff713 2023-10-14 570: if alterf then
8c706ff713 2023-10-14 571: e1:SetCondition(Auxiliary.XyzLevelFreeConditionAlter(f,gf,minc,maxc,alterf,alterdesc,alterop))
8c706ff713 2023-10-14 572: e1:SetTarget(Auxiliary.XyzLevelFreeTargetAlter(f,gf,minc,maxc,alterf,alterdesc,alterop))
8c706ff713 2023-10-14 573: e1:SetOperation(Auxiliary.XyzLevelFreeOperationAlter(f,gf,minc,maxc,alterf,alterdesc,alterop))
8c706ff713 2023-10-14 574: else
8c706ff713 2023-10-14 575: e1:SetCondition(Auxiliary.XyzLevelFreeCondition(f,gf,minc,maxc))
8c706ff713 2023-10-14 576: e1:SetTarget(Auxiliary.XyzLevelFreeTarget(f,gf,minc,maxc))
8c706ff713 2023-10-14 577: e1:SetOperation(Auxiliary.XyzLevelFreeOperation(f,gf,minc,maxc))
8c706ff713 2023-10-14 578: end
8c706ff713 2023-10-14 579: e1:SetValue(SUMMON_TYPE_XYZ)
8c706ff713 2023-10-14 580: c:RegisterEffect(e1)
8c706ff713 2023-10-14 581: end
8c706ff713 2023-10-14 582: --Xyz Summon(level free)
8c706ff713 2023-10-14 583: function Auxiliary.XyzLevelFreeFilter(c,xyzc,f)
8c706ff713 2023-10-14 584: return (not c:IsOnField() or c:IsFaceup()) and c:IsCanBeXyzMaterial(xyzc) and (not f or f(c,xyzc))
8c706ff713 2023-10-14 585: end
8c706ff713 2023-10-14 586: function Auxiliary.XyzLevelFreeGoal(g,tp,xyzc,gf)
8c706ff713 2023-10-14 587: return (not gf or gf(g)) and Duel.GetLocationCountFromEx(tp,tp,g,xyzc)>0
8c706ff713 2023-10-14 588: end
8c706ff713 2023-10-14 589: function Auxiliary.XyzLevelFreeCondition(f,gf,minct,maxct)
8c706ff713 2023-10-14 590: return function(e,c,og,min,max)
8c706ff713 2023-10-14 591: if c==nil then return true end
8c706ff713 2023-10-14 592: if c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end
8c706ff713 2023-10-14 593: local tp=c:GetControler()
8c706ff713 2023-10-14 594: local minc=minct
8c706ff713 2023-10-14 595: local maxc=maxct
8c706ff713 2023-10-14 596: if min then
8c706ff713 2023-10-14 597: minc=math.max(minc,min)
8c706ff713 2023-10-14 598: maxc=math.min(maxc,max)
8c706ff713 2023-10-14 599: end
8c706ff713 2023-10-14 600: if maxc<minc then return false end
8c706ff713 2023-10-14 601: local mg=nil
8c706ff713 2023-10-14 602: if og then
8c706ff713 2023-10-14 603: mg=og:Filter(Auxiliary.XyzLevelFreeFilter,nil,c,f)
8c706ff713 2023-10-14 604: else
8c706ff713 2023-10-14 605: mg=Duel.GetMatchingGroup(Auxiliary.XyzLevelFreeFilter,tp,LOCATION_MZONE,0,nil,c,f)
8c706ff713 2023-10-14 606: end
8c706ff713 2023-10-14 607: local sg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_XMATERIAL)
8c706ff713 2023-10-14 608: if sg:IsExists(Auxiliary.MustMaterialCounterFilter,1,nil,mg) then return false end
8c706ff713 2023-10-14 609: Duel.SetSelectedCard(sg)
8c706ff713 2023-10-14 610: Auxiliary.GCheckAdditional=Auxiliary.TuneMagicianCheckAdditionalX(EFFECT_TUNE_MAGICIAN_X)
8c706ff713 2023-10-14 611: local res=mg:CheckSubGroup(Auxiliary.XyzLevelFreeGoal,minc,maxc,tp,c,gf)
8c706ff713 2023-10-14 612: Auxiliary.GCheckAdditional=nil
8c706ff713 2023-10-14 613: return res
8c706ff713 2023-10-14 614: end
8c706ff713 2023-10-14 615: end
8c706ff713 2023-10-14 616: function Auxiliary.XyzLevelFreeTarget(f,gf,minct,maxct)
8c706ff713 2023-10-14 617: return function(e,tp,eg,ep,ev,re,r,rp,chk,c,og,min,max)
8c706ff713 2023-10-14 618: if og and not min then
8c706ff713 2023-10-14 619: return true
8c706ff713 2023-10-14 620: end
8c706ff713 2023-10-14 621: local minc=minct
8c706ff713 2023-10-14 622: local maxc=maxct
8c706ff713 2023-10-14 623: if min then
8c706ff713 2023-10-14 624: if min>minc then minc=min end
8c706ff713 2023-10-14 625: if max<maxc then maxc=max end
8c706ff713 2023-10-14 626: end
8c706ff713 2023-10-14 627: local mg=nil
8c706ff713 2023-10-14 628: if og then
8c706ff713 2023-10-14 629: mg=og:Filter(Auxiliary.XyzLevelFreeFilter,nil,c,f)
8c706ff713 2023-10-14 630: else
8c706ff713 2023-10-14 631: mg=Duel.GetMatchingGroup(Auxiliary.XyzLevelFreeFilter,tp,LOCATION_MZONE,0,nil,c,f)
8c706ff713 2023-10-14 632: end
8c706ff713 2023-10-14 633: local sg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_XMATERIAL)
8c706ff713 2023-10-14 634: Duel.SetSelectedCard(sg)
8c706ff713 2023-10-14 635: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_XMATERIAL)
8c706ff713 2023-10-14 636: local cancel=Duel.IsSummonCancelable()
8c706ff713 2023-10-14 637: Auxiliary.GCheckAdditional=Auxiliary.TuneMagicianCheckAdditionalX(EFFECT_TUNE_MAGICIAN_X)
8c706ff713 2023-10-14 638: local g=mg:SelectSubGroup(tp,Auxiliary.XyzLevelFreeGoal,cancel,minc,maxc,tp,c,gf)
8c706ff713 2023-10-14 639: Auxiliary.GCheckAdditional=nil
8c706ff713 2023-10-14 640: if g and g:GetCount()>0 then
8c706ff713 2023-10-14 641: g:KeepAlive()
8c706ff713 2023-10-14 642: e:SetLabelObject(g)
8c706ff713 2023-10-14 643: return true
8c706ff713 2023-10-14 644: else return false end
8c706ff713 2023-10-14 645: end
8c706ff713 2023-10-14 646: end
8c706ff713 2023-10-14 647: function Auxiliary.XyzLevelFreeOperation(f,gf,minct,maxct)
8c706ff713 2023-10-14 648: return function(e,tp,eg,ep,ev,re,r,rp,c,og,min,max)
8c706ff713 2023-10-14 649: if og and not min then
8c706ff713 2023-10-14 650: local sg=Group.CreateGroup()
8c706ff713 2023-10-14 651: local tc=og:GetFirst()
8c706ff713 2023-10-14 652: while tc do
8c706ff713 2023-10-14 653: local sg1=tc:GetOverlayGroup()
8c706ff713 2023-10-14 654: sg:Merge(sg1)
8c706ff713 2023-10-14 655: tc=og:GetNext()
8c706ff713 2023-10-14 656: end
8c706ff713 2023-10-14 657: Duel.SendtoGrave(sg,REASON_RULE)
8c706ff713 2023-10-14 658: c:SetMaterial(og)
8c706ff713 2023-10-14 659: Duel.Overlay(c,og)
8c706ff713 2023-10-14 660: else
8c706ff713 2023-10-14 661: local mg=e:GetLabelObject()
8c706ff713 2023-10-14 662: if e:GetLabel()==1 then
8c706ff713 2023-10-14 663: local mg2=mg:GetFirst():GetOverlayGroup()
8c706ff713 2023-10-14 664: if mg2:GetCount()~=0 then
8c706ff713 2023-10-14 665: Duel.Overlay(c,mg2)
8c706ff713 2023-10-14 666: end
8c706ff713 2023-10-14 667: else
8c706ff713 2023-10-14 668: local sg=Group.CreateGroup()
8c706ff713 2023-10-14 669: local tc=mg:GetFirst()
8c706ff713 2023-10-14 670: while tc do
8c706ff713 2023-10-14 671: local sg1=tc:GetOverlayGroup()
8c706ff713 2023-10-14 672: sg:Merge(sg1)
8c706ff713 2023-10-14 673: tc=mg:GetNext()
8c706ff713 2023-10-14 674: end
8c706ff713 2023-10-14 675: Duel.SendtoGrave(sg,REASON_RULE)
8c706ff713 2023-10-14 676: end
8c706ff713 2023-10-14 677: c:SetMaterial(mg)
8c706ff713 2023-10-14 678: Duel.Overlay(c,mg)
8c706ff713 2023-10-14 679: mg:DeleteGroup()
8c706ff713 2023-10-14 680: end
8c706ff713 2023-10-14 681: end
8c706ff713 2023-10-14 682: end
8c706ff713 2023-10-14 683: --Xyz summon(level free&alterf)
8c706ff713 2023-10-14 684: function Auxiliary.XyzLevelFreeConditionAlter(f,gf,minct,maxct,alterf,alterdesc,alterop)
8c706ff713 2023-10-14 685: return function(e,c,og,min,max)
8c706ff713 2023-10-14 686: if c==nil then return true end
8c706ff713 2023-10-14 687: if c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end
8c706ff713 2023-10-14 688: local tp=c:GetControler()
8c706ff713 2023-10-14 689: local mg=nil
8c706ff713 2023-10-14 690: if og then
8c706ff713 2023-10-14 691: mg=og
8c706ff713 2023-10-14 692: else
8c706ff713 2023-10-14 693: mg=Duel.GetFieldGroup(tp,LOCATION_MZONE,0)
8c706ff713 2023-10-14 694: end
8c706ff713 2023-10-14 695: local altg=mg:Filter(Auxiliary.XyzAlterFilter,nil,alterf,c,e,tp,alterop)
8c706ff713 2023-10-14 696: if (not min or min<=1) and altg:GetCount()>0 then
8c706ff713 2023-10-14 697: return true
8c706ff713 2023-10-14 698: end
8c706ff713 2023-10-14 699: local minc=minct
8c706ff713 2023-10-14 700: local maxc=maxct
8c706ff713 2023-10-14 701: if min then
8c706ff713 2023-10-14 702: if min>minc then minc=min end
8c706ff713 2023-10-14 703: if max<maxc then maxc=max end
8c706ff713 2023-10-14 704: if minc>maxc then return false end
8c706ff713 2023-10-14 705: end
8c706ff713 2023-10-14 706: mg=mg:Filter(Auxiliary.XyzLevelFreeFilter,nil,c,f)
8c706ff713 2023-10-14 707: local sg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_XMATERIAL)
8c706ff713 2023-10-14 708: if sg:IsExists(Auxiliary.MustMaterialCounterFilter,1,nil,mg) then return false end
8c706ff713 2023-10-14 709: Duel.SetSelectedCard(sg)
8c706ff713 2023-10-14 710: Auxiliary.GCheckAdditional=Auxiliary.TuneMagicianCheckAdditionalX(EFFECT_TUNE_MAGICIAN_X)
8c706ff713 2023-10-14 711: local res=mg:CheckSubGroup(Auxiliary.XyzLevelFreeGoal,minc,maxc,tp,c,gf)
8c706ff713 2023-10-14 712: Auxiliary.GCheckAdditional=nil
8c706ff713 2023-10-14 713: return res
8c706ff713 2023-10-14 714: end
8c706ff713 2023-10-14 715: end
8c706ff713 2023-10-14 716: function Auxiliary.XyzLevelFreeTargetAlter(f,gf,minct,maxct,alterf,alterdesc,alterop)
8c706ff713 2023-10-14 717: return function(e,tp,eg,ep,ev,re,r,rp,chk,c,og,min,max)
8c706ff713 2023-10-14 718: if og and not min then
8c706ff713 2023-10-14 719: return true
8c706ff713 2023-10-14 720: end
8c706ff713 2023-10-14 721: local minc=minct
8c706ff713 2023-10-14 722: local maxc=maxct
8c706ff713 2023-10-14 723: if min then
8c706ff713 2023-10-14 724: if min>minc then minc=min end
8c706ff713 2023-10-14 725: if max<maxc then maxc=max end
8c706ff713 2023-10-14 726: end
8c706ff713 2023-10-14 727: local mg=nil
8c706ff713 2023-10-14 728: if og then
8c706ff713 2023-10-14 729: mg=og
8c706ff713 2023-10-14 730: else
8c706ff713 2023-10-14 731: mg=Duel.GetFieldGroup(tp,LOCATION_MZONE,0)
8c706ff713 2023-10-14 732: end
8c706ff713 2023-10-14 733: local sg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_XMATERIAL)
8c706ff713 2023-10-14 734: local altg=mg:Filter(Auxiliary.XyzAlterFilter,nil,alterf,c,e,tp,alterop)
8c706ff713 2023-10-14 735: local mg2=mg:Filter(Auxiliary.XyzLevelFreeFilter,nil,c,f)
8c706ff713 2023-10-14 736: Duel.SetSelectedCard(sg)
8c706ff713 2023-10-14 737: local b1=mg2:CheckSubGroup(Auxiliary.XyzLevelFreeGoal,minc,maxc,tp,c,gf)
8c706ff713 2023-10-14 738: local b2=(not min or min<=1) and #altg>0
8c706ff713 2023-10-14 739: local g=nil
8c706ff713 2023-10-14 740: local cancel=Duel.IsSummonCancelable()
8c706ff713 2023-10-14 741: if b2 and (not b1 or Duel.SelectYesNo(tp,alterdesc)) then
8c706ff713 2023-10-14 742: e:SetLabel(1)
8c706ff713 2023-10-14 743: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_XMATERIAL)
8c706ff713 2023-10-14 744: local tc=altg:SelectUnselect(nil,tp,false,cancel,1,1)
8c706ff713 2023-10-14 745: if tc then
8c706ff713 2023-10-14 746: g=Group.FromCards(tc)
8c706ff713 2023-10-14 747: if alterop then alterop(e,tp,1,tc) end
8c706ff713 2023-10-14 748: end
8c706ff713 2023-10-14 749: else
8c706ff713 2023-10-14 750: e:SetLabel(0)
8c706ff713 2023-10-14 751: Duel.SetSelectedCard(sg)
8c706ff713 2023-10-14 752: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_XMATERIAL)
8c706ff713 2023-10-14 753: Auxiliary.GCheckAdditional=Auxiliary.TuneMagicianCheckAdditionalX(EFFECT_TUNE_MAGICIAN_X)
8c706ff713 2023-10-14 754: g=mg2:SelectSubGroup(tp,Auxiliary.XyzLevelFreeGoal,cancel,minc,maxc,tp,c,gf)
8c706ff713 2023-10-14 755: Auxiliary.GCheckAdditional=nil
8c706ff713 2023-10-14 756: end
8c706ff713 2023-10-14 757: if g and g:GetCount()>0 then
8c706ff713 2023-10-14 758: g:KeepAlive()
8c706ff713 2023-10-14 759: e:SetLabelObject(g)
8c706ff713 2023-10-14 760: return true
8c706ff713 2023-10-14 761: else return false end
8c706ff713 2023-10-14 762: end
8c706ff713 2023-10-14 763: end
8c706ff713 2023-10-14 764: function Auxiliary.XyzLevelFreeOperationAlter(f,gf,minct,maxct,alterf,alterdesc,alterop)
8c706ff713 2023-10-14 765: return function(e,tp,eg,ep,ev,re,r,rp,c,og,min,max)
8c706ff713 2023-10-14 766: if og and not min then
8c706ff713 2023-10-14 767: local sg=Group.CreateGroup()
8c706ff713 2023-10-14 768: local tc=og:GetFirst()
8c706ff713 2023-10-14 769: while tc do
8c706ff713 2023-10-14 770: local sg1=tc:GetOverlayGroup()
8c706ff713 2023-10-14 771: sg:Merge(sg1)
8c706ff713 2023-10-14 772: tc=og:GetNext()
8c706ff713 2023-10-14 773: end
8c706ff713 2023-10-14 774: Duel.SendtoGrave(sg,REASON_RULE)
8c706ff713 2023-10-14 775: c:SetMaterial(og)
8c706ff713 2023-10-14 776: Duel.Overlay(c,og)
8c706ff713 2023-10-14 777: else
8c706ff713 2023-10-14 778: local mg=e:GetLabelObject()
8c706ff713 2023-10-14 779: if e:GetLabel()==1 then
8c706ff713 2023-10-14 780: local mg2=mg:GetFirst():GetOverlayGroup()
8c706ff713 2023-10-14 781: if mg2:GetCount()~=0 then
8c706ff713 2023-10-14 782: Duel.Overlay(c,mg2)
8c706ff713 2023-10-14 783: end
8c706ff713 2023-10-14 784: else
8c706ff713 2023-10-14 785: local sg=Group.CreateGroup()
8c706ff713 2023-10-14 786: local tc=mg:GetFirst()
8c706ff713 2023-10-14 787: while tc do
8c706ff713 2023-10-14 788: local sg1=tc:GetOverlayGroup()
8c706ff713 2023-10-14 789: sg:Merge(sg1)
8c706ff713 2023-10-14 790: tc=mg:GetNext()
8c706ff713 2023-10-14 791: end
8c706ff713 2023-10-14 792: Duel.SendtoGrave(sg,REASON_RULE)
8c706ff713 2023-10-14 793: end
8c706ff713 2023-10-14 794: c:SetMaterial(mg)
8c706ff713 2023-10-14 795: Duel.Overlay(c,mg)
8c706ff713 2023-10-14 796: mg:DeleteGroup()
8c706ff713 2023-10-14 797: end
8c706ff713 2023-10-14 798: end
8c706ff713 2023-10-14 799: end
8c706ff713 2023-10-14 800:
8c706ff713 2023-10-14 801: --Fusion Summon
8c706ff713 2023-10-14 802: --material: names in material list
8c706ff713 2023-10-14 803: --Fusion monster, mixed materials
8c706ff713 2023-10-14 804: function Auxiliary.AddFusionProcMix(c,sub,insf,...)
8c706ff713 2023-10-14 805: if c:IsStatus(STATUS_COPYING_EFFECT) then return end
8c706ff713 2023-10-14 806: local val={...}
8c706ff713 2023-10-14 807: local fun={}
8c706ff713 2023-10-14 808: local mat={}
8c706ff713 2023-10-14 809: for i=1,#val do
8c706ff713 2023-10-14 810: if type(val[i])=='function' then
8c706ff713 2023-10-14 811: fun[i]=function(c,fc,sub,mg,sg) return val[i](c,fc,sub,mg,sg) and not c:IsHasEffect(6205579) end
8c706ff713 2023-10-14 812: elseif type(val[i])=='table' then
8c706ff713 2023-10-14 813: fun[i]=function(c,fc,sub,mg,sg)
8c706ff713 2023-10-14 814: for _,fcode in ipairs(val[i]) do
8c706ff713 2023-10-14 815: if type(fcode)=='function' then
8c706ff713 2023-10-14 816: if fcode(c,fc,sub,mg,sg) and not c:IsHasEffect(6205579) then return true end
8c706ff713 2023-10-14 817: else
8c706ff713 2023-10-14 818: if c:IsFusionCode(fcode) or (sub and c:CheckFusionSubstitute(fc)) then return true end
8c706ff713 2023-10-14 819: end
8c706ff713 2023-10-14 820: end
8c706ff713 2023-10-14 821: return false
8c706ff713 2023-10-14 822: end
8c706ff713 2023-10-14 823: for _,fcode in ipairs(val[i]) do
8c706ff713 2023-10-14 824: if type(fcode)~='function' then mat[fcode]=true end
8c706ff713 2023-10-14 825: end
8c706ff713 2023-10-14 826: else
8c706ff713 2023-10-14 827: fun[i]=function(c,fc,sub) return c:IsFusionCode(val[i]) or (sub and c:CheckFusionSubstitute(fc)) end
8c706ff713 2023-10-14 828: mat[val[i]]=true
8c706ff713 2023-10-14 829: end
8c706ff713 2023-10-14 830: end
8c706ff713 2023-10-14 831: local mt=getmetatable(c)
8c706ff713 2023-10-14 832: if mt.material==nil then
8c706ff713 2023-10-14 833: mt.material=mat
8c706ff713 2023-10-14 834: end
8c706ff713 2023-10-14 835: if mt.material_count==nil then
8c706ff713 2023-10-14 836: mt.material_count={#fun,#fun}
8c706ff713 2023-10-14 837: end
8c706ff713 2023-10-14 838: for index,_ in pairs(mat) do
8c706ff713 2023-10-14 839: Auxiliary.AddCodeList(c,index)
8c706ff713 2023-10-14 840: end
8c706ff713 2023-10-14 841: local e1=Effect.CreateEffect(c)
8c706ff713 2023-10-14 842: e1:SetType(EFFECT_TYPE_SINGLE)
8c706ff713 2023-10-14 843: e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
8c706ff713 2023-10-14 844: e1:SetCode(EFFECT_FUSION_MATERIAL)
8c706ff713 2023-10-14 845: e1:SetCondition(Auxiliary.FConditionMix(insf,sub,table.unpack(fun)))
8c706ff713 2023-10-14 846: e1:SetOperation(Auxiliary.FOperationMix(insf,sub,table.unpack(fun)))
8c706ff713 2023-10-14 847: c:RegisterEffect(e1)
8c706ff713 2023-10-14 848: end
8c706ff713 2023-10-14 849: function Auxiliary.FConditionMix(insf,sub,...)
8c706ff713 2023-10-14 850: --g:Material group(nil for Instant Fusion)
8c706ff713 2023-10-14 851: --gc:Material already used
8c706ff713 2023-10-14 852: --chkf: check field, default:PLAYER_NONE
8c706ff713 2023-10-14 853: --chkf&0x100: Not fusion summon
8c706ff713 2023-10-14 854: --chkf&0x200: Concat fusion
8c706ff713 2023-10-14 855: local funs={...}
8c706ff713 2023-10-14 856: return function(e,g,gc,chkfnf)
8c706ff713 2023-10-14 857: if g==nil then return insf and Auxiliary.MustMaterialCheck(nil,e:GetHandlerPlayer(),EFFECT_MUST_BE_FMATERIAL) end
8c706ff713 2023-10-14 858: local c=e:GetHandler()
8c706ff713 2023-10-14 859: local tp=c:GetControler()
8c706ff713 2023-10-14 860: local notfusion=chkfnf&0x100>0
8c706ff713 2023-10-14 861: local concat_fusion=chkfnf&0x200>0
8c706ff713 2023-10-14 862: local sub=(sub or notfusion) and not concat_fusion
8c706ff713 2023-10-14 863: local mg=g:Filter(Auxiliary.FConditionFilterMix,c,c,sub,concat_fusion,table.unpack(funs))
8c706ff713 2023-10-14 864: if gc then
8c706ff713 2023-10-14 865: if not mg:IsContains(gc) then return false end
8c706ff713 2023-10-14 866: Duel.SetSelectedCard(gc)
8c706ff713 2023-10-14 867: end
8c706ff713 2023-10-14 868: return mg:CheckSubGroup(Auxiliary.FCheckMixGoal,#funs,#funs,tp,c,sub,chkfnf,table.unpack(funs))
8c706ff713 2023-10-14 869: end
8c706ff713 2023-10-14 870: end
8c706ff713 2023-10-14 871: function Auxiliary.FOperationMix(insf,sub,...)
8c706ff713 2023-10-14 872: local funs={...}
8c706ff713 2023-10-14 873: return function(e,tp,eg,ep,ev,re,r,rp,gc,chkfnf)
8c706ff713 2023-10-14 874: local c=e:GetHandler()
8c706ff713 2023-10-14 875: local tp=c:GetControler()
8c706ff713 2023-10-14 876: local notfusion=chkfnf&0x100>0
8c706ff713 2023-10-14 877: local concat_fusion=chkfnf&0x200>0
8c706ff713 2023-10-14 878: local sub=(sub or notfusion) and not concat_fusion
8c706ff713 2023-10-14 879: local mg=eg:Filter(Auxiliary.FConditionFilterMix,c,c,sub,concat_fusion,table.unpack(funs))
8c706ff713 2023-10-14 880: if gc then Duel.SetSelectedCard(gc) end
8c706ff713 2023-10-14 881: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_FMATERIAL)
8c706ff713 2023-10-14 882: local sg=mg:SelectSubGroup(tp,Auxiliary.FCheckMixGoal,false,#funs,#funs,tp,c,sub,chkfnf,table.unpack(funs))
8c706ff713 2023-10-14 883: Duel.SetFusionMaterial(sg)
8c706ff713 2023-10-14 884: end
8c706ff713 2023-10-14 885: end
8c706ff713 2023-10-14 886: function Auxiliary.FConditionFilterMix(c,fc,sub,concat_fusion,...)
8c706ff713 2023-10-14 887: local fusion_type=concat_fusion and SUMMON_TYPE_SPECIAL or SUMMON_TYPE_FUSION
8c706ff713 2023-10-14 888: if not c:IsCanBeFusionMaterial(fc,fusion_type) then return false end
8c706ff713 2023-10-14 889: for i,f in ipairs({...}) do
8c706ff713 2023-10-14 890: if f(c,fc,sub) then return true end
8c706ff713 2023-10-14 891: end
8c706ff713 2023-10-14 892: return false
8c706ff713 2023-10-14 893: end
8c706ff713 2023-10-14 894: function Auxiliary.FCheckMix(c,mg,sg,fc,sub,fun1,fun2,...)
8c706ff713 2023-10-14 895: if fun2 then
8c706ff713 2023-10-14 896: sg:AddCard(c)
8c706ff713 2023-10-14 897: local res=false
8c706ff713 2023-10-14 898: if fun1(c,fc,false,mg,sg) then
8c706ff713 2023-10-14 899: res=mg:IsExists(Auxiliary.FCheckMix,1,sg,mg,sg,fc,sub,fun2,...)
8c706ff713 2023-10-14 900: elseif sub and fun1(c,fc,true,mg,sg) then
8c706ff713 2023-10-14 901: res=mg:IsExists(Auxiliary.FCheckMix,1,sg,mg,sg,fc,false,fun2,...)
8c706ff713 2023-10-14 902: end
8c706ff713 2023-10-14 903: sg:RemoveCard(c)
8c706ff713 2023-10-14 904: return res
8c706ff713 2023-10-14 905: else
8c706ff713 2023-10-14 906: return fun1(c,fc,sub,mg,sg)
8c706ff713 2023-10-14 907: end
8c706ff713 2023-10-14 908: end
8c706ff713 2023-10-14 909: --if sg1 is subset of sg2 then not Auxiliary.FCheckAdditional(tp,sg1,fc) -> not Auxiliary.FCheckAdditional(tp,sg2,fc)
8c706ff713 2023-10-14 910: Auxiliary.FCheckAdditional=nil
8c706ff713 2023-10-14 911: Auxiliary.FGoalCheckAdditional=nil
8c706ff713 2023-10-14 912: function Auxiliary.FCheckMixGoal(sg,tp,fc,sub,chkfnf,...)
8c706ff713 2023-10-14 913: local chkf=chkfnf&0xff
8c706ff713 2023-10-14 914: local concat_fusion=chkfnf&0x200>0
8c706ff713 2023-10-14 915: if not concat_fusion and sg:IsExists(Auxiliary.TuneMagicianCheckX,1,nil,sg,EFFECT_TUNE_MAGICIAN_F) then return false end
8c706ff713 2023-10-14 916: if not Auxiliary.MustMaterialCheck(sg,tp,EFFECT_MUST_BE_FMATERIAL) then return false end
8c706ff713 2023-10-14 917: local g=Group.CreateGroup()
8c706ff713 2023-10-14 918: return sg:IsExists(Auxiliary.FCheckMix,1,nil,sg,g,fc,sub,...) and (chkf==PLAYER_NONE or Duel.GetLocationCountFromEx(tp,tp,sg,fc)>0)
8c706ff713 2023-10-14 919: and (not Auxiliary.FCheckAdditional or Auxiliary.FCheckAdditional(tp,sg,fc))
8c706ff713 2023-10-14 920: and (not Auxiliary.FGoalCheckAdditional or Auxiliary.FGoalCheckAdditional(tp,sg,fc))
8c706ff713 2023-10-14 921: end
8c706ff713 2023-10-14 922: --Fusion monster, mixed material * minc to maxc + material + ...
8c706ff713 2023-10-14 923: function Auxiliary.AddFusionProcMixRep(c,sub,insf,fun1,minc,maxc,...)
8c706ff713 2023-10-14 924: if c:IsStatus(STATUS_COPYING_EFFECT) then return end
8c706ff713 2023-10-14 925: local val={fun1,...}
8c706ff713 2023-10-14 926: local fun={}
8c706ff713 2023-10-14 927: local mat={}
8c706ff713 2023-10-14 928: for i=1,#val do
8c706ff713 2023-10-14 929: if type(val[i])=='function' then
8c706ff713 2023-10-14 930: fun[i]=function(c,fc,sub,mg,sg) return val[i](c,fc,sub,mg,sg) and not c:IsHasEffect(6205579) end
8c706ff713 2023-10-14 931: elseif type(val[i])=='table' then
8c706ff713 2023-10-14 932: fun[i]=function(c,fc,sub,mg,sg)
8c706ff713 2023-10-14 933: for _,fcode in ipairs(val[i]) do
8c706ff713 2023-10-14 934: if type(fcode)=='function' then
8c706ff713 2023-10-14 935: if fcode(c,fc,sub,mg,sg) and not c:IsHasEffect(6205579) then return true end
8c706ff713 2023-10-14 936: else
8c706ff713 2023-10-14 937: if c:IsFusionCode(fcode) or (sub and c:CheckFusionSubstitute(fc)) then return true end
8c706ff713 2023-10-14 938: end
8c706ff713 2023-10-14 939: end
8c706ff713 2023-10-14 940: return false
8c706ff713 2023-10-14 941: end
8c706ff713 2023-10-14 942: for _,fcode in ipairs(val[i]) do
8c706ff713 2023-10-14 943: if type(fcode)~='function' then mat[fcode]=true end
8c706ff713 2023-10-14 944: end
8c706ff713 2023-10-14 945: else
8c706ff713 2023-10-14 946: fun[i]=function(c,fc,sub) return c:IsFusionCode(val[i]) or (sub and c:CheckFusionSubstitute(fc)) end
8c706ff713 2023-10-14 947: mat[val[i]]=true
8c706ff713 2023-10-14 948: end
8c706ff713 2023-10-14 949: end
8c706ff713 2023-10-14 950: local mt=getmetatable(c)
8c706ff713 2023-10-14 951: if mt.material==nil then
8c706ff713 2023-10-14 952: mt.material=mat
8c706ff713 2023-10-14 953: end
8c706ff713 2023-10-14 954: if mt.material_count==nil then
8c706ff713 2023-10-14 955: mt.material_count={#fun+minc-1,#fun+maxc-1}
8c706ff713 2023-10-14 956: end
8c706ff713 2023-10-14 957: for index,_ in pairs(mat) do
8c706ff713 2023-10-14 958: Auxiliary.AddCodeList(c,index)
8c706ff713 2023-10-14 959: end
8c706ff713 2023-10-14 960: local e1=Effect.CreateEffect(c)
8c706ff713 2023-10-14 961: e1:SetType(EFFECT_TYPE_SINGLE)
8c706ff713 2023-10-14 962: e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
8c706ff713 2023-10-14 963: e1:SetCode(EFFECT_FUSION_MATERIAL)
8c706ff713 2023-10-14 964: e1:SetCondition(Auxiliary.FConditionMixRep(insf,sub,fun[1],minc,maxc,table.unpack(fun,2)))
8c706ff713 2023-10-14 965: e1:SetOperation(Auxiliary.FOperationMixRep(insf,sub,fun[1],minc,maxc,table.unpack(fun,2)))
8c706ff713 2023-10-14 966: c:RegisterEffect(e1)
8c706ff713 2023-10-14 967: end
8c706ff713 2023-10-14 968: function Auxiliary.FConditionMixRep(insf,sub,fun1,minc,maxc,...)
8c706ff713 2023-10-14 969: local funs={...}
8c706ff713 2023-10-14 970: return function(e,g,gc,chkfnf)
8c706ff713 2023-10-14 971: if g==nil then return insf and Auxiliary.MustMaterialCheck(nil,e:GetHandlerPlayer(),EFFECT_MUST_BE_FMATERIAL) end
8c706ff713 2023-10-14 972: local c=e:GetHandler()
8c706ff713 2023-10-14 973: local tp=c:GetControler()
8c706ff713 2023-10-14 974: local notfusion=chkfnf&0x100>0
8c706ff713 2023-10-14 975: local concat_fusion=chkfnf&0x200>0
8c706ff713 2023-10-14 976: local sub=(sub or notfusion) and not concat_fusion
8c706ff713 2023-10-14 977: local mg=g:Filter(Auxiliary.FConditionFilterMix,c,c,sub,concat_fusion,fun1,table.unpack(funs))
8c706ff713 2023-10-14 978: if gc then
8c706ff713 2023-10-14 979: if not mg:IsContains(gc) then return false end
8c706ff713 2023-10-14 980: local sg=Group.CreateGroup()
8c706ff713 2023-10-14 981: return Auxiliary.FSelectMixRep(gc,tp,mg,sg,c,sub,chkfnf,fun1,minc,maxc,table.unpack(funs))
8c706ff713 2023-10-14 982: end
8c706ff713 2023-10-14 983: local sg=Group.CreateGroup()
8c706ff713 2023-10-14 984: return mg:IsExists(Auxiliary.FSelectMixRep,1,nil,tp,mg,sg,c,sub,chkfnf,fun1,minc,maxc,table.unpack(funs))
8c706ff713 2023-10-14 985: end
8c706ff713 2023-10-14 986: end
8c706ff713 2023-10-14 987: function Auxiliary.FOperationMixRep(insf,sub,fun1,minc,maxc,...)
8c706ff713 2023-10-14 988: local funs={...}
8c706ff713 2023-10-14 989: return function(e,tp,eg,ep,ev,re,r,rp,gc,chkfnf)
8c706ff713 2023-10-14 990: local c=e:GetHandler()
8c706ff713 2023-10-14 991: local tp=c:GetControler()
8c706ff713 2023-10-14 992: local notfusion=chkfnf&0x100>0
8c706ff713 2023-10-14 993: local concat_fusion=chkfnf&0x200>0
8c706ff713 2023-10-14 994: local sub=(sub or notfusion) and not concat_fusion
8c706ff713 2023-10-14 995: local mg=eg:Filter(Auxiliary.FConditionFilterMix,c,c,sub,concat_fusion,fun1,table.unpack(funs))
8c706ff713 2023-10-14 996: local sg=Group.CreateGroup()
8c706ff713 2023-10-14 997: if gc then sg:AddCard(gc) end
8c706ff713 2023-10-14 998: while sg:GetCount()<maxc+#funs do
8c706ff713 2023-10-14 999: local cg=mg:Filter(Auxiliary.FSelectMixRep,sg,tp,mg,sg,c,sub,chkfnf,fun1,minc,maxc,table.unpack(funs))
8c706ff713 2023-10-14 1000: if cg:GetCount()==0 then break end
8c706ff713 2023-10-14 1001: local finish=Auxiliary.FCheckMixRepGoal(tp,sg,c,sub,chkfnf,fun1,minc,maxc,table.unpack(funs))
8c706ff713 2023-10-14 1002: local cancel_group=sg:Clone()
8c706ff713 2023-10-14 1003: if gc then cancel_group:RemoveCard(gc) end
8c706ff713 2023-10-14 1004: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_FMATERIAL)
8c706ff713 2023-10-14 1005: local tc=cg:SelectUnselect(cancel_group,tp,finish,false,minc+#funs,maxc+#funs)
8c706ff713 2023-10-14 1006: if not tc then break end
8c706ff713 2023-10-14 1007: if sg:IsContains(tc) then
8c706ff713 2023-10-14 1008: sg:RemoveCard(tc)
8c706ff713 2023-10-14 1009: else
8c706ff713 2023-10-14 1010: sg:AddCard(tc)
8c706ff713 2023-10-14 1011: end
8c706ff713 2023-10-14 1012: end
8c706ff713 2023-10-14 1013: Duel.SetFusionMaterial(sg)
8c706ff713 2023-10-14 1014: end
8c706ff713 2023-10-14 1015: end
8c706ff713 2023-10-14 1016: function Auxiliary.FCheckMixRep(sg,g,fc,sub,chkf,fun1,minc,maxc,fun2,...)
8c706ff713 2023-10-14 1017: if fun2 then
8c706ff713 2023-10-14 1018: return sg:IsExists(Auxiliary.FCheckMixRepFilter,1,g,sg,g,fc,sub,chkf,fun1,minc,maxc,fun2,...)
8c706ff713 2023-10-14 1019: else
8c706ff713 2023-10-14 1020: local ct1=sg:FilterCount(fun1,g,fc,sub,mg,sg)
8c706ff713 2023-10-14 1021: local ct2=sg:FilterCount(fun1,g,fc,false,mg,sg)
8c706ff713 2023-10-14 1022: return ct1==sg:GetCount()-g:GetCount() and ct1-ct2<=1
8c706ff713 2023-10-14 1023: end
8c706ff713 2023-10-14 1024: end
8c706ff713 2023-10-14 1025: function Auxiliary.FCheckMixRepFilter(c,sg,g,fc,sub,chkf,fun1,minc,maxc,fun2,...)
8c706ff713 2023-10-14 1026: if fun2(c,fc,sub,mg,sg) then
8c706ff713 2023-10-14 1027: g:AddCard(c)
8c706ff713 2023-10-14 1028: local sub=sub and fun2(c,fc,false,mg,sg)
8c706ff713 2023-10-14 1029: local res=Auxiliary.FCheckMixRep(sg,g,fc,sub,chkf,fun1,minc,maxc,...)
8c706ff713 2023-10-14 1030: g:RemoveCard(c)
8c706ff713 2023-10-14 1031: return res
8c706ff713 2023-10-14 1032: end
8c706ff713 2023-10-14 1033: return false
8c706ff713 2023-10-14 1034: end
8c706ff713 2023-10-14 1035: function Auxiliary.FCheckMixRepGoalCheck(tp,sg,fc,chkfnf)
8c706ff713 2023-10-14 1036: local concat_fusion=chkfnf&0x200>0
8c706ff713 2023-10-14 1037: if not concat_fusion and sg:IsExists(Auxiliary.TuneMagicianCheckX,1,nil,sg,EFFECT_TUNE_MAGICIAN_F) then return false end
8c706ff713 2023-10-14 1038: if not Auxiliary.MustMaterialCheck(sg,tp,EFFECT_MUST_BE_FMATERIAL) then return false end
8c706ff713 2023-10-14 1039: if Auxiliary.FGoalCheckAdditional and not Auxiliary.FGoalCheckAdditional(tp,sg,fc) then return false end
8c706ff713 2023-10-14 1040: return true
8c706ff713 2023-10-14 1041: end
8c706ff713 2023-10-14 1042: function Auxiliary.FCheckMixRepGoal(tp,sg,fc,sub,chkfnf,fun1,minc,maxc,...)
8c706ff713 2023-10-14 1043: local chkf=chkfnf&0xff
8c706ff713 2023-10-14 1044: if sg:GetCount()<minc+#{...} or sg:GetCount()>maxc+#{...} then return false end
8c706ff713 2023-10-14 1045: if not (chkf==PLAYER_NONE or Duel.GetLocationCountFromEx(tp,tp,sg,fc)>0) then return false end
8c706ff713 2023-10-14 1046: if Auxiliary.FCheckAdditional and not Auxiliary.FCheckAdditional(tp,sg,fc) then return false end
8c706ff713 2023-10-14 1047: if not Auxiliary.FCheckMixRepGoalCheck(tp,sg,fc,chkfnf) then return false end
8c706ff713 2023-10-14 1048: local g=Group.CreateGroup()
8c706ff713 2023-10-14 1049: return Auxiliary.FCheckMixRep(sg,g,fc,sub,chkf,fun1,minc,maxc,...)
8c706ff713 2023-10-14 1050: end
8c706ff713 2023-10-14 1051: function Auxiliary.FCheckMixRepTemplate(c,cond,tp,mg,sg,g,fc,sub,chkfnf,fun1,minc,maxc,...)
8c706ff713 2023-10-14 1052: for i,f in ipairs({...}) do
8c706ff713 2023-10-14 1053: if f(c,fc,sub,mg,sg) then
8c706ff713 2023-10-14 1054: g:AddCard(c)
8c706ff713 2023-10-14 1055: local sub=sub and f(c,fc,false,mg,sg)
8c706ff713 2023-10-14 1056: local t={...}
8c706ff713 2023-10-14 1057: table.remove(t,i)
8c706ff713 2023-10-14 1058: local res=cond(tp,mg,sg,g,fc,sub,chkfnf,fun1,minc,maxc,table.unpack(t))
8c706ff713 2023-10-14 1059: g:RemoveCard(c)
8c706ff713 2023-10-14 1060: if res then return true end
8c706ff713 2023-10-14 1061: end
8c706ff713 2023-10-14 1062: end
8c706ff713 2023-10-14 1063: if maxc>0 then
8c706ff713 2023-10-14 1064: if fun1(c,fc,sub,mg,sg) then
8c706ff713 2023-10-14 1065: g:AddCard(c)
8c706ff713 2023-10-14 1066: local sub=sub and fun1(c,fc,false,mg,sg)
8c706ff713 2023-10-14 1067: local res=cond(tp,mg,sg,g,fc,sub,chkfnf,fun1,minc-1,maxc-1,...)
8c706ff713 2023-10-14 1068: g:RemoveCard(c)
8c706ff713 2023-10-14 1069: if res then return true end
8c706ff713 2023-10-14 1070: end
8c706ff713 2023-10-14 1071: end
8c706ff713 2023-10-14 1072: return false
8c706ff713 2023-10-14 1073: end
8c706ff713 2023-10-14 1074: function Auxiliary.FCheckMixRepSelectedCond(tp,mg,sg,g,...)
8c706ff713 2023-10-14 1075: if g:GetCount()<sg:GetCount() then
8c706ff713 2023-10-14 1076: return sg:IsExists(Auxiliary.FCheckMixRepSelected,1,g,tp,mg,sg,g,...)
8c706ff713 2023-10-14 1077: else
8c706ff713 2023-10-14 1078: return Auxiliary.FCheckSelectMixRep(tp,mg,sg,g,...)
8c706ff713 2023-10-14 1079: end
8c706ff713 2023-10-14 1080: end
8c706ff713 2023-10-14 1081: function Auxiliary.FCheckMixRepSelected(c,...)
8c706ff713 2023-10-14 1082: return Auxiliary.FCheckMixRepTemplate(c,Auxiliary.FCheckMixRepSelectedCond,...)
8c706ff713 2023-10-14 1083: end
8c706ff713 2023-10-14 1084: function Auxiliary.FCheckSelectMixRep(tp,mg,sg,g,fc,sub,chkfnf,fun1,minc,maxc,...)
8c706ff713 2023-10-14 1085: local chkf=chkfnf&0xff
8c706ff713 2023-10-14 1086: if Auxiliary.FCheckAdditional and not Auxiliary.FCheckAdditional(tp,g,fc) then return false end
8c706ff713 2023-10-14 1087: if chkf==PLAYER_NONE or Duel.GetLocationCountFromEx(tp,tp,g,fc)>0 then
8c706ff713 2023-10-14 1088: if minc<=0 and #{...}==0 and Auxiliary.FCheckMixRepGoalCheck(tp,g,fc,chkfnf) then return true end
8c706ff713 2023-10-14 1089: return mg:IsExists(Auxiliary.FCheckSelectMixRepAll,1,g,tp,mg,sg,g,fc,sub,chkfnf,fun1,minc,maxc,...)
8c706ff713 2023-10-14 1090: else
8c706ff713 2023-10-14 1091: return mg:IsExists(Auxiliary.FCheckSelectMixRepM,1,g,tp,mg,sg,g,fc,sub,chkfnf,fun1,minc,maxc,...)
8c706ff713 2023-10-14 1092: end
8c706ff713 2023-10-14 1093: end
8c706ff713 2023-10-14 1094: function Auxiliary.FCheckSelectMixRepAll(c,tp,mg,sg,g,fc,sub,chkf,fun1,minc,maxc,fun2,...)
8c706ff713 2023-10-14 1095: if fun2 then
8c706ff713 2023-10-14 1096: if fun2(c,fc,sub,mg,sg) then
8c706ff713 2023-10-14 1097: g:AddCard(c)
8c706ff713 2023-10-14 1098: local sub=sub and fun2(c,fc,false,mg,sg)
8c706ff713 2023-10-14 1099: local res=Auxiliary.FCheckSelectMixRep(tp,mg,sg,g,fc,sub,chkf,fun1,minc,maxc,...)
8c706ff713 2023-10-14 1100: g:RemoveCard(c)
8c706ff713 2023-10-14 1101: return res
8c706ff713 2023-10-14 1102: end
8c706ff713 2023-10-14 1103: elseif maxc>0 and fun1(c,fc,sub,mg,sg) then
8c706ff713 2023-10-14 1104: g:AddCard(c)
8c706ff713 2023-10-14 1105: local sub=sub and fun1(c,fc,false,mg,sg)
8c706ff713 2023-10-14 1106: local res=Auxiliary.FCheckSelectMixRep(tp,mg,sg,g,fc,sub,chkf,fun1,minc-1,maxc-1)
8c706ff713 2023-10-14 1107: g:RemoveCard(c)
8c706ff713 2023-10-14 1108: return res
8c706ff713 2023-10-14 1109: end
8c706ff713 2023-10-14 1110: return false
8c706ff713 2023-10-14 1111: end
8c706ff713 2023-10-14 1112: function Auxiliary.FCheckSelectMixRepM(c,tp,...)
8c706ff713 2023-10-14 1113: return c:IsControler(tp) and c:IsLocation(LOCATION_MZONE)
8c706ff713 2023-10-14 1114: and Auxiliary.FCheckMixRepTemplate(c,Auxiliary.FCheckSelectMixRep,tp,...)
8c706ff713 2023-10-14 1115: end
8c706ff713 2023-10-14 1116: function Auxiliary.FSelectMixRep(c,tp,mg,sg,fc,sub,chkfnf,...)
8c706ff713 2023-10-14 1117: sg:AddCard(c)
8c706ff713 2023-10-14 1118: local res=false
8c706ff713 2023-10-14 1119: if Auxiliary.FCheckAdditional and not Auxiliary.FCheckAdditional(tp,sg,fc) then
8c706ff713 2023-10-14 1120: res=false
8c706ff713 2023-10-14 1121: elseif Auxiliary.FCheckMixRepGoal(tp,sg,fc,sub,chkfnf,...) then
8c706ff713 2023-10-14 1122: res=true
8c706ff713 2023-10-14 1123: else
8c706ff713 2023-10-14 1124: local g=Group.CreateGroup()
8c706ff713 2023-10-14 1125: res=sg:IsExists(Auxiliary.FCheckMixRepSelected,1,nil,tp,mg,sg,g,fc,sub,chkfnf,...)
8c706ff713 2023-10-14 1126: end
8c706ff713 2023-10-14 1127: sg:RemoveCard(c)
8c706ff713 2023-10-14 1128: return res
8c706ff713 2023-10-14 1129: end
8c706ff713 2023-10-14 1130: --Fusion monster, name + name
8c706ff713 2023-10-14 1131: function Auxiliary.AddFusionProcCode2(c,code1,code2,sub,insf)
8c706ff713 2023-10-14 1132: Auxiliary.AddFusionProcMix(c,sub,insf,code1,code2)
8c706ff713 2023-10-14 1133: end
8c706ff713 2023-10-14 1134: --Fusion monster, name + name + name
8c706ff713 2023-10-14 1135: function Auxiliary.AddFusionProcCode3(c,code1,code2,code3,sub,insf)
8c706ff713 2023-10-14 1136: Auxiliary.AddFusionProcMix(c,sub,insf,code1,code2,code3)
8c706ff713 2023-10-14 1137: end
8c706ff713 2023-10-14 1138: --Fusion monster, name + name + name + name
8c706ff713 2023-10-14 1139: function Auxiliary.AddFusionProcCode4(c,code1,code2,code3,code4,sub,insf)
8c706ff713 2023-10-14 1140: Auxiliary.AddFusionProcMix(c,sub,insf,code1,code2,code3,code4)
8c706ff713 2023-10-14 1141: end
8c706ff713 2023-10-14 1142: --Fusion monster, name * n
8c706ff713 2023-10-14 1143: function Auxiliary.AddFusionProcCodeRep(c,code1,cc,sub,insf)
8c706ff713 2023-10-14 1144: local code={}
8c706ff713 2023-10-14 1145: for i=1,cc do
8c706ff713 2023-10-14 1146: code[i]=code1
8c706ff713 2023-10-14 1147: end
8c706ff713 2023-10-14 1148: Auxiliary.AddFusionProcMix(c,sub,insf,table.unpack(code))
8c706ff713 2023-10-14 1149: end
8c706ff713 2023-10-14 1150: --Fusion monster, name * minc to maxc
8c706ff713 2023-10-14 1151: function Auxiliary.AddFusionProcCodeRep2(c,code1,minc,maxc,sub,insf)
8c706ff713 2023-10-14 1152: Auxiliary.AddFusionProcMixRep(c,sub,insf,code1,minc,maxc)
8c706ff713 2023-10-14 1153: end
8c706ff713 2023-10-14 1154: --Fusion monster, name + condition * n
8c706ff713 2023-10-14 1155: function Auxiliary.AddFusionProcCodeFun(c,code1,f,cc,sub,insf)
8c706ff713 2023-10-14 1156: local fun={}
8c706ff713 2023-10-14 1157: for i=1,cc do
8c706ff713 2023-10-14 1158: fun[i]=f
8c706ff713 2023-10-14 1159: end
8c706ff713 2023-10-14 1160: Auxiliary.AddFusionProcMix(c,sub,insf,code1,table.unpack(fun))
8c706ff713 2023-10-14 1161: end
8c706ff713 2023-10-14 1162: --Fusion monster, condition + condition
8c706ff713 2023-10-14 1163: function Auxiliary.AddFusionProcFun2(c,f1,f2,insf)
8c706ff713 2023-10-14 1164: Auxiliary.AddFusionProcMix(c,false,insf,f1,f2)
8c706ff713 2023-10-14 1165: end
8c706ff713 2023-10-14 1166: --Fusion monster, condition * n
8c706ff713 2023-10-14 1167: function Auxiliary.AddFusionProcFunRep(c,f,cc,insf)
8c706ff713 2023-10-14 1168: local fun={}
8c706ff713 2023-10-14 1169: for i=1,cc do
8c706ff713 2023-10-14 1170: fun[i]=f
8c706ff713 2023-10-14 1171: end
8c706ff713 2023-10-14 1172: Auxiliary.AddFusionProcMix(c,false,insf,table.unpack(fun))
8c706ff713 2023-10-14 1173: end
8c706ff713 2023-10-14 1174: --Fusion monster, condition * minc to maxc
8c706ff713 2023-10-14 1175: function Auxiliary.AddFusionProcFunRep2(c,f,minc,maxc,insf)
8c706ff713 2023-10-14 1176: Auxiliary.AddFusionProcMixRep(c,false,insf,f,minc,maxc)
8c706ff713 2023-10-14 1177: end
8c706ff713 2023-10-14 1178: --Fusion monster, condition1 + condition2 * n
8c706ff713 2023-10-14 1179: function Auxiliary.AddFusionProcFunFun(c,f1,f2,cc,insf)
8c706ff713 2023-10-14 1180: local fun={}
8c706ff713 2023-10-14 1181: for i=1,cc do
8c706ff713 2023-10-14 1182: fun[i]=f2
8c706ff713 2023-10-14 1183: end
8c706ff713 2023-10-14 1184: Auxiliary.AddFusionProcMix(c,false,insf,f1,table.unpack(fun))
8c706ff713 2023-10-14 1185: end
8c706ff713 2023-10-14 1186: --Fusion monster, condition1 + condition2 * minc to maxc
8c706ff713 2023-10-14 1187: function Auxiliary.AddFusionProcFunFunRep(c,f1,f2,minc,maxc,insf)
8c706ff713 2023-10-14 1188: Auxiliary.AddFusionProcMixRep(c,false,insf,f2,minc,maxc,f1)
8c706ff713 2023-10-14 1189: end
8c706ff713 2023-10-14 1190: --Fusion monster, name + condition * minc to maxc
8c706ff713 2023-10-14 1191: function Auxiliary.AddFusionProcCodeFunRep(c,code1,f,minc,maxc,sub,insf)
8c706ff713 2023-10-14 1192: Auxiliary.AddFusionProcMixRep(c,sub,insf,f,minc,maxc,code1)
8c706ff713 2023-10-14 1193: end
8c706ff713 2023-10-14 1194: --Fusion monster, name + name + condition * minc to maxc
8c706ff713 2023-10-14 1195: function Auxiliary.AddFusionProcCode2FunRep(c,code1,code2,f,minc,maxc,sub,insf)
8c706ff713 2023-10-14 1196: Auxiliary.AddFusionProcMixRep(c,sub,insf,f,minc,maxc,code1,code2)
8c706ff713 2023-10-14 1197: end
8c706ff713 2023-10-14 1198: --Fusion monster, Shaddoll materials
8c706ff713 2023-10-14 1199: function Auxiliary.AddFusionProcShaddoll(c,attr)
8c706ff713 2023-10-14 1200: local e1=Effect.CreateEffect(c)
8c706ff713 2023-10-14 1201: e1:SetType(EFFECT_TYPE_SINGLE)
8c706ff713 2023-10-14 1202: e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
8c706ff713 2023-10-14 1203: e1:SetCode(EFFECT_FUSION_MATERIAL)
8c706ff713 2023-10-14 1204: e1:SetCondition(Auxiliary.FShaddollCondition(attr))
8c706ff713 2023-10-14 1205: e1:SetOperation(Auxiliary.FShaddollOperation(attr))
8c706ff713 2023-10-14 1206: c:RegisterEffect(e1)
8c706ff713 2023-10-14 1207: end
8c706ff713 2023-10-14 1208: function Auxiliary.FShaddollFilter(c,fc,attr)
8c706ff713 2023-10-14 1209: return (Auxiliary.FShaddollFilter1(c) or Auxiliary.FShaddollFilter2(c,attr)) and c:IsCanBeFusionMaterial(fc) and not c:IsHasEffect(6205579)
8c706ff713 2023-10-14 1210: end
8c706ff713 2023-10-14 1211: function Auxiliary.FShaddollExFilter(c,fc,attr,fe)
8c706ff713 2023-10-14 1212: return c:IsFaceup() and not c:IsImmuneToEffect(fe) and Auxiliary.FShaddollFilter(c,fc,attr)
8c706ff713 2023-10-14 1213: end
8c706ff713 2023-10-14 1214: function Auxiliary.FShaddollFilter1(c)
8c706ff713 2023-10-14 1215: return c:IsFusionSetCard(0x9d)
8c706ff713 2023-10-14 1216: end
8c706ff713 2023-10-14 1217: function Auxiliary.FShaddollFilter2(c,attr)
8c706ff713 2023-10-14 1218: return c:IsFusionAttribute(attr) or c:IsHasEffect(4904633)
8c706ff713 2023-10-14 1219: end
8c706ff713 2023-10-14 1220: function Auxiliary.FShaddollSpFilter1(c,fc,tp,mg,exg,attr,chkf)
8c706ff713 2023-10-14 1221: return mg:IsExists(Auxiliary.FShaddollSpFilter2,1,c,fc,tp,c,attr,chkf)
8c706ff713 2023-10-14 1222: or (exg and exg:IsExists(Auxiliary.FShaddollSpFilter2,1,c,fc,tp,c,attr,chkf))
8c706ff713 2023-10-14 1223: end
8c706ff713 2023-10-14 1224: function Auxiliary.FShaddollSpFilter2(c,fc,tp,mc,attr,chkf)
8c706ff713 2023-10-14 1225: local sg=Group.FromCards(c,mc)
8c706ff713 2023-10-14 1226: if sg:IsExists(Auxiliary.TuneMagicianCheckX,1,nil,sg,EFFECT_TUNE_MAGICIAN_F) then return false end
8c706ff713 2023-10-14 1227: if not Auxiliary.MustMaterialCheck(sg,tp,EFFECT_MUST_BE_FMATERIAL) then return false end
8c706ff713 2023-10-14 1228: if Auxiliary.FCheckAdditional and not Auxiliary.FCheckAdditional(tp,sg,fc)
8c706ff713 2023-10-14 1229: or Auxiliary.FGoalCheckAdditional and not Auxiliary.FGoalCheckAdditional(tp,sg,fc) then return false end
8c706ff713 2023-10-14 1230: return ((Auxiliary.FShaddollFilter1(c) and Auxiliary.FShaddollFilter2(mc,attr))
8c706ff713 2023-10-14 1231: or (Auxiliary.FShaddollFilter2(c,attr) and Auxiliary.FShaddollFilter1(mc)))
8c706ff713 2023-10-14 1232: and (chkf==PLAYER_NONE or Duel.GetLocationCountFromEx(tp,tp,sg,fc)>0)
8c706ff713 2023-10-14 1233: end
8c706ff713 2023-10-14 1234: function Auxiliary.FShaddollCondition(attr)
8c706ff713 2023-10-14 1235: return function(e,g,gc,chkf)
8c706ff713 2023-10-14 1236: if g==nil then return Auxiliary.MustMaterialCheck(nil,e:GetHandlerPlayer(),EFFECT_MUST_BE_FMATERIAL) end
8c706ff713 2023-10-14 1237: local c=e:GetHandler()
8c706ff713 2023-10-14 1238: local mg=g:Filter(Auxiliary.FShaddollFilter,nil,c,attr)
8c706ff713 2023-10-14 1239: local tp=e:GetHandlerPlayer()
8c706ff713 2023-10-14 1240: local fc=Duel.GetFieldCard(tp,LOCATION_FZONE,0)
8c706ff713 2023-10-14 1241: local exg=nil
8c706ff713 2023-10-14 1242: if fc and fc:IsHasEffect(81788994) and fc:IsCanRemoveCounter(tp,0x16,3,REASON_EFFECT) then
8c706ff713 2023-10-14 1243: local fe=fc:IsHasEffect(81788994)
8c706ff713 2023-10-14 1244: exg=Duel.GetMatchingGroup(Auxiliary.FShaddollExFilter,tp,0,LOCATION_MZONE,mg,c,attr,fe)
8c706ff713 2023-10-14 1245: end
8c706ff713 2023-10-14 1246: if gc then
8c706ff713 2023-10-14 1247: if not mg:IsContains(gc) then return false end
8c706ff713 2023-10-14 1248: return Auxiliary.FShaddollSpFilter1(gc,c,tp,mg,exg,attr,chkf)
8c706ff713 2023-10-14 1249: end
8c706ff713 2023-10-14 1250: return mg:IsExists(Auxiliary.FShaddollSpFilter1,1,nil,c,tp,mg,exg,attr,chkf)
8c706ff713 2023-10-14 1251: end
8c706ff713 2023-10-14 1252: end
8c706ff713 2023-10-14 1253: function Auxiliary.FShaddollOperation(attr)
8c706ff713 2023-10-14 1254: return function(e,tp,eg,ep,ev,re,r,rp,gc,chkf)
8c706ff713 2023-10-14 1255: local c=e:GetHandler()
8c706ff713 2023-10-14 1256: local mg=eg:Filter(Auxiliary.FShaddollFilter,nil,c,attr)
8c706ff713 2023-10-14 1257: local fc=Duel.GetFieldCard(tp,LOCATION_FZONE,0)
8c706ff713 2023-10-14 1258: local exg=nil
8c706ff713 2023-10-14 1259: if fc and fc:IsHasEffect(81788994) and fc:IsCanRemoveCounter(tp,0x16,3,REASON_EFFECT) then
8c706ff713 2023-10-14 1260: local fe=fc:IsHasEffect(81788994)
8c706ff713 2023-10-14 1261: exg=Duel.GetMatchingGroup(Auxiliary.FShaddollExFilter,tp,0,LOCATION_MZONE,mg,c,attr,fe)
8c706ff713 2023-10-14 1262: end
8c706ff713 2023-10-14 1263: local g=nil
8c706ff713 2023-10-14 1264: if gc then
8c706ff713 2023-10-14 1265: g=Group.FromCards(gc)
8c706ff713 2023-10-14 1266: mg:RemoveCard(gc)
8c706ff713 2023-10-14 1267: else
8c706ff713 2023-10-14 1268: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_FMATERIAL)
8c706ff713 2023-10-14 1269: g=mg:FilterSelect(tp,Auxiliary.FShaddollSpFilter1,1,1,nil,c,tp,mg,exg,attr,chkf)
8c706ff713 2023-10-14 1270: mg:Sub(g)
8c706ff713 2023-10-14 1271: end
8c706ff713 2023-10-14 1272: if exg and exg:IsExists(Auxiliary.FShaddollSpFilter2,1,nil,c,tp,g:GetFirst(),attr,chkf)
8c706ff713 2023-10-14 1273: and (mg:GetCount()==0 or (exg:GetCount()>0 and Duel.SelectYesNo(tp,aux.Stringid(81788994,0)))) then
8c706ff713 2023-10-14 1274: fc:RemoveCounter(tp,0x16,3,REASON_EFFECT)
8c706ff713 2023-10-14 1275: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_FMATERIAL)
8c706ff713 2023-10-14 1276: local sg=exg:FilterSelect(tp,Auxiliary.FShaddollSpFilter2,1,1,nil,c,tp,g:GetFirst(),attr,chkf)
8c706ff713 2023-10-14 1277: g:Merge(sg)
8c706ff713 2023-10-14 1278: else
8c706ff713 2023-10-14 1279: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_FMATERIAL)
8c706ff713 2023-10-14 1280: local sg=mg:FilterSelect(tp,Auxiliary.FShaddollSpFilter2,1,1,nil,c,tp,g:GetFirst(),attr,chkf)
8c706ff713 2023-10-14 1281: g:Merge(sg)
8c706ff713 2023-10-14 1282: end
8c706ff713 2023-10-14 1283: Duel.SetFusionMaterial(g)
8c706ff713 2023-10-14 1284: end
8c706ff713 2023-10-14 1285: end
8c706ff713 2023-10-14 1286:
8c706ff713 2023-10-14 1287: --Contact Fusion
8c706ff713 2023-10-14 1288: function Auxiliary.AddContactFusionProcedure(c,filter,self_location,opponent_location,mat_operation,...)
8c706ff713 2023-10-14 1289: local self_location=self_location or 0
8c706ff713 2023-10-14 1290: local opponent_location=opponent_location or 0
8c706ff713 2023-10-14 1291: local operation_params={...}
8c706ff713 2023-10-14 1292: local e2=Effect.CreateEffect(c)
8c706ff713 2023-10-14 1293: e2:SetType(EFFECT_TYPE_FIELD)
8c706ff713 2023-10-14 1294: e2:SetCode(EFFECT_SPSUMMON_PROC)
8c706ff713 2023-10-14 1295: e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
8c706ff713 2023-10-14 1296: e2:SetRange(LOCATION_EXTRA)
8c706ff713 2023-10-14 1297: e2:SetCondition(Auxiliary.ContactFusionCondition(filter,self_location,opponent_location))
8c706ff713 2023-10-14 1298: e2:SetOperation(Auxiliary.ContactFusionOperation(filter,self_location,opponent_location,mat_operation,operation_params))
8c706ff713 2023-10-14 1299: c:RegisterEffect(e2)
8c706ff713 2023-10-14 1300: return e2
8c706ff713 2023-10-14 1301: end
8c706ff713 2023-10-14 1302: function Auxiliary.ContactFusionMaterialFilter(c,fc,filter)
8c706ff713 2023-10-14 1303: return c:IsCanBeFusionMaterial(fc,SUMMON_TYPE_SPECIAL) and (not filter or filter(c,fc))
8c706ff713 2023-10-14 1304: end
8c706ff713 2023-10-14 1305: function Auxiliary.ContactFusionCondition(filter,self_location,opponent_location)
8c706ff713 2023-10-14 1306: return function(e,c)
8c706ff713 2023-10-14 1307: if c==nil then return true end
8c706ff713 2023-10-14 1308: if c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end
8c706ff713 2023-10-14 1309: local tp=c:GetControler()
8c706ff713 2023-10-14 1310: local mg=Duel.GetMatchingGroup(Auxiliary.ContactFusionMaterialFilter,tp,self_location,opponent_location,c,c,filter)
8c706ff713 2023-10-14 1311: return c:CheckFusionMaterial(mg,nil,tp|0x200)
8c706ff713 2023-10-14 1312: end
8c706ff713 2023-10-14 1313: end
8c706ff713 2023-10-14 1314: function Auxiliary.ContactFusionOperation(filter,self_location,opponent_location,mat_operation,operation_params)
8c706ff713 2023-10-14 1315: return function(e,tp,eg,ep,ev,re,r,rp,c)
8c706ff713 2023-10-14 1316: local mg=Duel.GetMatchingGroup(Auxiliary.ContactFusionMaterialFilter,tp,self_location,opponent_location,c,c,filter)
8c706ff713 2023-10-14 1317: local g=Duel.SelectFusionMaterial(tp,c,mg,nil,tp|0x200)
8c706ff713 2023-10-14 1318: c:SetMaterial(g)
8c706ff713 2023-10-14 1319: mat_operation(g,table.unpack(operation_params))
8c706ff713 2023-10-14 1320: end
8c706ff713 2023-10-14 1321: end
8c706ff713 2023-10-14 1322: --send to deck of contact fusion
8c706ff713 2023-10-14 1323: function Auxiliary.tdcfop(c)
8c706ff713 2023-10-14 1324: return function(g)
8c706ff713 2023-10-14 1325: local cg=g:Filter(Card.IsFacedown,nil)
8c706ff713 2023-10-14 1326: if cg:GetCount()>0 then
8c706ff713 2023-10-14 1327: Duel.ConfirmCards(1-c:GetControler(),cg)
8c706ff713 2023-10-14 1328: end
8c706ff713 2023-10-14 1329: Duel.SendtoDeck(g,nil,SEQ_DECKSHUFFLE,REASON_COST)
8c706ff713 2023-10-14 1330: end
8c706ff713 2023-10-14 1331: end
8c706ff713 2023-10-14 1332:
8c706ff713 2023-10-14 1333: --Ritual Summon
8c706ff713 2023-10-14 1334: function Auxiliary.AddRitualProcUltimate(c,filter,level_function,greater_or_equal,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
8c706ff713 2023-10-14 1335: summon_location=summon_location or LOCATION_HAND
8c706ff713 2023-10-14 1336: local e1=Effect.CreateEffect(c)
8c706ff713 2023-10-14 1337: e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
8c706ff713 2023-10-14 1338: e1:SetType(EFFECT_TYPE_ACTIVATE)
8c706ff713 2023-10-14 1339: e1:SetCode(EVENT_FREE_CHAIN)
8c706ff713 2023-10-14 1340: e1:SetTarget(Auxiliary.RitualUltimateTarget(filter,level_function,greater_or_equal,summon_location,grave_filter,mat_filter,extra_target))
8c706ff713 2023-10-14 1341: e1:SetOperation(Auxiliary.RitualUltimateOperation(filter,level_function,greater_or_equal,summon_location,grave_filter,mat_filter,extra_operation))
8c706ff713 2023-10-14 1342: if not pause then
8c706ff713 2023-10-14 1343: c:RegisterEffect(e1)
8c706ff713 2023-10-14 1344: end
8c706ff713 2023-10-14 1345: return e1
8c706ff713 2023-10-14 1346: end
8c706ff713 2023-10-14 1347: function Auxiliary.RitualCheckGreater(g,c,lv)
8c706ff713 2023-10-14 1348: Duel.SetSelectedCard(g)
8c706ff713 2023-10-14 1349: return g:CheckWithSumGreater(Card.GetRitualLevel,lv,c)
8c706ff713 2023-10-14 1350: end
8c706ff713 2023-10-14 1351: function Auxiliary.RitualCheckEqual(g,c,lv)
8c706ff713 2023-10-14 1352: return g:CheckWithSumEqual(Card.GetRitualLevel,lv,#g,#g,c)
8c706ff713 2023-10-14 1353: end
8c706ff713 2023-10-14 1354: Auxiliary.RCheckAdditional=nil
8c706ff713 2023-10-14 1355: function Auxiliary.RitualCheck(g,tp,c,lv,greater_or_equal)
8c706ff713 2023-10-14 1356: return Auxiliary["RitualCheck"..greater_or_equal](g,c,lv) and Duel.GetMZoneCount(tp,g,tp)>0 and (not c.mat_group_check or c.mat_group_check(g,tp))
8c706ff713 2023-10-14 1357: and (not Auxiliary.RCheckAdditional or Auxiliary.RCheckAdditional(tp,g,c))
8c706ff713 2023-10-14 1358: end
8c706ff713 2023-10-14 1359: function Auxiliary.RitualCheckAdditionalLevel(c,rc)
8c706ff713 2023-10-14 1360: local raw_level=c:GetRitualLevel(rc)
8c706ff713 2023-10-14 1361: local lv1=raw_level&0xffff
8c706ff713 2023-10-14 1362: local lv2=raw_level>>16
8c706ff713 2023-10-14 1363: if lv2>0 then
8c706ff713 2023-10-14 1364: return math.min(lv1,lv2)
8c706ff713 2023-10-14 1365: else
8c706ff713 2023-10-14 1366: return lv1
8c706ff713 2023-10-14 1367: end
8c706ff713 2023-10-14 1368: end
8c706ff713 2023-10-14 1369: Auxiliary.RGCheckAdditional=nil
8c706ff713 2023-10-14 1370: function Auxiliary.RitualCheckAdditional(c,lv,greater_or_equal)
8c706ff713 2023-10-14 1371: if greater_or_equal=="Equal" then
8c706ff713 2023-10-14 1372: return function(g)
8c706ff713 2023-10-14 1373: return (not Auxiliary.RGCheckAdditional or Auxiliary.RGCheckAdditional(g)) and g:GetSum(Auxiliary.RitualCheckAdditionalLevel,c)<=lv
8c706ff713 2023-10-14 1374: end
8c706ff713 2023-10-14 1375: else
8c706ff713 2023-10-14 1376: return function(g,ec)
8c706ff713 2023-10-14 1377: if ec then
8c706ff713 2023-10-14 1378: return (not Auxiliary.RGCheckAdditional or Auxiliary.RGCheckAdditional(g,ec)) and g:GetSum(Auxiliary.RitualCheckAdditionalLevel,c)-Auxiliary.RitualCheckAdditionalLevel(ec,c)<=lv
8c706ff713 2023-10-14 1379: else
8c706ff713 2023-10-14 1380: return not Auxiliary.RGCheckAdditional or Auxiliary.RGCheckAdditional(g)
8c706ff713 2023-10-14 1381: end
8c706ff713 2023-10-14 1382: end
8c706ff713 2023-10-14 1383: end
8c706ff713 2023-10-14 1384: end
8c706ff713 2023-10-14 1385: function Auxiliary.RitualUltimateFilter(c,filter,e,tp,m1,m2,level_function,greater_or_equal,chk)
8c706ff713 2023-10-14 1386: if bit.band(c:GetType(),0x81)~=0x81 or (filter and not filter(c,e,tp,chk)) or not c:IsCanBeSpecialSummoned(e,SUMMON_TYPE_RITUAL,tp,false,true) then return false end
8c706ff713 2023-10-14 1387: local mg=m1:Filter(Card.IsCanBeRitualMaterial,c,c)
8c706ff713 2023-10-14 1388: if m2 then
8c706ff713 2023-10-14 1389: mg:Merge(m2)
8c706ff713 2023-10-14 1390: end
8c706ff713 2023-10-14 1391: if c.mat_filter then
8c706ff713 2023-10-14 1392: mg=mg:Filter(c.mat_filter,c,tp)
8c706ff713 2023-10-14 1393: else
8c706ff713 2023-10-14 1394: mg:RemoveCard(c)
8c706ff713 2023-10-14 1395: end
8c706ff713 2023-10-14 1396: local lv=level_function(c)
8c706ff713 2023-10-14 1397: Auxiliary.GCheckAdditional=Auxiliary.RitualCheckAdditional(c,lv,greater_or_equal)
8c706ff713 2023-10-14 1398: local res=mg:CheckSubGroup(Auxiliary.RitualCheck,1,lv,tp,c,lv,greater_or_equal)
8c706ff713 2023-10-14 1399: Auxiliary.GCheckAdditional=nil
8c706ff713 2023-10-14 1400: return res
8c706ff713 2023-10-14 1401: end
8c706ff713 2023-10-14 1402: function Auxiliary.RitualExtraFilter(c,f)
8c706ff713 2023-10-14 1403: return c:GetLevel()>0 and f(c) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemove()
8c706ff713 2023-10-14 1404: end
8c706ff713 2023-10-14 1405: function Auxiliary.RitualUltimateTarget(filter,level_function,greater_or_equal,summon_location,grave_filter,mat_filter,extra_target)
8c706ff713 2023-10-14 1406: return function(e,tp,eg,ep,ev,re,r,rp,chk)
8c706ff713 2023-10-14 1407: if chk==0 then
8c706ff713 2023-10-14 1408: local mg=Duel.GetRitualMaterial(tp)
8c706ff713 2023-10-14 1409: if mat_filter then mg=mg:Filter(mat_filter,nil,e,tp,true) end
8c706ff713 2023-10-14 1410: local exg=nil
8c706ff713 2023-10-14 1411: if grave_filter then
8c706ff713 2023-10-14 1412: exg=Duel.GetMatchingGroup(Auxiliary.RitualExtraFilter,tp,LOCATION_GRAVE,0,nil,grave_filter)
8c706ff713 2023-10-14 1413: end
8c706ff713 2023-10-14 1414: return Duel.IsExistingMatchingCard(Auxiliary.RitualUltimateFilter,tp,summon_location,0,1,nil,filter,e,tp,mg,exg,level_function,greater_or_equal,true)
8c706ff713 2023-10-14 1415: end
8c706ff713 2023-10-14 1416: Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,summon_location)
8c706ff713 2023-10-14 1417: if grave_filter then
8c706ff713 2023-10-14 1418: Duel.SetOperationInfo(0,CATEGORY_REMOVE,nil,0,tp,LOCATION_GRAVE)
8c706ff713 2023-10-14 1419: end
8c706ff713 2023-10-14 1420: if extra_target then
8c706ff713 2023-10-14 1421: extra_target(e,tp,eg,ep,ev,re,r,rp)
8c706ff713 2023-10-14 1422: end
8c706ff713 2023-10-14 1423: end
8c706ff713 2023-10-14 1424: end
8c706ff713 2023-10-14 1425: function Auxiliary.RitualUltimateOperation(filter,level_function,greater_or_equal,summon_location,grave_filter,mat_filter,extra_operation)
8c706ff713 2023-10-14 1426: return function(e,tp,eg,ep,ev,re,r,rp)
8c706ff713 2023-10-14 1427: ::RitualUltimateSelectStart::
8c706ff713 2023-10-14 1428: local mg=Duel.GetRitualMaterial(tp)
8c706ff713 2023-10-14 1429: if mat_filter then mg=mg:Filter(mat_filter,nil,e,tp) end
8c706ff713 2023-10-14 1430: local exg=nil
8c706ff713 2023-10-14 1431: if grave_filter then
8c706ff713 2023-10-14 1432: exg=Duel.GetMatchingGroup(Auxiliary.RitualExtraFilter,tp,LOCATION_GRAVE,0,nil,grave_filter)
8c706ff713 2023-10-14 1433: end
8c706ff713 2023-10-14 1434: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)
8c706ff713 2023-10-14 1435: local tg=Duel.SelectMatchingCard(tp,Auxiliary.NecroValleyFilter(Auxiliary.RitualUltimateFilter),tp,summon_location,0,1,1,nil,filter,e,tp,mg,exg,level_function,greater_or_equal)
8c706ff713 2023-10-14 1436: local tc=tg:GetFirst()
8c706ff713 2023-10-14 1437: local mat
8c706ff713 2023-10-14 1438: if tc then
8c706ff713 2023-10-14 1439: mg=mg:Filter(Card.IsCanBeRitualMaterial,tc,tc)
8c706ff713 2023-10-14 1440: if exg then
8c706ff713 2023-10-14 1441: mg:Merge(exg)
8c706ff713 2023-10-14 1442: end
8c706ff713 2023-10-14 1443: if tc.mat_filter then
8c706ff713 2023-10-14 1444: mg=mg:Filter(tc.mat_filter,tc,tp)
8c706ff713 2023-10-14 1445: else
8c706ff713 2023-10-14 1446: mg:RemoveCard(tc)
8c706ff713 2023-10-14 1447: end
8c706ff713 2023-10-14 1448: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_RELEASE)
8c706ff713 2023-10-14 1449: local lv=level_function(tc)
8c706ff713 2023-10-14 1450: Auxiliary.GCheckAdditional=Auxiliary.RitualCheckAdditional(tc,lv,greater_or_equal)
8c706ff713 2023-10-14 1451: mat=mg:SelectSubGroup(tp,Auxiliary.RitualCheck,true,1,lv,tp,tc,lv,greater_or_equal)
8c706ff713 2023-10-14 1452: Auxiliary.GCheckAdditional=nil
8c706ff713 2023-10-14 1453: if not mat then goto RitualUltimateSelectStart end
8c706ff713 2023-10-14 1454: tc:SetMaterial(mat)
8c706ff713 2023-10-14 1455: Duel.ReleaseRitualMaterial(mat)
8c706ff713 2023-10-14 1456: Duel.BreakEffect()
8c706ff713 2023-10-14 1457: Duel.SpecialSummon(tc,SUMMON_TYPE_RITUAL,tp,tp,false,true,POS_FACEUP)
8c706ff713 2023-10-14 1458: tc:CompleteProcedure()
8c706ff713 2023-10-14 1459: end
8c706ff713 2023-10-14 1460: if extra_operation then
8c706ff713 2023-10-14 1461: extra_operation(e,tp,eg,ep,ev,re,r,rp,tc,mat)
8c706ff713 2023-10-14 1462: end
8c706ff713 2023-10-14 1463: end
8c706ff713 2023-10-14 1464: end
8c706ff713 2023-10-14 1465: --Ritual Summon, geq fixed lv
8c706ff713 2023-10-14 1466: function Auxiliary.AddRitualProcGreater(c,filter,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
8c706ff713 2023-10-14 1467: return Auxiliary.AddRitualProcUltimate(c,filter,Card.GetOriginalLevel,"Greater",summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
8c706ff713 2023-10-14 1468: end
8c706ff713 2023-10-14 1469: function Auxiliary.AddRitualProcGreaterCode(c,code1,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
8c706ff713 2023-10-14 1470: Auxiliary.AddCodeList(c,code1)
8c706ff713 2023-10-14 1471: return Auxiliary.AddRitualProcGreater(c,Auxiliary.FilterBoolFunction(Card.IsCode,code1),summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
8c706ff713 2023-10-14 1472: end
8c706ff713 2023-10-14 1473: --Ritual Summon, equal to fixed lv
8c706ff713 2023-10-14 1474: function Auxiliary.AddRitualProcEqual(c,filter,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
8c706ff713 2023-10-14 1475: return Auxiliary.AddRitualProcUltimate(c,filter,Card.GetOriginalLevel,"Equal",summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
8c706ff713 2023-10-14 1476: end
8c706ff713 2023-10-14 1477: function Auxiliary.AddRitualProcEqualCode(c,code1,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
8c706ff713 2023-10-14 1478: Auxiliary.AddCodeList(c,code1)
8c706ff713 2023-10-14 1479: return Auxiliary.AddRitualProcEqual(c,Auxiliary.FilterBoolFunction(Card.IsCode,code1),summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
8c706ff713 2023-10-14 1480: end
8c706ff713 2023-10-14 1481: --Ritual Summon, equal to monster lv
8c706ff713 2023-10-14 1482: function Auxiliary.AddRitualProcEqual2(c,filter,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
8c706ff713 2023-10-14 1483: return Auxiliary.AddRitualProcUltimate(c,filter,Card.GetLevel,"Equal",summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
8c706ff713 2023-10-14 1484: end
8c706ff713 2023-10-14 1485: function Auxiliary.AddRitualProcEqual2Code(c,code1,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
8c706ff713 2023-10-14 1486: Auxiliary.AddCodeList(c,code1)
8c706ff713 2023-10-14 1487: return Auxiliary.AddRitualProcEqual2(c,Auxiliary.FilterBoolFunction(Card.IsCode,code1),summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
8c706ff713 2023-10-14 1488: end
8c706ff713 2023-10-14 1489: function Auxiliary.AddRitualProcEqual2Code2(c,code1,code2,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
8c706ff713 2023-10-14 1490: Auxiliary.AddCodeList(c,code1,code2)
8c706ff713 2023-10-14 1491: return Auxiliary.AddRitualProcEqual2(c,Auxiliary.FilterBoolFunction(Card.IsCode,code1,code2),summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
8c706ff713 2023-10-14 1492: end
8c706ff713 2023-10-14 1493: --Ritual Summon, geq monster lv
8c706ff713 2023-10-14 1494: function Auxiliary.AddRitualProcGreater2(c,filter,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
8c706ff713 2023-10-14 1495: return Auxiliary.AddRitualProcUltimate(c,filter,Card.GetLevel,"Greater",summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
8c706ff713 2023-10-14 1496: end
8c706ff713 2023-10-14 1497: function Auxiliary.AddRitualProcGreater2Code(c,code1,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
8c706ff713 2023-10-14 1498: Auxiliary.AddCodeList(c,code1)
8c706ff713 2023-10-14 1499: return Auxiliary.AddRitualProcGreater2(c,Auxiliary.FilterBoolFunction(Card.IsCode,code1),summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
8c706ff713 2023-10-14 1500: end
8c706ff713 2023-10-14 1501: function Auxiliary.AddRitualProcGreater2Code2(c,code1,code2,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
8c706ff713 2023-10-14 1502: Auxiliary.AddCodeList(c,code1,code2)
8c706ff713 2023-10-14 1503: return Auxiliary.AddRitualProcGreater2(c,Auxiliary.FilterBoolFunction(Card.IsCode,code1,code2),summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
8c706ff713 2023-10-14 1504: end
8c706ff713 2023-10-14 1505:
8c706ff713 2023-10-14 1506: --Pendulum Summon
8c706ff713 2023-10-14 1507: --add procedure to Pendulum monster, also allows registeration of activation effect
8c706ff713 2023-10-14 1508: function Auxiliary.EnablePendulumAttribute(c,reg)
8c706ff713 2023-10-14 1509: if not Auxiliary.PendulumChecklist then
8c706ff713 2023-10-14 1510: Auxiliary.PendulumChecklist=0
8c706ff713 2023-10-14 1511: local ge1=Effect.GlobalEffect()
8c706ff713 2023-10-14 1512: ge1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
8c706ff713 2023-10-14 1513: ge1:SetCode(EVENT_PHASE_START+PHASE_DRAW)
8c706ff713 2023-10-14 1514: ge1:SetOperation(Auxiliary.PendulumReset)
8c706ff713 2023-10-14 1515: Duel.RegisterEffect(ge1,0)
8c706ff713 2023-10-14 1516: end
8c706ff713 2023-10-14 1517: local e1=Effect.CreateEffect(c)
8c706ff713 2023-10-14 1518: e1:SetDescription(1163)
8c706ff713 2023-10-14 1519: e1:SetType(EFFECT_TYPE_FIELD)
8c706ff713 2023-10-14 1520: e1:SetCode(EFFECT_SPSUMMON_PROC_G)
8c706ff713 2023-10-14 1521: e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
8c706ff713 2023-10-14 1522: e1:SetRange(LOCATION_PZONE)
8c706ff713 2023-10-14 1523: e1:SetCondition(Auxiliary.PendCondition())
8c706ff713 2023-10-14 1524: e1:SetOperation(Auxiliary.PendOperation())
8c706ff713 2023-10-14 1525: e1:SetValue(SUMMON_TYPE_PENDULUM)
8c706ff713 2023-10-14 1526: c:RegisterEffect(e1)
8c706ff713 2023-10-14 1527: --register by default
8c706ff713 2023-10-14 1528: if reg==nil or reg then
8c706ff713 2023-10-14 1529: local e2=Effect.CreateEffect(c)
8c706ff713 2023-10-14 1530: e2:SetDescription(1160)
8c706ff713 2023-10-14 1531: e2:SetType(EFFECT_TYPE_ACTIVATE)
8c706ff713 2023-10-14 1532: e2:SetCode(EVENT_FREE_CHAIN)
8c706ff713 2023-10-14 1533: e2:SetRange(LOCATION_HAND)
8c706ff713 2023-10-14 1534: c:RegisterEffect(e2)
8c706ff713 2023-10-14 1535: end
8c706ff713 2023-10-14 1536: end
8c706ff713 2023-10-14 1537: function Auxiliary.PendulumReset(e,tp,eg,ep,ev,re,r,rp)
8c706ff713 2023-10-14 1538: Auxiliary.PendulumChecklist=0
8c706ff713 2023-10-14 1539: end
8c706ff713 2023-10-14 1540: function Auxiliary.PConditionExtraFilterSpecific(c,e,tp,lscale,rscale,te)
8c706ff713 2023-10-14 1541: if not te then return true end
8c706ff713 2023-10-14 1542: local f=te:GetValue()
8c706ff713 2023-10-14 1543: return not f or f(te,c,e,tp,lscale,rscale)
8c706ff713 2023-10-14 1544: end
8c706ff713 2023-10-14 1545: function Auxiliary.PConditionExtraFilter(c,e,tp,lscale,rscale,eset)
8c706ff713 2023-10-14 1546: for _,te in ipairs(eset) do
8c706ff713 2023-10-14 1547: if Auxiliary.PConditionExtraFilterSpecific(c,e,tp,lscale,rscale,te) then return true end
8c706ff713 2023-10-14 1548: end
8c706ff713 2023-10-14 1549: return false
8c706ff713 2023-10-14 1550: end
8c706ff713 2023-10-14 1551: function Auxiliary.PConditionFilter(c,e,tp,lscale,rscale,eset)
8c706ff713 2023-10-14 1552: local lv=0
8c706ff713 2023-10-14 1553: if c.pendulum_level then
8c706ff713 2023-10-14 1554: lv=c.pendulum_level
8c706ff713 2023-10-14 1555: else
8c706ff713 2023-10-14 1556: lv=c:GetLevel()
8c706ff713 2023-10-14 1557: end
8c706ff713 2023-10-14 1558: local bool=Auxiliary.PendulumSummonableBool(c)
8c706ff713 2023-10-14 1559: return (c:IsLocation(LOCATION_HAND) or (c:IsFaceup() and c:IsType(TYPE_PENDULUM)))
8c706ff713 2023-10-14 1560: and lv>lscale and lv<rscale and c:IsCanBeSpecialSummoned(e,SUMMON_TYPE_PENDULUM,tp,bool,bool)
8c706ff713 2023-10-14 1561: and not c:IsForbidden()
8c706ff713 2023-10-14 1562: and (Auxiliary.PendulumChecklist&(0x1<<tp)==0 or Auxiliary.PConditionExtraFilter(c,e,tp,lscale,rscale,eset))
8c706ff713 2023-10-14 1563: end
8c706ff713 2023-10-14 1564: function Auxiliary.PendCondition()
8c706ff713 2023-10-14 1565: return function(e,c,og)
8c706ff713 2023-10-14 1566: if c==nil then return true end
8c706ff713 2023-10-14 1567: local tp=c:GetControler()
8c706ff713 2023-10-14 1568: local eset={Duel.IsPlayerAffectedByEffect(tp,EFFECT_EXTRA_PENDULUM_SUMMON)}
8c706ff713 2023-10-14 1569: if Auxiliary.PendulumChecklist&(0x1<<tp)~=0 and #eset==0 then return false end
8c706ff713 2023-10-14 1570: local rpz=Duel.GetFieldCard(tp,LOCATION_PZONE,1)
8c706ff713 2023-10-14 1571: if rpz==nil or c==rpz then return false end
8c706ff713 2023-10-14 1572: local lscale=c:GetLeftScale()
8c706ff713 2023-10-14 1573: local rscale=rpz:GetRightScale()
8c706ff713 2023-10-14 1574: if lscale>rscale then lscale,rscale=rscale,lscale end
8c706ff713 2023-10-14 1575: local loc=0
8c706ff713 2023-10-14 1576: if Duel.GetLocationCount(tp,LOCATION_MZONE)>0 then loc=loc+LOCATION_HAND end
8c706ff713 2023-10-14 1577: if Duel.GetLocationCountFromEx(tp,tp,nil,TYPE_PENDULUM)>0 then loc=loc+LOCATION_EXTRA end
8c706ff713 2023-10-14 1578: if loc==0 then return false end
8c706ff713 2023-10-14 1579: local g=nil
8c706ff713 2023-10-14 1580: if og then
8c706ff713 2023-10-14 1581: g=og:Filter(Card.IsLocation,nil,loc)
8c706ff713 2023-10-14 1582: else
8c706ff713 2023-10-14 1583: g=Duel.GetFieldGroup(tp,loc,0)
8c706ff713 2023-10-14 1584: end
8c706ff713 2023-10-14 1585: return g:IsExists(Auxiliary.PConditionFilter,1,nil,e,tp,lscale,rscale,eset)
8c706ff713 2023-10-14 1586: end
8c706ff713 2023-10-14 1587: end
8c706ff713 2023-10-14 1588: function Auxiliary.PendOperationCheck(ft1,ft2,ft)
8c706ff713 2023-10-14 1589: return function(g)
8c706ff713 2023-10-14 1590: local exg=g:Filter(Card.IsLocation,nil,LOCATION_EXTRA)
8c706ff713 2023-10-14 1591: local mg=g-exg
8c706ff713 2023-10-14 1592: return #g<=ft and #exg<=ft2 and #mg<=ft1
8c706ff713 2023-10-14 1593: end
8c706ff713 2023-10-14 1594: end
8c706ff713 2023-10-14 1595: function Auxiliary.PendOperation()
8c706ff713 2023-10-14 1596: return function(e,tp,eg,ep,ev,re,r,rp,c,sg,og)
8c706ff713 2023-10-14 1597: local rpz=Duel.GetFieldCard(tp,LOCATION_PZONE,1)
8c706ff713 2023-10-14 1598: local lscale=c:GetLeftScale()
8c706ff713 2023-10-14 1599: local rscale=rpz:GetRightScale()
8c706ff713 2023-10-14 1600: if lscale>rscale then lscale,rscale=rscale,lscale end
8c706ff713 2023-10-14 1601: local eset={Duel.IsPlayerAffectedByEffect(tp,EFFECT_EXTRA_PENDULUM_SUMMON)}
8c706ff713 2023-10-14 1602: local tg=nil
8c706ff713 2023-10-14 1603: local loc=0
8c706ff713 2023-10-14 1604: local ft1=Duel.GetLocationCount(tp,LOCATION_MZONE)
8c706ff713 2023-10-14 1605: local ft2=Duel.GetLocationCountFromEx(tp,tp,nil,TYPE_PENDULUM)
8c706ff713 2023-10-14 1606: local ft=Duel.GetUsableMZoneCount(tp)
8c706ff713 2023-10-14 1607: local ect=c29724053 and Duel.IsPlayerAffectedByEffect(tp,29724053) and c29724053[tp]
8c706ff713 2023-10-14 1608: if ect and ect<ft2 then ft2=ect end
8c706ff713 2023-10-14 1609: if Duel.IsPlayerAffectedByEffect(tp,59822133) then
8c706ff713 2023-10-14 1610: if ft1>0 then ft1=1 end
8c706ff713 2023-10-14 1611: if ft2>0 then ft2=1 end
8c706ff713 2023-10-14 1612: ft=1
8c706ff713 2023-10-14 1613: end
8c706ff713 2023-10-14 1614: if ft1>0 then loc=loc|LOCATION_HAND end
8c706ff713 2023-10-14 1615: if ft2>0 then loc=loc|LOCATION_EXTRA end
8c706ff713 2023-10-14 1616: if og then
8c706ff713 2023-10-14 1617: tg=og:Filter(Card.IsLocation,nil,loc):Filter(Auxiliary.PConditionFilter,nil,e,tp,lscale,rscale,eset)
8c706ff713 2023-10-14 1618: else
8c706ff713 2023-10-14 1619: tg=Duel.GetMatchingGroup(Auxiliary.PConditionFilter,tp,loc,0,nil,e,tp,lscale,rscale,eset)
8c706ff713 2023-10-14 1620: end
8c706ff713 2023-10-14 1621: local ce=nil
8c706ff713 2023-10-14 1622: local b1=Auxiliary.PendulumChecklist&(0x1<<tp)==0
8c706ff713 2023-10-14 1623: local b2=#eset>0
8c706ff713 2023-10-14 1624: if b1 and b2 then
8c706ff713 2023-10-14 1625: local options={1163}
8c706ff713 2023-10-14 1626: for _,te in ipairs(eset) do
8c706ff713 2023-10-14 1627: table.insert(options,te:GetDescription())
8c706ff713 2023-10-14 1628: end
8c706ff713 2023-10-14 1629: local op=Duel.SelectOption(tp,table.unpack(options))
8c706ff713 2023-10-14 1630: if op>0 then
8c706ff713 2023-10-14 1631: ce=eset[op]
8c706ff713 2023-10-14 1632: end
8c706ff713 2023-10-14 1633: elseif b2 and not b1 then
8c706ff713 2023-10-14 1634: local options={}
8c706ff713 2023-10-14 1635: for _,te in ipairs(eset) do
8c706ff713 2023-10-14 1636: table.insert(options,te:GetDescription())
8c706ff713 2023-10-14 1637: end
8c706ff713 2023-10-14 1638: local op=Duel.SelectOption(tp,table.unpack(options))
8c706ff713 2023-10-14 1639: ce=eset[op+1]
8c706ff713 2023-10-14 1640: end
8c706ff713 2023-10-14 1641: if ce then
8c706ff713 2023-10-14 1642: tg=tg:Filter(Auxiliary.PConditionExtraFilterSpecific,nil,e,tp,lscale,rscale,ce)
8c706ff713 2023-10-14 1643: end
8c706ff713 2023-10-14 1644: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)
8c706ff713 2023-10-14 1645: Auxiliary.GCheckAdditional=Auxiliary.PendOperationCheck(ft1,ft2,ft)
8c706ff713 2023-10-14 1646: local g=tg:SelectSubGroup(tp,aux.TRUE,true,1,math.min(#tg,ft))
8c706ff713 2023-10-14 1647: Auxiliary.GCheckAdditional=nil
8c706ff713 2023-10-14 1648: if not g then return end
8c706ff713 2023-10-14 1649: if ce then
8c706ff713 2023-10-14 1650: Duel.Hint(HINT_CARD,0,ce:GetOwner():GetOriginalCode())
8c706ff713 2023-10-14 1651: ce:UseCountLimit(tp)
8c706ff713 2023-10-14 1652: else
8c706ff713 2023-10-14 1653: Auxiliary.PendulumChecklist=Auxiliary.PendulumChecklist|(0x1<<tp)
8c706ff713 2023-10-14 1654: end
8c706ff713 2023-10-14 1655: sg:Merge(g)
8c706ff713 2023-10-14 1656: Duel.HintSelection(Group.FromCards(c))
8c706ff713 2023-10-14 1657: Duel.HintSelection(Group.FromCards(rpz))
8c706ff713 2023-10-14 1658: end
8c706ff713 2023-10-14 1659: end
8c706ff713 2023-10-14 1660: --enable revive limit for monsters that are also pendulum sumonable from certain locations (Odd-Eyes Revolution Dragon)
8c706ff713 2023-10-14 1661: function Auxiliary.EnableReviveLimitPendulumSummonable(c, loc)
8c706ff713 2023-10-14 1662: if c:IsStatus(STATUS_COPYING_EFFECT) then return end
8c706ff713 2023-10-14 1663: c:EnableReviveLimit()
8c706ff713 2023-10-14 1664: local mt=getmetatable(c)
8c706ff713 2023-10-14 1665: if loc==nil then loc=0xff end
8c706ff713 2023-10-14 1666: mt.psummonable_location=loc
8c706ff713 2023-10-14 1667: --complete procedure on pendulum summon success
8c706ff713 2023-10-14 1668: local e1=Effect.CreateEffect(c)
8c706ff713 2023-10-14 1669: e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
8c706ff713 2023-10-14 1670: e1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_CONTINUOUS)
8c706ff713 2023-10-14 1671: e1:SetCode(EVENT_SPSUMMON_SUCCESS)
8c706ff713 2023-10-14 1672: e1:SetOperation(Auxiliary.PSSCompleteProcedure)
8c706ff713 2023-10-14 1673: c:RegisterEffect(e1)
8c706ff713 2023-10-14 1674: end
8c706ff713 2023-10-14 1675: function Auxiliary.PendulumSummonableBool(c)
8c706ff713 2023-10-14 1676: return c.psummonable_location~=nil and c:GetLocation()&c.psummonable_location>0
8c706ff713 2023-10-14 1677: end
8c706ff713 2023-10-14 1678: function Auxiliary.PSSCompleteProcedure(e,tp,eg,ep,ev,re,r,rp)
8c706ff713 2023-10-14 1679: local c=e:GetHandler()
8c706ff713 2023-10-14 1680: if c:IsSummonType(SUMMON_TYPE_PENDULUM) then
8c706ff713 2023-10-14 1681: c:CompleteProcedure()
8c706ff713 2023-10-14 1682: end
8c706ff713 2023-10-14 1683: end
8c706ff713 2023-10-14 1684:
8c706ff713 2023-10-14 1685: --Link Summon
8c706ff713 2023-10-14 1686: function Auxiliary.AddLinkProcedure(c,f,min,max,gf)
8c706ff713 2023-10-14 1687: local e1=Effect.CreateEffect(c)
8c706ff713 2023-10-14 1688: e1:SetDescription(1166)
8c706ff713 2023-10-14 1689: e1:SetType(EFFECT_TYPE_FIELD)
8c706ff713 2023-10-14 1690: e1:SetCode(EFFECT_SPSUMMON_PROC)
8c706ff713 2023-10-14 1691: e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
8c706ff713 2023-10-14 1692: e1:SetRange(LOCATION_EXTRA)
8c706ff713 2023-10-14 1693: if max==nil then max=c:GetLink() end
8c706ff713 2023-10-14 1694: e1:SetCondition(Auxiliary.LinkCondition(f,min,max,gf))
8c706ff713 2023-10-14 1695: e1:SetTarget(Auxiliary.LinkTarget(f,min,max,gf))
8c706ff713 2023-10-14 1696: e1:SetOperation(Auxiliary.LinkOperation(f,min,max,gf))
8c706ff713 2023-10-14 1697: e1:SetValue(SUMMON_TYPE_LINK)
8c706ff713 2023-10-14 1698: c:RegisterEffect(e1)
8c706ff713 2023-10-14 1699: return e1
8c706ff713 2023-10-14 1700: end
8c706ff713 2023-10-14 1701: function Auxiliary.LConditionFilter(c,f,lc,e)
8c706ff713 2023-10-14 1702: return (c:IsFaceup() or not c:IsOnField() or e:IsHasProperty(EFFECT_FLAG_SET_AVAILABLE))
8c706ff713 2023-10-14 1703: and c:IsCanBeLinkMaterial(lc) and (not f or f(c))
8c706ff713 2023-10-14 1704: end
8c706ff713 2023-10-14 1705: function Auxiliary.LExtraFilter(c,f,lc,tp)
8c706ff713 2023-10-14 1706: if c:IsOnField() and c:IsFacedown() then return false end
8c706ff713 2023-10-14 1707: if not c:IsCanBeLinkMaterial(lc) or f and not f(c) then return false end
8c706ff713 2023-10-14 1708: local le={c:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)}
8c706ff713 2023-10-14 1709: for _,te in pairs(le) do
8c706ff713 2023-10-14 1710: local tf=te:GetValue()
8c706ff713 2023-10-14 1711: local related,valid=tf(te,lc,nil,c,tp)
8c706ff713 2023-10-14 1712: if related then return true end
8c706ff713 2023-10-14 1713: end
8c706ff713 2023-10-14 1714: return false
8c706ff713 2023-10-14 1715: end
8c706ff713 2023-10-14 1716: function Auxiliary.GetLinkCount(c)
8c706ff713 2023-10-14 1717: if c:IsType(TYPE_LINK) and c:GetLink()>1 then
8c706ff713 2023-10-14 1718: return 1+0x10000*c:GetLink()
8c706ff713 2023-10-14 1719: else return 1 end
8c706ff713 2023-10-14 1720: end
8c706ff713 2023-10-14 1721: function Auxiliary.GetLinkMaterials(tp,f,lc,e)
8c706ff713 2023-10-14 1722: local mg=Duel.GetMatchingGroup(Auxiliary.LConditionFilter,tp,LOCATION_MZONE,0,nil,f,lc,e)
8c706ff713 2023-10-14 1723: local mg2=Duel.GetMatchingGroup(Auxiliary.LExtraFilter,tp,LOCATION_HAND+LOCATION_SZONE,LOCATION_ONFIELD,nil,f,lc,tp)
8c706ff713 2023-10-14 1724: if mg2:GetCount()>0 then mg:Merge(mg2) end
8c706ff713 2023-10-14 1725: return mg
8c706ff713 2023-10-14 1726: end
8c706ff713 2023-10-14 1727: function Auxiliary.LCheckOtherMaterial(c,mg,lc,tp)
8c706ff713 2023-10-14 1728: local le={c:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)}
8c706ff713 2023-10-14 1729: local res1=false
8c706ff713 2023-10-14 1730: local res2=true
8c706ff713 2023-10-14 1731: for _,te in pairs(le) do
8c706ff713 2023-10-14 1732: local f=te:GetValue()
8c706ff713 2023-10-14 1733: local related,valid=f(te,lc,mg,c,tp)
8c706ff713 2023-10-14 1734: if related then res2=false end
8c706ff713 2023-10-14 1735: if related and valid then res1=true end
8c706ff713 2023-10-14 1736: end
8c706ff713 2023-10-14 1737: return res1 or res2
8c706ff713 2023-10-14 1738: end
8c706ff713 2023-10-14 1739: function Auxiliary.LUncompatibilityFilter(c,sg,lc,tp)
8c706ff713 2023-10-14 1740: local mg=sg:Filter(aux.TRUE,c)
8c706ff713 2023-10-14 1741: return not Auxiliary.LCheckOtherMaterial(c,mg,lc,tp)
8c706ff713 2023-10-14 1742: end
8c706ff713 2023-10-14 1743: function Auxiliary.LCheckGoal(sg,tp,lc,gf,lmat)
8c706ff713 2023-10-14 1744: return sg:CheckWithSumEqual(Auxiliary.GetLinkCount,lc:GetLink(),#sg,#sg)
8c706ff713 2023-10-14 1745: and Duel.GetLocationCountFromEx(tp,tp,sg,lc)>0 and (not gf or gf(sg,lc,tp))
8c706ff713 2023-10-14 1746: and not sg:IsExists(Auxiliary.LUncompatibilityFilter,1,nil,sg,lc,tp)
8c706ff713 2023-10-14 1747: and (not lmat or sg:IsContains(lmat))
8c706ff713 2023-10-14 1748: end
8c706ff713 2023-10-14 1749: function Auxiliary.LExtraMaterialCount(mg,lc,tp)
8c706ff713 2023-10-14 1750: for tc in aux.Next(mg) do
8c706ff713 2023-10-14 1751: local le={tc:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)}
8c706ff713 2023-10-14 1752: for _,te in pairs(le) do
8c706ff713 2023-10-14 1753: local sg=mg:Filter(aux.TRUE,tc)
8c706ff713 2023-10-14 1754: local f=te:GetValue()
8c706ff713 2023-10-14 1755: local related,valid=f(te,lc,sg,tc,tp)
8c706ff713 2023-10-14 1756: if related and valid then
8c706ff713 2023-10-14 1757: te:UseCountLimit(tp)
8c706ff713 2023-10-14 1758: end
8c706ff713 2023-10-14 1759: end
8c706ff713 2023-10-14 1760: end
8c706ff713 2023-10-14 1761: end
8c706ff713 2023-10-14 1762: function Auxiliary.LinkCondition(f,minc,maxc,gf)
8c706ff713 2023-10-14 1763: return function(e,c,og,lmat,min,max)
8c706ff713 2023-10-14 1764: if c==nil then return true end
8c706ff713 2023-10-14 1765: if c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end
8c706ff713 2023-10-14 1766: local minc=minc
8c706ff713 2023-10-14 1767: local maxc=maxc
8c706ff713 2023-10-14 1768: if min then
8c706ff713 2023-10-14 1769: if min>minc then minc=min end
8c706ff713 2023-10-14 1770: if max<maxc then maxc=max end
8c706ff713 2023-10-14 1771: if minc>maxc then return false end
8c706ff713 2023-10-14 1772: end
8c706ff713 2023-10-14 1773: local tp=c:GetControler()
8c706ff713 2023-10-14 1774: local mg=nil
8c706ff713 2023-10-14 1775: if og then
8c706ff713 2023-10-14 1776: mg=og:Filter(Auxiliary.LConditionFilter,nil,f,c,e)
8c706ff713 2023-10-14 1777: else
8c706ff713 2023-10-14 1778: mg=Auxiliary.GetLinkMaterials(tp,f,c,e)
8c706ff713 2023-10-14 1779: end
8c706ff713 2023-10-14 1780: if lmat~=nil then
8c706ff713 2023-10-14 1781: if not Auxiliary.LConditionFilter(lmat,f,c,e) then return false end
8c706ff713 2023-10-14 1782: mg:AddCard(lmat)
8c706ff713 2023-10-14 1783: end
8c706ff713 2023-10-14 1784: local fg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_LMATERIAL)
8c706ff713 2023-10-14 1785: if fg:IsExists(Auxiliary.MustMaterialCounterFilter,1,nil,mg) then return false end
8c706ff713 2023-10-14 1786: Duel.SetSelectedCard(fg)
8c706ff713 2023-10-14 1787: return mg:CheckSubGroup(Auxiliary.LCheckGoal,minc,maxc,tp,c,gf,lmat)
8c706ff713 2023-10-14 1788: end
8c706ff713 2023-10-14 1789: end
8c706ff713 2023-10-14 1790: function Auxiliary.LinkTarget(f,minc,maxc,gf)
8c706ff713 2023-10-14 1791: return function(e,tp,eg,ep,ev,re,r,rp,chk,c,og,lmat,min,max)
8c706ff713 2023-10-14 1792: local minc=minc
8c706ff713 2023-10-14 1793: local maxc=maxc
8c706ff713 2023-10-14 1794: if min then
8c706ff713 2023-10-14 1795: if min>minc then minc=min end
8c706ff713 2023-10-14 1796: if max<maxc then maxc=max end
8c706ff713 2023-10-14 1797: if minc>maxc then return false end
8c706ff713 2023-10-14 1798: end
8c706ff713 2023-10-14 1799: local mg=nil
8c706ff713 2023-10-14 1800: if og then
8c706ff713 2023-10-14 1801: mg=og:Filter(Auxiliary.LConditionFilter,nil,f,c,e)
8c706ff713 2023-10-14 1802: else
8c706ff713 2023-10-14 1803: mg=Auxiliary.GetLinkMaterials(tp,f,c,e)
8c706ff713 2023-10-14 1804: end
8c706ff713 2023-10-14 1805: if lmat~=nil then
8c706ff713 2023-10-14 1806: if not Auxiliary.LConditionFilter(lmat,f,c,e) then return false end
8c706ff713 2023-10-14 1807: mg:AddCard(lmat)
8c706ff713 2023-10-14 1808: end
8c706ff713 2023-10-14 1809: local fg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_LMATERIAL)
8c706ff713 2023-10-14 1810: Duel.SetSelectedCard(fg)
8c706ff713 2023-10-14 1811: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_LMATERIAL)
8c706ff713 2023-10-14 1812: local cancel=Duel.IsSummonCancelable()
8c706ff713 2023-10-14 1813: local sg=mg:SelectSubGroup(tp,Auxiliary.LCheckGoal,cancel,minc,maxc,tp,c,gf,lmat)
8c706ff713 2023-10-14 1814: if sg then
8c706ff713 2023-10-14 1815: sg:KeepAlive()
8c706ff713 2023-10-14 1816: e:SetLabelObject(sg)
8c706ff713 2023-10-14 1817: return true
8c706ff713 2023-10-14 1818: else return false end
8c706ff713 2023-10-14 1819: end
8c706ff713 2023-10-14 1820: end
8c706ff713 2023-10-14 1821: function Auxiliary.LinkOperation(f,minc,maxc,gf)
8c706ff713 2023-10-14 1822: return function(e,tp,eg,ep,ev,re,r,rp,c,og,lmat,min,max)
8c706ff713 2023-10-14 1823: local g=e:GetLabelObject()
8c706ff713 2023-10-14 1824: c:SetMaterial(g)
8c706ff713 2023-10-14 1825: Auxiliary.LExtraMaterialCount(g,c,tp)
8c706ff713 2023-10-14 1826: Duel.SendtoGrave(g,REASON_MATERIAL+REASON_LINK)
8c706ff713 2023-10-14 1827: g:DeleteGroup()
8c706ff713 2023-10-14 1828: end
8c706ff713 2023-10-14 1829: end
8c706ff713 2023-10-14 1830:
8c706ff713 2023-10-14 1831: --Must use X as material
8c706ff713 2023-10-14 1832: function Auxiliary.MustMaterialCheck(v,tp,code)
8c706ff713 2023-10-14 1833: local g=Duel.GetMustMaterial(tp,code)
8c706ff713 2023-10-14 1834: if not v then
8c706ff713 2023-10-14 1835: if code==EFFECT_MUST_BE_XMATERIAL and Duel.IsPlayerAffectedByEffect(tp,67120578) then return false end
8c706ff713 2023-10-14 1836: return #g==0
8c706ff713 2023-10-14 1837: end
8c706ff713 2023-10-14 1838: return Duel.CheckMustMaterial(tp,v,code)
8c706ff713 2023-10-14 1839: end
8c706ff713 2023-10-14 1840: function Auxiliary.MustMaterialCounterFilter(c,g)
8c706ff713 2023-10-14 1841: return not g:IsContains(c)
8c706ff713 2023-10-14 1842: end
8c706ff713 2023-10-14 1843:
8c706ff713 2023-10-14 1844: --Summon Condition
8c706ff713 2023-10-14 1845: --sp_summon condition for fusion monster
8c706ff713 2023-10-14 1846: function Auxiliary.fuslimit(e,se,sp,st)
8c706ff713 2023-10-14 1847: return st&SUMMON_TYPE_FUSION==SUMMON_TYPE_FUSION
8c706ff713 2023-10-14 1848: end
8c706ff713 2023-10-14 1849: --sp_summon condition for ritual monster
8c706ff713 2023-10-14 1850: function Auxiliary.ritlimit(e,se,sp,st)
8c706ff713 2023-10-14 1851: return st&SUMMON_TYPE_RITUAL==SUMMON_TYPE_RITUAL
8c706ff713 2023-10-14 1852: end
8c706ff713 2023-10-14 1853: --sp_summon condition for synchro monster
8c706ff713 2023-10-14 1854: function Auxiliary.synlimit(e,se,sp,st)
8c706ff713 2023-10-14 1855: return st&SUMMON_TYPE_SYNCHRO==SUMMON_TYPE_SYNCHRO
8c706ff713 2023-10-14 1856: end
8c706ff713 2023-10-14 1857: --sp_summon condition for xyz monster
8c706ff713 2023-10-14 1858: function Auxiliary.xyzlimit(e,se,sp,st)
8c706ff713 2023-10-14 1859: return st&SUMMON_TYPE_XYZ==SUMMON_TYPE_XYZ
8c706ff713 2023-10-14 1860: end
8c706ff713 2023-10-14 1861: --sp_summon condition for pendulum monster
8c706ff713 2023-10-14 1862: function Auxiliary.penlimit(e,se,sp,st)
8c706ff713 2023-10-14 1863: return st&SUMMON_TYPE_PENDULUM==SUMMON_TYPE_PENDULUM
8c706ff713 2023-10-14 1864: end
8c706ff713 2023-10-14 1865: --sp_summon condition for link monster
8c706ff713 2023-10-14 1866: function Auxiliary.linklimit(e,se,sp,st)
8c706ff713 2023-10-14 1867: return st&SUMMON_TYPE_LINK==SUMMON_TYPE_LINK
8c706ff713 2023-10-14 1868: end