View Single Post
10/28/15, 05:50 PM   #13
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
A very old bump for 1st thank you for this feedback

I personnally wrote this :

Lua Code:
  1. -- Our bagcache, because game don't have it in realtime
  2.     local tinyBagCache = {
  3.         [BAG_BACKPACK] = {},
  4.         [BAG_BANK] = {},
  5.     }
  6.    
  7.     -- Thanks Merlight & circonian, FindFirstEmptySlotInBag don't refresh in realtime.
  8.     local function FindEmptySlotInBag(bagId)
  9.         for slotIndex = 0, (GetBagSize(bagId) - 1) do
  10.             if not SHARED_INVENTORY.bagCache[bagId][slotIndex] and not tinyBagCache[bagId][slotIndex] then
  11.                 tinyBagCache[bagId][slotIndex] = true
  12.                 return slotIndex
  13.             end
  14.         end
  15.         return nil
  16.     end


But this function is not the only one to do not update in real time, a second one, more recent got the same problem : GetItemLinkStacks(itemLink)


My solution is :


Lua Code:
  1. -- Our bagcache for qty, because game don't have it in realtime
  2.     local qtyBagCache = {}
  3.  
  4.     -- this function returns more info than desired, but it's for the exemple.
  5.     local function StackInfoInBag(bagToCheck, slotIdFrom, bagIdFrom, itemLink)
  6.         local stackCountBackpack, stackCountBank
  7.        
  8.         if not qtyBagCache[itemLink] then
  9.             stackCountBackpack, stackCountBank = GetItemLinkStacks(itemLink) -- Not updated in realtime
  10.             qtyBagCache[itemLink] = {}
  11.             qtyBagCache[itemLink][BAG_BACKPACK] = stackCountBackpack
  12.             qtyBagCache[itemLink][BAG_BANK] = stackCountBank
  13.         else
  14.             stackCountBackpack = qtyBagCache[itemLink][BAG_BACKPACK]
  15.             stackCountBank = qtyBagCache[itemLink][BAG_BANK]
  16.         end
  17.        
  18.         d("--------------")
  19.         d(stackCountBackpack, stackCountBank)
  20.         d("---")
  21.         d(GetItemLinkStacks(itemLink))
  22.         d("--------------")
  23.        
  24.         local stackSize, maxStack = GetSlotStackSize(bagIdFrom, slotIdFrom)
  25.         if bagToCheck == BAG_BACKPACK then
  26.             return stackCountBackpack >= maxStack, stackSize, maxStack, stackCountBackpack, stackCountBank
  27.         elseif bagToCheck == BAG_BANK then
  28.             return stackCountBank >= maxStack, stackSize, maxStack, stackCountBackpack, stackCountBank
  29.         end
  30.     end


An exemple :

Code:
[00:38:18] --------------
[00:38:18] 672 -- backpackqty with mycache func
[00:38:18] 500 -- bankqty with mycache func
[00:38:18] ---
[00:38:18] 672 -- backpackqty with ZOS func
[00:38:18] 500 -- bankqty with ZOS func
[00:38:18] --------------
[00:38:18] BMR a déplacé 72x [Toile du Vide] en banque <----- my addon moved 72x from bag to bank
[00:38:18] --------------
[00:38:18] 600 -- backpackqty with mycache func
[00:38:18] 572 -- bankqty with mycache func
[00:38:18] ---
[00:38:18] 672 -- backpackqty with ZOS func -- Wrong
[00:38:18] 500 -- bankqty with ZOS func -- Wrong
[00:38:18] --------------
[00:38:18] BMR a déplacé 28x [Toile du Vide] en banque <----- my addon moved 28x from bag to bank (from another stack, approx 1ms after 1st move
[00:38:18] --------------
[00:38:18] 572 -- backpackqty with mycache func
[00:38:18] 600 -- bankqty with mycache func
[00:38:18] ---
[00:38:18] 672 -- backpackqty with ZOS func -- Wrong
[00:38:18] 500 -- bankqty with ZOS func -- Wrong
[00:38:18] --------------
  Reply With Quote