From 82b9bf2e03029806f701ed60e6e4842566526f16 Mon Sep 17 00:00:00 2001 From: Ade <923+ade@noreply.octowow.st> Date: Wed, 14 Oct 2026 02:33:00 +0000 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20=C2=AB?= =?UTF-8?q?/=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- events.lua | 12 ++++++++++- scan.lua | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++--- sync.lua | 34 ++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 4 deletions(-) diff --git a/events.lua b/events.lua index 153d261..5ce35c9 100644 --- a/events.lua +++ b/events.lua @@ -249,6 +249,16 @@ SlashCmdList["PROFCD"] = function(msg) AA.Print("stored " .. key .. ": " .. (exp > 0 and (AA.FormatTime(exp - time()) .. " left") or "ready")) end AA.Print("file sync: " .. ((ImportFile and ExportFile) and "on" or "off")) + elseif cmd == "bags" then + for bag = 0, 10 do + local nm = GetBagName and GetBagName(bag) + local inv = "" + if bag >= 1 and bag <= 4 then inv = tostring(ContainerIDToInventoryID(bag)) + elseif bag >= 5 and BankButtonIDToInvSlotID then inv = tostring(BankButtonIDToInvSlotID(bag - 4, 1)) end + local l = inv ~= "" and GetInventoryItemLink("player", tonumber(inv)) or nil + local _, _, ln = string.find(l or "", "%[(.-)%]") + AA.Print("bag " .. bag .. ": name=" .. tostring(nm) .. " slots=" .. tostring(GetContainerNumSlots(bag)) .. " invslot=" .. inv .. " link=" .. tostring(ln)) + end elseif cmd == "reset" then for k in pairs(AA.me.cds) do AA.me.cds[k] = 0 end AA.dirty = true @@ -265,7 +275,7 @@ SlashCmdList["PROFCD"] = function(msg) AA.Print("removed " .. n .. " character(s).") AA.Refresh() else - AA.Print("/ade - alts window | cd (cooldowns) | find | list | sync | scan | status | debug | export | import | minimap | alert | reset | del ") + AA.Print("/ade - alts window | cd (cooldowns) | find | list | sync | scan | status | debug | bags | export | import | minimap | alert | reset | del ") end end diff --git a/scan.lua b/scan.lua index 9b9c91b..ac0f86c 100644 --- a/scan.lua +++ b/scan.lua @@ -249,12 +249,16 @@ end local function ScanContainers(bags) local order, agg = {}, {} local slotsTotal = 0 + local binfo = {} + local claimed = {} for _, bag in ipairs(bags) do local slots = GetContainerNumSlots(bag) or 0 slotsTotal = slotsTotal + slots + local used = 0 for slot = 1, slots do local link = GetContainerItemLink(bag, slot) if link then + used = used + 1 local _, _, sid = string.find(link, "item:(%d+)") local id = tonumber(sid) if id then @@ -270,6 +274,48 @@ local function ScanContainers(bags) end end end + if slots > 0 then + -- the bag item itself (backpack / main bank have none) + local bid = 0 + local inv + if bag >= 1 and bag <= 4 then + local ok, v = pcall(ContainerIDToInventoryID, bag) + if ok then inv = v end + elseif bag >= 5 and BankButtonIDToInvSlotID then + local ok, v = pcall(BankButtonIDToInvSlotID, bag - 4, 1) + if ok then inv = v end + end + -- the client's own bag name is authoritative; the inventory slot guess may point at another bag + local want = GetBagName and GetBagName(bag) + local function linkName(l) + local _, _, nm = string.find(l or "", "%[(.-)%]") + return nm + end + local pick, pickLink + if inv then + local l = GetInventoryItemLink("player", inv) + if l and not claimed[inv] and (not want or want == "" or linkName(l) == want) then pick, pickLink = inv, l end + end + if not pick and want and want ~= "" then + local lo, hi = 20, 23 + if bag >= 5 then lo, hi = 40, 90 end + for s2 = lo, hi do + if not claimed[s2] then + local l = GetInventoryItemLink("player", s2) + if l and linkName(l) == want then pick, pickLink = s2, l; break end + end + end + end + if pick then + claimed[pick] = true + local _, _, bsid = string.find(pickLink, "item:(%d+)") + if bsid then + bid = tonumber(bsid) + LearnItem(bid, pickLink, GetInventoryItemTexture("player", pick)) + end + end + table.insert(binfo, slots .. ":" .. used .. ":" .. bid) + end end if slotsTotal == 0 then return nil end local list, parts = {}, {} @@ -277,7 +323,7 @@ local function ScanContainers(bags) table.insert(list, { id, agg[id] }) table.insert(parts, id .. ":" .. agg[id]) end - return list, table.concat(parts, "~") + return list, table.concat(parts, "~"), table.concat(binfo, "~") end -- equipped gear: slot -> "id:enchant:suffix:unique" @@ -377,7 +423,12 @@ function AA.ScanSelf() end if ScanEquip() then changed = true end if ScanSkills() then changed = true end - local list, sig = ScanContainers({ 0, 1, 2, 3, 4 }) + local list, sig, binfo = ScanContainers({ 0, 1, 2, 3, 4 }) + if list and binfo ~= AA.me.invBags then + AA.me.invBags = binfo + AA.me.invBagsTs = time() + changed = true + end if list and sig ~= AA.me.invSig then AA.me.inv = list AA.me.invSig = sig @@ -387,7 +438,12 @@ function AA.ScanSelf() if AA.bankOpen then local bags = { -1 } for b = 5, 10 do table.insert(bags, b) end - local bl, bs = ScanContainers(bags) + local bl, bs, bbinfo = ScanContainers(bags) + if bl and bbinfo ~= AA.me.bankBags then + AA.me.bankBags = bbinfo + AA.me.bankBagsTs = time() + changed = true + end if bl and bs ~= AA.me.bankSig then AA.me.bank = bl AA.me.bankSig = bs diff --git a/sync.lua b/sync.lua index f8ff9cc..42225f8 100644 --- a/sync.lua +++ b/sync.lua @@ -190,6 +190,37 @@ local function ReceiveEquip(text) return true end +-- bag sizes / used slots: B^name^realm^invBagsTs^bankBagsTs^inv^bank +local function EncodeBags(c) + return "B^" .. c.name .. "^" .. c.realm .. "^" .. (c.invBagsTs or 0) .. "^" .. (c.bankBagsTs or 0) + .. "^" .. (c.invBags or "") .. "^" .. (c.bankBags or "") +end + +local function ReceiveBags(text) + local _, _, name, realm, its, bts, inv, bank = + string.find(text, "^B%^([^%^]*)%^([^%^]*)%^(%d*)%^(%d*)%^([^%^]*)%^(.*)$") + if not name or name == "" then return false end + local k = name .. "-" .. realm + local c = AA.db.chars[k] + if not c then + c = { name = name, realm = realm, cds = {}, remote = true } + AA.db.chars[k] = c + end + its, bts = tonumber(its) or 0, tonumber(bts) or 0 + local ch = false + if its > (c.invBagsTs or 0) then + c.invBagsTs = its + c.invBags = inv + ch = true + end + if bts > (c.bankBagsTs or 0) then + c.bankBagsTs = bts + c.bankBags = bank + ch = true + end + return ch +end + local function FileRead(name) if not (ImportFile and ExportFile) then return nil end local ok, txt = pcall(ImportFile, name) @@ -211,6 +242,8 @@ local function MergeText(txt) if ReceiveProf(line) then n = n + 1 end elseif t == "E^" then if ReceiveEquip(line) then n = n + 1 end + elseif t == "B^" then + if ReceiveBags(line) then n = n + 1 end elseif t == "I^" then ReceiveItem(line) end @@ -245,6 +278,7 @@ local function FileWrite() if c.prof then for pname, p in pairs(c.prof) do table.insert(parts, EncodeProf(c, pname, p)) end end + if c.invBags or c.bankBags then table.insert(parts, EncodeBags(c)) end if c.equip then table.insert(parts, EncodeEquip(c)) for slot, ref in pairs(c.equip) do