vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | |
2 | function tradeDispenserOnLoad() |
||
3 | --math.randomseed(floor(GetTime())); -- initialize the randomizer |
||
4 | tradeDispenser:RegisterEvent("VARIABLES_LOADED") |
||
5 | tradeDispenser:RegisterEvent("TRADE_SHOW") -- used to activate the automated trade |
||
6 | tD_Temp.timeSlice = 0 |
||
7 | tD_Temp.broadcastSlice = 0 |
||
8 | tD_Temp.Target = { |
||
9 | ["Name"]=nil, |
||
10 | ["EnglishClass"]=nil, |
||
11 | ["Class"]=nil, |
||
12 | ["Level"]=nil, |
||
13 | }; |
||
14 | end |
||
15 | |||
16 | |||
17 | function tradeDispenser_Eventhandler() |
||
18 | if (tD_Temp.isEnabled) then |
||
19 | tradeDispenserVerbose(1,"Gonna activate some events"); |
||
20 | --tradeDispenser:RegisterEvent("TRADE_SHOW") -- used to activate the automated trade |
||
21 | tradeDispenser:RegisterEvent("TRADE_CLOSED") |
||
22 | tradeDispenser:RegisterEvent("TRADE_ACCEPT_UPDATE") -- used, if the opposite player changes the items -> re-accept |
||
23 | tradeDispenser:RegisterEvent("UI_ERROR_MESSAGE") |
||
24 | tradeDispenser:RegisterEvent("UI_INFO_MESSAGE") |
||
25 | tD_Temp.InitiateTrade=nil; |
||
26 | tD_Temp.Countdown=-1; |
||
27 | else |
||
28 | tradeDispenserVerbose(1,"Gonna deactivate some events"); |
||
29 | --tradeDispenser:UnregisterEvent("TRADE_SHOW") -- used to activate the automated trade |
||
30 | tradeDispenser:UnregisterEvent("TRADE_CLOSED") |
||
31 | tradeDispenser:UnregisterEvent("TRADE_ACCEPT_UPDATE") -- used, if the opposite player changes the items -> re-accept |
||
32 | tradeDispenser:UnregisterEvent("UI_ERROR_MESSAGE") |
||
33 | tradeDispenser:UnregisterEvent("UI_INFO_MESSAGE") |
||
34 | tradeDispenser:UnregisterEvent("PLAYER_TARGET_CHANGED") |
||
35 | end |
||
36 | tradeDispenserVerbose(2,"TRADE_SHOW, TRADE_CLOSED, TRADE_ACCEPT_UPDATE, UI_ERROR_MESSAGE, UI_INFO_MESSAGE"); |
||
37 | end |
||
38 | |||
39 | |||
40 | function tradeDispenserSetFaction() |
||
41 | --tradeDispenserVerbose(0,"Players Faction is: "..UnitFactionGroup("player")); |
||
42 | if (tradeDispenserProfileDDframe) then |
||
43 | tradeDispenserProfileDDframeSub9:SetText(tD_Loc.profile[UnitFactionGroup("player")]); |
||
44 | end |
||
45 | if (tD_CharDatas.ActualProfile==9) then |
||
46 | tradeDispenserProfileDDTitleLbL:SetText(tD_Loc.profile[UnitFactionGroup("player")]); |
||
47 | end |
||
48 | |||
49 | end |
||
50 | |||
51 | |||
52 | |||
53 | function tradeDispenserOnEvent(event) |
||
54 | if (event == "VARIABLES_LOADED") then |
||
55 | tradeDispenserVerbose(0,tD_Loc.logon.welcome); |
||
56 | tradeDispenser_OnVariablesLoaded() -- found in tradeDispenser_initialize |
||
57 | end |
||
58 | if (event == "PLAYER_TARGET_CHANGED") then |
||
59 | if (UnitIsPlayer("target") and UnitIsFriend("target", "player")) then |
||
60 | tradeDispenserBanlistName:SetText(UnitName("target")); |
||
61 | end |
||
62 | end |
||
63 | |||
64 | if (event=="TRADE_SHOW" and (tD_Temp.isEnabled or tD_CharDatas.ClientInfos) and WorldMapFrame:IsVisible()) then |
||
65 | ToggleWorldMap(); |
||
66 | tradeDispenserVerbose(1, " Closed the Map to avoid bugs. Sorry"); |
||
67 | end |
||
68 | |||
69 | if (event == "TRADE_SHOW" and (not tD_Temp.isEnabled) and tD_CharDatas.ClientInfos) then |
||
70 | local targetClass, targetEnglishClass = UnitClass("NPC"); |
||
71 | local guildName2, guildRankName2, guildRankIndex2 = GetGuildInfo("NPC"); |
||
72 | local guildName3 = ""; |
||
73 | if (guildName2~=nil) then guildName3 = "<"..guildName2.."> "; end |
||
74 | DEFAULT_CHAT_FRAME:AddMessage(tD_Loc.Opposite.." "..UnitName("NPC").." "..guildName3.." - "..targetClass.." Level "..UnitLevel("NPC"),1,1,0); |
||
75 | end |
||
76 | |||
77 | |||
78 | if (not tD_Temp.isEnabled) then |
||
79 | return |
||
80 | end |
||
81 | |||
82 | if ((event=="UI_ERROR_MESSAGE" or event=="UI_INFO_MESSAGE") and tD_Temp.Target.Name and arg1) then |
||
83 | if (strfind(arg1,tD_Loc.UImessages.cancelled)~=nil or strfind(arg1,tD_Loc.UImessages.failed)~=nil) then |
||
84 | tradeDispenserVerbose(2,arg1); |
||
85 | tD_Temp.Target.Name=nil; |
||
86 | end |
||
87 | if (strfind(arg1,tD_Loc.UImessages.complete)~=nil) then |
||
88 | tradeDispenserVerbose(2,arg1); |
||
89 | tradeDispenserVerbose(1,"Gonna Registrate the Player "..tD_Temp.Target.Name); |
||
90 | tradeDispenserAddClient(tD_Temp.Target.Name); |
||
91 | end |
||
92 | end |
||
93 | |||
94 | |||
95 | if (event == "TRADE_SHOW" and tD_Temp.isEnabled and tD_Temp.InitiateTrade==nil) then |
||
96 | if (CursorHasItem()) then PutItemInBackpack() end -- if the player's got an item on the cursor, tD's not running correctly |
||
97 | if (UnitAffectingCombat("Player")==nil) then TargetUnit("NPC") end -- target player, if you're not in combat |
||
98 | tD_Temp.Target = {}; |
||
99 | tD_Temp.Target.Name = UnitName("NPC"); |
||
100 | tD_Temp.Target.Level = UnitLevel("NPC"); |
||
101 | tD_Temp.Target.Class, tD_Temp.Target.EnglishClass = UnitClass("NPC"); |
||
102 | |||
103 | if (not tradeDispenserTradeControlChecker()) then |
||
104 | tD_Temp.Target.Name=nil; |
||
105 | CloseTrade(); |
||
106 | else |
||
107 | local itemsToTrade = tradeDispenserCompileProfile(); |
||
108 | if (itemsToTrade) then |
||
109 | if (itemsToTrade==0) then -- no items to trade - tradeDispenser should be inactive |
||
110 | tradeDispenserVerbose(0,tD_Loc.noItemsToTrade); |
||
111 | tD_Temp.Target.Name=nil; |
||
112 | else |
||
113 | tD_Temp.timeSlice = 0 |
||
114 | tD_Temp.tradeState = "populate" |
||
115 | tD_Temp.tradeData = {} |
||
116 | tD_Temp.tradeData.slotID = 1 |
||
117 | tD_Temp.tradeData.numAttempts = 0 |
||
118 | tD_Temp.tradeData.containerLocation = nil |
||
119 | end |
||
120 | end |
||
121 | end |
||
122 | end |
||
123 | if (event == "TRADE_ACCEPT_UPDATE") then |
||
124 | tradeDispenserVerbose(1,"TRADE_ACCEPT_UPDATE: Player="..arg1.." - Target="..arg2); |
||
125 | if (arg1==0 and arg2==1 and tD_CharDatas.AutoAccept) then |
||
126 | tradeDispenserAccept() |
||
127 | end |
||
128 | if (arg1==1 and arg2==0 and tD_CharDatas.TimelimitCheck) then |
||
129 | tradeDispenserStartTimelimiter() |
||
130 | end |
||
131 | end |
||
132 | if (event == "TRADE_CLOSED") then |
||
133 | tD_Temp.tradeState = nil |
||
134 | tD_Temp.tradeData = nil |
||
135 | tD_Temp.InitiateTrade=nil; |
||
136 | tD_Temp.Countdown=-1; |
||
137 | tradeDispenserVerbose(1,"Trade Closed") |
||
138 | |||
139 | --if (UnitIsPlayer("target")) then TargetLastEnemy() end |
||
140 | end |
||
141 | end |
||
142 | |||
143 | |||
144 | function tradeDispenserAddClient(name) |
||
145 | if (not name) then return end |
||
146 | |||
147 | local i=0 |
||
148 | local index=nil; |
||
149 | while (tD_Temp.RegUser[i]~=nil) do |
||
150 | tradeDispenserVerbose(3,"Registred Player at index "..i.." is: "..tD_Temp.RegUser[i].name); |
||
151 | if (tD_Temp.RegUser[i].name == name) then |
||
152 | tradeDispenserVerbose(2,name.." found in the List at position "..i); |
||
153 | index=i; |
||
154 | end |
||
155 | i=i+1; |
||
156 | end |
||
157 | |||
158 | if (index==nil) then |
||
159 | tradeDispenserVerbose(2,name.." was unregistred! New Registration-Index is: "..i); |
||
160 | tD_Temp.RegUser[i]= { |
||
161 | ["name"] = name, ["trades"] = 1 |
||
162 | } |
||
163 | else |
||
164 | tD_Temp.RegUser[index].trades = tD_Temp.RegUser[index].trades+1; |
||
165 | end |
||
166 | end |
||
167 | |||
168 | |||
169 | |||
170 | function tradeDispenserClick(slotID) |
||
171 | MoneyInputFrame_ClearFocus(tradeDispenserMoneyFrame) |
||
172 | |||
173 | ClickTradeButton(slotID) |
||
174 | local itemName, itemTexture, itemCount = GetTradePlayerItemInfo(slotID) |
||
175 | local itemLink = GetTradePlayerItemLink(slotID) |
||
176 | |||
177 | if ( itemName ) then |
||
178 | ClickTradeButton(slotID) |
||
179 | local i=tD_CharDatas.ActualProfile; |
||
180 | tD_CharDatas.profile[tD_CharDatas.ActualRack][i][slotID] = {} |
||
181 | tD_CharDatas.profile[tD_CharDatas.ActualRack][i][slotID].itemLink = itemLink |
||
182 | tD_CharDatas.profile[tD_CharDatas.ActualRack][i][slotID].itemName = itemName |
||
183 | tD_CharDatas.profile[tD_CharDatas.ActualRack][i][slotID].itemTexture = itemTexture |
||
184 | tD_CharDatas.profile[tD_CharDatas.ActualRack][i][slotID].itemCount = itemCount |
||
185 | else |
||
186 | tD_CharDatas.profile[tD_CharDatas.ActualRack][tD_CharDatas.ActualProfile][slotID]=nil |
||
187 | end |
||
188 | tradeDispenserVerbose(2, "Recieved Item on Slot "..slotID); |
||
189 | tradeDispenserUpdate() |
||
190 | end |
||
191 | |||
192 | |||
193 | function tradeDispenserUpdate() |
||
194 | local ActPro=tD_CharDatas.ActualProfile; |
||
195 | |||
196 | MoneyInputFrame_ClearFocus(tradeDispenserMoneyFrame) |
||
197 | if (tradeDispenserProfileDDframe) then tradeDispenserProfileDDframe:Hide(); end |
||
198 | if (tradeDispenserRackDDframe) then tradeDispenserRackDDframe:Hide(); end |
||
199 | |||
200 | |||
201 | if (tradeDispenserSettingsChannelDDframe) then tradeDispenserSettingsChannelDDframe:Hide(); end |
||
202 | for slotID=1,6 do |
||
203 | local buttonText = getglobal("tradeDispenserItem"..slotID.."Name") |
||
204 | local itemButton = getglobal("tradeDispenserItem"..slotID.."ItemButton") |
||
205 | |||
206 | if ( tD_CharDatas.profile and tD_CharDatas.profile[tD_CharDatas.ActualRack] and |
||
207 | tD_CharDatas.profile[tD_CharDatas.ActualRack][ActPro] and |
||
208 | tD_CharDatas.profile[tD_CharDatas.ActualRack][ActPro][slotID] and |
||
209 | tD_CharDatas.profile[tD_CharDatas.ActualRack][ActPro][slotID].itemName ) then |
||
210 | local temp = tD_CharDatas.profile[tD_CharDatas.ActualRack][ActPro][slotID]; |
||
211 | tradeDispenserVerbose(3,"tradeDispenserUpdate: slotID '"..slotID.."' is used") |
||
212 | buttonText:SetText(temp.itemName) |
||
213 | SetItemButtonTexture(itemButton, temp.itemTexture) |
||
214 | SetItemButtonCount(itemButton, temp.itemCount) |
||
215 | else |
||
216 | tradeDispenserVerbose(3,"tradeDispenserUpdate: slotID '"..slotID.."' is free") |
||
217 | buttonText:SetText("") |
||
218 | SetItemButtonTexture(itemButton, nil) |
||
219 | SetItemButtonCount(itemButton, nil) |
||
220 | end |
||
221 | end |
||
222 | |||
223 | if (tD_Temp.isVisible) then tradeDispenser:Show() |
||
224 | else |
||
225 | if (tradeDispenserTradeControl) then |
||
226 | tradeDispenser:Hide() |
||
227 | if (not tradeDispenserMessages:IsShown()) then |
||
228 | tradeDispenserSettings:Hide(); |
||
229 | tradeDispenserTradeControl:Hide() |
||
230 | tradeDispenserSettingsBtn:UnlockHighlight(); |
||
231 | tradeDispenserTradeControlBtn:UnlockHighlight(); |
||
232 | end |
||
233 | end |
||
234 | end |
||
235 | |||
236 | if (tD_Temp.isEnabled) then |
||
237 | tradeDispenserState:SetText(tD_Loc.buttons.enabled) |
||
238 | tradeDispenserState:LockHighlight(); |
||
239 | else |
||
240 | tradeDispenserState:SetText(tD_Loc.buttons.disabled) |
||
241 | tradeDispenserState:UnlockHighlight(); |
||
242 | end |
||
243 | |||
244 | if (tD_CharDatas.broadcastSlice) then |
||
245 | if (tD_CharDatas.broadcastSlice < 0) then |
||
246 | tD_CharDatas.broadcastSlice = 0 |
||
247 | elseif (tD_CharDatas.broadcastSlice > tradeDispenser_MaxBroadcastLength*60) then |
||
248 | tD_CharDatas.broadcastSlice = tradeDispenser_MaxBroadcastLength*60 |
||
249 | end |
||
250 | else |
||
251 | tD_CharDatas.broadcastSlice = math.floor(tradeDispenser_MaxBroadcastLength/2) |
||
252 | end |
||
253 | |||
254 | if (tD_CharDatas.AutoBroadcast) then |
||
255 | tradeDispenserSettingsBroadcastTimer:Show(); |
||
256 | tradeDispenserSettingsBroadcastCheck:SetChecked(1); |
||
257 | else |
||
258 | tradeDispenserSettingsBroadcastTimer:Hide(); |
||
259 | tradeDispenserSettingsBroadcastCheck:SetChecked(0); |
||
260 | end |
||
261 | |||
262 | local tmp = tD_CharDatas.ActualProfile; |
||
263 | if (tD_CharDatas.profile and tD_CharDatas.profile[tD_CharDatas.ActualRack] and tmp and tD_CharDatas.profile[tD_CharDatas.ActualRack][tmp].Charge) then |
||
264 | MoneyInputFrame_SetCopper(tradeDispenserMoneyFrame, tD_CharDatas.profile[tD_CharDatas.ActualRack][tmp].Charge) |
||
265 | end |
||
266 | |||
267 | local s = 1 |
||
268 | if (tD_CharDatas.ActualRack) then |
||
269 | s = tradeDispenserRackColor[tD_CharDatas.ActualRack] |
||
270 | end |
||
271 | local r,g,b = 0.8,0.8,0.8; |
||
272 | if (tD_Temp.isEnabled) then |
||
273 | r=s.r; g=s.g; b=s.b; |
||
274 | end |
||
275 | |||
276 | tradeDispenserBkg1:SetVertexColor(r,g,b,1); |
||
277 | tradeDispenserBkg2:SetVertexColor(r,g,b,1); |
||
278 | tradeDispenserBkg3:SetVertexColor(r,g,b,1); |
||
279 | end |
||
280 | |||
281 | |||
282 | function tradeDispenser_ResetFrames() |
||
283 | tradeDispenser:ClearAllPoints() |
||
284 | tradeDispenser:SetPoint("CENTER", "UIParent", "CENTER", 0, 0) |
||
285 | tradeDispenserMessages:ClearAllPoints() |
||
286 | tradeDispenserMessages:SetPoint("CENTER", "UIParent", "CENTER", 0, 0) |
||
287 | tradeDispenserOSD:ClearAllPoints() |
||
288 | tradeDispenserOSD:SetPoint("LEFT", "UIParent", "LEFT", 15, 0) |
||
289 | tradeDispenserVerbose(0,tD_Loc.resetframes) |
||
290 | end |
||
291 | |||
292 | |||
293 | |||
294 | SLASH_TRADE_DISPENSER1 = "/tradeDispenser" |
||
295 | SLASH_TRADE_DISPENSER2 = "/td" |
||
296 | SlashCmdList["TRADE_DISPENSER"] = function(msg) |
||
297 | tradeDispenser_SlashCommand(msg) |
||
298 | end |
||
299 | |||
300 | |||
301 | function tradeDispenser_SlashCommand(msg) |
||
302 | if (not msg) then tradeDispenser_Print(tD_Loc.help) |
||
303 | else |
||
304 | local command=string.lower(msg); |
||
305 | if (command=="config") then |
||
306 | tD_Temp.isVisible = not tD_Temp.isVisible; |
||
307 | tradeDispenserMessages:Hide(); |
||
308 | tradeDispenserUpdate(); |
||
309 | tradeDispenserOSD_OnUpdate(); |
||
310 | elseif (command=="toggle") then |
||
311 | tD_Temp.isEnabled = not tD_Temp.isEnabled; |
||
312 | if (tD_Temp.isEnabled) then |
||
313 | DEFAULT_CHAT_FRAME:AddMessage(tD_Loc.activated) |
||
314 | else |
||
315 | DEFAULT_CHAT_FRAME:AddMessage(tD_Loc.deactivated) |
||
316 | end |
||
317 | tradeDispenser_Eventhandler(); |
||
318 | tradeDispenserUpdate(); |
||
319 | tradeDispenserOSD_OnUpdate(); |
||
320 | elseif (command=="broadcast") then |
||
321 | if (tD_Temp.isEnabled) then |
||
322 | tradeDispenserBroadcastItems() |
||
323 | else |
||
324 | DEFAULT_CHAT_FRAME:AddMessage(tD_Loc.OSD.notenabled) |
||
325 | end |
||
326 | elseif (command=="osd") then |
||
327 | tD_CharDatas.OSD.isEnabled = not tD_CharDatas.OSD.isEnabled; |
||
328 | tradeDispenserUpdate(); |
||
329 | tradeDispenserSettings_OnUpdate(); |
||
330 | tradeDispenserOSD_OnUpdate(); |
||
331 | elseif (command=="about") then tradeDispenser_Print(tD_Loc.about) |
||
332 | elseif (command=="resetpos") then tradeDispenser_ResetFrames() |
||
333 | elseif (string.sub(command, 1,7)=="verbose") then |
||
334 | local temp=tonumber(string.sub(command, 8,10)); |
||
335 | if (not temp) then |
||
336 | tradeDispenserVerbose(0, tD_Loc.verbose.isset..tD_GlobalDatas.Verbose); |
||
337 | else |
||
338 | tD_GlobalDatas.Verbose=temp; |
||
339 | tradeDispenserVerbose(0,tD_Loc.verbose.setto..tD_GlobalDatas.Verbose); |
||
340 | end |
||
341 | else tradeDispenser_Print(tD_Loc.help); |
||
342 | end -- no correct command was found |
||
343 | end |
||
344 | end |