vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 local locals = KC_ITEMS_LOCALS.modules.inventory
2  
3 KC_Inventory = KC_ItemsModule:new({
4 type = "inventory",
5 name = locals.name,
6 desc = locals.description,
7 cmdOptions = locals.chat,
8 dependencies = {"common"},
9 db = AceDatabase:new("KC_InvDB")
10 })
11  
12 KC_Items:Register(KC_Inventory)
13  
14 function KC_Inventory:Enable()
15 for bag = 0, 4 do
16 self:SaveInv(bag)
17 end
18 self:RegisterEvent("BAG_UPDATE", "SaveInv")
19 end
20  
21 function KC_Inventory:SaveInv(bag)
22 if (not tonumber(bag) and not tonumber(arg1)) then
23 for bag = 0, 4 do
24 self:SaveInv(bag)
25 end
26  
27 return
28 end
29  
30 if ((bag or arg1) < 0 or (bag or arg1) > 4) then return end
31  
32 local slots = GetContainerNumSlots((bag or arg1)) or 0
33 if (slots > 0) then
34 if ((bag or arg1) > 0) then
35 local link = GetInventoryItemLink("player", (bag or arg1) + 19)
36 local code = self.common:GetCode(link)
37 local info = code and (code .. "," .. slots) or nil
38 self.db:set({ace.char.faction, ace.char.id}, (bag or arg1) .. 0, info)
39 self.common:AddCode(link)
40 elseif((bag or arg1) == 0) then
41 self.db:set({ace.char.faction, ace.char.id}, (bag or arg1) .. 0, "nil,16")
42 end
43  
44 for item = 1, slots do
45 local link = GetContainerItemLink((bag or arg1), item)
46 local _, qty = GetContainerItemInfo((bag or arg1), item)
47 local code = self.common:GetCode(link, true)
48 local info = code and (code .. "," .. qty) or nil
49 self.db:set({ace.char.faction, ace.char.id}, (bag or arg1) .. item, info)
50 self.common:AddCode(link)
51 end
52 end
53  
54 self:TriggerEvent("KCI_INV_DATA_UPDATE")
55 end
56  
57  
58 function KC_Inventory:Count(code, faction, char)
59 local count = 0; local stacks = 0;
60 for bag = 0, 4 do
61 local _, slots = self:BagInfo(bag, faction, char)
62 for item = 1, (tonumber(slots) or 0) do
63 local id, qty = self:SlotInfo(bag, item, faction, char)
64 local match = (code == id) or (self.common:GetCode(id) == code) or (self.common:GetCode(code) == id)
65 if (match) then count = count + qty; stacks = stacks + 1; end
66 end
67 end
68 return count, stacks
69 end
70  
71 function KC_Inventory:SlotInfo(bag, slot, faction, char)
72 local info = self.db:get({faction or ace.char.faction, char or ace.char.id}, bag .. slot) or ""
73 return self.common:Split(info, ",")
74 end
75  
76 function KC_Inventory:BagInfo(bag, faction, char)
77 local info = self.db:get({faction or ace.char.faction, char or ace.char.id}, bag .. 0) or ""
78 return self.common:Split(info, ",")
79 end