vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | Name: Glory-2.0 |
||
3 | Revision: $Rev: 8985 $ |
||
4 | Author(s): ckknight (ckknight@gmail.com) |
||
5 | Elkano (elkano@gmx.de) |
||
6 | hyperactiveChipmunk (hyperactiveChipmunk@gmail.com) |
||
7 | Website: http://ckknight.wowinterface.com/ |
||
8 | Documentation: http://wiki.wowace.com/index.php/Glory-2.0 |
||
9 | SVN: http://svn.wowace.com/root/trunk/GloryLib/Glory-2.0 |
||
10 | Description: A library for PvP and Battlegrounds. |
||
11 | Dependencies: AceLibrary, Babble-Zone-2.0, Deformat-2.0, AceEvent-2.0, AceConsole-2.0 (optional) |
||
12 | |||
13 | Notes: To use this library, the per-character saved variable Glory2DB must be available. |
||
14 | ]] |
||
15 | |||
16 | local MAJOR_VERSION = "Glory-2.0" |
||
17 | local MINOR_VERSION = "$Revision: 8985 $" |
||
18 | |||
19 | if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary") end |
||
20 | if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end |
||
21 | |||
22 | if not AceLibrary:HasInstance("Babble-Zone-2.0") then error(MAJOR_VERSION .. " requires Babble-Zone-2.0") end |
||
23 | if not AceLibrary:HasInstance("Deformat-2.0") then error(MAJOR_VERSION .. " requires Deformat-2.0") end |
||
24 | if not AceLibrary:HasInstance("AceEvent-2.0") then error(MAJOR_VERSION .. " requires AceEvent-2.0") end |
||
25 | |||
26 | local new, del |
||
27 | do |
||
28 | local list = setmetatable({}, {__mode="k"}) |
||
29 | function new() |
||
30 | local t = next(list) |
||
31 | if t then |
||
32 | list[t] = nil |
||
33 | return t |
||
34 | else |
||
35 | return {} |
||
36 | end |
||
37 | end |
||
38 | function del(t) |
||
39 | setmetatable(t, nil) |
||
40 | for k in pairs(t) do |
||
41 | t[k] = nil |
||
42 | end |
||
43 | table.setn(t, 0) |
||
44 | list[t] = true |
||
45 | end |
||
46 | end |
||
47 | |||
48 | local PATTERN_HORDE_FLAG_PICKED_UP, PATTERN_HORDE_FLAG_DROPPED, PATTERN_HORDE_FLAG_CAPTURED, PATTERN_ALLIANCE_FLAG_PICKED_UP, PATTERN_ALLIANCE_FLAG_DROPPED, PATTERN_ALLIANCE_FLAG_CAPTURED, FACTION_DEFILERS, FACTION_FROSTWOLF_CLAN, FACTION_WARSONG_OUTRIDERS, FACTION_LEAGUE_OF_ARATHOR, FACTION_STORMPIKE_GUARD, FACTION_SILVERWING_SENTINELS |
||
49 | |||
50 | local PATTERN_GWSUII_SCORE, PATTERN_GWSUII_BASES |
||
51 | local BGObjectiveDescriptions, BGChatAnnouncements, BGPatternReplacements, BGAcronyms, BattlefieldZoneObjectiveTimes, BattlefieldZoneResourceData --hC |
||
52 | |||
53 | local deformat = AceLibrary("Deformat-2.0") |
||
54 | local Z = AceLibrary("Babble-Zone-2.0") |
||
55 | local AceEvent = AceLibrary("AceEvent-2.0") |
||
56 | |||
57 | local WARSONG_GULCH = Z"Warsong Gulch" |
||
58 | local ALTERAC_VALLEY = Z"Alterac Valley" |
||
59 | local ARATHI_BASIN = Z"Arathi Basin" |
||
60 | |||
61 | local locale = GetLocale() |
||
62 | if locale ~= "deDE" then |
||
63 | locale = "enUS" |
||
64 | end |
||
65 | |||
66 | if locale == "enUS" then |
||
67 | PATTERN_HORDE_FLAG_PICKED_UP = "The Horde [Ff]lag was picked up by ([^!]+)!" |
||
68 | PATTERN_HORDE_FLAG_DROPPED = "The Horde [Ff]lag was dropped by (%a+)!" |
||
69 | PATTERN_HORDE_FLAG_CAPTURED = "(%a+) captured the Horde [Ff]lag!" |
||
70 | PATTERN_ALLIANCE_FLAG_PICKED_UP = "The Alliance [Ff]lag was picked up by (%a+)!" |
||
71 | PATTERN_ALLIANCE_FLAG_DROPPED = "The Alliance [Ff]lag was dropped by (%a+)!" |
||
72 | PATTERN_ALLIANCE_FLAG_CAPTURED = "(%a+) captured the Alliance [Ff]lag!" |
||
73 | |||
74 | FACTION_DEFILERS = "Defilers" |
||
75 | FACTION_FROSTWOLF_CLAN = "Frostwolf Clan" |
||
76 | FACTION_WARSONG_OUTRIDERS = "Warsong Outriders" |
||
77 | |||
78 | FACTION_LEAGUE_OF_ARATHOR = "League of Arathor" |
||
79 | FACTION_STORMPIKE_GUARD = "Stormpike Guard" |
||
80 | FACTION_SILVERWING_SENTINELS = "Silverwing Sentinels" |
||
81 | |||
82 | BGObjectiveDescriptions = { |
||
83 | ALLIANCE_CONTROLLED = "Alliance Controlled", |
||
84 | HORDE_CONTROLLED = "Horde Controlled", |
||
85 | IN_CONFLICT = "In Conflict", |
||
86 | UNCONTROLLED = "Uncontrolled", |
||
87 | DESTROYED = "Destroyed", |
||
88 | } |
||
89 | |||
90 | BGChatAnnouncements = { |
||
91 | BGObjectiveClaimedAnnouncements = { |
||
92 | PATTERN_OBJECTIVE_CLAIMED_AB = "claims the ([%w ]+).* (%a+) will control", |
||
93 | }, |
||
94 | |||
95 | BGObjectiveAttackedAnnouncements = { |
||
96 | PATTERN_OBJECTIVE_ATTACKED_AB = "assaulted the ([%w ]+)", |
||
97 | PATTERN_OBJECTIVE_ATTACKED_AV0 = "The ([%w ]+) is under attack", |
||
98 | PATTERN_OBJECTIVE_ATTACKED_AV1 = "^([%w ]+) is under attack", |
||
99 | }, |
||
100 | |||
101 | BGObjectiveDefendedAnnouncements = { |
||
102 | PATTERN_OBJECTIVE_DEFENDED_AB = "defended the ([%w ]+)", |
||
103 | }, |
||
104 | |||
105 | BGObjectiveCapturedAnnouncements = { |
||
106 | PATTERN_OBJECTIVE_CAPTURED_AB = "The (%a+) has taken the ([%w ]+)", |
||
107 | PATTERN_OBJECTIVE_CAPTURED_AV0 = "The ([%w ]+) was taken by the (%a+)", |
||
108 | PATTERN_OBJECTIVE_CAPTURED_AV1 = "^([%w ]+) was taken by the (%a+)", |
||
109 | PATTERN_OBJECTIVE_CAPTURED_AV2 = "the ([%w ]+) is.*MINE", --and the Irondeep Mine is...MINE! |
||
110 | PATTERN_OBJECTIVE_CAPTURED_AV3 = "claims the ([%w ]+)", --Snivvle claims the Coldtooth Mine! |
||
111 | }, |
||
112 | |||
113 | BGObjectiveDestroyedAnnouncements = { |
||
114 | PATTERN_OBJECTIVE_DESTROYED_AV0 = "The ([%w ]+) was destroyed", |
||
115 | PATTERN_OBJECTIVE_DESTROYED_AV1 = "^([%w ]+) was destroyed", |
||
116 | }, |
||
117 | } |
||
118 | |||
119 | BGPatternReplacements = { |
||
120 | ["mine"] = "gold mine", |
||
121 | ["southern farm"] = "farm" |
||
122 | } |
||
123 | |||
124 | BGAcronyms = { |
||
125 | [ALTERAC_VALLEY] = "AV", |
||
126 | [ARATHI_BASIN] = "AB", |
||
127 | [WARSONG_GULCH] = "WSG", |
||
128 | } |
||
129 | |||
130 | PATTERN_GWSUII_SCORE = "(%d+/%d+)" --for lifting the score out of the first return value of GetWorldStateUIInfo(index) |
||
131 | PATTERN_GWSUII_BASES = "Bases: (%d+)" --for lifting the number of bases held in Arathi Basin |
||
132 | PATTERN_GWSUII_RESOURCES = "Resources: (%d+)" --for lifting the number of bases held in Arathi Basin |
||
133 | PATTERN_OBJECTIVE_HOLDER = "([%w ]+) Controlled" |
||
134 | |||
135 | elseif locale == "deDE" then |
||
136 | PATTERN_HORDE_FLAG_PICKED_UP = "([^!]+) hat die [Ff]lagge der Horde aufgenommen!" |
||
137 | PATTERN_HORDE_FLAG_DROPPED = "(%a+) hat die [Ff]lagge der Horde fallen lassen!" |
||
138 | PATTERN_HORDE_FLAG_CAPTURED = "(%a+) hat die [Ff]lagge der Horde errungen!" |
||
139 | PATTERN_ALLIANCE_FLAG_PICKED_UP = "(%a+) hat die [Ff]lagge der Allianz aufgenommen!" |
||
140 | PATTERN_ALLIANCE_FLAG_DROPPED = "(%a+) hat die [Ff]lagge der Allianz fallen lassen!" |
||
141 | PATTERN_ALLIANCE_FLAG_CAPTURED = "(%a+) hat die [Ff]lagge der Allianz errungen!" |
||
142 | |||
143 | FACTION_DEFILERS = "Die Entweihten" |
||
144 | FACTION_FROSTWOLF_CLAN = "Frostwolfklan" |
||
145 | FACTION_WARSONG_OUTRIDERS = "Warsongvorhut" |
||
146 | |||
147 | FACTION_LEAGUE_OF_ARATHOR = "Liga von Arathor" |
||
148 | FACTION_STORMPIKE_GUARD = "Stormpike Garde" |
||
149 | FACTION_SILVERWING_SENTINELS = "Silverwing Schildwache" |
||
150 | |||
151 | BGObjectiveDescriptions = { |
||
152 | ALLIANCE_CONTROLLED = "Kontrolliert von der Allianz", |
||
153 | HORDE_CONTROLLED = "Kontrolliert von der Horde", |
||
154 | IN_CONFLICT = "Umk\195\164mpft", |
||
155 | UNCONTROLLED = "Unkontrolliert", |
||
156 | DESTROYED = "Zerst\195\182rt", |
||
157 | } |
||
158 | |||
159 | BGChatAnnouncements = { |
||
160 | BGObjectiveClaimedAnnouncements = { |
||
161 | PATTERN_OBJECTIVE_CLAIMED_AB0 = "hat das (.+) besetzt.* die (%a+) in", |
||
162 | PATTERN_OBJECTIVE_CLAIMED_AB1 = "hat den (.+) besetzt.* die (%a+) in", |
||
163 | PATTERN_OBJECTIVE_CLAIMED_AB2 = "hat die (.+) besetzt.* die (%a+) in", |
||
164 | PATTERN_OBJECTIVE_CLAIMED_AB3 = "hat (S\195\164gewerk) besetzt.* die (%a+) in", |
||
165 | PATTERN_OBJECTIVE_CLAIMED_AV0 = "hat den (.+) besetzt.* erlangt die (%a+) die Kontrolle" |
||
166 | }, |
||
167 | |||
168 | BGObjectiveAttackedAnnouncements = { |
||
169 | PATTERN_OBJECTIVE_ATTACKED_AB0 = "das (.+) angegriffen", |
||
170 | PATTERN_OBJECTIVE_ATTACKED_AB1 = "den (.+) angegriffen", |
||
171 | PATTERN_OBJECTIVE_ATTACKED_AB2 = "die (.+) angegriffen", |
||
172 | PATTERN_OBJECTIVE_ATTACKED_AV0 = "Das (.+) wird angegriffen.*wird die (%a+) es", |
||
173 | PATTERN_OBJECTIVE_ATTACKED_AV1 = "Der (.+) wird angegriffen.*wird die (%a+) ihn", |
||
174 | PATTERN_OBJECTIVE_ATTACKED_AV2 = "Die (.+) wird angegriffen.*wird die (%a+) sie", |
||
175 | }, |
||
176 | |||
177 | BGObjectiveDefendedAnnouncements = { |
||
178 | PATTERN_OBJECTIVE_DEFENDED_AB0 = "das (.+) verteidigt", |
||
179 | PATTERN_OBJECTIVE_DEFENDED_AB1 = "den (.+) verteidigt", |
||
180 | PATTERN_OBJECTIVE_DEFENDED_AB2 = "die (.+) verteidigt", |
||
181 | }, |
||
182 | |||
183 | BGObjectiveCapturedAnnouncements = { |
||
184 | PATTERN_OBJECTIVE_CAPTURED_AB0 = "Die (%a+) hat das (.+) eingenommen", |
||
185 | PATTERN_OBJECTIVE_CAPTURED_AB1 = "Die (%a+) hat den (.+) eingenommen", |
||
186 | PATTERN_OBJECTIVE_CAPTURED_AB2 = "Die (%a+) hat die (.+) eingenommen", |
||
187 | PATTERN_OBJECTIVE_CAPTURED_AV0 = "Das (.+) wurde von der (%a+) erobert", |
||
188 | PATTERN_OBJECTIVE_CAPTURED_AV1 = "Der (.+) wurde von der (%a+) erobert", |
||
189 | PATTERN_OBJECTIVE_CAPTURED_AV2 = "geh\195\182rt jetzt die (.+)!", |
||
190 | }, |
||
191 | |||
192 | BGObjectiveDestroyedAnnouncements = { |
||
193 | PATTERN_OBJECTIVE_DESTROYED_AV0 = "Der (.+) wurde von der (%a+) zerst\195\182rt", |
||
194 | }, |
||
195 | } |
||
196 | |||
197 | BGPatternReplacements = { |
||
198 | ["Schmiede"] = "Schmied", |
||
199 | ["Mine"] = "Goldmine", |
||
200 | ["s\195\188dlichen Hof"] = "Hof", |
||
201 | } |
||
202 | |||
203 | BGAcronyms = { |
||
204 | [ALTERAC_VALLEY] = "AV", -- CHECK |
||
205 | [ARATHI_BASIN] = "AB", -- CHECK |
||
206 | [WARSONG_GULCH] = "WSG", -- CHECK |
||
207 | } |
||
208 | |||
209 | PATTERN_GWSUII_SCORE = "(%d+/%d+)" --for lifting the score out of the first return value of GetWorldStateUIInfo(index) |
||
210 | PATTERN_GWSUII_BASES = "Basen: (%d+)" --for lifting the number of bases held in Arathi Basin |
||
211 | PATTERN_GWSUII_RESOURCES = "Ressourcen: (%d+)" --for lifting the number of bases held in Arathi Basin -- CHECK |
||
212 | PATTERN_OBJECTIVE_HOLDER = "Kontrolliert von der ([%w ]+)" |
||
213 | end |
||
214 | |||
215 | BattlefieldZoneObjectiveTimes = { |
||
216 | [ARATHI_BASIN] = 62.5, |
||
217 | [ALTERAC_VALLEY] = 302.5, |
||
218 | } |
||
219 | |||
220 | BattlefieldZoneResourceData = { |
||
221 | [ARATHI_BASIN] = { [0]=0, 5/6, 10/9, 5/3, 10/3, 30, 2000 } |
||
222 | } |
||
223 | |||
224 | local Glory = {} |
||
225 | local events = {} |
||
226 | |||
227 | AceEvent:embed(events) |
||
228 | |||
229 | local _,race = UnitRace("player") |
||
230 | local isHorde = (race == "Orc" or race == "Troll" or race == "Tauren" or race == "Scourge") |
||
231 | local playerName = UnitName("player") |
||
232 | local playerRealm = GetRealmName() |
||
233 | |||
234 | local enemyList = {} |
||
235 | |||
236 | local function CheckNewWeek(self) |
||
237 | local _,_,lastWeekHonor,_ = GetPVPLastWeekStats() |
||
238 | if lastWeekHonor ~= self.data.lastWeek then |
||
239 | self.data.lastWeek = lastWeekHonor |
||
240 | events:TriggerEvent("Glory_NewWeek") |
||
241 | end |
||
242 | end |
||
243 | |||
244 | local function CheckNewDay(self) |
||
245 | local _,_,yesterdayHonor = GetPVPYesterdayStats() |
||
246 | local lifetimeHK,_,_ = GetPVPLifetimeStats() |
||
247 | if yesterdayHonor ~= self.data.yesterday and not (yesterdayHonor == 0 and lifetimeHK == 0) then |
||
248 | self.data.yesterday = yesterdayHonor |
||
249 | self.data.hks = {} |
||
250 | self.data.todayHK = 0 |
||
251 | self.data.todayHKHonor = 0 |
||
252 | self.data.todayBonusHonor = 0 |
||
253 | self.data.todayDeaths = 0 |
||
254 | events:TriggerEvent("Glory_NewDay") |
||
255 | end |
||
256 | end |
||
257 | |||
258 | local function IncreaseHKs(self, person) |
||
259 | self.data.todayHK = self.data.todayHK + 1 |
||
260 | self.data.hks[person] = (self.data.hks[person] or 0) + 1 |
||
261 | return self.data.hks[person] |
||
262 | end |
||
263 | |||
264 | local function IncreaseHKHonor(self, amount) |
||
265 | self.data.todayHKHonor = self.data.todayHKHonor + amount |
||
266 | end |
||
267 | |||
268 | local function IncreaseBonusHonor(self, amount) |
||
269 | self.data.todayBonusHonor = self.data.todayBonusHonor + amount |
||
270 | end |
||
271 | |||
272 | local function IncreaseBattlegroundsWins(self) |
||
273 | if self:IsInAlteracValley() then |
||
274 | self.data.avWin = self.data.avWin + 1 |
||
275 | events:TriggerEvent("Glory_BGWinAV") |
||
276 | elseif self:IsInArathiBasin() then |
||
277 | self.data.abWin = self.data.abWin + 1 |
||
278 | events:TriggerEvent("Glory_BGWinAB") |
||
279 | else |
||
280 | self.data.wsgWin = self.data.wsgWin + 1 |
||
281 | events:TriggerEvent("Glory_BGWinWSG") |
||
282 | end |
||
283 | events:TriggerEvent("Glory_BGWin") |
||
284 | end |
||
285 | |||
286 | local function IncreaseBattlegroundsLosses(self) |
||
287 | if self:IsInAlteracValley() then |
||
288 | self.data.avLoss = self.data.avLoss + 1 |
||
289 | events:TriggerEvent("Glory_BGLossAV") |
||
290 | elseif self:IsInArathiBasin() then |
||
291 | self.data.abLoss = self.data.abLoss + 1 |
||
292 | events:TriggerEvent("Glory_BGLossAB") |
||
293 | else |
||
294 | self.data.wsgLoss = self.data.wsgLoss + 1 |
||
295 | events:TriggerEvent("Glory_BGLossWSG") |
||
296 | end |
||
297 | events:TriggerEvent("Glory_BGLoss") |
||
298 | end |
||
299 | |||
300 | local function IncreaseDeaths(self) |
||
301 | self.data.todayDeaths = self.data.todayDeaths + 1 |
||
302 | events:TriggerEvent("Glory_Death") |
||
303 | end |
||
304 | |||
305 | local db |
||
306 | |||
307 | local function VerifyData(self) |
||
308 | if not self.data then |
||
309 | if type(Glory2DB) ~= "table" then |
||
310 | Glory2DB = {} |
||
311 | end |
||
312 | db = Glory2DB |
||
313 | if type(db[MAJOR_VERSION]) ~= "table" then |
||
314 | db[MAJOR_VERSION] = {} |
||
315 | end |
||
316 | self.data = db[MAJOR_VERSION] |
||
317 | elseif db ~= Glory2DB then |
||
318 | local old = db |
||
319 | local new = Glory2DB |
||
320 | if type(new) ~= "table" then |
||
321 | Glory2DB = old |
||
322 | else |
||
323 | for k in pairs(old) do |
||
324 | if not new[k] then |
||
325 | new[k] = old[k] |
||
326 | elseif new[k].time == nil then |
||
327 | new[k] = old[k] |
||
328 | elseif old[k].time == nil then |
||
329 | -- keep new |
||
330 | elseif new[k].time < old[k].time then |
||
331 | new[k] = old[k] |
||
332 | end |
||
333 | end |
||
334 | db = new |
||
335 | self.data = db[MAJOR_VERSION] |
||
336 | end |
||
337 | end |
||
338 | if not self.data.hks then self.data.hks = {} end |
||
339 | if not self.data.todayDeaths then self.data.todayDeaths = 0 end |
||
340 | if not self.data.todayHK then self.data.todayHK = 0 end |
||
341 | if not self.data.todayHKHonor then self.data.todayHKHonor = 0 end |
||
342 | if not self.data.todayBonusHonor then self.data.todayBonusHonor = 0 end |
||
343 | if not self.data.wsgWin then self.data.wsgWin = 0 end |
||
344 | if not self.data.wsgLoss then self.data.wsgLoss = 0 end |
||
345 | if not self.data.abWin then self.data.abWin = 0 end |
||
346 | if not self.data.abLoss then self.data.abLoss = 0 end |
||
347 | if not self.data.avWin then self.data.avWin = 0 end |
||
348 | if not self.data.avLoss then self.data.avLoss = 0 end |
||
349 | if not self.data.yesterday then self.data.yesterday = 0 end |
||
350 | if not self.data.lastWeek then self.data.lastWeek = 0 end |
||
351 | |||
352 | CheckNewDay(self) |
||
353 | CheckNewWeek(self) |
||
354 | events:UNIT_PVP_UPDATE() |
||
355 | end |
||
356 | |||
357 | function events:ADDON_LOADED() |
||
358 | VerifyData(Glory) |
||
359 | end |
||
360 | |||
361 | function events:VARIABLES_LOADED() |
||
362 | VerifyData(Glory) |
||
363 | end |
||
364 | |||
365 | function events:PLAYER_LOGOUT() |
||
366 | Glory.data.time = time() |
||
367 | end |
||
368 | |||
369 | function events:CHAT_MSG_COMBAT_HONOR_GAIN(text) |
||
370 | CheckNewDay(Glory) |
||
371 | local name, rank, honor = deformat(text, COMBATLOG_HONORGAIN) |
||
372 | if name then |
||
373 | local realm = enemyList[name] or playerRealm |
||
374 | if realm ~= playerRealm then |
||
375 | name = name .. "-" .. realm |
||
376 | end |
||
377 | local kills = IncreaseHKs(Glory, name) |
||
378 | local factor |
||
379 | factor = (11 - kills) / 10 |
||
380 | if factor < 0 then |
||
381 | factor = 0 |
||
382 | end |
||
383 | local realHonor = ceil(honor * factor) |
||
384 | IncreaseHKHonor(Glory, realHonor) |
||
385 | events:TriggerEvent("Glory_GainHK", rank, name, realHonor, kills) |
||
386 | return |
||
387 | end |
||
388 | |||
389 | local bonus = deformat(text, COMBATLOG_HONORAWARD) |
||
390 | if bonus then |
||
391 | bonus = tonumber(bonus) |
||
392 | IncreaseBonusHonor(Glory, bonus) |
||
393 | events:TriggerEvent("Glory_GainBonusHonor", bonus) |
||
394 | end |
||
395 | end |
||
396 | |||
397 | function events:CHAT_MSG_BG_SYSTEM_NEUTRAL(text) |
||
398 | if string.find(string.lower(text), string.lower(VICTORY_TEXT0)) then |
||
399 | if isHorde then |
||
400 | IncreaseBattlegroundsWins(Glory) |
||
401 | else |
||
402 | IncreaseBattlegroundsLosses(Glory) |
||
403 | end |
||
404 | elseif string.find(string.lower(text), string.lower(VICTORY_TEXT1)) then |
||
405 | if not isHorde then |
||
406 | IncreaseBattlegroundsWins(Glory) |
||
407 | else |
||
408 | IncreaseBattlegroundsLosses(Glory) |
||
409 | end |
||
410 | end |
||
411 | end |
||
412 | |||
413 | function events:CHAT_MSG_BG_SYSTEM_HORDE(text) |
||
414 | if Glory:IsInWarsongGulch() then |
||
415 | local _, _, hordeFC = string.find(text, PATTERN_ALLIANCE_FLAG_PICKED_UP) |
||
416 | if hordeFC then |
||
417 | Glory.hordeFC = hordeFC |
||
418 | events:TriggerEvent("Glory_AllianceFlagPickedUp", Glory.hordeFC) |
||
419 | events:TriggerEvent("Glory_AllianceFlagCarrierUpdate", Glory.hordeFC) |
||
420 | if not isHorde then |
||
421 | events:TriggerEvent("Glory_FriendlyFlagPickedUp", Glory.hordeFC) |
||
422 | events:TriggerEvent("Glory_FriendlyFlagCarrierUpdate", Glory.hordeFC) |
||
423 | else |
||
424 | events:TriggerEvent("Glory_HostileFlagPickedUp", Glory.hordeFC) |
||
425 | events:TriggerEvent("Glory_HostileFlagCarrierUpdate", Glory.hordeFC) |
||
426 | end |
||
427 | return |
||
428 | end |
||
429 | |||
430 | if string.find(text, PATTERN_ALLIANCE_FLAG_CAPTURED) then |
||
431 | local hordeFC = Glory.hordeFC |
||
432 | Glory.allianceFC = nil |
||
433 | Glory.hordeFC = nil |
||
434 | events:TriggerEvent("Glory_AllianceFlagCaptured", hordeFC) |
||
435 | if not isHorde then |
||
436 | events:TriggerEvent("Glory_FriendlyFlagCaptured", hordeFC) |
||
437 | else |
||
438 | events:TriggerEvent("Glory_HostileFlagCaptured", hordeFC) |
||
439 | end |
||
440 | events:TriggerEvent("Glory_FriendlyFlagCarrierUpdate", nil) |
||
441 | events:TriggerEvent("Glory_HostileFlagCarrierUpdate", nil) |
||
442 | events:TriggerEvent("Glory_AllianceFlagCarrierUpdate", nil) |
||
443 | events:TriggerEvent("Glory_HordeFlagCarrierUpdate", nil) |
||
444 | return |
||
445 | end |
||
446 | |||
447 | if string.find(text, PATTERN_HORDE_FLAG_DROPPED) then |
||
448 | local allianceFC = Glory.allianceFC |
||
449 | Glory.allianceFC = nil |
||
450 | events:TriggerEvent("Glory_HordeFlagDropped", allianceFC) |
||
451 | if isHorde then |
||
452 | events:TriggerEvent("Glory_FriendlyFlagDropped", allianceFC) |
||
453 | events:TriggerEvent("Glory_HostileFlagCarrierUpdate", nil) |
||
454 | else |
||
455 | events:TriggerEvent("Glory_HostileFlagDropped", allianceFC) |
||
456 | events:TriggerEvent("Glory_FriendlyFlagCarrierUpdate", nil) |
||
457 | end |
||
458 | return |
||
459 | end |
||
460 | elseif Glory:IsInArathiBasin() or Glory:IsInAlteracValley() then |
||
461 | events:BattlefieldObjectiveEventProcessing(text) |
||
462 | end |
||
463 | end |
||
464 | |||
465 | function events:CHAT_MSG_BG_SYSTEM_ALLIANCE(text) |
||
466 | if Glory:IsInWarsongGulch() then |
||
467 | local _, _, allianceFC = string.find(text, PATTERN_HORDE_FLAG_PICKED_UP) |
||
468 | if allianceFC then |
||
469 | Glory.allianceFC = allianceFC |
||
470 | events:TriggerEvent("Glory_HordeFlagPickedUp", Glory.allianceFC) |
||
471 | if isHorde then |
||
472 | events:TriggerEvent("Glory_FriendlyFlagPickedUp", Glory.allianceFC) |
||
473 | events:TriggerEvent("Glory_HostileFlagCarrierUpdate", Glory.allianceFC) |
||
474 | else |
||
475 | events:TriggerEvent("Glory_HostileFlagPickedUp", Glory.allianceFC) |
||
476 | events:TriggerEvent("Glory_FriendlyFlagCarrierUpdate", Glory.allianceFC) |
||
477 | end |
||
478 | return |
||
479 | end |
||
480 | |||
481 | if string.find(text, PATTERN_HORDE_FLAG_CAPTURED) then |
||
482 | local alliance = Glory.allianceFC |
||
483 | Glory.allianceFC = nil |
||
484 | Glory.hordeFC = nil |
||
485 | events:TriggerEvent("Glory_HordeFlagCaptured", allianceFC) |
||
486 | if isHorde then |
||
487 | events:TriggerEvent("Glory_FriendlyFlagCaptured", allianceFC) |
||
488 | else |
||
489 | events:TriggerEvent("Glory_HostileFlagCaptured", allianceFC) |
||
490 | end |
||
491 | events:TriggerEvent("Glory_FriendlyFlagCarrierUpdate", nil) |
||
492 | events:TriggerEvent("Glory_HostileFlagCarrierUpdate", nil) |
||
493 | events:TriggerEvent("Glory_AllianceFlagCarrierUpdate", nil) |
||
494 | events:TriggerEvent("Glory_HordeFlagCarrierUpdate", nil) |
||
495 | return |
||
496 | end |
||
497 | |||
498 | if string.find(text, PATTERN_ALLIANCE_FLAG_DROPPED) then |
||
499 | local hordeFC = Glory.hordeFC |
||
500 | Glory.hordeFC = nil |
||
501 | events:TriggerEvent("Glory_AllianceFlagDropped", hordeFC) |
||
502 | if not isHorde then |
||
503 | events:TriggerEvent("Glory_FriendlyFlagDropped", hordeFC) |
||
504 | events:TriggerEvent("Glory_HostileFlagCarrierUpdate", nil) |
||
505 | else |
||
506 | events:TriggerEvent("Glory_HostileFlagDropped", hordeFC) |
||
507 | events:TriggerEvent("Glory_FriendlyFlagCarrierUpdate", nil) |
||
508 | end |
||
509 | return |
||
510 | end |
||
511 | elseif Glory:IsInArathiBasin() or Glory:IsInAlteracValley() then |
||
512 | events:BattlefieldObjectiveEventProcessing(text) |
||
513 | end |
||
514 | end |
||
515 | |||
516 | function events:CHAT_MSG_MONSTER_YELL(text) |
||
517 | if Glory:IsInAlteracValley() then |
||
518 | if string.find(string.lower(text), string.lower(VICTORY_TEXT0)) then |
||
519 | if isHorde then |
||
520 | IncreaseBattlegroundsWins(Glory) |
||
521 | else |
||
522 | IncreaseBattlegroundsLosses(Glory) |
||
523 | end |
||
524 | elseif string.find(string.lower(text), string.lower(VICTORY_TEXT1)) then |
||
525 | if not isHorde then |
||
526 | IncreaseBattlegroundsWins(Glory) |
||
527 | else |
||
528 | IncreaseBattlegroundsLosses(Glory) |
||
529 | end |
||
530 | else |
||
531 | events:BattlefieldObjectiveEventProcessing(text) |
||
532 | end |
||
533 | end |
||
534 | end |
||
535 | |||
536 | function events:BattlefieldObjectiveEventProcessing(text) |
||
537 | local node, faction |
||
538 | for k, pattern in pairs(BGChatAnnouncements.BGObjectiveClaimedAnnouncements) do |
||
539 | _, _, node, faction = string.find(text, pattern) |
||
540 | if node then |
||
541 | if node == FACTION_ALLIANCE or node == FACTION_HORDE then |
||
542 | node, faction = faction, node |
||
543 | end |
||
544 | events:OnObjectiveClaimed(BGPatternReplacements[node] or node, faction) |
||
545 | events:TriggerEvent("Glory_ObjectiveClaimed", BGPatternReplacements[node] or node, faction) |
||
546 | return |
||
547 | end |
||
548 | end |
||
549 | for k, pattern in pairs(BGChatAnnouncements.BGObjectiveCapturedAnnouncements) do |
||
550 | _, _, node, faction = string.find(text, pattern) |
||
551 | if node then |
||
552 | if node == FACTION_ALLIANCE or node == FACTION_HORDE then |
||
553 | node, faction = faction, node |
||
554 | end |
||
555 | events:OnObjectiveCaptured(BGPatternReplacements[node] or node, faction) |
||
556 | events:TriggerEvent("Glory_ObjectiveCaptured", BGPatternReplacements[node] or node, faction) |
||
557 | return |
||
558 | end |
||
559 | end |
||
560 | for k, pattern in pairs(BGChatAnnouncements.BGObjectiveAttackedAnnouncements) do |
||
561 | _, _, node = string.find(text, pattern) |
||
562 | if node then |
||
563 | events:OnObjectiveAttacked(BGPatternReplacements[node] or node) |
||
564 | events:TriggerEvent("Glory_ObjectiveAttacked", BGPatternReplacements[node] or node) |
||
565 | return |
||
566 | end |
||
567 | end |
||
568 | for k, pattern in pairs(BGChatAnnouncements.BGObjectiveDefendedAnnouncements) do |
||
569 | _, _, node = string.find(text, pattern) |
||
570 | if node then |
||
571 | events:OnObjectiveDefended(BGPatternReplacements[node] or node) |
||
572 | events:TriggerEvent("Glory_ObjectiveDefended", BGPatternReplacements[node] or node) |
||
573 | return |
||
574 | end |
||
575 | end |
||
576 | for k, pattern in pairs(BGChatAnnouncements.BGObjectiveDestroyedAnnouncements) do |
||
577 | _, _, node = string.find(text, pattern) |
||
578 | if node then |
||
579 | events:OnObjectiveDestroyed(BGPatternReplacements[node] or node) |
||
580 | events:TriggerEvent("Glory_ObjectiveDestroyed", BGPatternReplacements[node] or node) |
||
581 | return |
||
582 | end |
||
583 | end |
||
584 | end |
||
585 | |||
586 | function events:CHAT_MSG_COMBAT_FACTION_CHANGE(text) |
||
587 | local faction, rep = deformat(text, FACTION_STANDING_INCREASED) |
||
588 | if faction and rep then |
||
589 | if faction == FACTION_DEFILERS or faction == FACTION_FROSTWOLF_CLAN or faction == FACTION_WARSONG_OUTRIDERS or faction == FACTION_LEAGUE_OF_ARATHOR or faction == FACTION_STORMPIKE_GUARD or faction == FACTION_SILVERWING_SENTINELS then |
||
590 | events:TriggerEvent("Glory_FactionGain", faction, rep) |
||
591 | end |
||
592 | end |
||
593 | end |
||
594 | |||
595 | function events:CHAT_MSG_COMBAT_HOSTILEPLAYER_HITS() |
||
596 | Glory.lastHostileTime = GetTime() |
||
597 | end |
||
598 | events.CHAT_MSG_SPELL_HOSTILEPLAYER_DAMAGE = events.CHAT_MSG_COMBAT_HOSTILEPLAYER_HITS |
||
599 | |||
600 | function events:UNIT_PVP_UPDATE() |
||
601 | if not UnitIsPVP("player") and Glory.permaPvP then |
||
602 | Glory.permaPvP = false |
||
603 | events:TriggerEvent("Glory_UpdatePermanentPvP", Glory.permaPvP) |
||
604 | end |
||
605 | if UnitIsPVP("player") or Glory:IsInBattlegrounds() then |
||
606 | Glory.pvpTime = GetTime() |
||
607 | events:TriggerEvent("Glory_UpdatePvPCooldown", Glory:GetPvPCooldown()) |
||
608 | else |
||
609 | events:TriggerEvent("Glory_UpdatePvPCooldown", 0) |
||
610 | end |
||
611 | end |
||
612 | |||
613 | function events:UPDATE_WORLD_STATES() |
||
614 | local resData = BattlefieldZoneResourceData[Glory:GetActiveBattlefieldZone()] |
||
615 | if resData and Glory:GetNumAllianceBases() and Glory:GetNumHordeBases() then |
||
616 | -- Common |
||
617 | local goalResources = resData[table.getn(resData)] |
||
618 | -- Alliance |
||
619 | _, _, resources = string.find(Glory:GetAllianceScoreString(), "(%d+)/") |
||
620 | bases = Glory:GetNumAllianceBases() |
||
621 | if resources and bases and (resources ~= Glory.aLastResources or bases ~= Glory.aLastBases) then |
||
622 | Glory.aResourceTTV = (goalResources - resources) / resData[bases] |
||
623 | Glory.aLastResources = resources |
||
624 | Glory.aLastBases = bases |
||
625 | Glory.aLastUpdate = GetTime() |
||
626 | end |
||
627 | -- Horde |
||
628 | _, _, resources = string.find(Glory:GetHordeScoreString(), "(%d+)/") |
||
629 | bases = Glory:GetNumHordeBases() |
||
630 | if resources and bases and (resources ~= Glory.hLastResources or bases ~= Glory.hLastBases) then |
||
631 | Glory.hResourceTTV = (goalResources - resources) / resData[bases] |
||
632 | Glory.hLastResources = resources |
||
633 | Glory.hLastBases = bases |
||
634 | Glory.hLastUpdate = GetTime() |
||
635 | end |
||
636 | end |
||
637 | end |
||
638 | |||
639 | function events:PLAYER_ENTERING_WORLD() |
||
640 | events:UNIT_PVP_UPDATE() |
||
641 | SetMapToCurrentZone() |
||
642 | if Glory:IsInBattlegrounds() and GetNumMapLandmarks() > 0 then |
||
643 | events:InitializeBattlefieldObjectives() |
||
644 | else |
||
645 | events:ClearBattlefieldObjectives() |
||
646 | end |
||
647 | end |
||
648 | |||
649 | function events:PLAYER_DEAD() |
||
650 | if GetTime() <= Glory.lastHostileTime + 15 then |
||
651 | IncreaseDeaths(Glory) |
||
652 | end |
||
653 | end |
||
654 | |||
655 | function events:UPDATE_BATTLEFIELD_SCORE() |
||
656 | for k,v in pairs(enemyList) do |
||
657 | enemyList[k] = nil |
||
658 | end |
||
659 | for i = 1, GetNumBattlefieldScores() do |
||
660 | local name, _, _, _, _, faction = GetBattlefieldScore(i) |
||
661 | if faction == (isHorde and 1 or 0) then |
||
662 | local _,_,realName, realm = string.find(name, "(.*)%-(.*)") |
||
663 | if not realName then |
||
664 | realName = name |
||
665 | realm = playerRealm |
||
666 | end |
||
667 | enemyList[realName] = realm |
||
668 | end |
||
669 | end |
||
670 | end |
||
671 | |||
672 | function Glory:IsInBattlegrounds() |
||
673 | -- local zone = GetRealZoneText() |
||
674 | -- return zone == WARSONG_GULCH or zone == ARATHI_BASIN or zone == ALTERAC_VALLEY |
||
675 | return (MiniMapBattlefieldFrame.status == "active") |
||
676 | end |
||
677 | |||
678 | function Glory:IsInWarsongGulch() |
||
679 | return GetRealZoneText() == WARSONG_GULCH |
||
680 | end |
||
681 | |||
682 | function Glory:IsInArathiBasin() |
||
683 | return GetRealZoneText() == ARATHI_BASIN |
||
684 | end |
||
685 | |||
686 | function Glory:IsInAlteracValley() |
||
687 | return GetRealZoneText() == ALTERAC_VALLEY |
||
688 | end |
||
689 | |||
690 | local function copyTable(to, from) |
||
691 | for k, v in pairs(from) do |
||
692 | to[k] = v |
||
693 | end |
||
694 | return to |
||
695 | end |
||
696 | |||
697 | local tdate, start, done |
||
698 | local firstbg = { [2006] = 2, } |
||
699 | local function GetBattlegroundWeek(bgdate) |
||
700 | local bgweekday = math.mod(bgdate.wday + 4, 7) + 1 |
||
701 | local bgweek = math.floor((bgdate.yday + 6 - bgweekday) / 7) + 1 |
||
702 | if not firstbg[bgdate.year] then |
||
703 | if not tdate then |
||
704 | tdate = {} |
||
705 | end |
||
706 | tdate = copyTable(tdate, bgdate) |
||
707 | tdate.day = 1 |
||
708 | tdate.month = 1 |
||
709 | tdate = date("*t", time(tdate)) |
||
710 | local d = GetBattlegroundWeek(date) |
||
711 | tdate.day = 31 |
||
712 | tdate.month = 12 |
||
713 | tdate.year = tdate.year - 1 |
||
714 | tdate = date("*t", time(tdate)) |
||
715 | local _, _, bg = GetBattlegroundWeek(date) |
||
716 | if d == 1 then |
||
717 | firstbg[bgdate.year] = math.mod(bg, 4) + 1 |
||
718 | else |
||
719 | firstbg[bgdate.year] = bg |
||
720 | end |
||
721 | end |
||
722 | local bg = math.mod(bgweek -1 + firstbg[bgdate.year], 4) + 1 |
||
723 | return bgweekday, bgweek, bg |
||
724 | end |
||
725 | |||
726 | local function GetCurrentOrNextBattlegroundWeekend(week) |
||
727 | local now = date("*t") |
||
728 | local bgweekday, bgweek, bg = GetBattlegroundWeek(now) |
||
729 | local bginweeks |
||
730 | if bg <= week then |
||
731 | bginweeks = week - bg |
||
732 | else |
||
733 | bginweeks = week + 4 - bg |
||
734 | end |
||
735 | if not start then |
||
736 | start = {} |
||
737 | end |
||
738 | start = copyTable(start, now) |
||
739 | start.day = start.day + 4 - bgweekday + 7 * bginweeks |
||
740 | start.hour = 0 |
||
741 | start.min = 0 |
||
742 | start.sec = 0 |
||
743 | start = date("*t", time(start)) |
||
744 | if not done then |
||
745 | done = {} |
||
746 | end |
||
747 | done = copyTable(done, now) |
||
748 | done.day = done.day + 7 - bgweekday + 7 * bginweeks |
||
749 | done.hour = 23 |
||
750 | done.min = 59 |
||
751 | done.sec = 59 |
||
752 | done = date("*t", time(done)) |
||
753 | local sMonth |
||
754 | local dMonth |
||
755 | if start.month == done.month then |
||
756 | sMonth = date("%B", time(start)) |
||
757 | dMonth = sMonth |
||
758 | else |
||
759 | sMonth = date("%b", time(start)) |
||
760 | dMonth = date("%b", time(done)) |
||
761 | end |
||
762 | return sMonth, start.day, dMonth, done.day, time(start) <= time(now) and time(now) <= time(done) |
||
763 | end |
||
764 | |||
765 | function Glory:GetCurrentOrNextArathiWeekend() |
||
766 | return GetCurrentOrNextBattlegroundWeekend(4) |
||
767 | end |
||
768 | |||
769 | function Glory:GetCurrentOrNextWarsongWeekend() |
||
770 | return GetCurrentOrNextBattlegroundWeekend(3) |
||
771 | end |
||
772 | |||
773 | function Glory:GetCurrentOrNextAlteracWeekend() |
||
774 | return GetCurrentOrNextBattlegroundWeekend(2) |
||
775 | end |
||
776 | |||
777 | function Glory:_TogglePVP() |
||
778 | self.permaPvP = not self.permaPvP |
||
779 | if not UnitIsPVP("player") then |
||
780 | self.permaPvP = true |
||
781 | end |
||
782 | events:TriggerEvent("Glory_UpdatePermanentPvP", self.permaPvP) |
||
783 | self.pvpTime = GetTime() |
||
784 | end |
||
785 | |||
786 | function Glory:GetTodayHKs(person, realm) |
||
787 | if person then |
||
788 | self:argCheck(person, 2, "string") |
||
789 | if realm and realm ~= playerRealm then |
||
790 | self:argCheck(realm, 3, "string", "nil") |
||
791 | person = person .. "-" .. realm |
||
792 | end |
||
793 | return self.data.hks[person] or 0 |
||
794 | else |
||
795 | return self.data.todayHK |
||
796 | end |
||
797 | end |
||
798 | |||
799 | function Glory:GetTodayDeaths() |
||
800 | return self.data.todayDeaths |
||
801 | end |
||
802 | |||
803 | function Glory:GetTodayHKHonor() |
||
804 | return self.data.todayHKHonor |
||
805 | end |
||
806 | |||
807 | function Glory:GetTodayBonusHonor() |
||
808 | return self.data.todayBonusHonor |
||
809 | end |
||
810 | |||
811 | function Glory:GetTodayHonor() |
||
812 | return self.data.todayHKHonor + self.data.todayBonusHonor |
||
813 | end |
||
814 | |||
815 | function Glory:GetBattlegroundsWins() |
||
816 | return self.data.wsgWin + self.data.abWin + self.data.avWin |
||
817 | end |
||
818 | |||
819 | function Glory:GetWarsongGulchWins() |
||
820 | return self.data.wsgWin |
||
821 | end |
||
822 | |||
823 | function Glory:GetArathiBasinWins() |
||
824 | return self.data.abWin |
||
825 | end |
||
826 | |||
827 | function Glory:GetAlteracValleyWins() |
||
828 | return self.data.avWin |
||
829 | end |
||
830 | |||
831 | function Glory:GetBattlegroundsLosses() |
||
832 | return self.data.wsgLoss + self.data.abLoss + self.data.avLoss |
||
833 | end |
||
834 | |||
835 | function Glory:GetWarsongGulchLosses() |
||
836 | return self.data.wsgLoss |
||
837 | end |
||
838 | |||
839 | function Glory:GetArathiBasinLosses() |
||
840 | return self.data.abLoss |
||
841 | end |
||
842 | |||
843 | function Glory:GetAlteracValleyLosses() |
||
844 | return self.data.avLoss |
||
845 | end |
||
846 | |||
847 | function Glory:ResetBGScores() |
||
848 | self.data.wsgWin = 0 |
||
849 | self.data.wsgLoss = 0 |
||
850 | self.data.abWin = 0 |
||
851 | self.data.abLoss = 0 |
||
852 | self.data.avWin = 0 |
||
853 | self.data.avLoss = 0 |
||
854 | events:TriggerEvent("Glory_BGResetScores") |
||
855 | end |
||
856 | |||
857 | function Glory:IsPermanentPvP() |
||
858 | return self.permaPvP |
||
859 | end |
||
860 | |||
861 | function Glory:GetPvPCooldown() |
||
862 | if self:IsInBattlegrounds() or self.permaPvP then |
||
863 | return 300 |
||
864 | end |
||
865 | local t = self.pvpTime - GetTime() + 300 |
||
866 | if t < 0 or not UnitIsPVP("player") then |
||
867 | return 0 |
||
868 | else |
||
869 | return t |
||
870 | end |
||
871 | end |
||
872 | |||
873 | function Glory:GetRankLimitInfo() |
||
874 | local level = UnitLevel("player") |
||
875 | if level < 10 then |
||
876 | return NONE, 0 |
||
877 | elseif level <= 32 then |
||
878 | return GetPVPRankInfo(7) |
||
879 | elseif level <= 37 then |
||
880 | return GetPVPRankInfo(8) |
||
881 | elseif level <= 40 then |
||
882 | return GetPVPRankInfo(9) |
||
883 | elseif level <= 43 then |
||
884 | return GetPVPRankInfo(10) |
||
885 | elseif level <= 45 then |
||
886 | return GetPVPRankInfo(11) |
||
887 | elseif level <= 47 then |
||
888 | return GetPVPRankInfo(12) |
||
889 | elseif level <= 50 then |
||
890 | return GetPVPRankInfo(13) |
||
891 | elseif level <= 52 then |
||
892 | return GetPVPRankInfo(14) |
||
893 | elseif level <= 54 then |
||
894 | return GetPVPRankInfo(15) |
||
895 | elseif level <= 56 then |
||
896 | return GetPVPRankInfo(16) |
||
897 | elseif level <= 58 then |
||
898 | return GetPVPRankInfo(17) |
||
899 | elseif level <= 60 then |
||
900 | return GetPVPRankInfo(18) |
||
901 | end |
||
902 | end |
||
903 | |||
904 | function Glory:GetRatingLimit() |
||
905 | local level = UnitLevel("player") |
||
906 | if level < 10 then |
||
907 | return 0 |
||
908 | elseif level <= 29 then |
||
909 | return 6500 |
||
910 | elseif level <= 35 then |
||
911 | return 7150 + (level - 30) * 975 |
||
912 | elseif level <= 39 then |
||
913 | return 13325 + (level - 36) * 1300 |
||
914 | elseif level <= 43 then |
||
915 | return 18850 + (level - 40) * 1625 |
||
916 | elseif level <= 52 then |
||
917 | return 26000 + (level - 44) * 2275 |
||
918 | elseif level <= 59 then |
||
919 | return 46800 + (level - 53) * 2600 |
||
920 | else |
||
921 | return 65000 |
||
922 | end |
||
923 | end |
||
924 | |||
925 | function Glory:GetStanding(name) |
||
926 | name = name or playerName |
||
927 | self:argCheck(name, 2, "string") |
||
928 | for i=1, GetNumBattlefieldScores() do |
||
929 | if name == GetBattlefieldScore(i) then |
||
930 | return i |
||
931 | end |
||
932 | end |
||
933 | end |
||
934 | |||
935 | function Glory:GetKillingBlows(name) |
||
936 | local unit, killingBlows |
||
937 | name = name or playerName |
||
938 | self:argCheck(name, 2, "string") |
||
939 | for i=1, GetNumBattlefieldScores() do |
||
940 | unit, killingBlows = GetBattlefieldScore(i) |
||
941 | if unit == name then |
||
942 | return killingBlows |
||
943 | end |
||
944 | end |
||
945 | end |
||
946 | |||
947 | function Glory:GetHonorableKills(name) |
||
948 | name = name or playerName |
||
949 | self:argCheck(name, 2, "string") |
||
950 | local unit, honorableKills |
||
951 | for i=1, GetNumBattlefieldScores() do |
||
952 | unit, _, honorableKills = GetBattlefieldScore(i) |
||
953 | if unit == name then |
||
954 | return honorableKills |
||
955 | end |
||
956 | end |
||
957 | end |
||
958 | |||
959 | function Glory:GetDeaths(name) |
||
960 | name = name or playerName |
||
961 | self:argCheck(name, 2, "string") |
||
962 | local unit, deaths |
||
963 | for i=1, GetNumBattlefieldScores() do |
||
964 | unit, _, _, deaths = GetBattlefieldScore(i) |
||
965 | if unit == name then |
||
966 | return deaths |
||
967 | end |
||
968 | end |
||
969 | end |
||
970 | |||
971 | function Glory:GetBonusHonor(name) |
||
972 | name = name or playerName |
||
973 | self:argCheck(name, 2, "string") |
||
974 | local unit, bonusHonor |
||
975 | for i=1, GetNumBattlefieldScores() do |
||
976 | unit, _, _, _, bonusHonor = GetBattlefieldScore(i) |
||
977 | if unit == name then |
||
978 | return bonusHonor |
||
979 | end |
||
980 | end |
||
981 | end |
||
982 | |||
983 | function Glory:GetActiveBattlefieldZone() |
||
984 | local status, mapName |
||
985 | for i = 1, MAX_BATTLEFIELD_QUEUES do |
||
986 | status, mapName = GetBattlefieldStatus(i) |
||
987 | if status == "active" then |
||
988 | return mapName |
||
989 | end |
||
990 | end |
||
991 | end |
||
992 | |||
993 | function Glory:GetActiveBattlefieldUniqueID() |
||
994 | local status, mapName, instanceID |
||
995 | for i = 1, MAX_BATTLEFIELD_QUEUES do |
||
996 | status, mapName, instanceID = GetBattlefieldStatus(i) |
||
997 | if status == "active" then |
||
998 | return mapName .. " " .. instanceID |
||
999 | end |
||
1000 | end |
||
1001 | end |
||
1002 | |||
1003 | local function queuedBattlefieldIndicesIter(_, position) |
||
1004 | position = position + 1 |
||
1005 | while position <= MAX_BATTLEFIELD_QUEUES do |
||
1006 | local status, name = GetBattlefieldStatus(position) |
||
1007 | if status == "queued" then |
||
1008 | return position, name |
||
1009 | end |
||
1010 | position = position + 1 |
||
1011 | end |
||
1012 | return nil |
||
1013 | end |
||
1014 | function Glory:IterateQueuedBattlefieldZones() |
||
1015 | return queuedBattlefieldIndicesIter, nil, 0 |
||
1016 | end |
||
1017 | |||
1018 | local function GetHolder(self, node) |
||
1019 | local poi = self:NodeToPOI(node) |
||
1020 | if self:IsUncontrolled(node) then |
||
1021 | return BGObjectiveDescriptions.UNCONTROLLED |
||
1022 | end |
||
1023 | if poi and not self:IsDestroyed(poi) then |
||
1024 | _, description = GetMapLandmarkInfo(poi) |
||
1025 | if string.find(description, PATTERN_OBJECTIVE_HOLDER) then |
||
1026 | local _, _, faction = string.find(description, PATTERN_OBJECTIVE_HOLDER) |
||
1027 | return faction |
||
1028 | end |
||
1029 | end |
||
1030 | end |
||
1031 | |||
1032 | function Glory:IsBattlefieldObjective(node) |
||
1033 | self:argCheck(node, 2, "string", "number") |
||
1034 | local poi = self:NodeToPOI(node) |
||
1035 | if poi and (GetHolder(self, node) or self:IsInConflict(node) or self:IsDestroyed(node)) then |
||
1036 | return true |
||
1037 | end |
||
1038 | return false |
||
1039 | end |
||
1040 | |||
1041 | function Glory:IsInConflict(node) |
||
1042 | self:argCheck(node, 2, "string", "number") |
||
1043 | local poi = self:NodeToPOI(node) |
||
1044 | if poi then |
||
1045 | local _, description = GetMapLandmarkInfo(poi) |
||
1046 | if description == BGObjectiveDescriptions.IN_CONFLICT then |
||
1047 | return true |
||
1048 | end |
||
1049 | end |
||
1050 | return false |
||
1051 | end |
||
1052 | |||
1053 | function Glory:IsAllianceControlled(node) |
||
1054 | self:argCheck(node, 2, "string", "number") |
||
1055 | local poi = self:NodeToPOI(node) |
||
1056 | if poi then |
||
1057 | local _, description = GetMapLandmarkInfo(poi) |
||
1058 | if description == BGObjectiveDescriptions.ALLIANCE_CONTROLLED then |
||
1059 | return true |
||
1060 | end |
||
1061 | end |
||
1062 | return false |
||
1063 | end |
||
1064 | |||
1065 | function Glory:IsHordeControlled(node) |
||
1066 | self:argCheck(node, 2, "string", "number") |
||
1067 | local poi = self:NodeToPOI(node) |
||
1068 | if poi then |
||
1069 | local _, description = GetMapLandmarkInfo(poi) |
||
1070 | if description == BGObjectiveDescriptions.HORDE_CONTROLLED then |
||
1071 | return true |
||
1072 | end |
||
1073 | end |
||
1074 | return false |
||
1075 | end |
||
1076 | |||
1077 | if isHorde then |
||
1078 | Glory.IsFriendlyControlled = Glory.IsHordeControlled |
||
1079 | Glory.IsHostileControlled = Glory.IsAllianceControlled |
||
1080 | else |
||
1081 | Glory.IsFriendlyControlled = Glory.IsAllianceControlled |
||
1082 | Glory.IsHostileControlled = Glory.IsHordeControlled |
||
1083 | end |
||
1084 | |||
1085 | function Glory:IsUncontrolled(node) |
||
1086 | self:argCheck(node, 2, "string", "number") |
||
1087 | local poi = self:NodeToPOI(node) |
||
1088 | if poi then |
||
1089 | local _, description = GetMapLandmarkInfo(poi) |
||
1090 | if description == BGObjectiveDescriptions.UNCONTROLLED then |
||
1091 | return true |
||
1092 | end |
||
1093 | end |
||
1094 | return |
||
1095 | end |
||
1096 | |||
1097 | function Glory:IsDestroyed(node) |
||
1098 | self:argCheck(node, 2, "string", "number") |
||
1099 | local poi = self:NodeToPOI(node) |
||
1100 | if poi then |
||
1101 | local _, description = GetMapLandmarkInfo(poi) |
||
1102 | if description == BGObjectiveDescriptions.DESTROYED then |
||
1103 | return true |
||
1104 | end |
||
1105 | end |
||
1106 | return |
||
1107 | end |
||
1108 | |||
1109 | function Glory:GetTimeAttacked(node) |
||
1110 | self:argCheck(node, 2, "string", "number") |
||
1111 | return self.battlefieldObjectiveStatus[node].timeAttacked |
||
1112 | end |
||
1113 | |||
1114 | function Glory:GetTimeToCapture(node) |
||
1115 | self:argCheck(node, 2, "string", "number") |
||
1116 | local t = BattlefieldZoneObjectiveTimes[self:GetActiveBattlefieldZone()] or 0 |
||
1117 | return t - GetTime() + self.battlefieldObjectiveStatus[node].timeAttacked |
||
1118 | end |
||
1119 | |||
1120 | function Glory:GetName(node) |
||
1121 | self:argCheck(node, 2, "string", "number") |
||
1122 | return self.battlefieldObjectiveStatus[node].name |
||
1123 | end |
||
1124 | |||
1125 | function Glory:GetDefender(node) |
||
1126 | self:argCheck(node, 2, "string", "number") |
||
1127 | return self.battlefieldObjectiveStatus[node].defender |
||
1128 | end |
||
1129 | |||
1130 | function Glory:GetAttacker(node) |
||
1131 | self:argCheck(node, 2, "string", "number") |
||
1132 | return self.battlefieldObjectiveStatus[node].attacker |
||
1133 | end |
||
1134 | |||
1135 | local function objectiveNodesIter(t, position) |
||
1136 | local k = next(t, position) |
||
1137 | while k ~= nil and type(k) ~= "number" do |
||
1138 | k = next(t, position) |
||
1139 | end |
||
1140 | return k |
||
1141 | end |
||
1142 | |||
1143 | function Glory:IterateObjectiveNodes() |
||
1144 | return objectiveNodesIter, self.battlefieldObjectiveStatus, nil |
||
1145 | end |
||
1146 | |||
1147 | local function sortedObjectiveNodesIter(t, position) |
||
1148 | position = position + 1 |
||
1149 | if position <= table.getn(t) then |
||
1150 | return position, t[position] |
||
1151 | else |
||
1152 | t = del(t) |
||
1153 | return nil |
||
1154 | end |
||
1155 | end |
||
1156 | local mySort |
||
1157 | function Glory:IterateSortedObjectiveNodes() |
||
1158 | local t = new() |
||
1159 | for poi in pairs(self.battlefieldObjectiveStatus) do |
||
1160 | if type(poi) == "number" then |
||
1161 | table.insert(t, poi) |
||
1162 | end |
||
1163 | end |
||
1164 | if not mySort then |
||
1165 | mySort = function(a, b) |
||
1166 | return self.battlefieldObjectiveStatus[a].ypos and self.battlefieldObjectiveStatus[b].ypos and self.battlefieldObjectiveStatus[a].ypos < self.battlefieldObjectiveStatus[b].ypos |
||
1167 | end |
||
1168 | end |
||
1169 | table.sort(t, mySort) |
||
1170 | return sortedObjectiveNodesIter, t, 0 |
||
1171 | end |
||
1172 | |||
1173 | function events:ClearBattlefieldObjectives() |
||
1174 | for i = 1, table.getn(Glory.battlefieldObjectiveStatus) do |
||
1175 | local o = Glory.battlefieldObjectiveStatus[i] |
||
1176 | if Glory.battlefieldObjectiveStatus[o.node] == o then |
||
1177 | Glory.battlefieldObjectiveStatus[o.node] = nil |
||
1178 | end |
||
1179 | Glory.battlefieldObjectiveStatus[i] = del(o) |
||
1180 | end |
||
1181 | for k in pairs(Glory.battlefieldObjectiveStatus) do |
||
1182 | Glory.battlefieldObjectiveStatus[k] = del(Glory.battlefieldObjectiveStatus[k]) |
||
1183 | k = nil |
||
1184 | end |
||
1185 | end |
||
1186 | |||
1187 | function events:InitializeBattlefieldObjectives() |
||
1188 | local n, node, y |
||
1189 | events:ClearBattlefieldObjectives() |
||
1190 | SetMapToCurrentZone() |
||
1191 | local numPOIS = GetNumMapLandmarks() |
||
1192 | for i=1, numPOIS do |
||
1193 | if Glory:IsBattlefieldObjective(i) then |
||
1194 | node, _, _, _, y = GetMapLandmarkInfo(i) |
||
1195 | Glory.battlefieldObjectiveStatus[i] = { |
||
1196 | name = node, |
||
1197 | ypos = y, |
||
1198 | defender = GetHolder(Glory, i), |
||
1199 | inConflict = Glory:IsInConflict(i), |
||
1200 | isDestroyed = Glory:IsDestroyed(i), |
||
1201 | } |
||
1202 | Glory.battlefieldObjectiveStatus[node] = Glory.battlefieldObjectiveStatus[i] |
||
1203 | end |
||
1204 | end |
||
1205 | end |
||
1206 | |||
1207 | function events:OnObjectiveClaimed(node, faction) |
||
1208 | local poi = Glory:NodeToPOI(node) |
||
1209 | if poi then |
||
1210 | if not next(Glory.battlefieldObjectiveStatus) then |
||
1211 | events:InitializeBattlefieldObjectives() |
||
1212 | end |
||
1213 | local n = Glory.battlefieldObjectiveStatus[poi] |
||
1214 | if n then |
||
1215 | n.attacker = faction |
||
1216 | n.inConflict = true |
||
1217 | n.timeAttacked = GetTime() |
||
1218 | end |
||
1219 | end |
||
1220 | end |
||
1221 | |||
1222 | function events:OnObjectiveCaptured(node, faction) |
||
1223 | local poi = Glory:NodeToPOI(node) |
||
1224 | if poi then |
||
1225 | if not next(Glory.battlefieldObjectiveStatus) then |
||
1226 | events:InitializeBattlefieldObjectives() |
||
1227 | end |
||
1228 | local n = Glory.battlefieldObjectiveStatus[poi] |
||
1229 | if n then |
||
1230 | n.defender = GetHolder(Glory, node) or faction |
||
1231 | n.attacker = nil |
||
1232 | n.inConflict = nil |
||
1233 | n.timeAttacked = nil |
||
1234 | end |
||
1235 | end |
||
1236 | end |
||
1237 | |||
1238 | function events:OnObjectiveAttacked(node) |
||
1239 | local poi = Glory:NodeToPOI(node) |
||
1240 | if poi then |
||
1241 | if not next(Glory.battlefieldObjectiveStatus) then |
||
1242 | events:InitializeBattlefieldObjectives() |
||
1243 | end |
||
1244 | local n = Glory.battlefieldObjectiveStatus[poi] |
||
1245 | if n then |
||
1246 | if n.defender == FACTION_ALLIANCE then |
||
1247 | n.attacker = FACTION_HORDE |
||
1248 | else |
||
1249 | n.attacker = FACTION_ALLIANCE |
||
1250 | end |
||
1251 | n.inConflict = true |
||
1252 | n.timeAttacked = GetTime() |
||
1253 | end |
||
1254 | end |
||
1255 | end |
||
1256 | |||
1257 | function events:OnObjectiveDefended(node) |
||
1258 | local poi = Glory:NodeToPOI(node) |
||
1259 | if poi then |
||
1260 | if not next(Glory.battlefieldObjectiveStatus) then |
||
1261 | events:InitializeBattlefieldObjectives() |
||
1262 | end |
||
1263 | local n = Glory.battlefieldObjectiveStatus[poi] |
||
1264 | if n then |
||
1265 | n.attacker = nil |
||
1266 | n.inConflict = nil |
||
1267 | n.timeAttacked = nil |
||
1268 | end |
||
1269 | end |
||
1270 | end |
||
1271 | |||
1272 | function events:OnObjectiveDestroyed(node) |
||
1273 | local poi = Glory:NodeToPOI(node) |
||
1274 | if poi then |
||
1275 | if not next(Glory.battlefieldObjectiveStatus) then |
||
1276 | events:InitializeBattlefieldObjectives() |
||
1277 | end |
||
1278 | local n = Glory.battlefieldObjectiveStatus[poi] |
||
1279 | if n then |
||
1280 | n.isDestroyed = true |
||
1281 | n.defender = nil |
||
1282 | n.attacker = nil |
||
1283 | n.inConflict = nil |
||
1284 | n.timeAttacked = nil |
||
1285 | end |
||
1286 | end |
||
1287 | end |
||
1288 | |||
1289 | function Glory:GetAllianceFlagCarrier() |
||
1290 | return self.allianceFC |
||
1291 | end |
||
1292 | |||
1293 | function Glory:GetHordeFlagCarrier() |
||
1294 | return self.hordeFC |
||
1295 | end |
||
1296 | |||
1297 | function Glory:TargetAllianceFlagCarrier() |
||
1298 | if self.allianceFC then |
||
1299 | TargetByName(self.allianceFC) |
||
1300 | end |
||
1301 | end |
||
1302 | |||
1303 | function Glory:TargetHordeFlagCarrier() |
||
1304 | if self.hordeFC then |
||
1305 | TargetByName(self.hordeFC) |
||
1306 | end |
||
1307 | end |
||
1308 | |||
1309 | if isHorde then |
||
1310 | Glory.GetFriendlyFlagCarrier = Glory.GetHordeFlagCarrier |
||
1311 | Glory.GetHostileFlagCarrier = Glory.GetAllianceFlagCarrier |
||
1312 | Glory.TargetFriendlyFlagCarrier = Glory.TargetHordeFlagCarrier |
||
1313 | Glory.TargetHostileFlagCarrier = Glory.TargetAllianceFlagCarrier |
||
1314 | else |
||
1315 | Glory.GetFriendlyFlagCarrier = Glory.GetAllianceFlagCarrier |
||
1316 | Glory.GetHostileFlagCarrier = Glory.GetHordeFlagCarrier |
||
1317 | Glory.TargetFriendlyFlagCarrier = Glory.TargetAllianceFlagCarrier |
||
1318 | Glory.TargetHostileFlagCarrier = Glory.TargetHordeFlagCarrier |
||
1319 | end |
||
1320 | |||
1321 | function Glory:GetFlagCarrier(faction) |
||
1322 | self:argCheck(faction, 2, "string", "number") |
||
1323 | if faction == FACTION_ALLIANCE or faction == "Alliance" or faction == 1 then |
||
1324 | return self.allianceFC |
||
1325 | else |
||
1326 | return self.hordeFC |
||
1327 | end |
||
1328 | end |
||
1329 | |||
1330 | function Glory:TargetFlagCarrier(faction) |
||
1331 | self:argCheck(faction, 2, "string", "number") |
||
1332 | if faction == FACTION_ALLIANCE or faction == "Alliance" or faction == 1 then |
||
1333 | if self.allianceFC then |
||
1334 | TargetByName(self.allianceFC) |
||
1335 | end |
||
1336 | elseif self.hordeFC then |
||
1337 | TargetByName(self.hordeFC) |
||
1338 | end |
||
1339 | end |
||
1340 | |||
1341 | function Glory:GetNumAllianceBases() |
||
1342 | if GetWorldStateUIInfo(1) then |
||
1343 | local _, _, bases = string.find(GetWorldStateUIInfo(1), PATTERN_GWSUII_BASES) |
||
1344 | return tonumber(bases) |
||
1345 | end |
||
1346 | end |
||
1347 | |||
1348 | function Glory:GetNumHordeBases() |
||
1349 | if GetWorldStateUIInfo(2) then |
||
1350 | local _, _, bases = string.find(GetWorldStateUIInfo(2), PATTERN_GWSUII_BASES) |
||
1351 | return tonumber(bases) |
||
1352 | end |
||
1353 | end |
||
1354 | |||
1355 | if isHorde then |
||
1356 | Glory.GetNumFriendlyBases = Glory.GetNumHordeBases |
||
1357 | Glory.GetNumHostileBases = Glory.GetNumAllianceBases |
||
1358 | else |
||
1359 | Glory.GetNumFriendlyBases = Glory.GetNumAllianceBases |
||
1360 | Glory.GetNumHostileBases = Glory.GetNumHordeBases |
||
1361 | end |
||
1362 | |||
1363 | function Glory:GetNumBases(team) |
||
1364 | self:argCheck(team, 2, "string", "number") |
||
1365 | if team == FACTION_ALLIANCE or team == "Alliance" or team == 1 then |
||
1366 | team = 1 |
||
1367 | else |
||
1368 | team = 2 |
||
1369 | end |
||
1370 | if GetWorldStateUIInfo(team) then |
||
1371 | local _, _, bases = string.find(GetWorldStateUIInfo(team), PATTERN_GWSUII_BASES) |
||
1372 | return tonumber(bases) |
||
1373 | end |
||
1374 | end |
||
1375 | |||
1376 | function Glory:GetNumAllianceResources() |
||
1377 | if GetWorldStateUIInfo(1) then |
||
1378 | local _, _, resources = string.find(GetWorldStateUIInfo(1), PATTERN_GWSUII_RESOURCES) |
||
1379 | return tonumber(resources) |
||
1380 | end |
||
1381 | end |
||
1382 | |||
1383 | function Glory:GetNumHordeResources() |
||
1384 | if GetWorldStateUIInfo(2) then |
||
1385 | local _, _, resources = string.find(GetWorldStateUIInfo(2), PATTERN_GWSUII_RESOURCES) |
||
1386 | return tonumber(resources) |
||
1387 | end |
||
1388 | end |
||
1389 | |||
1390 | if isHorde then |
||
1391 | Glory.GetNumFriendlyResources = Glory.GetNumHordeResources |
||
1392 | Glory.GetNumHostileResources = Glory.GetNumAllianceResources |
||
1393 | else |
||
1394 | Glory.GetNumFriendlyResources = Glory.GetNumAllianceResources |
||
1395 | Glory.GetNumHostileResources = Glory.GetNumHordeResources |
||
1396 | end |
||
1397 | |||
1398 | function Glory:GetNumTeamResources(team) |
||
1399 | self:argCheck(team, 2, "string", "number") |
||
1400 | if team == FACTION_ALLIANCE or team == "Alliance" or team == 1 then |
||
1401 | return self:GetNumAllianceResources() |
||
1402 | else |
||
1403 | return self:GetNumHordeResources() |
||
1404 | end |
||
1405 | end |
||
1406 | |||
1407 | function Glory:GetAllianceTTV() |
||
1408 | return self.aResourceTTV - GetTime() + self.aLastUpdate |
||
1409 | end |
||
1410 | |||
1411 | function Glory:GetHordeTTV() |
||
1412 | return self.hResourceTTV - GetTime() + self.hLastUpdate |
||
1413 | end |
||
1414 | |||
1415 | function Glory:GetTeamTTV(team) |
||
1416 | self:argCheck(team, 2, "string", "number") |
||
1417 | if team == FACTION_ALLIANCE or team == "Alliance" or team == 1 then |
||
1418 | return self:GetAllianceTTV() |
||
1419 | else |
||
1420 | return self:GetHordeTTV() |
||
1421 | end |
||
1422 | end |
||
1423 | |||
1424 | if isHorde then |
||
1425 | Glory.GetFriendlyTTV = Glory.GetHordeTTV |
||
1426 | Glory.GetHostileTTV = Glory.GetAllianceTTV |
||
1427 | else |
||
1428 | Glory.GetFriendlyTTV = Glory.GetAllianceTTV |
||
1429 | Glory.GetHostileTTV = Glory.GetHordeTTV |
||
1430 | end |
||
1431 | |||
1432 | function Glory:GetAllianceScoreString() |
||
1433 | if GetWorldStateUIInfo(1) then |
||
1434 | local _, _, scoreString = string.find(GetWorldStateUIInfo(1), PATTERN_GWSUII_SCORE) |
||
1435 | return scoreString |
||
1436 | end |
||
1437 | end |
||
1438 | |||
1439 | function Glory:GetHordeScoreString() |
||
1440 | if GetWorldStateUIInfo(2) then |
||
1441 | local _, _, scoreString = string.find(GetWorldStateUIInfo(2), PATTERN_GWSUII_SCORE) |
||
1442 | return scoreString |
||
1443 | end |
||
1444 | end |
||
1445 | |||
1446 | if isHorde then |
||
1447 | Glory.GetFriendlyScoreString = Glory.GetHordeScoreString |
||
1448 | Glory.GetHostileScoreString = Glory.GetAllianceScoreString |
||
1449 | else |
||
1450 | Glory.GetFriendlyScoreString = Glory.GetAllianceScoreString |
||
1451 | Glory.GetHostileScoreString = Glory.GetHordeScoreString |
||
1452 | end |
||
1453 | |||
1454 | function Glory:GetTeamScoreString(team) |
||
1455 | if team == FACTION_ALLIANCE or team == "Alliance" or team == 1 then |
||
1456 | return self:GetAllianceScoreString() |
||
1457 | else |
||
1458 | return self:GetHordeScoreString() |
||
1459 | end |
||
1460 | end |
||
1461 | |||
1462 | function Glory:GetNumAlliancePlayers() |
||
1463 | local numPlayers = 0 |
||
1464 | for i = 1, GetNumBattlefieldScores() do |
||
1465 | local _, _, _, _, _, faction = GetBattlefieldScore(i) |
||
1466 | if faction == 1 then |
||
1467 | numPlayers = numPlayers + 1 |
||
1468 | end |
||
1469 | end |
||
1470 | return numPlayers |
||
1471 | end |
||
1472 | |||
1473 | function Glory:GetNumHordePlayers() |
||
1474 | local numPlayers = 0 |
||
1475 | for i = 1, GetNumBattlefieldScores() do |
||
1476 | local _, _, _, _, _, faction = GetBattlefieldScore(i) |
||
1477 | if faction == 0 then |
||
1478 | numPlayers = numPlayers + 1 |
||
1479 | end |
||
1480 | end |
||
1481 | return numPlayers |
||
1482 | end |
||
1483 | |||
1484 | if isHorde then |
||
1485 | Glory.GetNumFriendlyPlayers = Glory.GetNumHordePlayers |
||
1486 | Glory.GetNumHostilePlayers = Glory.GetNumAlliancePlayers |
||
1487 | else |
||
1488 | Glory.GetNumFriendlyPlayers = Glory.GetNumAlliancePlayers |
||
1489 | Glory.GetNumHostilePlayers = Glory.GetNumHordePlayers |
||
1490 | end |
||
1491 | |||
1492 | function Glory:GetNumPlayers(team) |
||
1493 | self:argCheck(team, 2, "string", "number") |
||
1494 | if team == FACTION_ALLIANCE or team == "Alliance" or team == 1 then |
||
1495 | return self:GetNumAlliancePlayers() |
||
1496 | else |
||
1497 | return self:GetNumHordePlayers() |
||
1498 | end |
||
1499 | end |
||
1500 | |||
1501 | function Glory:NodeToPOI(node) |
||
1502 | local landmark, description |
||
1503 | if type(node) == "number" and node > 0 and node <= GetNumMapLandmarks() then |
||
1504 | return node |
||
1505 | elseif type(node) == "string" then |
||
1506 | for i = 1, GetNumMapLandmarks() do |
||
1507 | if string.lower(node) == string.lower(GetMapLandmarkInfo(i)) then |
||
1508 | return i |
||
1509 | end |
||
1510 | end |
||
1511 | elseif type(node) ~= "number" then |
||
1512 | self:error("Bad argument #2 to `NodeToPOI' (string or number expected, got %s)", tostring(type(node))) |
||
1513 | else |
||
1514 | self:error("Bad argument #2 to `NodeToPOI' (out of bounds: [1, %d] expected, got %d)", GetNumMapLandmarks(), node) |
||
1515 | end |
||
1516 | end |
||
1517 | |||
1518 | function Glory:GetBGAcronym(bgName) |
||
1519 | self:argCheck(bgName, 2, "string") |
||
1520 | return BGAcronyms[bgName] or bgName |
||
1521 | end |
||
1522 | |||
1523 | function Glory:GetFactionColor(faction) |
||
1524 | self:argCheck(faction, 2, "string", "number", "nil") |
||
1525 | if faction then |
||
1526 | if faction == "Alliance" or faction == FACTION_ALLIANCE or faction == 1 then |
||
1527 | faction = "ALLIANCE" |
||
1528 | elseif faction == "Horde" or faction == FACTION_HORDE or faction == 0 or faction == 2 then |
||
1529 | faction = "HORDE" |
||
1530 | end |
||
1531 | local cti = ChatTypeInfo["BG_SYSTEM_" .. faction] |
||
1532 | if cti then |
||
1533 | return cti.r, cti.g, cti.b |
||
1534 | end |
||
1535 | end |
||
1536 | return 0.7, 0.7, 0.7 |
||
1537 | end |
||
1538 | |||
1539 | function Glory:GetFactionHexColor(faction) |
||
1540 | local r, g, b = self:GetFactionColor(faction) |
||
1541 | return string.format("%02X%02X%02X", 255*r, 255*g, 255*b) |
||
1542 | end |
||
1543 | |||
1544 | local function activate(self, oldLib, oldDeactivate) |
||
1545 | Glory = self |
||
1546 | if oldLib then |
||
1547 | self.registry = oldLib.registry |
||
1548 | else |
||
1549 | self.registry = {} |
||
1550 | end |
||
1551 | events:CancelAllScheduledEvents() |
||
1552 | events:UnregisterAllEvents() |
||
1553 | events:RegisterEvent("ADDON_LOADED") |
||
1554 | events:RegisterEvent("VARIABLES_LOADED") |
||
1555 | events:RegisterEvent("PLAYER_LOGOUT") |
||
1556 | events:RegisterEvent("CHAT_MSG_COMBAT_HONOR_GAIN") |
||
1557 | events:RegisterEvent("CHAT_MSG_BG_SYSTEM_NEUTRAL") |
||
1558 | events:RegisterEvent("CHAT_MSG_BG_SYSTEM_HORDE") |
||
1559 | events:RegisterEvent("CHAT_MSG_MONSTER_YELL") |
||
1560 | events:RegisterEvent("CHAT_MSG_BG_SYSTEM_ALLIANCE") |
||
1561 | events:RegisterEvent("CHAT_MSG_COMBAT_FACTION_CHANGE") |
||
1562 | events:RegisterEvent("CHAT_MSG_SPELL_HOSTILEPLAYER_DAMAGE") |
||
1563 | events:RegisterEvent("CHAT_MSG_COMBAT_HOSTILEPLAYER_HITS") |
||
1564 | events:RegisterEvent("UPDATE_WORLD_STATES") |
||
1565 | events:RegisterEvent("PLAYER_ENTERING_WORLD") |
||
1566 | events:RegisterEvent("UNIT_PVP_UPDATE") |
||
1567 | events:RegisterEvent("PLAYER_DEAD") |
||
1568 | events:RegisterEvent("UPDATE_BATTLEFIELD_SCORE") |
||
1569 | events:VARIABLES_LOADED() |
||
1570 | events:ScheduleRepeatingEvent(function() |
||
1571 | if self:IsInBattlegrounds() then |
||
1572 | RequestBattlefieldScoreData() |
||
1573 | end |
||
1574 | end, 15) |
||
1575 | |||
1576 | if not oldLib then |
||
1577 | local old_TogglePVP = TogglePVP |
||
1578 | function TogglePVP() |
||
1579 | AceLibrary(MAJOR_VERSION):_TogglePVP() |
||
1580 | |||
1581 | old_TogglePVP() |
||
1582 | end |
||
1583 | end |
||
1584 | |||
1585 | self.battlefieldObjectiveStatus = new() |
||
1586 | self.pvpTime = 0 |
||
1587 | self.currentBonusHonor = 0 |
||
1588 | self.lastHostileTime = 0 |
||
1589 | self.aLastResources = 0 |
||
1590 | self.hLastResources = 0 |
||
1591 | self.aLastBases = 0 |
||
1592 | self.hLastBases = 0 |
||
1593 | self.aLastUpdate = 0 |
||
1594 | self.hLastUpdate = 0 |
||
1595 | self.aResourceTTV = 0 |
||
1596 | self.hResourceTTV = 0 |
||
1597 | |||
1598 | SLASH_TARFLAG1 = "/tarflag" |
||
1599 | SLASH_TARFLAG2 = "/tflag" |
||
1600 | SlashCmdList.TARFLAG = function() |
||
1601 | self:TargetHostileFlagCarrier() |
||
1602 | end |
||
1603 | |||
1604 | if oldDeactivate then |
||
1605 | oldDeactivate(oldLib) |
||
1606 | end |
||
1607 | end |
||
1608 | |||
1609 | local function external(self, major, instance) |
||
1610 | if major == "AceConsole-2.0" then |
||
1611 | local print = print |
||
1612 | if DEFAULT_CHAT_FRAME then |
||
1613 | function print(key, value) |
||
1614 | DEFAULT_CHAT_FRAME:AddMessage("|cffffff7f" .. key .. ": [|r" .. value .. "|cffffff7f]|r") |
||
1615 | end |
||
1616 | end |
||
1617 | instance.RegisterChatCommand(self, { "/glory", "/glorylib" }, { |
||
1618 | name = MAJOR_VERSION .. "." .. string.gsub(MINOR_VERSION, ".-(%d+).*", "%1"), |
||
1619 | desc = "A library for PvP and Battlegrounds.", |
||
1620 | type = "group", |
||
1621 | args = { |
||
1622 | bg = { |
||
1623 | name = "Battlegrounds", |
||
1624 | desc = "Show battlegrounds information", |
||
1625 | type = "execute", |
||
1626 | func = function() |
||
1627 | print("BG Score", self:GetBattlegroundsWins() .. "-" .. self:GetBattlegroundsLosses()) |
||
1628 | print("WSG Score", self:GetWarsongGulchWins() .. "-" .. self:GetWarsongGulchLosses()) |
||
1629 | print("AB Score", self:GetArathiBasinWins() .. "-" .. self:GetArathiBasinLosses()) |
||
1630 | print("AV Score", self:GetAlteracValleyWins() .. "-" .. self:GetAlteracValleyLosses()) |
||
1631 | if self:IsInBattlegrounds() then |
||
1632 | print("Current", self:GetActiveBattlegroundUniqueID()) |
||
1633 | print("Standing", self:GetStanding()) |
||
1634 | print("Killing Blows", self:GetKillingBlows()) |
||
1635 | print("Honorable Kills", self:GetHonorableKills()) |
||
1636 | print("Deaths", self:GetDeaths()) |
||
1637 | print("Bonus Honor", self:GetBonusHonor()) |
||
1638 | if self:IsInWarsongGulch() then |
||
1639 | print("Friendly FC", (self:GetFriendlyFlagCarrier() or NONE)) |
||
1640 | print("Hostile FC", (self:GetHostileFlagCarrier() or NONE)) |
||
1641 | else |
||
1642 | print("Friendly Bases", self:GetNumFriendlyBases()) |
||
1643 | print("Hostile Bases", self:GetNumHostileBases()) |
||
1644 | print("Friendly Resources", self:GetNumFriendlyResources()) |
||
1645 | print("Hostile Resources", self:GetNumHostileResources()) |
||
1646 | end |
||
1647 | print("Friendly Players", self:GetNumFriendlyPlayers()) |
||
1648 | print("Hostile Players", self:GetNumHostilePlayers()) |
||
1649 | end |
||
1650 | end |
||
1651 | }, |
||
1652 | honor = { |
||
1653 | name = "Honor", |
||
1654 | desc = "Show honor information", |
||
1655 | type = "execute", |
||
1656 | func = function() |
||
1657 | print("Today's HKs", self:GetTodayHKs()) |
||
1658 | print("Today's Deaths", self:GetTodayDeaths()) |
||
1659 | print("Today's HK Honor", self:GetTodayHKHonor()) |
||
1660 | print("Today's Bonus Honor", self:GetTodayBonusHonor()) |
||
1661 | print("Today's Honor", self:GetTodayHonor()) |
||
1662 | local s |
||
1663 | if self:IsPermanentPvP() then |
||
1664 | s = "Flagged" |
||
1665 | elseif self:IsInBattlegrounds() then |
||
1666 | s = "Battlegrounds" |
||
1667 | else |
||
1668 | local t = self:GetPvPCooldown() |
||
1669 | if t == 0 then |
||
1670 | s = "None" |
||
1671 | else |
||
1672 | local min = floor(t / 60) |
||
1673 | local sec = floor(mod(t, 60)) |
||
1674 | s = format("%d:%02d", min, sec) |
||
1675 | end |
||
1676 | end |
||
1677 | print("PvP Cooldown", s) |
||
1678 | print("Rank Limit", string.format("%s (%d)", self:GetRankLimitInfo())) |
||
1679 | print("Rating Limit", self:GetRatingLimit()) |
||
1680 | end |
||
1681 | } |
||
1682 | } |
||
1683 | }, "GLORY") |
||
1684 | end |
||
1685 | end |
||
1686 | |||
1687 | AceLibrary:Register(Glory, MAJOR_VERSION, MINOR_VERSION, activate, nil, external) |