0183a50e08 2024-07-01 1: Auxiliary={}
0183a50e08 2024-07-01 2: aux=Auxiliary
0183a50e08 2024-07-01 3: POS_FACEUP_DEFENCE=POS_FACEUP_DEFENSE
0183a50e08 2024-07-01 4: POS_FACEDOWN_DEFENCE=POS_FACEDOWN_DEFENSE
0183a50e08 2024-07-01 5: RACE_CYBERS=RACE_CYBERSE
0183a50e08 2024-07-01 6:
0183a50e08 2024-07-01 7: function GetID()
0183a50e08 2024-07-01 8: local offset=self_code<100000000 and 1 or 100
0183a50e08 2024-07-01 9: return self_table,self_code,offset
0183a50e08 2024-07-01 10: end
0183a50e08 2024-07-01 11:
0183a50e08 2024-07-01 12: --the lua version of the bit32 lib, which is deprecated in lua 5.3
0183a50e08 2024-07-01 13: bit={}
0183a50e08 2024-07-01 14: function bit.band(a,b)
0183a50e08 2024-07-01 15: return a&b
0183a50e08 2024-07-01 16: end
0183a50e08 2024-07-01 17: function bit.bor(a,b)
0183a50e08 2024-07-01 18: return a|b
0183a50e08 2024-07-01 19: end
0183a50e08 2024-07-01 20: function bit.bxor(a,b)
0183a50e08 2024-07-01 21: return a~b
0183a50e08 2024-07-01 22: end
0183a50e08 2024-07-01 23: function bit.lshift(a,b)
0183a50e08 2024-07-01 24: return a<<b
0183a50e08 2024-07-01 25: end
0183a50e08 2024-07-01 26: function bit.rshift(a,b)
0183a50e08 2024-07-01 27: return a>>b
0183a50e08 2024-07-01 28: end
0183a50e08 2024-07-01 29: function bit.bnot(a)
0183a50e08 2024-07-01 30: return ~a
0183a50e08 2024-07-01 31: end
0183a50e08 2024-07-01 32: local function fieldargs(f,width)
0183a50e08 2024-07-01 33: local w=width or 1
0183a50e08 2024-07-01 34: assert(f>=0,"field cannot be negative")
0183a50e08 2024-07-01 35: assert(w>0,"width must be positive")
0183a50e08 2024-07-01 36: assert(f+w<=32,"trying to access non-existent bits")
0183a50e08 2024-07-01 37: return f,~(-1<<w)
0183a50e08 2024-07-01 38: end
0183a50e08 2024-07-01 39: function bit.extract(r,field,width)
0183a50e08 2024-07-01 40: width=width or 1
0183a50e08 2024-07-01 41: local f,m=fieldargs(field,width)
0183a50e08 2024-07-01 42: return (r>>f)&m
0183a50e08 2024-07-01 43: end
0183a50e08 2024-07-01 44: function bit.replace(r,v,field,width)
0183a50e08 2024-07-01 45: width=width or 1
0183a50e08 2024-07-01 46: local f,m=fieldargs(field,width)
0183a50e08 2024-07-01 47: return (r&~(m<<f))|((v&m)<< f)
0183a50e08 2024-07-01 48: end
0183a50e08 2024-07-01 49:
0183a50e08 2024-07-01 50: ---Subgroup check function
0183a50e08 2024-07-01 51: ---@param sg Group
0183a50e08 2024-07-01 52: ---@param c Card|nil
0183a50e08 2024-07-01 53: ---@param g Group
0183a50e08 2024-07-01 54: ---@return boolean
0183a50e08 2024-07-01 55: Auxiliary.GCheckAdditional=function(sg,c,g) return true end
0183a50e08 2024-07-01 56:
0183a50e08 2024-07-01 57: --the table of xyz number
0183a50e08 2024-07-01 58: Auxiliary.xyz_number={}
0183a50e08 2024-07-01 59: function Auxiliary.GetXyzNumber(v)
0183a50e08 2024-07-01 60: local id
0183a50e08 2024-07-01 61: if Auxiliary.GetValueType(v)=="Card" then id=v:GetCode() end
0183a50e08 2024-07-01 62: if Auxiliary.GetValueType(v)=="number" then id=v end
0183a50e08 2024-07-01 63: return Auxiliary.xyz_number[id]
0183a50e08 2024-07-01 64: end
0183a50e08 2024-07-01 65:
0183a50e08 2024-07-01 66: --iterator for getting playerid of current turn player and the other player
0183a50e08 2024-07-01 67: function Auxiliary.TurnPlayers()
0183a50e08 2024-07-01 68: local i=0
0183a50e08 2024-07-01 69: return function()
0183a50e08 2024-07-01 70: i=i+1
0183a50e08 2024-07-01 71: if i==1 then return Duel.GetTurnPlayer() end
0183a50e08 2024-07-01 72: if i==2 then return 1-Duel.GetTurnPlayer() end
0183a50e08 2024-07-01 73: end
0183a50e08 2024-07-01 74: end
0183a50e08 2024-07-01 75:
0183a50e08 2024-07-01 76: Auxiliary.idx_table=table.pack(1,2,3,4,5,6,7,8)
0183a50e08 2024-07-01 77:
0183a50e08 2024-07-01 78: function Auxiliary.Stringid(code,id)
0183a50e08 2024-07-01 79: return code*16+id
0183a50e08 2024-07-01 80: end
0183a50e08 2024-07-01 81: function Auxiliary.Next(g)
0183a50e08 2024-07-01 82: local first=true
0183a50e08 2024-07-01 83: return function()
0183a50e08 2024-07-01 84: if first then first=false return g:GetFirst()
0183a50e08 2024-07-01 85: else return g:GetNext() end
0183a50e08 2024-07-01 86: end
0183a50e08 2024-07-01 87: end
0183a50e08 2024-07-01 88: function Auxiliary.NULL()
0183a50e08 2024-07-01 89: end
0183a50e08 2024-07-01 90: function Auxiliary.TRUE()
0183a50e08 2024-07-01 91: return true
0183a50e08 2024-07-01 92: end
0183a50e08 2024-07-01 93: function Auxiliary.FALSE()
0183a50e08 2024-07-01 94: return false
0183a50e08 2024-07-01 95: end
0183a50e08 2024-07-01 96: function Auxiliary.AND(...)
0183a50e08 2024-07-01 97: local function_list={...}
0183a50e08 2024-07-01 98: return function(...)
0183a50e08 2024-07-01 99: local res=false
0183a50e08 2024-07-01 100: for i,f in ipairs(function_list) do
0183a50e08 2024-07-01 101: res=f(...)
0183a50e08 2024-07-01 102: if not res then return res end
0183a50e08 2024-07-01 103: end
0183a50e08 2024-07-01 104: return res
0183a50e08 2024-07-01 105: end
0183a50e08 2024-07-01 106: end
0183a50e08 2024-07-01 107: function Auxiliary.OR(...)
0183a50e08 2024-07-01 108: local function_list={...}
0183a50e08 2024-07-01 109: return function(...)
0183a50e08 2024-07-01 110: local res=false
0183a50e08 2024-07-01 111: for i,f in ipairs(function_list) do
0183a50e08 2024-07-01 112: res=f(...)
0183a50e08 2024-07-01 113: if res then return res end
0183a50e08 2024-07-01 114: end
0183a50e08 2024-07-01 115: return res
0183a50e08 2024-07-01 116: end
0183a50e08 2024-07-01 117: end
0183a50e08 2024-07-01 118: function Auxiliary.NOT(f)
0183a50e08 2024-07-01 119: return function(...)
0183a50e08 2024-07-01 120: return not f(...)
0183a50e08 2024-07-01 121: end
0183a50e08 2024-07-01 122: end
0183a50e08 2024-07-01 123: function Auxiliary.BeginPuzzle(effect)
0183a50e08 2024-07-01 124: local e1=Effect.GlobalEffect()
0183a50e08 2024-07-01 125: e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
0183a50e08 2024-07-01 126: e1:SetCode(EVENT_TURN_END)
0183a50e08 2024-07-01 127: e1:SetCountLimit(1)
0183a50e08 2024-07-01 128: e1:SetOperation(Auxiliary.PuzzleOp)
0183a50e08 2024-07-01 129: Duel.RegisterEffect(e1,0)
0183a50e08 2024-07-01 130: local e2=Effect.GlobalEffect()
0183a50e08 2024-07-01 131: e2:SetType(EFFECT_TYPE_FIELD)
0183a50e08 2024-07-01 132: e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
0183a50e08 2024-07-01 133: e2:SetCode(EFFECT_SKIP_DP)
0183a50e08 2024-07-01 134: e2:SetTargetRange(1,0)
0183a50e08 2024-07-01 135: Duel.RegisterEffect(e2,0)
0183a50e08 2024-07-01 136: local e3=Effect.GlobalEffect()
0183a50e08 2024-07-01 137: e3:SetType(EFFECT_TYPE_FIELD)
0183a50e08 2024-07-01 138: e3:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
0183a50e08 2024-07-01 139: e3:SetCode(EFFECT_SKIP_SP)
0183a50e08 2024-07-01 140: e3:SetTargetRange(1,0)
0183a50e08 2024-07-01 141: Duel.RegisterEffect(e3,0)
0183a50e08 2024-07-01 142: end
0183a50e08 2024-07-01 143: function Auxiliary.PuzzleOp(e,tp)
0183a50e08 2024-07-01 144: Duel.SetLP(0,0)
0183a50e08 2024-07-01 145: end
0183a50e08 2024-07-01 146: ---Duel.SelectOption with option condition
0183a50e08 2024-07-01 147: ---Return value starts from 1, different from Duel.SelectOption
0183a50e08 2024-07-01 148: ---@param tp integer
0183a50e08 2024-07-01 149: ---@param ... table {condition, option[, value]}
0183a50e08 2024-07-01 150: ---@return integer
0183a50e08 2024-07-01 151: function Auxiliary.SelectFromOptions(tp,...)
0183a50e08 2024-07-01 152: local options={...}
0183a50e08 2024-07-01 153: local ops={}
0183a50e08 2024-07-01 154: local opvals={}
0183a50e08 2024-07-01 155: for i=1,#options do
0183a50e08 2024-07-01 156: if options[i][1] then
0183a50e08 2024-07-01 157: table.insert(ops,options[i][2])
0183a50e08 2024-07-01 158: table.insert(opvals,options[i][3] or i)
0183a50e08 2024-07-01 159: end
0183a50e08 2024-07-01 160: end
0183a50e08 2024-07-01 161: if #ops==0 then return nil end
0183a50e08 2024-07-01 162: local select=Duel.SelectOption(tp,table.unpack(ops))
0183a50e08 2024-07-01 163: return opvals[select+1]
0183a50e08 2024-07-01 164: end
0183a50e08 2024-07-01 165: --register effect of return to hand for Spirit monsters
0183a50e08 2024-07-01 166: function Auxiliary.EnableSpiritReturn(c,event1,...)
0183a50e08 2024-07-01 167: local e1=Effect.CreateEffect(c)
0183a50e08 2024-07-01 168: e1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_CONTINUOUS)
0183a50e08 2024-07-01 169: e1:SetCode(event1)
0183a50e08 2024-07-01 170: e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
0183a50e08 2024-07-01 171: e1:SetOperation(Auxiliary.SpiritReturnReg)
0183a50e08 2024-07-01 172: c:RegisterEffect(e1)
0183a50e08 2024-07-01 173: for i,event in ipairs{...} do
0183a50e08 2024-07-01 174: local e2=e1:Clone()
0183a50e08 2024-07-01 175: e2:SetCode(event)
0183a50e08 2024-07-01 176: c:RegisterEffect(e2)
0183a50e08 2024-07-01 177: end
0183a50e08 2024-07-01 178: end
0183a50e08 2024-07-01 179: function Auxiliary.SpiritReturnReg(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 180: local c=e:GetHandler()
0183a50e08 2024-07-01 181: local e1=Effect.CreateEffect(c)
0183a50e08 2024-07-01 182: e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_F)
0183a50e08 2024-07-01 183: e1:SetDescription(1104)
0183a50e08 2024-07-01 184: e1:SetCategory(CATEGORY_TOHAND)
0183a50e08 2024-07-01 185: e1:SetCode(EVENT_PHASE+PHASE_END)
0183a50e08 2024-07-01 186: e1:SetRange(LOCATION_MZONE)
0183a50e08 2024-07-01 187: e1:SetCountLimit(1)
0183a50e08 2024-07-01 188: e1:SetReset(RESET_EVENT+0xd7e0000+RESET_PHASE+PHASE_END)
0183a50e08 2024-07-01 189: e1:SetCondition(Auxiliary.SpiritReturnConditionForced)
0183a50e08 2024-07-01 190: e1:SetTarget(Auxiliary.SpiritReturnTargetForced)
0183a50e08 2024-07-01 191: e1:SetOperation(Auxiliary.SpiritReturnOperation)
0183a50e08 2024-07-01 192: c:RegisterEffect(e1)
0183a50e08 2024-07-01 193: local e2=e1:Clone()
0183a50e08 2024-07-01 194: e2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_O)
0183a50e08 2024-07-01 195: e2:SetCondition(Auxiliary.SpiritReturnConditionOptional)
0183a50e08 2024-07-01 196: e2:SetTarget(Auxiliary.SpiritReturnTargetOptional)
0183a50e08 2024-07-01 197: c:RegisterEffect(e2)
0183a50e08 2024-07-01 198: end
0183a50e08 2024-07-01 199: function Auxiliary.SpiritReturnConditionForced(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 200: local c=e:GetHandler()
0183a50e08 2024-07-01 201: return not c:IsHasEffect(EFFECT_SPIRIT_DONOT_RETURN) and not c:IsHasEffect(EFFECT_SPIRIT_MAYNOT_RETURN)
0183a50e08 2024-07-01 202: end
0183a50e08 2024-07-01 203: function Auxiliary.SpiritReturnTargetForced(e,tp,eg,ep,ev,re,r,rp,chk)
0183a50e08 2024-07-01 204: if chk==0 then return true end
0183a50e08 2024-07-01 205: Duel.SetOperationInfo(0,CATEGORY_TOHAND,e:GetHandler(),1,0,0)
0183a50e08 2024-07-01 206: end
0183a50e08 2024-07-01 207: function Auxiliary.SpiritReturnConditionOptional(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 208: local c=e:GetHandler()
0183a50e08 2024-07-01 209: return not c:IsHasEffect(EFFECT_SPIRIT_DONOT_RETURN) and c:IsHasEffect(EFFECT_SPIRIT_MAYNOT_RETURN)
0183a50e08 2024-07-01 210: end
0183a50e08 2024-07-01 211: function Auxiliary.SpiritReturnTargetOptional(e,tp,eg,ep,ev,re,r,rp,chk)
0183a50e08 2024-07-01 212: if chk==0 then return e:GetHandler():IsAbleToHand() end
0183a50e08 2024-07-01 213: Duel.SetOperationInfo(0,CATEGORY_TOHAND,e:GetHandler(),1,0,0)
0183a50e08 2024-07-01 214: end
0183a50e08 2024-07-01 215: function Auxiliary.SpiritReturnOperation(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 216: local c=e:GetHandler()
0183a50e08 2024-07-01 217: if c:IsRelateToEffect(e) then
0183a50e08 2024-07-01 218: Duel.SendtoHand(c,nil,REASON_EFFECT)
0183a50e08 2024-07-01 219: end
0183a50e08 2024-07-01 220: end
0183a50e08 2024-07-01 221: function Auxiliary.EnableNeosReturn(c,operation,set_category)
0183a50e08 2024-07-01 222: --return
0183a50e08 2024-07-01 223: local e1=Effect.CreateEffect(c)
0183a50e08 2024-07-01 224: e1:SetDescription(1193)
0183a50e08 2024-07-01 225: e1:SetCategory(CATEGORY_TODECK)
0183a50e08 2024-07-01 226: e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_F)
0183a50e08 2024-07-01 227: e1:SetCode(EVENT_PHASE+PHASE_END)
0183a50e08 2024-07-01 228: e1:SetRange(LOCATION_MZONE)
0183a50e08 2024-07-01 229: e1:SetCountLimit(1)
0183a50e08 2024-07-01 230: e1:SetCondition(Auxiliary.NeosReturnConditionForced)
0183a50e08 2024-07-01 231: e1:SetTarget(Auxiliary.NeosReturnTargetForced(set_category))
0183a50e08 2024-07-01 232: e1:SetOperation(operation)
0183a50e08 2024-07-01 233: c:RegisterEffect(e1)
0183a50e08 2024-07-01 234: local e2=e1:Clone()
0183a50e08 2024-07-01 235: e2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_O)
0183a50e08 2024-07-01 236: e2:SetCondition(Auxiliary.NeosReturnConditionOptional)
0183a50e08 2024-07-01 237: e2:SetTarget(Auxiliary.NeosReturnTargetOptional(set_category))
0183a50e08 2024-07-01 238: c:RegisterEffect(e2)
0183a50e08 2024-07-01 239: return e1,e2
0183a50e08 2024-07-01 240: end
0183a50e08 2024-07-01 241: function Auxiliary.NeosReturnConditionForced(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 242: return not e:GetHandler():IsHasEffect(42015635)
0183a50e08 2024-07-01 243: end
0183a50e08 2024-07-01 244: function Auxiliary.NeosReturnTargetForced(set_category)
0183a50e08 2024-07-01 245: return function(e,tp,eg,ep,ev,re,r,rp,chk)
0183a50e08 2024-07-01 246: if chk==0 then return true end
0183a50e08 2024-07-01 247: Duel.SetOperationInfo(0,CATEGORY_TODECK,e:GetHandler(),1,0,0)
0183a50e08 2024-07-01 248: if set_category then set_category(e,tp,eg,ep,ev,re,r,rp) end
0183a50e08 2024-07-01 249: end
0183a50e08 2024-07-01 250: end
0183a50e08 2024-07-01 251: function Auxiliary.NeosReturnConditionOptional(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 252: return e:GetHandler():IsHasEffect(42015635)
0183a50e08 2024-07-01 253: end
0183a50e08 2024-07-01 254: function Auxiliary.NeosReturnTargetOptional(set_category)
0183a50e08 2024-07-01 255: return function(e,tp,eg,ep,ev,re,r,rp,chk)
0183a50e08 2024-07-01 256: if chk==0 then return e:GetHandler():IsAbleToExtra() end
0183a50e08 2024-07-01 257: Duel.SetOperationInfo(0,CATEGORY_TODECK,e:GetHandler(),1,0,0)
0183a50e08 2024-07-01 258: if set_category then set_category(e,tp,eg,ep,ev,re,r,rp) end
0183a50e08 2024-07-01 259: end
0183a50e08 2024-07-01 260: end
0183a50e08 2024-07-01 261: function Auxiliary.IsUnionState(effect)
0183a50e08 2024-07-01 262: local c=effect:GetHandler()
0183a50e08 2024-07-01 263: return c:IsHasEffect(EFFECT_UNION_STATUS) and c:GetEquipTarget()
0183a50e08 2024-07-01 264: end
0183a50e08 2024-07-01 265: --set EFFECT_EQUIP_LIMIT after equipping
0183a50e08 2024-07-01 266: function Auxiliary.SetUnionState(c)
0183a50e08 2024-07-01 267: local eset={c:IsHasEffect(EFFECT_UNION_LIMIT)}
0183a50e08 2024-07-01 268: if #eset==0 then return end
0183a50e08 2024-07-01 269: local e0=Effect.CreateEffect(c)
0183a50e08 2024-07-01 270: e0:SetType(EFFECT_TYPE_SINGLE)
0183a50e08 2024-07-01 271: e0:SetCode(EFFECT_EQUIP_LIMIT)
0183a50e08 2024-07-01 272: e0:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
0183a50e08 2024-07-01 273: e0:SetValue(eset[1]:GetValue())
0183a50e08 2024-07-01 274: e0:SetReset(RESET_EVENT+RESETS_STANDARD)
0183a50e08 2024-07-01 275: c:RegisterEffect(e0)
0183a50e08 2024-07-01 276: local e1=Effect.CreateEffect(c)
0183a50e08 2024-07-01 277: e1:SetType(EFFECT_TYPE_SINGLE)
0183a50e08 2024-07-01 278: e1:SetCode(EFFECT_UNION_STATUS)
0183a50e08 2024-07-01 279: e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
0183a50e08 2024-07-01 280: e1:SetReset(RESET_EVENT+RESETS_STANDARD)
0183a50e08 2024-07-01 281: c:RegisterEffect(e1)
0183a50e08 2024-07-01 282: if c.old_union then
0183a50e08 2024-07-01 283: local e2=e1:Clone()
0183a50e08 2024-07-01 284: e2:SetCode(EFFECT_OLDUNION_STATUS)
0183a50e08 2024-07-01 285: c:RegisterEffect(e2)
0183a50e08 2024-07-01 286: end
0183a50e08 2024-07-01 287: end
0183a50e08 2024-07-01 288: --uc: the union monster to be equipped, tc: the target monster
0183a50e08 2024-07-01 289: function Auxiliary.CheckUnionEquip(uc,tc,exclude_modern_count)
0183a50e08 2024-07-01 290: local modern_count,old_count=tc:GetUnionCount()
0183a50e08 2024-07-01 291: if exclude_modern_count then modern_count=modern_count-exclude_modern_count end
0183a50e08 2024-07-01 292: if uc.old_union then return modern_count==0
0183a50e08 2024-07-01 293: else return old_count==0 end
0183a50e08 2024-07-01 294: end
0183a50e08 2024-07-01 295: --EFFECT_DESTROY_SUBSTITUTE filter for modern union monsters
0183a50e08 2024-07-01 296: function Auxiliary.UnionReplaceFilter(e,re,r,rp)
0183a50e08 2024-07-01 297: return r&(REASON_BATTLE+REASON_EFFECT)~=0
0183a50e08 2024-07-01 298: end
0183a50e08 2024-07-01 299: ---add effect to modern union monsters
0183a50e08 2024-07-01 300: ---@param c Card
0183a50e08 2024-07-01 301: ---@param filter function
0183a50e08 2024-07-01 302: function Auxiliary.EnableUnionAttribute(c,filter)
0183a50e08 2024-07-01 303: local equip_limit=Auxiliary.UnionEquipLimit(filter)
0183a50e08 2024-07-01 304: --destroy sub
0183a50e08 2024-07-01 305: local e1=Effect.CreateEffect(c)
0183a50e08 2024-07-01 306: e1:SetType(EFFECT_TYPE_EQUIP)
0183a50e08 2024-07-01 307: e1:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
0183a50e08 2024-07-01 308: e1:SetCode(EFFECT_DESTROY_SUBSTITUTE)
0183a50e08 2024-07-01 309: e1:SetValue(Auxiliary.UnionReplaceFilter)
0183a50e08 2024-07-01 310: c:RegisterEffect(e1)
0183a50e08 2024-07-01 311: --limit
0183a50e08 2024-07-01 312: local e2=Effect.CreateEffect(c)
0183a50e08 2024-07-01 313: e2:SetType(EFFECT_TYPE_SINGLE)
0183a50e08 2024-07-01 314: e2:SetCode(EFFECT_UNION_LIMIT)
0183a50e08 2024-07-01 315: e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
0183a50e08 2024-07-01 316: e2:SetValue(equip_limit)
0183a50e08 2024-07-01 317: c:RegisterEffect(e2)
0183a50e08 2024-07-01 318: --equip
0183a50e08 2024-07-01 319: local equip_filter=Auxiliary.UnionEquipFilter(filter)
0183a50e08 2024-07-01 320: local e3=Effect.CreateEffect(c)
0183a50e08 2024-07-01 321: e3:SetDescription(1068)
0183a50e08 2024-07-01 322: e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
0183a50e08 2024-07-01 323: e3:SetCategory(CATEGORY_EQUIP)
0183a50e08 2024-07-01 324: e3:SetType(EFFECT_TYPE_IGNITION)
0183a50e08 2024-07-01 325: e3:SetRange(LOCATION_MZONE)
0183a50e08 2024-07-01 326: e3:SetTarget(Auxiliary.UnionEquipTarget(equip_filter))
0183a50e08 2024-07-01 327: e3:SetOperation(Auxiliary.UnionEquipOperation(equip_filter))
0183a50e08 2024-07-01 328: c:RegisterEffect(e3)
0183a50e08 2024-07-01 329: --unequip
0183a50e08 2024-07-01 330: local e4=Effect.CreateEffect(c)
0183a50e08 2024-07-01 331: e4:SetDescription(1152)
0183a50e08 2024-07-01 332: e4:SetCategory(CATEGORY_SPECIAL_SUMMON)
0183a50e08 2024-07-01 333: e4:SetType(EFFECT_TYPE_IGNITION)
0183a50e08 2024-07-01 334: e4:SetRange(LOCATION_SZONE)
0183a50e08 2024-07-01 335: e4:SetTarget(Auxiliary.UnionUnequipTarget)
0183a50e08 2024-07-01 336: e4:SetOperation(Auxiliary.UnionUnequipOperation)
0183a50e08 2024-07-01 337: c:RegisterEffect(e4)
0183a50e08 2024-07-01 338: end
0183a50e08 2024-07-01 339: function Auxiliary.UnionEquipFilter(filter)
0183a50e08 2024-07-01 340: return function(c,tp)
0183a50e08 2024-07-01 341: local ct1,ct2=c:GetUnionCount()
0183a50e08 2024-07-01 342: return c:IsFaceup() and ct2==0 and c:IsControler(tp) and filter(c)
0183a50e08 2024-07-01 343: end
0183a50e08 2024-07-01 344: end
0183a50e08 2024-07-01 345: function Auxiliary.UnionEquipLimit(filter)
0183a50e08 2024-07-01 346: return function(e,c)
0183a50e08 2024-07-01 347: return (c:IsControler(e:GetHandlerPlayer()) and filter(c)) or e:GetHandler():GetEquipTarget()==c
0183a50e08 2024-07-01 348: end
0183a50e08 2024-07-01 349: end
0183a50e08 2024-07-01 350: function Auxiliary.UnionEquipTarget(equip_filter)
0183a50e08 2024-07-01 351: return function(e,tp,eg,ep,ev,re,r,rp,chk,chkc)
0183a50e08 2024-07-01 352: local c=e:GetHandler()
0183a50e08 2024-07-01 353: if chkc then return chkc:IsLocation(LOCATION_MZONE) and equip_filter(chkc,tp) end
0183a50e08 2024-07-01 354: if chk==0 then return c:GetFlagEffect(FLAG_ID_UNION)==0 and Duel.GetLocationCount(tp,LOCATION_SZONE)>0
0183a50e08 2024-07-01 355: and Duel.IsExistingTarget(equip_filter,tp,LOCATION_MZONE,0,1,c,tp) end
0183a50e08 2024-07-01 356: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_EQUIP)
0183a50e08 2024-07-01 357: local g=Duel.SelectTarget(tp,equip_filter,tp,LOCATION_MZONE,0,1,1,c,tp)
0183a50e08 2024-07-01 358: Duel.SetOperationInfo(0,CATEGORY_EQUIP,g,1,0,0)
0183a50e08 2024-07-01 359: c:RegisterFlagEffect(FLAG_ID_UNION,RESET_EVENT+0x7e0000+RESET_PHASE+PHASE_END,0,1)
0183a50e08 2024-07-01 360: end
0183a50e08 2024-07-01 361: end
0183a50e08 2024-07-01 362: function Auxiliary.UnionEquipOperation(equip_filter)
0183a50e08 2024-07-01 363: return function(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 364: local c=e:GetHandler()
0183a50e08 2024-07-01 365: local tc=Duel.GetFirstTarget()
0183a50e08 2024-07-01 366: if not c:IsRelateToEffect(e) or c:IsFacedown() then return end
0183a50e08 2024-07-01 367: if not tc:IsRelateToEffect(e) or not equip_filter(tc,tp) then
0183a50e08 2024-07-01 368: Duel.SendtoGrave(c,REASON_RULE)
0183a50e08 2024-07-01 369: return
0183a50e08 2024-07-01 370: end
0183a50e08 2024-07-01 371: if not Duel.Equip(tp,c,tc,false) then return end
0183a50e08 2024-07-01 372: Auxiliary.SetUnionState(c)
0183a50e08 2024-07-01 373: end
0183a50e08 2024-07-01 374: end
0183a50e08 2024-07-01 375: function Auxiliary.UnionUnequipTarget(e,tp,eg,ep,ev,re,r,rp,chk)
0183a50e08 2024-07-01 376: local c=e:GetHandler()
0183a50e08 2024-07-01 377: if chk==0 then return c:GetFlagEffect(FLAG_ID_UNION)==0 and Duel.GetLocationCount(tp,LOCATION_MZONE)>0
0183a50e08 2024-07-01 378: and c:GetEquipTarget() and c:IsCanBeSpecialSummoned(e,0,tp,true,false) end
0183a50e08 2024-07-01 379: Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,c,1,0,0)
0183a50e08 2024-07-01 380: c:RegisterFlagEffect(FLAG_ID_UNION,RESET_EVENT+0x7e0000+RESET_PHASE+PHASE_END,0,1)
0183a50e08 2024-07-01 381: end
0183a50e08 2024-07-01 382: function Auxiliary.UnionUnequipOperation(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 383: local c=e:GetHandler()
0183a50e08 2024-07-01 384: if not c:IsRelateToEffect(e) then return end
0183a50e08 2024-07-01 385: Duel.SpecialSummon(c,0,tp,tp,true,false,POS_FACEUP)
0183a50e08 2024-07-01 386: end
0183a50e08 2024-07-01 387: function Auxiliary.EnableChangeCode(c,code,location,condition)
0183a50e08 2024-07-01 388: Auxiliary.AddCodeList(c,code)
0183a50e08 2024-07-01 389: local loc=c:GetOriginalType()&TYPE_MONSTER~=0 and LOCATION_MZONE or LOCATION_SZONE
0183a50e08 2024-07-01 390: loc=location or loc
0183a50e08 2024-07-01 391: if condition==nil then condition=Auxiliary.TRUE end
0183a50e08 2024-07-01 392: local e1=Effect.CreateEffect(c)
0183a50e08 2024-07-01 393: e1:SetType(EFFECT_TYPE_SINGLE)
0183a50e08 2024-07-01 394: e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
0183a50e08 2024-07-01 395: e1:SetCode(EFFECT_CHANGE_CODE)
0183a50e08 2024-07-01 396: e1:SetRange(loc)
0183a50e08 2024-07-01 397: e1:SetCondition(condition)
0183a50e08 2024-07-01 398: e1:SetValue(code)
0183a50e08 2024-07-01 399: c:RegisterEffect(e1)
0183a50e08 2024-07-01 400: return e1
0183a50e08 2024-07-01 401: end
0183a50e08 2024-07-01 402: function Auxiliary.TargetEqualFunction(f,value,...)
0183a50e08 2024-07-01 403: local ext_params={...}
0183a50e08 2024-07-01 404: return function(effect,target)
0183a50e08 2024-07-01 405: return f(target,table.unpack(ext_params))==value
0183a50e08 2024-07-01 406: end
0183a50e08 2024-07-01 407: end
0183a50e08 2024-07-01 408: function Auxiliary.TargetBoolFunction(f,...)
0183a50e08 2024-07-01 409: local ext_params={...}
0183a50e08 2024-07-01 410: return function(effect,target)
0183a50e08 2024-07-01 411: return f(target,table.unpack(ext_params))
0183a50e08 2024-07-01 412: end
0183a50e08 2024-07-01 413: end
0183a50e08 2024-07-01 414: function Auxiliary.FilterEqualFunction(f,value,...)
0183a50e08 2024-07-01 415: local ext_params={...}
0183a50e08 2024-07-01 416: return function(target)
0183a50e08 2024-07-01 417: return f(target,table.unpack(ext_params))==value
0183a50e08 2024-07-01 418: end
0183a50e08 2024-07-01 419: end
0183a50e08 2024-07-01 420: function Auxiliary.FilterBoolFunction(f,...)
0183a50e08 2024-07-01 421: local ext_params={...}
0183a50e08 2024-07-01 422: return function(target)
0183a50e08 2024-07-01 423: return f(target,table.unpack(ext_params))
0183a50e08 2024-07-01 424: end
0183a50e08 2024-07-01 425: end
0183a50e08 2024-07-01 426: function Auxiliary.GetValueType(v)
0183a50e08 2024-07-01 427: local t=type(v)
0183a50e08 2024-07-01 428: if t=="userdata" then
0183a50e08 2024-07-01 429: local mt=getmetatable(v)
0183a50e08 2024-07-01 430: if mt==Group then return "Group"
0183a50e08 2024-07-01 431: elseif mt==Effect then return "Effect"
0183a50e08 2024-07-01 432: else return "Card" end
0183a50e08 2024-07-01 433: else return t end
0183a50e08 2024-07-01 434: end
0183a50e08 2024-07-01 435: --Extra Deck summon count
0183a50e08 2024-07-01 436: function Auxiliary.EnableExtraDeckSummonCountLimit()
0183a50e08 2024-07-01 437: if Auxiliary.ExtraDeckSummonCountLimit~=nil then return end
0183a50e08 2024-07-01 438: Auxiliary.ExtraDeckSummonCountLimit={}
0183a50e08 2024-07-01 439: Auxiliary.ExtraDeckSummonCountLimit[0]=1
0183a50e08 2024-07-01 440: Auxiliary.ExtraDeckSummonCountLimit[1]=1
0183a50e08 2024-07-01 441: local ge1=Effect.GlobalEffect()
0183a50e08 2024-07-01 442: ge1:SetType(EFFECT_TYPE_CONTINUOUS+EFFECT_TYPE_FIELD)
0183a50e08 2024-07-01 443: ge1:SetCode(EVENT_PHASE_START+PHASE_DRAW)
0183a50e08 2024-07-01 444: ge1:SetOperation(Auxiliary.ExtraDeckSummonCountLimitReset)
0183a50e08 2024-07-01 445: Duel.RegisterEffect(ge1,0)
0183a50e08 2024-07-01 446: end
0183a50e08 2024-07-01 447: function Auxiliary.ExtraDeckSummonCountLimitReset()
0183a50e08 2024-07-01 448: Auxiliary.ExtraDeckSummonCountLimit[0]=1
0183a50e08 2024-07-01 449: Auxiliary.ExtraDeckSummonCountLimit[1]=1
0183a50e08 2024-07-01 450: end
0183a50e08 2024-07-01 451: --Fusion Monster is unnecessary to use this
0183a50e08 2024-07-01 452: function Auxiliary.AddMaterialCodeList(c,...)
0183a50e08 2024-07-01 453: if c:IsStatus(STATUS_COPYING_EFFECT) then return end
0183a50e08 2024-07-01 454: local mat={}
0183a50e08 2024-07-01 455: for _,code in ipairs{...} do
0183a50e08 2024-07-01 456: mat[code]=true
0183a50e08 2024-07-01 457: end
0183a50e08 2024-07-01 458: if c.material==nil then
0183a50e08 2024-07-01 459: local mt=getmetatable(c)
0183a50e08 2024-07-01 460: mt.material=mat
0183a50e08 2024-07-01 461: end
0183a50e08 2024-07-01 462: for index,_ in pairs(mat) do
0183a50e08 2024-07-01 463: Auxiliary.AddCodeList(c,index)
0183a50e08 2024-07-01 464: end
0183a50e08 2024-07-01 465: end
0183a50e08 2024-07-01 466: function Auxiliary.IsMaterialListCode(c,code)
0183a50e08 2024-07-01 467: return c.material and c.material[code]
0183a50e08 2024-07-01 468: end
0183a50e08 2024-07-01 469: function Auxiliary.IsMaterialListSetCard(c,setcode)
0183a50e08 2024-07-01 470: if not c.material_setcode then return false end
0183a50e08 2024-07-01 471: if type(c.material_setcode)=="table" then
0183a50e08 2024-07-01 472: for i,scode in ipairs(c.material_setcode) do
0183a50e08 2024-07-01 473: if setcode&0xfff==scode&0xfff and setcode&scode==setcode then return true end
0183a50e08 2024-07-01 474: end
0183a50e08 2024-07-01 475: else
0183a50e08 2024-07-01 476: return setcode&0xfff==c.material_setcode&0xfff and setcode&c.material_setcode==setcode
0183a50e08 2024-07-01 477: end
0183a50e08 2024-07-01 478: return false
0183a50e08 2024-07-01 479: end
0183a50e08 2024-07-01 480: function Auxiliary.IsMaterialListType(c,type)
0183a50e08 2024-07-01 481: return c.material_type and type&c.material_type==type
0183a50e08 2024-07-01 482: end
0183a50e08 2024-07-01 483: function Auxiliary.GetMaterialListCount(c)
0183a50e08 2024-07-01 484: if not c.material_count then return 0,0 end
0183a50e08 2024-07-01 485: return c.material_count[1],c.material_count[2]
0183a50e08 2024-07-01 486: end
0183a50e08 2024-07-01 487: function Auxiliary.AddCodeList(c,...)
0183a50e08 2024-07-01 488: if c:IsStatus(STATUS_COPYING_EFFECT) then return end
0183a50e08 2024-07-01 489: if c.card_code_list==nil then
0183a50e08 2024-07-01 490: local mt=getmetatable(c)
0183a50e08 2024-07-01 491: mt.card_code_list={}
0183a50e08 2024-07-01 492: for _,code in ipairs{...} do
0183a50e08 2024-07-01 493: mt.card_code_list[code]=true
0183a50e08 2024-07-01 494: end
0183a50e08 2024-07-01 495: else
0183a50e08 2024-07-01 496: for _,code in ipairs{...} do
0183a50e08 2024-07-01 497: c.card_code_list[code]=true
0183a50e08 2024-07-01 498: end
0183a50e08 2024-07-01 499: end
0183a50e08 2024-07-01 500: end
0183a50e08 2024-07-01 501: function Auxiliary.IsCodeListed(c,code)
0183a50e08 2024-07-01 502: return c.card_code_list and c.card_code_list[code]
0183a50e08 2024-07-01 503: end
0183a50e08 2024-07-01 504: function Auxiliary.AddSetNameMonsterList(c,...)
0183a50e08 2024-07-01 505: if c:IsStatus(STATUS_COPYING_EFFECT) then return end
0183a50e08 2024-07-01 506: if c.setcode_monster_list==nil then
0183a50e08 2024-07-01 507: local mt=getmetatable(c)
0183a50e08 2024-07-01 508: mt.setcode_monster_list={}
0183a50e08 2024-07-01 509: for i,scode in ipairs{...} do
0183a50e08 2024-07-01 510: mt.setcode_monster_list[i]=scode
0183a50e08 2024-07-01 511: end
0183a50e08 2024-07-01 512: else
0183a50e08 2024-07-01 513: for i,scode in ipairs{...} do
0183a50e08 2024-07-01 514: c.setcode_monster_list[i]=scode
0183a50e08 2024-07-01 515: end
0183a50e08 2024-07-01 516: end
0183a50e08 2024-07-01 517: end
0183a50e08 2024-07-01 518: function Auxiliary.IsSetNameMonsterListed(c,setcode)
0183a50e08 2024-07-01 519: if not c.setcode_monster_list then return false end
0183a50e08 2024-07-01 520: for i,scode in ipairs(c.setcode_monster_list) do
0183a50e08 2024-07-01 521: if setcode&0xfff==scode&0xfff and setcode&scode==setcode then return true end
0183a50e08 2024-07-01 522: end
0183a50e08 2024-07-01 523: return false
0183a50e08 2024-07-01 524: end
0183a50e08 2024-07-01 525: function Auxiliary.IsCounterAdded(c,counter)
0183a50e08 2024-07-01 526: if not c.counter_add_list then return false end
0183a50e08 2024-07-01 527: for i,ccounter in ipairs(c.counter_add_list) do
0183a50e08 2024-07-01 528: if counter==ccounter then return true end
0183a50e08 2024-07-01 529: end
0183a50e08 2024-07-01 530: return false
0183a50e08 2024-07-01 531: end
0183a50e08 2024-07-01 532: function Auxiliary.IsTypeInText(c,type)
0183a50e08 2024-07-01 533: return c.has_text_type and type&c.has_text_type==type
0183a50e08 2024-07-01 534: end
0183a50e08 2024-07-01 535: function Auxiliary.GetAttributeCount(g)
0183a50e08 2024-07-01 536: if #g==0 then return 0 end
0183a50e08 2024-07-01 537: local att=0
0183a50e08 2024-07-01 538: for tc in Auxiliary.Next(g) do
0183a50e08 2024-07-01 539: att=att|tc:GetAttribute()
0183a50e08 2024-07-01 540: end
0183a50e08 2024-07-01 541: local ct=0
0183a50e08 2024-07-01 542: while att~=0 do
0183a50e08 2024-07-01 543: if att&0x1~=0 then ct=ct+1 end
0183a50e08 2024-07-01 544: att=att>>1
0183a50e08 2024-07-01 545: end
0183a50e08 2024-07-01 546: return ct
0183a50e08 2024-07-01 547: end
0183a50e08 2024-07-01 548: function Auxiliary.IsInGroup(c,g)
0183a50e08 2024-07-01 549: return g:IsContains(c)
0183a50e08 2024-07-01 550: end
0183a50e08 2024-07-01 551: --return the column of card c (from the viewpoint of p)
0183a50e08 2024-07-01 552: function Auxiliary.GetColumn(c,p)
0183a50e08 2024-07-01 553: local seq=c:GetSequence()
0183a50e08 2024-07-01 554: if c:IsLocation(LOCATION_MZONE) then
0183a50e08 2024-07-01 555: if seq==5 then
0183a50e08 2024-07-01 556: seq=1
0183a50e08 2024-07-01 557: elseif seq==6 then
0183a50e08 2024-07-01 558: seq=3
0183a50e08 2024-07-01 559: end
0183a50e08 2024-07-01 560: elseif c:IsLocation(LOCATION_SZONE) then
0183a50e08 2024-07-01 561: if seq>4 then
0183a50e08 2024-07-01 562: return nil
0183a50e08 2024-07-01 563: end
0183a50e08 2024-07-01 564: else
0183a50e08 2024-07-01 565: return nil
0183a50e08 2024-07-01 566: end
0183a50e08 2024-07-01 567: if c:IsControler(p or 0) then
0183a50e08 2024-07-01 568: return seq
0183a50e08 2024-07-01 569: else
0183a50e08 2024-07-01 570: return 4-seq
0183a50e08 2024-07-01 571: end
0183a50e08 2024-07-01 572: end
0183a50e08 2024-07-01 573: --return the column of monster zone seq (from the viewpoint of controller)
0183a50e08 2024-07-01 574: function Auxiliary.MZoneSequence(seq)
0183a50e08 2024-07-01 575: if seq==5 then return 1 end
0183a50e08 2024-07-01 576: if seq==6 then return 3 end
0183a50e08 2024-07-01 577: return seq
0183a50e08 2024-07-01 578: end
0183a50e08 2024-07-01 579: --return the column of spell/trap zone seq (from the viewpoint of controller)
0183a50e08 2024-07-01 580: function Auxiliary.SZoneSequence(seq)
0183a50e08 2024-07-01 581: if seq>4 then return nil end
0183a50e08 2024-07-01 582: return seq
0183a50e08 2024-07-01 583: end
0183a50e08 2024-07-01 584: --generate the value function of EFFECT_CHANGE_BATTLE_DAMAGE on monsters
0183a50e08 2024-07-01 585: function Auxiliary.ChangeBattleDamage(player,value)
0183a50e08 2024-07-01 586: return function(e,damp)
0183a50e08 2024-07-01 587: if player==0 then
0183a50e08 2024-07-01 588: if e:GetOwnerPlayer()==damp then
0183a50e08 2024-07-01 589: return value
0183a50e08 2024-07-01 590: else
0183a50e08 2024-07-01 591: return -1
0183a50e08 2024-07-01 592: end
0183a50e08 2024-07-01 593: elseif player==1 then
0183a50e08 2024-07-01 594: if e:GetOwnerPlayer()==1-damp then
0183a50e08 2024-07-01 595: return value
0183a50e08 2024-07-01 596: else
0183a50e08 2024-07-01 597: return -1
0183a50e08 2024-07-01 598: end
0183a50e08 2024-07-01 599: end
0183a50e08 2024-07-01 600: end
0183a50e08 2024-07-01 601: end
0183a50e08 2024-07-01 602: --filter for "negate the effects of a face-up monster" (無限泡影/Infinite Impermanence)
0183a50e08 2024-07-01 603: function Auxiliary.NegateMonsterFilter(c)
0183a50e08 2024-07-01 604: return c:IsFaceup() and not c:IsDisabled() and (c:IsType(TYPE_EFFECT) or c:GetOriginalType()&TYPE_EFFECT~=0)
0183a50e08 2024-07-01 605: end
0183a50e08 2024-07-01 606: --filter for "negate the effects of an Effect Monster" (エフェクト・ヴェーラー/Effect Veiler)
0183a50e08 2024-07-01 607: function Auxiliary.NegateEffectMonsterFilter(c)
0183a50e08 2024-07-01 608: return c:IsFaceup() and not c:IsDisabled() and c:IsType(TYPE_EFFECT)
0183a50e08 2024-07-01 609: end
0183a50e08 2024-07-01 610: --filter for "negate the effects of a face-up card"
0183a50e08 2024-07-01 611: function Auxiliary.NegateAnyFilter(c)
0183a50e08 2024-07-01 612: if c:IsType(TYPE_TRAPMONSTER) then
0183a50e08 2024-07-01 613: return c:IsFaceup()
0183a50e08 2024-07-01 614: elseif c:IsType(TYPE_SPELL+TYPE_TRAP) then
0183a50e08 2024-07-01 615: return c:IsFaceup() and not c:IsDisabled()
0183a50e08 2024-07-01 616: else
0183a50e08 2024-07-01 617: return Auxiliary.NegateMonsterFilter(c)
0183a50e08 2024-07-01 618: end
0183a50e08 2024-07-01 619: end
0183a50e08 2024-07-01 620: --alias for compatibility
0183a50e08 2024-07-01 621: Auxiliary.disfilter1=Auxiliary.NegateAnyFilter
0183a50e08 2024-07-01 622: --condition of EVENT_BATTLE_DESTROYING
0183a50e08 2024-07-01 623: function Auxiliary.bdcon(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 624: local c=e:GetHandler()
0183a50e08 2024-07-01 625: return c:IsRelateToBattle()
0183a50e08 2024-07-01 626: end
0183a50e08 2024-07-01 627: --condition of EVENT_BATTLE_DESTROYING + opponent monster
0183a50e08 2024-07-01 628: function Auxiliary.bdocon(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 629: local c=e:GetHandler()
0183a50e08 2024-07-01 630: return c:IsRelateToBattle() and c:IsStatus(STATUS_OPPO_BATTLE)
0183a50e08 2024-07-01 631: end
0183a50e08 2024-07-01 632: --condition of EVENT_BATTLE_DESTROYING + to_grave
0183a50e08 2024-07-01 633: function Auxiliary.bdgcon(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 634: local c=e:GetHandler()
0183a50e08 2024-07-01 635: local bc=c:GetBattleTarget()
0183a50e08 2024-07-01 636: return c:IsRelateToBattle() and bc:IsLocation(LOCATION_GRAVE) and bc:IsType(TYPE_MONSTER)
0183a50e08 2024-07-01 637: end
0183a50e08 2024-07-01 638: --condition of EVENT_BATTLE_DESTROYING + opponent monster + to_grave
0183a50e08 2024-07-01 639: function Auxiliary.bdogcon(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 640: local c=e:GetHandler()
0183a50e08 2024-07-01 641: local bc=c:GetBattleTarget()
0183a50e08 2024-07-01 642: return c:IsRelateToBattle() and c:IsStatus(STATUS_OPPO_BATTLE) and bc:IsLocation(LOCATION_GRAVE) and bc:IsType(TYPE_MONSTER)
0183a50e08 2024-07-01 643: end
0183a50e08 2024-07-01 644: --condition of EVENT_DAMAGE_STEP_END + this monster is releate to battle
0183a50e08 2024-07-01 645: function Auxiliary.dsercon(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 646: local c=e:GetHandler()
0183a50e08 2024-07-01 647: return c:IsRelateToBattle() or c:IsStatus(STATUS_BATTLE_DESTROYED)
0183a50e08 2024-07-01 648: end
0183a50e08 2024-07-01 649: --condition of EVENT_TO_GRAVE + destroyed by opponent
0183a50e08 2024-07-01 650: function Auxiliary.dogcon(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 651: local c=e:GetHandler()
0183a50e08 2024-07-01 652: return c:IsPreviousControler(tp) and c:IsReason(REASON_DESTROY) and rp==1-tp
0183a50e08 2024-07-01 653: end
0183a50e08 2024-07-01 654: --condition of EVENT_TO_GRAVE + destroyed by opponent + from field
0183a50e08 2024-07-01 655: function Auxiliary.dogfcon(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 656: local c=e:GetHandler()
0183a50e08 2024-07-01 657: return c:IsPreviousLocation(LOCATION_ONFIELD) and c:IsPreviousControler(tp)
0183a50e08 2024-07-01 658: and c:IsReason(REASON_DESTROY) and rp==1-tp
0183a50e08 2024-07-01 659: end
0183a50e08 2024-07-01 660: --condition of "except the turn this card was sent to the Graveyard"
0183a50e08 2024-07-01 661: function Auxiliary.exccon(e)
0183a50e08 2024-07-01 662: return Duel.GetTurnCount()~=e:GetHandler():GetTurnID() or e:GetHandler():IsReason(REASON_RETURN)
0183a50e08 2024-07-01 663: end
0183a50e08 2024-07-01 664: --condition of checking battle phase availability
0183a50e08 2024-07-01 665: function Auxiliary.bpcon(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 666: return Duel.IsAbleToEnterBP() or (Duel.GetCurrentPhase()>=PHASE_BATTLE_START and Duel.GetCurrentPhase()<=PHASE_BATTLE)
0183a50e08 2024-07-01 667: end
0183a50e08 2024-07-01 668: --condition of free chain effects changing ATK/DEF
0183a50e08 2024-07-01 669: function Auxiliary.dscon(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 670: return Duel.GetCurrentPhase()~=PHASE_DAMAGE or not Duel.IsDamageCalculated()
0183a50e08 2024-07-01 671: end
0183a50e08 2024-07-01 672: --flag effect for spell counter
0183a50e08 2024-07-01 673: function Auxiliary.chainreg(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 674: if e:GetHandler():GetFlagEffect(FLAG_ID_CHAINING)==0 then
0183a50e08 2024-07-01 675: e:GetHandler():RegisterFlagEffect(FLAG_ID_CHAINING,RESET_EVENT+RESETS_STANDARD-RESET_TURN_SET+RESET_CHAIN,0,1)
0183a50e08 2024-07-01 676: end
0183a50e08 2024-07-01 677: end
0183a50e08 2024-07-01 678: --default filter for EFFECT_CANNOT_BE_BATTLE_TARGET
0183a50e08 2024-07-01 679: function Auxiliary.imval1(e,c)
0183a50e08 2024-07-01 680: return not c:IsImmuneToEffect(e)
0183a50e08 2024-07-01 681: end
0183a50e08 2024-07-01 682: --filter for EFFECT_INDESTRUCTABLE_EFFECT + self
0183a50e08 2024-07-01 683: function Auxiliary.indsval(e,re,rp)
0183a50e08 2024-07-01 684: return rp==e:GetHandlerPlayer()
0183a50e08 2024-07-01 685: end
0183a50e08 2024-07-01 686: --filter for EFFECT_INDESTRUCTABLE_EFFECT + opponent
0183a50e08 2024-07-01 687: function Auxiliary.indoval(e,re,rp)
0183a50e08 2024-07-01 688: return rp==1-e:GetHandlerPlayer()
0183a50e08 2024-07-01 689: end
0183a50e08 2024-07-01 690: --filter for EFFECT_CANNOT_BE_EFFECT_TARGET + self
0183a50e08 2024-07-01 691: function Auxiliary.tgsval(e,re,rp)
0183a50e08 2024-07-01 692: return rp==e:GetHandlerPlayer()
0183a50e08 2024-07-01 693: end
0183a50e08 2024-07-01 694: --filter for EFFECT_CANNOT_BE_EFFECT_TARGET + opponent
0183a50e08 2024-07-01 695: function Auxiliary.tgoval(e,re,rp)
0183a50e08 2024-07-01 696: return rp==1-e:GetHandlerPlayer()
0183a50e08 2024-07-01 697: end
0183a50e08 2024-07-01 698: --filter for non-zero ATK
0183a50e08 2024-07-01 699: function Auxiliary.nzatk(c)
0183a50e08 2024-07-01 700: return c:IsFaceup() and c:GetAttack()>0
0183a50e08 2024-07-01 701: end
0183a50e08 2024-07-01 702: --filter for non-zero DEF
0183a50e08 2024-07-01 703: function Auxiliary.nzdef(c)
0183a50e08 2024-07-01 704: return c:IsFaceup() and c:GetDefense()>0
0183a50e08 2024-07-01 705: end
0183a50e08 2024-07-01 706: --flag effect for summon/sp_summon turn
0183a50e08 2024-07-01 707: function Auxiliary.sumreg(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 708: local tc=eg:GetFirst()
0183a50e08 2024-07-01 709: local code=e:GetLabel()
0183a50e08 2024-07-01 710: while tc do
0183a50e08 2024-07-01 711: if tc:GetOriginalCode()==code then
0183a50e08 2024-07-01 712: tc:RegisterFlagEffect(code,RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END,0,1)
0183a50e08 2024-07-01 713: end
0183a50e08 2024-07-01 714: tc=eg:GetNext()
0183a50e08 2024-07-01 715: end
0183a50e08 2024-07-01 716: end
0183a50e08 2024-07-01 717: --for EVENT_BE_MATERIAL effect releated to the summoned monster
0183a50e08 2024-07-01 718: function Auxiliary.CreateMaterialReasonCardRelation(c,te)
0183a50e08 2024-07-01 719: local e1=Effect.CreateEffect(c)
0183a50e08 2024-07-01 720: e1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_CONTINUOUS)
0183a50e08 2024-07-01 721: e1:SetCode(EVENT_BE_MATERIAL)
0183a50e08 2024-07-01 722: e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
0183a50e08 2024-07-01 723: e1:SetOperation(Auxiliary.MaterialReasonCardReg)
0183a50e08 2024-07-01 724: e1:SetLabelObject(te)
0183a50e08 2024-07-01 725: c:RegisterEffect(e1)
0183a50e08 2024-07-01 726: end
0183a50e08 2024-07-01 727: function Auxiliary.MaterialReasonCardReg(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 728: local c=e:GetHandler()
0183a50e08 2024-07-01 729: local te=e:GetLabelObject()
0183a50e08 2024-07-01 730: c:GetReasonCard():CreateEffectRelation(te)
0183a50e08 2024-07-01 731: end
0183a50e08 2024-07-01 732: --the player tp has token on the field
0183a50e08 2024-07-01 733: function Auxiliary.tkfcon(e,tp)
0183a50e08 2024-07-01 734: if tp==nil and e~=nil then tp=e:GetHandlerPlayer() end
0183a50e08 2024-07-01 735: return Duel.IsExistingMatchingCard(Card.IsType,tp,LOCATION_ONFIELD,0,1,nil,TYPE_TOKEN)
0183a50e08 2024-07-01 736: end
0183a50e08 2024-07-01 737: --effects inflicting damage to tp
0183a50e08 2024-07-01 738: function Auxiliary.damcon1(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 739: local e1=Duel.IsPlayerAffectedByEffect(tp,EFFECT_REVERSE_DAMAGE)
0183a50e08 2024-07-01 740: local e2=Duel.IsPlayerAffectedByEffect(tp,EFFECT_REVERSE_RECOVER)
0183a50e08 2024-07-01 741: local rd=e1 and not e2
0183a50e08 2024-07-01 742: local rr=not e1 and e2
0183a50e08 2024-07-01 743: local ex,cg,ct,cp,cv=Duel.GetOperationInfo(ev,CATEGORY_DAMAGE)
0183a50e08 2024-07-01 744: if ex and (cp==tp or cp==PLAYER_ALL) and not rd and not Duel.IsPlayerAffectedByEffect(tp,EFFECT_NO_EFFECT_DAMAGE) then
0183a50e08 2024-07-01 745: return true
0183a50e08 2024-07-01 746: end
0183a50e08 2024-07-01 747: ex,cg,ct,cp,cv=Duel.GetOperationInfo(ev,CATEGORY_RECOVER)
0183a50e08 2024-07-01 748: return ex and (cp==tp or cp==PLAYER_ALL) and rr and not Duel.IsPlayerAffectedByEffect(tp,EFFECT_NO_EFFECT_DAMAGE)
0183a50e08 2024-07-01 749: end
0183a50e08 2024-07-01 750: --filter for the immune effect of qli monsters
0183a50e08 2024-07-01 751: function Auxiliary.qlifilter(e,te)
0183a50e08 2024-07-01 752: if te:IsActiveType(TYPE_MONSTER) and te:IsActivated() then
0183a50e08 2024-07-01 753: local lv=e:GetHandler():GetLevel()
0183a50e08 2024-07-01 754: local ec=te:GetOwner()
0183a50e08 2024-07-01 755: if ec:IsType(TYPE_LINK) then
0183a50e08 2024-07-01 756: return false
0183a50e08 2024-07-01 757: elseif ec:IsType(TYPE_XYZ) then
0183a50e08 2024-07-01 758: return ec:GetOriginalRank()<lv
0183a50e08 2024-07-01 759: else
0183a50e08 2024-07-01 760: return ec:GetOriginalLevel()<lv
0183a50e08 2024-07-01 761: end
0183a50e08 2024-07-01 762: else
0183a50e08 2024-07-01 763: return false
0183a50e08 2024-07-01 764: end
0183a50e08 2024-07-01 765: end
0183a50e08 2024-07-01 766: --sp_summon condition for gladiator beast monsters
0183a50e08 2024-07-01 767: function Auxiliary.gbspcon(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 768: local c=e:GetHandler()
0183a50e08 2024-07-01 769: local typ=c:GetSpecialSummonInfo(SUMMON_INFO_TYPE)
0183a50e08 2024-07-01 770: return c:IsSummonType(SUMMON_VALUE_GLADIATOR) or (typ&TYPE_MONSTER~=0 and c:IsSpecialSummonSetCard(0x19))
0183a50e08 2024-07-01 771: end
0183a50e08 2024-07-01 772: --sp_summon condition for evolsaur monsters
0183a50e08 2024-07-01 773: function Auxiliary.evospcon(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 774: local c=e:GetHandler()
0183a50e08 2024-07-01 775: local typ=c:GetSpecialSummonInfo(SUMMON_INFO_TYPE)
0183a50e08 2024-07-01 776: return c:IsSummonType(SUMMON_VALUE_EVOLTILE) or (typ&TYPE_MONSTER~=0 and c:IsSpecialSummonSetCard(0x304e))
0183a50e08 2024-07-01 777: end
0183a50e08 2024-07-01 778: --filter for necro_valley test
0183a50e08 2024-07-01 779: function Auxiliary.NecroValleyFilter(f)
0183a50e08 2024-07-01 780: return function(target,...)
0183a50e08 2024-07-01 781: return (not f or f(target,...)) and not target:IsHasEffect(EFFECT_NECRO_VALLEY)
0183a50e08 2024-07-01 782: end
0183a50e08 2024-07-01 783: end
0183a50e08 2024-07-01 784: --Necrovalley test for effect with not certain target or not certain action
0183a50e08 2024-07-01 785: function Auxiliary.NecroValleyNegateCheck(v)
0183a50e08 2024-07-01 786: if not Duel.IsChainDisablable(0) then return false end
0183a50e08 2024-07-01 787: local g=Group.CreateGroup()
0183a50e08 2024-07-01 788: if Auxiliary.GetValueType(v)=="Card" then g:AddCard(v) end
0183a50e08 2024-07-01 789: if Auxiliary.GetValueType(v)=="Group" then g:Merge(v) end
0183a50e08 2024-07-01 790: if g:IsExists(Card.IsHasEffect,1,nil,EFFECT_NECRO_VALLEY) then
0183a50e08 2024-07-01 791: Duel.NegateEffect(0)
0183a50e08 2024-07-01 792: return true
0183a50e08 2024-07-01 793: end
0183a50e08 2024-07-01 794: return false
0183a50e08 2024-07-01 795: end
0183a50e08 2024-07-01 796: --Ursarctic common summon from hand effect
0183a50e08 2024-07-01 797: function Auxiliary.AddUrsarcticSpSummonEffect(c)
0183a50e08 2024-07-01 798: local e1=Effect.CreateEffect(c)
0183a50e08 2024-07-01 799: e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
0183a50e08 2024-07-01 800: e1:SetType(EFFECT_TYPE_QUICK_O)
0183a50e08 2024-07-01 801: e1:SetCode(EVENT_FREE_CHAIN)
0183a50e08 2024-07-01 802: e1:SetRange(LOCATION_HAND)
0183a50e08 2024-07-01 803: e1:SetHintTiming(0,TIMINGS_CHECK_MONSTER+TIMING_MAIN_END)
0183a50e08 2024-07-01 804: e1:SetCondition(Auxiliary.UrsarcticSpSummonCondition)
0183a50e08 2024-07-01 805: e1:SetCost(Auxiliary.UrsarcticSpSummonCost)
0183a50e08 2024-07-01 806: e1:SetTarget(Auxiliary.UrsarcticSpSummonTarget)
0183a50e08 2024-07-01 807: e1:SetOperation(Auxiliary.UrsarcticSpSummonOperation)
0183a50e08 2024-07-01 808: c:RegisterEffect(e1)
0183a50e08 2024-07-01 809: return e1
0183a50e08 2024-07-01 810: end
0183a50e08 2024-07-01 811: function Auxiliary.UrsarcticSpSummonCondition(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 812: return Duel.GetCurrentPhase()==PHASE_MAIN1 or Duel.GetCurrentPhase()==PHASE_MAIN2
0183a50e08 2024-07-01 813: end
0183a50e08 2024-07-01 814: function Auxiliary.UrsarcticReleaseFilter(c)
0183a50e08 2024-07-01 815: return c:IsLevelAbove(7) and c:IsLocation(LOCATION_HAND)
0183a50e08 2024-07-01 816: end
0183a50e08 2024-07-01 817: function Auxiliary.UrsarcticExCostFilter(c,tp)
0183a50e08 2024-07-01 818: return c:IsAbleToRemoveAsCost() and (c:IsHasEffect(16471775,tp) or c:IsHasEffect(89264428,tp))
0183a50e08 2024-07-01 819: end
0183a50e08 2024-07-01 820: function Auxiliary.UrsarcticSpSummonCost(e,tp,eg,ep,ev,re,r,rp,chk)
0183a50e08 2024-07-01 821: local g1=Duel.GetReleaseGroup(tp,true):Filter(Auxiliary.UrsarcticReleaseFilter,e:GetHandler())
0183a50e08 2024-07-01 822: local g2=Duel.GetMatchingGroup(Auxiliary.UrsarcticExCostFilter,tp,LOCATION_GRAVE,0,nil,tp)
0183a50e08 2024-07-01 823: g1:Merge(g2)
0183a50e08 2024-07-01 824: if chk==0 then return g1:GetCount()>0 end
0183a50e08 2024-07-01 825: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_RELEASE)
0183a50e08 2024-07-01 826: local tc=g1:Select(tp,1,1,nil):GetFirst()
0183a50e08 2024-07-01 827: local te=tc:IsHasEffect(16471775,tp) or tc:IsHasEffect(89264428,tp)
0183a50e08 2024-07-01 828: if te then
0183a50e08 2024-07-01 829: te:UseCountLimit(tp)
0183a50e08 2024-07-01 830: Duel.Remove(tc,POS_FACEUP,REASON_EFFECT+REASON_REPLACE)
0183a50e08 2024-07-01 831: else
0183a50e08 2024-07-01 832: Duel.Release(tc,REASON_COST)
0183a50e08 2024-07-01 833: end
0183a50e08 2024-07-01 834: end
0183a50e08 2024-07-01 835: function Auxiliary.UrsarcticSpSummonTarget(e,tp,eg,ep,ev,re,r,rp,chk)
0183a50e08 2024-07-01 836: if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0
0183a50e08 2024-07-01 837: and e:GetHandler():IsCanBeSpecialSummoned(e,0,tp,false,false) end
0183a50e08 2024-07-01 838: Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,e:GetHandler(),1,0,0)
0183a50e08 2024-07-01 839: end
0183a50e08 2024-07-01 840: function Auxiliary.UrsarcticSpSummonOperation(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 841: local c=e:GetHandler()
0183a50e08 2024-07-01 842: if c:IsRelateToEffect(e) then
0183a50e08 2024-07-01 843: Duel.SpecialSummon(c,0,tp,tp,false,false,POS_FACEUP)
0183a50e08 2024-07-01 844: end
0183a50e08 2024-07-01 845: local e1=Effect.CreateEffect(c)
0183a50e08 2024-07-01 846: e1:SetType(EFFECT_TYPE_FIELD)
0183a50e08 2024-07-01 847: e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
0183a50e08 2024-07-01 848: e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
0183a50e08 2024-07-01 849: e1:SetTargetRange(1,0)
0183a50e08 2024-07-01 850: e1:SetTarget(Auxiliary.UrsarcticSpSummonLimit)
0183a50e08 2024-07-01 851: e1:SetReset(RESET_PHASE+PHASE_END)
0183a50e08 2024-07-01 852: Duel.RegisterEffect(e1,tp)
0183a50e08 2024-07-01 853: end
0183a50e08 2024-07-01 854: function Auxiliary.UrsarcticSpSummonLimit(e,c)
0183a50e08 2024-07-01 855: return c:IsLevel(0)
0183a50e08 2024-07-01 856: end
0183a50e08 2024-07-01 857: --Drytron common summon effect
0183a50e08 2024-07-01 858: function Auxiliary.AddDrytronSpSummonEffect(c,func)
0183a50e08 2024-07-01 859: local e1=Effect.CreateEffect(c)
0183a50e08 2024-07-01 860: e1:SetType(EFFECT_TYPE_IGNITION)
0183a50e08 2024-07-01 861: e1:SetRange(LOCATION_HAND+LOCATION_GRAVE)
0183a50e08 2024-07-01 862: e1:SetCost(Auxiliary.DrytronSpSummonCost)
0183a50e08 2024-07-01 863: e1:SetTarget(Auxiliary.DrytronSpSummonTarget)
0183a50e08 2024-07-01 864: e1:SetOperation(Auxiliary.DrytronSpSummonOperation(func))
0183a50e08 2024-07-01 865: c:RegisterEffect(e1)
0183a50e08 2024-07-01 866: Duel.AddCustomActivityCounter(97148796,ACTIVITY_SPSUMMON,Auxiliary.DrytronCounterFilter)
0183a50e08 2024-07-01 867: return e1
0183a50e08 2024-07-01 868: end
0183a50e08 2024-07-01 869: function Auxiliary.DrytronCounterFilter(c)
0183a50e08 2024-07-01 870: return not c:IsSummonableCard()
0183a50e08 2024-07-01 871: end
0183a50e08 2024-07-01 872: function Auxiliary.DrytronCostFilter(c,tp)
0183a50e08 2024-07-01 873: return (c:IsSetCard(0x154) or c:IsType(TYPE_RITUAL)) and c:IsType(TYPE_MONSTER) and Duel.GetMZoneCount(tp,c)>0
0183a50e08 2024-07-01 874: and (c:IsControler(tp) or c:IsFaceup())
0183a50e08 2024-07-01 875: end
0183a50e08 2024-07-01 876: function Auxiliary.DrytronExtraCostFilter(c,tp)
0183a50e08 2024-07-01 877: return c:IsAbleToRemove() and c:IsHasEffect(89771220,tp)
0183a50e08 2024-07-01 878: end
0183a50e08 2024-07-01 879: function Auxiliary.DrytronSpSummonCost(e,tp,eg,ep,ev,re,r,rp,chk)
0183a50e08 2024-07-01 880: e:SetLabel(100)
0183a50e08 2024-07-01 881: local g1=Duel.GetReleaseGroup(tp,true):Filter(Auxiliary.DrytronCostFilter,e:GetHandler(),tp)
0183a50e08 2024-07-01 882: local g2=Duel.GetMatchingGroup(Auxiliary.DrytronExtraCostFilter,tp,LOCATION_GRAVE,0,nil,tp)
0183a50e08 2024-07-01 883: g1:Merge(g2)
0183a50e08 2024-07-01 884: if chk==0 then return #g1>0 and Duel.GetCustomActivityCount(97148796,tp,ACTIVITY_SPSUMMON)==0 end
0183a50e08 2024-07-01 885: local e1=Effect.CreateEffect(e:GetHandler())
0183a50e08 2024-07-01 886: e1:SetType(EFFECT_TYPE_FIELD)
0183a50e08 2024-07-01 887: e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
0183a50e08 2024-07-01 888: e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET+EFFECT_FLAG_OATH)
0183a50e08 2024-07-01 889: e1:SetTargetRange(1,0)
0183a50e08 2024-07-01 890: e1:SetTarget(Auxiliary.DrytronSpSummonLimit)
0183a50e08 2024-07-01 891: e1:SetReset(RESET_PHASE+PHASE_END)
0183a50e08 2024-07-01 892: Duel.RegisterEffect(e1,tp)
0183a50e08 2024-07-01 893: --cant special summon summonable card check
0183a50e08 2024-07-01 894: local e2=Effect.CreateEffect(e:GetHandler())
0183a50e08 2024-07-01 895: e2:SetType(EFFECT_TYPE_FIELD)
0183a50e08 2024-07-01 896: e2:SetCode(97148796)
0183a50e08 2024-07-01 897: e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET+EFFECT_FLAG_OATH)
0183a50e08 2024-07-01 898: e2:SetTargetRange(1,0)
0183a50e08 2024-07-01 899: e2:SetReset(RESET_PHASE+PHASE_END)
0183a50e08 2024-07-01 900: Duel.RegisterEffect(e2,tp)
0183a50e08 2024-07-01 901: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_RELEASE)
0183a50e08 2024-07-01 902: local rg=g1:Select(tp,1,1,nil)
0183a50e08 2024-07-01 903: local tc=rg:GetFirst()
0183a50e08 2024-07-01 904: local te=tc:IsHasEffect(89771220,tp)
0183a50e08 2024-07-01 905: if te then
0183a50e08 2024-07-01 906: te:UseCountLimit(tp)
0183a50e08 2024-07-01 907: Duel.Remove(tc,POS_FACEUP,REASON_EFFECT+REASON_REPLACE)
0183a50e08 2024-07-01 908: else
0183a50e08 2024-07-01 909: Auxiliary.UseExtraReleaseCount(rg,tp)
0183a50e08 2024-07-01 910: Duel.Release(tc,REASON_COST)
0183a50e08 2024-07-01 911: end
0183a50e08 2024-07-01 912: end
0183a50e08 2024-07-01 913: function Auxiliary.DrytronSpSummonLimit(e,c,sump,sumtype,sumpos,targetp,se)
0183a50e08 2024-07-01 914: return c:IsSummonableCard()
0183a50e08 2024-07-01 915: end
0183a50e08 2024-07-01 916: function Auxiliary.DrytronSpSummonTarget(e,tp,eg,ep,ev,re,r,rp,chk)
0183a50e08 2024-07-01 917: local res=e:GetLabel()==100 or Duel.GetLocationCount(tp,LOCATION_MZONE)>0
0183a50e08 2024-07-01 918: if chk==0 then
0183a50e08 2024-07-01 919: e:SetLabel(0)
0183a50e08 2024-07-01 920: return res and e:GetHandler():IsCanBeSpecialSummoned(e,0,tp,false,true,POS_FACEUP_DEFENSE)
0183a50e08 2024-07-01 921: end
0183a50e08 2024-07-01 922: e:SetLabel(0)
0183a50e08 2024-07-01 923: Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,e:GetHandler(),1,0,0)
0183a50e08 2024-07-01 924: end
0183a50e08 2024-07-01 925: function Auxiliary.DrytronSpSummonOperation(func)
0183a50e08 2024-07-01 926: return function(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 927: local c=e:GetHandler()
0183a50e08 2024-07-01 928: if not c:IsRelateToEffect(e) then return end
0183a50e08 2024-07-01 929: if Duel.SpecialSummon(c,0,tp,tp,false,true,POS_FACEUP_DEFENSE)~=0 then
0183a50e08 2024-07-01 930: c:CompleteProcedure()
0183a50e08 2024-07-01 931: func(e,tp)
0183a50e08 2024-07-01 932: end
0183a50e08 2024-07-01 933: end
0183a50e08 2024-07-01 934: end
0183a50e08 2024-07-01 935: ---The `nolimit` parameter for Special Summon effects of Drytron cards
0183a50e08 2024-07-01 936: ---@param c Card
0183a50e08 2024-07-01 937: ---@return boolean
0183a50e08 2024-07-01 938: function Auxiliary.DrytronSpSummonType(c)
0183a50e08 2024-07-01 939: return c:IsType(TYPE_SPSUMMON)
0183a50e08 2024-07-01 940: end
0183a50e08 2024-07-01 941: ---The `nolimit` parameter for Special Summon effects of Dragon, Xyz monsters where Soul Drain Dragon is available
0183a50e08 2024-07-01 942: ---(Soul Drain Dragon, Level 8/LIGHT/Dragon/4000/0)
0183a50e08 2024-07-01 943: ---@param c Card
0183a50e08 2024-07-01 944: ---@return boolean
0183a50e08 2024-07-01 945: function Auxiliary.DragonXyzSpSummonType(c)
0183a50e08 2024-07-01 946: return c:GetOriginalCode()==55735315
0183a50e08 2024-07-01 947: end
0183a50e08 2024-07-01 948: ---The `nolimit` parameter for Special Summon effects of Triamid cards
0183a50e08 2024-07-01 949: ---@param c Card
0183a50e08 2024-07-01 950: ---@return boolean
0183a50e08 2024-07-01 951: function Auxiliary.TriamidSpSummonType(c)
0183a50e08 2024-07-01 952: return c:IsType(TYPE_SPSUMMON)
0183a50e08 2024-07-01 953: end
0183a50e08 2024-07-01 954: --additional destroy effect for the Labrynth field
0183a50e08 2024-07-01 955: function Auxiliary.LabrynthDestroyOp(e,tp,res)
0183a50e08 2024-07-01 956: local c=e:GetHandler()
0183a50e08 2024-07-01 957: local chk=not c:IsStatus(STATUS_ACT_FROM_HAND) and c:IsSetCard(0x117e) and c:GetType()==TYPE_TRAP and e:IsHasType(EFFECT_TYPE_ACTIVATE)
0183a50e08 2024-07-01 958: local exc=nil
0183a50e08 2024-07-01 959: if c:IsStatus(STATUS_LEAVE_CONFIRMED) then exc=c end
0183a50e08 2024-07-01 960: local te=Duel.IsPlayerAffectedByEffect(tp,33407125)
0183a50e08 2024-07-01 961: if chk and te
0183a50e08 2024-07-01 962: and Duel.IsExistingMatchingCard(nil,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,1,exc)
0183a50e08 2024-07-01 963: and Duel.SelectYesNo(tp,Auxiliary.Stringid(33407125,0)) then
0183a50e08 2024-07-01 964: if res>0 then Duel.BreakEffect() end
0183a50e08 2024-07-01 965: Duel.Hint(HINT_CARD,0,33407125)
0183a50e08 2024-07-01 966: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_DESTROY)
0183a50e08 2024-07-01 967: local dg=Duel.SelectMatchingCard(tp,nil,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,1,1,exc)
0183a50e08 2024-07-01 968: Duel.HintSelection(dg)
0183a50e08 2024-07-01 969: Duel.Destroy(dg,REASON_EFFECT)
0183a50e08 2024-07-01 970: te:UseCountLimit(tp)
0183a50e08 2024-07-01 971: end
0183a50e08 2024-07-01 972: end
0183a50e08 2024-07-01 973: --shortcut for Gizmek cards
0183a50e08 2024-07-01 974: function Auxiliary.AtkEqualsDef(c)
0183a50e08 2024-07-01 975: if not c:IsType(TYPE_MONSTER) or c:IsType(TYPE_LINK) then return false end
0183a50e08 2024-07-01 976: if c:GetAttack()~=c:GetDefense() then return false end
0183a50e08 2024-07-01 977: return c:IsLocation(LOCATION_MZONE) or c:GetTextAttack()>=0 and c:GetTextDefense()>=0
0183a50e08 2024-07-01 978: end
0183a50e08 2024-07-01 979: --shortcut for self-banish costs
0183a50e08 2024-07-01 980: function Auxiliary.bfgcost(e,tp,eg,ep,ev,re,r,rp,chk)
0183a50e08 2024-07-01 981: if chk==0 then return e:GetHandler():IsAbleToRemoveAsCost() end
0183a50e08 2024-07-01 982: Duel.Remove(e:GetHandler(),POS_FACEUP,REASON_COST)
0183a50e08 2024-07-01 983: end
0183a50e08 2024-07-01 984: --check for cards with different names
0183a50e08 2024-07-01 985: function Auxiliary.dncheck(g)
0183a50e08 2024-07-01 986: return g:GetClassCount(Card.GetCode)==#g
0183a50e08 2024-07-01 987: end
0183a50e08 2024-07-01 988: --check for cards with different levels
0183a50e08 2024-07-01 989: function Auxiliary.dlvcheck(g)
0183a50e08 2024-07-01 990: return g:GetClassCount(Card.GetLevel)==#g
0183a50e08 2024-07-01 991: end
0183a50e08 2024-07-01 992: --check for cards with different ranks
0183a50e08 2024-07-01 993: function Auxiliary.drkcheck(g)
0183a50e08 2024-07-01 994: return g:GetClassCount(Card.GetRank)==#g
0183a50e08 2024-07-01 995: end
0183a50e08 2024-07-01 996: --check for cards with different links
0183a50e08 2024-07-01 997: function Auxiliary.dlkcheck(g)
0183a50e08 2024-07-01 998: return g:GetClassCount(Card.GetLink)==#g
0183a50e08 2024-07-01 999: end
0183a50e08 2024-07-01 1000: --check for cards with different attributes
0183a50e08 2024-07-01 1001: function Auxiliary.dabcheck(g)
0183a50e08 2024-07-01 1002: return g:GetClassCount(Card.GetAttribute)==#g
0183a50e08 2024-07-01 1003: end
0183a50e08 2024-07-01 1004: --check for cards with different races
0183a50e08 2024-07-01 1005: function Auxiliary.drccheck(g)
0183a50e08 2024-07-01 1006: return g:GetClassCount(Card.GetRace)==#g
0183a50e08 2024-07-01 1007: end
0183a50e08 2024-07-01 1008: --check for group with 2 cards, each card match f with a1/a2 as argument
0183a50e08 2024-07-01 1009: function Auxiliary.gfcheck(g,f,a1,a2)
0183a50e08 2024-07-01 1010: if #g~=2 then return false end
0183a50e08 2024-07-01 1011: local c1=g:GetFirst()
0183a50e08 2024-07-01 1012: local c2=g:GetNext()
0183a50e08 2024-07-01 1013: return f(c1,a1) and f(c2,a2) or f(c2,a1) and f(c1,a2)
0183a50e08 2024-07-01 1014: end
0183a50e08 2024-07-01 1015: --check for group with 2 cards, each card match f1 with a1, f2 with a2 as argument
0183a50e08 2024-07-01 1016: function Auxiliary.gffcheck(g,f1,a1,f2,a2)
0183a50e08 2024-07-01 1017: if #g~=2 then return false end
0183a50e08 2024-07-01 1018: local c1=g:GetFirst()
0183a50e08 2024-07-01 1019: local c2=g:GetNext()
0183a50e08 2024-07-01 1020: return f1(c1,a1) and f2(c2,a2) or f1(c2,a1) and f2(c1,a2)
0183a50e08 2024-07-01 1021: end
0183a50e08 2024-07-01 1022: function Auxiliary.mzctcheck(g,tp)
0183a50e08 2024-07-01 1023: return Duel.GetMZoneCount(tp,g)>0
0183a50e08 2024-07-01 1024: end
0183a50e08 2024-07-01 1025: ---Check if there is space in mzone after tp releases g by reason
0183a50e08 2024-07-01 1026: ---@param g Group
0183a50e08 2024-07-01 1027: ---@param tp integer
0183a50e08 2024-07-01 1028: ---@param reason? integer
0183a50e08 2024-07-01 1029: ---@return boolean
0183a50e08 2024-07-01 1030: function Auxiliary.mzctcheckrel(g,tp,reason)
0183a50e08 2024-07-01 1031: reason=reason or REASON_COST
0183a50e08 2024-07-01 1032: return Duel.GetMZoneCount(tp,g)>0 and Duel.CheckReleaseGroupEx(tp,Auxiliary.IsInGroup,#g,reason,false,nil,g)
0183a50e08 2024-07-01 1033: end
0183a50e08 2024-07-01 1034: --used for "except this card"
0183a50e08 2024-07-01 1035: function Auxiliary.ExceptThisCard(e)
0183a50e08 2024-07-01 1036: local c=e:GetHandler()
0183a50e08 2024-07-01 1037: if c:IsRelateToChain() then return c else return nil end
0183a50e08 2024-07-01 1038: end
0183a50e08 2024-07-01 1039: --used for multi-linked zone(zone linked by two or more link monsters)
0183a50e08 2024-07-01 1040: function Auxiliary.GetMultiLinkedZone(tp)
0183a50e08 2024-07-01 1041: local f=function(c)
0183a50e08 2024-07-01 1042: return c:IsFaceup() and c:IsType(TYPE_LINK)
0183a50e08 2024-07-01 1043: end
0183a50e08 2024-07-01 1044: local lg=Duel.GetMatchingGroup(f,tp,LOCATION_MZONE,LOCATION_MZONE,nil)
0183a50e08 2024-07-01 1045: local multi_linked_zone=0
0183a50e08 2024-07-01 1046: local single_linked_zone=0
0183a50e08 2024-07-01 1047: for tc in Auxiliary.Next(lg) do
0183a50e08 2024-07-01 1048: local zone=tc:GetLinkedZone(tp)&0x7f
0183a50e08 2024-07-01 1049: multi_linked_zone=single_linked_zone&zone|multi_linked_zone
0183a50e08 2024-07-01 1050: single_linked_zone=single_linked_zone~zone
0183a50e08 2024-07-01 1051: end
0183a50e08 2024-07-01 1052: return multi_linked_zone
0183a50e08 2024-07-01 1053: end
0183a50e08 2024-07-01 1054: Auxiliary.SubGroupCaptured=nil
0183a50e08 2024-07-01 1055: function Auxiliary.CheckGroupRecursive(c,sg,g,f,min,max,ext_params)
0183a50e08 2024-07-01 1056: sg:AddCard(c)
0183a50e08 2024-07-01 1057: if Auxiliary.GCheckAdditional and not Auxiliary.GCheckAdditional(sg,c,g) then
0183a50e08 2024-07-01 1058: sg:RemoveCard(c)
0183a50e08 2024-07-01 1059: return false
0183a50e08 2024-07-01 1060: end
0183a50e08 2024-07-01 1061: local res=(#sg>=min and #sg<=max and f(sg,table.unpack(ext_params)))
0183a50e08 2024-07-01 1062: or (#sg<max and g:IsExists(Auxiliary.CheckGroupRecursive,1,sg,sg,g,f,min,max,ext_params))
0183a50e08 2024-07-01 1063: sg:RemoveCard(c)
0183a50e08 2024-07-01 1064: return res
0183a50e08 2024-07-01 1065: end
0183a50e08 2024-07-01 1066: function Auxiliary.CheckGroupRecursiveCapture(c,sg,g,f,min,max,ext_params)
0183a50e08 2024-07-01 1067: sg:AddCard(c)
0183a50e08 2024-07-01 1068: if Auxiliary.GCheckAdditional and not Auxiliary.GCheckAdditional(sg,c,g) then
0183a50e08 2024-07-01 1069: sg:RemoveCard(c)
0183a50e08 2024-07-01 1070: return false
0183a50e08 2024-07-01 1071: end
0183a50e08 2024-07-01 1072: local res=#sg>=min and #sg<=max and f(sg,table.unpack(ext_params))
0183a50e08 2024-07-01 1073: if res then
0183a50e08 2024-07-01 1074: Auxiliary.SubGroupCaptured:Clear()
0183a50e08 2024-07-01 1075: Auxiliary.SubGroupCaptured:Merge(sg)
0183a50e08 2024-07-01 1076: else
0183a50e08 2024-07-01 1077: res=#sg<max and g:IsExists(Auxiliary.CheckGroupRecursiveCapture,1,sg,sg,g,f,min,max,ext_params)
0183a50e08 2024-07-01 1078: end
0183a50e08 2024-07-01 1079: sg:RemoveCard(c)
0183a50e08 2024-07-01 1080: return res
0183a50e08 2024-07-01 1081: end
0183a50e08 2024-07-01 1082: ---
0183a50e08 2024-07-01 1083: ---@param g Group
0183a50e08 2024-07-01 1084: ---@param f function
0183a50e08 2024-07-01 1085: ---@param min? integer
0183a50e08 2024-07-01 1086: ---@param max? integer
0183a50e08 2024-07-01 1087: ---@param ... any
0183a50e08 2024-07-01 1088: ---@return boolean
0183a50e08 2024-07-01 1089: function Group.CheckSubGroup(g,f,min,max,...)
0183a50e08 2024-07-01 1090: min=min or 1
0183a50e08 2024-07-01 1091: max=max or #g
0183a50e08 2024-07-01 1092: if min>max then return false end
0183a50e08 2024-07-01 1093: local ext_params={...}
0183a50e08 2024-07-01 1094: local sg=Duel.GrabSelectedCard()
0183a50e08 2024-07-01 1095: if #sg>max or #(g+sg)<min then return false end
0183a50e08 2024-07-01 1096: if #sg==max and (not f(sg,...) or Auxiliary.GCheckAdditional and not Auxiliary.GCheckAdditional(sg,nil,g)) then return false end
0183a50e08 2024-07-01 1097: if #sg>=min and #sg<=max and f(sg,...) and (not Auxiliary.GCheckAdditional or Auxiliary.GCheckAdditional(sg,nil,g)) then return true end
0183a50e08 2024-07-01 1098: local eg=g:Clone()
0183a50e08 2024-07-01 1099: for c in Auxiliary.Next(g-sg) do
0183a50e08 2024-07-01 1100: if Auxiliary.CheckGroupRecursive(c,sg,eg,f,min,max,ext_params) then return true end
0183a50e08 2024-07-01 1101: eg:RemoveCard(c)
0183a50e08 2024-07-01 1102: end
0183a50e08 2024-07-01 1103: return false
0183a50e08 2024-07-01 1104: end
0183a50e08 2024-07-01 1105: ---
0183a50e08 2024-07-01 1106: ---@param g Group
0183a50e08 2024-07-01 1107: ---@param tp integer
0183a50e08 2024-07-01 1108: ---@param f function
0183a50e08 2024-07-01 1109: ---@param cancelable boolean
0183a50e08 2024-07-01 1110: ---@param min? integer
0183a50e08 2024-07-01 1111: ---@param max? integer
0183a50e08 2024-07-01 1112: ---@param ... any
0183a50e08 2024-07-01 1113: ---@return Group
0183a50e08 2024-07-01 1114: function Group.SelectSubGroup(g,tp,f,cancelable,min,max,...)
0183a50e08 2024-07-01 1115: Auxiliary.SubGroupCaptured=Group.CreateGroup()
0183a50e08 2024-07-01 1116: min=min or 1
0183a50e08 2024-07-01 1117: max=max or #g
0183a50e08 2024-07-01 1118: local ext_params={...}
0183a50e08 2024-07-01 1119: local sg=Group.CreateGroup()
0183a50e08 2024-07-01 1120: local fg=Duel.GrabSelectedCard()
0183a50e08 2024-07-01 1121: if #fg>max or min>max or #(g+fg)<min then return nil end
0183a50e08 2024-07-01 1122: for tc in Auxiliary.Next(fg) do
0183a50e08 2024-07-01 1123: fg:SelectUnselect(sg,tp,false,false,min,max)
0183a50e08 2024-07-01 1124: end
0183a50e08 2024-07-01 1125: sg:Merge(fg)
0183a50e08 2024-07-01 1126: local finish=(#sg>=min and #sg<=max and f(sg,...))
0183a50e08 2024-07-01 1127: while #sg<max do
0183a50e08 2024-07-01 1128: local cg=Group.CreateGroup()
0183a50e08 2024-07-01 1129: local eg=g:Clone()
0183a50e08 2024-07-01 1130: for c in Auxiliary.Next(g-sg) do
0183a50e08 2024-07-01 1131: if not cg:IsContains(c) then
0183a50e08 2024-07-01 1132: if Auxiliary.CheckGroupRecursiveCapture(c,sg,eg,f,min,max,ext_params) then
0183a50e08 2024-07-01 1133: cg:Merge(Auxiliary.SubGroupCaptured)
0183a50e08 2024-07-01 1134: else
0183a50e08 2024-07-01 1135: eg:RemoveCard(c)
0183a50e08 2024-07-01 1136: end
0183a50e08 2024-07-01 1137: end
0183a50e08 2024-07-01 1138: end
0183a50e08 2024-07-01 1139: cg:Sub(sg)
0183a50e08 2024-07-01 1140: finish=(#sg>=min and #sg<=max and f(sg,...))
0183a50e08 2024-07-01 1141: if #cg==0 then break end
0183a50e08 2024-07-01 1142: local cancel=not finish and cancelable
0183a50e08 2024-07-01 1143: local tc=cg:SelectUnselect(sg,tp,finish,cancel,min,max)
0183a50e08 2024-07-01 1144: if not tc then break end
0183a50e08 2024-07-01 1145: if not fg:IsContains(tc) then
0183a50e08 2024-07-01 1146: if not sg:IsContains(tc) then
0183a50e08 2024-07-01 1147: sg:AddCard(tc)
0183a50e08 2024-07-01 1148: if #sg==max then finish=true end
0183a50e08 2024-07-01 1149: else
0183a50e08 2024-07-01 1150: sg:RemoveCard(tc)
0183a50e08 2024-07-01 1151: end
0183a50e08 2024-07-01 1152: elseif cancelable then
0183a50e08 2024-07-01 1153: return nil
0183a50e08 2024-07-01 1154: end
0183a50e08 2024-07-01 1155: end
0183a50e08 2024-07-01 1156: if finish then
0183a50e08 2024-07-01 1157: return sg
0183a50e08 2024-07-01 1158: else
0183a50e08 2024-07-01 1159: return nil
0183a50e08 2024-07-01 1160: end
0183a50e08 2024-07-01 1161: end
0183a50e08 2024-07-01 1162: ---Create a table of filter functions
0183a50e08 2024-07-01 1163: ---@param f function
0183a50e08 2024-07-01 1164: ---@param list table
0183a50e08 2024-07-01 1165: ---@return table
0183a50e08 2024-07-01 1166: function Auxiliary.CreateChecks(f,list)
0183a50e08 2024-07-01 1167: local checks={}
0183a50e08 2024-07-01 1168: for i=1,#list do
0183a50e08 2024-07-01 1169: checks[i]=function(c) return f(c,list[i]) end
0183a50e08 2024-07-01 1170: end
0183a50e08 2024-07-01 1171: return checks
0183a50e08 2024-07-01 1172: end
0183a50e08 2024-07-01 1173: function Auxiliary.CheckGroupRecursiveEach(c,sg,g,f,checks,ext_params)
0183a50e08 2024-07-01 1174: if not checks[1+#sg](c) then
0183a50e08 2024-07-01 1175: return false
0183a50e08 2024-07-01 1176: end
0183a50e08 2024-07-01 1177: sg:AddCard(c)
0183a50e08 2024-07-01 1178: if Auxiliary.GCheckAdditional and not Auxiliary.GCheckAdditional(sg,c,g) then
0183a50e08 2024-07-01 1179: sg:RemoveCard(c)
0183a50e08 2024-07-01 1180: return false
0183a50e08 2024-07-01 1181: end
0183a50e08 2024-07-01 1182: local res
0183a50e08 2024-07-01 1183: if #sg==#checks then
0183a50e08 2024-07-01 1184: res=f(sg,table.unpack(ext_params))
0183a50e08 2024-07-01 1185: else
0183a50e08 2024-07-01 1186: res=g:IsExists(Auxiliary.CheckGroupRecursiveEach,1,sg,sg,g,f,checks,ext_params)
0183a50e08 2024-07-01 1187: end
0183a50e08 2024-07-01 1188: sg:RemoveCard(c)
0183a50e08 2024-07-01 1189: return res
0183a50e08 2024-07-01 1190: end
0183a50e08 2024-07-01 1191: ---
0183a50e08 2024-07-01 1192: ---@param g Group
0183a50e08 2024-07-01 1193: ---@param checks table
0183a50e08 2024-07-01 1194: ---@param f? function
0183a50e08 2024-07-01 1195: ---@param ... any
0183a50e08 2024-07-01 1196: ---@return boolean
0183a50e08 2024-07-01 1197: function Group.CheckSubGroupEach(g,checks,f,...)
0183a50e08 2024-07-01 1198: if f==nil then f=Auxiliary.TRUE end
0183a50e08 2024-07-01 1199: if #g<#checks then return false end
0183a50e08 2024-07-01 1200: local ext_params={...}
0183a50e08 2024-07-01 1201: local sg=Group.CreateGroup()
0183a50e08 2024-07-01 1202: return g:IsExists(Auxiliary.CheckGroupRecursiveEach,1,sg,sg,g,f,checks,ext_params)
0183a50e08 2024-07-01 1203: end
0183a50e08 2024-07-01 1204: ---
0183a50e08 2024-07-01 1205: ---@param g Group
0183a50e08 2024-07-01 1206: ---@param tp integer
0183a50e08 2024-07-01 1207: ---@param checks table
0183a50e08 2024-07-01 1208: ---@param cancelable? boolean
0183a50e08 2024-07-01 1209: ---@param f? function
0183a50e08 2024-07-01 1210: ---@param ... any
0183a50e08 2024-07-01 1211: ---@return Group
0183a50e08 2024-07-01 1212: function Group.SelectSubGroupEach(g,tp,checks,cancelable,f,...)
0183a50e08 2024-07-01 1213: if cancelable==nil then cancelable=false end
0183a50e08 2024-07-01 1214: if f==nil then f=Auxiliary.TRUE end
0183a50e08 2024-07-01 1215: local ct=#checks
0183a50e08 2024-07-01 1216: local ext_params={...}
0183a50e08 2024-07-01 1217: local sg=Group.CreateGroup()
0183a50e08 2024-07-01 1218: local finish=false
0183a50e08 2024-07-01 1219: while #sg<ct do
0183a50e08 2024-07-01 1220: local cg=g:Filter(Auxiliary.CheckGroupRecursiveEach,sg,sg,g,f,checks,ext_params)
0183a50e08 2024-07-01 1221: if #cg==0 then break end
0183a50e08 2024-07-01 1222: local tc=cg:SelectUnselect(sg,tp,false,cancelable,ct,ct)
0183a50e08 2024-07-01 1223: if not tc then break end
0183a50e08 2024-07-01 1224: if not sg:IsContains(tc) then
0183a50e08 2024-07-01 1225: sg:AddCard(tc)
0183a50e08 2024-07-01 1226: if #sg==ct then finish=true end
0183a50e08 2024-07-01 1227: else
0183a50e08 2024-07-01 1228: sg:Clear()
0183a50e08 2024-07-01 1229: end
0183a50e08 2024-07-01 1230: end
0183a50e08 2024-07-01 1231: if finish then
0183a50e08 2024-07-01 1232: return sg
0183a50e08 2024-07-01 1233: else
0183a50e08 2024-07-01 1234: return nil
0183a50e08 2024-07-01 1235: end
0183a50e08 2024-07-01 1236: end
0183a50e08 2024-07-01 1237: --for effects that player usually select card from field, avoid showing panel
0183a50e08 2024-07-01 1238: function Auxiliary.SelectCardFromFieldFirst(tp,f,player,s,o,min,max,ex,...)
0183a50e08 2024-07-01 1239: local ext_params={...}
0183a50e08 2024-07-01 1240: local g=Duel.GetMatchingGroup(f,player,s,o,ex,table.unpack(ext_params))
0183a50e08 2024-07-01 1241: local fg=g:Filter(Card.IsOnField,nil)
0183a50e08 2024-07-01 1242: g:Sub(fg)
0183a50e08 2024-07-01 1243: if #fg>=min and #g>0 then
0183a50e08 2024-07-01 1244: local last_hint=Duel.GetLastSelectHint(tp)
0183a50e08 2024-07-01 1245: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_FIELD_FIRST)
0183a50e08 2024-07-01 1246: local sg=fg:CancelableSelect(tp,min,max,nil)
0183a50e08 2024-07-01 1247: if sg then
0183a50e08 2024-07-01 1248: return sg
0183a50e08 2024-07-01 1249: else
0183a50e08 2024-07-01 1250: Duel.Hint(HINT_SELECTMSG,tp,last_hint)
0183a50e08 2024-07-01 1251: end
0183a50e08 2024-07-01 1252: end
0183a50e08 2024-07-01 1253: return Duel.SelectMatchingCard(tp,f,player,s,o,min,max,ex,table.unpack(ext_params))
0183a50e08 2024-07-01 1254: end
0183a50e08 2024-07-01 1255: function Auxiliary.SelectTargetFromFieldFirst(tp,f,player,s,o,min,max,ex,...)
0183a50e08 2024-07-01 1256: local ext_params={...}
0183a50e08 2024-07-01 1257: local g=Duel.GetMatchingGroup(f,player,s,o,ex,table.unpack(ext_params)):Filter(Card.IsCanBeEffectTarget,nil)
0183a50e08 2024-07-01 1258: local fg=g:Filter(Card.IsOnField,nil)
0183a50e08 2024-07-01 1259: g:Sub(fg)
0183a50e08 2024-07-01 1260: if #fg>=min and #g>0 then
0183a50e08 2024-07-01 1261: local last_hint=Duel.GetLastSelectHint(tp)
0183a50e08 2024-07-01 1262: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_FIELD_FIRST)
0183a50e08 2024-07-01 1263: local sg=fg:CancelableSelect(tp,min,max,nil)
0183a50e08 2024-07-01 1264: if sg then
0183a50e08 2024-07-01 1265: Duel.SetTargetCard(sg)
0183a50e08 2024-07-01 1266: return sg
0183a50e08 2024-07-01 1267: else
0183a50e08 2024-07-01 1268: Duel.Hint(HINT_SELECTMSG,tp,last_hint)
0183a50e08 2024-07-01 1269: end
0183a50e08 2024-07-01 1270: end
0183a50e08 2024-07-01 1271: return Duel.SelectTarget(tp,f,player,s,o,min,max,ex,table.unpack(ext_params))
0183a50e08 2024-07-01 1272: end
0183a50e08 2024-07-01 1273: --condition of "negate activation and banish"
0183a50e08 2024-07-01 1274: function Auxiliary.nbcon(tp,re)
0183a50e08 2024-07-01 1275: local rc=re:GetHandler()
0183a50e08 2024-07-01 1276: return Duel.IsPlayerCanRemove(tp)
0183a50e08 2024-07-01 1277: and (not rc:IsRelateToEffect(re) or rc:IsAbleToRemove())
0183a50e08 2024-07-01 1278: end
0183a50e08 2024-07-01 1279: function Auxiliary.nbtg(e,tp,eg,ep,ev,re,r,rp,chk)
0183a50e08 2024-07-01 1280: if chk==0 then return Auxiliary.nbcon(tp,re) end
0183a50e08 2024-07-01 1281: Duel.SetOperationInfo(0,CATEGORY_NEGATE,eg,1,0,0)
0183a50e08 2024-07-01 1282: if re:GetHandler():IsRelateToEffect(re) then
0183a50e08 2024-07-01 1283: Duel.SetOperationInfo(0,CATEGORY_REMOVE,eg,1,0,0)
0183a50e08 2024-07-01 1284: end
0183a50e08 2024-07-01 1285: if re:GetActivateLocation()==LOCATION_GRAVE then
0183a50e08 2024-07-01 1286: e:SetCategory(e:GetCategory()|CATEGORY_GRAVE_ACTION)
0183a50e08 2024-07-01 1287: else
0183a50e08 2024-07-01 1288: e:SetCategory(e:GetCategory()&~CATEGORY_GRAVE_ACTION)
0183a50e08 2024-07-01 1289: end
0183a50e08 2024-07-01 1290: end
0183a50e08 2024-07-01 1291: --condition of "negate activation and return to deck"
0183a50e08 2024-07-01 1292: function Auxiliary.ndcon(tp,re)
0183a50e08 2024-07-01 1293: local rc=re:GetHandler()
0183a50e08 2024-07-01 1294: return re:IsHasType(EFFECT_TYPE_ACTIVATE) or not rc:IsRelateToEffect(re) or rc:IsAbleToDeck()
0183a50e08 2024-07-01 1295: end
0183a50e08 2024-07-01 1296: --return the global index of the zone in (p,loc,seq)
0183a50e08 2024-07-01 1297: function Auxiliary.SequenceToGlobal(p,loc,seq)
0183a50e08 2024-07-01 1298: if p~=0 and p~=1 then
0183a50e08 2024-07-01 1299: return 0
0183a50e08 2024-07-01 1300: end
0183a50e08 2024-07-01 1301: if loc==LOCATION_MZONE then
0183a50e08 2024-07-01 1302: if seq<=6 then
0183a50e08 2024-07-01 1303: return 0x0001<<(16*p+seq)
0183a50e08 2024-07-01 1304: else
0183a50e08 2024-07-01 1305: return 0
0183a50e08 2024-07-01 1306: end
0183a50e08 2024-07-01 1307: elseif loc == LOCATION_SZONE then
0183a50e08 2024-07-01 1308: if seq<=4 then
0183a50e08 2024-07-01 1309: return 0x0100<<(16*p+seq)
0183a50e08 2024-07-01 1310: else
0183a50e08 2024-07-01 1311: return 0
0183a50e08 2024-07-01 1312: end
0183a50e08 2024-07-01 1313: else
0183a50e08 2024-07-01 1314: return 0
0183a50e08 2024-07-01 1315: end
0183a50e08 2024-07-01 1316: end
0183a50e08 2024-07-01 1317: --use the count limit of Lair of Darkness if the tributes are not selected by Duel.SelectReleaseGroup
0183a50e08 2024-07-01 1318: function Auxiliary.UseExtraReleaseCount(g,tp)
0183a50e08 2024-07-01 1319: local eg=g:Filter(Auxiliary.ExtraReleaseFilter,nil,tp)
0183a50e08 2024-07-01 1320: for ec in Auxiliary.Next(eg) do
0183a50e08 2024-07-01 1321: local te=ec:IsHasEffect(EFFECT_EXTRA_RELEASE_NONSUM,tp)
0183a50e08 2024-07-01 1322: if te then te:UseCountLimit(tp) end
0183a50e08 2024-07-01 1323: end
0183a50e08 2024-07-01 1324: end
0183a50e08 2024-07-01 1325: function Auxiliary.ExtraReleaseFilter(c,tp)
0183a50e08 2024-07-01 1326: return c:IsControler(1-tp) and c:IsHasEffect(EFFECT_EXTRA_RELEASE_NONSUM,tp)
0183a50e08 2024-07-01 1327: end
0183a50e08 2024-07-01 1328: --
0183a50e08 2024-07-01 1329: function Auxiliary.GetCappedLevel(c)
0183a50e08 2024-07-01 1330: local lv=c:GetLevel()
0183a50e08 2024-07-01 1331: if lv>MAX_PARAMETER then
0183a50e08 2024-07-01 1332: return MAX_PARAMETER
0183a50e08 2024-07-01 1333: else
0183a50e08 2024-07-01 1334: return lv
0183a50e08 2024-07-01 1335: end
0183a50e08 2024-07-01 1336: end
0183a50e08 2024-07-01 1337: --
0183a50e08 2024-07-01 1338: function Auxiliary.GetCappedAttack(c)
0183a50e08 2024-07-01 1339: local x=c:GetAttack()
0183a50e08 2024-07-01 1340: if x>MAX_PARAMETER then
0183a50e08 2024-07-01 1341: return MAX_PARAMETER
0183a50e08 2024-07-01 1342: else
0183a50e08 2024-07-01 1343: return x
0183a50e08 2024-07-01 1344: end
0183a50e08 2024-07-01 1345: end
0183a50e08 2024-07-01 1346: --when this card is sent to grave, record the reason effect
0183a50e08 2024-07-01 1347: --to check whether the reason effect do something simultaneously
0183a50e08 2024-07-01 1348: --so the "while this card is in your GY" condition isn't met
0183a50e08 2024-07-01 1349: function Auxiliary.AddThisCardInGraveAlreadyCheck(c)
0183a50e08 2024-07-01 1350: local e1=Effect.CreateEffect(c)
0183a50e08 2024-07-01 1351: e1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_CONTINUOUS)
0183a50e08 2024-07-01 1352: e1:SetCode(EVENT_TO_GRAVE)
0183a50e08 2024-07-01 1353: e1:SetCondition(Auxiliary.ThisCardInGraveAlreadyCheckReg)
0183a50e08 2024-07-01 1354: c:RegisterEffect(e1)
0183a50e08 2024-07-01 1355: return e1
0183a50e08 2024-07-01 1356: end
0183a50e08 2024-07-01 1357: function Auxiliary.ThisCardInGraveAlreadyCheckReg(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 1358: --condition of continous effect will be checked before other effects
0183a50e08 2024-07-01 1359: if re==nil then return false end
0183a50e08 2024-07-01 1360: if e:GetLabelObject()~=nil then return false end
0183a50e08 2024-07-01 1361: if (r&REASON_EFFECT)>0 then
0183a50e08 2024-07-01 1362: e:SetLabelObject(re)
0183a50e08 2024-07-01 1363: local e1=Effect.CreateEffect(e:GetHandler())
0183a50e08 2024-07-01 1364: e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
0183a50e08 2024-07-01 1365: e1:SetCode(EVENT_CHAIN_END)
0183a50e08 2024-07-01 1366: e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
0183a50e08 2024-07-01 1367: e1:SetOperation(Auxiliary.ThisCardInGraveAlreadyReset1)
0183a50e08 2024-07-01 1368: e1:SetLabelObject(e)
0183a50e08 2024-07-01 1369: Duel.RegisterEffect(e1,tp)
0183a50e08 2024-07-01 1370: local e2=e1:Clone()
0183a50e08 2024-07-01 1371: e2:SetCode(EVENT_BREAK_EFFECT)
0183a50e08 2024-07-01 1372: e2:SetOperation(Auxiliary.ThisCardInGraveAlreadyReset2)
0183a50e08 2024-07-01 1373: e2:SetReset(RESET_CHAIN)
0183a50e08 2024-07-01 1374: e2:SetLabelObject(e1)
0183a50e08 2024-07-01 1375: Duel.RegisterEffect(e2,tp)
0183a50e08 2024-07-01 1376: elseif (r&REASON_MATERIAL)>0 or not re:IsActivated() and (r&REASON_COST)>0 then
0183a50e08 2024-07-01 1377: e:SetLabelObject(re)
0183a50e08 2024-07-01 1378: local reset_event=EVENT_SPSUMMON
0183a50e08 2024-07-01 1379: if re:GetCode()~=EFFECT_SPSUMMON_PROC then reset_event=EVENT_SUMMON end
0183a50e08 2024-07-01 1380: local e1=Effect.CreateEffect(e:GetHandler())
0183a50e08 2024-07-01 1381: e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
0183a50e08 2024-07-01 1382: e1:SetCode(reset_event)
0183a50e08 2024-07-01 1383: e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
0183a50e08 2024-07-01 1384: e1:SetOperation(Auxiliary.ThisCardInGraveAlreadyReset1)
0183a50e08 2024-07-01 1385: e1:SetLabelObject(e)
0183a50e08 2024-07-01 1386: Duel.RegisterEffect(e1,tp)
0183a50e08 2024-07-01 1387: end
0183a50e08 2024-07-01 1388: return false
0183a50e08 2024-07-01 1389: end
0183a50e08 2024-07-01 1390: function Auxiliary.ThisCardInGraveAlreadyReset1(e)
0183a50e08 2024-07-01 1391: --this will run after EVENT_SPSUMMON_SUCCESS
0183a50e08 2024-07-01 1392: e:GetLabelObject():SetLabelObject(nil)
0183a50e08 2024-07-01 1393: e:Reset()
0183a50e08 2024-07-01 1394: end
0183a50e08 2024-07-01 1395: function Auxiliary.ThisCardInGraveAlreadyReset2(e)
0183a50e08 2024-07-01 1396: local e1=e:GetLabelObject()
0183a50e08 2024-07-01 1397: e1:GetLabelObject():SetLabelObject(nil)
0183a50e08 2024-07-01 1398: e1:Reset()
0183a50e08 2024-07-01 1399: e:Reset()
0183a50e08 2024-07-01 1400: end
0183a50e08 2024-07-01 1401: --Player p place g on the top of Deck in any order
0183a50e08 2024-07-01 1402: function Auxiliary.PlaceCardsOnDeckTop(p,g,reason)
0183a50e08 2024-07-01 1403: if reason==nil then reason=REASON_EFFECT end
0183a50e08 2024-07-01 1404: Duel.SendtoDeck(g,nil,SEQ_DECKTOP,reason)
0183a50e08 2024-07-01 1405: local rg=Duel.GetOperatedGroup()
0183a50e08 2024-07-01 1406: local og=rg:Filter(Card.IsLocation,nil,LOCATION_DECK)
0183a50e08 2024-07-01 1407: local ct1=og:FilterCount(Card.IsControler,nil,p)
0183a50e08 2024-07-01 1408: local ct2=og:FilterCount(Card.IsControler,nil,1-p)
0183a50e08 2024-07-01 1409: if ct1>1 then
0183a50e08 2024-07-01 1410: Duel.SortDecktop(p,p,ct1)
0183a50e08 2024-07-01 1411: end
0183a50e08 2024-07-01 1412: if ct2>1 then
0183a50e08 2024-07-01 1413: Duel.SortDecktop(p,1-p,ct2)
0183a50e08 2024-07-01 1414: end
0183a50e08 2024-07-01 1415: return #rg
0183a50e08 2024-07-01 1416: end
0183a50e08 2024-07-01 1417: --Player p place g on the bottom of Deck in any order
0183a50e08 2024-07-01 1418: function Auxiliary.PlaceCardsOnDeckBottom(p,g,reason)
0183a50e08 2024-07-01 1419: if reason==nil then reason=REASON_EFFECT end
0183a50e08 2024-07-01 1420: Duel.SendtoDeck(g,nil,SEQ_DECKTOP,reason)
0183a50e08 2024-07-01 1421: local rg=Duel.GetOperatedGroup()
0183a50e08 2024-07-01 1422: local og=rg:Filter(Card.IsLocation,nil,LOCATION_DECK)
0183a50e08 2024-07-01 1423: local ct1=og:FilterCount(Card.IsControler,nil,p)
0183a50e08 2024-07-01 1424: local ct2=og:FilterCount(Card.IsControler,nil,1-p)
0183a50e08 2024-07-01 1425: if ct1>0 then
0183a50e08 2024-07-01 1426: if ct1>1 then
0183a50e08 2024-07-01 1427: Duel.SortDecktop(p,p,ct1)
0183a50e08 2024-07-01 1428: end
0183a50e08 2024-07-01 1429: for i=1,ct1 do
0183a50e08 2024-07-01 1430: local tc=Duel.GetDecktopGroup(p,1):GetFirst()
0183a50e08 2024-07-01 1431: Duel.MoveSequence(tc,SEQ_DECKBOTTOM)
0183a50e08 2024-07-01 1432: end
0183a50e08 2024-07-01 1433: end
0183a50e08 2024-07-01 1434: if ct2>0 then
0183a50e08 2024-07-01 1435: if ct2>1 then
0183a50e08 2024-07-01 1436: Duel.SortDecktop(p,1-p,ct2)
0183a50e08 2024-07-01 1437: end
0183a50e08 2024-07-01 1438: for i=1,ct2 do
0183a50e08 2024-07-01 1439: local tc=Duel.GetDecktopGroup(1-p,1):GetFirst()
0183a50e08 2024-07-01 1440: Duel.MoveSequence(tc,SEQ_DECKBOTTOM)
0183a50e08 2024-07-01 1441: end
0183a50e08 2024-07-01 1442: end
0183a50e08 2024-07-01 1443: return #rg
0183a50e08 2024-07-01 1444: end
0183a50e08 2024-07-01 1445: --The event is triggered multiple times in a chain
0183a50e08 2024-07-01 1446: --but only 1 event with EVENT_CUSTOM+code will be triggered at EVENT_CHAIN_END, or immediately if not in chain
0183a50e08 2024-07-01 1447: --NOTE: re,r,rp,ep,ev of that custom event ARE NOT releated to the real event that trigger this custom event
0183a50e08 2024-07-01 1448: function Auxiliary.RegisterMergedDelayedEvent(c,code,event,g)
0183a50e08 2024-07-01 1449: local mt=getmetatable(c)
0183a50e08 2024-07-01 1450: if mt[event]==true then return end
0183a50e08 2024-07-01 1451: mt[event]=true
0183a50e08 2024-07-01 1452: if not g then g=Group.CreateGroup() end
0183a50e08 2024-07-01 1453: g:KeepAlive()
0183a50e08 2024-07-01 1454: local ge1=Effect.CreateEffect(c)
0183a50e08 2024-07-01 1455: ge1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
0183a50e08 2024-07-01 1456: ge1:SetCode(event)
0183a50e08 2024-07-01 1457: ge1:SetLabel(code)
0183a50e08 2024-07-01 1458: ge1:SetLabelObject(g)
0183a50e08 2024-07-01 1459: ge1:SetOperation(Auxiliary.MergedDelayEventCheck1)
0183a50e08 2024-07-01 1460: Duel.RegisterEffect(ge1,0)
0183a50e08 2024-07-01 1461: local ge2=ge1:Clone()
0183a50e08 2024-07-01 1462: ge2:SetCode(EVENT_CHAIN_END)
0183a50e08 2024-07-01 1463: ge2:SetOperation(Auxiliary.MergedDelayEventCheck2)
0183a50e08 2024-07-01 1464: Duel.RegisterEffect(ge2,0)
0183a50e08 2024-07-01 1465: end
0183a50e08 2024-07-01 1466: function Auxiliary.MergedDelayEventCheck1(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 1467: local g=e:GetLabelObject()
0183a50e08 2024-07-01 1468: g:Merge(eg)
0183a50e08 2024-07-01 1469: if Duel.GetCurrentChain()==0 and not Duel.CheckEvent(EVENT_CHAIN_END) then
0183a50e08 2024-07-01 1470: local _eg=g:Clone()
0183a50e08 2024-07-01 1471: Duel.RaiseEvent(_eg,EVENT_CUSTOM+e:GetLabel(),re,r,rp,ep,ev)
0183a50e08 2024-07-01 1472: g:Clear()
0183a50e08 2024-07-01 1473: end
0183a50e08 2024-07-01 1474: end
0183a50e08 2024-07-01 1475: function Auxiliary.MergedDelayEventCheck2(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 1476: local g=e:GetLabelObject()
0183a50e08 2024-07-01 1477: if #g>0 then
0183a50e08 2024-07-01 1478: local _eg=g:Clone()
0183a50e08 2024-07-01 1479: Duel.RaiseEvent(_eg,EVENT_CUSTOM+e:GetLabel(),re,r,rp,ep,ev)
0183a50e08 2024-07-01 1480: g:Clear()
0183a50e08 2024-07-01 1481: end
0183a50e08 2024-07-01 1482: end
0183a50e08 2024-07-01 1483: --B.E.S. remove counter
0183a50e08 2024-07-01 1484: function Auxiliary.EnableBESRemove(c)
0183a50e08 2024-07-01 1485: local e1=Effect.CreateEffect(c)
0183a50e08 2024-07-01 1486: e1:SetDescription(10)
0183a50e08 2024-07-01 1487: e1:SetCategory(CATEGORY_DESTROY)
0183a50e08 2024-07-01 1488: e1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_F)
0183a50e08 2024-07-01 1489: e1:SetCode(EVENT_DAMAGE_STEP_END)
0183a50e08 2024-07-01 1490: e1:SetRange(LOCATION_MZONE)
0183a50e08 2024-07-01 1491: e1:SetCondition(Auxiliary.RemoveCondtion)
0183a50e08 2024-07-01 1492: e1:SetTarget(Auxiliary.RemoveTarget)
0183a50e08 2024-07-01 1493: e1:SetOperation(Auxiliary.RemoveOperation)
0183a50e08 2024-07-01 1494: c:RegisterEffect(e1)
0183a50e08 2024-07-01 1495: end
0183a50e08 2024-07-01 1496: function Auxiliary.RemoveCondtion(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 1497: local c=e:GetHandler()
0183a50e08 2024-07-01 1498: return c:IsRelateToBattle()
0183a50e08 2024-07-01 1499: end
0183a50e08 2024-07-01 1500: function Auxiliary.RemoveTarget(e,tp,eg,ep,ev,re,r,rp,chk)
0183a50e08 2024-07-01 1501: if chk==0 then return true end
0183a50e08 2024-07-01 1502: if not e:GetHandler():IsCanRemoveCounter(tp,0x1f,1,REASON_EFFECT) then
0183a50e08 2024-07-01 1503: Duel.SetOperationInfo(0,CATEGORY_DESTROY,e:GetHandler(),1,0,0)
0183a50e08 2024-07-01 1504: end
0183a50e08 2024-07-01 1505: end
0183a50e08 2024-07-01 1506: function Auxiliary.RemoveOperation(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 1507: local c=e:GetHandler()
0183a50e08 2024-07-01 1508: if c:IsRelateToEffect(e) then
0183a50e08 2024-07-01 1509: if c:IsCanRemoveCounter(tp,0x1f,1,REASON_EFFECT) then
0183a50e08 2024-07-01 1510: c:RemoveCounter(tp,0x1f,1,REASON_EFFECT)
0183a50e08 2024-07-01 1511: else
0183a50e08 2024-07-01 1512: Duel.Destroy(c,REASON_EFFECT)
0183a50e08 2024-07-01 1513: end
0183a50e08 2024-07-01 1514: end
0183a50e08 2024-07-01 1515: end
0183a50e08 2024-07-01 1516: --The operation function of "destroy during End Phase"
0183a50e08 2024-07-01 1517: function Auxiliary.EPDestroyOperation(e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 1518: local tc=e:GetLabelObject()
0183a50e08 2024-07-01 1519: if Auxiliary.GetValueType(tc)=="Card" or Auxiliary.GetValueType(tc)=="Group" then
0183a50e08 2024-07-01 1520: Duel.Destroy(tc,REASON_EFFECT,LOCATION_GRAVE)
0183a50e08 2024-07-01 1521: end
0183a50e08 2024-07-01 1522: end
0183a50e08 2024-07-01 1523: --
0183a50e08 2024-07-01 1524: function Auxiliary.NegateSummonCondition()
0183a50e08 2024-07-01 1525: return Duel.GetReadyChain()==0
0183a50e08 2024-07-01 1526: end
0183a50e08 2024-07-01 1527: ---Check if all cards in g have the same Attribute/Race
0183a50e08 2024-07-01 1528: ---@param g Group
0183a50e08 2024-07-01 1529: ---@param f function Like Card.GetAttribute, must return binary value
0183a50e08 2024-07-01 1530: ---@return boolean
0183a50e08 2024-07-01 1531: function Auxiliary.SameValueCheck(g,f)
0183a50e08 2024-07-01 1532: if #g<=1 then return true end
0183a50e08 2024-07-01 1533: if #g==2 then return f(g:GetFirst())&f(g:GetNext())~=0 end
0183a50e08 2024-07-01 1534: local tc=g:GetFirst()
0183a50e08 2024-07-01 1535: local v=f(tc)
0183a50e08 2024-07-01 1536: tc=g:GetNext()
0183a50e08 2024-07-01 1537: while tc do
0183a50e08 2024-07-01 1538: v=v&f(tc)
0183a50e08 2024-07-01 1539: if v==0 then return false end
0183a50e08 2024-07-01 1540: tc=g:GetNext()
0183a50e08 2024-07-01 1541: end
0183a50e08 2024-07-01 1542: return v~=0
0183a50e08 2024-07-01 1543: end
0183a50e08 2024-07-01 1544: ---
0183a50e08 2024-07-01 1545: ---@param tp integer
0183a50e08 2024-07-01 1546: ---@return boolean
0183a50e08 2024-07-01 1547: function Auxiliary.IsPlayerCanNormalDraw(tp)
0183a50e08 2024-07-01 1548: return Duel.GetDrawCount(tp)>0 and Duel.GetFieldGroupCount(tp,LOCATION_DECK,0)>0
0183a50e08 2024-07-01 1549: and Duel.GetFlagEffect(tp,FLAG_ID_NO_NORMAL_DRAW)==0
0183a50e08 2024-07-01 1550: end
0183a50e08 2024-07-01 1551: ---
0183a50e08 2024-07-01 1552: ---@param e Effect
0183a50e08 2024-07-01 1553: ---@param tp integer
0183a50e08 2024-07-01 1554: ---@param property? integer
0183a50e08 2024-07-01 1555: function Auxiliary.GiveUpNormalDraw(e,tp,property)
0183a50e08 2024-07-01 1556: property=property or 0
0183a50e08 2024-07-01 1557: local c=e:GetHandler()
0183a50e08 2024-07-01 1558: local e1=Effect.CreateEffect(c)
0183a50e08 2024-07-01 1559: e1:SetType(EFFECT_TYPE_FIELD)
0183a50e08 2024-07-01 1560: e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET|property)
0183a50e08 2024-07-01 1561: e1:SetCode(EFFECT_DRAW_COUNT)
0183a50e08 2024-07-01 1562: e1:SetTargetRange(1,0)
0183a50e08 2024-07-01 1563: e1:SetReset(RESET_PHASE+PHASE_DRAW)
0183a50e08 2024-07-01 1564: e1:SetValue(0)
0183a50e08 2024-07-01 1565: Duel.RegisterEffect(e1,tp)
0183a50e08 2024-07-01 1566: Duel.RegisterFlagEffect(tp,FLAG_ID_NO_NORMAL_DRAW,RESET_PHASE+PHASE_DRAW,property,1)
0183a50e08 2024-07-01 1567: end
0183a50e08 2024-07-01 1568: ---Add EFFECT_TYPE_ACTIVATE effect to Equip Spell Cards
0183a50e08 2024-07-01 1569: ---@param c Card
0183a50e08 2024-07-01 1570: ---@param is_self boolean
0183a50e08 2024-07-01 1571: ---@param is_opponent boolean
0183a50e08 2024-07-01 1572: ---@param filter function
0183a50e08 2024-07-01 1573: ---@param eqlimit function|nil
0183a50e08 2024-07-01 1574: ---@param pause? boolean
0183a50e08 2024-07-01 1575: ---@param skip_target? boolean
0183a50e08 2024-07-01 1576: function Auxiliary.AddEquipSpellEffect(c,is_self,is_opponent,filter,eqlimit,pause,skip_target)
0183a50e08 2024-07-01 1577: local value=(type(eqlimit)=="function") and eqlimit or 1
0183a50e08 2024-07-01 1578: if pause==nil then pause=false end
0183a50e08 2024-07-01 1579: if skip_target==nil then skip_target=false end
0183a50e08 2024-07-01 1580: --Activate
0183a50e08 2024-07-01 1581: local e1=Effect.CreateEffect(c)
0183a50e08 2024-07-01 1582: e1:SetCategory(CATEGORY_EQUIP)
0183a50e08 2024-07-01 1583: e1:SetType(EFFECT_TYPE_ACTIVATE)
0183a50e08 2024-07-01 1584: e1:SetCode(EVENT_FREE_CHAIN)
0183a50e08 2024-07-01 1585: e1:SetProperty(EFFECT_FLAG_CARD_TARGET+EFFECT_FLAG_CONTINUOUS_TARGET)
0183a50e08 2024-07-01 1586: if not skip_target then
0183a50e08 2024-07-01 1587: e1:SetTarget(Auxiliary.EquipSpellTarget(is_self,is_opponent,filter,eqlimit))
0183a50e08 2024-07-01 1588: end
0183a50e08 2024-07-01 1589: e1:SetOperation(Auxiliary.EquipSpellOperation(eqlimit))
0183a50e08 2024-07-01 1590: if not pause then
0183a50e08 2024-07-01 1591: c:RegisterEffect(e1)
0183a50e08 2024-07-01 1592: end
0183a50e08 2024-07-01 1593: --Equip limit
0183a50e08 2024-07-01 1594: local e2=Effect.CreateEffect(c)
0183a50e08 2024-07-01 1595: e2:SetType(EFFECT_TYPE_SINGLE)
0183a50e08 2024-07-01 1596: e2:SetCode(EFFECT_EQUIP_LIMIT)
0183a50e08 2024-07-01 1597: e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
0183a50e08 2024-07-01 1598: e2:SetValue(value)
0183a50e08 2024-07-01 1599: c:RegisterEffect(e2)
0183a50e08 2024-07-01 1600: return e1
0183a50e08 2024-07-01 1601: end
0183a50e08 2024-07-01 1602: function Auxiliary.EquipSpellTarget(is_self,is_opponent,filter,eqlimit)
0183a50e08 2024-07-01 1603: local loc1=is_self and LOCATION_MZONE or 0
0183a50e08 2024-07-01 1604: local loc2=is_opponent and LOCATION_MZONE or 0
0183a50e08 2024-07-01 1605: return function(e,tp,eg,ep,ev,re,r,rp,chk,chkc)
0183a50e08 2024-07-01 1606: if chkc then return chkc:IsLocation(LOCATION_MZONE) and chkc:IsFaceup() and (not eqlimit or eqlimit(e,chkc)) end
0183a50e08 2024-07-01 1607: if chk==0 then return Duel.IsExistingTarget(filter,tp,loc1,loc2,1,nil) end
0183a50e08 2024-07-01 1608: Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_EQUIP)
0183a50e08 2024-07-01 1609: Duel.SelectTarget(tp,filter,tp,loc1,loc2,1,1,nil)
0183a50e08 2024-07-01 1610: Duel.SetOperationInfo(0,CATEGORY_EQUIP,e:GetHandler(),1,0,0)
0183a50e08 2024-07-01 1611: end
0183a50e08 2024-07-01 1612: end
0183a50e08 2024-07-01 1613: function Auxiliary.EquipSpellOperation(eqlimit)
0183a50e08 2024-07-01 1614: return function (e,tp,eg,ep,ev,re,r,rp)
0183a50e08 2024-07-01 1615: local c=e:GetHandler()
0183a50e08 2024-07-01 1616: local tc=Duel.GetFirstTarget()
0183a50e08 2024-07-01 1617: if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) and tc:IsFaceup() and (not eqlimit or eqlimit(e,tc)) then
0183a50e08 2024-07-01 1618: Duel.Equip(tp,c,tc)
0183a50e08 2024-07-01 1619: end
0183a50e08 2024-07-01 1620: end
0183a50e08 2024-07-01 1621: end
0183a50e08 2024-07-01 1622: ---If this face-up card would leave the field, banish it instead.
0183a50e08 2024-07-01 1623: ---@param c Card
0183a50e08 2024-07-01 1624: ---@param condition? function
0183a50e08 2024-07-01 1625: function Auxiliary.AddBanishRedirect(c,condition)
0183a50e08 2024-07-01 1626: if type(condition)~="function" then
0183a50e08 2024-07-01 1627: condition=Auxiliary.BanishRedirectCondition
0183a50e08 2024-07-01 1628: end
0183a50e08 2024-07-01 1629: local e1=Effect.CreateEffect(c)
0183a50e08 2024-07-01 1630: e1:SetType(EFFECT_TYPE_SINGLE)
0183a50e08 2024-07-01 1631: e1:SetCode(EFFECT_LEAVE_FIELD_REDIRECT)
0183a50e08 2024-07-01 1632: e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_CAN_FORBIDDEN)
0183a50e08 2024-07-01 1633: e1:SetCondition(condition)
0183a50e08 2024-07-01 1634: e1:SetValue(LOCATION_REMOVED)
0183a50e08 2024-07-01 1635: c:RegisterEffect(e1)
0183a50e08 2024-07-01 1636: end
0183a50e08 2024-07-01 1637: ---
0183a50e08 2024-07-01 1638: ---@param e Effect
0183a50e08 2024-07-01 1639: function Auxiliary.BanishRedirectCondition(e)
0183a50e08 2024-07-01 1640: return e:GetHandler():IsFaceup()
0183a50e08 2024-07-01 1641: end