vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -- LOAD LOCALISATION |
2 | if (GetLocale()=="deDE") then |
||
3 | tradeDispenser_GetGerman() |
||
4 | elseif (GetLocale()=="zhCN") then |
||
5 | tradeDispenser_GetChinese() |
||
6 | elseif (GetLocale()=="frFR") then |
||
7 | tradeDispenser_GetFrench() |
||
8 | else tradeDispenser_GetEnglish() |
||
9 | end |
||
10 | |||
11 | |||
12 | function tradeDispenserVerbose(level, text) |
||
13 | local temp=0; |
||
14 | if (tD_GlobalDatas.Verbose) then temp = tD_GlobalDatas.Verbose end |
||
15 | if (temp>=level) then |
||
16 | DEFAULT_CHAT_FRAME:AddMessage(tradeDispenser_ProgName..": "..text) |
||
17 | end |
||
18 | end |
||
19 | |||
20 | |||
21 | function tradeDispenserMessage(channel, message) |
||
22 | channel = strupper(channel) |
||
23 | if (channel=="WHISPER") then |
||
24 | SendChatMessage(message, "WHISPER", tD_Loc[UnitFactionGroup("player")], tD_Temp.Target.Name) |
||
25 | elseif (channel=="RAID" or channel=="PARTY" or channel=="GUILD" or channel=="YELL" or channel=="SAY") then |
||
26 | SendChatMessage(message, channel); |
||
27 | else |
||
28 | tradeDispenserVerbose(0,"Error: cannot use channel '"..channel.."'") |
||
29 | end |
||
30 | end |
||
31 | |||
32 | |||
33 | function tradeDispenserPlaySound(frame) |
||
34 | if (frame:GetFrameType()=="Button") then |
||
35 | PlaySound("GAMEGENERICBUTTONPRESS") |
||
36 | elseif (frame:GetFrameType()=="CheckButton") then |
||
37 | if ( frame:GetChecked() ) then |
||
38 | PlaySound("igMainMenuOptionCheckBoxOn"); |
||
39 | else |
||
40 | PlaySound("igMainMenuOptionCheckBoxOff"); |
||
41 | end |
||
42 | end |
||
43 | end |
||
44 | |||
45 | |||
46 | |||
47 | function tradeDispenserDrawTooltip(textfield) |
||
48 | local i=0; |
||
49 | GameTooltip:AddLine("|cFFFFFFFF"..textfield[i]); |
||
50 | for i=1,table.getn(textfield) do |
||
51 | GameTooltip:AddLine(textfield[i]); |
||
52 | end |
||
53 | GameTooltip:Show(); |
||
54 | end |
||
55 | |||
56 | function tradeDispenserSetTooltipPosition(frame,mx,my) |
||
57 | local lx,ly = frame:GetCenter(); |
||
58 | local px, py = UIParent:GetCenter(); |
||
59 | local pos, korrX, korrY = "ANCHOR_",1,1; |
||
60 | if (ly>py) then pos=pos.."BOTTOM"; else korrY=-1; end |
||
61 | if (lx>px) then pos=pos.."LEFT"; korrX=-1; else pos=pos.."RIGHT"; end |
||
62 | GameTooltip:SetOwner(frame,pos,mx*korrX,my*korrY); |
||
63 | end |
||
64 | |||
65 | |||
66 | function tradeDispenser_Print(textfield) |
||
67 | table.foreach(textfield, function(k,v) DEFAULT_CHAT_FRAME:AddMessage(v) end) |
||
68 | end |
||
69 | |||
70 | -- Hooked Function to check, if the PLAYER or the CLIENT has initiated the trade! |
||
71 | -- this is triggered BEFORE the event TradeShow gets fired |
||
72 | local OldInitiateTrade = InitiateTrade; |
||
73 | function InitiateTrade(UnitID) |
||
74 | tradeDispenserVerbose(1,"Trade Started - triggered by hooked Function: InitiateTrade"); |
||
75 | tD_Temp.InitiateTrade=true; |
||
76 | OldInitiateTrade(UnitID) |
||
77 | end |
||
78 | |||
79 | local OldBeginTrade = BeginTrade; |
||
80 | function BeginTrade() |
||
81 | tradeDispenserVerbose(1,"Trade Started - triggered by hooked Function: BeginTrade"); |
||
82 | tD_Temp.InitiateTrade=true; |
||
83 | OldBeginTrade() |
||
84 | end |
||
85 | |||
86 | |||
87 | function tradeDispenserUpdateMoney() |
||
88 | tD_CharDatas.profile[tD_CharDatas.ActualRack][tD_CharDatas.ActualProfile].Charge = MoneyInputFrame_GetCopper(tradeDispenserMoneyFrame) |
||
89 | end |
||
90 | |||
91 | |||
92 | function tradeDispenserSplitMoney(money) |
||
93 | local gold = floor(money / (COPPER_PER_GOLD)) |
||
94 | local silver = floor((money - (gold * COPPER_PER_GOLD)) / COPPER_PER_SILVER) |
||
95 | local copper = mod(money, COPPER_PER_SILVER) |
||
96 | return gold, silver, copper |
||
97 | end |
||
98 | |||
99 | |||
100 | |||
101 | function tradeDispenserCompile(slotID) |
||
102 | if (tD_Temp.Slot[slotID].itemLink == nil) then |
||
103 | return "deadlink",nil |
||
104 | end |
||
105 | |||
106 | local configItemLink = tD_Temp.Slot[slotID].itemLink |
||
107 | local configItemCount = tD_Temp.Slot[slotID].itemCount |
||
108 | |||
109 | if (configItemLink) then tradeDispenserVerbose(1,"tradeDispenserCompile: looking for: "..configItemLink) end |
||
110 | tradeDispenserVerbose(2,"tradeDispenserCompile: first round") |
||
111 | |||
112 | -- first we look for complete stacks |
||
113 | for cID=4,0,-1 do |
||
114 | tradeDispenserVerbose(3,"tradeDispenserCompile: "..GetContainerNumSlots(cID).." slots in bag "..cID) |
||
115 | for sID=1,GetContainerNumSlots(cID) do |
||
116 | local itemLink = GetContainerItemLink(cID, sID) |
||
117 | local _, itemCount, itemLocked = GetContainerItemInfo(cID, sID) |
||
118 | |||
119 | if (tradeDispenserLink(itemLink) == tradeDispenserLink(configItemLink) and not itemLocked) then |
||
120 | if (itemCount) then tradeDispenserVerbose(2,"tradeDispenserCompile: found item: itemCount: "..itemCount) end |
||
121 | if (itemCount == configItemCount) then |
||
122 | tradeDispenserVerbose(3,"tradeDispenserCompile: found in first round in "..cID.."/"..sID) |
||
123 | return cID, sID |
||
124 | end |
||
125 | end |
||
126 | end |
||
127 | end |
||
128 | |||
129 | -- there is no complete stack, we have to compile one |
||
130 | -- first we have to find a free bag slot |
||
131 | local _cID, _sID = tradeDispenserFreeSlot() |
||
132 | if (_cID == nil) then |
||
133 | tradeDispenserVerbose(2,"tradeDispenserCompile: no free slots") |
||
134 | return nil, nil |
||
135 | end |
||
136 | |||
137 | tradeDispenserVerbose(2,"tradeDispenserCompile: second round, tmp slot is :".._cID.."/".._sID) |
||
138 | |||
139 | local stackCount = 0 |
||
140 | local stackFound = false |
||
141 | for cID=4,0,-1 do |
||
142 | for sID=1,GetContainerNumSlots(cID) do |
||
143 | if (cID ~= _cID or sID ~= _sID) then |
||
144 | local itemLink = GetContainerItemLink(cID, sID) |
||
145 | local _, itemCount, itemLocked = GetContainerItemInfo(cID, sID) |
||
146 | |||
147 | if (tradeDispenserLink(itemLink) == tradeDispenserLink(configItemLink) and not itemLocked) then |
||
148 | stackFound = true |
||
149 | local missingCount = configItemCount - stackCount |
||
150 | local splitCount = math.min(missingCount, itemCount) |
||
151 | tradeDispenserVerbose(3,"tradeDispenserCompile: second round found item: missingCount: "..missingCount..", itemCount: "..itemCount) |
||
152 | SplitContainerItem(cID, sID, splitCount) |
||
153 | PickupContainerItem(_cID, _sID) |
||
154 | |||
155 | stackCount = stackCount + splitCount |
||
156 | tradeDispenserVerbose(3,"tradeDispenserCompile: added "..splitCount.." items to temp stack, now we have "..stackCount) |
||
157 | |||
158 | -- if we have compiled the stack... return |
||
159 | if (stackCount == configItemCount) then |
||
160 | tradeDispenserVerbose(2,"tradeDispenserCompile: finished second round") |
||
161 | return _cID, _sID |
||
162 | end |
||
163 | end |
||
164 | end |
||
165 | end |
||
166 | end |
||
167 | |||
168 | if (stackFound) then |
||
169 | tradeDispenserVerbose(1,"tradeDispenserCompile: returning temp stack") |
||
170 | return _cID, _sID |
||
171 | else |
||
172 | tradeDispenserVerbose(1,"tradeDispenserCompile: nothing found") |
||
173 | return nil |
||
174 | end |
||
175 | end |
||
176 | |||
177 | |||
178 | |||
179 | |||
180 | function tradeDispenserTradeControlChecker() |
||
181 | local tradeDispenserClient = {}; -- used for saving the stats (guild, party, raid) of the Client; |
||
182 | local targetClass, targetEnglishClass = UnitClass("NPC"); |
||
183 | tradeDispenserClient = { |
||
184 | ["Class"] = targetEnglishClass, |
||
185 | ["Level"] = UnitLevel("NPC"), |
||
186 | ["Name"] = UnitName("NPC") |
||
187 | } |
||
188 | if (UnitInRaid("player")) then |
||
189 | if (UnitInRaid("NPC")) then tradeDispenserClient.Raid = "IsMember"; |
||
190 | else tradeDispenserClient.Raid = "NotMember"; end |
||
191 | else |
||
192 | if (UnitInParty("player")) then |
||
193 | if (UnitInParty("NPC")) then tradeDispenserClient.Raid = "IsMember"; |
||
194 | else tradeDispenserClient.Raid = "NotMember"; end |
||
195 | else tradeDispenserClient.Raid = "SinglePlayer"; end |
||
196 | end |
||
197 | |||
198 | local guildName, guildRankName, guildRankIndex = GetGuildInfo("player"); |
||
199 | local guildName2, guildRankName2, guildRankIndex2 = GetGuildInfo("NPC"); |
||
200 | |||
201 | if (guildName==guildName2) then |
||
202 | tradeDispenserClient.Guild = "IsMember"; |
||
203 | else tradeDispenserClient.Guild = "NotMember"; end |
||
204 | |||
205 | if (tradeDispenserClient.Raid=="IsMember" or tradeDispenserClient.Guild=="IsMember") then tD_Temp.isInsider=true; end |
||
206 | |||
207 | if (tD_CharDatas.ClientInfos) then |
||
208 | local guildName3 = ""; |
||
209 | if (guildName2~=nil) then guildName3 = "<"..guildName2.."> "; end |
||
210 | if (not targetClass) then targetClass="Unknown" end |
||
211 | DEFAULT_CHAT_FRAME:AddMessage(tD_Loc.Opposite.." "..tradeDispenserClient.Name.." "..guildName3.." - "..targetClass.." Level "..tradeDispenserClient.Level,1,1,0); |
||
212 | else |
||
213 | tradeDispenserVerbose(1,"Clients Name = "..tradeDispenserClient.Name); |
||
214 | tradeDispenserVerbose(1,"Clients Level = "..tradeDispenserClient.Level); |
||
215 | tradeDispenserVerbose(1,"Clients Class = "..tradeDispenserClient.Class); |
||
216 | tradeDispenserVerbose(1,"Group/Party = "..tradeDispenserClient.Raid); |
||
217 | tradeDispenserVerbose(1,"your Guild = "..tradeDispenserClient.Guild); |
||
218 | end |
||
219 | |||
220 | if (tD_CharDatas.Raid and tradeDispenserClient.Raid=="NotMember") then |
||
221 | if (tD_CharDatas.Guild) then |
||
222 | if (tradeDispenserClient.Guild=="NotMember") then |
||
223 | tradeDispenserMessage("WHISPER",tD_GlobalDatas.whisper[8]) |
||
224 | return false; |
||
225 | end |
||
226 | else |
||
227 | tradeDispenserMessage("WHISPER",tD_GlobalDatas.whisper[8]) |
||
228 | return false; |
||
229 | end |
||
230 | end |
||
231 | |||
232 | if (tD_CharDatas.LevelCheck and tradeDispenserClient.Level<tD_CharDatas.LevelValue) then |
||
233 | tradeDispenserMessage("WHISPER",tD_GlobalDatas.whisper[6]) |
||
234 | return false; |
||
235 | end |
||
236 | |||
237 | |||
238 | local trades=tradeDispenserClientTrades(tradeDispenserClient.Name); |
||
239 | if (trades>=1 and trades+1>tD_CharDatas.RegisterValue) then |
||
240 | tradeDispenserMessage("WHISPER",tD_GlobalDatas.whisper[9]) |
||
241 | return false |
||
242 | end |
||
243 | |||
244 | if (tD_CharDatas.BanlistActive and tD_GlobalDatas.Bannlist and table.getn(tD_GlobalDatas.Bannlist)>0) then |
||
245 | local found=false; |
||
246 | table.foreach(tD_GlobalDatas.Bannlist, function(k,v) if (strlower(v)==strlower(tradeDispenserClient.Name)) then found=true; end; end) |
||
247 | if (found) then |
||
248 | tradeDispenserMessage("WHISPER",tD_GlobalDatas.whisper[10]) |
||
249 | return false; |
||
250 | end |
||
251 | end |
||
252 | |||
253 | return true; |
||
254 | end |
||
255 | |||
256 | |||
257 | |||
258 | function tradeDispenserClientTrades(name) |
||
259 | if (not tD_CharDatas.RegisterCheck) then return 0 end |
||
260 | local i=0 |
||
261 | local index=nil; |
||
262 | while (tD_Temp.RegUser[i]~=nil) do |
||
263 | if (tD_Temp.RegUser[i].name == name) then |
||
264 | tradeDispenserVerbose(2,"Registred Player found at index "..i.." is: "..tD_Temp.RegUser[i].name); |
||
265 | index=i; |
||
266 | end |
||
267 | i=i+1; |
||
268 | end |
||
269 | |||
270 | if (index==nil) then |
||
271 | tradeDispenserVerbose(1,name.." not registrated!"); |
||
272 | return 0 |
||
273 | else |
||
274 | tradeDispenserVerbose(1,name.." found with "..tD_Temp.RegUser[index].trades.." trades"); |
||
275 | return tD_Temp.RegUser[index].trades |
||
276 | end |
||
277 | end |
||
278 | |||
279 | |||
280 | |||
281 | |||
282 | function tradeDispenserAccept() |
||
283 | tradeDispenserVerbose(1,"tradeDispenserAccept: Triggered") |
||
284 | if (tD_Temp.tradeCharge and tD_Temp.tradeCharge > 0) then |
||
285 | local recipientMoney = GetTargetTradeMoney() |
||
286 | if (recipientMoney >= tD_Temp.tradeCharge) then |
||
287 | tD_Temp.tradeState = nil |
||
288 | AcceptTrade() |
||
289 | |||
290 | if (tD_Temp.tradeData) then |
||
291 | tD_Temp.tradeData = nil |
||
292 | tD_Temp.isEnabled = false |
||
293 | tradeDispenserUpdate() |
||
294 | tradeDispenser_OSD_buttons() |
||
295 | end |
||
296 | else |
||
297 | local gold, silver, copper = tradeDispenserSplitMoney(tD_Temp.tradeCharge) |
||
298 | tradeDispenserMessage("WHISPER",tD_GlobalDatas.whisper[5].." "..gold.."g "..silver.."s "..copper.."c") |
||
299 | end |
||
300 | else |
||
301 | tD_Temp.tradeState = nil |
||
302 | AcceptTrade() |
||
303 | |||
304 | if (tD_Temp.tradeData) then |
||
305 | tD_Temp.tradeData = nil |
||
306 | tD_Temp.isEnabled = false |
||
307 | tradeDispenserUpdate() |
||
308 | tradeDispenser_OSD_buttons() |
||
309 | end |
||
310 | end |
||
311 | end |
||
312 | |||
313 | |||
314 | function tradeDispenserFreeSlot() |
||
315 | for cID=0,4 do |
||
316 | for sID=1,GetContainerNumSlots(cID) do |
||
317 | local itemLink = GetContainerItemLink(cID, sID) |
||
318 | if (itemLink == nil) then |
||
319 | return cID, sID |
||
320 | end |
||
321 | end |
||
322 | end |
||
323 | return nil |
||
324 | end |
||
325 | |||
326 | function tradeDispenserLink(itemLink) |
||
327 | if (itemLink) then |
||
328 | local _, _, itemID, itemEnchant, randomProperty, uniqueID, itemName = string.find(itemLink, "|Hitem:(%d+):(%d+):(%d+):(%d+)|h[[]([^]]+)[]]|h") |
||
329 | return tonumber(itemID or 0), tonumber(randomProperty or 0), tonumber(itemEnchant or 0), tonumber(uniqueID or 0), itemName |
||
330 | else |
||
331 | return nil |
||
332 | end |
||
333 | end |
||
334 | |||
335 | |||
336 | |||
337 | function tradeDispenserCompileProfile() |
||
338 | if (not tD_Temp.Target.Name) then return false end |
||
339 | local actualID=1; |
||
340 | local i; |
||
341 | tD_Temp.tradeCharge = 0; |
||
342 | local getprofile = { |
||
343 | ["WARRIOR"] = { [1]=2, [2]=10}, |
||
344 | ["ROGUE"] = { [1]=3, [2]=10}, |
||
345 | ["HUNTER"] = { [1]=4, [2]=11}, |
||
346 | ["WARLOCK"] = { [1]=5, [2]=11}, |
||
347 | ["MAGE"] = { [1]=6, [2]=11}, |
||
348 | ["DRUID"] = { [1]=7, [2]=12}, |
||
349 | ["PRIEST"] = { [1]=8, [2]=12}, |
||
350 | ["PALADIN"] = { [1]=9, [2]=12}, |
||
351 | ["SHAMAN"] = { [1]=9, [2]=12} |
||
352 | }; |
||
353 | tD_Temp.Slot={ |
||
354 | [1]={}, [2]={}, [3]={}, [4]={}, [5]={}, [6]={} |
||
355 | }; |
||
356 | |||
357 | tD_Temp.Target.EnglishClass = strupper(tD_Temp.Target.EnglishClass); |
||
358 | tradeDispenserVerbose(1,"Compile the TradeProfiles: All Classes + "..tD_Temp.Target.EnglishClass.." + "..tD_Loc.profile[ getprofile[tD_Temp.Target.EnglishClass][2] ]); |
||
359 | |||
360 | tD_Temp.tradeCharge = tD_CharDatas.profile[tD_CharDatas.ActualRack][1].Charge; |
||
361 | for slotID=1,6 do |
||
362 | if (tD_CharDatas.profile[tD_CharDatas.ActualRack][1][slotID] and tD_CharDatas.profile[tD_CharDatas.ActualRack][1][slotID].itemName) then |
||
363 | tD_Temp.Slot[actualID] = tD_CharDatas.profile[tD_CharDatas.ActualRack][1][slotID]; |
||
364 | actualID=actualID+1; |
||
365 | end |
||
366 | end |
||
367 | |||
368 | local act=getprofile[tD_Temp.Target.EnglishClass][1]; |
||
369 | tradeDispenserVerbose(2, "looking in Profile "..act.." for items") |
||
370 | tD_Temp.tradeCharge = tD_Temp.tradeCharge + tD_CharDatas.profile[tD_CharDatas.ActualRack][act].Charge; |
||
371 | for slotID=1,6 do |
||
372 | if (actualID<=6) then |
||
373 | local profile = tD_CharDatas.profile[tD_CharDatas.ActualRack][act][slotID] |
||
374 | if ( profile and profile.itemName) then |
||
375 | tD_Temp.Slot[actualID] = profile; |
||
376 | actualID=actualID+1; |
||
377 | end |
||
378 | end |
||
379 | end |
||
380 | |||
381 | local act=getprofile[tD_Temp.Target.EnglishClass][2]; |
||
382 | tradeDispenserVerbose(2, "looking in Profile "..act.." for items") |
||
383 | |||
384 | tD_Temp.tradeCharge = tD_Temp.tradeCharge + tD_CharDatas.profile[tD_CharDatas.ActualRack][act].Charge; |
||
385 | for slotID=1,6 do |
||
386 | if (actualID<=6) then |
||
387 | local profile = tD_CharDatas.profile[tD_CharDatas.ActualRack][act][slotID]; |
||
388 | if (profile and profile.itemName) then |
||
389 | tD_Temp.Slot[actualID] = profile; |
||
390 | actualID=actualID+1; |
||
391 | end |
||
392 | end |
||
393 | end |
||
394 | |||
395 | if (tD_CharDatas.Free4Guild and tD_Temp.isInsider) then tD_Temp.tradeCharge=0 end; |
||
396 | actualID=actualID-1; |
||
397 | tradeDispenserVerbose(1,"Found "..actualID.." items to trade"); |
||
398 | return actualID; |
||
399 | end |