vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -- ## Tracks battleground queues and statistics. |
2 | -- ## |
||
3 | -- ## This mod was adapted from TitanBG 1600 developed by Sphiromi. |
||
4 | -- ## |
||
5 | -- ## Name : TitanBG (Updated) |
||
6 | -- ## Author : Maina (Chromaggus), Sphiromi |
||
7 | -- ## Version : 1.2.3 |
||
8 | -- ## |
||
9 | -- ## Version 1.2.3 |
||
10 | -- ## * Added a slash command to toggle the options menu. This command is /titabg or /tbg. |
||
11 | -- ## * Fixed a problem with timers being cleared when moving around Stormpike Graveyard in Alterac Valley. |
||
12 | -- ## * Fixed a problem with the Warsong Gulch flag tracker incorrectly extracting names containing special characters. |
||
13 | -- ## * Fixed a problem with the Warsong Gulch flag tracker throwing errors in German and French clients, as a result of incorrect class name translations. |
||
14 | -- ## * Fixed a problem with incorrect slash commands throwing errors. |
||
15 | -- ## |
||
16 | -- ## Version 1.2.2.1 |
||
17 | -- ## * Fixed a problem with the Warsong Gulch flag tracker not displaying the player occasionally. |
||
18 | -- ## * Fixed a problem with player statistics not being correctly tracked. |
||
19 | -- ## |
||
20 | -- ## Version 1.2.2 |
||
21 | -- ## * Fixed a problem with the join battleground popup not joining when the accept button is clicked in the German client. |
||
22 | -- ## * Fixed a problem with errors being generated when non-standard characters are used in player names in Warsong Gulch. |
||
23 | -- ## * Fixed a problem with changing battlegrounds from Arathi Basin to another, occasionally throwing arithmetic errors. |
||
24 | -- ## * Fixed a problem with nil value errors occuring when the current flag carrier leaves Warsong Gulch. |
||
25 | -- ## * Fixed a problem with the Warsong Gulch flag runner name occasionally not being hidden when the flag is dropped or captured. |
||
26 | -- ## * Fixed a problem with unassociated popups being modified to contain battleground information, if the original battleground ready popup was hidden. |
||
27 | -- ## * Fixed a problem where the time left before the battleground queue expires would still show, even if it was disabled, while auto joining. |
||
28 | -- ## * Updated the French translation. |
||
29 | -- ## * Updated existing Warlock coloring to appear lighter. |
||
30 | -- ## |
||
31 | -- ## Version 1.2.1 |
||
32 | -- ## * Added an option to choose if you still wish to automatically release if you have a Soulstone or Shaman Ressurect available. |
||
33 | -- ## * Fixed a problem with the player statistics not showing. |
||
34 | -- ## * Fixed a problem with the 'BattlefieldMinimapCloseButton' frame not existing. |
||
35 | -- ## * Fixed a problem with the Blizzard instance array throwing nil value errors. |
||
36 | -- ## * Fixed a problem with the Warsong Gulch flag tracker throwing nil value errors. |
||
37 | -- ## * Updated options to use a stand alone frame. |
||
38 | -- ## * Updated the French translation. |
||
39 | -- ## |
||
40 | -- ## Version 1.2.0 |
||
41 | -- ## * Added the ability to overwrite similar settings in other addons. |
||
42 | -- ## * Added the ability to play custom sounds when a battleground is ready. |
||
43 | -- ## * Added the ability to play the battleground ready sound periodically or only once. |
||
44 | -- ## * Added the ability to automatically show the battleground minimap, when entering a battleground. |
||
45 | -- ## * Added the ability to show the battleground minimap while not in a battleground. |
||
46 | -- ## * Added the ability to display players in the battleground on the button. |
||
47 | -- ## * Added the ability to display the instance number of the battleground ready to be joined in the button and tooltip. |
||
48 | -- ## * Added the ability to display the amount of time before a battleground queue expires in the button and tooltip. |
||
49 | -- ## * Added the ability to show the active battleground and queue information in separate tooltips while in a battleground. |
||
50 | -- ## * Added the ability to hide active information while in a battleground, when a queue is ready to be joined. |
||
51 | -- ## * Added the ability to track who is carrying the Warsong Gulch flag and the ability to target them easily. |
||
52 | -- ## * Added, to the Arathi Basin estimations, the ability to calculate the amount of nodes the enemy needs to capture in order to win. |
||
53 | -- ## * Added, to the Arathi Basin estimations, the ability to calculate the approximate amount of time before the amount of nodes needed increases. |
||
54 | -- ## * Added the ability to invert the on screen capture timers, so that they are displayed bottom to top, rather than top to bottom. |
||
55 | -- ## * Fixed a problem with the auto join timer counting down, even if not enabled. |
||
56 | -- ## * Fixed a problem with the addon performing various actions even when not enabled. |
||
57 | -- ## * Fixed a problem with the French translation causing errors. |
||
58 | -- ## * Updated the battleground ready popup to display the auto join time and the time until the queue expires. |
||
59 | -- ## * Removed the battleground raid invitation system. |
||
60 | -- ## * Removed the ability to auto accept raid invites in a battleground. |
||
61 | -- ## |
||
62 | -- ## Version 1.1.2 |
||
63 | -- ## * Added a French translation, provided by Triel on Curse Gaming. |
||
64 | -- ## * Fixed a problem with the Arathi Basin estimators not working for languages other than English, even before the patch. |
||
65 | -- ## * Fixed a problem with the recent patch causing Arathi Basin estimations to throw an error. |
||
66 | -- ## * Fixed a problem with new installations of the addon throwing nil value errors. |
||
67 | -- ## * Updated on the screen timers to be unlocked when the user first installs the addon. An explanation has been added to the frame to make this process clearer. |
||
68 | -- ## * Updated it so that on the screen capture timers can now be clicked through. |
||
69 | -- ## * Updated to World of Warcraft patch 1.12. |
||
70 | -- ## |
||
71 | -- ## Version 1.1.1 |
||
72 | -- ## * !! WARNING !! This version will reset all previous settings. |
||
73 | -- ## |
||
74 | -- ## * Added the option to display queue times on the Titan Panel, in the format of [Time in Queue/Estimated Wait Time]. |
||
75 | -- ## * Added the ability for the addon to estimate who will win an Arathi Basin. |
||
76 | -- ## * Added the ability for the addon to estimate the final score in Arathi Basin (with an accuracy of within 10 points). |
||
77 | -- ## * Added the ability for the addon to estimate how long the battle will take in Arathi Basin. |
||
78 | -- ## * Added the ability for the addon to estimate how many nodes your team needs to capture in order to win, if they are losing, in Arathi Basin. |
||
79 | -- ## * Added the ability for the addon to remember how many open battlegrounds existed for each battleground when the user last checked. |
||
80 | -- ## * Added French localization to the .xml file. |
||
81 | -- ## * Fixed a problem with existing queues being abandoned when the addon is first loaded. |
||
82 | -- ## * Fixed a problem with the bonus honor not being displayed correctly. |
||
83 | -- ## * Fixed a problem with it only displaying four timers on the screen, when there should have been five. |
||
84 | -- ## * Fixed problems with abnormal behaviour when hiding or showing various UI elements. |
||
85 | -- ## * Updated German translation to include previously missing variables. |
||
86 | -- ## * Updated saved variable names for consistency. |
||
87 | -- ## |
||
88 | -- ## Version 1.1.0.1 |
||
89 | -- ## * Emergency fix for the errors caused by version 1.1.0. |
||
90 | -- ## |
||
91 | -- ## Version 1.1.0 |
||
92 | -- ## * Added statistics and capture tracking for Arathi Basin, previously not implemented. |
||
93 | -- ## * Added statistics tracking for Warsong Gulch, previously implemented but not printed. |
||
94 | -- ## * Added an on the screen display of the capture timers for Alterac Valley and Arathi Basin. |
||
95 | -- ## * Added German translation, provided by Szeraxenia on Der Rat von Dalaran. |
||
96 | -- ## * Added showing of ready to join queues in the button text, when already in a battleground. |
||
97 | -- ## * Fixed the auto join timer. |
||
98 | -- ## * Fixed minor issues with disbanding a raid, or leaving a raid group on completion. |
||
99 | -- ## * Updated statistics and capture tracking code. |
||
100 | -- ## * Updated 'Location Statistics' to 'Player Objective Statistics' for clarification. |
||
101 | -- ## |
||
102 | -- ## Version 1.0.2 |
||
103 | -- ## * Updated the capture timers to correspond to faction colour. Red will now indicate it is going to be captured by the Horde. Blue indicates it will be captured by the Alliance. |
||
104 | -- ## * Updated all code, so that the localization file can be easily modified into other languages. |
||
105 | -- ## * Updated various display functions to include faster processing. |
||
106 | -- ## |
||
107 | -- ## Version 1.0.1 |
||
108 | -- ## * Added function to determine if the user is currently interacting with a battleground in any fashion. |
||
109 | -- ## * Fixed issue with the showing and hiding of the minimap button when not in the queue. |
||
110 | -- ## * Updated toc files to the current patch. |
||
111 | -- ## |
||
112 | -- ## Version 1.0.0 |
||
113 | -- ## * Removed auto ressurect ability, implemented by Blizzard. |
||
114 | -- ## * Removed sound to be played on queue pop, implemented by Blizzard. |
||
115 | -- ## * Added auto invite and mass invite abilities. |
||
116 | -- ## * Added auto remove ability. |
||
117 | -- ## * Added auto promote ability. |
||
118 | -- ## * Added auto free for all looting ability. |
||
119 | -- ## * Added hide join battleground popup. |
||
120 | -- ## * Fixed auto join ability. |
||
121 | -- ## * Fixed auto release ability. |
||
122 | -- ## * Fixed hide minimap button. |
||
123 | -- ## * Updated addon to work with multiple queues. |
||
124 | -- ## * Updated and reorganised menus and options. |
||
125 | |||
126 | -- Addon information variables. |
||
127 | TITAN_TITANBG_ID = "TitanBG"; |
||
128 | TITANBG_ARTWORK_PATH = "Interface\\AddOns\\Titan\\TitanBG\\Artwork\\TitanBG"; |
||
129 | TITAN_TITANBG_FREQ = 0.5; |
||
130 | |||
131 | -- Checking variables. |
||
132 | |||
133 | -- Status of battlegrounds. Must be exactly as returned by the first variable of GetBattlefieldStatus(i). |
||
134 | TITANBG_BG_STATUS_NONE = "none"; |
||
135 | TITANBG_BG_STATUS_QUEUED = "queued"; |
||
136 | TITANBG_BG_STATUS_CONFIRM = "confirm"; |
||
137 | TITANBG_BG_STATUS_ACTIVE = "active"; |
||
138 | |||
139 | -- Faction names. EXACTLY as returned by UnitFactionGroup("player") or UnitFactionGroup("target"). |
||
140 | TITANBG_HORDE = "Horde"; |
||
141 | TITANBG_ALLIANCE = "Alliance"; |
||
142 | |||
143 | -- Colors and icons. |
||
144 | TITANBG_ICON_CAP_BLANK = {0.75, 0.875, 0.125, 0.25}; |
||
145 | TITANBG_ICON_BUTTON_SPACER = "*"; |
||
146 | |||
147 | TITANBG_COLOR_BLUE = "|cff0097d0"; |
||
148 | TITANBG_COLOR_RED = RED_FONT_COLOR_CODE; |
||
149 | TITANBG_COLOR_GREEN = GREEN_FONT_COLOR_CODE; |
||
150 | TITANBG_COLOR_GREY = "|cffb6b6b6"; |
||
151 | TITANBG_COLOR_WHITE = HIGHLIGHT_FONT_COLOR_CODE; |
||
152 | TITANBG_COLOR_YELLOW = NORMAL_FONT_COLOR_CODE; |
||
153 | TITANBG_COLOR_YELLOW_LIGHT = LIGHTYELLOW_FONT_COLOR_CODE; |
||
154 | TITANBG_COLOR_PURPLE = "|cffd94fff"; |
||
155 | |||
156 | TITANBG_COLOR_CLASS = { |
||
157 | ["WARRIOR"] = { color = "|cffbba58d", }, |
||
158 | ["DRUID"] = { color = "|cffffad0f", }, |
||
159 | ["MAGE"] = { color = "|cff3fd7ff", }, |
||
160 | ["WARLOCK"] = { color = "|cffc783ff", }, |
||
161 | ["ROGUE"] = { color = "|cffffe92f", }, |
||
162 | ["HUNTER"] = { color = "|cff70ce56", }, |
||
163 | ["PRIEST"] = { color = "|cffffffff", }, |
||
164 | ["PALADIN"] = { color = "|cfffe9ee9", }, |
||
165 | ["SHAMAN"] = { color = "|cfffe9ee9", }, |
||
166 | }; |
||
167 | |||
168 | -- Sounds |
||
169 | TITANBG_SOUNDS_BGWARNING = { |
||
170 | [1] = { name = TITANBG_SOUND_DEFAULT, file = "", }, |
||
171 | |||
172 | [2] = { name = TITANBG_SOUND_BELL, file = "Sound\\Doodad\\BoatDockedWarning.wav", }, |
||
173 | [3] = { name = TITANBG_SOUND_CHIME, file = "Sound\\Spells\\ShaysBell.wav", }, |
||
174 | [4] = { name = TITANBG_SOUND_CRASH, file = "Sound\\Doodad\\ArcaneCrystalOpen.wav", }, |
||
175 | [5] = { name = TITANBG_SOUND_CYMBAL, file = "Sound\\interface\\LevelUp.wav", }, |
||
176 | [6] = { name = TITANBG_SOUND_HORN, file = "Sound\\Doodad\\DwarfHorn.wav", }, |
||
177 | [7] = { name = TITANBG_SOUND_LIGHTNING, file = "Sound\\Doodad\\BlastedLandsLightningbolt01Stand-Bolt.wav", }, |
||
178 | [8] = { name = TITANBG_SOUND_TRUMPET, file = "Sound\\interface\\levelup2.wav", }, |
||
179 | [9] = { name = TITANBG_SOUND_WHISTLE, file = "Sound\\Spells\\PetCall.wav", }, |
||
180 | }; |
||
181 | |||
182 | -- Player information variables. |
||
183 | local _player_name = UNKNOWNOBJECT; |
||
184 | local _player_faction = TITANBG_HORDE; |
||
185 | local _player_enemy_faction = TITANBG_HORDE; |
||
186 | local _player_zone = UNKNOWN; |
||
187 | local _player_realm = UNKNOWNOBJECT; |
||
188 | |||
189 | -- Auto join and leave. |
||
190 | local _autojoin_bg = ""; -- Which battleground we are auto joining. |
||
191 | local _autojoin_time = 0; |
||
192 | local _autojoin_paused = 0; |
||
193 | local _autojoin_delay = 10; -- Delay until the battleground is joined, in seconds. |
||
194 | |||
195 | local _autoleave_time = 0; |
||
196 | local _autoleave_paused = 0; |
||
197 | local _autoleave_delay = 10; -- Delay until the battleground is joined, in seconds. |
||
198 | |||
199 | -- Capture delays. |
||
200 | local _capture_delay_av = 300; -- Alterac Valley. |
||
201 | local _capture_delay_ab = 60; -- Arathi Basin. |
||
202 | |||
203 | -- Battleground information variables. |
||
204 | local _active_init_stored = false; -- If the active nodes have been stored on load. |
||
205 | |||
206 | _bgs = { }; -- Battleground infromation. |
||
207 | _active = { }; -- Information on the current active battleground. |
||
208 | |||
209 | local _update_number = 0; -- The id number of the last battleground information update. |
||
210 | local _display_queue_tt = false; -- Display the secondary tooltip, or the primary one. |
||
211 | |||
212 | local _timetonodeincrease = 0; -- Amount of seconds until the nodes needing to be captured increases. |
||
213 | local _bgready_sound_delay = 20; -- Number of seconds between battleground ready sounds if repetitive. |
||
214 | |||
215 | local _popups = { }; -- Popups that appear on the screen containing queue information. |
||
216 | |||
217 | -- Friend's list tracking in active battlegrounds. |
||
218 | local _friendlist = { }; |
||
219 | local _friendasked = false; |
||
220 | local _friendstring = ""; |
||
221 | |||
222 | -- Indicates the addon was successfully loaded. |
||
223 | _addon_loaded = false; |
||
224 | _vars_loaded = false; |
||
225 | local _titan_loaded = false; |
||
226 | |||
227 | -- Tracking variables. |
||
228 | local _blizzard_releasesoul = false; |
||
229 | local _blizzard_interactbg = false; |
||
230 | local _blizzard_manualshowbg = nil; -- "SHOW": Show battlemap. "HIDE": Don't show battlemap. |
||
231 | local _titan_titanbg_leftclick = false; |
||
232 | |||
233 | -- Arathi Basin time until number of nodes required increases. |
||
234 | local _ab_timeinc_check = false; |
||
235 | local _ab_timeinc_sec = 0; |
||
236 | local _ab_timeinc_update = 0; |
||
237 | local _ab_timeing_update_delay = 0.05; |
||
238 | |||
239 | -- ##################### |
||
240 | -- ## EVENT FUNCTIONS ## |
||
241 | -- ##################### |
||
242 | |||
243 | |||
244 | -- ## Events occuring when caught in game by the system. |
||
245 | function TitanPanelTitanBGButton_OnEvent(event, arg1) |
||
246 | if (event == "ADDON_LOADED") then |
||
247 | |||
248 | -- If the addon is being loaded for the first time, make sure sv_menu exists. |
||
249 | if (sv_menu == nil) then sv_menu = {}; end |
||
250 | |||
251 | if (sv_menu["ShowLabelText"] == nil) then sv_menu["ShowLabelText"]= true; end |
||
252 | |||
253 | if (sv_menu["D_B_Spacers"] == nil) then sv_menu["D_B_Spacers"] = true; end |
||
254 | if (sv_menu["D_B_Time"] == nil) then sv_menu["D_B_Time"] = true; end |
||
255 | if (sv_menu["D_B_Kills"] == nil) then sv_menu["D_B_Kills"] = true; end |
||
256 | if (sv_menu["D_B_KillingBlows"] == nil) then sv_menu["D_B_KillingBlows"] = true; end |
||
257 | if (sv_menu["D_B_Deaths"] == nil) then sv_menu["D_B_Deaths"] = true; end |
||
258 | if (sv_menu["D_B_Honor"] == nil) then sv_menu["D_B_Honor"] = true; end |
||
259 | if (sv_menu["D_B_Standing"] == nil) then sv_menu["D_B_Standing"] = true; end |
||
260 | if (sv_menu["D_B_Players"] == nil) then sv_menu["D_B_Players"] = true; end |
||
261 | |||
262 | if (sv_menu["D_BG_SeperateActiveQueue"] == nil) then sv_menu["D_BG_SeperateActiveQueue"] = false; end |
||
263 | if (sv_menu["D_TT_QueueTimers"] == nil) then sv_menu["D_TT_QueueTimers"] = true; end |
||
264 | if (sv_menu["D_B_QueueExpire"] == nil) then sv_menu["D_B_QueueExpire"] = true; end |
||
265 | if (sv_menu["D_TT_RememberOpenBgs"] == nil) then sv_menu["D_TT_RememberOpenBgs"] = false; end |
||
266 | if (sv_menu["D_TT_ABWinEstimates"] == nil) then sv_menu["D_TT_ABWinEstimates"] = true; end |
||
267 | if (sv_menu["D_TT_PlayerStats"] == nil) then sv_menu["D_TT_PlayerStats"] = true; end |
||
268 | if (sv_menu["D_TT_LocationStats"] == nil) then sv_menu["D_TT_LocationStats"] = false; end |
||
269 | if (sv_menu["D_TT_Friends"] == nil) then sv_menu["D_TT_Friends"] = false; end |
||
270 | if (sv_menu["D_TT_Capture"] == nil) then sv_menu["D_TT_Capture"] = true; end |
||
271 | if (sv_menu["D_TT_FlagTracker"] == nil) then sv_menu["D_TT_FlagTracker"] = true; end |
||
272 | |||
273 | if (sv_menu["D_OS_PanelLock"] == nil) then sv_menu["D_OS_PanelLock"] = false; end |
||
274 | |||
275 | if (sv_menu["D_OS_CaptureShow"] == nil) then sv_menu["D_OS_CaptureShow"] = true; end |
||
276 | if (sv_menu["D_NT_TimersInvert"] == nil) then sv_menu["D_NT_TimersInvert"] = false; end |
||
277 | |||
278 | if (sv_menu["D_OS_WSG_Show"] == nil) then sv_menu["D_OS_WSG_Show"] = true; end |
||
279 | if (sv_menu["D_OS_WSG_Click"] == nil) then sv_menu["D_OS_WSG_Click"] = true; end |
||
280 | if (sv_menu["D_OS_WSG_ColorClass"] == nil) then sv_menu["D_OS_WSG_ColorClass"] = true; end |
||
281 | if (sv_menu["D_OS_WSG_TextClass"] == nil) then sv_menu["D_OS_WSG_TextClass"] = true; end |
||
282 | if (sv_menu["D_OS_WSG_Invert"] == nil) then sv_menu["D_OS_WSG_Invert"] = false; end |
||
283 | if (sv_menu["D_OS_WSG_AttachScore"] == nil) then sv_menu["D_OS_WSG_AttachScore"] = false; end |
||
284 | |||
285 | if (sv_menu["I_OverwriteOtherSettings"] == nil) then sv_menu["I_OverwriteOtherSettings"] = true; end |
||
286 | if (sv_menu["B_HideMinimapButton"] == nil) then sv_menu["B_HideMinimapButton"] = false; end |
||
287 | if (sv_menu["D_S_Sound"] == nil) then sv_menu["D_S_Sound"] = false; end |
||
288 | if (sv_menu["D_S_PlayWhatSound"] == nil) then sv_menu["D_S_PlayWhatSound"] = 1; end |
||
289 | if (sv_menu["D_S_RepeatSound"] == nil) then sv_menu["D_S_RepeatSound"] = false; end |
||
290 | if (sv_menu["B_AutoShowBGMinimap"] == nil) then sv_menu["B_AutoShowBGMinimap"] = true; end |
||
291 | if (sv_menu["B_HideJoinPopup"] == nil) then sv_menu["B_HideJoinPopup"] = false; end |
||
292 | if (sv_menu["B_AutoJoinBG"] == nil) then sv_menu["B_AutoJoinBG"] = false; end |
||
293 | if (sv_menu["B_AutoLeaveBG"] == nil) then sv_menu["B_AutoLeaveBG"] = false; end |
||
294 | if (sv_menu["B_AutoRelease"] == nil) then sv_menu["B_AutoRelease"] = false; end |
||
295 | if (sv_menu["B_ReleaseCheck"] == nil) then sv_menu["B_ReleaseCheck"] = true; end |
||
296 | if (sv_menu["B_ReplaceActive"] == nil) then sv_menu["B_ReplaceActive"] = true; end |
||
297 | |||
298 | if (sv_menu["D_POP_QueueExpire"] == nil) then sv_menu["D_POP_QueueExpire"] = true; end |
||
299 | |||
300 | -- Indicate the addon has finished loading. |
||
301 | _addon_loaded = true; |
||
302 | |||
303 | -- Reset storage values. |
||
304 | if (sv_menu["AddonEnabled"]) then |
||
305 | TitanPanelTitanBG_ZonesChanged(); |
||
306 | end |
||
307 | |||
308 | elseif (event == "VARIABLES_LOADED") then |
||
309 | |||
310 | -- If the battlefield minimap hasn't been loaded, load it. |
||
311 | if (not BattlefieldMinimap) then BattlefieldMinimap_LoadUI(); end |
||
312 | |||
313 | TitanPanelTitanBG_StoreFunctions(); |
||
314 | TitanPanelTitanBG_HookFunctions(); |
||
315 | |||
316 | _vars_loaded = true; |
||
317 | |||
318 | -- Store player information variables. |
||
319 | elseif (event == "PLAYER_ENTERING_WORLD") then |
||
320 | TitanPanelTitanBG_ResetPlayerInformation(); |
||
321 | |||
322 | elseif (event == "FRIENDLIST_UPDATE") then |
||
323 | local nFriends = GetNumFriends(); |
||
324 | _friendlist = { }; |
||
325 | local indexf; |
||
326 | for indexf=1, nFriends do |
||
327 | local fname,_,_,_,_ = GetFriendInfo(indexf); |
||
328 | _friendlist[fname] = 1; |
||
329 | end |
||
330 | |||
331 | -- ## Alliance message for Warsong Gulch. |
||
332 | elseif (event == "CHAT_MSG_BG_SYSTEM_ALLIANCE" and _player_zone == TITANBG_BG_WSG) then |
||
333 | _active.stats.wsg.alliance.msg = arg1; |
||
334 | |||
335 | -- ## Horde message for Warsong Gulch. |
||
336 | elseif (event == "CHAT_MSG_BG_SYSTEM_HORDE" and _player_zone == TITANBG_BG_WSG) then |
||
337 | _active.stats.wsg.horde.msg = arg1; |
||
338 | |||
339 | -- ## Hide join popup and minimap button. |
||
340 | elseif (event == "UPDATE_BATTLEFIELD_STATUS" and sv_menu["AddonEnabled"]) then |
||
341 | TitanPanelTitanBG_ToggleMiniMapIcon(); |
||
342 | TitanPanelTitanBG_HideBattlegroundReadyPopup(); |
||
343 | |||
344 | -- ## Actions taken the the user changes zones. |
||
345 | elseif (event == "ZONE_CHANGED_NEW_AREA" and sv_menu["AddonEnabled"]) then |
||
346 | TitanPanelTitanBG_ZonesChanged(); |
||
347 | |||
348 | -- If the user opens the battlefield queue window. |
||
349 | elseif (event == "BATTLEFIELDS_SHOW" and sv_menu["AddonEnabled"]) then |
||
350 | TitanPanelTitanBG_StoreActiveInstanceInformation(); |
||
351 | end |
||
352 | end |
||
353 | |||
354 | |||
355 | -- ## Performed periodically on shedule. |
||
356 | function TitanPanelTitanBGButton_CheckEvents() |
||
357 | |||
358 | -- If the addon is being shown on titan panel, indicate such. |
||
359 | if (not _titan_loaded and _vars_loaded and TitanPanelSettings) then |
||
360 | _titan_loaded = true; |
||
361 | |||
362 | -- Check if the addon is being displayed in Titan. |
||
363 | if (TitanPanel_IsPluginShown(TITAN_TITANBG_ID)) then |
||
364 | sv_menu["AddonEnabled"] = true; |
||
365 | else |
||
366 | sv_menu["AddonEnabled"] = false; |
||
367 | end |
||
368 | |||
369 | TitanPanelTitanBG_HookFunctions(); |
||
370 | end |
||
371 | |||
372 | -- Update the stored battleground information. |
||
373 | TitanPanelTitanBG_StoreBattlegroundInformation(); |
||
374 | |||
375 | -- Update non titan display of captures and flags. |
||
376 | if (_addon_loaded and TitanPanelTitanBG_IsBattleground(_player_zone)) then |
||
377 | TitanPanelTitanBG_NT_UpdateCaptures(); |
||
378 | TitanPanelTitanBG_NT_UpdateFlags(); |
||
379 | end |
||
380 | |||
381 | -- Check if the battleground minimap needs to be shown. |
||
382 | if (_addon_loaded) then |
||
383 | TitanPanelTitanBG_ToggleBattlefieldMinimap(); |
||
384 | TitanPanelTitanBG_ChangeAttachFlagTracker(); |
||
385 | end |
||
386 | end |
||
387 | |||
388 | |||
389 | -- ## Performs periodic updates. |
||
390 | function TitanPanelTitanBG_OnUpdate() |
||
391 | |||
392 | -- Check how much time the losing team has before they have to capture another node. |
||
393 | if (_player_zone == TITANBG_BG_AB and _addon_loaded and sv_menu["AddonEnabled"]) then |
||
394 | |||
395 | -- Checks the amount of time until the amount of nodes needing to be captured increases. |
||
396 | -- Cannot be done as a basic loop as it can lock up the game. |
||
397 | if (GetTime() - _ab_timeinc_update >= _ab_timeing_update_delay) then |
||
398 | _ab_timeinc_update = GetTime(); |
||
399 | |||
400 | if (not _ab_timeinc_check) then |
||
401 | _ab_timeinc_sec = 0; |
||
402 | _ab_timeinc_check = true; |
||
403 | end |
||
404 | |||
405 | _ab_timeinc_sec = _ab_timeinc_sec + 30; |
||
406 | |||
407 | local winner, win_time = TitanPanelTitanBG_AB_GetWinner(_active.stats.ab.bases_alliance, _active.stats.ab.bases_horde); |
||
408 | |||
409 | if (winner ~= nil) then |
||
410 | local complete = false; |
||
411 | |||
412 | -- If the player's faction isn't going to win. |
||
413 | if (winner ~= UnitFactionGroup("player")) then |
||
414 | local bases = TitanPanelTitanBG_AB_NodesRequiredToWin(_player_faction); |
||
415 | complete = TitanPanelTitanBG_AB_TimeLeftToCapture(_player_faction, bases, _ab_timeinc_sec); |
||
416 | |||
417 | -- Otherwise, if their faction is going to win. |
||
418 | else |
||
419 | local bases = TitanPanelTitanBG_AB_NodesRequiredToWin(_player_enemy_faction); |
||
420 | complete = TitanPanelTitanBG_AB_TimeLeftToCapture(_player_enemy_faction, bases, _ab_timeinc_sec); |
||
421 | end |
||
422 | |||
423 | if (complete) then |
||
424 | _ab_timeinc_check = false; |
||
425 | _timetonodeincrease = _ab_timeinc_sec; |
||
426 | end |
||
427 | |||
428 | if (win_time < _ab_timeinc_sec) then |
||
429 | _ab_timeinc_check = false; |
||
430 | _timetonodeincrease = win_time; |
||
431 | end |
||
432 | end |
||
433 | end |
||
434 | end |
||
435 | end |
||
436 | |||
437 | |||
438 | -- ############################ |
||
439 | -- ## BATTLEGROUND FUNCTIONS ## |
||
440 | -- ############################ |
||
441 | |||
442 | |||
443 | -- ## Performed when the user changes zones. |
||
444 | function TitanPanelTitanBG_ZonesChanged() |
||
445 | local zone = GetRealZoneText(); |
||
446 | |||
447 | if (zone ~= _player_zone) then |
||
448 | _player_zone = zone; |
||
449 | |||
450 | -- Reset any existing active battleground information. |
||
451 | TitanPanelTitanBG_ResetActiveInformation(); |
||
452 | |||
453 | -- If this is a battleground. |
||
454 | if (TitanPanelTitanBG_IsBattleground(_player_zone)) then |
||
455 | |||
456 | -- Store any existing captures. |
||
457 | _active.captures = { }; |
||
458 | TitanPanelTitanBG_CheckMap(_player_zone, true); |
||
459 | |||
460 | _active_init_stored = true; |
||
461 | |||
462 | _autojoin_bg = ""; |
||
463 | _autojoin_time = 0; |
||
464 | _autojoin_paused = 0; |
||
465 | |||
466 | _autoleave_time = 0; |
||
467 | _autoleave_paused = 0; |
||
468 | end |
||
469 | |||
470 | -- Reset basic battleground data. |
||
471 | TitanPanelTitanBG_ResetBattlegroundInformation(); |
||
472 | |||
473 | -- Reset zone data. |
||
474 | _blizzard_manualshowbg = nil; |
||
475 | _display_queue_tt = false; |
||
476 | _ab_timeinc_check = false; |
||
477 | |||
478 | -- Check if the battleground minimap needs to be shown. |
||
479 | if (_addon_loaded) then |
||
480 | |||
481 | -- Hide and show items as necessary. |
||
482 | TitanPanelTitanBG_ToggleLockCaptures(); |
||
483 | TitanPanelTitanBG_ToggleMiniMapIcon(); |
||
484 | TitanPanelTitanBG_HideBattlegroundReadyPopup(); |
||
485 | TitanPanelTitanBG_ToggleClickFlagRunner(); |
||
486 | TitanPanelTitanBG_InvertFlagTracker(); |
||
487 | |||
488 | -- Update non titan display of captures and flags. |
||
489 | TitanPanelTitanBG_NT_UpdateCaptures(true); |
||
490 | TitanPanelTitanBG_NT_UpdateFlags(); |
||
491 | end |
||
492 | end |
||
493 | end |
||
494 | |||
495 | |||
496 | -- ## Determines if a given zone is a battleground. |
||
497 | function TitanPanelTitanBG_IsBattleground(zone) |
||
498 | if (zone == TITANBG_BG_AV or zone == TITANBG_BG_AB or zone == TITANBG_BG_WSG) then |
||
499 | return true; |
||
500 | else |
||
501 | return false; |
||
502 | end |
||
503 | end |
||
504 | |||
505 | |||
506 | -- ## Stores information on a battleground and performs any actions based on this information that require periodic checks. |
||
507 | function TitanPanelTitanBG_StoreBattlegroundInformation() |
||
508 | if (_update_number > 1000) then _update_number = 0; end |
||
509 | |||
510 | _bgs.queue = 0; |
||
511 | |||
512 | -- Perform battlefield actions. |
||
513 | for i = 1, MAX_BATTLEFIELD_QUEUES do |
||
514 | local status, name, instance = GetBattlefieldStatus(i); |
||
515 | |||
516 | -- If this battleground is active, collect information on this battleground. |
||
517 | if (status == TITANBG_BG_STATUS_ACTIVE) then |
||
518 | |||
519 | -- Update friend information. |
||
520 | if (not _friendasked) then |
||
521 | ShowFriends(); |
||
522 | _friendasked = true; |
||
523 | end |
||
524 | |||
525 | if (GetBattlefieldWinner() ~= nil) then |
||
526 | |||
527 | -- If a battleground is finished, get ready to leave it. |
||
528 | if (sv_menu["B_AutoLeaveBG"] and _autoleave_time == 0) then |
||
529 | _autoleave_time = GetTime() + _autoleave_delay; |
||
530 | _autoleave_paused = 0; |
||
531 | end |
||
532 | |||
533 | -- If paused, update timer. |
||
534 | if (_autoleave_paused > 0 and sv_menu["B_AutoLeaveBG"]) then |
||
535 | _autoleave_time = _autoleave_paused + GetTime(); |
||
536 | end |
||
537 | |||
538 | -- Auto leave a battleground if complete. |
||
539 | if (TitanPanelTitanBG_IsBattleground(_player_zone) and sv_menu["B_AutoLeaveBG"] and math.floor(_autoleave_time - GetTime()) <= 0) then |
||
540 | TitanPanelTitanBG_AcceptBattlefieldPort(i, nil, true); |
||
541 | _autoleave_time = 0; |
||
542 | _autoleave_paused = 0; |
||
543 | end |
||
544 | end |
||
545 | |||
546 | TitanPanelTitanBG_StoreActiveInformation(name, status, instance, i); |
||
547 | |||
548 | -- Otherwise, if this battleground is waiting for confirmation, perform auto join. |
||
549 | elseif (status == TITANBG_BG_STATUS_CONFIRM) then |
||
550 | |||
551 | -- If a battleground is ready for confirmation, start the auto join timer. |
||
552 | if (sv_menu["B_AutoJoinBG"] and (_autojoin_bg == "" or _autojoin_bg == nil)) then |
||
553 | _autojoin_bg = name; |
||
554 | _autojoin_time = GetTime() + _autojoin_delay; |
||
555 | _autojoin_paused = 0; |
||
556 | end |
||
557 | |||
558 | -- If paused, update timer. |
||
559 | if (_autojoin_paused > 0 and sv_menu["B_AutoJoinBG"]) then |
||
560 | _autojoin_time = _autojoin_paused + GetTime(); |
||
561 | end |
||
562 | |||
563 | -- Auto join a battleground if not already in a battleground. |
||
564 | if (not TitanPanelTitanBG_IsBattleground(_player_zone) and _autojoin_bg == name and math.floor(_autojoin_time - GetTime()) <= 0) then |
||
565 | TitanPanelTitanBG_AutoJoinBattleground(i); |
||
566 | end |
||
567 | end |
||
568 | |||
569 | -- If this is a battleground, store status infromation. |
||
570 | if (TitanPanelTitanBG_IsBattleground(name)) then |
||
571 | if (status == TITANBG_BG_STATUS_QUEUED or status == TITANBG_BG_STATUS_CONFIRM) then |
||
572 | _bgs.queue = _bgs.queue + 1; |
||
573 | end |
||
574 | |||
575 | -- Check if a new sound needs to be played. |
||
576 | if (_bgs.names[name].status ~= status and status == TITANBG_BG_STATUS_CONFIRM) then |
||
577 | _bgs.names[name].sound = true; |
||
578 | _bgs.names[name].sound_timer = 0; |
||
579 | |||
580 | elseif (status ~= TITANBG_BG_STATUS_CONFIRM) then |
||
581 | _bgs.names[name].sound = false; |
||
582 | _bgs.names[name].sound_timer = 0; |
||
583 | end |
||
584 | |||
585 | -- Play a new sound for this battleground. |
||
586 | if (_bgs.names[name].sound and sv_menu["D_S_PlayWhatSound"] > 0) then |
||
587 | local PlayReadySound = function() |
||
588 | if (sv_menu["D_S_PlayWhatSound"] == 1) then |
||
589 | PlaySound("PVPTHROUGHQUEUE", true); |
||
590 | else |
||
591 | PlaySoundFile(TITANBG_SOUNDS_BGWARNING[sv_menu["D_S_PlayWhatSound"]].file); |
||
592 | end |
||
593 | end |
||
594 | |||
595 | -- If repeat the sound periodically. |
||
596 | if (sv_menu["D_S_RepeatSound"]) then |
||
597 | if (GetTime() - _bgs.names[name].sound_timer >= _bgready_sound_delay) then |
||
598 | _bgs.names[name].sound_timer = GetTime(); |
||
599 | |||
600 | PlayReadySound(); |
||
601 | end |
||
602 | else |
||
603 | PlayReadySound(); |
||
604 | _bgs.names[name].sound = false; |
||
605 | end |
||
606 | end |
||
607 | |||
608 | _bgs.names[name].index = i; |
||
609 | _bgs.names[name].status = status; |
||
610 | _bgs.names[name].instance = instance; |
||
611 | _bgs.names[name].update = _update_number; |
||
612 | |||
613 | if (status == TITANBG_BG_STATUS_CONFIRM) then |
||
614 | _bgs.names[name].expires = GetBattlefieldPortExpiration(i) / 1000; |
||
615 | else |
||
616 | _bgs.names[name].expires = 0; |
||
617 | end |
||
618 | |||
619 | _bgs.blizzard[i] = name; |
||
620 | |||
621 | -- Otherwise, this slot is not being used by blizzard. |
||
622 | else |
||
623 | if (_bgs.blizzard[i]) then |
||
624 | _bgs.blizzard[i] = nil; |
||
625 | end |
||
626 | end |
||
627 | end |
||
628 | |||
629 | -- Reset all the battlegrounds that were not updated. |
||
630 | for i = 1, table.getn(_bgs.index) do |
||
631 | if (_bgs.names[_bgs.index[i]].update ~= _update_number) then |
||
632 | _bgs.names[_bgs.index[i]].index = 0; |
||
633 | _bgs.names[_bgs.index[i]].status = TITANBG_BG_STATUS_NONE; |
||
634 | _bgs.names[_bgs.index[i]].instance = 0; |
||
635 | |||
636 | _bgs.names[_bgs.index[i]].update = nil; |
||
637 | _bgs.names[_bgs.index[i]].expires = 0; |
||
638 | |||
639 | _bgs.names[_bgs.index[i]].sound = false; |
||
640 | _bgs.names[_bgs.index[i]].sound_timer = 0; |
||
641 | |||
642 | if (_autojoin_bg == _bgs.index[i]) then |
||
643 | _autojoin_bg = ""; |
||
644 | _autojoin_time = 0; |
||
645 | _autojoin_paused = 0; |
||
646 | end |
||
647 | end |
||
648 | end |
||
649 | |||
650 | local i = 1; |
||
651 | |||
652 | -- Process battleround popups. |
||
653 | if (_titan_loaded and _addon_loaded and not sv_menu["B_HideJoinPopup"]) then |
||
654 | while (i <= table.getn(_popups)) do |
||
655 | |||
656 | if ((_popups[i].dialog.text_arg1 == _popups[i].text_arg1 and _popups[i].dialog.text_arg2 == _popups[i].text_arg2) and _popups[i].which == "CONFIRM_BATTLEFIELD_ENTRY" and (_bgs.blizzard[_popups[i].data] and _bgs.names[_bgs.blizzard[_popups[i].data]].status == TITANBG_BG_STATUS_CONFIRM)) then |
||
657 | local expire = ""; |
||
658 | |||
659 | -- Check if the queue expire time is to be shown. |
||
660 | if (sv_menu["D_POP_QueueExpire"]) then |
||
661 | expire = " (" .. TITANBG_COLOR_RED .. SecondsToTime(GetBattlefieldPortExpiration(_popups[i].data) / 1000) .. TITANBG_COLOR_GREEN .. ")"; |
||
662 | end |
||
663 | |||
664 | -- If the user is not already in a battleground and is autojoining. |
||
665 | if (TitanPanelTitanBG_IsBattleground(_player_zone) == false and sv_menu["B_AutoJoinBG"] and _autojoin_time > GetTime() and string.find(_popups[i].text_arg1, _autojoin_bg)) then |
||
666 | local autojoin = SecondsToTime(_autojoin_time - GetTime()); |
||
667 | |||
668 | if (_autojoin_paused > 0) then |
||
669 | autojoin = autojoin .. TITANBG_COLOR_WHITE .. "(" .. TITANBG_TOOLTIP_PAUSED .. ")"; |
||
670 | getglobal(_popups[i].dialog:GetName().."Button2"):SetText(TITANBG_TOOLTIP_UNPAUSE); |
||
671 | else |
||
672 | getglobal(_popups[i].dialog:GetName().."Button2"):SetText(KEY_PAUSE); |
||
673 | end |
||
674 | |||
675 | _popups[i].text:SetText(TITANBG_COLOR_GREEN .. string.gsub(string.gsub(TITANBG_AUTOJOIN, "{bg}", TITANBG_COLOR_WHITE .. _popups[i].text_arg1 .. TITANBG_COLOR_GREEN, 1), "{time}", TITANBG_COLOR_YELLOW .. autojoin .. TITANBG_COLOR_GREEN .. expire, 1)); |
||
676 | |||
677 | -- If the user is in a battleground or is not autojoining. |
||
678 | else |
||
679 | _popups[i].text:SetText(TITANBG_COLOR_GREEN .. string.gsub(string.gsub(TITANBG_CONFIRMJOIN, "{bg}", TITANBG_COLOR_WHITE .. _popups[i].text_arg1 .. TITANBG_COLOR_GREEN, 1), "{time}", TITANBG_COLOR_GREEN .. expire, 1)); |
||
680 | end |
||
681 | else |
||
682 | table.remove(_popups, i); |
||
683 | i = i - 1; |
||
684 | end |
||
685 | |||
686 | i = i + 1; |
||
687 | end |
||
688 | end |
||
689 | |||
690 | _update_number = _update_number + 1; |
||
691 | end |
||
692 | |||
693 | |||
694 | -- ## Stores information about the instances that were active when a user looked at the queue window. |
||
695 | function TitanPanelTitanBG_StoreActiveInstanceInformation() |
||
696 | local name, _, _, _, _, _, _, _, _ = GetBattlefieldInfo(); |
||
697 | local instances = GetNumBattlefields(); |
||
698 | local bg = _bgs.names[name]; |
||
699 | |||
700 | if (bg ~= nil) then |
||
701 | bg.open_instances = instances; |
||
702 | bg.open_age = GetTime(); |
||
703 | end |
||
704 | end |
||
705 | |||
706 | |||
707 | -- ## Indicates if the person is currently in a battleground queue or in a battleground. |
||
708 | function TitanPanelTitanBG_InBGQueue() |
||
709 | local in_queue = false; |
||
710 | |||
711 | -- Loop through and check on the status of the battlegrounds. |
||
712 | for i = 1, MAX_BATTLEFIELD_QUEUES do |
||
713 | local status, _, _ = GetBattlefieldStatus(i); |
||
714 | |||
715 | -- If the user is in a queue or in a battleground. |
||
716 | if (status ~= TITANBG_BG_STATUS_NONE) then |
||
717 | |||
718 | in_queue = true; |
||
719 | break; |
||
720 | end |
||
721 | end |
||
722 | |||
723 | return in_queue; |
||
724 | end |
||
725 | |||
726 | |||
727 | -- ## Collects information on a specified battleground. |
||
728 | function TitanPanelTitanBG_StoreActiveInformation(bg_name, bg_status, bg_instance, bg_i) |
||
729 | |||
730 | -- Request new data for GetBattlefieldScore(). |
||
731 | RequestBattlefieldScoreData(); |
||
732 | |||
733 | -- Run checks on the battlefield map information. |
||
734 | if (_active_init_stored) then |
||
735 | TitanPanelTitanBG_CheckMap(bg_name, false); |
||
736 | end |
||
737 | |||
738 | -- Clear the friend's list string. |
||
739 | _friendstring = ""; |
||
740 | |||
741 | _active.stats.bg.name = bg_name; |
||
742 | _active.stats.bg.index = bg_i; |
||
743 | _active.stats.bg.instance = bg_instance; |
||
744 | _active.stats.bg.run = GetBattlefieldInstanceRunTime(); |
||
745 | _active.stats.bg.total = 0; |
||
746 | _active.stats.bg.horde = 0; |
||
747 | _active.stats.bg.alliance = 0; |
||
748 | |||
749 | -- Loop through all the players. |
||
750 | for i = 1, 80 do |
||
751 | local name, killingblows, kills, deaths, honor, faction, rank, race, class = GetBattlefieldScore(i); |
||
752 | |||
753 | local player_id = ""; |
||
754 | local player_name = ""; |
||
755 | local server = ""; |
||
756 | |||
757 | if (name ~= nil) then |
||
758 | _active.stats.bg.total = _active.stats.bg.total + 1; |
||
759 | |||
760 | if (string.find(name, "-")) then |
||
761 | server = string.sub(name, string.find(name, "-") + 1, string.len(name)); |
||
762 | player_name = string.sub(name, 1, string.find(name, "-") - 1); |
||
763 | else |
||
764 | player_name = name; |
||
765 | server = _player_realm; |
||
766 | end |
||
767 | |||
768 | if (faction == 0) then |
||
769 | _active.stats.bg.horde = _active.stats.bg.horde + 1; |
||
770 | player_id = player_name .. "|Horde"; |
||
771 | else |
||
772 | _active.stats.bg.alliance = _active.stats.bg.alliance + 1; |
||
773 | player_id = player_name .. "|Alliance"; |
||
774 | end |
||
775 | |||
776 | local player = TitanBG_GetPlayerData(player_id); |
||
777 | |||
778 | -- Store the player information. |
||
779 | if (not player and player_name ~= "" and player_name ~= nil) then |
||
780 | player = { id = player_id, |
||
781 | name = player_name, |
||
782 | server = server, |
||
783 | faction = faction, |
||
784 | class = class, |
||
785 | rank = rank, }; |
||
786 | |||
787 | table.insert(_active.stats.wsg.players, player); |
||
788 | end |
||
789 | end |
||
790 | |||
791 | -- If this is the current player. |
||
792 | if (player_name == _player_name) then |
||
793 | |||
794 | _active.stats.player.standing = i; |
||
795 | _active.stats.player.kills = kills; |
||
796 | _active.stats.player.deaths = deaths; |
||
797 | _active.stats.player.killing_blows = killingblows; |
||
798 | _active.stats.player.honor = honor; |
||
799 | |||
800 | -- Create the friend's list string. |
||
801 | elseif ( _friendlist[name] and sv_menu["D_TT_Friends"] ) then |
||
802 | _friendstring = _friendstring.."\n"..name.."\t"; |
||
803 | _friendstring = _friendstring..TitanUtils_GetHighlightText("#: ")..TitanUtils_GetGreenText(i)..", "; |
||
804 | _friendstring = _friendstring..TitanUtils_GetHighlightText(TITANBG_S_KILLINGBLOWS)..TitanUtils_GetGreenText(killingblows)..", "; |
||
805 | _friendstring = _friendstring..TitanUtils_GetHighlightText(TITANBG_S_KILLS)..TitanUtils_GetGreenText(kills)..", "; |
||
806 | _friendstring = _friendstring..TitanUtils_GetHighlightText(TITANBG_S_DEATHS)..TitanUtils_GetRedText(deaths); |
||
807 | end |
||
808 | end |
||
809 | |||
810 | -- How many battleground statistics are there. |
||
811 | local sColumns = GetNumBattlefieldStats(); |
||
812 | |||
813 | -- Loop through the statistics. |
||
814 | for j = 1, MAX_NUM_STAT_COLUMNS do |
||
815 | |||
816 | if (j <= sColumns) then |
||
817 | local cData = GetBattlefieldStatData(_active.stats.player.standing, j); |
||
818 | |||
819 | -- Collect player capture stats on Alterac Valley. |
||
820 | if (bg_name == TITANBG_BG_AV) then |
||
821 | |||
822 | if (j == 1) then |
||
823 | _active.stats.av.gy_assulted = cData; |
||
824 | elseif (j == 2) then |
||
825 | _active.stats.av.gy_defended = cData; |
||
826 | elseif (j == 3) then |
||
827 | _active.stats.av.towers_assaulted = cData; |
||
828 | elseif (j == 4) then |
||
829 | _active.stats.av.towers_defended = cData; |
||
830 | elseif (j == 5) then |
||
831 | _active.stats.av.mines_captured = cData; |
||
832 | elseif (j == 6) then |
||
833 | _active.stats.av.leaders_killed = cData; |
||
834 | elseif (j == 7) then |
||
835 | _active.stats.av.secondary_obj = cData; |
||
836 | end |
||
837 | |||
838 | -- Collect player capture stats on Warsong Gulch. |
||
839 | elseif (name == TITANBG_BG_WSG) then |
||
840 | |||
841 | if (j == 1) then |
||
842 | _active.stats.wsg.flag_captures = cData; |
||
843 | elseif (j == 2) then |
||
844 | _active.stats.wsg.flag_returns = cData; |
||
845 | end |
||
846 | |||
847 | -- Collect player capture stats on Arathi Basin. |
||
848 | elseif (name == TITANBG_BG_AB) then |
||
849 | |||
850 | if (j == 1) then |
||
851 | _active.stats.ab.bases_assulted = cData; |
||
852 | elseif (j == 2) then |
||
853 | _active.stats.ab.bases_defended = cData; |
||
854 | end |
||
855 | end |
||
856 | end |
||
857 | end |
||
858 | end |
||
859 | |||
860 | |||
861 | -- ## Returns data on a player in the battleground. |
||
862 | -- ## |
||
863 | -- ## Variables |
||
864 | -- ## * id: Is the player 'name|faction'. For example, 'Maina|Alliance'. |
||
865 | function TitanBG_GetPlayerData(id) |
||
866 | for i = 1, table.getn(_active.stats.wsg.players) do |
||
867 | if (_active.stats.wsg.players[i].id == id) then |
||
868 | return _active.stats.wsg.players[i]; |
||
869 | end |
||
870 | end |
||
871 | |||
872 | return nil; |
||
873 | end |
||
874 | |||
875 | |||
876 | -- ## Checks on the location in the battleground and their capture status. |
||
877 | function TitanPanelTitanBG_CheckMap(bg_name, just_entered) |
||
878 | local marks = GetNumMapLandmarks(); |
||
879 | local delay = 0; |
||
880 | |||
881 | -- Reset base owned tracking variables. |
||
882 | _active.stats.ab.bases_alliance = 0; |
||
883 | _active.stats.ab.bases_horde = 0; |
||
884 | |||
885 | -- If this is a cap on enter, reset capture information. |
||
886 | if (just_entered) then |
||
887 | _active.captures = { }; |
||
888 | end |
||
889 | |||
890 | -- Determine delay based on battleground. |
||
891 | if (bg_name == TITANBG_BG_AV) then |
||
892 | delay = _capture_delay_av; |
||
893 | elseif (bg_name == TITANBG_BG_AB) then |
||
894 | delay = _capture_delay_ab; |
||
895 | end |
||
896 | |||
897 | for i = 1, marks, 1 do |
||
898 | local name, _, txture, _, _ = GetMapLandmarkInfo(i); |
||
899 | local owned = TitanPanelTitanBG_OwnedBy(txture); |
||
900 | |||
901 | -- Determine who this item is owned by and if we are in ab, increase the count for that faction. |
||
902 | if (bg_name == TITANBG_BG_AB) then |
||
903 | if (owned == "Alliance") then |
||
904 | _active.stats.ab.bases_alliance = _active.stats.ab.bases_alliance + 1; |
||
905 | elseif (owned == "Horde") then |
||
906 | _active.stats.ab.bases_horde = _active.stats.ab.bases_horde + 1; |
||
907 | end |
||
908 | end |
||
909 | |||
910 | -- Set up the local capture information. |
||
911 | local c = { |
||
912 | name = "", -- What is the name of this item. |
||
913 | cap = 0, -- Time when the point will be capped. If zero, capped on enter. |
||
914 | who = "", -- Who the point will be capped by. |
||
915 | t = 15, -- The texture of the cap. |
||
916 | }; |
||
917 | |||
918 | -- Store data. |
||
919 | c.name = name; |
||
920 | c.who = TitanPanelTitanBG_CappedBy(txture); |
||
921 | c.t = txture; |
||
922 | |||
923 | -- Location of the capture in the capture's list. |
||
924 | local loc = -1; |
||
925 | |||
926 | -- Loop through and find the capture if it is in the list. |
||
927 | if (table.getn(_active.captures) > 0) then |
||
928 | for j = 1, table.getn(_active.captures) do |
||
929 | |||
930 | if (_active.captures[j].name == c.name) then |
||
931 | loc = j; |
||
932 | break; |
||
933 | end |
||
934 | end |
||
935 | end |
||
936 | |||
937 | -- If this is a new item being contested, store data. |
||
938 | if (loc == -1 and c.who ~= "") then |
||
939 | |||
940 | -- If the time capped is known, store the time to cap. |
||
941 | if (not just_entered) then |
||
942 | c.cap = GetTime() + delay; |
||
943 | end |
||
944 | |||
945 | table.insert(_active.captures, c); |
||
946 | |||
947 | -- Otherwise, remove any item not contested. |
||
948 | elseif (loc > -1 and (c.who == "" or (c.who ~= "" and _active.captures[loc].who ~= c.who))) then |
||
949 | table.remove(_active.captures, loc); |
||
950 | end |
||
951 | end |
||
952 | |||
953 | -- If this is Warsong Gulch, collect flag information. |
||
954 | if (_player_zone == TITANBG_BG_WSG) then |
||
955 | _active.stats.wsg.alliance.flag = GetWorldStateUIInfo(1); |
||
956 | _active.stats.wsg.horde.flag = GetWorldStateUIInfo(2); |
||
957 | |||
958 | -- Collect alliance flag information. |
||
959 | if (_active.stats.wsg.alliance.msg ~= "") then |
||
960 | |||
961 | -- Flag picked up. The faction the message is for is the same as the faction of the player carrying the flag. |
||
962 | -- "The Horde flag was picked up by Maina!". |
||
963 | if (string.find(_active.stats.wsg.alliance.msg, TITANBG_WSG_PICKEDUP)) then |
||
964 | _active.stats.wsg.alliance.msg = string.gsub(_active.stats.wsg.alliance.msg, TITANBG_WSG_PICKEDUP, ""); |
||
965 | _active.stats.wsg.alliance.player = string.sub(_active.stats.wsg.alliance.msg, string.find(_active.stats.wsg.alliance.msg, "([^%p^%s]+)")); |
||
966 | |||
967 | -- Flag dropped. The faction the message is for is the faction that owns the flag. The player dropping the flag is the enemy. |
||
968 | -- "The Alliance flag was dropped by Maina!". |
||
969 | elseif (string.find(_active.stats.wsg.alliance.msg, TITANBG_WSG_DROPPED)) then |
||
970 | _active.stats.wsg.horde.player = ""; |
||
971 | |||
972 | -- Flag captured. The faction the message is for is the same as the faction of the player carrying the flag. |
||
973 | -- "Maina captured the Horde flag!". |
||
974 | elseif (string.find(_active.stats.wsg.alliance.msg, TITANBG_WSG_CAPTURED)) then |
||
975 | _active.stats.wsg.alliance.player = ""; |
||
976 | end |
||
977 | |||
978 | _active.stats.wsg.alliance.msg = ""; |
||
979 | end |
||
980 | |||
981 | -- Collect horde flag information. |
||
982 | if (_active.stats.wsg.horde.msg ~= "") then |
||
983 | |||
984 | -- Flag picked up. The faction the message is for is the same as the faction of the player carrying the flag. |
||
985 | -- "The Alliance flag was picked up by Maina!". |
||
986 | if (string.find(_active.stats.wsg.horde.msg, TITANBG_WSG_PICKEDUP)) then |
||
987 | _active.stats.wsg.horde.msg = string.gsub(_active.stats.wsg.horde.msg, TITANBG_WSG_PICKEDUP, ""); |
||
988 | _active.stats.wsg.horde.player = string.sub(_active.stats.wsg.horde.msg, string.find(_active.stats.wsg.horde.msg, "([^%p^%s]+)")); |
||
989 | |||
990 | -- Flag dropped. The faction the message is for is the faction that owns the flag. The player dropping the flag is the enemy. |
||
991 | -- "The Horde flag was dropped by Maina!". |
||
992 | elseif (string.find(_active.stats.wsg.horde.msg, TITANBG_WSG_DROPPED)) then |
||
993 | _active.stats.wsg.alliance.player = ""; |
||
994 | |||
995 | -- Flag captured. The faction the message is for is the same as the faction of the player carrying the flag. |
||
996 | -- "Maina captured the Alliance flag!". |
||
997 | elseif (string.find(_active.stats.wsg.horde.msg, TITANBG_WSG_CAPTURED)) then |
||
998 | _active.stats.wsg.horde.player = ""; |
||
999 | end |
||
1000 | |||
1001 | _active.stats.wsg.horde.msg = ""; |
||
1002 | end |
||
1003 | end |
||
1004 | end |
||
1005 | |||
1006 | |||
1007 | -- TEXTURE KEY (Alterac Valley) |
||
1008 | -- |
||
1009 | -- Mine |
||
1010 | -- 0: None |
||
1011 | -- 1: Horde |
||
1012 | -- 2: Alliance |
||
1013 | -- |
||
1014 | -- Graveyard |
||
1015 | -- 7: Free |
||
1016 | -- 12: Horde |
||
1017 | -- 3: Contested (Horde, Assulted by the Alliance) |
||
1018 | -- 14: Alliance |
||
1019 | -- 13: Contested (Alliance, Assulted by the Horde) |
||
1020 | -- |
||
1021 | -- Tower |
||
1022 | -- 9: Horde |
||
1023 | -- 8: Contested (Horde, Assulted by the Alliance) |
||
1024 | -- 10: Alliance |
||
1025 | -- 11: Contested (Alliance, Assulted by the Horde) |
||
1026 | |||
1027 | -- TEXTURE KEY (Arathi Basin) |
||
1028 | -- |
||
1029 | -- Lumber Mill |
||
1030 | -- 21: None |
||
1031 | -- 25: Horde |
||
1032 | -- 22: Contested (Horde, Assulted by the Alliance) |
||
1033 | -- 23: Alliance |
||
1034 | -- 24: Contested (Alliance, Assulted by the Horde) |
||
1035 | -- |
||
1036 | -- Mine |
||
1037 | -- 16: None |
||
1038 | -- 20: Horde |
||
1039 | -- 17: Contested (Horde, Assulted by the Alliance) |
||
1040 | -- 18: Alliance |
||
1041 | -- 19: Contested (Alliance, Assulted by the Horde) |
||
1042 | -- |
||
1043 | -- Blacksmith |
||
1044 | -- 26: None |
||
1045 | -- 30: Horde |
||
1046 | -- 27: Contested (Horde, Assulted by the Alliance) |
||
1047 | -- 28: Alliance |
||
1048 | -- 29: Contested (Alliance, Assulted by the Horde) |
||
1049 | -- |
||
1050 | -- Farm |
||
1051 | -- 31: None |
||
1052 | -- 35: Horde |
||
1053 | -- 32: Contested (Horde, Assulted by the Alliance) |
||
1054 | -- 33: Alliance |
||
1055 | -- 34: Contested (Alliance, Assulted by the Horde) |
||
1056 | -- |
||
1057 | -- Stables |
||
1058 | -- 36: None |
||
1059 | -- 40: Horde |
||
1060 | -- 37: Contested (Horde, Assulted by the Alliance) |
||
1061 | -- 38: Alliance |
||
1062 | -- 39: Contested (Alliance, Assulted by the Horde) |
||
1063 | |||
1064 | |||
1065 | -- ## Determines who the point will be capped by. If not under contestation, return a zero length string. |
||
1066 | function TitanPanelTitanBG_CappedBy(t) |
||
1067 | local capped = ""; |
||
1068 | |||
1069 | if (t == 3 or t == 8 or t == 22 or t == 17 or t == 27 or t == 32 or t == 37) then |
||
1070 | capped = "Alliance"; |
||
1071 | elseif (t == 13 or t == 11 or t == 24 or t == 19 or t == 29 or t == 34 or t == 39) then |
||
1072 | capped = "Horde"; |
||
1073 | end |
||
1074 | |||
1075 | return capped; |
||
1076 | end |
||
1077 | |||
1078 | |||
1079 | -- ## Determines who owns the point, if it is not under contestation. Otherwise, returns a zero length string. |
||
1080 | function TitanPanelTitanBG_OwnedBy(t) |
||
1081 | local owned = ""; |
||
1082 | |||
1083 | if (t == 2 or t == 14 or t == 10 or t == 23 or t == 18 or t == 28 or t == 33 or t == 38) then |
||
1084 | owned = "Alliance"; |
||
1085 | elseif (t == 1 or t == 12 or t == 9 or t == 25 or t == 20 or t == 30 or t == 35 or t == 40) then |
||
1086 | owned = "Horde"; |
||
1087 | end |
||
1088 | |||
1089 | return owned; |
||
1090 | end |
||
1091 | |||
1092 | |||
1093 | -- ## Automatically joins a battleground. |
||
1094 | function TitanPanelTitanBG_AutoJoinBattleground(i) |
||
1095 | if (sv_menu["B_AutoJoinBG"]) then |
||
1096 | TitanPanelTitanBG_AcceptBattlefieldPort(i, 1, true); |
||
1097 | _autojoin_bg = ""; |
||
1098 | _autojoin_time = 0; |
||
1099 | end |
||
1100 | end |
||
1101 | |||
1102 | |||
1103 | -- ## Determines who is likely to win the Arathi Basin game. |
||
1104 | -- ## |
||
1105 | -- ## Variables |
||
1106 | -- ## * b_alliance: Number of bases held by the Alliance. |
||
1107 | -- ## * b_horde: Number of bases held by the Horde. |
||
1108 | -- ## * a_extra: Extra resources to add to the alliance side when performing a future prediction check. |
||
1109 | -- ## * h_extra: Extra resources to add to the horde side when performing a future prediction check. |
||
1110 | -- ## |
||
1111 | -- ## Returns |
||
1112 | -- ## * The team that will win. Nil/"Horde"/"Alliance". |
||
1113 | -- ## * The amount of time it will take them to win. Nil/time in seconds. |
||
1114 | -- ## * Final score held by the Alliance. |
||
1115 | -- ## * Final score held by the Horde. |
||
1116 | function TitanPanelTitanBG_AB_GetWinner(b_alliance, b_horde, a_extra, h_extra) |
||
1117 | |||
1118 | -- Get the amount of resources held by the teams. |
||
1119 | local a_resources, h_resources = TitanPanelTitanBG_AB_GetResources(); |
||
1120 | |||
1121 | -- -- If we are checking possible future scenarios, add the extra resources. |
||
1122 | if (a_extra ~= nil and h_extra ~= nil) then |
||
1123 | a_resources = a_resources + a_extra; |
||
1124 | h_resources = h_resources + h_extra; |
||
1125 | end |
||
1126 | |||
1127 | -- Get the amount of resources per second. |
||
1128 | local a_res_sec = TitanPanelTitanBG_AB_GetResourcesPerSecond(b_alliance); |
||
1129 | local h_res_sec = TitanPanelTitanBG_AB_GetResourcesPerSecond(b_horde); |
||
1130 | |||
1131 | -- The amount of time left until the team gathers 2000 resources. |
||
1132 | local a_timeleft = -1; |
||
1133 | local h_timeleft = -1; |
||
1134 | |||
1135 | -- Catch division by zero exceptions. |
||
1136 | if (a_res_sec > 0) then |
||
1137 | a_timeleft = (2000 - a_resources) / a_res_sec; |
||
1138 | end |
||
1139 | |||
1140 | if (h_res_sec > 0) then |
||
1141 | h_timeleft = (2000 - h_resources) / h_res_sec; |
||
1142 | end |
||
1143 | |||
1144 | -- Determine final scores at the end. |
||
1145 | local a_final = a_resources; |
||
1146 | local h_final = h_resources; |
||
1147 | |||
1148 | if (a_res_sec > 0) then |
||
1149 | a_final = math.floor((a_final + (math.floor(h_timeleft / 30) * (a_res_sec * 30))) / 10) * 10; |
||
1150 | end |
||
1151 | |||
1152 | if (h_res_sec > 0) then |
||
1153 | h_final = math.floor((h_final + (math.floor(a_timeleft / 30) * (h_res_sec * 30))) / 10) * 10; |
||
1154 | end |
||
1155 | |||
1156 | -- Unknown who will win. |
||
1157 | if (a_timeleft == -1 and h_timeleft == -1) then |
||
1158 | return nil, nil, nil, nil; |
||
1159 | |||
1160 | -- Alliance will win. |
||
1161 | elseif ((a_timeleft > -1 and a_timeleft < h_timeleft) or (a_timeleft > -1 and h_timeleft == -1)) then |
||
1162 | return "Alliance", a_timeleft, 2000, h_final; |
||
1163 | |||
1164 | -- Horde will win. |
||
1165 | elseif ((h_timeleft > -1 and h_timeleft < a_timeleft) or (h_timeleft > -1 and a_timeleft == -1)) then |
||
1166 | return "Horde", h_timeleft, a_final, 2000; |
||
1167 | end |
||
1168 | |||
1169 | -- Otherwise return unknown. |
||
1170 | return nil, nil, nil, nil; |
||
1171 | end |
||
1172 | |||
1173 | |||
1174 | -- ## Determines how many resources per second a team gets with the amount of bases they're holding. |
||
1175 | function TitanPanelTitanBG_AB_GetResourcesPerSecond(bases) |
||
1176 | if (bases == 1) then |
||
1177 | return (25.0 / 30.0); |
||
1178 | elseif (bases == 2) then |
||
1179 | return (300.0 / 9.0) / 30.0; |
||
1180 | elseif (bases == 3) then |
||
1181 | return 50.0 / 30.0; |
||
1182 | elseif (bases == 4) then |
||
1183 | return 100.0 / 30.0; |
||
1184 | elseif (bases == 5) then |
||
1185 | return 900.0 / 30.0; |
||
1186 | else |
||
1187 | return 0; |
||
1188 | end |
||
1189 | end |
||
1190 | |||
1191 | -- ## Gets the current resources for both factions. |
||
1192 | function TitanPanelTitanBG_AB_GetResources() |
||
1193 | local a_resources = 0; |
||
1194 | local h_resources = 0; |
||
1195 | |||
1196 | -- Get the amount of resources owned by each team. |
||
1197 | local _, a_text, _, _, _, _ = GetWorldStateUIInfo(1); |
||
1198 | local _, h_text, _, _, _, _ = GetWorldStateUIInfo(2); |
||
1199 | |||
1200 | -- Extract the resources. |
||
1201 | if (a_text and h_text and _player_zone == TITANBG_BG_AB and string.find(a_text, TITANBG_AB_RESOURCES_DP) and string.find(h_text, TITANBG_AB_RESOURCES_DP)) then |
||
1202 | a_resources = string.sub(a_text, string.find(a_text, TITANBG_AB_RESOURCES_DP) + 11, string.find(a_text, "/") - 1); |
||
1203 | h_resources = string.sub(h_text, string.find(h_text, TITANBG_AB_RESOURCES_DP) + 11, string.find(h_text, "/") - 1); |
||
1204 | end |
||
1205 | |||
1206 | return a_resources, h_resources; |
||
1207 | end |
||
1208 | |||
1209 | |||
1210 | -- ## Determines how many nodes are required to win. |
||
1211 | -- ## |
||
1212 | -- ## Returns |
||
1213 | -- ## * TITANBG_AB_IMPOSSIBLE: If not possible to win. |
||
1214 | -- ## OR: Number of nodes required to win. |
||
1215 | function TitanPanelTitanBG_AB_NodesRequiredToWin(faction, a_resources, h_resources) |
||
1216 | local nodes = TITANBG_AB_IMPOSSIBLE; |
||
1217 | local bases = 0; |
||
1218 | |||
1219 | -- Determine which faction we are checking is. |
||
1220 | if (faction == TITANBG_ALLIANCE) then |
||
1221 | bases = _active.stats.ab.bases_alliance; |
||
1222 | else |
||
1223 | bases = _active.stats.ab.bases_horde; |
||
1224 | end |
||
1225 | |||
1226 | -- Try different base numbers. |
||
1227 | for i = 1, (5 - bases) do |
||
1228 | local winner = nil; |
||
1229 | |||
1230 | if (faction == TITANBG_ALLIANCE) then |
||
1231 | winner = TitanPanelTitanBG_AB_GetWinner(bases + i, _active.stats.ab.bases_horde - i, a_resources, h_resources); |
||
1232 | else |
||
1233 | winner = TitanPanelTitanBG_AB_GetWinner(_active.stats.ab.bases_alliance - i, bases + i, a_resouces, h_resources); |
||
1234 | end |
||
1235 | |||
1236 | -- If the winner is the faction, then stop. |
||
1237 | if (winner == faction) then |
||
1238 | nodes = i; |
||
1239 | break; |
||
1240 | end |
||
1241 | end |
||
1242 | |||
1243 | return nodes; |
||
1244 | end |
||
1245 | |||
1246 | -- ## Determines how long it will take until the amount of nodes needing to be captured in order to win increases. |
||
1247 | -- ## |
||
1248 | -- ## Variables |
||
1249 | -- ## * faction: The faction we are checking. |
||
1250 | -- ## * initial: The number of nodes that need to be captured by the faction in order to win. |
||
1251 | function TitanPanelTitanBG_AB_TimeLeftToCapture(faction, initial, seconds) |
||
1252 | local nodes = nil; |
||
1253 | local complete = false; |
||
1254 | |||
1255 | local a_resources = 0; |
||
1256 | local h_resources = 0; |
||
1257 | |||
1258 | -- Get the amount of resources per second. |
||
1259 | local a_res_sec = TitanPanelTitanBG_AB_GetResourcesPerSecond(_active.stats.ab.bases_alliance); |
||
1260 | local h_res_sec = TitanPanelTitanBG_AB_GetResourcesPerSecond(_active.stats.ab.bases_horde); |
||
1261 | |||
1262 | -- Get the amount of resources produced in this time period. |
||
1263 | a_resources = a_res_sec * seconds; |
||
1264 | h_resources = h_res_sec * seconds; |
||
1265 | |||
1266 | -- Check the amount of nodes |
||
1267 | nodes = TitanPanelTitanBG_AB_NodesRequiredToWin(faction, a_resources, h_resources); |
||
1268 | |||
1269 | if (nodes ~= initial) then |
||
1270 | complete = true; |
||
1271 | end |
||
1272 | |||
1273 | return complete; |
||
1274 | end |
||
1275 | |||
1276 | |||
1277 | -- ###################### |
||
1278 | -- ## ACTION FUNCTIONS ## |
||
1279 | -- ###################### |
||
1280 | |||
1281 | |||
1282 | -- ## Events that occur when the user clicks on the addon. |
||
1283 | function TitanPanelTitanBGButton_OnClick(button) |
||
1284 | if (button == "LeftButton") then |
||
1285 | |||
1286 | -- Check on auto join pauses. |
||
1287 | if (not TitanPanelTitanBG_IsBattleground(_player_zone)) then |
||
1288 | |||
1289 | -- If the user want to pause the auto join timer. |
||
1290 | if (sv_menu["B_AutoJoinBG"] and _autojoin_paused == 0) then |
||
1291 | _autojoin_paused = _autojoin_time - GetTime(); |
||
1292 | |||
1293 | -- If the user wants to unpause the auto join timer. |
||
1294 | elseif (sv_menu["B_AutoJoinBG"] and _autojoin_paused > 0) then |
||
1295 | _autojoin_paused = 0; |
||
1296 | end |
||
1297 | |||
1298 | -- Check on auto leave pauses. |
||
1299 | elseif (GetBattlefieldWinner() ~= nil) then |
||
1300 | |||
1301 | -- If the user want to pause the auto leave timer. |
||
1302 | if (sv_menu["B_AutoLeaveBG"] and _autoleave_paused == 0) then |
||
1303 | _autoleave_paused = _autoleave_time - GetTime(); |
||
1304 | |||
1305 | -- If the user wants to unpause the auto leave timer. |
||
1306 | elseif (sv_menu["B_AutoLeaveBG"] and _autoleave_paused > 0) then |
||
1307 | _autoleave_paused = 0; |
||
1308 | end |
||
1309 | end |
||
1310 | |||
1311 | -- Show the battlemap. |
||
1312 | if (IsShiftKeyDown() and not IsControlKeyDown()) then |
||
1313 | if ((sv_menu["B_AutoShowBGMinimap"] and BattlefieldMinimap:IsShown()) or (not TitanPanelTitanBG_IsBattleground(_player_zone) and BattlefieldMinimap:IsShown())) then |
||
1314 | _blizzard_manualshowbg = "HIDE"; |
||
1315 | elseif ((not sv_menu["B_AutoShowBGMinimap"] and not BattlefieldMinimap:IsShown()) or (not TitanPanelTitanBG_IsBattleground(_player_zone) and not BattlefieldMinimap:IsShown())) then |
||
1316 | _blizzard_manualshowbg = "SHOW"; |
||
1317 | else |
||
1318 | _blizzard_manualshowbg = nil; |
||
1319 | end |
||
1320 | |||
1321 | TitanPanelTitanBG_ToggleBattlefieldMinimap(); |
||
1322 | end |
||
1323 | |||
1324 | -- If the user is in a battleground. |
||
1325 | if (TitanPanelTitanBG_IsBattleground(_player_zone) and (GetBattlefieldWinner() == nil or not WorldStateScoreFrame:IsVisible()) and not IsControlKeyDown() and not IsShiftKeyDown()) then |
||
1326 | ToggleWorldStateScoreFrame(); |
||
1327 | end |
||
1328 | |||
1329 | _titan_titanbg_leftclick = true; |
||
1330 | end |
||
1331 | end |
||
1332 | |||
1333 | |||
1334 | -- ## Toggles a specified variable in the menu. |
||
1335 | function TitanPanelTitanBGButton_ToggleVar() |
||
1336 | TitanToggleVar(TITAN_TITANBG_ID, this.value); |
||
1337 | TitanPanelButton_UpdateButton(TITAN_TITANBG_ID); |
||
1338 | end |
||
1339 | |||
1340 | |||
1341 | -- ## Releases a player's corpse. |
||
1342 | function TitanPanelTitanBG_RepopMe() |
||
1343 | if ((sv_menu["B_AutoRelease"] and TitanPanelTitanBG_IsBattleground(_player_zone) and UnitIsDeadOrGhost("player")) or _blizzard_releasesoul) then |
||
1344 | if ((sv_menu["B_ReleaseCheck"] and not HasSoulstone()) or not sv_menu["B_ReleaseCheck"]) then |
||
1345 | Hook_RepopMe(); |
||
1346 | end |
||
1347 | end |
||
1348 | end |
||
1349 | |||
1350 | |||
1351 | -- ## Ports a user into the battleground, or leaves the queue. |
||
1352 | function TitanPanelTitanBG_AcceptBattlefieldPort(index, accept, titanbg) |
||
1353 | |||
1354 | -- Check if called by a blizzard drop down menu functions. |
||
1355 | if (this.arg1) then |
||
1356 | index = this.arg1; |
||
1357 | accept = this.arg2; |
||
1358 | titanbg = true; |
||
1359 | end |
||
1360 | |||
1361 | -- If called by a Blizzard or a TitanBG function, then perform this action. |
||
1362 | if (_blizzard_interactbg or titanbg) then |
||
1363 | TitanPanelRightClickMenu_Close(); |
||
1364 | Hook_AcceptBattlefieldPort(index, accept); |
||
1365 | end |
||
1366 | end |
||
1367 | |||
1368 | |||
1369 | -- ## Toggles the locking of the capture timers on the screen. |
||
1370 | function TitanPanelTitanBG_ToggleLockCaptures() |
||
1371 | |||
1372 | -- Lock the on screen capture timers. |
||
1373 | if (sv_menu["D_OS_PanelLock"] or not sv_menu["AddonEnabled"]) then |
||
1374 | TitanPanelTitanBG_Display_Capture:Hide(); |
||
1375 | |||
1376 | -- Unlock the on screen capture timers. |
||
1377 | else |
||
1378 | TitanPanelTitanBG_Display_Capture:Show(); |
||
1379 | end |
||
1380 | end |
||
1381 | |||
1382 | |||
1383 | -- ## Hides or shows the battleground mini map button. |
||
1384 | function TitanPanelTitanBG_ToggleMiniMapIcon() |
||
1385 | |||
1386 | -- Hide the mini map button if the user wants it hidden. |
||
1387 | if ((sv_menu["B_HideMinimapButton"] and TitanPanelTitanBG_InBGQueue() and sv_menu["AddonEnabled"]) or (not sv_menu["AddonEnabled"] and not TitanPanelTitanBG_InBGQueue())) then |
||
1388 | MiniMapBattlefieldFrame:Hide(); |
||
1389 | elseif (TitanPanelTitanBG_InBGQueue()) then |
||
1390 | MiniMapBattlefieldFrame:Show(); |
||
1391 | end |
||
1392 | end |
||
1393 | |||
1394 | |||
1395 | -- ## Hides or shows the battleground minimap. |
||
1396 | function TitanPanelTitanBG_ToggleBattlefieldMinimap() |
||
1397 | |||
1398 | -- If this is a battleground or a world pvp area, determine if the battlemap needs to be shown or hidden. |
||
1399 | if (sv_menu["AddonEnabled"]) then |
||
1400 | local showmap = sv_menu["B_AutoShowBGMinimap"]; |
||
1401 | |||
1402 | -- Check if the user has changed the settings for this zone manually. |
||
1403 | if (_blizzard_manualshowbg) then |
||
1404 | if (_blizzard_manualshowbg == "SHOW") then |
||
1405 | showmap = true; |
||
1406 | elseif (_blizzard_manualshowbg == "HIDE") then |
||
1407 | showmap = false; |
||
1408 | end |
||
1409 | end |
||
1410 | |||
1411 | -- If the battlefield minimap hasn't been loaded, load it. |
||
1412 | if (not BattlefieldMinimap) then BattlefieldMinimap_LoadUI(); end |
||
1413 | |||
1414 | -- If we want to show the battlemap. |
||
1415 | if (showmap and not BattlefieldMinimap:IsShown() and sv_menu["AddonEnabled"] and (TitanPanelTitanBG_IsBattleground(_player_zone) or (not TitanPanelTitanBG_IsBattleground(_player_zone) and _blizzard_manualshowbg ~= nil))) then |
||
1416 | BattlefieldMinimap:Show(); |
||
1417 | |||
1418 | -- If we want to hide the battlemap. |
||
1419 | elseif ((not showmap and BattlefieldMinimap:IsShown()) or (not TitanPanelTitanBG_IsBattleground(_player_zone) and _blizzard_manualshowbg == nil)) then |
||
1420 | if (BattlefieldMinimap) then |
||
1421 | BattlefieldMinimap:Hide(); |
||
1422 | end |
||
1423 | end |
||
1424 | end |
||
1425 | end |
||
1426 | |||
1427 | |||
1428 | -- ## Enables and disables click targetting of the flag runner. |
||
1429 | function TitanPanelTitanBG_ToggleClickFlagRunner() |
||
1430 | if (sv_menu["D_OS_WSG_Click"]) then |
||
1431 | TitanPanelTitanBG_Display_Flag_1:EnableMouse(true); |
||
1432 | TitanPanelTitanBG_Display_Flag_2:EnableMouse(true); |
||
1433 | |||
1434 | TitanPanelTitanBG_Display_Flag_1_Button:EnableMouse(true); |
||
1435 | TitanPanelTitanBG_Display_Flag_2_Button:EnableMouse(true); |
||
1436 | else |
||
1437 | TitanPanelTitanBG_Display_Flag_1:EnableMouse(false); |
||
1438 | TitanPanelTitanBG_Display_Flag_2:EnableMouse(false); |
||
1439 | |||
1440 | TitanPanelTitanBG_Display_Flag_1_Button:EnableMouse(false); |
||
1441 | TitanPanelTitanBG_Display_Flag_2_Button:EnableMouse(false); |
||
1442 | end |
||
1443 | end |
||
1444 | |||
1445 | -- Changes the attachment points of the flag tracker. |
||
1446 | function TitanPanelTitanBG_InvertFlagTracker() |
||
1447 | if (not sv_menu["D_OS_WSG_Invert"]) then |
||
1448 | TitanPanelTitanBG_Display_Flag_1:ClearAllPoints(); |
||
1449 | TitanPanelTitanBG_Display_Flag_2:ClearAllPoints(); |
||
1450 | |||
1451 | TitanPanelTitanBG_Display_Flag_1:SetPoint("TOPLEFT", "TitanPanelTitanBG_Display_Capture", "TOPLEFT"); |
||
1452 | TitanPanelTitanBG_Display_Flag_2:SetPoint("TOPLEFT", "TitanPanelTitanBG_Display_Flag_1", "BOTTOMLEFT"); |
||
1453 | else |
||
1454 | TitanPanelTitanBG_Display_Flag_1:ClearAllPoints(); |
||
1455 | TitanPanelTitanBG_Display_Flag_2:ClearAllPoints(); |
||
1456 | |||
1457 | TitanPanelTitanBG_Display_Flag_1:SetPoint("BOTTOMLEFT", "TitanPanelTitanBG_Display_Flag_2", "TOPLEFT"); |
||
1458 | TitanPanelTitanBG_Display_Flag_2:SetPoint("BOTTOMLEFT", "TitanPanelTitanBG_Display_Capture", "BOTTOMLEFT"); |
||
1459 | |||
1460 | end |
||
1461 | end |
||
1462 | |||
1463 | |||
1464 | -- Attaches the flag tracker to the score frame. |
||
1465 | function TitanPanelTitanBG_ChangeAttachFlagTracker() |
||
1466 | if (_player_zone == TITANBG_BG_WSG) then |
||
1467 | if (not sv_menu["D_OS_WSG_AttachScore"]) then |
||
1468 | TitanPanelTitanBG_Display_Flag_1_Button:ClearAllPoints(); |
||
1469 | TitanPanelTitanBG_Display_Flag_2_Button:ClearAllPoints(); |
||
1470 | |||
1471 | TitanPanelTitanBG_Display_Flag_1_Button:SetPoint("TOPLEFT", "TitanPanelTitanBG_Display_Flag_1_Icon", "TOPRIGHT", 0, -2); |
||
1472 | TitanPanelTitanBG_Display_Flag_2_Button:SetPoint("TOPLEFT", "TitanPanelTitanBG_Display_Flag_2_Icon", "TOPRIGHT", 0, -2); |
||
1473 | |||
1474 | else |
||
1475 | if (AlwaysUpFrame1DynamicIconButton ~= nil and AlwaysUpFrame2DynamicIconButton ~= nil) then |
||
1476 | TitanPanelTitanBG_Display_Flag_1_Button:ClearAllPoints(); |
||
1477 | TitanPanelTitanBG_Display_Flag_2_Button:ClearAllPoints(); |
||
1478 | |||
1479 | TitanPanelTitanBG_Display_Flag_1_Button:SetPoint("TOPLEFT", "AlwaysUpFrame1DynamicIconButton", "TOPRIGHT", 2, -4); |
||
1480 | TitanPanelTitanBG_Display_Flag_2_Button:SetPoint("TOPLEFT", "AlwaysUpFrame2DynamicIconButton", "TOPRIGHT", 2, -4); |
||
1481 | end |
||
1482 | end |
||
1483 | end |
||
1484 | end |
||
1485 | |||
1486 | -- ## Overwrites the similar settings in other addons. |
||
1487 | function TitanPanelTitanBG_ToggleOverwriteOtherSettings() |
||
1488 | |||
1489 | -- If we are overwriting the settings of other addons. |
||
1490 | if (sv_menu["I_OverwriteOtherSettings"] and sv_menu["AddonEnabled"]) then |
||
1491 | |||
1492 | -- Blizzard |
||
1493 | WorldStateFrame_ToggleMinimap = TitanPanelTitanBG_ToggleBattlefieldMinimap; |
||
1494 | RepopMe = TitanPanelTitanBG_RepopMe; |
||
1495 | AcceptBattlefieldPort = TitanPanelTitanBG_AcceptBattlefieldPort; |
||
1496 | |||
1497 | -- TITAN HONOR PLUS |
||
1498 | -- Auto battleground minimap. |
||
1499 | if (TitanPanelHonorPlus_ToggleVar_AutoBGMap) then |
||
1500 | TitanPanelHonorPlus_ToggleVar_AutoBGMap = function() |
||
1501 | TitanPanelTitanBG_MessagePopup(TITANBG_MESSAGE_ACTIONOVERWRITTEN, 140); |
||
1502 | Hook_TitanPanelHonorPlus_ToggleVar_AutoBGMap(); |
||
1503 | end |
||
1504 | end |
||
1505 | |||
1506 | -- Auto join battleground. |
||
1507 | if (TitanPanelHonorPlus_ToggleVar_AutoJoinBG) then |
||
1508 | TitanPanelHonorPlus_ToggleVar_AutoJoinBG = function() |
||
1509 | TitanPanelTitanBG_MessagePopup(TITANBG_MESSAGE_ACTIONOVERWRITTEN, 140); |
||
1510 | Hook_TitanPanelHonorPlus_ToggleVar_AutoJoinBG(); |
||
1511 | end |
||
1512 | |||
1513 | TitanHonorPlus_CheckBGConfirm = function() end |
||
1514 | TitanHonorPlus_StaticPopup_OnHide = function() end |
||
1515 | end |
||
1516 | |||
1517 | -- Auto release on death. |
||
1518 | if (TitanPanelHonorPlus_ToggleVar_AutoRelease) then |
||
1519 | TitanPanelHonorPlus_ToggleVar_AutoRelease = function() |
||
1520 | TitanPanelTitanBG_MessagePopup(TITANBG_MESSAGE_ACTIONOVERWRITTEN, 140); |
||
1521 | Hook_TitanPanelHonorPlus_ToggleVar_AutoRelease(); |
||
1522 | end |
||
1523 | end |
||
1524 | |||
1525 | -- If we don't want to overwrite the settings of other addons. |
||
1526 | else |
||
1527 | |||
1528 | -- Blizzard |
||
1529 | WorldStateFrame_ToggleMinimap = Hook_WorldStateFrame_ToggleMinimap; |
||
1530 | RepopMe = Hook_RepopMe; |
||
1531 | AcceptBattlefieldPort = Hook_AcceptBattlefieldPort; |
||
1532 | |||
1533 | -- TITAN HONOR PLUS |
||
1534 | -- Auto battleground minimap. |
||
1535 | if (Hook_TitanPanelHonorPlus_ToggleVar_AutoBGMap) then |
||
1536 | TitanPanelHonorPlus_ToggleVar_AutoBGMap = Hook_TitanPanelHonorPlus_ToggleVar_AutoBGMap; |
||
1537 | end |
||
1538 | |||
1539 | -- Auto join battleground. |
||
1540 | if (Hook_TitanPanelHonorPlus_ToggleVar_AutoJoinBG) then |
||
1541 | TitanPanelHonorPlus_ToggleVar_AutoJoinBG = Hook_TitanPanelHonorPlus_ToggleVar_AutoJoinBG; |
||
1542 | TitanHonorPlus_CheckBGConfirm = Hook_TitanHonorPlus_CheckBGConfirm; |
||
1543 | TitanHonorPlus_StaticPopup_OnHide = Hook_TitanHonorPlus_StaticPopup_OnHide; |
||
1544 | end |
||
1545 | |||
1546 | -- Auto release on death. |
||
1547 | if (Hook_TitanPanelHonorPlus_ToggleVar_AutoRelease) then |
||
1548 | TitanPanelHonorPlus_ToggleVar_AutoRelease = Hook_TitanPanelHonorPlus_ToggleVar_AutoRelease; |
||
1549 | end |
||
1550 | end |
||
1551 | end |
||
1552 | |||
1553 | |||
1554 | -- ## Hides the battleground ready popup. |
||
1555 | function TitanPanelTitanBG_HideBattlegroundReadyPopup() |
||
1556 | if (sv_menu["B_HideJoinPopup"]) then |
||
1557 | StaticPopup_Hide("CONFIRM_BATTLEFIELD_ENTRY"); |
||
1558 | end |
||
1559 | end |
||
1560 | |||
1561 | |||
1562 | -- ##################### |
||
1563 | -- ## TITAN FUNCTIONS ## |
||
1564 | -- ##################### |
||
1565 | |||
1566 | -- ## Creates the text located on the titan bar. |
||
1567 | function TitanPanelTitanBGButton_SetButtonText(id) |
||
1568 | TitanPanelTitanBGButton_CheckEvents(); |
||
1569 | |||
1570 | local text = ""; -- The tooltip text. |
||
1571 | |||
1572 | local active = ""; -- Active battleground data. |
||
1573 | local ready = ""; -- Ready battleground data. |
||
1574 | local queue = ""; -- Queue battleground data. |
||
1575 | |||
1576 | local spacer = TITANBG_COLOR_BLUE .. TITANBG_ICON_BUTTON_SPACER; |
||
1577 | |||
1578 | -- If the user wants to display the label text, display it. |
||
1579 | if (sv_menu["ShowLabelText"]) then |
||
1580 | |||
1581 | -- Loop through and process all the battlegrounds. |
||
1582 | for i = 1, table.getn(_bgs.index) do |
||
1583 | if (_bgs.names[_bgs.index[i]].status ~= TITANBG_BG_STATUS_NONE) then |
||
1584 | |||
1585 | -- Get active battleground text. |
||
1586 | if (_bgs.names[_bgs.index[i]].status == TITANBG_BG_STATUS_ACTIVE) then |
||
1587 | active = active .. TitanPanelTitanBGButton_GetButtonText(_bgs.names[_bgs.index[i]]); |
||
1588 | |||
1589 | -- Ready battleground data. |
||
1590 | elseif (_bgs.names[_bgs.index[i]].status == TITANBG_BG_STATUS_CONFIRM) then |
||
1591 | if (ready ~= "") then ready = ready .. " "; end |
||
1592 | |||
1593 | ready = ready .. TitanPanelTitanBGButton_GetButtonText(_bgs.names[_bgs.index[i]]); |
||
1594 | |||
1595 | -- Queue data. |
||
1596 | else |
||
1597 | if (queue ~= "") then queue = queue .. " "; end |
||
1598 | |||
1599 | queue = queue .. TitanPanelTitanBGButton_GetButtonText(_bgs.names[_bgs.index[i]]); |
||
1600 | end |
||
1601 | end |
||
1602 | end |
||
1603 | |||
1604 | -- If this is a battleground, don't display generic queue information. |
||
1605 | if (TitanPanelTitanBG_IsBattleground(_player_zone)) then |
||
1606 | queue = ""; |
||
1607 | |||
1608 | -- If a queue is ready and the user wants to active information hidden. |
||
1609 | if (sv_menu["B_ReplaceActive"] and ready ~= "") then |
||
1610 | active = ""; |
||
1611 | end |
||
1612 | end |
||
1613 | |||
1614 | if (active ~= "" and ready ~= "") then ready = " " .. ready; end |
||
1615 | if ((active ~= "" or ready ~= "") and queue ~= "") then queue = " " .. queue; end |
||
1616 | |||
1617 | if (sv_menu["D_B_Spacers"]) then |
||
1618 | text = (spacer .. " " .. active .. ready .. queue .. " " .. spacer); |
||
1619 | else |
||
1620 | text = (active .. ready .. queue); |
||
1621 | end |
||
1622 | |||
1623 | -- If nothing is going on, show place holder. |
||
1624 | if (active == "" and ready == "" and queue == "") then |
||
1625 | text = TITANBG_COLOR_YELLOW .. TITANBG_MENU_HEADER; |
||
1626 | end |
||
1627 | end |
||
1628 | |||
1629 | -- Return the button text. |
||
1630 | return text; |
||
1631 | end |
||
1632 | |||
1633 | function TitanPanelTitanBGButton_GetButtonText(bg) |
||
1634 | local text = ""; |
||
1635 | local short = TITANBG_COLOR_GREEN .. bg.short; |
||
1636 | |||
1637 | -- If the user is queued for a BG. |
||
1638 | if (bg.status == TITANBG_BG_STATUS_QUEUED) then |
||
1639 | |||
1640 | -- If the user wants to go into the first BG available. |
||
1641 | if (bg.instance == 0) then |
||
1642 | text = short .. ": " .. TITANBG_COLOR_WHITE .. TITANBG_FIRST_AVAILABLE; |
||
1643 | |||
1644 | -- If the user wants to go into a specific bg. |
||
1645 | else |
||
1646 | text = short .. ": " .. TITANBG_COLOR_WHITE .. bg.instance; |
||
1647 | end |
||
1648 | |||
1649 | -- If the user wants to display the time in the queue and wait time, show it. |
||
1650 | if (sv_menu["D_B_Time"]) then |
||
1651 | |||
1652 | local wait_time = GetBattlefieldEstimatedWaitTime(bg.index); |
||
1653 | local in_queue = SecondsToTimeAbbrev(GetBattlefieldTimeWaited(bg.index) / 1000); |
||
1654 | |||
1655 | -- Unavailable. |
||
1656 | if (wait_time == 0) then |
||
1657 | wait_time = TITANBG_COLOR_RED .. "?"; |
||
1658 | |||
1659 | -- Time. |
||
1660 | else |
||
1661 | wait_time = SecondsToTimeAbbrev(wait_time / 1000, 1); |
||
1662 | end |
||
1663 | |||
1664 | text = text .. TITANBG_COLOR_YELLOW .. " [" .. TITANBG_COLOR_WHITE .. in_queue .. TITANBG_COLOR_YELLOW .. "/" .. wait_time .. TITANBG_COLOR_YELLOW .."]"; |
||
1665 | end |
||
1666 | |||
1667 | -- If the user can join a battleground on confirmation. |
||
1668 | elseif (bg.status == TITANBG_BG_STATUS_CONFIRM) then |
||
1669 | |||
1670 | -- If auto joining and not currently in a battleground. |
||
1671 | if (not TitanPanelTitanBG_IsBattleground(_player_zone) and sv_menu["B_AutoJoinBG"] and _autojoin_time > GetTime() and _autojoin_bg == bg.name) then |
||
1672 | text = short .. " " .. bg.instance ..": " .. TITANBG_COLOR_GREEN .. SecondsToTime(_autojoin_time - GetTime()); |
||
1673 | |||
1674 | if (_autojoin_paused > 0) then |
||
1675 | text = text .. TITANBG_COLOR_WHITE .. " (" .. TITANBG_COLOR_GREEN .. TITANBG_BUTTON_PAUSED .. TITANBG_COLOR_WHITE .. ")"; |
||
1676 | end |
||
1677 | |||
1678 | -- If currently in a battleground or not auto joining. |
||
1679 | else |
||
1680 | text = short .. " " .. bg.instance ..": " .. TITANBG_COLOR_GREEN .. TITANBG_LABEL_READY; |
||
1681 | end |
||
1682 | |||
1683 | if (sv_menu["D_B_QueueExpire"]) then |
||
1684 | text = text .. TITANBG_COLOR_YELLOW .." (" .. TITANBG_COLOR_RED .. SecondsToTime(bg.expires) .. TITANBG_COLOR_YELLOW ..")"; |
||
1685 | end |
||
1686 | |||
1687 | -- If the user is currently in a battleground. |
||
1688 | elseif (bg.status == TITANBG_BG_STATUS_ACTIVE) then |
||
1689 | text = short .. " " .. bg.instance; |
||
1690 | |||
1691 | if (sv_menu["D_B_Players"] and _active.stats.bg.total > 0) then |
||
1692 | text = text .. TITANBG_COLOR_WHITE .. " (".. TITANBG_COLOR_BLUE .. _active.stats.bg.alliance .. TITANBG_COLOR_WHITE .. ":" .. TITANBG_COLOR_RED .. _active.stats.bg.horde .. TITANBG_COLOR_WHITE .. ")"; |
||
1693 | end |
||
1694 | |||
1695 | text = text .. TITANBG_COLOR_YELLOW .. ": "; |
||
1696 | |||
1697 | if (sv_menu["D_B_Standing"] and _active.stats.player.standing ~= nil) then |
||
1698 | text = text .. TITANBG_COLOR_YELLOW .. TITANBG_S_STANDING .. TITANBG_COLOR_WHITE .. _active.stats.player.standing .. " "; |
||
1699 | end |
||
1700 | |||
1701 | if (sv_menu["D_B_KillingBlows"] and _active.stats.player.killing_blows ~= nil) then |
||
1702 | text = text .. TITANBG_COLOR_YELLOW .. TITANBG_S_KILLINGBLOWS .. TITANBG_COLOR_GREEN .. _active.stats.player.killing_blows .. " "; |
||
1703 | end |
||
1704 | |||
1705 | if (sv_menu["D_B_Kills"] and _active.stats.player.kills ~= nil) then |
||
1706 | text = text .. TITANBG_COLOR_YELLOW .. TITANBG_S_KILLS .. TITANBG_COLOR_GREEN .. _active.stats.player.kills .. " "; |
||
1707 | end |
||
1708 | |||
1709 | if (sv_menu["D_B_Deaths"] and _active.stats.player.deaths ~= nil) then |
||
1710 | text = text .. TITANBG_COLOR_YELLOW .. TITANBG_S_DEATHS .. TITANBG_COLOR_RED .. _active.stats.player.deaths .. " "; |
||
1711 | end |
||
1712 | |||
1713 | if (sv_menu["D_B_Honor"] and _active.stats.player.honor ~= nil) then |
||
1714 | text = text .. TITANBG_COLOR_YELLOW .. TITANBG_S_HONOR .. TITANBG_COLOR_WHITE .. _active.stats.player.honor .. " "; |
||
1715 | end |
||
1716 | |||
1717 | -- If the player is auto leaving the battleground. |
||
1718 | if (sv_menu["B_AutoLeaveBG"] and _autoleave_time > GetTime()) then |
||
1719 | text = short .. " " .. bg.instance ..": " .. TITANBG_COLOR_RED .. SecondsToTime(_autoleave_time - GetTime()); |
||
1720 | |||
1721 | if (_autoleave_paused > 0) then |
||
1722 | text = text .. TITANBG_COLOR_WHITE .. " (" .. TITANBG_COLOR_RED .. TITANBG_BUTTON_PAUSED .. TITANBG_COLOR_WHITE .. ")"; |
||
1723 | end |
||
1724 | end |
||
1725 | end |
||
1726 | |||
1727 | return text; |
||
1728 | end |
||
1729 | |||
1730 | |||
1731 | -- ## Creates the text located on the titan bar. |
||
1732 | function TitanPanelTitanBGButton_SetTooltipText(id) |
||
1733 | local text = ""; -- The tooltip text. |
||
1734 | |||
1735 | local active = ""; -- Active battleground data. |
||
1736 | local ready = ""; -- Ready battleground data. |
||
1737 | local queue = ""; -- Queue battleground data. |
||
1738 | local empty = ""; -- Irrelevant battleground data. |
||
1739 | local hint = ""; -- Any hints to add to the end. |
||
1740 | |||
1741 | -- Loop through and process all the battlegrounds. |
||
1742 | for i = 1, table.getn(_bgs.index) do |
||
1743 | |||
1744 | -- No battleground interaction. |
||
1745 | if (_bgs.names[_bgs.index[i]].status == TITANBG_BG_STATUS_NONE) then |
||
1746 | if (empty ~= "") then empty = empty .. "\n"; end |
||
1747 | |||
1748 | empty = empty .. TitanPanelTitanBGButton_GetTooltipText(_bgs.names[_bgs.index[i]]); |
||
1749 | |||
1750 | -- Active battleground data. |
||
1751 | elseif (_bgs.names[_bgs.index[i]].status == TITANBG_BG_STATUS_ACTIVE) then |
||
1752 | if (active ~= "") then active = active .. "\n\n"; end |
||
1753 | |||
1754 | active = active .. TitanPanelTitanBGButton_GetTooltipText(_bgs.names[_bgs.index[i]]); |
||
1755 | |||
1756 | -- Ready battleground data. |
||
1757 | elseif (_bgs.names[_bgs.index[i]].status == TITANBG_BG_STATUS_CONFIRM) then |
||
1758 | if (ready ~= "") then ready = ready .. "\n"; end |
||
1759 | |||
1760 | ready = ready .. TitanPanelTitanBGButton_GetTooltipText(_bgs.names[_bgs.index[i]]); |
||
1761 | |||
1762 | -- Queue data. |
||
1763 | else |
||
1764 | if (queue ~= "") then queue = queue .. "\n\n"; end |
||
1765 | |||
1766 | queue = queue .. TitanPanelTitanBGButton_GetTooltipText(_bgs.names[_bgs.index[i]]); |
||
1767 | end |
||
1768 | end |
||
1769 | |||
1770 | -- Show hints. |
||
1771 | if (not TitanPanelTitanBG_IsBattleground(_player_zone)) then |
||
1772 | hint = hint .. "\n"; |
||
1773 | |||
1774 | if (not TitanPanelTitanBG_IsBattleground(_player_zone) and _autojoin_time > 0 and ready ~= "" and sv_menu["B_AutoJoinBG"]) then |
||
1775 | hint = hint .. "\n" .. TITANBG_COLOR_RED .. TITANBG_AUTOJOIN_HINT; |
||
1776 | end |
||
1777 | |||
1778 | hint = hint .. "\n" .. TITANBG_COLOR_RED .. TITANBG_MINIMAP_HINT; |
||
1779 | end |
||
1780 | |||
1781 | -- If the user wants two tooltips. |
||
1782 | if (sv_menu["D_BG_SeperateActiveQueue"] and TitanPanelTitanBG_IsBattleground(_player_zone)) then |
||
1783 | hint = hint .. "\n\n" .. TITANBG_COLOR_RED .. TITANBG_TOOLTIP_HINT; |
||
1784 | |||
1785 | if (_display_queue_tt) then |
||
1786 | if (ready ~= "" and queue ~= "") then queue = "\n\n" .. queue; end |
||
1787 | if ((ready ~= "" or queue ~= "") and empty ~= "") then empty = "\n\n" .. empty; end |
||
1788 | |||
1789 | text = "\n" .. ready .. queue .. empty .. hint; |
||
1790 | else |
||
1791 | text = "\n" .. active .. hint; |
||
1792 | end |
||
1793 | |||
1794 | -- If the user wants to display everthing in one tooltip. |
||
1795 | else |
||
1796 | if (ready ~= "" and active ~= "") then active = "\n\n" .. active; end |
||
1797 | if ((ready ~= "" or active ~= "") and queue ~= "") then queue = "\n\n" .. queue; end |
||
1798 | if ((ready ~= "" or active ~= "" or queue ~= "") and empty ~= "") then empty = "\n\n" .. empty; end |
||
1799 | |||
1800 | text = "\n" .. ready .. active .. queue .. empty .. hint; |
||
1801 | end |
||
1802 | |||
1803 | return text; |
||
1804 | end |
||
1805 | |||
1806 | |||
1807 | -- ## Creates the tooltip text for the addon. |
||
1808 | function TitanPanelTitanBGButton_GetTooltipText(bg) |
||
1809 | local text = ""; |
||
1810 | |||
1811 | -- If the user is not queued for the battleground. |
||
1812 | if (bg.status == TITANBG_BG_STATUS_NONE) then |
||
1813 | text = text .. TITANBG_COLOR_GREY .. string.gsub(TITANBG_NOT_IN_QUEUE_LONG, "{bg}", bg.name, 1); |
||
1814 | |||
1815 | -- If the user is queued for the battleground. |
||
1816 | elseif (bg.status == TITANBG_BG_STATUS_QUEUED) then |
||
1817 | local wait_time = GetBattlefieldEstimatedWaitTime(bg.index); |
||
1818 | local in_queue = GetBattlefieldTimeWaited(bg.index); |
||
1819 | |||
1820 | text = text .. TITANBG_COLOR_GREEN .. string.upper(bg.name) .. "\n"; |
||
1821 | |||
1822 | if (bg.instance ~= 0) then |
||
1823 | text = text .. TITANBG_COLOR_GREY .. string.gsub(TITANBG_QUEUED_PREF, "{bg}", bg.name .. " " .. bg.instance, 1); |
||
1824 | else |
||
1825 | text = text .. TITANBG_COLOR_GREY .. string.gsub(TITANBG_QUEUED_NOPREF, "{bg}", bg.name, 1); |
||
1826 | end |
||
1827 | |||
1828 | -- If the user knows how many active battlegrounds there were previously. |
||
1829 | if (bg.open_age > 0 and sv_menu["D_TT_RememberOpenBgs"]) then |
||
1830 | local age = ""; |
||
1831 | |||
1832 | -- If older than 10 minutes, display age. |
||
1833 | if (GetTime() - bg.open_age >= 300) then |
||
1834 | age = TITANBG_COLOR_YELLOW .. " [" .. TITANBG_COLOR_WHITE .. SecondsToTimeAbbrev(GetTime() - bg.open_age) .. TITANBG_COLOR_YELLOW .. "]"; |
||
1835 | end |
||
1836 | |||
1837 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_ACTIVE_INSTANCES .. "\t" .. TITANBG_COLOR_WHITE .. bg.open_instances .. age; |
||
1838 | end |
||
1839 | |||
1840 | if (sv_menu["D_TT_QueueTimers"]) then |
||
1841 | text = text .. "\n\n" .. TITANBG_COLOR_YELLOW .. TITANBG_ESTIMATED_WAIT; |
||
1842 | |||
1843 | if (wait_time == 0) then |
||
1844 | text = text .. "\t" .. TITANBG_COLOR_RED .. QUEUE_TIME_UNAVAILABLE .. "."; |
||
1845 | elseif (wait_time < 60000) then |
||
1846 | text = text .. "\t" .. TITANBG_COLOR_GREEN .. TITANBG_LESS_THAN_ONE_MIN; |
||
1847 | else |
||
1848 | text = text .. "\t" .. TITANBG_COLOR_WHITE .. SecondsToTime(wait_time / 1000, 1); |
||
1849 | end |
||
1850 | |||
1851 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_TIME_IN_QUEUE .. "\t" .. TITANBG_COLOR_WHITE .. SecondsToTime(in_queue / 1000); |
||
1852 | |||
1853 | -- Estimated time remaining. |
||
1854 | if (wait_time > in_queue) then |
||
1855 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_ESTIMATED_REMAINING .. "\t" .. TITANBG_COLOR_WHITE .. SecondsToTime((wait_time - in_queue) / 1000); |
||
1856 | end |
||
1857 | end |
||
1858 | |||
1859 | -- If the user can now accept to go into the battleground. |
||
1860 | elseif (bg.status == TITANBG_BG_STATUS_CONFIRM) then |
||
1861 | local expire = ""; |
||
1862 | |||
1863 | -- Check if the queue expire time is to be shown. |
||
1864 | if (sv_menu["D_POP_QueueExpire"]) then |
||
1865 | expire = " (" .. TITANBG_COLOR_RED .. SecondsToTime(bg.expires) .. TITANBG_COLOR_GREEN .. ")"; |
||
1866 | end |
||
1867 | |||
1868 | -- If the user is not already in a battleground and is autojoining. |
||
1869 | if (TitanPanelTitanBG_IsBattleground(_player_zone) == false and sv_menu["B_AutoJoinBG"] and _autojoin_time > GetTime() and _autojoin_bg == bg.name) then |
||
1870 | local autojoin = SecondsToTime(_autojoin_time - GetTime()); |
||
1871 | |||
1872 | if (_autojoin_paused > 0) then |
||
1873 | autojoin = autojoin .. TITANBG_COLOR_WHITE .. "(" .. TITANBG_TOOLTIP_PAUSED .. ")"; |
||
1874 | end |
||
1875 | |||
1876 | text = text .. TITANBG_COLOR_GREEN .. string.gsub(string.gsub(TITANBG_AUTOJOIN, "{bg}", TITANBG_COLOR_WHITE .. bg.name .. TITANBG_COLOR_GREEN, 1), "{time}", TITANBG_COLOR_YELLOW .. autojoin .. TITANBG_COLOR_GREEN .. expire, 1); |
||
1877 | |||
1878 | -- If the user is in a battleground or is not autojoining. |
||
1879 | else |
||
1880 | text = text .. TITANBG_COLOR_GREEN .. string.gsub(string.gsub(TITANBG_CONFIRMJOIN, "{bg}", TITANBG_COLOR_WHITE .. bg.name .. TITANBG_COLOR_GREEN, 1), "{time}", TITANBG_COLOR_GREEN .. expire, 1); |
||
1881 | end |
||
1882 | |||
1883 | -- If the battleground is currently active. |
||
1884 | elseif (bg.status == TITANBG_BG_STATUS_ACTIVE) then |
||
1885 | text = TITANBG_COLOR_GREEN .. string.upper(bg.name) .. "\n" .. text; |
||
1886 | |||
1887 | -- If the player is auto leaving the battleground. |
||
1888 | if (sv_menu["B_AutoLeaveBG"] and _autoleave_time > GetTime()) then |
||
1889 | local autoleave = SecondsToTime(_autoleave_time - GetTime()); |
||
1890 | |||
1891 | if (_autoleave_paused > 0) then |
||
1892 | autoleave = autoleave .. TITANBG_COLOR_WHITE .. "(" .. TITANBG_TOOLTIP_PAUSED .. ")"; |
||
1893 | end |
||
1894 | |||
1895 | text = text .. TITANBG_COLOR_RED .. string.gsub(TITANBG_AUTOLEAVE, "{time}", autoleave .. TITANBG_COLOR_RED, 1) .. "\n\n"; |
||
1896 | end |
||
1897 | |||
1898 | text = text .. TITANBG_COLOR_YELLOW .. bg.name .. " " .. bg.instance .. ":"; |
||
1899 | |||
1900 | -- Print the instance and the run time. |
||
1901 | if (_active.stats.bg.run > 0) then |
||
1902 | text = text .. "\t" .. TITANBG_COLOR_WHITE .. SecondsToTime(_active.stats.bg.run/1000, 1); |
||
1903 | else |
||
1904 | text = text .. "\t" .. TITANBG_COLOR_RED .. TITANBG_INSTANCE_RUN_TIME_NA; |
||
1905 | end |
||
1906 | |||
1907 | -- Print the number of players. |
||
1908 | if (_active.stats.bg.total > 0) then |
||
1909 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_PLAYERS .. "\t" .. TITANBG_COLOR_WHITE .. _active.stats.bg.total; |
||
1910 | |||
1911 | text = text .. TITANBG_COLOR_YELLOW .. " [" .. TITANBG_COLOR_BLUE .. _active.stats.bg.alliance .. TITANBG_COLOR_YELLOW .. "]"; |
||
1912 | text = text .. TITANBG_COLOR_YELLOW .. " [" .. TITANBG_COLOR_RED .. _active.stats.bg.horde .. TITANBG_COLOR_YELLOW .. "]"; |
||
1913 | end |
||
1914 | |||
1915 | -- If this is Arathi Basin, print who is likely to win this battleground. |
||
1916 | if (bg.name == TITANBG_BG_AB and sv_menu["D_TT_ABWinEstimates"] and GetBattlefieldWinner() == nil) then |
||
1917 | local winner, win_time, alliance_score, horde_score, nodes = TitanPanelTitanBG_AB_GetWinner(_active.stats.ab.bases_alliance, _active.stats.ab.bases_horde); |
||
1918 | |||
1919 | text = text .. "\n\n" .. TITANBG_COLOR_WHITE .. TITANBG_WIN_ESTIMATE; |
||
1920 | |||
1921 | -- If unknown. |
||
1922 | if (winner == nil) then |
||
1923 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_AB_WINNER .. "\t" .. TITANBG_COLOR_WHITE .. TITANBG_AB_WINNER_UNKNOWN; |
||
1924 | |||
1925 | -- If Horde. |
||
1926 | elseif (winner == "Horde") then |
||
1927 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_AB_WINNER .. "\t" .. TITANBG_COLOR_RED .. FACTION_HORDE; |
||
1928 | |||
1929 | -- If Alliance. |
||
1930 | elseif (winner == "Alliance") then |
||
1931 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_AB_WINNER .. "\t" .. TITANBG_COLOR_BLUE .. FACTION_ALLIANCE; |
||
1932 | end |
||
1933 | |||
1934 | if (winner ~= nil) then |
||
1935 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_AB_FINAL_SCORE .. "\t" .. TITANBG_COLOR_BLUE .. alliance_score .. TITANBG_COLOR_WHITE .. " : " .. TITANBG_COLOR_RED .. horde_score; |
||
1936 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_AB_TIME_LEFT .. "\t" .. TITANBG_COLOR_WHITE .. SecondsToTimeAbbrev(win_time); |
||
1937 | |||
1938 | -- Determine number of bases the player needs to win. |
||
1939 | |||
1940 | -- If the player's faction isn't going to win. |
||
1941 | if (winner ~= UnitFactionGroup("player")) then |
||
1942 | local bases = TitanPanelTitanBG_AB_NodesRequiredToWin(_player_faction); |
||
1943 | text = text .. "\n\n" .. TITANBG_COLOR_YELLOW .. TITANBG_AB_TO_WIN .. "\t" .. TITANBG_COLOR_WHITE .. bases; |
||
1944 | |||
1945 | -- Otherwise, if their faction is going to win. |
||
1946 | else |
||
1947 | local bases = TitanPanelTitanBG_AB_NodesRequiredToWin(_player_enemy_faction); |
||
1948 | text = text .. "\n\n" .. TITANBG_COLOR_YELLOW .. TITANBG_AB_TO_WIN_ENEMY .. "\t" .. TITANBG_COLOR_WHITE .. bases; |
||
1949 | end |
||
1950 | |||
1951 | -- Time left until the number of nodes needed increases. |
||
1952 | if (_timetonodeincrease > 0) then |
||
1953 | text = text .. TITANBG_COLOR_YELLOW .. " (" .. TITANBG_COLOR_RED .. SecondsToTimeAbbrev(_timetonodeincrease) .. TITANBG_COLOR_YELLOW .. ")"; |
||
1954 | end |
||
1955 | end |
||
1956 | end |
||
1957 | |||
1958 | -- Print information on the user. |
||
1959 | if (sv_menu["D_TT_PlayerStats"]) then |
||
1960 | text = text .. "\n\n" .. TITANBG_COLOR_WHITE .. TITANBG_PLAYER_STATS; |
||
1961 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_PLAYER_STANDING .. "\t" .. TITANBG_COLOR_WHITE .. _active.stats.player.standing; |
||
1962 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_PLAYER_KILLINGBLOWS .. "\t" .. TITANBG_COLOR_GREEN .. _active.stats.player.killing_blows; |
||
1963 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_PLAYER_KILLS .. "\t" .. TITANBG_COLOR_GREEN .. _active.stats.player.kills; |
||
1964 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_PLAYER_DEATHS .. "\t" .. TITANBG_COLOR_RED .. _active.stats.player.deaths; |
||
1965 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_PLAYER_BONUSHONOR .. "\t" .. TITANBG_COLOR_WHITE .. _active.stats.player.honor; |
||
1966 | end |
||
1967 | |||
1968 | -- Print information on the locations in Alterac Valley. |
||
1969 | if (sv_menu["D_TT_LocationStats"] and bg.name == TITANBG_BG_AV) then |
||
1970 | text = text .. "\n\n" .. TITANBG_COLOR_WHITE .. TITANBG_LOCATION_STATS; |
||
1971 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_PLAYER_GYASSAULTED .. "\t" .. TITANBG_COLOR_WHITE .. _active.stats.av.gy_assulted; |
||
1972 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_PLAYER_GYDEFENDED .. "\t" .. TITANBG_COLOR_WHITE .. _active.stats.av.gy_defended; |
||
1973 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_PLAYER_TASSAULTED .. "\t" .. TITANBG_COLOR_WHITE .. _active.stats.av.towers_assaulted; |
||
1974 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_PLAYER_TDEFENDED .. "\t" .. TITANBG_COLOR_WHITE .. _active.stats.av.towers_defended; |
||
1975 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_PLAYER_MCAPTURED .. "\t" .. TITANBG_COLOR_WHITE .. _active.stats.av.mines_captured; |
||
1976 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_PLAYER_LKILLED .. "\t" .. TITANBG_COLOR_WHITE .. _active.stats.av.leaders_killed; |
||
1977 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_PLAYER_SECOBJ .. "\t" .. TITANBG_COLOR_WHITE .. _active.stats.av.secondary_obj; |
||
1978 | |||
1979 | -- Print information on the locations in Warsong Gulch. |
||
1980 | elseif (sv_menu["D_TT_LocationStats"] and bg.name == TITANBG_BG_WSG) then |
||
1981 | text = text .. "\n\n" .. TITANBG_COLOR_WHITE .. TITANBG_LOCATION_STATS; |
||
1982 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_PLAYER_FCAPTURED.. "\t" .. TITANBG_COLOR_WHITE .. _active.stats.wsg.flag_captures; |
||
1983 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_PLAYER_FRETURNED.. "\t" .. TITANBG_COLOR_WHITE .. _active.stats.wsg.flag_returns; |
||
1984 | |||
1985 | -- Print information on the locations in Arathi Basin. |
||
1986 | elseif (sv_menu["D_TT_LocationStats"] and bg.name == TITANBG_BG_AB) then |
||
1987 | text = text .. "\n\n" .. TITANBG_COLOR_WHITE .. TITANBG_LOCATION_STATS; |
||
1988 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_PLAYER_BSASSULTED.. "\t" .. TITANBG_COLOR_WHITE .. _active.stats.ab.bases_assulted; |
||
1989 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. TITANBG_PLAYER_BSDEFENDED.. "\t" .. TITANBG_COLOR_WHITE .. _active.stats.ab.bases_defended; |
||
1990 | end |
||
1991 | |||
1992 | -- Print information on friends. |
||
1993 | if ( sv_menu["D_TT_Friends"] and _friendstring ~= "" ) then |
||
1994 | text = text .. "\n\n" .. TITANBG_COLOR_WHITE .. TITANBG_FRIENDS; |
||
1995 | text = text .. _friendstring; |
||
1996 | end |
||
1997 | |||
1998 | -- Print information on incoming captures. |
||
1999 | if (sv_menu["D_TT_Capture"] and _active.captures ~= nil and table.getn(_active.captures) > 0 and GetBattlefieldWinner() == nil) then |
||
2000 | local capInfo = ""; |
||
2001 | |||
2002 | for i = 1, table.getn(_active.captures) do |
||
2003 | local eta = ""; |
||
2004 | |||
2005 | -- If the capture was done while the player was not there, show unknown. |
||
2006 | if (_active.captures[i].cap == 0) then |
||
2007 | eta = TITANBG_CAPTURE_UNKNOWN; |
||
2008 | |||
2009 | -- Otherwise, show the timer. |
||
2010 | else |
||
2011 | eta = SecondsToTime(_active.captures[i].cap - GetTime()); |
||
2012 | |||
2013 | -- If there is a capture imminent, indicate. |
||
2014 | if (eta == "") then |
||
2015 | eta = TITANBG_CAPTURE_IMINENT; |
||
2016 | end |
||
2017 | end |
||
2018 | |||
2019 | -- If not unknown, display timers. |
||
2020 | if (eta ~= TITANBG_CAPTURE_UNKNOWN) then |
||
2021 | |||
2022 | if (_active.captures[i].who == "Horde") then |
||
2023 | capInfo = capInfo .. "\n" .. TITANBG_COLOR_YELLOW .. _active.captures[i].name .. "\t" .. TITANBG_COLOR_RED .. eta; |
||
2024 | elseif (_active.captures[i].who == "Alliance") then |
||
2025 | capInfo = capInfo .. "\n" .. TITANBG_COLOR_YELLOW .. _active.captures[i].name .. "\t" .. TITANBG_COLOR_BLUE .. eta; |
||
2026 | end |
||
2027 | end |
||
2028 | end |
||
2029 | |||
2030 | -- If any valid captures, print them. |
||
2031 | if (capInfo ~= "") then |
||
2032 | text = text .. "\n\n" .. TITANBG_COLOR_WHITE .. TITANBG_CAPTURE_TIMERS .. capInfo; |
||
2033 | end |
||
2034 | end |
||
2035 | |||
2036 | -- Print information on flag caps. |
||
2037 | if (sv_menu["D_TT_FlagTracker"] and ((_active.stats.wsg.horde.player ~= "" and _active.stats.wsg.horde.player ~= nil) or (_active.stats.wsg.alliance.player ~= "" and _active.stats.wsg.alliance.player ~= nil)) and GetBattlefieldWinner() == nil) then |
||
2038 | text = text .. "\n\n" .. TITANBG_COLOR_WHITE .. TITANBG_FLAG_TRACKER; |
||
2039 | |||
2040 | if (_active.stats.wsg.alliance.player ~= "" and _active.stats.wsg.alliance.player ~= nil) then |
||
2041 | local player = TitanBG_GetPlayerData(_active.stats.wsg.alliance.player .. "|Alliance"); |
||
2042 | |||
2043 | if (player) then |
||
2044 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. "(" .. TITANBG_COLOR_RED .. TITANBG_FLAG .. TITANBG_COLOR_YELLOW .. ") " .. TITANBG_COLOR_BLUE .. _active.stats.wsg.alliance.player .. "\t" .. TITANBG_COLOR_WHITE .. player.class; |
||
2045 | end |
||
2046 | end |
||
2047 | |||
2048 | if (_active.stats.wsg.horde.player ~= "" and _active.stats.wsg.horde.player ~= nil) then |
||
2049 | local player = TitanBG_GetPlayerData(_active.stats.wsg.horde.player .. "|Horde"); |
||
2050 | |||
2051 | if (player) then |
||
2052 | text = text .. "\n" .. TITANBG_COLOR_YELLOW .. "(" .. TITANBG_COLOR_BLUE .. TITANBG_FLAG .. TITANBG_COLOR_YELLOW .. ") " .. TITANBG_COLOR_RED .. _active.stats.wsg.horde.player .. "\t" .. TITANBG_COLOR_WHITE .. player.class; |
||
2053 | end |
||
2054 | end |
||
2055 | end |
||
2056 | |||
2057 | -- Show hints. |
||
2058 | text = text .. "\n\n".. TITANBG_COLOR_RED .. TITANBG_SCOREFRAME_HINT; |
||
2059 | text = text .. "\n" .. TITANBG_COLOR_RED .. TITANBG_MINIMAP_HINT; |
||
2060 | end |
||
2061 | |||
2062 | return text; |
||
2063 | end |
||
2064 | |||
2065 | |||
2066 | -- ####################### |
||
2067 | -- ## DISPLAY FUNCTIONS ## |
||
2068 | -- ####################### |
||
2069 | |||
2070 | |||
2071 | -- ## Prints a message to the user's console. |
||
2072 | function TitanPanelTitanBG_Print(s) |
||
2073 | if (s == nil) then s = "nil"; end |
||
2074 | if (s == true) then s = "true"; end |
||
2075 | if (s == false) then s = "false"; end |
||
2076 | |||
2077 | DEFAULT_CHAT_FRAME:AddMessage("[TITANBG]: " .. s); |
||
2078 | end |
||
2079 | |||
2080 | -- ## Prints a message to a popup frame. |
||
2081 | function TitanPanelTitanBG_MessagePopup(s, height) |
||
2082 | if (s == nil) then s = "nil"; end |
||
2083 | if (s == true) then s = "true"; end |
||
2084 | if (s == false) then s = "false"; end |
||
2085 | |||
2086 | TitanPanelTitanBG_Message:SetHeight(height); |
||
2087 | TitanPanelTitanBG_Message_Text:SetText(s); |
||
2088 | TitanPanelTitanBG_Message:Show(); |
||
2089 | end |
||
2090 | |||
2091 | |||
2092 | -- ## Updates the on the screen display of the capture timers. |
||
2093 | function TitanPanelTitanBG_NT_UpdateCaptures(hide) |
||
2094 | local caps = 0; |
||
2095 | local display = 5; |
||
2096 | local shown = 1; |
||
2097 | local i = 1; |
||
2098 | |||
2099 | -- Hide all of the frames first. |
||
2100 | if (hide) then |
||
2101 | for i = 1, 5 do |
||
2102 | getglobal("TitanPanelTitanBG_Display_Capture_" .. i):Hide(); |
||
2103 | end |
||
2104 | end |
||
2105 | |||
2106 | if (sv_menu["AddonEnabled"] and (_player_zone == TITANBG_BG_AV or _player_zone == TITANBG_BG_AB) and GetBattlefieldWinner() == nil) then |
||
2107 | if (_active.captures ~= nil) then |
||
2108 | caps = table.getn(_active.captures); -- Number of captures. |
||
2109 | |||
2110 | if (table.getn(_active.captures) > 5) then |
||
2111 | display = caps; |
||
2112 | end |
||
2113 | end |
||
2114 | |||
2115 | -- If the player is printing the timers upside down. |
||
2116 | if (sv_menu["D_NT_TimersInvert"]) then |
||
2117 | local temp = i; |
||
2118 | |||
2119 | i = display; |
||
2120 | display = temp; |
||
2121 | end |
||
2122 | |||
2123 | while ((not sv_menu["D_NT_TimersInvert"] and i <= display) or (sv_menu["D_NT_TimersInvert"] and i >= display)) do |
||
2124 | local frame = "TitanPanelTitanBG_Display_Capture_" .. shown; |
||
2125 | |||
2126 | -- If this slot is not active, turn it off. |
||
2127 | if (_active.captures[i] == nil or not sv_menu["D_OS_CaptureShow"]) then |
||
2128 | |||
2129 | -- Blank out the points. |
||
2130 | getglobal(frame .. "_Icon"):SetTexCoord(TITANBG_ICON_CAP_BLANK[1], TITANBG_ICON_CAP_BLANK[2], TITANBG_ICON_CAP_BLANK[3], TITANBG_ICON_CAP_BLANK[4]); |
||
2131 | getglobal(frame .. "_Point"):SetText(""); |
||
2132 | getglobal(frame .. "_Time"):SetText(""); |
||
2133 | |||
2134 | -- Hide the frame. |
||
2135 | getglobal(frame):Hide(); |
||
2136 | |||
2137 | shown = shown + 1; |
||
2138 | |||
2139 | -- Update this slot with a timer if this is a valid capture. |
||
2140 | else |
||
2141 | |||
2142 | local eta = ""; |
||
2143 | |||
2144 | -- If the capture was done while the player was not there, show unknown. |
||
2145 | if (_active.captures[i].cap == 0) then |
||
2146 | eta = TITANBG_CAPTURE_UNKNOWN; |
||
2147 | |||
2148 | -- Otherwise, show the timer. |
||
2149 | else |
||
2150 | eta = SecondsToTime(_active.captures[i].cap - GetTime()); |
||
2151 | |||
2152 | -- If there is a capture imminent, indicate. |
||
2153 | if (eta == "") then |
||
2154 | eta = TITANBG_CAPTURE_IMINENT; |
||
2155 | end |
||
2156 | end |
||
2157 | |||
2158 | -- If not unknown, display timers. |
||
2159 | if (eta ~= TITANBG_CAPTURE_UNKNOWN) then |
||
2160 | local tOne, tTwo, tThree, tFour = WorldMap_GetPOITextureCoords(_active.captures[i].t); |
||
2161 | |||
2162 | -- Update the points. |
||
2163 | getglobal(frame .. "_Icon"):SetTexCoord(tOne, tTwo, tThree, tFour); |
||
2164 | getglobal(frame .. "_Point"):SetText(_active.captures[i].name); |
||
2165 | getglobal(frame .. "_Time"):SetText(eta); |
||
2166 | |||
2167 | -- Show the frame. |
||
2168 | getglobal(frame):Show(); |
||
2169 | |||
2170 | shown = shown + 1; |
||
2171 | end |
||
2172 | end |
||
2173 | |||
2174 | if (shown == 6) then |
||
2175 | break; |
||
2176 | end |
||
2177 | |||
2178 | if (not sv_menu["D_NT_TimersInvert"]) then |
||
2179 | i = i + 1; |
||
2180 | else |
||
2181 | i = i - 1; |
||
2182 | end |
||
2183 | end |
||
2184 | end |
||
2185 | end |
||
2186 | |||
2187 | -- ## Updates the on the screen display of the Warsong Gulch flag tracker. |
||
2188 | function TitanPanelTitanBG_NT_UpdateFlags() |
||
2189 | local i = 1; |
||
2190 | |||
2191 | if (sv_menu["D_OS_WSG_Invert"]) then i = 2; end |
||
2192 | |||
2193 | TitanPanelTitanBG_Display_Flag_1_ButtonText:SetText(""); |
||
2194 | TitanPanelTitanBG_Display_Flag_2_ButtonText:SetText(""); |
||
2195 | |||
2196 | TitanPanelTitanBG_Display_Flag_1:Hide(); |
||
2197 | TitanPanelTitanBG_Display_Flag_2:Hide(); |
||
2198 | |||
2199 | if (sv_menu["D_OS_WSG_Show"] and sv_menu["AddonEnabled"] and _player_zone == TITANBG_BG_WSG) then |
||
2200 | |||
2201 | -- Collect alliance flag information. |
||
2202 | if (_active.stats.wsg.alliance.player ~= "" and _active.stats.wsg.alliance.player ~= nil) then |
||
2203 | local color = ""; |
||
2204 | local class = ""; |
||
2205 | local player = TitanBG_GetPlayerData(_active.stats.wsg.alliance.player .. "|Alliance"); |
||
2206 | |||
2207 | if (player) then |
||
2208 | if (sv_menu["D_OS_WSG_AttachScore"]) then |
||
2209 | i = 1; |
||
2210 | end |
||
2211 | |||
2212 | if (sv_menu["D_OS_WSG_ColorClass"]) then |
||
2213 | color = TITANBG_COLOR_CLASS[TITANBG_CLASS[player.class]].color; |
||
2214 | end |
||
2215 | |||
2216 | if (sv_menu["D_OS_WSG_TextClass"]) then |
||
2217 | class = TITANBG_COLOR_WHITE .. " (" .. player.class .. ")"; |
||
2218 | end |
||
2219 | |||
2220 | -- Set icon. |
||
2221 | if (sv_menu["D_OS_WSG_AttachScore"]) then |
||
2222 | getglobal("TitanPanelTitanBG_Display_Flag_" .. i .. "_Icon"):Hide(); |
||
2223 | else |
||
2224 | getglobal("TitanPanelTitanBG_Display_Flag_" .. i .. "_Icon"):SetTexture("Interface\\WorldStateFrame\\HordeFlag"); |
||
2225 | getglobal("TitanPanelTitanBG_Display_Flag_" .. i .. "_Icon"):Show(); |
||
2226 | end |
||
2227 | |||
2228 | -- Set text. |
||
2229 | getglobal("TitanPanelTitanBG_Display_Flag_" .. i .. "_ButtonText"):SetText(color .. _active.stats.wsg.alliance.player .. class); |
||
2230 | getglobal("TitanPanelTitanBG_Display_Flag_" .. i .. "_Button"):SetWidth(getglobal("TitanPanelTitanBG_Display_Flag_" .. i .. "_ButtonText"):GetWidth()); |
||
2231 | |||
2232 | -- Set on click script. |
||
2233 | if (sv_menu["D_OS_WSG_Click"]) then |
||
2234 | getglobal("TitanPanelTitanBG_Display_Flag_" .. i .. "_Button"):SetScript("OnClick", function() |
||
2235 | TargetByName(_active.stats.wsg.alliance.player, true); |
||
2236 | end); |
||
2237 | end |
||
2238 | |||
2239 | getglobal("TitanPanelTitanBG_Display_Flag_" .. i):Show(); |
||
2240 | |||
2241 | if (sv_menu["D_OS_WSG_Invert"]) then |
||
2242 | i = i - 1; |
||
2243 | else |
||
2244 | i = i + 1; |
||
2245 | end |
||
2246 | end |
||
2247 | end |
||
2248 | |||
2249 | -- Collect horde flag information. |
||
2250 | if (_active.stats.wsg.horde.player ~= "" and _active.stats.wsg.horde.player ~= nil) then |
||
2251 | local color = ""; |
||
2252 | local class = ""; |
||
2253 | local player = TitanBG_GetPlayerData(_active.stats.wsg.horde.player .. "|Horde"); |
||
2254 | |||
2255 | if (player) then |
||
2256 | if (sv_menu["D_OS_WSG_AttachScore"]) then |
||
2257 | i = 2; |
||
2258 | end |
||
2259 | |||
2260 | if (sv_menu["D_OS_WSG_ColorClass"]) then |
||
2261 | color = TITANBG_COLOR_CLASS[TITANBG_CLASS[player.class]].color; |
||
2262 | end |
||
2263 | |||
2264 | if (sv_menu["D_OS_WSG_TextClass"]) then |
||
2265 | class = TITANBG_COLOR_WHITE .. " (" ..player.class .. ")"; |
||
2266 | end |
||
2267 | |||
2268 | -- Set icon. |
||
2269 | if (sv_menu["D_OS_WSG_AttachScore"]) then |
||
2270 | getglobal("TitanPanelTitanBG_Display_Flag_" .. i .. "_Icon"):Hide(); |
||
2271 | else |
||
2272 | getglobal("TitanPanelTitanBG_Display_Flag_" .. i .. "_Icon"):SetTexture("Interface\\WorldStateFrame\\AllianceFlag"); |
||
2273 | getglobal("TitanPanelTitanBG_Display_Flag_" .. i .. "_Icon"):Show(); |
||
2274 | end |
||
2275 | |||
2276 | -- Set text. |
||
2277 | getglobal("TitanPanelTitanBG_Display_Flag_" .. i .. "_ButtonText"):SetText(color .. _active.stats.wsg.horde.player .. class); |
||
2278 | getglobal("TitanPanelTitanBG_Display_Flag_" .. i .. "_Button"):SetWidth(getglobal("TitanPanelTitanBG_Display_Flag_" .. i .. "_ButtonText"):GetWidth()); |
||
2279 | |||
2280 | -- Set on click script. |
||
2281 | if (sv_menu["D_OS_WSG_Click"]) then |
||
2282 | getglobal("TitanPanelTitanBG_Display_Flag_" .. i .. "_Button"):SetScript("OnClick", function() |
||
2283 | TargetByName(_active.stats.wsg.horde.player, true); |
||
2284 | end); |
||
2285 | end |
||
2286 | |||
2287 | getglobal("TitanPanelTitanBG_Display_Flag_" .. i):Show(); |
||
2288 | |||
2289 | if (sv_menu["D_OS_WSG_Invert"]) then |
||
2290 | i = i - 1; |
||
2291 | else |
||
2292 | i = i + 1; |
||
2293 | end |
||
2294 | end |
||
2295 | end |
||
2296 | end |
||
2297 | end |
||
2298 | |||
2299 | |||
2300 | -- ############################# |
||
2301 | -- ## INITALISATION FUNCTIONS ## |
||
2302 | -- ############################# |
||
2303 | |||
2304 | |||
2305 | -- ## Performed when the addon is loaded. |
||
2306 | function TitanPanelTitanBGButton_OnLoad() |
||
2307 | this.registry = { |
||
2308 | id = TITAN_TITANBG_ID, |
||
2309 | menuText = TITAN_TITANBG_ID, |
||
2310 | tooltipTitle = TITANBG_TOOLTIP, |
||
2311 | buttonTextFunction = "TitanPanelTitanBGButton_SetButtonText", |
||
2312 | tooltipTextFunction = "TitanPanelTitanBGButton_SetTooltipText", |
||
2313 | icon = TITANBG_ARTWORK_PATH, |
||
2314 | iconWidth = 16, |
||
2315 | frequency = TITAN_TITANBG_FREQ; |
||
2316 | |||
2317 | savedVariables = { |
||
2318 | ShowIcon = 1, |
||
2319 | } |
||
2320 | }; |
||
2321 | |||
2322 | this:RegisterEvent("ADDON_LOADED"); |
||
2323 | this:RegisterEvent("VARIABLES_LOADED"); |
||
2324 | this:RegisterEvent("PLAYER_ENTERING_WORLD"); |
||
2325 | this:RegisterEvent("FRIENDLIST_UPDATE"); |
||
2326 | this:RegisterEvent("ZONE_CHANGED"); |
||
2327 | this:RegisterEvent("ZONE_CHANGED_NEW_AREA"); |
||
2328 | this:RegisterEvent("CHAT_MSG_SYSTEM"); |
||
2329 | this:RegisterEvent("UPDATE_BATTLEFIELD_STATUS"); |
||
2330 | this:RegisterEvent("ZONE_CHANGED_INDOORS"); |
||
2331 | this:RegisterEvent("BATTLEFIELDS_SHOW"); |
||
2332 | this:RegisterEvent("CHAT_MSG_BG_SYSTEM_ALLIANCE"); |
||
2333 | this:RegisterEvent("CHAT_MSG_BG_SYSTEM_HORDE"); |
||
2334 | |||
2335 | -- Register slash commands. |
||
2336 | SLASH_TITANBG1 = "/titanbg"; |
||
2337 | SLASH_TITANBG2 = "/tbg"; |
||
2338 | |||
2339 | -- Register slash command handler. |
||
2340 | SlashCmdList["TITANBG"] = function(command) |
||
2341 | if (not command or command == "") then |
||
2342 | TitanBG_Menu_Toggle(); |
||
2343 | elseif (string.find(command, " ")) then |
||
2344 | local c = string.sub(command, 0, string.find(command, " ") - 1); |
||
2345 | local val = string.sub(command, string.find(command, " ") + 1, string.len(command)); |
||
2346 | |||
2347 | if (string.lower(c) == "flag") then |
||
2348 | if ((string.lower(val) == "a" or string.lower(val) == "alliance") and _active.stats.wsg.alliance.player ~= "" and _active.stats.wsg.alliance.player ~= nil) then |
||
2349 | TargetByName(_active.stats.wsg.alliance.player, true); |
||
2350 | elseif ((string.lower(val) == "h" or string.lower(val) == "horde") and _active.stats.wsg.horde.player ~= "" and _active.stats.wsg.horde.player ~= nil) then |
||
2351 | TargetByName(_active.stats.wsg.horde.player, true); |
||
2352 | end |
||
2353 | end |
||
2354 | end |
||
2355 | end |
||
2356 | |||
2357 | -- Store any existing captures if the player is in a battleground. |
||
2358 | if (TitanPanelTitanBG_IsBattleground(_player_zone)) then |
||
2359 | _active_init_stored = false; |
||
2360 | TitanPanelTitanBG_CheckMap(_player_zone, true); |
||
2361 | _active_init_stored = true; |
||
2362 | end |
||
2363 | |||
2364 | -- Shows the status of each queue point returned by the server. If the slot is not taken up by a battleground, |
||
2365 | -- it will return the zone the user is currently in. |
||
2366 | -- !! DEBUG START |
||
2367 | |||
2368 | -- DEFAULT_CHAT_FRAME:AddMessage("Printing queue status ... "); |
||
2369 | |||
2370 | -- for i = 1, MAX_BATTLEFIELD_QUEUES do |
||
2371 | -- local _, name, _ = GetBattlefieldStatus(i); |
||
2372 | |||
2373 | -- DEFAULT_CHAT_FRAME:AddMessage("BG = " .. name); |
||
2374 | -- end |
||
2375 | |||
2376 | -- !! DEBUG END |
||
2377 | end |
||
2378 | |||
2379 | |||
2380 | -- ## Resets battleground status information to original values. |
||
2381 | function TitanPanelTitanBG_ResetBattlegroundInformation() |
||
2382 | |||
2383 | -- Battleground information variables. |
||
2384 | _bgs = { |
||
2385 | queue = 0; -- The number of battegrounds that are in queue or active status. |
||
2386 | |||
2387 | -- Table which links the blizzard battleground index to the correct information. |
||
2388 | blizzard = { |
||
2389 | [1] = nil, |
||
2390 | [2] = nil, |
||
2391 | [3] = nil, |
||
2392 | }; |
||
2393 | |||
2394 | -- Allows looping of the battlegrounds numerically. |
||
2395 | index = { |
||
2396 | [1] = TITANBG_BG_AV, |
||
2397 | [2] = TITANBG_BG_WSG, |
||
2398 | [3] = TITANBG_BG_AB, |
||
2399 | }; |
||
2400 | |||
2401 | -- Battleground information stored by name. |
||
2402 | names = { |
||
2403 | [TITANBG_BG_AV] = { |
||
2404 | index = 0, |
||
2405 | short = TITANBG_BG_AV_SHORT, |
||
2406 | name = TITANBG_BG_AV, |
||
2407 | status = TITANBG_BG_STATUS_NONE, |
||
2408 | instance = 0, |
||
2409 | expires = 0, |
||
2410 | |||
2411 | open_instances = 0, |
||
2412 | open_age = 0, |
||
2413 | |||
2414 | update = nil, |
||
2415 | |||
2416 | sound = false; |
||
2417 | sound_timer = 0; |
||
2418 | }, |
||
2419 | |||
2420 | [TITANBG_BG_WSG] = { |
||
2421 | index = 0, |
||
2422 | short = TITANBG_BG_WSG_SHORT, |
||
2423 | name = TITANBG_BG_WSG, |
||
2424 | status = TITANBG_BG_STATUS_NONE, |
||
2425 | instance = 0, |
||
2426 | expires = 0, |
||
2427 | |||
2428 | open_instances = 0, |
||
2429 | open_age = 0, |
||
2430 | |||
2431 | update = nil, |
||
2432 | |||
2433 | sound = false; |
||
2434 | sound_timer = 0; |
||
2435 | }, |
||
2436 | |||
2437 | [TITANBG_BG_AB] = { |
||
2438 | index = 0, |
||
2439 | short = TITANBG_BG_AB_SHORT, |
||
2440 | name = TITANBG_BG_AB, |
||
2441 | status = TITANBG_BG_STATUS_NONE, |
||
2442 | instance = 0, |
||
2443 | expires = 0, |
||
2444 | |||
2445 | open_instances = 0, |
||
2446 | open_age = 0, |
||
2447 | |||
2448 | update = nil, |
||
2449 | |||
2450 | sound = false; |
||
2451 | sound_timer = 0; |
||
2452 | }, |
||
2453 | } |
||
2454 | }; |
||
2455 | end |
||
2456 | |||
2457 | |||
2458 | -- ## Resets information on the current active battleground. |
||
2459 | function TitanPanelTitanBG_ResetActiveInformation() |
||
2460 | _active = { |
||
2461 | stats = { |
||
2462 | |||
2463 | bg = { |
||
2464 | name = "", |
||
2465 | index = "", |
||
2466 | instance = "", |
||
2467 | win = "", |
||
2468 | run = 0, |
||
2469 | total = 0, |
||
2470 | horde = 0, |
||
2471 | alliance = 0, |
||
2472 | }, |
||
2473 | |||
2474 | player = { |
||
2475 | standing = 0, |
||
2476 | kills = 0, |
||
2477 | deaths = 0, |
||
2478 | killing_blows = 0, |
||
2479 | honor = 0, |
||
2480 | |||
2481 | }, |
||
2482 | |||
2483 | av = { |
||
2484 | gy_assulted = 0, |
||
2485 | gy_defended = 0, |
||
2486 | towers_assaulted = 0, |
||
2487 | towers_defended = 0, |
||
2488 | mines_captured = 0, |
||
2489 | leaders_killed = 0, |
||
2490 | secondary_obj = 0, |
||
2491 | }, |
||
2492 | |||
2493 | wsg = { |
||
2494 | flag_captures = 0, |
||
2495 | flag_returns = 0, |
||
2496 | |||
2497 | alliance = { msg = "", flag = 1, player = "", }, |
||
2498 | horde = { msg = "", flag = 1, player = "", }, |
||
2499 | |||
2500 | players = { }; |
||
2501 | }, |
||
2502 | |||
2503 | ab = { |
||
2504 | bases_assulted = 0, |
||
2505 | bases_defended = 0, |
||
2506 | |||
2507 | bases_horde = 0; |
||
2508 | bases_alliance = 0; |
||
2509 | }, |
||
2510 | }, |
||
2511 | |||
2512 | captures = { |
||
2513 | }, |
||
2514 | }; |
||
2515 | end |
||
2516 | |||
2517 | -- ## Resets player information. |
||
2518 | function TitanPanelTitanBG_ResetPlayerInformation() |
||
2519 | _player_name = UnitName("player"); |
||
2520 | |||
2521 | if (UnitFactionGroup("player") == TITANBG_ALLIANCE) then |
||
2522 | _player_faction = TITANBG_ALLIANCE; |
||
2523 | _player_enemy_faction = TITANBG_HORDE; |
||
2524 | else |
||
2525 | _player_faction = TITANBG_HORDE; |
||
2526 | _player_enemy_faction = TITANBG_ALLIANCE; |
||
2527 | end |
||
2528 | |||
2529 | _player_realm = GetRealmName(); |
||
2530 | end |
||
2531 | |||
2532 | |||
2533 | -- ## Stores the original functions. |
||
2534 | function TitanPanelTitanBG_StoreFunctions() |
||
2535 | |||
2536 | -- Hook battlemap showing and hiding function to TitanBG. |
||
2537 | Hook_WorldStateFrame_ToggleMinimap = WorldStateFrame_ToggleMinimap; |
||
2538 | Hook_RepopMe = RepopMe; |
||
2539 | Hook_DialogDeathAccept = StaticPopupDialogs["DEATH"].OnAccept; |
||
2540 | Hook_DialogDeathCancel = StaticPopupDialogs["DEATH"].OnCancel; |
||
2541 | Hook_DialogBattlefieldEntryAccept = StaticPopupDialogs["CONFIRM_BATTLEFIELD_ENTRY"].OnAccept; |
||
2542 | Hook_DialogDeathOnShow = StaticPopupDialogs["DEATH"].OnShow; |
||
2543 | Hook_AcceptBattlefieldPort = AcceptBattlefieldPort; |
||
2544 | Hook_PlaySound = PlaySound; |
||
2545 | Hook_StaticPopup_Show = StaticPopup_Show; |
||
2546 | Hook_MiniMapBattlefieldFrame = MiniMapBattlefieldFrame:GetScript("OnClick"); |
||
2547 | |||
2548 | -- If the battlefield minimap hasn't been loaded, load it. |
||
2549 | if (not BattlefieldMinimap) then BattlefieldMinimap_LoadUI(); end |
||
2550 | if (BattlefieldMinimapCloseButton) then |
||
2551 | Hook_BattlefieldMinimapCloseButton = BattlefieldMinimapCloseButton:GetScript("OnClick"); |
||
2552 | end |
||
2553 | |||
2554 | Hook_StaticPopup1Button2OnClick = StaticPopup1Button2:GetScript("OnClick"); |
||
2555 | |||
2556 | -- Hook functions from other addons that may be overwritten. |
||
2557 | -- Titan Panel |
||
2558 | Hook_TitanPanel_AddButton = TitanPanel_AddButton; |
||
2559 | Hook_TitanPanel_RemoveButton = TitanPanel_RemoveButton; |
||
2560 | Hook_TitanPanelButton_OnClick = TitanPanelButton_OnClick; |
||
2561 | |||
2562 | -- Titan Honor Plus |
||
2563 | Hook_TitanPanelHonorPlus_ToggleVar_AutoBGMap = TitanPanelHonorPlus_ToggleVar_AutoBGMap; |
||
2564 | Hook_TitanPanelHonorPlus_ToggleVar_AutoJoinBG = TitanPanelHonorPlus_ToggleVar_AutoJoinBG; |
||
2565 | Hook_TitanHonorPlus_CheckBGConfirm = TitanHonorPlus_CheckBGConfirm; |
||
2566 | Hook_TitanHonorPlus_StaticPopup_OnHide = TitanHonorPlus_StaticPopup_OnHide; |
||
2567 | Hook_TitanPanelHonorPlus_ToggleVar_AutoRelease = TitanPanelHonorPlus_ToggleVar_AutoRelease; |
||
2568 | end |
||
2569 | |||
2570 | -- ## Overwrites the similar settings in other addons. |
||
2571 | function TitanPanelTitanBG_HookFunctions() |
||
2572 | TitanPanelTitanBG_ToggleOverwriteOtherSettings(); |
||
2573 | |||
2574 | if (sv_menu["AddonEnabled"]) then |
||
2575 | |||
2576 | -- Overwrite the Titan Panel show and hide functions for each addon, so that we know when our addon is enabled. |
||
2577 | TitanPanel_AddButton = function(id) |
||
2578 | if (id == TITAN_TITANBG_ID) then |
||
2579 | sv_menu["AddonEnabled"] = true; |
||
2580 | TitanPanelTitanBG_HookFunctions(); |
||
2581 | end |
||
2582 | |||
2583 | return Hook_TitanPanel_AddButton(id); |
||
2584 | end |
||
2585 | |||
2586 | TitanPanel_RemoveButton = function(id) |
||
2587 | if (id == TITAN_TITANBG_ID) then |
||
2588 | sv_menu["AddonEnabled"] = false; |
||
2589 | TitanPanelTitanBG_HookFunctions(); |
||
2590 | end |
||
2591 | |||
2592 | return Hook_TitanPanel_RemoveButton(id); |
||
2593 | end |
||
2594 | |||
2595 | -- Switch tooltip views if necessary. |
||
2596 | TitanPanelButton_OnClick = function(button, isChildButton) |
||
2597 | if (button == "RightButton" or (button == "LeftButton" and not _titan_titanbg_leftclick)) then |
||
2598 | return Hook_TitanPanelButton_OnClick(button, isChildButton); |
||
2599 | end |
||
2600 | |||
2601 | local id = TitanUtils_Ternary(isChildButton, TitanUtils_GetParentButtonID(), TitanUtils_GetButtonID()); |
||
2602 | |||
2603 | if (id == TITAN_TITANBG_ID) then |
||
2604 | if (not IsShiftKeyDown() and IsControlKeyDown()) then |
||
2605 | if (_display_queue_tt) then |
||
2606 | _display_queue_tt = false; |
||
2607 | else |
||
2608 | _display_queue_tt = true; |
||
2609 | end |
||
2610 | |||
2611 | TitanPanelButton_SetTooltip(TITAN_TITANBG_ID); |
||
2612 | GameTooltip:Show(); |
||
2613 | end |
||
2614 | end |
||
2615 | |||
2616 | _titan_titanbg_leftclick = false; |
||
2617 | end |
||
2618 | |||
2619 | -- Hook blizzard functions. |
||
2620 | |||
2621 | -- Do not play the battleground ready sound using this function. |
||
2622 | PlaySound = function(sound, titanbg) |
||
2623 | if (sound ~= "PVPTHROUGHQUEUE" or titanbg) then |
||
2624 | return Hook_PlaySound(sound); |
||
2625 | end |
||
2626 | end |
||
2627 | |||
2628 | -- Allow modification of the ready queue popup. |
||
2629 | StaticPopup_Show = function(which, text_arg1, text_arg2, data) |
||
2630 | local dialog = nil; |
||
2631 | |||
2632 | if (which ~= "CONFIRM_BATTLEFIELD_ENTRY" or (which == "CONFIRM_BATTLEFIELD_ENTRY" and not sv_menu["B_HideJoinPopup"])) then |
||
2633 | dialog = Hook_StaticPopup_Show(which, text_arg1, text_arg2, data); |
||
2634 | dialog.text_arg1 = text_arg1; |
||
2635 | dialog.text_arg2 = text_arg2; |
||
2636 | end |
||
2637 | |||
2638 | if (which == "CONFIRM_BATTLEFIELD_ENTRY" and dialog) then |
||
2639 | local text = getglobal(dialog:GetName() .. "Text"); |
||
2640 | local pop = { }; |
||
2641 | |||
2642 | -- dialog:SetScript("OnHide", function() |
||
2643 | -- while (i <= table.getn(_popups)) do |
||
2644 | -- if (_popups[i].dialog.text_arg1 == this.text_arg1) then |
||
2645 | -- table.remove(_popups, i); |
||
2646 | -- break; |
||
2647 | -- end |
||
2648 | -- end |
||
2649 | -- end); |
||
2650 | |||
2651 | |||
2652 | pop.dialog = dialog; |
||
2653 | pop.text = text; |
||
2654 | pop.which = which; |
||
2655 | pop.data = data; |
||
2656 | pop.text_arg1 = text_arg1; |
||
2657 | pop.text_arg2 = text_arg2; |
||
2658 | |||
2659 | table.insert(_popups, pop); |
||
2660 | |||
2661 | TitanPanelTitanBG_StoreBattlegroundInformation(); |
||
2662 | end |
||
2663 | |||
2664 | return dialog; |
||
2665 | end |
||
2666 | |||
2667 | -- Allow blizzard functions to release or ressurect players, without being interfered with by the addon. |
||
2668 | StaticPopupDialogs["DEATH"].OnAccept = function() |
||
2669 | _blizzard_releasesoul = true; |
||
2670 | Hook_DialogDeathAccept(); |
||
2671 | _blizzard_releasesoul = false; |
||
2672 | end |
||
2673 | |||
2674 | StaticPopupDialogs["DEATH"].OnCancel = function(data, reason) |
||
2675 | _blizzard_releasesoul = true; |
||
2676 | Hook_DialogDeathCancel(data, reason); |
||
2677 | _blizzard_releasesoul = false; |
||
2678 | end |
||
2679 | |||
2680 | -- Allow blizzard functions to join battlegrounds without interferance. |
||
2681 | StaticPopupDialogs["CONFIRM_BATTLEFIELD_ENTRY"].OnAccept = function(data) |
||
2682 | _blizzard_interactbg = true; |
||
2683 | Hook_DialogBattlefieldEntryAccept(data); |
||
2684 | _blizzard_interactbg = false; |
||
2685 | end |
||
2686 | |||
2687 | -- Does not show the ressurect functions if it should be hidden. |
||
2688 | StaticPopupDialogs["DEATH"].OnShow = function() |
||
2689 | if (sv_menu["B_AutoRelease"] and TitanPanelTitanBG_IsBattleground(_player_zone)) then |
||
2690 | if ((sv_menu["B_ReleaseCheck"] and not HasSoulstone()) or not sv_menu["B_ReleaseCheck"]) then |
||
2691 | TitanPanelTitanBG_RepopMe(); |
||
2692 | end |
||
2693 | else |
||
2694 | Hook_DialogDeathOnShow(); |
||
2695 | end |
||
2696 | end |
||
2697 | |||
2698 | -- When you shift click the battleground icon, shows or hides the battleground minimap for the duration |
||
2699 | -- of your stay in the zone. |
||
2700 | MiniMapBattlefieldFrame:SetScript("OnClick", |
||
2701 | function() |
||
2702 | if (IsShiftKeyDown()) then |
||
2703 | if ((sv_menu["B_AutoShowBGMinimap"] and BattlefieldMinimap:IsShown()) or (not TitanPanelTitanBG_IsBattleground(_player_zone) and BattlefieldMinimap:IsShown())) then |
||
2704 | _blizzard_manualshowbg = "HIDE"; |
||
2705 | elseif ((not sv_menu["B_AutoShowBGMinimap"] and not BattlefieldMinimap:IsShown()) or (not TitanPanelTitanBG_IsBattleground(_player_zone) and not BattlefieldMinimap:IsShown())) then |
||
2706 | _blizzard_manualshowbg = "SHOW"; |
||
2707 | else |
||
2708 | _blizzard_manualshowbg = nil; |
||
2709 | end |
||
2710 | end |
||
2711 | |||
2712 | return Hook_MiniMapBattlefieldFrame(); |
||
2713 | end |
||
2714 | ); |
||
2715 | |||
2716 | -- If the battlefield minimap hasn't been loaded, load it. |
||
2717 | if (not BattlefieldMinimap) then BattlefieldMinimap_LoadUI(); end |
||
2718 | if (BattlefieldMinimapCloseButton) then |
||
2719 | |||
2720 | -- When you click the close button on the battleground minimap, closes the minimap for the duration of |
||
2721 | -- the player's stay in the zone. |
||
2722 | BattlefieldMinimapCloseButton:SetScript("OnClick", |
||
2723 | function() |
||
2724 | if ((sv_menu["B_AutoShowBGMinimap"] and BattlefieldMinimap:IsShown()) or (not TitanPanelTitanBG_IsBattleground(_player_zone) and attlefieldMinimap:IsShown())) then |
||
2725 | _blizzard_manualshowbg = "HIDE"; |
||
2726 | else |
||
2727 | _blizzard_manualshowbg = nil; |
||
2728 | end |
||
2729 | |||
2730 | return Hook_BattlefieldMinimapCloseButton(); |
||
2731 | end |
||
2732 | ); |
||
2733 | end |
||
2734 | |||
2735 | -- When you press the 'Hide' button, it pauses the auto join timer. |
||
2736 | StaticPopup1Button2:SetScript("OnClick", |
||
2737 | function() |
||
2738 | |||
2739 | -- If the user want to pause the auto join timer. |
||
2740 | if (sv_menu["B_AutoJoinBG"] and _autojoin_paused == 0) then |
||
2741 | _autojoin_paused = _autojoin_time - GetTime(); |
||
2742 | end |
||
2743 | |||
2744 | return Hook_StaticPopup1Button2OnClick(); |
||
2745 | end |
||
2746 | ); |
||
2747 | |||
2748 | -- Run data collection. |
||
2749 | TitanPanelTitanBG_ZonesChanged(); |
||
2750 | else |
||
2751 | |||
2752 | -- Unhook other addon functions. |
||
2753 | TitanPanelButton_OnClick = Hook_TitanPanelButton_OnClick; |
||
2754 | |||
2755 | -- Unhook blizzard functions. |
||
2756 | PlaySound = Hook_PlaySound; |
||
2757 | |||
2758 | StaticPopup_Show = Hook_StaticPopup_Show; |
||
2759 | |||
2760 | StaticPopupDialogs["DEATH"].OnAccept = Hook_DialogDeathAccept; |
||
2761 | StaticPopupDialogs["DEATH"].OnCancel = Hook_DialogDeathCancel; |
||
2762 | StaticPopupDialogs["CONFIRM_BATTLEFIELD_ENTRY"].OnAccept = Hook_DialogBattlefieldEntryAccept; |
||
2763 | StaticPopupDialogs["DEATH"].OnShow = Hook_DialogDeathOnShow; |
||
2764 | |||
2765 | MiniMapBattlefieldFrame:SetScript("OnClick", Hook_MiniMapBattlefieldFrame); |
||
2766 | |||
2767 | -- If the battlefield minimap hasn't been loaded, load it. |
||
2768 | if (not BattlefieldMinimap) then BattlefieldMinimap_LoadUI(); end |
||
2769 | if (BattlefieldMinimapCloseButton) then |
||
2770 | BattlefieldMinimapCloseButton:SetScript("OnClick", Hook_BattlefieldMinimapCloseButton); |
||
2771 | end |
||
2772 | |||
2773 | StaticPopup1Button2:SetScript("OnClick", Hook_StaticPopup1Button2OnClick); |
||
2774 | |||
2775 | -- Reset variables. |
||
2776 | _autojoin_bg = ""; |
||
2777 | _autojoin_time = 0; |
||
2778 | _autojoin_paused = 0; |
||
2779 | |||
2780 | _autoleave_time = 0; |
||
2781 | _autoleave_paused = 0; |
||
2782 | |||
2783 | -- Update interface. |
||
2784 | TitanPanelTitanBG_NT_UpdateCaptures(true); |
||
2785 | TitanPanelTitanBG_NT_UpdateFlags(); |
||
2786 | TitanPanelTitanBG_ToggleMiniMapIcon(); |
||
2787 | TitanPanelTitanBG_ToggleLockCaptures(); |
||
2788 | |||
2789 | BattlefieldFrame_UpdateStatus(); |
||
2790 | end |
||
2791 | end |