vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | BGvar_BlackList = {}; |
2 | BGvar_NotInBG = {}; |
||
3 | |||
4 | BGInvite_Var = {}; |
||
5 | BGInvite_Var.debug = false; |
||
6 | |||
7 | BGvar_initialMessageSent = false; |
||
8 | BGvar_AutoInviteTimer = 0; |
||
9 | BGvar_AutoPurgeTimer = 0; |
||
10 | |||
11 | BGInvite_ITEM_HEIGHT = 32; |
||
12 | BGInvite_ITEMS_SHOWN = 7; |
||
13 | |||
14 | BGInvite_Config = { |
||
15 | AutoInvite = 0 |
||
16 | ,AutoPurge = 0 |
||
17 | ,MagicWord = "invite" |
||
18 | ,RetryTimeout = 20 |
||
19 | ,PurgeTimeout = 120 |
||
20 | ,MaxRetries = 5 |
||
21 | ,SendWhisper = 1 |
||
22 | ,AutoInviteTimeout = 5 |
||
23 | ,MsgChannelId=1 |
||
24 | ,Disable |
||
25 | }; |
||
26 | |||
27 | local Pre_BGinvite_ToggleWorldStateScoreFrame; |
||
28 | local Pre_BGinvite_ChatFrame_OnEvent; |
||
29 | local chatParseInfoMagicWordWhisper = { AddOn = "BGInvite" }; |
||
30 | local chatParseInfoMagicWordSay = { AddOn = "BGInvite" }; |
||
31 | |||
32 | UIPanelWindows["BGInviteFrame"] = { area = "left", pushable = 3 }; |
||
33 | BGINVITE_TAB_SUBFRAMES = { "BGInvite_OptionsFrame", "BGInvite_BlackListFrame" }; |
||
34 | |||
35 | --[[ |
||
36 | ============================================================================= |
||
37 | ============================================================================= |
||
38 | ]] |
||
39 | function BGInvite_GetBattleFieldStatus() |
||
40 | for i=1, MAX_BATTLEFIELD_QUEUES do |
||
41 | status, mapName, instanceID = GetBattlefieldStatus(i); |
||
42 | --BGDebugMessage("DEBUG","status="..status.." mapName="..mapName.." id="..instanceID,"debug"); |
||
43 | if ( instanceID ~= 0 ) then |
||
44 | mapName = mapName.." "..instanceID; |
||
45 | return status,mapName,instanceID; |
||
46 | end |
||
47 | end |
||
48 | --status="active"; |
||
49 | return status,mapName,instanceID; |
||
50 | |||
51 | end |
||
52 | |||
53 | function MagicWordChanged() |
||
54 | BGDebugMessage("DEBUG","magicword changed="..BGInvite_Config.MagicWord,"debug"); |
||
55 | chatParseInfoMagicWordWhisper.template = BGInvite_Config.MagicWord; |
||
56 | chatParseInfoMagicWordSay.template = BGInvite_Config.MagicWord; |
||
57 | |||
58 | BGChatParse_UnregisterEvent(chatParseInfoMagicWordWhisper); |
||
59 | BGChatParse_UnregisterEvent(chatParseInfoMagicWordSay); |
||
60 | |||
61 | BGChatParse_RegisterEvent(chatParseInfoMagicWordWhisper); |
||
62 | BGChatParse_RegisterEvent(chatParseInfoMagicWordSay); |
||
63 | end |
||
64 | |||
65 | --[[ |
||
66 | ============================================================================= |
||
67 | The loading frame handles getting our AddOn initialized properly |
||
68 | ============================================================================= |
||
69 | ]] |
||
70 | function BGInviteLoadingFrame_OnUpdate() |
||
71 | if ( BGInviteFrame.loaded ) then |
||
72 | BGInviteLoadingFrame:UnregisterEvent("VARIABLES_LOADED"); |
||
73 | BGInviteLoadingFrame:UnregisterEvent("UNIT_NAME_UPDATE"); |
||
74 | BGInviteLoadingFrame:Hide(); |
||
75 | BGInviteLoadingFrame = nil; |
||
76 | elseif ( BGInviteLoadingFrame.loadTime + 2 <= GetTime() ) then |
||
77 | BGInviteFrame_LoadData(); |
||
78 | BGInviteLoadingFrame.loadTime = GetTime(); |
||
79 | end |
||
80 | end |
||
81 | |||
82 | function BGInviteLoadingFrame_OnLoad() |
||
83 | BGInviteLoadingFrame:RegisterEvent("VARIABLES_LOADED"); |
||
84 | BGInviteLoadingFrame:RegisterEvent("UNIT_NAME_UPDATE"); |
||
85 | BGInviteLoadingFrame.init = 0; |
||
86 | BGInviteLoadingFrame.loadTime = GetTime(); |
||
87 | |||
88 | end |
||
89 | |||
90 | function BGInviteLoadingFrame_OnEvent(event, arg1) |
||
91 | if ( not BGInviteLoadingFrame ) then |
||
92 | return; |
||
93 | end |
||
94 | if ( event == "VARIABLES_LOADED" or event == "UNIT_NAME_UPDATE" ) then |
||
95 | BGInviteLoadingFrame.init = BGInviteLoadingFrame.init + 1; |
||
96 | BGInviteFrame_LoadData(); |
||
97 | end |
||
98 | |||
99 | if ( BGInviteLoadingFrame.init >= 2 ) then |
||
100 | BGInviteFrame_LoadData(); |
||
101 | end |
||
102 | |||
103 | end |
||
104 | |||
105 | --[[ |
||
106 | ============================================================================= |
||
107 | Variable initialization |
||
108 | ============================================================================= |
||
109 | ]] |
||
110 | function BGInviteFrame_LoadData() |
||
111 | BGInviteFrame.loaded = true; |
||
112 | -- check each variable to ensure its set |
||
113 | if ( BGInvite_Config.AutoInvite == nil) then |
||
114 | BGInvite_Config.AutoInvite = 0; |
||
115 | end |
||
116 | if ( BGInvite_Config.AutoPurge == nil) then |
||
117 | BGInvite_Config.AutoPurge = 0; |
||
118 | end |
||
119 | if ( BGInvite_Config.MagicWord == nil) then |
||
120 | BGInvite_Config.MagicWord = "invite"; |
||
121 | end |
||
122 | if ( BGInvite_Config.RetryTimeout == nil ) then |
||
123 | BGInvite_Config.RetryTimeout = 20; |
||
124 | end |
||
125 | if ( BGInvite_Config.PurgeTimeout == nil ) then |
||
126 | BGInvite_Config.PurgeTimeout = 120; |
||
127 | end |
||
128 | if ( BGInvite_Config.MaxRetries == nil ) then |
||
129 | BGInvite_Config.MaxRetries = 5; |
||
130 | end |
||
131 | if ( BGInvite_Config.SendWhisper == nil ) then |
||
132 | BGDebugMessage("DEBUG","SendWhisper=nil","debug"); |
||
133 | BGInvite_Config.SendWhisper = 1; |
||
134 | end |
||
135 | if ( BGInvite_Config.AutoInviteTimeout == nil ) then |
||
136 | BGInvite_Config.AutoInviteTimeout = 5; |
||
137 | end |
||
138 | if ( BGInvite_Config.MsgChannelId == nil ) then |
||
139 | BGInvite_Config.MsgChannelId = 1; |
||
140 | end |
||
141 | if ( BGInvite_Config.Disable == nil ) then |
||
142 | BGInvite_Config.Disable = 0; |
||
143 | end |
||
144 | |||
145 | end |
||
146 | |||
147 | function BGInvite_ResetVariables() |
||
148 | BGInviteClearVars(); |
||
149 | BGInvite_Config = {}; |
||
150 | -- AutoInvite = 0 |
||
151 | -- ,AutoPurge = 0 |
||
152 | -- ,MagicWord = "invite" |
||
153 | -- ,RetryTimeout = 20 |
||
154 | -- ,PurgeTimeout = 120 |
||
155 | -- }; |
||
156 | end |
||
157 | |||
158 | --[[ |
||
159 | ============================================================================= |
||
160 | Initialization. |
||
161 | ============================================================================= |
||
162 | ]] |
||
163 | function BGInviteFrame_OnLoad() |
||
164 | |||
165 | this:RegisterEvent("PARTY_MEMBERS_CHANGED") |
||
166 | this:RegisterEvent("VARIABLES_LOADED") |
||
167 | this:RegisterEvent("ZONE_CHANGED_NEW_AREA") |
||
168 | |||
169 | this:RegisterEvent("CHAT_MSG_SAY"); |
||
170 | this:RegisterEvent("CHAT_MSG_YELL"); |
||
171 | this:RegisterEvent("CHAT_MSG_RAID"); |
||
172 | this:RegisterEvent("CHAT_MSG_SYSTEM"); --(ie user joins the battlefield msgs?) |
||
173 | this:RegisterEvent("CHAT_MSG_WHISPER") |
||
174 | this:RegisterEvent("CHAT_MSG_CHANNEL"); |
||
175 | this:RegisterEvent("CHAT_MSG_CHANNEL_JOIN"); |
||
176 | this:RegisterEvent("CHAT_MSG_CHANNEL_NOTICE"); |
||
177 | this:RegisterEvent("UI_INFO_MESSAGE"); |
||
178 | this:RegisterEvent("CHAT_MSG_BG_SYSTEM_NEUTRAL"); |
||
179 | |||
180 | Pre_BGinvite_ChatFrame_OnEvent = ChatFrame_OnEvent; |
||
181 | ChatFrame_OnEvent = BGinvite_ChatFrame_OnEvent; |
||
182 | |||
183 | SLASH_BGINVITE1 = "/bginvite"; |
||
184 | SlashCmdList["BGINVITE"] = function ( msg ) |
||
185 | BGinvite_SlashCmdHandler(msg); |
||
186 | end |
||
187 | |||
188 | -- Intall ChatMessge handlers |
||
189 | local chatParseInfo = { AddOn = "BGInvite" }; |
||
190 | chatParseInfo.event = "CHAT_MSG_SYSTEM"; |
||
191 | chatParseInfo.func = function(t) BGInvite_AddBlackList(t.name,BGINVITE_DECLINED); end; |
||
192 | chatParseInfo.template = BGlocal_BLANK_DECLINES_YOUR_INVITATION; |
||
193 | chatParseInfo.english = "%s declines your group invitation."; |
||
194 | chatParseInfo.fields = { "name" }; |
||
195 | BGChatParse_RegisterEvent(chatParseInfo); |
||
196 | |||
197 | local chatParseInfo1 = { AddOn = "BGInvite" }; |
||
198 | chatParseInfo1.event = "CHAT_MSG_SYSTEM"; |
||
199 | chatParseInfo1.func = function(t) BGInvite_AddBlackList(t.name, BGINVITE_DECLINED); end; |
||
200 | chatParseInfo1.template = BGlocal_BLANK_IS_IGNORING_YOU; |
||
201 | chatParseInfo1.english = "%s is ignoring you."; |
||
202 | chatParseInfo1.fields = { "name" }; |
||
203 | BGChatParse_RegisterEvent(chatParseInfo1); |
||
204 | |||
205 | local chatParseInfo2 = { AddOn = "BGInvite" }; |
||
206 | chatParseInfo2.event = "CHAT_MSG_SYSTEM"; |
||
207 | chatParseInfo2.func = function(t) BGInvite_AddBlackList(t.name,BGINVITE_ALREADY_IN_GROUP); end; |
||
208 | chatParseInfo2.template = BGlocal_BLANK_IS_ALREADY_IN_GROUP; |
||
209 | chatParseInfo2.english = "%s is already in a group."; |
||
210 | chatParseInfo2.fields = { "name" }; |
||
211 | BGChatParse_RegisterEvent(chatParseInfo2); |
||
212 | |||
213 | chatParseInfoMagicWordWhisper.event = "CHAT_MSG_WHISPER"; |
||
214 | chatParseInfoMagicWordWhisper.func = function(t) BGInvite_MagicWordWhisperInvite(t.player); end; |
||
215 | chatParseInfoMagicWordWhisper.template = BGInvite_Config.MagicWord; |
||
216 | chatParseInfoMagicWordWhisper.english = BGInvite_Config.MagicWord; |
||
217 | chatParseInfoMagicWordWhisper.fields = { }; |
||
218 | BGChatParse_RegisterEvent(chatParseInfoMagicWordWhisper); |
||
219 | |||
220 | chatParseInfoMagicWordSay.event = "CHAT_MSG_SAY"; |
||
221 | chatParseInfoMagicWordSay.func = function(t) BGInvite_MagicWordInvite(t.player); end; |
||
222 | chatParseInfoMagicWordSay.template = BGInvite_Config.MagicWord; |
||
223 | chatParseInfoMagicWordSay.english = BGInvite_Config.MagicWord; |
||
224 | chatParseInfoMagicWordSay.fields = { }; |
||
225 | BGChatParse_RegisterEvent(chatParseInfoMagicWordSay); |
||
226 | |||
227 | |||
228 | local chatParseInfo3 = { AddOn = "BGInvite" }; |
||
229 | chatParseInfo1.event = "CHAT_MSG_SYSTEM"; |
||
230 | chatParseInfo1.func = function(t) BGDebugMessage("DEBUG","days is "..t.days,"debug"); end; |
||
231 | chatParseInfo1.template = "%d days"; |
||
232 | chatParseInfo1.english = "%s is ignoring you."; |
||
233 | chatParseInfo1.fields = { "days" }; |
||
234 | BGChatParse_RegisterEvent(chatParseInfo3); |
||
235 | |||
236 | -- Tab Handling code |
||
237 | PanelTemplates_SetNumTabs(BGInviteFrame, 2); |
||
238 | PanelTemplates_SetTab(BGInviteFrame, 1); |
||
239 | |||
240 | --RegisterForSave("BGInvite_Config"); |
||
241 | |||
242 | if ( DEFAULT_CHAT_FRAME ) then |
||
243 | DEFAULT_CHAT_FRAME:AddMessage(BGINVITE_TITLE.." AddOn loaded. Use /bginvite"); |
||
244 | end |
||
245 | UIErrorsFrame:AddMessage(loadMessage, 1.0, 1.0, 0.0, 1.0, UIERRORS_HOLD_TIME); |
||
246 | |||
247 | end |
||
248 | |||
249 | --[[ |
||
250 | ============================================================================= |
||
251 | The main event handler. Gets called when any event we are subscribed to is fired |
||
252 | ============================================================================= |
||
253 | ]] |
||
254 | function BGInviteFrame_OnEvent(event) |
||
255 | --BGDebugMessage("DEBUG","event="..event,"debug"); |
||
256 | |||
257 | if (BGInvite_Config.Disable == 1 ) then |
||
258 | return; |
||
259 | end |
||
260 | |||
261 | if (event == "ZONE_CHANGED_NEW_AREA") then |
||
262 | BGInviteClearVars(); |
||
263 | end |
||
264 | |||
265 | -- ready to convert to a raid? |
||
266 | if ( IsPartyLeader() and GetNumPartyMembers() >= 3 and GetNumRaidMembers() == 0 ) then |
||
267 | BGinvite_ConvertToRaid(); |
||
268 | end |
||
269 | |||
270 | -- If already in a Raid, no need to send out the initial message |
||
271 | -- This is true when another player started the raid and you are now an officer and can invite |
||
272 | if ( IsRaidLeader() or IsRaidOfficer() ) then |
||
273 | BGvar_initialMessageSent = true; |
||
274 | end |
||
275 | |||
276 | |||
277 | -- Handle invites |
||
278 | if ( (IsPartyLeader() or IsRaidLeader() or IsRaidOfficer()) and (BGInvite_Config.AutoInvite == 1) and (BGvar_AutoInviteTimer+BGInvite_Config.AutoInviteTimeout < GetTime() )) then |
||
279 | BGinvite_sendinvites(); |
||
280 | end |
||
281 | |||
282 | -- Handle purges |
||
283 | if ((IsPartyLeader() or IsRaidLeader() or IsRaidOfficer()) and (BGInvite_Config.AutoPurge == 1) and (BGvar_AutoPurgeTimer+BGInvite_Config.PurgeTimeout < GetTime() ) ) then |
||
284 | BGinvite_purge(); |
||
285 | end |
||
286 | |||
287 | end |
||
288 | |||
289 | --[[ |
||
290 | ============================================================================= |
||
291 | ============================================================================= |
||
292 | ]] |
||
293 | function BGInviteClearVars() |
||
294 | --BGvar_BlackList = {}; |
||
295 | BGInviteClearBlackListExceptPerms(); |
||
296 | BGvar_initialMessageSent = false; |
||
297 | end |
||
298 | |||
299 | function BGInviteClearBlackList() |
||
300 | BGvar_BlackList = {}; |
||
301 | end |
||
302 | |||
303 | -- Only removes the players that were added because |
||
304 | -- they were in a group. |
||
305 | -- Leaves Declines and Manual adds |
||
306 | function BGInviteClearBlackListExceptPerms() |
||
307 | for key,value in BGvar_BlackList do |
||
308 | if ( value.reason == BGINVITE_ALREADY_IN_GROUP ) then |
||
309 | table.remove(BGvar_BlackList,key); |
||
310 | elseif ( value.reason == BGINVITE_DECLINED ) then |
||
311 | table.remove(BGvar_BlackList,key); |
||
312 | end |
||
313 | end |
||
314 | end |
||
315 | |||
316 | --[[ |
||
317 | ============================================================================= |
||
318 | Toggles the BGInvite UI on/off. Gets called by tab click handler |
||
319 | ============================================================================= |
||
320 | ]] |
||
321 | function toggleBGInvite(tab) |
||
322 | if ( not tab ) then |
||
323 | if ( BGInviteFrame:IsVisible() ) then |
||
324 | HideUIPanel(BGInviteFrame); |
||
325 | else |
||
326 | ShowUIPanel(BGInviteFrame); |
||
327 | local selectedFrame = getglobal(BGINVITE_TAB_SUBFRAMES[BGInviteFrame.selectedTab]); |
||
328 | if ( not selectedFrame:IsVisible() ) then |
||
329 | selectedFrame:Show(); |
||
330 | end |
||
331 | end |
||
332 | else |
||
333 | local subFrame = getglobal(tab); |
||
334 | if ( subFrame ) then |
||
335 | PanelTemplates_SetTab(BGInviteFrame, subFrame:GetID() ); |
||
336 | if ( BGInviteFrame:IsVisible() ) then |
||
337 | if ( subFrame:IsVisible() ) then |
||
338 | HideUIPanel( BGInviteFrame ); |
||
339 | else |
||
340 | PlaySound("igCharacterInfoTab"); |
||
341 | BGInviteFrame_ShowSubFrame(tab); |
||
342 | end |
||
343 | else |
||
344 | ShowUIPanel( BGInviteFrame ); |
||
345 | BGInviteFrame_ShowSubFrame(tab); |
||
346 | end |
||
347 | end |
||
348 | end |
||
349 | |||
350 | end |
||
351 | |||
352 | --[[ |
||
353 | ============================================================================= |
||
354 | Shows or hides a subframe (tab) |
||
355 | ============================================================================= |
||
356 | ]] |
||
357 | function BGInviteFrame_ShowSubFrame(frameName) |
||
358 | for index, value in BGINVITE_TAB_SUBFRAMES do |
||
359 | if ( value == frameName ) then |
||
360 | getglobal(value):Show(); |
||
361 | else |
||
362 | getglobal(value):Hide(); |
||
363 | end |
||
364 | end |
||
365 | end |
||
366 | |||
367 | |||
368 | --[[ |
||
369 | ============================================================================= |
||
370 | Called when you click on any Tab and decodes into the correct tab to show. |
||
371 | ============================================================================= |
||
372 | ]] |
||
373 | function BGInviteTab_OnClick() |
||
374 | if ( this:GetName() == "BGInviteFrameTab1" ) then |
||
375 | toggleBGInvite("BGInvite_OptionsFrame"); |
||
376 | elseif ( this:GetName() == "BGInviteFrameTab2" ) then |
||
377 | toggleBGInvite("BGInvite_BlackListFrame"); |
||
378 | end |
||
379 | PlaySound("igCharacterInfoTab"); |
||
380 | end |
||
381 | |||
382 | --[[ |
||
383 | ============================================================================= |
||
384 | Handles slash commands. Most of the switches are for debugging/testing |
||
385 | ============================================================================= |
||
386 | ]] |
||
387 | function BGinvite_SlashCmdHandler(msg) |
||
388 | if (string.lower(msg) == "promote all") then |
||
389 | BGinvite_promoteall() |
||
390 | elseif (string.lower(msg) == "demote all") then |
||
391 | BGinvite_demoteall() |
||
392 | elseif (string.lower(msg) == "invite") then |
||
393 | BGinvite_sendinvites() |
||
394 | elseif (string.sub(msg,1,6) == "invite") then |
||
395 | BGDebugMessage("debug","invname="..string.sub(msg,8),"debug"); |
||
396 | BGInvite_SendInvite(string.sub(msg,8)); |
||
397 | elseif (msg == "testaig1" ) then |
||
398 | testAlreadyInGroup(); |
||
399 | elseif (msg == "testaig2" ) then |
||
400 | testAIG(); |
||
401 | elseif (msg == "testaig3" ) then |
||
402 | testAIG3(); |
||
403 | elseif (msg == "vi" ) then |
||
404 | vi(); |
||
405 | elseif (msg == "aig" ) then |
||
406 | dumpAIG(); |
||
407 | elseif (string.sub(msg,1,7) == "cleanse") then |
||
408 | testcleanse(string.sub(msg,9)); |
||
409 | elseif (string.sub(msg,1,3) == "aig") then |
||
410 | BGInvite_AddBlackList(string.sub(msg,5),BGINVITE_ALREADY_IN_GROUP); |
||
411 | elseif (string.sub(msg,1,4) == "aig2") then |
||
412 | BGInvite_AddBlackList(string.sub(msg,6),BGINVITE_DECLINED); |
||
413 | elseif (string.sub(msg,1,4) == "nibg") then |
||
414 | BGinvite_inbattleground(string.sub(msg,6)); |
||
415 | table.foreach(BGvar_NotInBG, debugprintAIG); |
||
416 | elseif (msg == "testbg" ) then |
||
417 | local status,mapname,instanceid = BGInvite_GetBattleFieldStatus(); |
||
418 | BGDebugMessage("debug","status="..status.." mapname="..mapname.." instance="..instanceid,"debug"); |
||
419 | elseif (msg == "scores") then |
||
420 | debugDumpBGScores(); |
||
421 | elseif (msg == "reset") then |
||
422 | BGInvite_ResetVariables(); |
||
423 | elseif (msg == "purge") then |
||
424 | BGinvite_purge(); |
||
425 | elseif (msg == "testgroup") then |
||
426 | testgroup(); |
||
427 | elseif (msg == "testmath") then |
||
428 | testmath(); |
||
429 | elseif (msg == "testmatch") then |
||
430 | testmatch(); |
||
431 | elseif (msg == "testcleanser") then |
||
432 | testcleanser(); |
||
433 | elseif (msg == "channel") then |
||
434 | mychannel(); |
||
435 | else |
||
436 | toggleBGInvite(); |
||
437 | end |
||
438 | end |
||
439 | |||
440 | |||
441 | --[[ |
||
442 | ============================================================================= |
||
443 | Called when the player clicks "Send Invites" in the UI or when AutoInvites |
||
444 | are enabled. |
||
445 | ============================================================================= |
||
446 | ]] |
||
447 | function BGinvite_sendinvites() |
||
448 | local status, mapName, instanceID = BGInvite_GetBattleFieldStatus() |
||
449 | if ( status ~= "active" ) then |
||
450 | return; |
||
451 | end |
||
452 | if (not BGvar_initialMessageSent) then |
||
453 | SendChatMessage(BGlocal_SAY_INVITING, "SAY") |
||
454 | BGvar_initialMessageSent = true; |
||
455 | end |
||
456 | |||
457 | -- Clean up Blacklist prior to sending invites. |
||
458 | BGInvite_CleanseGroups(); |
||
459 | |||
460 | -- Invite the first 5 for the party, after convertToRaid invite all. |
||
461 | local numPositions = GetNumBattlefieldPositions(); |
||
462 | local numInvites = 0; |
||
463 | for i=1,numPositions do |
||
464 | local x, y, name = GetBattlefieldPosition(i) |
||
465 | if ( BGInvite_SendInvite(name) == true ) then |
||
466 | numInvites = numInvites + 1; |
||
467 | end |
||
468 | if ( (GetNumRaidMembers() == 0) and (numInvites >= 4 - GetNumPartyMembers()) ) then |
||
469 | break; |
||
470 | end |
||
471 | end |
||
472 | BGvar_AutoInviteTimer = GetTime(); |
||
473 | end |
||
474 | |||
475 | --[[ |
||
476 | ============================================================================= |
||
477 | ============================================================================= |
||
478 | ]] |
||
479 | function BGInvite_SendInvite(player) |
||
480 | if (BGInvite_Config.Disable == 1 ) then |
||
481 | return; |
||
482 | end |
||
483 | if ( BGIsValidInvite(player) == true ) then |
||
484 | InviteByName(player); |
||
485 | return true; |
||
486 | end |
||
487 | return false; |
||
488 | end |
||
489 | |||
490 | --[[ |
||
491 | ============================================================================= |
||
492 | Called by the ChatMessage callback handler for when the MagicWord is |
||
493 | detected. Checks to ensure that AutoInvite is enabled before inviting. |
||
494 | ============================================================================= |
||
495 | ]] |
||
496 | function BGInvite_MagicWordInvite(player) |
||
497 | local status, mapName, instanceID = BGInvite_GetBattleFieldStatus() |
||
498 | if ( status ~= "active" ) then |
||
499 | if ( IsPartyLeader() or IsRaidLeader() or IsRaidOfficer() ) then |
||
500 | if (BGInvite_Config.AutoInvite == 1) then |
||
501 | BGInvite_SendInvite(player); |
||
502 | end |
||
503 | end |
||
504 | end |
||
505 | end |
||
506 | |||
507 | |||
508 | --[[ |
||
509 | ============================================================================= |
||
510 | Called by the ChatMessage callback handler for when the MagicWord is |
||
511 | detected. Called when player whispers to Leader. |
||
512 | ============================================================================= |
||
513 | ]] |
||
514 | function BGInvite_MagicWordWhisperInvite(player) |
||
515 | if ( IsPartyLeader() or IsRaidLeader() or IsRaidOfficer() ) then |
||
516 | if (BGInvite_Config.AutoInvite == 1) then |
||
517 | BGInvite_SendInvite(player); |
||
518 | end |
||
519 | end |
||
520 | end |
||
521 | |||
522 | --[[ |
||
523 | ============================================================================= |
||
524 | Check to ensure we can send an invite to this player. |
||
525 | Checks whether a user is blackedlisted and whether they are already in the raid. |
||
526 | ============================================================================= |
||
527 | ]] |
||
528 | function BGIsValidInvite(player) |
||
529 | local index = findPlayerIndexInList(BGvar_BlackList,player); |
||
530 | |||
531 | if ( index ) then |
||
532 | if ( BGvar_BlackList[index].retries >= BGInvite_Config.MaxRetries or BGvar_BlackList[index].time+BGInvite_Config.RetryTimeout > GetTime() ) then |
||
533 | if ( BGvar_BlackList[index].retries >= BGInvite_Config.MaxRetries ) then |
||
534 | BGDebugMessage("DEBUG","Invite Not valid due to retries >= max "..BGInvite_Config.MaxRetries,"debug"); |
||
535 | end |
||
536 | if ( BGvar_BlackList[index].time+BGInvite_Config.RetryTimeout > GetTime() ) then |
||
537 | BGDebugMessage("DEBUG","Invite Not valid by time"..BGvar_BlackList[index].time+BGInvite_Config.RetryTimeout.." is greater than "..GetTime(),"debug"); |
||
538 | end |
||
539 | return false; |
||
540 | end |
||
541 | if ( BGvar_BlackList[index].declined == 1 or BGvar_BlackList[index].reason == BGINVITE_DECLINED ) then |
||
542 | BGDebugMessage("DEBUG","Invite Not valid because of decline:"..BGvar_BlackList[index].declined,"debug"); |
||
543 | return false; |
||
544 | end |
||
545 | if ( BGvar_BlackList[index].reason == BGINVITE_MANUAL_ADD ) then |
||
546 | BGDebugMessage("DEBUG","Invite Not valid because player was manually added =>"..player,"debug"); |
||
547 | return false; |
||
548 | end |
||
549 | end |
||
550 | |||
551 | if ( isInRaid(player) == true ) then |
||
552 | return false; |
||
553 | end |
||
554 | |||
555 | BGDebugMessage("DEBUG","Invite is valid","debug"); |
||
556 | return true; |
||
557 | end |
||
558 | |||
559 | --[[ |
||
560 | ============================================================================= |
||
561 | Converts the party to a raid -- called by the EventHandler |
||
562 | ============================================================================= |
||
563 | ]] |
||
564 | function BGinvite_ConvertToRaid() |
||
565 | local status, mapName, instanceID = BGInvite_GetBattleFieldStatus() |
||
566 | if ( status == "active" ) then |
||
567 | BGinvite_print(BGlocal_CONVERTING_TO_RAID); |
||
568 | ConvertToRaid(); |
||
569 | end |
||
570 | end |
||
571 | |||
572 | --[[ |
||
573 | ============================================================================= |
||
574 | Determines whether the player is in the Raid or not |
||
575 | ============================================================================= |
||
576 | ]] |
||
577 | function isInRaid(player) |
||
578 | for i=1,GetNumRaidMembers() do |
||
579 | local name = GetRaidRosterInfo(i); |
||
580 | if ( name == player ) then |
||
581 | return true; |
||
582 | end |
||
583 | end |
||
584 | |||
585 | return false; |
||
586 | end |
||
587 | |||
588 | --[[ |
||
589 | ============================================================================= |
||
590 | Purges players from the Raid that have left the Battlefield. |
||
591 | This gets called if the user clicks "Purge" in the UI or if autopurges are enabled |
||
592 | ============================================================================= |
||
593 | ]] |
||
594 | function BGinvite_purge() |
||
595 | BGvar_AutoPurgeTimer = GetTime(); |
||
596 | --BGinvite_print(BGlocal_PURGING_PLAYERS) |
||
597 | if GetBattlefieldScore(1) == nil then |
||
598 | --BGinvite_print(BGlocal_ERROR_SCANNING) |
||
599 | -- not in BG |
||
600 | return; |
||
601 | else |
||
602 | for i=1,GetNumRaidMembers() do |
||
603 | local name = GetRaidRosterInfo(i) |
||
604 | if (BGinvite_inbattleground(name) ~= true) then |
||
605 | if ( BGInvite_Config.SendWhisper == 1) then |
||
606 | SendChatMessage("[BGInvite] "..BGlocal_YOU_APPEAR_GONE, "WHISPER",this.language, name) |
||
607 | end |
||
608 | UninviteByName(name); |
||
609 | BGDebugMessage("[BGINVITE]","Uninviting from raid: "..name.." (not in BG)","debug"); |
||
610 | end |
||
611 | end |
||
612 | end |
||
613 | end |
||
614 | |||
615 | --[[ |
||
616 | ============================================================================= |
||
617 | -- Determines whether a player is still on the BattleField |
||
618 | -- For some reason this can return false positives and so it performs |
||
619 | -- an extra check. Places users not found in BG into a list for reference. |
||
620 | ============================================================================= |
||
621 | ]] |
||
622 | function BGinvite_inbattleground(name) |
||
623 | |||
624 | local player = {}; |
||
625 | local x = findPlayerIndexInList(BGvar_NotInBG,name); |
||
626 | for i=1,80 do |
||
627 | local bgname = GetBattlefieldScore(i); |
||
628 | if (bgname and bgname == name) then |
||
629 | -- if previously flagged as not in BG, now we can remove them from that list. |
||
630 | if ( x ) then |
||
631 | table.remove(BGvar_NotInBG,x); |
||
632 | end |
||
633 | return true; |
||
634 | end |
||
635 | end |
||
636 | |||
637 | if ( x ) then |
||
638 | BGvar_NotInBG[x].retries = BGvar_NotInBG[x].retries+1; |
||
639 | if (BGvar_NotInBG[x].retries > 2) then |
||
640 | table.remove(BGvar_NotInBG,x); |
||
641 | return false; |
||
642 | end |
||
643 | else |
||
644 | player.name = name; |
||
645 | player.time = 0; |
||
646 | player.retries = 1; |
||
647 | table.insert(BGvar_NotInBG,player); |
||
648 | end |
||
649 | |||
650 | return true; |
||
651 | end |
||
652 | |||
653 | |||
654 | function debugDumpBGScores() |
||
655 | for i=1,80 do |
||
656 | local bgname,killingBlows,honorKills,deaths,honorGained = GetBattlefieldScore(i); |
||
657 | if (bgname) then |
||
658 | local msg = bgname..":kb="..killingBlows..":kills="..honorKills..":deaths="..deaths..":honor="..honorGained; |
||
659 | DEFAULT_CHAT_FRAME:AddMessage(format("|ccfff0000[%s]: %s|r", "debug", msg)); |
||
660 | end |
||
661 | end |
||
662 | end |
||
663 | |||
664 | function BGinvite_print(msg) |
||
665 | ChatFrame1:AddMessage(msg, 0, .5, 1) |
||
666 | end |
||
667 | |||
668 | --[[ |
||
669 | ============================================================================= |
||
670 | Promotion/Demotion handlers |
||
671 | ============================================================================= |
||
672 | ]] |
||
673 | function BGinvite_promoteall() |
||
674 | if (IsRaidLeader()) then |
||
675 | for i=1, GetNumRaidMembers() do |
||
676 | local name = GetRaidRosterInfo(i) |
||
677 | PromoteToAssistant(name) |
||
678 | end |
||
679 | end |
||
680 | end |
||
681 | |||
682 | function BGinvite_demoteall() |
||
683 | if (IsRaidLeader()) then |
||
684 | for i=1, GetNumRaidMembers() do |
||
685 | local name = GetRaidRosterInfo(i) |
||
686 | DemoteAssistant(name) |
||
687 | end |
||
688 | end |
||
689 | end |
||
690 | |||
691 | --[[ |
||
692 | ============================================================================= |
||
693 | -- Adds a user to the Blacklist |
||
694 | -- Called by the Chat Message handlers |
||
695 | ============================================================================= |
||
696 | ]] |
||
697 | function BGInvite_AddBlackList(name,reason) |
||
698 | local player = {}; |
||
699 | local status,mapname,instanceid = BGInvite_GetBattleFieldStatus(); |
||
700 | |||
701 | --if (BGInvite_Config.Disable == 1 ) then |
||
702 | -- return; |
||
703 | --end |
||
704 | |||
705 | if (status == "active" or BGInvite_Var.debug == true or reason == BGINVITE_MANUAL_ADD) then |
||
706 | if ( isInRaid(name) ) then |
||
707 | return; |
||
708 | end |
||
709 | local index = findPlayerIndexInList(BGvar_BlackList,name); |
||
710 | if ( index ) then |
||
711 | BGDebugMessage("DEBUG","AIG: "..name.." is already flagged "..BGvar_BlackList[index].retries,"debug"); |
||
712 | BGvar_BlackList[index].time = GetTime(); |
||
713 | BGvar_BlackList[index].retries = BGvar_BlackList[index].retries + 1; |
||
714 | player = BGvar_BlackList[index]; |
||
715 | else |
||
716 | player.name = name; |
||
717 | player.time = GetTime(); |
||
718 | player.retries = 0; |
||
719 | player.reason = reason; |
||
720 | player.declined = 0; |
||
721 | if ( reason == BGINVITE_DECLINED ) then |
||
722 | player.declined = 1; |
||
723 | end |
||
724 | table.insert(BGvar_BlackList,player); |
||
725 | end |
||
726 | |||
727 | if (BGInvite_Config.SendWhisper == 1 and math.mod(player.retries,2) == 0 and player.declined ~= 1) then |
||
728 | SendChatMessage("[BGInvite] "..BGINVITE_LEAVE_YOUR_GROUP, "WHISPER", this.language, name); |
||
729 | end |
||
730 | |||
731 | BGDebugMessage("DEBUG","[BlackList adding player] "..name,"debug"); |
||
732 | |||
733 | end |
||
734 | BGInvite_BlackListFrame_Update(); |
||
735 | end |
||
736 | |||
737 | --[[ |
||
738 | ============================================================================= |
||
739 | Walks the Blacklist array and calls BGInvite_CleanseBlackList for each entry |
||
740 | ============================================================================= |
||
741 | ]] |
||
742 | function BGInvite_CleanseGroups() |
||
743 | --table.foreach(BGvar_BlackList, BGInvite_CleanseBlackList); |
||
744 | BGInvite_CleanseBlackList(); |
||
745 | end |
||
746 | |||
747 | --[[ |
||
748 | ============================================================================= |
||
749 | -- Removes players from the Blacklist that are now in the Raid |
||
750 | ============================================================================= |
||
751 | ]] |
||
752 | function BGInvite_CleanseBlackList() |
||
753 | for i=1,GetNumRaidMembers() do |
||
754 | local playerName = GetRaidRosterInfo(i) |
||
755 | local index = findPlayerIndexInList(BGvar_BlackList,playerName); |
||
756 | if ( index ) then |
||
757 | table.remove(BGvar_BlackList, index); |
||
758 | end |
||
759 | end |
||
760 | end |
||
761 | |||
762 | |||
763 | --[[ |
||
764 | ============================================================================= |
||
765 | -- Hook function for chat messages |
||
766 | -- Suppresses "Already in Group" messages |
||
767 | ============================================================================= |
||
768 | ]] |
||
769 | function BGinvite_ChatFrame_OnEvent(event) |
||
770 | |||
771 | if (BGvar_initialMessageSent and (event == "CHAT_MSG_SYSTEM")) then |
||
772 | --BGDebugMessage("DEBUG", "chatmessagehook="..arg1, "debug"); |
||
773 | if string.find(arg1, BGlocal_BLANK_IS_ALREADY_IN_GROUP_FIND) then |
||
774 | x=0; |
||
775 | --BGDebugMessage("DEBUG", "hiding already in group message", "debug"); |
||
776 | elseif string.find(arg1, BGlocal_YOU_HAVE_INVITED_FIND) then |
||
777 | x=0; |
||
778 | --BGDebugMessage("DEBUG", "hiding you have invited message", "debug"); |
||
779 | else |
||
780 | Pre_BGinvite_ChatFrame_OnEvent(event) |
||
781 | end |
||
782 | else |
||
783 | Pre_BGinvite_ChatFrame_OnEvent(event) |
||
784 | end |
||
785 | end |
||
786 | |||
787 | --[[ |
||
788 | ============================================================================= |
||
789 | Called when frame window opens or closes |
||
790 | ============================================================================= |
||
791 | ]] |
||
792 | function BGInviteFrame_OnShow() |
||
793 | PlaySound("igCharacterInfoOpen"); |
||
794 | end |
||
795 | |||
796 | function BGInviteFrame_OnHide() |
||
797 | PlaySound("igCharacterInfoClose"); |
||
798 | end |
||
799 | |||
800 | |||
801 | --[[ |
||
802 | ============================================================================= |
||
803 | Finds our player object in any list. |
||
804 | ============================================================================= |
||
805 | ]] |
||
806 | function findPlayerIndexInList(list,name) |
||
807 | local i; |
||
808 | BGDebugMessage("DEBUG", "find player "..name, "debug"); |
||
809 | for i=1, table.getn( list ) do |
||
810 | BGDebugMessage("DEBUG", "player="..list[i].name, "debug"); |
||
811 | if (list[i].name == name ) then |
||
812 | BGDebugMessage("DEBUG", "found player="..list[i].name, "debug"); |
||
813 | return i; |
||
814 | end |
||
815 | end |
||
816 | end |
||
817 | |||
818 | --[[ |
||
819 | ============================================================================= |
||
820 | Debug message output |
||
821 | ============================================================================= |
||
822 | ]] |
||
823 | function BGDebugMessage(x,y,z) |
||
824 | if ( z == "error" ) then |
||
825 | DEFAULT_CHAT_FRAME:AddMessage(format("|cffff0000[%s]: %s|r", x, y)) |
||
826 | end |
||
827 | |||
828 | if ( BGInvite_Var.debug ) then |
||
829 | DEFAULT_CHAT_FRAME:AddMessage(format("|ccfff0000[%s]: %s|r", x, y)) |
||
830 | end |
||
831 | --if ( z == "debug" ) then |
||
832 | -- DEFAULT_CHAT_FRAME:AddMessage(format("|cffff0000[%s]: %s|r", x, y)) |
||
833 | --end |
||
834 | --if ( z == "foods" ) then |
||
835 | -- DEFAULT_CHAT_FRAME:AddMessage(format("|cffff0000[%s]: %s|r", x, y)) |
||
836 | --end |
||
837 | end |
||
838 | |||
839 | --[[ |
||
840 | ============================================================================= |
||
841 | TEST CODE FROM HERE DOWN |
||
842 | ============================================================================= |
||
843 | ]] |
||
844 | function testAlreadyInGroup() |
||
845 | |||
846 | for i=1,GetNumRaidMembers() do |
||
847 | local name = GetRaidRosterInfo(i) |
||
848 | BGInvite_AddBlackList(name,BGINVITE_ALREADY_IN_GROUP); |
||
849 | end |
||
850 | |||
851 | dumpAIG(); |
||
852 | BGvar_BlackList = {}; |
||
853 | end |
||
854 | |||
855 | function testAIG() |
||
856 | BGInvite_AddBlackList("testplayer1",BGINVITE_ALREADY_IN_GROUP); |
||
857 | BGInvite_AddBlackList("testplayer2",BGINVITE_ALREADY_IN_GROUP); |
||
858 | dumpAIG(); |
||
859 | BGInvite_AddBlackList("testplayer2",BGINVITE_ALREADY_IN_GROUP); |
||
860 | dumpAIG(); |
||
861 | |||
862 | BGDebugMessage("DEBUG","magicword="..BGInvite_Config.MagicWord,"debug"); |
||
863 | BGDebugMessage("DEBUG","RetryTimeout="..BGInvite_Config.RetryTimeout,"debug"); |
||
864 | end |
||
865 | |||
866 | function testAIG3() |
||
867 | BGInvite_AddBlackList("testplayer1",BGINVITE_DECLINED); |
||
868 | BGInvite_AddBlackList("testplayer2",BGINVITE_DECLINED); |
||
869 | BGInvite_AddBlackList("testplayer3",BGINVITE_DECLINED); |
||
870 | BGInvite_AddBlackList("testplayer4",BGINVITE_DECLINED); |
||
871 | BGInvite_AddBlackList("testplayer5",BGINVITE_DECLINED); |
||
872 | BGInvite_AddBlackList("testplayer6",BGINVITE_DECLINED); |
||
873 | BGInvite_AddBlackList("testplayer7",BGINVITE_DECLINED); |
||
874 | BGInvite_AddBlackList("testplayer8",BGINVITE_DECLINED); |
||
875 | BGInvite_AddBlackList("testplayer9",BGINVITE_DECLINED); |
||
876 | BGInvite_AddBlackList("testplayer10",BGINVITE_DECLINED); |
||
877 | BGInvite_AddBlackList("testplayer11",BGINVITE_DECLINED); |
||
878 | BGInvite_AddBlackList("testplayer12",BGINVITE_ALREADY_IN_GROUP); |
||
879 | end |
||
880 | |||
881 | function vi() |
||
882 | BGDebugMessage("DEBUG","testplayer1 isvalid "..decodeBoolean(BGIsValidInvite("testplayer1"))); |
||
883 | BGDebugMessage("DEBUG","testplayer2 isvalid "..decodeBoolean(BGIsValidInvite("testplayer2"))); |
||
884 | BGDebugMessage("DEBUG","testplayer3 isvalid "..decodeBoolean(BGIsValidInvite("testplayer3"))); |
||
885 | BGDebugMessage("DEBUG","testplayer4 isvalid "..decodeBoolean(BGIsValidInvite("testplayer4"))); |
||
886 | BGDebugMessage("DEBUG","testplayer5 isvalid "..decodeBoolean(BGIsValidInvite("testplayer5"))); |
||
887 | BGDebugMessage("DEBUG","testplayer6 isvalid "..decodeBoolean(BGIsValidInvite("testplayer6"))); |
||
888 | BGDebugMessage("DEBUG","testplayer7 isvalid "..decodeBoolean(BGIsValidInvite("testplayer7"))); |
||
889 | BGDebugMessage("DEBUG","testplayer8 isvalid "..decodeBoolean(BGIsValidInvite("testplayer8"))); |
||
890 | BGDebugMessage("DEBUG","testplayer9 isvalid "..decodeBoolean(BGIsValidInvite("testplayer9"))); |
||
891 | BGDebugMessage("DEBUG","testplayer10 isvalid "..decodeBoolean(BGIsValidInvite("testplayer10"))); |
||
892 | BGDebugMessage("DEBUG","testplayer11 isvalid "..decodeBoolean(BGIsValidInvite("testplayer11"))); |
||
893 | BGDebugMessage("DEBUG","testplayer12 isvalid "..decodeBoolean(BGIsValidInvite("testplayer12"))); |
||
894 | end |
||
895 | |||
896 | function decodeBoolean(value) |
||
897 | if ( value ) then |
||
898 | return "true"; |
||
899 | end |
||
900 | return "false"; |
||
901 | end |
||
902 | |||
903 | function dumpAIG() |
||
904 | BGDebugMessage("DEBUG","Dump AIG","debug"); |
||
905 | table.foreach(BGvar_BlackList, debugprintAIG); |
||
906 | BGDebugMessage("DEBUG","Dump AIG2","debug"); |
||
907 | for key,value in BGvar_BlackList do debugprintAIG(key,value) end |
||
908 | end |
||
909 | |||
910 | function debugprintAIG(key,player) |
||
911 | BGDebugMessage("DEBUG","key="..key.." "..player.name..'-'..player.time..'-'..player.retries,"debug"); |
||
912 | end |
||
913 | |||
914 | function testgroup() |
||
915 | if ( IsPartyLeader() ) then |
||
916 | BGDebugMessage("DEBUG","you are party leader","debug"); |
||
917 | else |
||
918 | BGDebugMessage("DEBUG","you are NOT party leader","debug"); |
||
919 | end |
||
920 | local n = GetNumPartyMembers(); |
||
921 | BGDebugMessage("DEBUG","party member cnt="..n,"debug"); |
||
922 | local x = GetNumRaidMembers(); |
||
923 | BGDebugMessage("DEBUG","raid member cnt="..x,"debug"); |
||
924 | end |
||
925 | |||
926 | function testmath() |
||
927 | local x = math.mod(0,2); |
||
928 | local y = math.mod(1,2); |
||
929 | local z = math.mod(2,2); |
||
930 | local a = math.mod(3,2); |
||
931 | |||
932 | BGDebugMessage("DEBUG","x="..x,"debug"); |
||
933 | BGDebugMessage("DEBUG","y="..y,"debug"); |
||
934 | BGDebugMessage("DEBUG","z="..z,"debug"); |
||
935 | BGDebugMessage("DEBUG","a="..a,"debug"); |
||
936 | end |
||
937 | |||
938 | function testmatch() |
||
939 | BGDebugMessage("DEBUG","testmatch","debug"); |
||
940 | local message = "who needs invite?"; |
||
941 | local pattern = "invite.*"; |
||
942 | local match = { string.gfind(message, pattern)() }; |
||
943 | if ( table.getn(match) ~= 0 ) then |
||
944 | BGDebugMessage("DEBUG","matched","debug"); |
||
945 | local ret = { }; |
||
946 | local index; |
||
947 | for index=1, table.getn(match), 1 do |
||
948 | BGDebugMessage("DEBUG","match:"..match[index],"debug"); |
||
949 | end |
||
950 | end |
||
951 | message = "invite me!"; |
||
952 | match = { string.gfind(message, pattern)() }; |
||
953 | if ( table.getn(match) ~= 0 ) then |
||
954 | BGDebugMessage("DEBUG","matched","debug"); |
||
955 | local ret = { }; |
||
956 | local index; |
||
957 | for index=1, table.getn(match), 1 do |
||
958 | BGDebugMessage("DEBUG","match:"..match[index],"debug"); |
||
959 | end |
||
960 | end |
||
961 | |||
962 | end |
||
963 | |||
964 | function testcleanse(key) |
||
965 | table.remove(BGvar_BlackList, key); |
||
966 | end |
||
967 | |||
968 | function testcleanser() |
||
969 | for i=1,GetNumRaidMembers() do |
||
970 | local name = GetRaidRosterInfo(i) |
||
971 | if (BGinvite_inbattleground(name) ~= true) then |
||
972 | BGDebugMessage("DEBUG","should rmeove from group:"..name,"debug"); |
||
973 | end |
||
974 | end |
||
975 | end |
||
976 | |||
977 | function mychannel() |
||
978 | BGDebugMessage("DEBUG","channelname = "..BGInvite_Config.MsgChannelId,"debug"); |
||
979 | SendChatMessage("?", BGINVITE_CHANNELS[BGInvite_Config.MsgChannelId].type, nil,BGINVITE_CHANNELS[BGInvite_Config.MsgChannelId].id); |
||
980 | end |
||
981 |