-- Opens owned cases, including case rewards, until inventory is empty. local OPEN_LIMIT = math.huge local INTERVAL = 10 local TIMEOUT = 20 local env = getgenv() assert(game.PlaceId == 82983707799188, "Unexpected place.") assert(not env.WeaponDuelsCasesRunning, "Opener already running.") local RS = game:GetService("ReplicatedStorage") local R = RS:WaitForChild("Remotes", 10) assert(R and R:FindFirstChild("Crate") and R:FindFirstChild("Inventory"), "Interface missing.") local definitions = require(RS.Database.Modules.Crate) local Http = game:GetService("HttpService") local report = {status="running",sent=0,verified=0,rewards={}} env.WeaponDuelsCaseReport = report env.WeaponDuelsCasesRunning = true env.WeaponDuelsCasesStop = false local active, unexpected, connection local function snapshot() local done, ok, result = false, false, nil task.spawn(function() ok, result = pcall(function() return R.Inventory.GetInventory:InvokeServer() end) done = true end) local deadline = os.clock() + TIMEOUT repeat task.wait(0.1) until done or os.clock() >= deadline assert(done and ok and type(result)=="table" and type(result.Crate)=="table", "Inventory query failed.") local copy = {} for name,n in pairs(result.Crate) do assert(type(n)=="number" and n>=0 and n0 then table.insert(names,name) end end table.sort(names) report.remaining=before if #names==0 then report.status="complete"; return end local name=names[1] for _,candidate in ipairs(names) do if candidate>lastName then name=candidate; break end end lastName=name active={name=name} report.sent+=1 R.Crate:FireServer(name) nextAllowed=os.clock()+INTERVAL local deadline=os.clock()+TIMEOUT repeat task.wait(0.1) until active.result or unexpected or os.clock()>=deadline assert(not unexpected, "Unexpected result; stopped.") assert(active.result, "No server acknowledgment; stopped without retrying.") local result=active.result local after repeat after=snapshot() if matches(before,after,result) then break end task.wait(0.5) until os.clock()>=deadline assert(matches(before,after,result), "Inventory mismatch; stopped.") assert(not unexpected, "Extra result; stopped.") report.verified+=1 report.remaining=after table.insert(report.rewards,result) active=nil print("[Cases] Verified",report.verified,name,"->",result.reward) end report.status=env.WeaponDuelsCasesStop and "stopped" or "test complete" end,debug.traceback) if connection then connection:Disconnect() end env.WeaponDuelsCasesRunning=false if not ok then report.status="error"; report.error=tostring(err); warn(report.error) end print("[Cases] Queue summary",Http:JSONEncode(report))