diff --git a/module_bags.lua b/module_bags.lua index 0fd73a1..89cf6f6 100755 --- a/module_bags.lua +++ b/module_bags.lua @@ -9,14 +9,44 @@ local modul = { } local db local desc = format('%sCount', modulname) +local GetContainerItemInfo = GetContainerItemInfo +if(C_Container and C_Container.GetContainerItemInfo) then + GetContainerItemInfo2 = C_Container.GetContainerItemInfo +else + GetContainerItemInfo2 = function(bag, slot) + local icon, itemCount, locked, quality, readable, lootable, itemLink, isFiltered, noValue, itemID, isBound = GetContainerItemInfo(bag, slot) + if(icon) then + return { + ['iconFileID'] = icon, + ['stackCount'] = itemCount, + ['isLocked'] = locked, + ['quality'] = quality, + ['isReadable'] = readable, + ['hasLoot'] = lootable, + ['hyperlink'] = itemLink, + ['isFiltered'] = isFiltered, + ['hasNoValue'] = noValue, + ['itemID'] = itemID, + ['isBound'] = isBound + } + end + end +end + +local function GetContainerNumSlots2(bag, slot) + if(C_Container and C_Container.GetContainerNumSlots) then + return C_Container.GetContainerNumSlots(bag, slot) + end + return GetContainerNumSlots(bag, slot) +end function child:scanBag(bag) local slot = 1 local itemlist = {} local empty = true - while(slot<=C_Container.GetContainerNumSlots(bag)) do + while(slot<=GetContainerNumSlots2(bag)) do local item = Item:CreateFromBagAndSlot(bag, slot) if(item) then - local itemInfo = C_Container.GetContainerItemInfo(bag, slot) + local itemInfo = GetContainerItemInfo2(bag, slot) local id = item:GetItemID() if(itemInfo and id) then empty = false @@ -30,16 +60,25 @@ function child:scanBag(bag) end return empty and nil or itemlist end +local startbag, endbag +if(Enum and Enum.BagIndex) then + startbag = Enum.BagIndex.Backpack + endbag = Enum.BagIndex.ReagentBag +else + startbag = BACKPACK_CONTAINER + endbag = NUM_BAG_SLOTS +end local function scanAllBags(delayed) if(not child:funcSync(scanAllBags, delayed)) then return end local playerID = child.getPID() if(playerID) then local tab = modul['db'][playerID] - for bag=Enum.BagIndex.Backpack ,Enum.BagIndex.ReagentBag do + print() + for bag=startbag ,endbag do tab[bag] = child:scanBag(bag) -- loop all bought bags end for k,v in pairs(modul['db'][playerID]) do - if(kEnum.BagIndex.ReagentBag) then + if(k < startbag or k > endbag) then tab[k] = nil -- prevent bogus bags end end diff --git a/module_bank.lua b/module_bank.lua index 60276fe..d19fe54 100755 --- a/module_bank.lua +++ b/module_bank.lua @@ -11,6 +11,20 @@ local db local desc = format('%sCount', modulname) local desc2 = 'reagentCount' local BankIsOpen = false +local startbag, endbag, bankbag, reagentbankbag = 0, 4, -1, -3 +if(Enum and Enum.BagIndex) then + startbag = Enum.BagIndex.Backpack + endbag = Enum.BagIndex.ReagentBag + bankbag = Enum.BagIndex.Bank + reagentbankbag = Enum.BagIndex.Reagentbank + reagentbag = Enum.BagIndex.ReagentBag +else + startbag = 6 + endbag = startbag + GetNumBankSlots() + bankbag = BANK_CONTAINER + reagentbankbag = -3 + reagentbag = BACKPACK_CONTAINER + NUM_BAG_SLOTS + 1 +end function modul.Guess(id) local dbcount = modul.Get(id) local count = GetItemCount(id,true) @@ -20,7 +34,7 @@ function modul.Guess(id) local dif = dbcount - count modul['db'][playerID] = modul['db'][playerID] or {} local tab = modul['db'][playerID] - for bag = Enum.BagIndex.BankBag_1 ,Enum.BagIndex.BankBag_1 + GetNumBankSlots() - 1 do + for bag = startbag ,endbag - 1 do local btab = tab[bag] if(btab and btab[id] and btab[id]['count'] > 0) then while(dif > 0 and btab[id]['count'] > 0) do @@ -54,7 +68,7 @@ local function scanAllBankBags(delayed) if(playerID) then modul['db'][playerID] = modul['db'][playerID] or {} local tab = modul['db'][playerID] - for bag = Enum.BagIndex.BankBag_1 ,Enum.BagIndex.BankBag_1 + GetNumBankSlots() - 1 do + for bag = startbag ,endbag - 1 do tab[bag] = tab[bag] or {} if(BankIsOpen) then tab[bag] = child:scanBag(bag) -- loop all bought bankbags @@ -63,17 +77,17 @@ local function scanAllBankBags(delayed) end end if(BankIsOpen) then - tab[Enum.BagIndex.Bank] = child:scanBag(Enum.BagIndex.Bank) -- Main bankbag + tab[bankbag] = child:scanBag(bankbag) -- Main bankbag else - guess(tab[Enum.BagIndex.Bank]) + guess(tab[bankbag]) end if(BankIsOpen) then - tab[Enum.BagIndex.Reagentbank] = child:scanBag(Enum.BagIndex.Reagentbank) -- Main reagentbag + tab[reagentbankbag] = child:scanBag(reagentbankbag) -- Main reagentbag else - guess(tab[Enum.BagIndex.Reagentbank]) + guess(tab[reagentbankbag]) end for k,v in pairs(modul['db'][playerID]) do - if(not(k == Enum.BagIndex.Bank) and not(k == Enum.BagIndex.Reagentbank) and not(k > Enum.BagIndex.ReagentBag and k <= GetNumBankSlots() + Enum.BagIndex.ReagentBag)) then + if(not(k == bankbag) and not(k == reagentbankbag) and not(k > reagentbag and k <= GetNumBankSlots() + reagentbag)) then tab[k] = nil -- prevent bogus bankbags end end @@ -89,7 +103,7 @@ local function bagLoop(id, res) if(playerID and units[k]['faction'] == units[playerID]['faction']) then local unitname = units[k]['name'] for bag, list in pairs(v) do - dName = (bag == Enum.BagIndex.Reagentbank) and desc2 or desc + dName = (bag == reagentbankbag) and desc2 or desc for a, b in pairs(list) do if(a == id) then res[unitname] = res[unitname] or { @@ -135,7 +149,9 @@ function events:PLAYERBANKBAGSLOTS_CHANGED(...) scanAllBankBags() end events.PLAYERBANKSLOTS_CHANGED = events.PLAYERBANKBAGSLOTS_CHANGED -events.PLAYERREAGENTBANKSLOTS_CHANGED = events.PLAYERBANKBAGSLOTS_CHANGED +if(BuyReagentBank) then + events.PLAYERREAGENTBANKSLOTS_CHANGED = events.PLAYERBANKBAGSLOTS_CHANGED +end events.ITEM_UNLOCKED = events.PLAYERBANKBAGSLOTS_CHANGED events.BAG_UPDATE_DELAYED = events.PLAYERBANKBAGSLOTS_CHANGED local function OnEvent(self, event, ...) @@ -171,15 +187,13 @@ function modul:Delete(id, typ) self['db'][id] = nil end end -local skip = { - [WOW_PROJECT_WRATH_CLASSIC] = { - ['PLAYERREAGENTBANKSLOTS_CHANGED'] = true - }, - [WOW_PROJECT_MAINLINE] = { +local skip = {} +if(WOW_PROJECT_MAINLINE) then + skip[WOW_PROJECT_MAINLINE] = { ['BANKFRAME_OPENED'] = true, ['BANKFRAME_CLOSED'] = true - } -} + } +end function modul:Enable() self['status'] = true local list = {} diff --git a/module_currency.lua b/module_currency.lua index 7f64d0d..8318fe0 100755 --- a/module_currency.lua +++ b/module_currency.lua @@ -201,7 +201,7 @@ function modul:Disable() end end end -if(LE_EXPANSION_LEVEL_CURRENT