vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | OneStorage = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0", "AceHook-2.0", "AceDebug-2.0", "AceConsole-2.0") |
2 | local L = AceLibrary("AceLocale-2.0"):new("OneView") |
||
3 | |||
4 | function OneStorage:OnInitialize() |
||
5 | self:RegisterEvent("OneView_Loaded") |
||
6 | end |
||
7 | |||
8 | function OneStorage:OneView_Loaded() |
||
9 | if not self.db then |
||
10 | self.db = OneView:AcquireDBNamespace("storage") |
||
11 | OneView:RegisterDefaults("storage", 'account', { ['*'] = { ['*'] = { } } }) |
||
12 | local AceDB = AceLibrary("AceDB-2.0") |
||
13 | self.faction = AceDB.FACTION |
||
14 | self.charId = AceDB.CHAR_ID |
||
15 | end |
||
16 | |||
17 | self:RegisterEvent("BAG_UPDATE", function() self:SaveBag(arg1) end) |
||
18 | self:RegisterEvent("BANKFRAME_OPENED", function() self.bankOpened = true self:SaveBag(-1) for i=5,10 do self:SaveBag(i) end end) |
||
19 | self:RegisterEvent("BANKFRAME_CLOSED", function() self.bankOpened = false end) |
||
20 | self:RegisterEvent("PLAYERBANKSLOTS_CHANGED", function() self:SaveBag(-1) end) |
||
21 | self:RegisterEvent("PLAYERBANKBAGSLOTS_CHANGED" , function() self:SaveBag(-1) end) |
||
22 | |||
23 | self:RegisterEvent("UNIT_INVENTORY_CHANGED", "SaveEquipment") |
||
24 | |||
25 | self:RegisterEvent("PLAYER_MONEY", "SaveMoney") |
||
26 | self:SaveEquipment() |
||
27 | self:SaveMoney() |
||
28 | |||
29 | for bag = 0, 4 do |
||
30 | self:SaveBag(bag) |
||
31 | end |
||
32 | end |
||
33 | |||
34 | function OneStorage:SaveMoney() |
||
35 | self.db.account[self.faction][self.charId]["money"] = GetMoney() |
||
36 | end |
||
37 | |||
38 | function OneStorage:SaveBag(bag) |
||
39 | local size = GetContainerNumSlots(bag) or 0 |
||
40 | |||
41 | if (bag > 4 and bag <= 10) and not self.bankOpened then return end |
||
42 | |||
43 | if bag > 0 then |
||
44 | local link = GetInventoryItemLink("player", bag < 5 and bag + 19 or bag + 59) |
||
45 | local _, _, code = strfind(link or "", "(item:%d+:%d+:%d+:%d+)") |
||
46 | local info = code and (code .. "," .. size) or nil |
||
47 | isAmmo, isSoul, isProf = self:GetBagTypes(bag) |
||
48 | if info then |
||
49 | info = format("%s,%s,%s,%s", info, tostring(isAmmo), tostring(isSoul), tostring(isProf)) |
||
50 | end |
||
51 | self.db.account[self.faction][self.charId][bag .. 0] = info |
||
52 | elseif(bag == 0) then |
||
53 | self.db.account[self.faction][self.charId][bag .. 0] = "nil,16,false,false,false" |
||
54 | elseif(bag == -1) then |
||
55 | self.db.account[self.faction][self.charId][bag .. 0] = "nil,24,false,false,false" |
||
56 | end |
||
57 | |||
58 | for slot = 1, size do |
||
59 | local link = GetContainerItemLink(bag, slot) |
||
60 | local _, qty = GetContainerItemInfo(bag, slot) |
||
61 | local _, _, code = strfind(link or "", "(item:%d+:%d+:%d+:%d+)") |
||
62 | local info = code and (code .. "," .. qty) or nil |
||
63 | self.db.account[self.faction][self.charId][bag .. slot] = info |
||
64 | end |
||
65 | end |
||
66 | |||
67 | function OneStorage:SaveEquipment() |
||
68 | for slot = 0, 19 do |
||
69 | local link = GetInventoryItemLink("player",slot) |
||
70 | if (link) then |
||
71 | local _, _, code = strfind(link or "", "(item:%d+:%d+:%d+:%d+)") |
||
72 | self.db.account[self.faction][self.charId]["e" .. slot] = code |
||
73 | else |
||
74 | self.db.account[self.faction][self.charId]["e" .. slot] = code |
||
75 | end |
||
76 | end |
||
77 | self.db.account[self.faction][self.charId]["relic"] = UnitHasRelicSlot("player") |
||
78 | end |
||
79 | |||
80 | function OneStorage:Trim(msg) |
||
81 | if not msg then return end |
||
82 | local results = string.gsub(msg, "^%s+", "") |
||
83 | return string.gsub(results, "%s+$", "") |
||
84 | end |
||
85 | |||
86 | function OneStorage:Split(string, sep) |
||
87 | if (not string or type(string) ~= "string") then error("Bad String was a " .. type(string) .. "value: " .. (string or "nil"), 2) end |
||
88 | local x, y = (strfind(string , sep) or 0), (strlen(sep) or 1) |
||
89 | return (tonumber(strsub(string, 1, x-1)) or strsub(string, 1, x-1)), (tonumber(strsub(string, x+y)) or strsub(string, x+y)) |
||
90 | end |
||
91 | |||
92 | function OneStorage:Explode(string, sep) |
||
93 | if (not string) then return end |
||
94 | if (type(string) ~= "string") then error("Bad String was a " .. type(string) .. "value: " .. (string or "nil"), 2) end |
||
95 | local a, b = self:Split(string, sep) |
||
96 | if (not b or b == "") then return a; end |
||
97 | if (not strfind(b, sep)) then return a, b; end |
||
98 | return a, self:Explode(b, sep) |
||
99 | end |
||
100 | |||
101 | function OneStorage:SlotInfo(faction, charId, bag, slot) |
||
102 | local info = self.db.account[faction or self.faction][charId or self.charId][bag .. slot] |
||
103 | if info then |
||
104 | return self:Split(info, ",") |
||
105 | end |
||
106 | end |
||
107 | |||
108 | function OneStorage:BagInfo(faction, charId, bag) |
||
109 | local info = self.db.account[faction or self.faction][charId or self.charId][bag .. 0] |
||
110 | if info then |
||
111 | local itemId, size, isAmmo, isSoul, isProf = self:Explode(info, ",") |
||
112 | return itemId, size, (isAmmo == "true"), (isSoul == "true"), (isProf == "true") |
||
113 | end |
||
114 | end |
||
115 | |||
116 | function OneStorage:HasRelic(faction, charId) |
||
117 | return self.db.account[faction or self.faction][charId or self.charId]["relic"] |
||
118 | end |
||
119 | |||
120 | function OneStorage:EquipmentInfo(faction, charId, slot) |
||
121 | return self.db.account[faction or self.faction][charId or self.charId]["e" .. slot] |
||
122 | end |
||
123 | |||
124 | function OneStorage:GetMoney(faction, charId) |
||
125 | return self.db.account[faction or self.faction][charId or self.charId]["money"] |
||
126 | end |
||
127 | |||
128 | function OneStorage:GetBagTypes(bag) |
||
129 | if( bag <= 0 ) then return end |
||
130 | |||
131 | local _, _, id = strfind(GetInventoryItemLink("player", ContainerIDToInventoryID(bag)) or "", "item:(%d+)"); |
||
132 | if id then |
||
133 | local _, _, _, _, itemType, subType = GetItemInfo(id); |
||
134 | return (itemType == L"Quiver" or false), (subType == L"Soul Bag" or false), (( itemType == L"Container" and not (subType == L"Bag" or subType == L"Soul Bag") ) or false) |
||
135 | end |
||
136 | end |
||
137 | |||
138 | function OneStorage:GetCharListByServerId() |
||
139 | local list = {} |
||
140 | for k, v in OneStorage.db.account do |
||
141 | for k2, v2 in v do |
||
142 | local _, _, name, server = string.find(k2, "(.+) of (.+)") |
||
143 | serverId = format("%s - %s", server, k) |
||
144 | |||
145 | if not list[serverId] then list[serverId] = {} end |
||
146 | table.insert(list[serverId], string.format("%s - %s", name, k2) ) |
||
147 | sort(list[serverId]) |
||
148 | end |
||
149 | end |
||
150 | return list |
||
151 | end |