vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | local locals = KC_ITEMS_LOCALS.modules.bank |
2 | |||
3 | KC_Bank = KC_ItemsModule:new({ |
||
4 | type = "bank", |
||
5 | name = locals.name, |
||
6 | desc = locals.description, |
||
7 | cmdOptions = locals.chat, |
||
8 | dependencies = {"common"}, |
||
9 | db = AceDatabase:new("KC_BankDB") |
||
10 | }) |
||
11 | |||
12 | KC_Items:Register(KC_Bank) |
||
13 | |||
14 | function KC_Bank:Enable() |
||
15 | self:RegisterEvent("BANKFRAME_OPENED") |
||
16 | self:RegisterEvent("BANKFRAME_CLOSED") |
||
17 | self:RegisterEvent("PLAYERBANKSLOTS_CHANGED" , "SaveBank") |
||
18 | self:RegisterEvent("PLAYERBANKBAGSLOTS_CHANGED" , "SaveBank") |
||
19 | self:RegisterEvent("BAG_UPDATE" , "SaveBank") |
||
20 | |||
21 | if (not self.db:get({ace.char.faction, ace.char.id}, "-10")) then |
||
22 | ace:print({1.0,0.0,0.0,UIErrorsFrame,12}, format(locals.msgs.nodata, ace.char.name)); |
||
23 | end |
||
24 | end |
||
25 | |||
26 | function KC_Bank:BANKFRAME_OPENED() |
||
27 | self.ShouldScan = true |
||
28 | local bags = {-1, 5, 6, 7, 8, 9, 10} |
||
29 | for _, bag in bags do |
||
30 | self:SaveBank(bag) |
||
31 | end |
||
32 | end |
||
33 | |||
34 | function KC_Bank:BANKFRAME_CLOSED() |
||
35 | self.ShouldScan = false |
||
36 | end |
||
37 | |||
38 | function KC_Bank:SaveBank(bag) |
||
39 | |||
40 | if (not tonumber(bag) and not tonumber(arg1)) then |
||
41 | local bags = {-1, 5, 6, 7, 8, 9, 10} |
||
42 | for _, bag in bags do |
||
43 | self:SaveBank(bag) |
||
44 | end |
||
45 | return |
||
46 | end |
||
47 | |||
48 | if (not self.ShouldScan or (tonumber(bag or arg1) > 10 and tonumber(bag or arg1) < 5 and tonumber(bag or arg1) ~= -1)) then return end |
||
49 | |||
50 | local slots = GetContainerNumSlots(bag or arg1) |
||
51 | if (slots > 0) then |
||
52 | if (bag or arg1 > 0) then |
||
53 | local link = GetInventoryItemLink("player", (bag or arg1) + 59) |
||
54 | local code = self.common:GetCode(link) |
||
55 | local info = code and (code .. "," .. slots) or nil |
||
56 | self.db:set({ace.char.faction, ace.char.id}, (bag or arg1) .. 0, info) |
||
57 | self.common:AddCode(link) |
||
58 | elseif ((bag or arg1) == -1) then |
||
59 | self.db:set({ace.char.faction, ace.char.id}, (bag or arg1) .. 0, "nil,24") |
||
60 | end |
||
61 | |||
62 | for item = 1, slots do |
||
63 | local link = GetContainerItemLink((bag or arg1), item) |
||
64 | local _, qty = GetContainerItemInfo((bag or arg1), item) |
||
65 | local code = self.common:GetCode(link, true) |
||
66 | local info = code and (code .. "," .. qty) or nil |
||
67 | self.db:set({ace.char.faction, ace.char.id}, (bag or arg1) .. item, info) |
||
68 | self.common:AddCode(link) |
||
69 | end |
||
70 | end |
||
71 | self:TriggerEvent("KCI_BANK_DATA_UPDATE") |
||
72 | end |
||
73 | |||
74 | function KC_Bank:Count(code, faction, char) |
||
75 | local count = 0; local stacks = 0; |
||
76 | local bags = {-1, 5, 6, 7, 8, 9, 10} |
||
77 | for _, bag in bags do |
||
78 | local _, slots = self:BagInfo(bag, faction, char) |
||
79 | for item = 1, (tonumber(slots) or 0) do |
||
80 | local id, qty = self:SlotInfo(bag, item, faction, char) |
||
81 | local match = (code == id) or (self.common:GetCode(id) == code) or (self.common:GetCode(code) == id) |
||
82 | if (match) then count = count + qty; stacks = stacks + 1; end |
||
83 | end |
||
84 | end |
||
85 | return count, stacks |
||
86 | end |
||
87 | |||
88 | function KC_Bank:SlotInfo(bag, slot, faction, char) |
||
89 | local info = self.db:get({faction or ace.char.faction, char or ace.char.id}, bag .. slot) or "" |
||
90 | return self.common:Split(info, ",") |
||
91 | end |
||
92 | |||
93 | function KC_Bank:BagInfo(bag, faction, char) |
||
94 | local info = self.db:get({faction or ace.char.faction, char or ace.char.id}, bag .. 0) or "" |
||
95 | return self.common:Split(info, ",") |
||
96 | end |