vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Tradeskill support
3 Gives you quantities based upon your tradeskilling abilities.
4 $Id: InfTrades.lua 716 2006-02-09 15:25:17Z mentalpower $
5 Version 3.8.0 (Kangaroo)
6  
7 License:
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12  
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17  
18 You should have received a copy of the GNU General Public License
19 along with this program(see GLP.txt); if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 --]]
22  
23 local p = EnhancedTooltip.DebugPrint;
24  
25 local tsfHookOnUpdate, tsfHookSetSelection, scanTradeskillLink, tradeSkillText
26 local readFormula, getCounts, scanBank, scanBags, scanContainer, getPlayerName
27 local initTrades
28  
29 -- Hooked functions
30  
31 function tradeHook(type, selID)
32 p("Processing trade", trade, selID);
33 if (selID == nil) then
34 -- We are hooked into the tradeskill frame and it has been updated
35 for i=1, TRADE_SKILLS_DISPLAYED, 1 do
36 local button = getglobal("TradeSkillSkill"..i)
37 local skillIndex = button:GetID()
38 local skillName, skillType, numAvailable, isExpanded = GetTradeSkillInfo(skillIndex);
39 button:SetText(tradeSkillText(skillIndex, skillName))
40 scanTradeskillID(i, false)
41 end
42 else
43 scanTradeskillLink(selID, true)
44 end
45 end
46  
47 function bankHook()
48 p("Processing bank contents");
49 scanContainer(BANK_CONTAINER)
50 for bag = 5, 10 do
51 scanContainer(bag)
52 end
53 end
54  
55 function bagHook()
56 p("Processing bag contents");
57 for bag = 0, 4 do
58 scanContainer(bag)
59 end
60 end
61  
62 function initTrades()
63 Stubby.RegisterFunctionHook("EnhTooltip.TradeHook", 100, tradeHook);
64 Stubby.RegisterFunctionHook("EnhTooltip.BankHook", 100, bankHook);
65 Stubby.RegisterFunctionHook("EnhTooltip.BagHook", 100, bagHook);
66 Informant.InitTrades = function() end
67 end
68 Informant.InitTrades = initTrades
69  
70 -- Associated functions
71  
72 function scanTradeskillLink(id, setStrings)
73 -- We are hooked into the tradeskill frame and it has been updated
74 local skillName, skillType, numAvailable, isExpanded = GetTradeSkillInfo(id)
75 local skillLink = GetTradeSkillItemLink(id)
76 local skillID = EnhancedTooltip.baselinkFromLink(skillLink)
77  
78 if (setStrings) then
79 local totalSkillItems = getTotalCount(skillID)
80 if (totalSkillItems > 0) then
81 local invSkillItems = getInventoryCount(skillID)
82 TradeSkillSkillName:SetText(skillName.." ["..invSkillItems.."/"..totalSkillItems.."]")
83 else
84 TradeSkillSkillName:SetText(skillName)
85 end
86 end
87  
88 local formula = "";
89 local numReagents = GetTradeSkillNumReagents(id)
90 for i=1, numReagents, 1 do
91 local reagentName, reagentTexture, reagentCount, playerReagentCount = GetTradeSkillReagentInfo(id, i)
92 local reagentLink = GetTradeSkillReagentLink(id, i);
93 local reagentID = EnhancedTooltip.baselinkFromLink(reagentLink);
94 local totalReagents = getTotalCount(reagentName)
95 formula = formula..":"..reagentID.."x"..reagentCount
96 if (setStrings) then
97 getglobal("TradeSkillReagent"..i.."Name"):SetText(reagentName.." ["..totalReagents.."]")
98 end
99 end
100 Informant_Formulae[skillID] = formula;
101 end
102  
103  
104 function scanContainer(bag)
105 local texture, itemCount, itemLink
106 local itemID, randomProperty, enchantment, uniqueID, itemName
107 local containerItems = GetContainerNumSlots(bag)
108 if (containerItems) then
109 for containerItemNum = 1, containerItems do
110 itemLink = GetContainerItemLink(bag, containerItemNum)
111 if (itemLink) then
112 texture, itemCount = GetContainerItemInfo(bag, containerItemNum)
113 itemID, randomProperty, enchantment, uniqueID, itemName = EnhTooltip.BreakLink(itemLink)
114  
115 if ((bag == BANK_CONTAINER) or ((bag >= 5) and (bag <= 10))) then
116 end
117 end
118 end
119 end
120 end
121  
122  
123 -- Utility functions
124  
125 -- Get the current realm and player
126 local playerRealm = nil
127 local playerName = nil
128 function getPlayerName()
129 if (playerName == nil) then
130 playerRealm = GetCVar("realmName")
131 playerName = UnitName("player")
132 end
133 return playerRealm, playerName;
134 end
135  
136 -- Read (and extrapolate) a formula and work out how many we can make
137 function readFormula(itemKey)
138 local formula = Informant_Formulae[itemKey]
139 local bag, bank, other, make, vend, all
140 local tBag, tBank, tOther, tMake, tVend, tAll
141 for reagKey, reagCount in string.gfind(formula, ":(%d+)x(%d+)") do
142 local _,_, reagID = string.find(reagKey, "(\d+):");
143 bag, bank, other = getCounts(reagKey)
144 if (InformantFormula[reagKey]) then
145 local subMake = readFormula(reagKey)
146 make = subMake.all
147 end
148 vend = 0;
149 local reagData = Informant.getItem(reagID);
150 if (reagData.quantity > 0) then
151 vend = 9999;
152 end
153 all = math.max(9999, bag + bank + other + vend + make);
154  
155 tBag = math.min(tBag, math.floor(bag / reagCount))
156 tBank = math.min(tBank, math.floor(bank / reagCount))
157 tOther = math.min(tOther, math.floor(other / reagCount))
158 tMake = math.min(tMake, math.floor(make / reagCount))
159 tAll = math.min(tAll, math.floor(all / reagCount))
160 end
161  
162 return {
163 bag = tBag,
164 bank = tBank,
165 other = tOther,
166 make = tMake,
167 all = tAll,
168 }
169 end
170  
171 -- How many of these do I have?
172 function getCounts(itemID)
173 local curRealm, curPlayer = getPlayerName()
174 local invTotal = 0
175 local bankTotal = 0
176 local otherTotal = 0
177 if (InformantItems and InformatItems[curRealm]) then
178 for player, pData in Informant_Items[curRealm] do
179 local i,j, invCount, bankCount = string.find(pData, "(%d):(%d)");
180 if (player == curPlayer) then
181 invTotal = tonumber(invCount)
182 bankTotal = tonumber(bankCount)
183 else
184 otherTotal = tonumber(invCount) + tonumber(bankCount)
185 end
186 end
187 end
188 return invTotal, bankTotal, otherTotal;
189 end
190