vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --$Id: enhancedtrades.lua 2435 2006-06-07 04:26:29Z kaelten $ |
2 | |||
3 | local locals = KC_ET_LOCALS |
||
4 | |||
5 | local toLesserEssence = { |
||
6 | ["10939:0:0:0"] = "10938:0:0:0", |
||
7 | ["11082:0:0:0"] = "10998:0:0:0", |
||
8 | ["11135:0:0:0"] = "11134:0:0:0", |
||
9 | ["11175:0:0:0"] = "11174:0:0:0", |
||
10 | ["16203:0:0:0"] = "16202:0:0:0", |
||
11 | } |
||
12 | |||
13 | -- put in the id for a lesser and get the id for a greater |
||
14 | local toGreaterEssence= { |
||
15 | ["10938:0:0:0"] = "10939:0:0:0", |
||
16 | ["10998:0:0:0"] = "11082:0:0:0", |
||
17 | ["11134:0:0:0"] = "11135:0:0:0", |
||
18 | ["11174:0:0:0"] = "11175:0:0:0", |
||
19 | ["16202:0:0:0"] = "16203:0:0:0", |
||
20 | } |
||
21 | |||
22 | local buyables = { |
||
23 | -- alchemy |
||
24 | ["3371:0:0:0"] = 1, -- Empty Vial |
||
25 | ["3372:0:0:0"] = 1, -- Leaded Vial |
||
26 | ["8925:0:0:0"] = 1, -- Crystal Vial |
||
27 | |||
28 | -- tailoring (and leatherworking) |
||
29 | ["2320:0:0:0"] = 1, -- Coarse Thread |
||
30 | ["2321:0:0:0"] = 1, -- Fine Thread |
||
31 | ["4291:0:0:0"] = 1, -- Silken Thread |
||
32 | ["8343:0:0:0"] = 1, -- Heavy Silken Thread |
||
33 | ["14341:0:0:0"] = 1, -- Rune Thread |
||
34 | |||
35 | ["2324:0:0:0"] = 1, -- Bleach |
||
36 | ["2325:0:0:0"] = 1, -- Black Dye |
||
37 | ["6260:0:0:0"] = 1, -- Blue Dye |
||
38 | ["2605:0:0:0"] = 1, -- Green Dye |
||
39 | ["4342:0:0:0"] = 1, -- Purple Dye |
||
40 | ["2604:0:0:0"] = 1, -- Red Dye |
||
41 | ["4341:0:0:0"] = 1, -- Yellow Dye |
||
42 | ["4340:0:0:0"] = 1, -- Gray Dye |
||
43 | ["6261:0:0:0"] = 1, -- Orange Dye |
||
44 | ["10290:0:0:0"] = 1, -- Pink Dye |
||
45 | |||
46 | ["4289:0:0:0"] = 1, -- Salt |
||
47 | |||
48 | -- mining |
||
49 | ["3857:0:0:0"] = 1, -- Coal |
||
50 | |||
51 | -- enchanting |
||
52 | ["6217:0:0:0"] = 1, -- Copper Rod |
||
53 | ["17034:0:0:0"] = 1, -- Maple Seed |
||
54 | ["4470:0:0:0"] = 1, -- Simple Wood |
||
55 | ["11291:0:0:0"] = 1, -- Star Wood |
||
56 | |||
57 | -- poison |
||
58 | ["2928:0:0:0"] = 1, -- Dust of Decay |
||
59 | ["3777:0:0:0"] = 1, -- Lethargy Root |
||
60 | ["2930:0:0:0"] = 1, -- Essence of Pain |
||
61 | ["8923:0:0:0"] = 1, -- Essence of Agony |
||
62 | ["5173:0:0:0"] = 1, -- Deathweed |
||
63 | ["8924:0:0:0"] = 1, -- Dust of Deterioration |
||
64 | |||
65 | -- cooking |
||
66 | ["2692:0:0:0"] = 1, -- Hot Spices |
||
67 | ["2678:0:0:0"] = 1, -- Mild Spices |
||
68 | ["3713:0:0:0"] = 1, -- Soothing Spices |
||
69 | ["2665:0:0:0"] = 1, -- Stormwind Seasoning Herbs |
||
70 | |||
71 | ["159:0:0:0"] = 1, -- Refreshing Spring Water |
||
72 | ["1179:0:0:0"] = 1, -- Ice Cold Milk |
||
73 | ["2596:0:0:0"] = 1, -- Skin of Dwarven Stout |
||
74 | ["2894:0:0:0"] = 1, -- Rhapsody Malt |
||
75 | ["4536:0:0:0"] = 1, -- Shiny Red Apple |
||
76 | |||
77 | -- blacksmithing (and engineering) |
||
78 | ["3466:0:0:0"] = 1, -- Strong Flux |
||
79 | ["2880:0:0:0"] = 1, -- Weak Flux |
||
80 | |||
81 | -- engineering (some items included above) |
||
82 | ["4400:0:0:0"] = 1, -- Heavy Stock |
||
83 | ["4399:0:0:0"] = 1, -- Wooden Stock |
||
84 | |||
85 | ["10647:0:0:0"] = 1, -- Engineer's Ink |
||
86 | ["10648:0:0:0"] = 1, -- Blank Parchment |
||
87 | |||
88 | -- fishing |
||
89 | ["6530:0:0:0"] = 1, -- Nightcrawlers |
||
90 | } |
||
91 | |||
92 | KC_EnhancedTrades = KC_ItemsModule:new({ |
||
93 | type = "trades", |
||
94 | name = locals.name, |
||
95 | desc = locals.description, |
||
96 | cmdOptions = locals.chat, |
||
97 | dependencies = {"common", "bank", "inventory"}, |
||
98 | compost = CompostLib:GetInstance("compost-1"), |
||
99 | sebags = SpecialEventsEmbed:GetInstance("Bags 1"), |
||
100 | sebank = SpecialEventsEmbed:GetInstance("Bank 1"), |
||
101 | }) |
||
102 | |||
103 | KC_Items:Register(KC_EnhancedTrades) |
||
104 | |||
105 | function KC_EnhancedTrades:Enable() |
||
106 | self:RegisterEvent("CRAFT_SHOW") |
||
107 | self:RegisterEvent("TRADE_SKILL_SHOW") |
||
108 | self:RegisterEvent("CRAFT_CLOSE") |
||
109 | self:RegisterEvent("TRADE_SKILL_CLOSE") |
||
110 | |||
111 | if (not self:GetOpt({"trades", "options"}, "installed")) then |
||
112 | self:SetOpt({"trades", "options"}, 1, true) |
||
113 | self:SetOpt({"trades", "options"}, 2, true) |
||
114 | self:SetOpt({"trades", "options"}, 3, true) |
||
115 | self:SetOpt({"trades", "options"}, 4, true) |
||
116 | self:SetOpt({"trades", "options"}, 5, true) |
||
117 | self:SetOpt({"trades", "options"}, 6, false) |
||
118 | self:SetOpt({"trades", "options"}, "installed", true) |
||
119 | end |
||
120 | |||
121 | self:BuildLegend() |
||
122 | end |
||
123 | |||
124 | function KC_EnhancedTrades:TRADE_SKILL_SHOW() |
||
125 | if (not self.Hooks or not self.Hooks["TradeSkillFrame_Update"]) then |
||
126 | self:Hook("TradeSkillFrame_SetSelection" , function (id) self:SetSelection(id) end) |
||
127 | self:Hook("TradeSkillFrame_Update", function () self:Update() end) |
||
128 | self.sebags:RegisterEvent(self, "SPECIAL_BAGSLOT_UPDATE", "BagUpdate") |
||
129 | self.sebank:RegisterEvent(self, "SPECIAL_BANKBAGSLOT_UPDATE", "BagUpdate") |
||
130 | self:RegisterEvent("KCI_BANK_DATA_UPDATE", "BankDataUpdate") |
||
131 | end |
||
132 | |||
133 | self.tsf.frame:SetParents(); |
||
134 | self.tsf.frame:Initialize(self, self.tsf.config) |
||
135 | |||
136 | if (self.opt.frame.initialized) then |
||
137 | self.opt.frame:UpdateAnchor() |
||
138 | end |
||
139 | |||
140 | self:Update() |
||
141 | end |
||
142 | |||
143 | function KC_EnhancedTrades:CRAFT_SHOW() |
||
144 | |||
145 | if (not self.Hooks or not self.Hooks["CraftFrame_Update"]) then |
||
146 | self:Hook("CraftFrame_SetSelection" , function (id) self:SetSelection(id, true) end) |
||
147 | self:Hook("CraftFrame_Update", function () self:Update(true) end) |
||
148 | self.sebags:RegisterEvent(self, "SPECIAL_BAGSLOT_UPDATE", "BagUpdate") |
||
149 | self.sebank:RegisterEvent(self, "SPECIAL_BANKBAGSLOT_UPDATE", "BagUpdate") |
||
150 | self:RegisterEvent("KCI_BANK_DATA_UPDATE", "BankDataUpdate") |
||
151 | end |
||
152 | |||
153 | self.cf.frame:SetParents(); |
||
154 | self.cf.frame:Initialize(self, self.cf.config) |
||
155 | |||
156 | if (self.opt.frame.initialized) then |
||
157 | self.opt.frame:UpdateAnchor() |
||
158 | end |
||
159 | |||
160 | self:Update(true) |
||
161 | end |
||
162 | |||
163 | function KC_EnhancedTrades:TRADE_SKILL_CLOSE() |
||
164 | if (self.opt.frame.initialized) then |
||
165 | self.opt.frame:UpdateAnchor() |
||
166 | end |
||
167 | end |
||
168 | |||
169 | function KC_EnhancedTrades:CRAFT_CLOSE() |
||
170 | if (self.opt.frame.initialized) then |
||
171 | self.opt.frame:UpdateAnchor() |
||
172 | end |
||
173 | end |
||
174 | |||
175 | function KC_EnhancedTrades:BankDataUpdate() |
||
176 | if (self.Hooks["TradeSkillFrame_SetSelection"]) then |
||
177 | self:SetSelection(self.tsfid) |
||
178 | end |
||
179 | |||
180 | if (self.Hooks["CraftFrame_SetSelection"]) then |
||
181 | self:SetSelection(self.cfid, true) |
||
182 | end |
||
183 | end |
||
184 | |||
185 | function KC_EnhancedTrades:BagUpdate(bag, slot, itemlink, stack, oldlink) |
||
186 | if ((not itemlink and not oldlink)) then |
||
187 | return |
||
188 | end |
||
189 | |||
190 | self:ClearCacheItem(itemlink) |
||
191 | self:ClearCacheItem(oldlink) |
||
192 | |||
193 | end |
||
194 | |||
195 | function KC_EnhancedTrades:ClearCacheItem(link) |
||
196 | if (not link) then return end |
||
197 | local code = self.common:GetCode(link, true) |
||
198 | |||
199 | if (self.cross[code]) then |
||
200 | for k,v in self.cross[code] do |
||
201 | self.cache[k] = nil |
||
202 | end |
||
203 | |||
204 | if (self.Hooks["TradeSkillFrame_Update"]) then |
||
205 | self:Update() |
||
206 | getglobal("TradeSkillFrameTitleText"):SetText(self.legend) |
||
207 | end |
||
208 | |||
209 | if (self.Hooks["CraftFrame_Update"]) then |
||
210 | self:Update(true) |
||
211 | getglobal("CraftFrameTitleText"):SetText(self.legend) |
||
212 | end |
||
213 | end |
||
214 | end |
||
215 | |||
216 | function KC_EnhancedTrades:Update(craft) |
||
217 | |||
218 | self.Hooks[craft and "CraftFrame_Update" or "TradeSkillFrame_Update"].orig() |
||
219 | |||
220 | if (self:GetOpt({"trades", "options"}, 1)) then |
||
221 | local skillname = craft and GetCraftDisplaySkillLine() or GetTradeSkillLine() |
||
222 | getglobal(craft and "CraftFrameTitleText" or "TradeSkillFrameTitleText"):SetText(format("%s %s", skillname, self.legend)) |
||
223 | end |
||
224 | |||
225 | if (craft and not CraftRankFrame:IsVisible()) then |
||
226 | return |
||
227 | end |
||
228 | |||
229 | if (not self.cache) then |
||
230 | self.cache = {} |
||
231 | end |
||
232 | |||
233 | for i=1, (craft and CRAFTS_DISPLAYED or TRADE_SKILLS_DISPLAYED) do |
||
234 | local button = getglobal((craft and "Craft" or "TradeSkillSkill")..i) |
||
235 | local skill = button:GetID() |
||
236 | |||
237 | local skillName, skillType |
||
238 | |||
239 | if (craft) then |
||
240 | skillName, _, skillType = GetCraftInfo(skill) |
||
241 | else |
||
242 | skillName, skillType = GetTradeSkillInfo(skill) |
||
243 | end |
||
244 | |||
245 | if (not skillName) then return end |
||
246 | |||
247 | if (not self.cache[skillName] and skillType ~= "header") then |
||
248 | self:BuildData(skill, skillName, craft) |
||
249 | end |
||
250 | |||
251 | if (skillType ~= "header") then |
||
252 | button:SetText(format(" %s [%s]", skillName or "", self.cache[skillName] or "")) |
||
253 | end |
||
254 | end |
||
255 | end |
||
256 | |||
257 | function KC_EnhancedTrades:SetSelection(id, craft) |
||
258 | if (craft) then self.cfid = id else self.tsfid = id end |
||
259 | self.Hooks[craft and "CraftFrame_SetSelection" or "TradeSkillFrame_SetSelection"].orig(id) |
||
260 | |||
261 | local skillName, skillType |
||
262 | |||
263 | if (craft) then |
||
264 | skillName, _, skillType = GetCraftInfo(id) |
||
265 | else |
||
266 | skillName, skillType = GetTradeSkillInfo(id) |
||
267 | end |
||
268 | |||
269 | if (skillType == "header") then |
||
270 | return |
||
271 | end |
||
272 | |||
273 | for i=1, (craft and GetCraftNumReagents(id) or GetTradeSkillNumReagents(id)) do |
||
274 | local reagentName = craft and GetCraftReagentInfo(id, i) or GetTradeSkillReagentInfo(id, i) |
||
275 | if (not reagentName) then break end |
||
276 | |||
277 | local code = self.common:GetCode((craft and GetCraftReagentItemLink(id, i) or GetTradeSkillReagentItemLink(id,i)), true) |
||
278 | local count = self.app.bank:Count(code) |
||
279 | |||
280 | local text = format(count > 0 and "%s [%s] %s" or "%s %s", reagentName, count > 0 and count or (buyables[code] and locals.buyable or ""), buyables[code] and locals.buyable or "") |
||
281 | |||
282 | getglobal(format((craft and "CraftReagent%sName" or "TradeSkillReagent%sName"),i)):SetText(text) |
||
283 | end |
||
284 | |||
285 | end |
||
286 | |||
287 | function KC_EnhancedTrades:BuildData(skill, skillName, craft) |
||
288 | if (not self.cross) then |
||
289 | self.cross = {} |
||
290 | end |
||
291 | |||
292 | local i = self.compost:GetTable() |
||
293 | local iv = self.compost:GetTable() |
||
294 | local ib = self.compost:GetTable() |
||
295 | local ivb = self.compost:GetTable() |
||
296 | local ivba = self.compost:GetTable() |
||
297 | |||
298 | for reag = 1, (craft and GetCraftNumReagents(skill) or GetTradeSkillNumReagents(skill)) do |
||
299 | local code = self.common:GetCode((craft and GetCraftReagentItemLink(skill, reag) or GetTradeSkillReagentItemLink(skill,reag)), true) |
||
300 | |||
301 | if (not code) then |
||
302 | break |
||
303 | end |
||
304 | |||
305 | if (not self.cross[code]) then |
||
306 | self.cross[code] = {} |
||
307 | end |
||
308 | |||
309 | if (not self.cross[code][skillName]) then |
||
310 | self.cross[code][skillName] = 1 |
||
311 | end |
||
312 | |||
313 | local qty, icount |
||
314 | |||
315 | if (craft) then |
||
316 | _, _, qty, icount = GetCraftReagentInfo(skill, reag) |
||
317 | else |
||
318 | _, _, qty, icount = GetTradeSkillReagentInfo(skill, reag) |
||
319 | end |
||
320 | |||
321 | |||
322 | local bcount = self.app.bank:Count(code) |
||
323 | local acount = 0 |
||
324 | |||
325 | if (self:GetOpt({"trades", "options"}, 6)) then |
||
326 | acount = self:AltCount(code) |
||
327 | end |
||
328 | |||
329 | tinsert(i, floor(icount/qty)) |
||
330 | tinsert(ib, floor((icount + bcount)/qty)) |
||
331 | |||
332 | if (not buyables[code]) then |
||
333 | tinsert(iv, floor(icount/qty)) |
||
334 | tinsert(ivb, floor((icount + bcount)/qty)) |
||
335 | tinsert(ivba, floor((icount + bcount + acount)/qty)) |
||
336 | end |
||
337 | end |
||
338 | |||
339 | local num = function(array) |
||
340 | sort(array) |
||
341 | return math.min(unpack(array) or 0) |
||
342 | end |
||
343 | |||
344 | numI = num(i) |
||
345 | numIv = num(iv) |
||
346 | numIb = num(ib) |
||
347 | numIvb = num(ivb) |
||
348 | numIvba = num(ivba) |
||
349 | |||
350 | if (self:GetOpt({"trades", "options"}, 2) and numI == numIv and numI == numIb and numI == numIvb and numI == numIvba) then |
||
351 | self.cache[skillName] = numI |
||
352 | else |
||
353 | local data = self.compost:GetTable() |
||
354 | local mask = "%s" |
||
355 | |||
356 | if (self:GetOpt({"trades", "options"}, 3)) then |
||
357 | mask = mask .. "/%s" |
||
358 | tinsert(data, numIv) |
||
359 | end |
||
360 | |||
361 | if (self:GetOpt({"trades", "options"}, 4)) then |
||
362 | mask = mask .. "/%s" |
||
363 | tinsert(data, numIb) |
||
364 | end |
||
365 | |||
366 | if (self:GetOpt({"trades", "options"}, 5)) then |
||
367 | mask = mask .. "/%s" |
||
368 | tinsert(data, numIvb) |
||
369 | end |
||
370 | |||
371 | if (self:GetOpt({"trades", "options"}, 6)) then |
||
372 | mask = mask .. "/%s" |
||
373 | tinsert(data, numIvba) |
||
374 | end |
||
375 | |||
376 | self.cache[skillName] = format(mask, numI, unpack(data)) |
||
377 | |||
378 | self.compost:Reclaim(data) |
||
379 | end |
||
380 | |||
381 | |||
382 | self.compost:Reclaim(i) |
||
383 | self.compost:Reclaim(iv) |
||
384 | self.compost:Reclaim(ib) |
||
385 | self.compost:Reclaim(ivb) |
||
386 | self.compost:Reclaim(ivba) |
||
387 | end |
||
388 | |||
389 | function KC_EnhancedTrades:AltCount(code) |
||
390 | if (not self.peeps) then |
||
391 | self.peeps = self.common:GetCharList(ace.char.realm, ace.char.faction) |
||
392 | self.peeps[ace.char.id] = nil |
||
393 | end |
||
394 | |||
395 | local total = 0 |
||
396 | |||
397 | for k,v in self.peeps do |
||
398 | total = total + self.app.bank:Count(code, v.faction, k) + self.app.inventory:Count(code, v.faction, k) |
||
399 | end |
||
400 | |||
401 | return total |
||
402 | end |
||
403 | |||
404 | function KC_EnhancedTrades:BuildLegend() |
||
405 | local legend = "|cff00aa00i" |
||
406 | |||
407 | if (self:GetOpt({"trades", "options"}, 3)) then |
||
408 | legend = legend .. "/i+v" |
||
409 | end |
||
410 | |||
411 | if (self:GetOpt({"trades", "options"}, 4)) then |
||
412 | legend = legend .. "/i+b" |
||
413 | end |
||
414 | |||
415 | if (self:GetOpt({"trades", "options"}, 5)) then |
||
416 | legend = legend .. "/i+v+b" |
||
417 | end |
||
418 | |||
419 | if (self:GetOpt({"trades", "options"}, 6)) then |
||
420 | legend = legend .. "/ivb+alts" |
||
421 | end |
||
422 | |||
423 | self.legend = legend |
||
424 | end |