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