· 8 years ago · May 10, 2018, 08:12 PM
1local addonName, Data = ...
2local L = LibStub("AceLocale-3.0"):GetLocale("BattleGroundEnemies")
3local LSM = LibStub("LibSharedMedia-3.0")
4local DRData = LibStub("DRData-1.0")
5local LibRaces = LibStub("LibRaces-1.0")
6LSM:Register("font", "PT Sans Narrow Bold", [[Interface\AddOns\BattleGroundEnemies\Fonts\PT Sans Narrow Bold.ttf]])
7LSM:Register("statusbar", "UI-StatusBar", "Interface\\TargetingFrame\\UI-StatusBar")
8
9local BattleGroundEnemies = CreateFrame("Frame", "BattleGroundEnemies")
10
11
12--upvalues
13local _G = _G
14local pairs = pairs
15local print = print
16local type = type
17local unpack = unpack
18local gsub = gsub
19local floor = math.floor
20local random = math.random
21local tinsert = table.insert
22local tremove = table.remove
23
24local C_PvP = C_PvP
25local GetArenaCrowdControlInfo = C_PvP.GetArenaCrowdControlInfo
26local RequestCrowdControlSpell = C_PvP.RequestCrowdControlSpell
27local IsInBrawl = C_PvP.IsInBrawl
28local CreateFrame = CreateFrame
29local GetBattlefieldArenaFaction = GetBattlefieldArenaFaction
30local GetBattlefieldScore = GetBattlefieldScore
31local GetBattlefieldTeamInfo = GetBattlefieldTeamInfo
32local GetCurrentMapAreaID = GetCurrentMapAreaID
33local GetNumBattlefieldScores = GetNumBattlefieldScores
34local GetNumGroupMembers = GetNumGroupMembers
35local GetRaidRosterInfo = GetRaidRosterInfo
36local GetSpellInfo = GetSpellInfo
37local GetSpellTexture = GetSpellTexture
38local GetTime = GetTime
39local InCombatLockdown = InCombatLockdown
40local IsInInstance = IsInInstance
41local IsItemInRange = IsItemInRange
42local IsRatedBattleground = IsRatedBattleground
43local PlaySound = PlaySound
44local PowerBarColor = PowerBarColor --table
45local RaidNotice_AddMessage = RaidNotice_AddMessage
46local RequestBattlefieldScoreData = RequestBattlefieldScoreData
47local SetMapToCurrentZone = SetMapToCurrentZone
48local UnitDebuff = UnitDebuff
49local UnitExists = UnitExists
50--local UnitGUID = UnitGUID
51local UnitHealth = UnitHealth
52local UnitHealthMax = UnitHealthMax
53local UnitIsDead = UnitIsDead
54local UnitIsDeadOrGhost = UnitIsDeadOrGhost
55local UnitIsGhost = UnitIsGhost
56local UnitLevel = UnitLevel
57local UnitName = UnitName
58
59
60--variables used in multiple functions, if a variable is only used by one function its declared above that function
61--BattleGroundEnemies.BattlegroundBuff --contains the battleground specific enemy buff to watchout for of the current active battlefield
62BattleGroundEnemies.BattleGroundDebuffs = {} --contains battleground specific enemy debbuffs to watchout for of the current active battlefield
63--BattleGroundEnemies.IsRatedBG
64local playerFaction = UnitFactionGroup("player")
65local PlayerDetails = {}
66local PlayerButton
67local PlayerLevel = UnitLevel("player")
68local MaxLevel = GetMaxPlayerLevel()
69local CurrentMapID --contains the map id of the current active battleground
70--BattleGroundEnemies.EnemyFaction
71--BattleGroundEnemies.AllyFaction
72
73
74
75
76BattleGroundEnemies:SetScript("OnEvent", function(self, event, ...) self[event](self, ...) end)
77BattleGroundEnemies:Hide()
78
79
80
81BattleGroundEnemies.Objects = {}
82
83
84local RequestFrame = CreateFrame("Frame", nil, BattleGroundEnemies)
85
86
87
88BattleGroundEnemies.ArenaEnemyIDToPlayerButton = {} --key = arenaID: arenaX, value = playerButton of that unitID
89
90BattleGroundEnemies.Enemies = CreateFrame("Frame", nil, BattleGroundEnemies)
91BattleGroundEnemies.Enemies.OnUpdate = {} --key = number from 1 to x, value = enemyButton
92BattleGroundEnemies.Enemies:Hide()
93BattleGroundEnemies.Enemies:SetScript("OnEvent", function(self, event, ...) self[event](self, ...) end)
94
95
96BattleGroundEnemies.Allies = CreateFrame("Frame", nil, BattleGroundEnemies) --index = name, value = table
97BattleGroundEnemies.Allies:Hide()
98BattleGroundEnemies.Allies.UnitIDToAllyButton = {} --index = unitID ("raid"..i) of raidmember, value = Allytable of that group member
99BattleGroundEnemies.Allies:SetScript("OnEvent", function(self, event, ...) self[event](self, ...) end)
100
101
102
103BattleGroundEnemies:RegisterEvent("PLAYER_LOGIN")
104BattleGroundEnemies:RegisterEvent("PLAYER_ENTERING_WORLD")
105BattleGroundEnemies:RegisterEvent("UI_SCALE_CHANGED")
106
107function BattleGroundEnemies:UI_SCALE_CHANGED()
108 if not InCombatLockdown() then
109 self:SetScale(UIParent:GetScale())
110 else
111 self:UI_SCALE_CHANGED()
112 end
113end
114
115UIParent:HookScript("OnShow", function() BattleGroundEnemies:SetAlpha(1) end)
116
117UIParent:HookScript("OnHide", function() BattleGroundEnemies:SetAlpha(0) end)
118
119
120BattleGroundEnemies:SetScale(UIParent:GetScale())
121
122
123BattleGroundEnemies:SetScript("OnShow", function(self)
124 if not self.TestmodeActive then
125 self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
126 self:RegisterEvent("UPDATE_MOUSEOVER_UNIT")
127 self:RegisterEvent("PLAYER_TARGET_CHANGED")
128 self:RegisterEvent("PLAYER_FOCUS_CHANGED")
129 self:RegisterEvent("ARENA_OPPONENT_UPDATE")
130 self:RegisterEvent("ARENA_CROWD_CONTROL_SPELL_UPDATE")
131 self:RegisterEvent("ARENA_COOLDOWNS_UPDATE")
132 -- self:RegisterEvent("LOSS_OF_CONTROL_ADDED")
133 self:RegisterEvent("UNIT_TARGET")
134 self:RegisterEvent("PLAYER_ALIVE")
135 self:RegisterEvent("PLAYER_UNGHOST")
136
137 RequestFrame:Show()
138 self:RegisterEvent("UPDATE_BATTLEFIELD_SCORE")--stopping the onupdate script should do it but other addons make "UPDATE_BATTLEFIELD_SCORE" trigger aswell
139 else
140 RequestFrame:Hide()
141 end
142end)
143
144BattleGroundEnemies:SetScript("OnHide", function(self)
145 self:UnregisterEvent("UPDATE_BATTLEFIELD_SCORE")--stopping the onupdate script should do it but other addons make "UPDATE_BATTLEFIELD_SCORE" trigger aswell
146 self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
147 self:UnregisterEvent("UPDATE_MOUSEOVER_UNIT")
148 self:UnregisterEvent("PLAYER_TARGET_CHANGED")
149 self:UnregisterEvent("PLAYER_FOCUS_CHANGED")
150
151 self:UnregisterEvent("ARENA_OPPONENT_UPDATE")--fires when a arena enemy appears and a frame is ready to be shown
152 self:UnregisterEvent("ARENA_CROWD_CONTROL_SPELL_UPDATE") --fires when data requested by C_PvP.RequestCrowdControlSpell(unitID) is available
153 self:UnregisterEvent("ARENA_COOLDOWNS_UPDATE") --fires when a arenaX enemy used a trinket or racial to break cc, C_PvP.GetArenaCrowdControlInfo(unitID) shoudl be called afterwards to get used CCs
154
155 -- self:RegisterEvent("LOSS_OF_CONTROL_ADDED")
156 self:UnregisterEvent("UNIT_TARGET")
157 self:UnregisterEvent("PLAYER_ALIVE")
158 self:UnregisterEvent("PLAYER_UNGHOST")
159 self.BGSize = false
160end)
161
162do
163 local TimeSinceLastOnUpdate = 0
164 local UpdatePeroid = 0.1 --update every 0.1 seconds
165 function BattleGroundEnemies.Enemies:RealPlayersOnUpdate(elapsed)
166 --BattleGroundEnemies:Debug("läuft")
167 TimeSinceLastOnUpdate = TimeSinceLastOnUpdate + elapsed
168 if TimeSinceLastOnUpdate > UpdatePeroid then
169 if BattleGroundEnemies.PlayerIsAlive then
170 local onUpdate = self.OnUpdate
171 for i = 1, #onUpdate do
172 local enemyButton = onUpdate[i]
173 local unitIDs = enemyButton.UnitIDs
174 local activeUnitID = unitIDs.Active
175 if not unitIDs.CheckIfUnitExists or UnitExists(activeUnitID) then
176
177 if unitIDs.UpdateHealth then
178 if unitIDs.UpdatePower then
179 enemyButton:UpdatePower(activeUnitID)
180 end
181 enemyButton:UpdateHealth(activeUnitID)
182 end
183 enemyButton:UpdateRange(IsItemInRange(self.config.RangeIndicator_Range, activeUnitID))
184 enemyButton:UpdateTargets()
185 end
186 end
187 end
188 TimeSinceLastOnUpdate = 0
189 end
190 end
191end
192
193BattleGroundEnemies.Enemies:SetScript("OnShow", function(self)
194 if not BattleGroundEnemies.TestmodeActive then
195 self:RegisterEvent("UNIT_HEALTH_FREQUENT") --fires when health of player, target, focus, nameplateX, arenaX, raidX updates
196 if self.bgSizeConfig.PowerBar_Enabled then self:RegisterEvent("UNIT_POWER_FREQUENT") end --fires when health of player, target, focus, nameplateX, arenaX, raidX updates
197 self:RegisterEvent("NAME_PLATE_UNIT_ADDED")
198 self:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
199 self:SetScript("OnUpdate", self.RealPlayersOnUpdate)
200 else
201 self:SetScript("OnUpdate", nil)
202 end
203end)
204
205BattleGroundEnemies.Enemies:SetScript("OnHide", BattleGroundEnemies.Enemies.UnregisterAllEvents)
206
207do
208 local TimeSinceLastOnUpdate = 0
209 local UpdatePeroid = 0.1 --update every 0.1 seconds
210 function BattleGroundEnemies.Allies:RealPlayersOnUpdate(elapsed)
211 --BattleGroundEnemies:Debug("läuft")
212 TimeSinceLastOnUpdate = TimeSinceLastOnUpdate + elapsed
213 if TimeSinceLastOnUpdate > UpdatePeroid then
214 if BattleGroundEnemies.PlayerIsAlive then
215 for name, allyButton in pairs(self.Players) do
216 if allyButton ~= PlayerButton then
217 --BattleGroundEnemies:Debug(IsItemInRange(self.config.RangeIndicator_Range, allyButton.unit), self.config.RangeIndicator_Range, allyButton.unit)
218 allyButton:UpdateRange(IsItemInRange(self.config.RangeIndicator_Range, allyButton.unit))
219 end
220 end
221 end
222 TimeSinceLastOnUpdate = 0
223 end
224 end
225end
226
227BattleGroundEnemies.Allies:SetScript("OnShow", function(self)
228 if not BattleGroundEnemies.TestmodeActive then
229 self:SetScript("OnUpdate", self.RealPlayersOnUpdate)
230 self:RegisterEvent("GROUP_ROSTER_UPDATE")
231 else
232 self:SetScript("OnUpdate", nil)
233 end
234end)
235
236BattleGroundEnemies.Allies:SetScript("OnHide", BattleGroundEnemies.Allies.UnregisterAllEvents)
237
238
239-- if lets say raid1 leaves all remaining players get shifted up, so raid2 is the new raid1, raid 3 gets raid2 etc.
240function BattleGroundEnemies.Allies:GROUP_ROSTER_UPDATE()
241
242 if not self then self = BattleGroundEnemies.Allies end -- for the C_Timer.After call
243 if InCombatLockdown() then C_Timer.After(1, self.GROUP_ROSTER_UPDATE) end--recheck in 1 second end
244
245 wipe(self.UnitIDToAllyButton)
246
247 local numGroupMembers = GetNumGroupMembers()
248 if numGroupMembers > 0 then
249 for i = 1, numGroupMembers do
250
251 local allyName, _, _, _, _, classTag = GetRaidRosterInfo(i)
252 if allyName and classTag then
253
254 local allyButton = self.Players[allyName]
255
256 if allyName ~= PlayerDetails.PlayerName then
257
258 local unit = "raid"..i --it happens that numGroupMembers is higher than the value of the maximal players for that battleground, for example 15 in a 10 man bg, thats why we wipe AllyUnitIDToAllyDetails
259 local targetUnitID = unit.."target"
260
261 if allyButton and allyButton.unit ~= unit then -- ally has a new unitID now
262
263 local targetEnemyButton = allyButton.Target
264 if targetEnemyButton then
265 --self:Debug("player", allyName, "has a new unit and targeted something")
266 if targetEnemyButton.UnitIDs.Active == allyButton.TargetUnitID then
267 targetEnemyButton.UnitIDs.Active = targetUnitID
268 end
269 if targetEnemyButton.UnitIDs.Ally == allyButton.TargetUnitID then
270 targetEnemyButton.UnitIDs.Ally = targetUnitID
271 end
272 end
273
274 allyButton:SetLevel(UnitLevel(unit))
275 allyButton.unit = unit
276 if not InCombatLockdown() then
277 allyButton:SetAttribute('unit', unit)
278 else
279 C_Timer.After(1, self.GROUP_ROSTER_UPDATE)
280 end
281
282 allyButton.TargetUnitID = targetUnitID
283 self.UnitIDToAllyButton[unit] = allyButton
284 allyButton:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", unit) --fires when health of player, target, focus, nameplateX, arenaX, raidX updates
285 allyButton:RegisterUnitEvent("UNIT_POWER_FREQUENT", unit) --fires when health of player, target, focus, nameplateX, arenaX, raidX updates
286 --allyButton:RegisterUnitEvent("UNIT_AURA", unit)
287 end
288
289 else -- its the player
290 if allyButton and not allyButton:IsEventRegistered("UNIT_HEALTH_FREQUENT") then
291
292 if not InCombatLockdown() then
293 allyButton:SetAttribute('unit', "player")
294 else
295 C_Timer.After(1, self.GROUP_ROSTER_UPDATE)
296 end
297
298 allyButton.unit = "player"
299 allyButton.TargetUnitID = "target"
300
301 allyButton:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", "player") --fires when health of player, target, focus, nameplateX, arenaX, raidX updates
302 allyButton:RegisterUnitEvent("UNIT_POWER_FREQUENT", "player")
303 --allyButton:RegisterUnitEvent("UNIT_AURA", "player")
304
305 PlayerButton = allyButton
306 end
307 end
308
309 else
310 C_Timer.After(1, self.GROUP_ROSTER_UPDATE) --recheck in 1 second
311 end
312 end
313 end
314end
315
316function BattleGroundEnemies.Allies:GetAllybuttonByUnitID(unitID)
317 local uName, realm = UnitName(unitID)
318 if realm then
319 uName = uName.."-"..realm
320 end
321 return self.Players[uName]
322end
323
324BattleGroundEnemies.SetBasicPosition = function(frame, basicPoint, relativeTo, relativePoint, space)
325 frame:ClearAllPoints()
326 if relativeTo == "Button" then
327 relativeTo = frame:GetParent()
328 else
329 relativeTo = frame:GetParent()[relativeTo]
330 end
331 --BattleGroundEnemies:Debug('TOP'..basicPoint, relativeTo, 'TOP'..relativePoint, space, 0)
332 frame:SetPoint('TOP'..basicPoint, relativeTo, 'TOP'..relativePoint, space, 0)
333 frame:SetPoint('BOTTOM'..basicPoint, relativeTo, 'BOTTOM'..relativePoint, space, 0)
334end
335
336local function EnableShadowColor(fontString, enableShadow, shadowColor)
337 if shadowColor then fontString:SetShadowColor(unpack(shadowColor)) end
338 if enableShadow then
339 fontString:SetShadowOffset(1, -1)
340 else
341 fontString:SetShadowOffset(0, 0)
342 end
343end
344
345function BattleGroundEnemies.CropImage(texture, width, height)
346 local left, right, top, bottom = 0.075, 0.925, 0.075, 0.925
347 local ratio = height / width
348 if ratio > 1 then --crop the sides
349 ratio = 1/ratio
350 texture:SetTexCoord( (left) + ((1- ratio) / 2), right - ((1- ratio) / 2), top, bottom)
351 elseif ratio == 1 then
352 texture:SetTexCoord(left, right, top, bottom)
353 else
354 -- crop the height
355 texture:SetTexCoord(left, right, top + ((1- ratio) / 2), bottom - ( (1- ratio) / 2))
356 end
357end
358
359local function ApplyCooldownSettings(self, showNumber, cdReverse, setDrawSwipe, swipeColor)
360 self:SetReverse(cdReverse)
361 self:SetDrawSwipe(setDrawSwipe)
362 if swipeColor then self:SetSwipeColor(unpack(swipeColor)) end
363 self:SetHideCountdownNumbers(not showNumber)
364end
365
366local function ApplyFontStringSettings(fontString, Fontsize, FontOutline, enableShadow, shadowColor)
367 fontString:SetFont(LSM:Fetch("font", BattleGroundEnemies.db.profile.Font), Fontsize, FontOutline)
368
369 fontString:EnableShadowColor(enableShadow, shadowColor)
370end
371
372function BattleGroundEnemies.MyCreateFontString(parent)
373 local fontString = parent:CreateFontString(nil, "OVERLAY")
374 fontString.ApplyFontStringSettings = ApplyFontStringSettings
375 fontString.EnableShadowColor = EnableShadowColor
376 fontString:SetDrawLayer('OVERLAY', 2)
377 return fontString
378end
379
380function BattleGroundEnemies.MyCreateCooldown(parent)
381 local cooldown = CreateFrame("Cooldown", nil, parent)
382 cooldown:SetAllPoints()
383 cooldown:SetSwipeTexture('Interface/Buttons/WHITE8X8')
384 cooldown.ApplyCooldownSettings = ApplyCooldownSettings
385
386 -- Find fontstring of the cooldown
387 for _, region in pairs{cooldown:GetRegions()} do
388 if region:GetObjectType() == "FontString" then
389 cooldown.Text = region
390 cooldown.Text.ApplyFontStringSettings = ApplyFontStringSettings
391 cooldown.Text.EnableShadowColor = EnableShadowColor
392 break
393 end
394 end
395
396 return cooldown
397end
398
399
400function BattleGroundEnemies:BGSizeChanged(newBGSize)
401 self.BGSize = newBGSize
402 --self:Debug(newBGSize)
403 self.Enemies:ApplyBGSizeSettings()
404 self.Allies:ApplyBGSizeSettings()
405end
406
407function BattleGroundEnemies:BGSizeCheck(newBGSize)
408 if newBGSize then
409 if newBGSize > 15 then
410 if not self.BGSize or self.BGSize ~= 40 then
411 self:BGSizeChanged(40)
412 end
413 else
414 if not self.BGSize or self.BGSize ~= 15 then
415 self:BGSizeChanged(15)
416 end
417 end
418 end
419end
420
421
422local enemyButtonFunctions = {}
423do
424 function enemyButtonFunctions:RegisterForOnUpdate() --Add to OnUpdate
425 local unitIDs = self.UnitIDs
426 if not unitIDs.OnUpdate then
427 local i = #BattleGroundEnemies.Enemies.OnUpdate + 1
428 BattleGroundEnemies.Enemies.OnUpdate[i] = self
429 self.UnitIDs.OnUpdate = i
430 end
431 if unitIDs.CheckIfUnitExists and not UnitExists(unitIDs.Active) then return end
432 self:UpdateHealth(unitIDs.Active)
433 self:UpdatePower(unitIDs.Active)
434 self:SetLevel(UnitLevel(unitIDs.Active))
435 end
436
437 function enemyButtonFunctions:FetchAnAllyUnitID()
438 local unitIDs = self.UnitIDs
439 if unitIDs.Ally then
440 unitIDs.Active = unitIDs.Ally
441 unitIDs.UpdateHealth = true
442 if self.config.PowerBar_Enabled then
443 unitIDs.UpdatePower = true
444 end
445 unitIDs.CheckIfUnitExists = true
446 self:RegisterForOnUpdate()
447 else
448 self:DeleteActiveUnitID()
449 end
450 end
451
452 --Remove from OnUpdate
453 function enemyButtonFunctions:DeleteActiveUnitID() --Delete from OnUpdate
454 --BattleGroundEnemies:Debug("DeleteActiveUnitID")
455 local unitIDs = self.UnitIDs
456 unitIDs.Active = false
457 self:UpdateRange(false)
458
459 local onUpdate = unitIDs.OnUpdate
460 if onUpdate then
461 unitIDs.OnUpdate = false
462 unitIDs.UpdateHealth = false
463 unitIDs.UpdatePower = false
464 unitIDs.CheckIfUnitExists = false
465 local BGEEnemieOnUpdate = BattleGroundEnemies.Enemies.OnUpdate
466 tremove(BGEEnemieOnUpdate, onUpdate)
467 for i = onUpdate, #BGEEnemieOnUpdate do
468 local enemyButton = BGEEnemieOnUpdate[i]
469 enemyButton.UnitIDs.OnUpdate = i
470 end
471 end
472 end
473
474 function enemyButtonFunctions:FetchAnotherUnitID()
475 local unitIDs = self.UnitIDs
476 unitIDs.CheckIfUnitExists = false -- we need to do UnitExists() for allytargets and Arena-UnitIDs since there is a delay of like 1 second
477
478 if unitIDs.Arena then
479 unitIDs.Active = unitIDs.Arena
480 unitIDs.CheckIfUnitExists = true
481 self:RegisterForOnUpdate()
482 else
483 unitIDs.Active = unitIDs.Nameplate or unitIDs.Target or unitIDs.Focus
484 if unitIDs.Active then
485 self:RegisterForOnUpdate()
486 else
487 self:FetchAnAllyUnitID()
488 end
489 end
490 end
491
492 function enemyButtonFunctions:NowTargetedBy(allyButton)
493 local unitIDs = self.UnitIDs
494 local targetUnitID = allyButton.TargetUnitID
495 if not unitIDs.Active then
496 unitIDs.Active = targetUnitID
497 self:RegisterForOnUpdate()
498 end
499 if not unitIDs.Ally then
500 unitIDs.Ally = targetUnitID
501 end
502
503 unitIDs.TargetedByEnemy[allyButton] = true
504 self:UpdateTargetIndicators()
505 end
506
507 function enemyButtonFunctions:NoLongerTargetedBy(allyButton)
508 local unitIDs = self.UnitIDs
509
510
511 if allyButton.TargetUnitID == unitIDs.Ally then
512 unitIDs.Ally = false
513 for allyButton in pairs(unitIDs.TargetedByEnemy) do
514 if not allyButton.TargetUnitID == "target" then
515 unitIDs.Ally = allyButton.TargetUnitID
516 break
517 end
518 end
519 end
520
521 if allyButton.TargetUnitID == unitIDs.Active then
522 self:FetchAnAllyUnitID()
523 end
524
525 unitIDs.TargetedByEnemy[allyButton] = nil
526 self:UpdateTargetIndicators()
527 end
528
529end
530
531
532local buttonFunctions = {}
533do
534
535 function buttonFunctions:OnDragStart()
536 return BattleGroundEnemies.db.profile.Locked or self:GetParent():StartMoving()
537 end
538
539 function buttonFunctions:OnEnter()
540 self.SelectionHighlight:Show()
541 end
542
543 function buttonFunctions:OnLeave()
544 self.SelectionHighlight:Hide()
545 end
546
547 function buttonFunctions:OnDragStop()
548 local parent = self:GetParent()
549 parent:StopMovingOrSizing()
550 if not InCombatLockdown() then
551 local scale = self:GetEffectiveScale()
552 self.bgSizeConfig.Position_X = parent:GetLeft() * scale
553 self.bgSizeConfig.Position_Y = parent:GetTop() * scale
554 end
555 end
556
557 function buttonFunctions:SetLevel(level)
558 if not self.PlayerLevel or level ~= self.PlayerLevel then
559 self.PlayerLevel = level
560 self:DisplayLevel()
561 end
562 end
563
564 function buttonFunctions:DisplayLevel()
565 if self.config.LevelText_Enabled and (not self.config.LevelText_OnlyShowIfNotMaxLevel or (self.PlayerLevel and self.PlayerLevel < MaxLevel)) then
566 self.Level:SetText(MaxLevel - 1) -- to set the width of the frame (the name shoudl have the same space from the role icon/spec icon regardless of level shown)
567 self.Level:SetWidth(0)
568 self.Level:SetText(self.PlayerLevel)
569 else
570 self.Level:SetWidth(0.01)
571 end
572 end
573
574 function buttonFunctions:SetSpecAndRole()
575 local specData = Data.Classes[self.PlayerClass][self.PlayerSpecName]
576 self.PlayerRoleNumber = specData.roleNumber
577 self.PlayerRoleID = specData.roleID
578 self.Role.Icon:SetTexCoord(GetTexCoordsForRoleSmallCircle(self.PlayerRoleID))
579 self.Spec.Icon:SetTexture(specData.specIcon)
580 self.PlayerSpecID = specData.specID
581 self.Spec_AuraDisplay.SpecHasReducedInterruptTime = Data.SpecIDsWithInterruptDurations[self.PlayerSpecID] or false
582 end
583
584 function buttonFunctions:ApplyButtonSettings()
585 self.bgSizeConfig = self:GetParent().bgSizeConfig
586 local conf = self.bgSizeConfig
587
588 self:SetWidth(conf.BarWidth)
589 self:SetHeight(conf.BarHeight)
590
591 self:SetRangeIncicatorFrame()
592
593 --spec
594 self.Spec:ApplySettings()
595
596 -- auras on spec
597 self.Spec_AuraDisplay.Cooldown:ApplyCooldownSettings(conf.Spec_AuraDisplay_ShowNumbers, true, true, {0, 0, 0, 0.5})
598 self.Spec_AuraDisplay.Cooldown.Text:ApplyFontStringSettings(conf.Spec_AuraDisplay_Cooldown_Fontsize, conf.Spec_AuraDisplay_Cooldown_Outline, conf.Spec_AuraDisplay_Cooldown_EnableTextshadow, conf.Spec_AuraDisplay_Cooldown_TextShadowcolor)
599
600 -- power
601 self.Power:SetHeight(conf.PowerBar_Enabled and conf.PowerBar_Height or 0.01)
602 self.Power:SetStatusBarTexture(LSM:Fetch("statusbar", conf.PowerBar_Texture))--self.Health:SetStatusBarTexture(137012)
603 self.Power.Background:SetVertexColor(unpack(conf.PowerBar_Background))
604
605 -- health
606 self.Health:SetStatusBarTexture(LSM:Fetch("statusbar", conf.HealthBar_Texture))--self.Health:SetStatusBarTexture(137012)
607 self.Health.Background:SetVertexColor(unpack(conf.HealthBar_Background))
608
609 -- role
610 self.Role:ApplySettings()
611
612 -- level
613 self:DisplayLevel()
614
615 self.Level:ApplyFontStringSettings(self.config.LevelText_Fontsize, self.config.LevelText_Outline, self.config.LevelText_EnableTextshadow, self.config.LevelText_TextShadowcolor)
616
617 --MyTarget, indicating the current target of the player
618 self.MyTarget:SetBackdropBorderColor(unpack(BattleGroundEnemies.db.profile.MyTarget_Color))
619
620 --MyFocus, indicating the current focus of the player
621 self.MyFocus:SetBackdropBorderColor(unpack(BattleGroundEnemies.db.profile.MyFocus_Color))
622
623 --SelectionHighlight, highlighting the frame the mouse is currently on
624 self.SelectionHighlight:SetColorTexture(unpack(BattleGroundEnemies.db.profile.Highlight_Color))
625
626 -- numerical target indicator
627 self.NumericTargetindicator:SetShown(conf.NumericTargetindicator_Enabled)
628
629 self.NumericTargetindicator:SetTextColor(unpack(conf.NumericTargetindicator_Textcolor))
630 self.NumericTargetindicator:ApplyFontStringSettings(conf.NumericTargetindicator_Fontsize, conf.NumericTargetindicator_Outline, conf.NumericTargetindicator_EnableTextshadow, conf.NumericTargetindicator_TextShadowcolor)
631 self.NumericTargetindicator:SetText(0)
632
633
634 -- name
635 self.Name:SetTextColor(unpack(conf.Name_Textcolor))
636 self.Name:ApplyFontStringSettings(conf.Name_Fontsize, conf.Name_Outline, conf.Name_EnableTextshadow, conf.Name_TextShadowcolor)
637
638 -- trinket
639 self.Trinket:ApplySettings()
640
641 -- RACIALS
642 self.Racial:ApplySettings()
643
644 -- objective and respawn
645
646 self.ObjectiveAndRespawn:ApplySettings()
647
648 --Dr Tracking
649 self.DRContainer:ApplySettings()
650
651
652 --Auras
653 self.DebuffContainer:ApplySettings()
654 self.BuffContainer:ApplySettings()
655 end
656
657 function buttonFunctions:SetName()
658 local playerName = self.PlayerName
659
660 local name, realm = strsplit( "-", playerName, 2)
661
662 if self.config.ConvertCyrillic then
663 playerName = ""
664 for i = 1, name:utf8len() do
665 local c = name:utf8sub(i,i)
666
667 if Data.CyrillicToRomanian[c] then
668 playerName = playerName..Data.CyrillicToRomanian[c]
669 if i == 1 then
670 playerName = playerName:gsub("^.",string.upper) --uppercase the first character
671 end
672 else
673 playerName = playerName..c
674 end
675 end
676 --self.DisplayedName = self.DisplayedName:gsub("-.",string.upper) --uppercase the realm name
677 name = playerName
678 if realm then
679 playerName = playerName.."-"..realm
680 end
681 end
682
683 if self.config.ShowRealmnames then
684 name = playerName
685 end
686
687 self.Name:SetText(name)
688 self.DisplayedName = name
689 end
690
691
692
693 do
694 local mouseButtonNumberToBindingType = {
695 [1] = "LeftButtonType",
696 [2] = "RightButtonType",
697 [3] = "MiddleButtonType"
698 }
699
700 local mouseButtonNumberToBindingMacro = {
701 [1] = "LeftButtonValue",
702 [2] = "RightButtonValue",
703 [3] = "MiddleButtonValue"
704 }
705
706 function buttonFunctions:SetBindings()
707
708 for i = 1, 3 do
709 local bindingType = self.config[mouseButtonNumberToBindingType[i]]
710
711 if bindingType == "Target" then
712 self:SetAttribute('macrotext'..i,
713 '/cleartarget\n'..
714 '/targetexact '..self.PlayerName
715 )
716 elseif bindingType == "Focus" then
717 self:SetAttribute('macrotext'..i,
718 '/targetexact '..self.PlayerName..'\n'..
719 '/focus\n'..
720 '/targetlasttarget'
721 )
722
723 else -- Custom
724 local macrotext = BattleGroundEnemies.db.profile[self.PlayerType][mouseButtonNumberToBindingMacro[i]]:gsub("%%n", self.PlayerName)
725 self:SetAttribute('macrotext'..i, macrotext)
726 end
727 end
728 end
729 end
730
731 function buttonFunctions:UpdateHealth(unitID)
732 if UnitIsDeadOrGhost(unitID) then
733 --BattleGroundEnemies:Debug("UpdateAll", UnitName(unitID), "UnitIsDead")
734 self.ObjectiveAndRespawn:PlayerDied()
735 elseif self.ObjectiveAndRespawn.ActiveRespawnTimer then --player is alive again
736 self.ObjectiveAndRespawn.Cooldown:Clear()
737 end
738 self.Health:SetValue(UnitHealth(unitID)/UnitHealthMax(unitID))
739 end
740
741 function buttonFunctions:SetRangeIncicatorFrame()
742 if self.config.RangeIndicator_Everything then
743 self.RangeIndicator = self
744 else
745 self.RangeIndicator = self.RangeIndicator_Frame
746 for frameName, enableRange in pairs(self.config.RangeIndicator_Frames) do
747 if enableRange then
748 self[frameName]:SetParent(self.RangeIndicator)
749 else
750 self[frameName]:SetParent(self)
751 end
752 self[frameName]:SetAlpha(1)
753 end
754 end
755 self:SetAlpha(1)
756 end
757
758 function buttonFunctions:ArenaOpponentShown(unitID)
759 if self.bgSizeConfig.ObjectiveAndRespawn_ObjectiveEnabled then
760 self.ObjectiveAndRespawn:ShowObjective()
761
762 self:RegisterUnitEvent("UNIT_AURA", unitID)
763 BattleGroundEnemies.ArenaEnemyIDToPlayerButton[unitID] = self
764
765 if self.PlayerIsEnemy then
766 self:FetchAnotherUnitID()
767 end
768 self.UnitIDs.Arena = unitID
769 end
770 RequestCrowdControlSpell(unitID)
771 end
772
773 -- Shows/Hides targeting indicators for a button
774 function buttonFunctions:UpdateTargetIndicators()
775
776 local i = 1
777 for enemyButton in pairs(self.UnitIDs.TargetedByEnemy) do
778 if self.bgSizeConfig.SymbolicTargetindicator_Enabled then
779 local indicator = self.TargetIndicators[i]
780 if not indicator then
781 indicator = CreateFrame("frame",nil,self.Health)
782 indicator:SetSize(8,10)
783 indicator:SetPoint("TOP",floor(i/2)*(i%2==0 and -10 or 10), 0) --1: 0, 0 2: -10, 0 3: 10, 0 4: -20, 0 > i = even > left, uneven > right
784 indicator:SetBackdrop({
785 bgFile = "Interface/Buttons/WHITE8X8", --drawlayer "BACKGROUND"
786 edgeFile = 'Interface/Buttons/WHITE8X8', --drawlayer "BORDER"
787 edgeSize = 1
788 })
789 indicator:SetBackdropBorderColor(0,0,0,1)
790 self.TargetIndicators[i] = indicator
791 end
792 local classColor = enemyButton.PlayerClassColor
793 indicator:SetBackdropColor(classColor.r,classColor.g,classColor.b)
794 indicator:Show()
795 end
796 i = i + 1
797 end
798 if self.bgSizeConfig.NumericTargetindicator_Enabled then
799 self.NumericTargetindicator:SetText(i - 1)
800 end
801 while self.TargetIndicators[i] do --hide no longer used ones
802 self.TargetIndicators[i]:Hide()
803 i = i + 1
804 end
805 end
806
807 function buttonFunctions:CheckForNewPowerColor(powerToken)
808 if self.Power.powerToken ~= powerToken then
809 local color = PowerBarColor[powerToken]
810 if color then
811 self.Power:SetStatusBarColor(color.r, color.g, color.b)
812 self.Power.powerToken = powerToken
813 end
814 end
815 end
816
817 function buttonFunctions:UpdatePower(unitID, powerToken)
818 if powerToken then
819 self:CheckForNewPowerColor(powerToken)
820 else
821 local powerType, powerToken, altR, altG, altB = UnitPowerType(unitID)
822 self:CheckForNewPowerColor(powerToken)
823 end
824 self.Power:SetValue(UnitPower(unitID)/UnitPowerMax(unitID))
825 end
826
827 function buttonFunctions:UpdateRange(inRange)
828 if self.config.RangeIndicator_Enabled and not inRange then
829 self.RangeIndicator:SetAlpha(self.config.RangeIndicator_Alpha)
830 else
831 self.RangeIndicator:SetAlpha(1)
832 end
833 end
834
835 function buttonFunctions:UpdateAll(unitID)
836 self:UpdateRange(IsItemInRange(self.config.RangeIndicator_Range, unitID))
837 self:UpdateHealth(unitID)
838 if self.config.PowerBar_Enabled then self:UpdatePower(unitID) end
839 end
840
841 local UAspellIDs = {
842 [233490] = true,
843 [233496] = true,
844 [233497] = true,
845 [233498] = true,
846 [233499] = true,
847 }
848
849 function buttonFunctions:AuraApplied(spellID, spellName, srcName, auraType, amount)
850 local config = self.bgSizeConfig
851
852 local isMine = srcName == PlayerDetails.PlayerName
853 local isDebuff, func, aurasEnabled
854 if auraType == "DEBUFF" then
855 isDebuff = true
856 func = UnitDebuff
857 aurasEnabled = config.Auras_Enabled and config.Auras_Debuffs_Enabled
858 else
859 isDebuff = false
860 func = UnitBuff
861 aurasEnabled = config.Auras_Enabled and config.Auras_Buffs_Enabled
862 end
863
864 local drCat = DRData:GetSpellCategory(spellID)
865 --BattleGroundEnemies:Debug(operation, spellID)
866 local showAurasOnSpecicon = config.Spec_AuraDisplay_Enabled
867 local drTrackingEnabled = drCat and config.DrTracking_Enabled and (not config.DrTrackingFiltering_Enabled or config.DrTrackingFiltering_Filterlist[drCat])
868 local relentlessCheck = drCat and config.Trinket_Enabled and not self.Trinket.HasTrinket and Data.cCduration[drCat] and Data.cCduration[drCat][spellID]
869 local isAdaptation = isDebuff and spellID == 195901
870
871 --if srcName == PlayerDetails.PlayerName then BattleGroundEnemies:Debug(aurasEnabled, config.Auras_Enabled, config.AurasFiltering_Enabled, config.AurasFiltering_Filterlist[spellID]) end
872 if not (showAurasOnSpecicon or drTrackingEnabled or aurasEnabled or relentlessCheck) then return end
873
874
875 local count, actualDuration, endTime, debuffType, _
876
877 if BattleGroundEnemies.TestmodeActive then
878 actualDuration = Data.cCdurationBySpellID[spellID] or random(10, 15)
879 amount = random(1, 20)
880 debuffType = Data.RandomDebuffType[random(1, #Data.RandomDebuffType)]
881 if drCat and self.DRContainer.DR[drCat] then
882 actualDuration = actualDuration/2^self.DRContainer.DR[drCat].status
883 end
884 endTime = GetTime() + actualDuration
885
886 elseif spellName then
887 local unitIDs = self.UnitIDs
888 local activeUnitID
889 -- we can't get Buffs from nameplates(we only use nameplates for enemies) > find another unitID for that enemy if auraType is a buff and the active unitID is a nameplate
890 if self.PlayerIsEnemy then
891 if isDebuff then
892 activeUnitID = unitIDs.Active
893 else
894 if unitIDs.Active ~= unitIDs.Nameplate then
895 activeUnitID = unitIDs.Active
896 else
897 activeUnitID = unitIDs.Target or unitIDs.Focus or unitIDs.Ally
898 end
899 end
900 else
901 activeUnitID = self.unit
902 end
903
904 if not activeUnitID then return end
905 if isMine then
906 if UAspellIDs[spellID] then --more expensier way since we need to iterate through all debuffs
907 for i = 1, 40 do
908 local _spellID
909 _, _, _, count, debuffType , actualDuration, endTime, _, _, _, _spellID, _, _, _, _, _, _, _, _ = UnitDebuff(activeUnitID, i, "PLAYER")
910 if spellID == _spellID then
911 break
912 end
913 end
914 else
915 _, _, _, count, debuffType , actualDuration, endTime, _, _, _, _, _, _, _, _, _, _, _, _ = func(activeUnitID, spellName, nil, "PLAYER")
916 end
917 else
918 for i = 1, 40 do
919 local _spellID, unitCaster
920 _, _, _, count, debuffType , actualDuration, endTime, unitCaster, _, _, _spellID, _, _, _, _, _, _, _, _ = func(activeUnitID, i)
921 if spellID == _spellID and unitCaster then
922 local uName, realm = UnitName(unitCaster)
923 if realm then
924 uName = uName.."-"..realm
925 end
926 if uName == srcName then
927 break
928 end
929 end
930 end
931 end
932 end
933 --if srcName == PlayerDetails.PlayerName then BattleGroundEnemies:Debug(aurasEnabled, config.Auras_Enabled, config.AurasFiltering_Enabled, config.AurasFiltering_Filterlist[spellID], actualDuration) end
934
935 if actualDuration and actualDuration > 0 then
936 if showAurasOnSpecicon then
937 local priority = Data.SpellPriorities[spellID]
938 if priority then
939 self.Spec_AuraDisplay:NewAura(spellID, srcName, actualDuration, endTime, priority)
940 end
941 end
942 if drTrackingEnabled then
943 self.DRContainer:DisplayDR(drCat, spellID, actualDuration)
944 self.DRContainer.DR[drCat]:IncreaseDRState()
945 end
946 if aurasEnabled then
947 if isDebuff then
948 if not config.Auras_Debuffs_Filtering_Enabled or ((not config.Auras_Debuffs_OnlyShowMine or isMine) and ((not config.Auras_Debuffs_DebuffTypeFiltering_Enabled or config.Auras_Debuffs_DebuffTypeFiltering_Filterlist[debuffType]) or (config.Auras_Debuffs_SpellIDFiltering_Enabled and config.Auras_Debuffs_SpellIDFiltering_Filterlist[spellID]))) then
949 self.DebuffContainer:DisplayAura(spellID, srcName, amount or count, actualDuration, endTime, debuffType)
950 end
951 elseif not config.Auras_Buffs_Filtering_Enabled or ((not config.Auras_Buffs_OnlyShowMine or isMine) and (not config.Auras_Buffs_SpellIDFiltering_Enabled or config.Auras_Buffs_SpellIDFiltering_Filterlist[spellID])) then
952 self.BuffContainer:DisplayAura(spellID, srcName, amount or count, actualDuration, endTime)
953 end
954 end
955 if relentlessCheck then
956
957 local Racefaktor = 1
958 if drCat == "stun" and self.PlayerRace == "Orc" then
959 Racefaktor = 0.8 --Hardiness
960 end
961
962
963 --local diminish = actualduraion/(Racefaktor * normalDuration * Trinketfaktor)
964 --local trinketFaktor * diminish = actualDuration/(Racefaktor * normalDuration)
965 --trinketTimesDiminish = trinketFaktor * diminish
966 --trinketTimesDiminish = without relentless : 1, 0.5, 0.25, with relentless: 0.8, 0.4, 0.2
967
968 local trinketTimesDiminish = actualDuration/(Racefaktor * relentlessCheck)
969
970 if trinketTimesDiminish == 0.8 or trinketTimesDiminish == 0.4 or trinketTimesDiminish == 0.2 then --Relentless
971 self.Trinket.HasTrinket = 4
972 self.Trinket.Icon:SetTexture(GetSpellTexture(196029))
973 end
974 end
975 if isAdaptation then
976 self.Trinket:DisplayTrinket(spellID, actualDuration)
977 end
978 end
979 end
980
981 function buttonFunctions:AuraRemoved(spellID, srcName)
982 srcName = srcName or ""
983 local config = self.bgSizeConfig
984 local drCat = DRData:GetSpellCategory(spellID)
985 --BattleGroundEnemies:Debug(operation, spellID)
986 local showAurasOnSpecicon = config.Spec_AuraDisplay_Enabled
987 local drTrackingEnabled = drCat and config.DrTracking_Enabled and (not config.DrTrackingFiltering_Enabled or config.DrTrackingFiltering_Filterlist[drCat])
988
989
990 if not (showAurasOnSpecicon or drTrackingEnabled) then return end
991
992 if drTrackingEnabled then
993 self.DRContainer:DisplayDR(drCat, spellID, 0)
994 local drFrame = self.DRContainer.DR[drCat]
995 if drFrame.status == 0 then -- we didn't get the applied, so we set the color and increase the dr state
996 --BattleGroundEnemies:Debug("DR Problem")
997 drFrame:IncreaseDRState()
998 end
999 end
1000 if showAurasOnSpecicon then
1001 local identifier = spellID..(srcName)
1002 local auraFrame = self.Spec_AuraDisplay
1003 if self.ActiveAuras then self.ActiveAuras[identifier] = nil end
1004 if auraFrame.DisplayedAura and auraFrame.DisplayedAura.identifier == identifier then
1005 --Look for another one
1006 auraFrame:ActiveAuraRemoved()
1007 end
1008 end
1009 local AuraFrame = self.BuffContainer.Active[spellID..srcName] or self.DebuffContainer.Active[spellID..srcName]
1010 if AuraFrame then
1011 AuraFrame.Cooldown:Clear()
1012 end
1013 end
1014
1015 function buttonFunctions:Kotmoguorbs(unitID)
1016 local objective = self.ObjectiveAndRespawn
1017 --BattleGroundEnemies:Debug("Läüft")
1018 local battleGroundDebuffs = BattleGroundEnemies.BattleGroundDebuffs
1019 for i = 1, #battleGroundDebuffs do
1020 local name, _, _, count, _, _, _, _, _, _, spellID, _, _, _, _, _, value2, value3, value4 = UnitDebuff(unitID, battleGroundDebuffs[i])
1021 --values for orb debuff:
1022 --BattleGroundEnemies:Debug(value0, value1, value2, value3, value4, value5)
1023 -- value2 = Reduces healing received by value2
1024 -- value3 = Increases damage taken by value3
1025 -- value4 = Increases damage done by value4
1026 if value3 then
1027 if not objective.Value then
1028 --BattleGroundEnemies:Debug("hier")
1029 --player just got the debuff
1030 objective.Icon:SetTexture(GetSpellTexture(spellID))
1031 objective:Show()
1032 --BattleGroundEnemies:Debug("Texture set")
1033 end
1034 if value3 ~= objective.Value then
1035 objective.AuraText:SetText(value3)
1036 objective.Value = value3
1037 end
1038 return
1039 end
1040 end
1041 end
1042
1043 function buttonFunctions:NotKotmogu(unitID)
1044 local objective = self.ObjectiveAndRespawn
1045 local battleGroundDebuffs = BattleGroundEnemies.BattleGroundDebuffs
1046 local name, count, _
1047 for i = 1, #battleGroundDebuffs do
1048 name, _, _, count = UnitDebuff(unitID, battleGroundDebuffs[i])
1049 --values for orb debuff:
1050 --BattleGroundEnemies:Debug(value0, value1, value2, value3, value4, value5)
1051 -- value2 = Reduces healing received by value2
1052 -- value3 = Increases damage taken by value3
1053 -- value4 = Increases damage done by value4
1054
1055 if count then -- Focused Assault, Brutal Assault
1056 if count ~= objective.Value then
1057 objective.AuraText:SetText(count)
1058 objective.Value = count
1059 end
1060 return
1061 end
1062 end
1063 end
1064
1065 function buttonFunctions:UNIT_AURA(unitID)
1066 if BattleGroundEnemies.BattleGroundDebuffs then
1067 if CurrentMapID == 856 then --856 is kotmogu
1068 self:Kotmoguorbs(unitID)
1069 else
1070 self:NotKotmogu(unitID)
1071 end
1072 end
1073 end
1074
1075 function buttonFunctions:UpdateTargets()
1076 --self:Debug(unitID, "target changed")
1077
1078 local oldTargetPlayerButton = self.Target
1079 local newTargetPlayerButton
1080
1081 if oldTargetPlayerButton then
1082 oldTargetPlayerButton:NoLongerTargetedBy(self)
1083 --self:Debug(oldTargetEnemyButton.DisplayedName, "is not targeted by", unitID, "anymore")
1084 end
1085
1086 if self.PlayerIsEnemy then
1087 newTargetPlayerButton = BattleGroundEnemies.Allies:GetPlayerbuttonByUnitID((self.UnitIDs.Active or "") .."target")
1088 else
1089 newTargetPlayerButton = BattleGroundEnemies.Enemies:GetPlayerbuttonByUnitID(self.TargetUnitID or "")
1090 end
1091
1092 if newTargetPlayerButton then --ally targets an existing enemy
1093 newTargetPlayerButton:NowTargetedBy(self)
1094 self.Target = newTargetPlayerButton
1095 --self:Debug(newTargetEnemyButton.DisplayedName, "is now targeted by", unitID)
1096 else
1097 self.Target = false
1098 end
1099 end
1100end
1101
1102local allyButtonFunctions = {}
1103do
1104
1105 function allyButtonFunctions:NowTargetedBy(enemyButton)
1106 local unitIDs = self.UnitIDs
1107 unitIDs.TargetedByEnemy[enemyButton] = true
1108 self:UpdateTargetIndicators()
1109 end
1110
1111 function allyButtonFunctions:NoLongerTargetedBy(enemyButton)
1112 local unitIDs = self.UnitIDs
1113 unitIDs.TargetedByEnemy[enemyButton] = nil
1114 self:UpdateTargetIndicators()
1115 end
1116
1117 allyButtonFunctions.UNIT_HEALTH_FREQUENT = buttonFunctions.UpdateHealth
1118 allyButtonFunctions.UNIT_POWER_FREQUENT = buttonFunctions.UpdatePower
1119
1120 -- function allyButtonFunctions:UNIT_AURA()
1121 -- local unitID = self.unit
1122 -- for i = 1, 40 do
1123 -- local _spellID
1124 -- _, _, _, count, debuffType , actualDuration, endTime, _, _, _, _spellID, _, _, _, _, _, _, _, _ = UnitDebuff(unitID, i, "PLAYER")
1125 -- if spellID == _spellID then
1126 -- break
1127 -- end
1128 -- end
1129 -- end
1130end
1131
1132-- functions for aura on spec icon
1133local AuraFrameFunctions = {}
1134function AuraFrameFunctions:ActiveAuraRemoved()
1135 local activeAuras = self.ActiveAuras
1136 if self.DisplayedAura then
1137 activeAuras[self.DisplayedAura.identifier] = nil
1138 self.DisplayedAura = false
1139 end
1140
1141
1142 local highestPrioritySpell
1143
1144 for identifier, spellDetails in pairs(activeAuras) do
1145
1146 if spellDetails.endTime > GetTime() then
1147 activeAuras[identifier] = nil
1148 else
1149 if not highestPrioritySpell or spellDetails.priority > highestPrioritySpell.priority then
1150 highestPrioritySpell = spellDetails
1151 end
1152 end
1153 end
1154 if highestPrioritySpell then
1155 self:DisplayNewAura(highestPrioritySpell)
1156 else
1157 self:Hide()
1158 end
1159end
1160
1161function AuraFrameFunctions:GotInterrupted(spellID, interruptDuration)
1162 if self.SpecHasReducedInterruptTime then
1163 interruptDuration = interruptDuration * 0.7
1164 end
1165 if self.HasAdditionalReducedInterruptTime then
1166 interruptDuration = interruptDuration * 0.3
1167 end
1168 self:NewAura(spellID, nil, interruptDuration, GetTime() + interruptDuration, 4)
1169end
1170
1171function AuraFrameFunctions:NewAura(spellID, srcName, actualDuration, endTime, priority)
1172 local identifier = spellID..(srcName or "")
1173 if not self.ActiveAuras[identifier] then self.ActiveAuras[identifier] = {} end
1174 local activAuraSpell = self.ActiveAuras[identifier]
1175 activAuraSpell.identifier = identifier
1176 activAuraSpell.spellID = spellID
1177 activAuraSpell.duration = actualDuration
1178 activAuraSpell.endTime = endTime
1179 activAuraSpell.priority = priority
1180 if not self.DisplayedAura or priority > self.DisplayedAura.priority then
1181 self:DisplayNewAura(activAuraSpell)
1182 end
1183end
1184
1185function AuraFrameFunctions:DisplayNewAura(spellDetails)
1186 self.DisplayedAura = spellDetails
1187 self:Show()
1188 self.Icon:SetTexture(GetSpellTexture(spellDetails.spellID))
1189 self.Cooldown:SetCooldown(spellDetails.endTime - spellDetails.duration, spellDetails.duration)
1190end
1191
1192
1193local MainFrameFunctions = {}
1194do
1195 function MainFrameFunctions:ApplyAllSettings()
1196 --BattleGroundEnemies:Debug(self.PlayerType)
1197 self.config = BattleGroundEnemies.db.profile[self.PlayerType]
1198 if BattleGroundEnemies.BGSize then self:ApplyBGSizeSettings() end
1199 end
1200
1201 function MainFrameFunctions:ApplyBGSizeSettings()
1202 self.bgSizeConfig = self.config[tostring(BattleGroundEnemies.BGSize)]
1203 local conf = self.bgSizeConfig
1204
1205 self:SetSize(conf.BarWidth, 30)
1206 self:SetScale(conf.Framescale)
1207
1208 self:ClearAllPoints()
1209 if not conf.Position_X and not conf.Position_Y then
1210 self:SetPoint("CENTER", UIParent, "CENTER")
1211 else
1212 local scale = self:GetEffectiveScale()
1213 self:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", conf.Position_X / scale, conf.Position_Y / scale)
1214 end
1215 self.PlayerCount:SetTextColor(unpack(conf.PlayerCount_Textcolor))
1216
1217 self:SetPlayerCountJustifyV(conf.BarVerticalGrowdirection)
1218
1219 self.PlayerCount:ApplyFontStringSettings(conf.PlayerCount_Fontsize, conf.PlayerCount_Outline, conf.PlayerCount_EnableTextshadow, conf.PlayerCount_TextShadowcolor)
1220
1221 for name, playerButton in pairs(self.Players) do
1222 playerButton:ApplyButtonSettings()
1223 playerButton:SetName()
1224 playerButton:SetBindings()
1225 end
1226 self:ButtonPositioning()
1227
1228 for number, playerButton in pairs(self.InactivePlayerButtons) do
1229 playerButton:ApplyButtonSettings()
1230 end
1231
1232
1233 self:CheckIfShouldShow()
1234 end
1235
1236 function MainFrameFunctions:CheckIfShouldShow()
1237 if self.config.Enabled and BattleGroundEnemies.BGSize and self.bgSizeConfig.Enabled then
1238 self:Show()
1239 else
1240 self:Hide()
1241 end
1242 end
1243
1244
1245 function MainFrameFunctions:UpdatePlayerCount(currentCount)
1246 if not currentCount then currentCount = BattleGroundEnemies.BGSize end
1247
1248 local isEnemy = self.PlayerType == "Enemies"
1249 local enemyFaction = BattleGroundEnemies.EnemyFaction or (playerFaction == "Horde" and 1 or 0)
1250
1251
1252 local oldCount = self.PlayerCount.oldPlayerNumber or 0
1253 if oldCount ~= currentCount then
1254 if BattleGroundEnemies.IsRatedBG and self.bgSizeConfig.Notifications_Enabled then
1255 if currentCount < oldCount then
1256 RaidNotice_AddMessage(RaidWarningFrame, L[isEnemy and "EnemyLeft" or "AllyLeft"], ChatTypeInfo["RAID_WARNING"])
1257 PlaySound(isEnemy and 124 or 8959) --LEVELUPSOUND
1258 else -- currentCount > oldCount
1259 RaidNotice_AddMessage(RaidWarningFrame, L[isEnemy and "EnemyJoined" or "AllyJoined"], ChatTypeInfo["RAID_WARNING"])
1260 PlaySound(isEnemy and 8959 or 124) --RaidWarning
1261 end
1262 end
1263 if self.bgSizeConfig.PlayerCount_Enabled then
1264 self.PlayerCount:SetText(format(isEnemy == (enemyFaction == 0) and PLAYER_COUNT_HORDE or PLAYER_COUNT_ALLIANCE, currentCount))
1265 end
1266 self.PlayerCount.oldPlayerNumber = currentCount
1267 end
1268 end
1269
1270 function MainFrameFunctions:GetPlayerbuttonByUnitID(unitID)
1271 local uName, realm = UnitName(unitID)
1272 if realm then
1273 uName = uName.."-"..realm
1274 end
1275 return self.Players[uName]
1276 end
1277
1278
1279 function MainFrameFunctions:SetPlayerCountJustifyV(direction)
1280 if direction == "downwards" then
1281 self.PlayerCount:SetJustifyV("BOTTOM")
1282 else
1283 self.PlayerCount:SetJustifyV("TOP")
1284 end
1285 end
1286
1287 function MainFrameFunctions:SetupButtonForNewPlayer(playerDetails)
1288 local playerButton = self.InactivePlayerButtons[#self.InactivePlayerButtons]
1289 if playerButton then --recycle a previous used button
1290
1291 tremove(self.InactivePlayerButtons, #self.InactivePlayerButtons)
1292 --Cleanup previous shown stuff of another player
1293 playerButton.RangeIndicator:SetAlpha(self.config.RangeIndicator_Alpha)
1294 playerButton.Trinket:Reset()
1295 playerButton.Racial:Reset()
1296 playerButton.MyTarget:Hide() --reset possible shown target indicator frame
1297 playerButton.MyFocus:Hide() --reset possible shown target indicator frame
1298 playerButton.BuffContainer:Reset()
1299 playerButton.DebuffContainer:Reset()
1300 playerButton.DRContainer:Reset()
1301 playerButton.SelectionHighlight:Hide()
1302 playerButton.NumericTargetindicator:SetText(0) --reset testmode
1303
1304 if playerButton.UnitIDs and playerButton.PlayerIsEnemy then --check because of testmode
1305 wipe(playerButton.UnitIDs.TargetedByEnemy)
1306 playerButton:UpdateTargetIndicators() --update numerical and symbolic target indicator
1307 playerButton:DeleteActiveUnitID()
1308 end
1309
1310 else --no recycleable buttons remaining => create a new one
1311 playerButton = CreateFrame('Button', nil, self, 'SecureUnitButtonTemplate')
1312 -- setmetatable(playerButton, self)
1313 -- self.__index = self
1314 playerButton.PlayerType = self.PlayerType
1315 playerButton.PlayerIsEnemy = playerButton.PlayerType == "Enemies" and true or false
1316
1317 playerButton.config = self.config
1318 playerButton.bgSizeConfig = self.bgSizeConfig
1319
1320 playerButton:SetScript("OnSizeChanged", function(self, width, height)
1321 self.DRContainer:SetWidthOfAuraFrames(height)
1322 playerButton.Level:SetHeight(height)
1323 playerButton:DisplayLevel()
1324 end)
1325
1326 for functionName, func in pairs(buttonFunctions) do
1327 playerButton[functionName] = func
1328 end
1329
1330 if playerButton.PlayerIsEnemy then
1331 for funcName, func in pairs(enemyButtonFunctions) do
1332 playerButton[funcName] = func
1333 end
1334 else
1335 for funcName, func in pairs(allyButtonFunctions) do
1336 playerButton[funcName] = func
1337 end
1338 RegisterUnitWatch(playerButton, true)
1339
1340 end
1341
1342 playerButton:SetScript("OnEvent", function(self, event, ...) self[event](self, ...) end)
1343 playerButton:SetScript("OnHide", playerButton.UnregisterAllEvents)
1344
1345 -- events/scripts
1346 playerButton:RegisterForClicks('AnyUp')
1347 playerButton:RegisterForDrag('LeftButton')
1348 playerButton:SetAttribute('type1','macro')-- type1 = LEFT-Click
1349 playerButton:SetAttribute('type2','macro')-- type2 = Right-Click
1350 playerButton:SetAttribute('type3','macro')-- type3 = Middle-Click
1351
1352 playerButton:SetScript('OnDragStart', playerButton.OnDragStart)
1353 playerButton:SetScript('OnDragStop', playerButton.OnDragStop)
1354 playerButton:SetScript('OnEnter', playerButton.OnEnter)
1355 playerButton:SetScript('OnLeave', playerButton.OnLeave)
1356
1357
1358 playerButton.RangeIndicator_Frame = CreateFrame("Frame", nil, playerButton)
1359 --playerButton.RangeIndicator_Frame:SetFrameLevel(playerButton:GetFrameLevel())
1360 -- playerButton.RangeIndicator = playerButton.RangeIndicator_Frame
1361
1362 -- spec
1363 playerButton.Spec = CreateFrame("Frame", nil, playerButton)
1364
1365 playerButton.Spec.ApplySettings = function(self)
1366 if playerButton.bgSizeConfig.Spec_Enabled then
1367 self:Show()
1368 self:SetWidth(playerButton.bgSizeConfig.Spec_Width)
1369 else
1370 --dont SetWidth before Hide() otherwise it won't work as aimed
1371 self:Hide()
1372 self:SetWidth(0.01)
1373 end
1374 end
1375
1376 playerButton.Spec:SetPoint('TOPLEFT', playerButton, 'TOPLEFT', 0, 0)
1377 playerButton.Spec:SetPoint('BOTTOMLEFT' , playerButton, 'BOTTOMLEFT', 0, 0)
1378
1379 playerButton.Spec:SetScript("OnSizeChanged", function(self, width, height)
1380 BattleGroundEnemies.CropImage(self.Icon, width, height)
1381 BattleGroundEnemies.CropImage(playerButton.Spec_AuraDisplay.Icon, width, height)
1382 end)
1383
1384 playerButton.Spec.Icon = playerButton.Spec:CreateTexture(nil, 'BACKGROUND')
1385 playerButton.Spec.Icon:SetAllPoints()
1386
1387
1388 playerButton.Spec_AuraDisplay = CreateFrame("Frame", nil, playerButton.Spec)
1389 playerButton.Spec_AuraDisplay:Hide()
1390 for funcName, func in pairs(AuraFrameFunctions) do
1391 playerButton.Spec_AuraDisplay[funcName] = func
1392 end
1393 playerButton.Spec_AuraDisplay:SetAllPoints()
1394 playerButton.Spec_AuraDisplay:SetFrameLevel(playerButton.Spec:GetFrameLevel() + 1)
1395 playerButton.Spec_AuraDisplay.ActiveAuras = {}
1396 playerButton.Spec_AuraDisplay.Icon = playerButton.Spec_AuraDisplay:CreateTexture(nil, 'BACKGROUND')
1397 playerButton.Spec_AuraDisplay.Icon:SetAllPoints()
1398 playerButton.Spec_AuraDisplay.Cooldown = BattleGroundEnemies.MyCreateCooldown(playerButton.Spec_AuraDisplay)
1399
1400 playerButton.Spec_AuraDisplay.Cooldown:SetScript("OnHide", function(self)
1401 --self:Debug("ObjectiveAndRespawn.Cooldown hidden")
1402 self:GetParent():ActiveAuraRemoved()
1403 end)
1404
1405 -- power
1406 playerButton.Power = CreateFrame('StatusBar', nil, playerButton)
1407 playerButton.Power:SetPoint('BOTTOMLEFT', playerButton.Spec, "BOTTOMRIGHT", 1, 1)
1408 playerButton.Power:SetPoint('BOTTOMRIGHT', playerButton, "BOTTOMRIGHT", -1, 1)
1409 playerButton.Power:SetMinMaxValues(0, 1)
1410
1411
1412 --playerButton.Power.Background = playerButton.Power:CreateTexture(nil, 'BACKGROUND', nil, 2)
1413 playerButton.Power.Background = playerButton.Power:CreateTexture(nil, 'BACKGROUND')
1414 playerButton.Power.Background:SetAllPoints()
1415 playerButton.Power.Background:SetTexture("Interface/Buttons/WHITE8X8")
1416
1417 -- health
1418 playerButton.Health = CreateFrame('StatusBar', nil, playerButton.Power)
1419 playerButton.Health:SetPoint('BOTTOMLEFT', playerButton.Power, "TOPLEFT", 0, 0)
1420 playerButton.Health:SetPoint('TOPRIGHT', playerButton, "TOPRIGHT", -1, -1)
1421 playerButton.Health:SetMinMaxValues(0, 1)
1422
1423 --playerButton.Health.Background = playerButton.Health:CreateTexture(nil, 'BACKGROUND', nil, 2)
1424 playerButton.Health.Background = playerButton.Health:CreateTexture(nil, 'BACKGROUND')
1425 playerButton.Health.Background:SetAllPoints()
1426 playerButton.Health.Background:SetTexture("Interface/Buttons/WHITE8X8")
1427
1428 -- role
1429 playerButton.Role = CreateFrame("Frame", nil, playerButton.Health)
1430 playerButton.Role:SetPoint("TOPLEFT")
1431 playerButton.Role:SetPoint("BOTTOMLEFT")
1432 playerButton.Role.Icon = playerButton.Role:CreateTexture(nil, 'OVERLAY')
1433 playerButton.Role.Icon:SetTexture("Interface\\LFGFrame\\UI-LFG-ICON-PORTRAITROLES")
1434
1435 playerButton.Role.ApplySettings = function(self)
1436 if playerButton.bgSizeConfig.RoleIcon_Enabled then
1437 self:SetWidth(playerButton.bgSizeConfig.RoleIcon_Size)
1438 self.Icon:SetSize(playerButton.bgSizeConfig.RoleIcon_Size, playerButton.bgSizeConfig.RoleIcon_Size)
1439 self.Icon:SetPoint("TOPLEFT", self, "TOPLEFT", 2, -playerButton.bgSizeConfig.RoleIcon_VerticalPosition)
1440 self:Show()
1441 else
1442 self:Hide()
1443 self:SetSize(0.01, 0.01)
1444 end
1445 end
1446
1447
1448 --MyTarget, indicating the current target of the player
1449 playerButton.MyTarget = CreateFrame('Frame', nil, playerButton.Health)
1450 playerButton.MyTarget:SetPoint("TOPLEFT", playerButton.Health, "TOPLEFT", -1, 1)
1451 playerButton.MyTarget:SetPoint("BOTTOMRIGHT", playerButton.Power, "BOTTOMRIGHT", 1, -1)
1452 playerButton.MyTarget:SetBackdrop({
1453 bgFile = "Interface/Buttons/WHITE8X8", --drawlayer "BACKGROUND"
1454 edgeFile = 'Interface/Buttons/WHITE8X8', --drawlayer "BORDER"
1455 edgeSize = 1
1456 })
1457 playerButton.MyTarget:SetBackdropColor(0, 0, 0, 0)
1458 playerButton.MyTarget:Hide()
1459
1460 --MyFocus, indicating the current focus of the player
1461 playerButton.MyFocus = CreateFrame('Frame', nil, playerButton.Health)
1462 playerButton.MyFocus:SetPoint("TOPLEFT", playerButton.Health, "TOPLEFT", -1, 1)
1463 playerButton.MyFocus:SetPoint("BOTTOMRIGHT", playerButton.Power, "BOTTOMRIGHT", 1, -1)
1464 playerButton.MyFocus:SetBackdrop({
1465 bgFile = "Interface/Buttons/WHITE8X8", --drawlayer "BACKGROUND"
1466 edgeFile = 'Interface/Buttons/WHITE8X8', --drawlayer "BORDER"
1467 edgeSize = 1
1468 })
1469 playerButton.MyFocus:SetBackdropColor(0, 0, 0, 0)
1470 playerButton.MyFocus:Hide()
1471
1472 -- selection highlight
1473 playerButton.SelectionHighlight = playerButton:CreateTexture(nil, 'HIGHLIGHT')
1474 playerButton.SelectionHighlight:SetPoint("TOPLEFT", playerButton.MyTarget)
1475 playerButton.SelectionHighlight:SetPoint("BOTTOMRIGHT", playerButton.MyTarget)
1476 playerButton.SelectionHighlight:Hide()
1477
1478 -- level
1479 playerButton.Level = BattleGroundEnemies.MyCreateFontString(playerButton.Health)
1480 playerButton.Level:SetPoint("TOPLEFT", playerButton.Role, "TOPRIGHT", 2, 2)
1481 playerButton.Level:SetJustifyH("LEFT")
1482
1483 -- numerical target indicator
1484 playerButton.NumericTargetindicator = BattleGroundEnemies.MyCreateFontString(playerButton.Health)
1485 playerButton.NumericTargetindicator:SetPoint('TOPRIGHT', playerButton, "TOPRIGHT", -5, 0)
1486 playerButton.NumericTargetindicator:SetPoint('BOTTOMRIGHT', playerButton, "BOTTOMRIGHT", -5, 0)
1487 playerButton.NumericTargetindicator:SetJustifyH("RIGHT")
1488
1489 -- symbolic target indicator
1490 playerButton.TargetIndicators = {}
1491
1492 -- name
1493 playerButton.Name = BattleGroundEnemies.MyCreateFontString(playerButton.Health)
1494 playerButton.Name:SetPoint('TOPLEFT', playerButton.Level, "TOPRIGHT", 5, 2)
1495 playerButton.Name:SetPoint('BOTTOMRIGHT', playerButton.NumericTargetindicator, "BOTTOMLEFT", 0, 0)
1496 playerButton.Name:SetJustifyH("LEFT")
1497
1498 -- trinket
1499 playerButton.Trinket = BattleGroundEnemies.Objects.Trinket.New(playerButton)
1500
1501
1502 -- RACIALS
1503 playerButton.Racial = BattleGroundEnemies.Objects.Racial.New(playerButton)
1504
1505 -- Objective and respawn
1506 playerButton.ObjectiveAndRespawn = BattleGroundEnemies.Objects.ObjectiveAndRespawn.New(playerButton)
1507
1508 -- Diminishing Returns
1509 playerButton.DRContainer = BattleGroundEnemies.Objects.DR.New(playerButton)
1510
1511 -- Auras
1512 playerButton.BuffContainer = BattleGroundEnemies.Objects.Buffs.New(playerButton)
1513 playerButton.DebuffContainer = BattleGroundEnemies.Objects.Debuffs.New(playerButton)
1514
1515 playerButton:ApplyButtonSettings()
1516 end
1517
1518 for detail, value in pairs(playerDetails) do
1519 playerButton[detail] = value
1520 end
1521
1522
1523 playerButton:SetSpecAndRole()
1524
1525 playerButton.Spec_AuraDisplay.HasAdditionalReducedInterruptTime = false
1526
1527 -- level
1528 if playerButton.PlayerLevel then playerButton:SetLevel(playerButton.PlayerLevel) end --for testmode
1529
1530
1531 local color = playerButton.PlayerClassColor
1532 playerButton.Health:SetStatusBarColor(color.r,color.g,color.b)
1533 playerButton.Health:SetValue(1)
1534
1535 color = PowerBarColor[Data.Classes[playerButton.PlayerClass][playerButton.PlayerSpecName].Ressource]
1536 playerButton.Power:SetStatusBarColor(color.r, color.g, color.b)
1537
1538 playerButton:SetName()
1539 playerButton:SetBindings()
1540
1541 playerButton:Show()
1542
1543 tinsert(self.PlayerSortingTable, playerButton)
1544 self.Players[playerButton.PlayerName] = playerButton
1545
1546 return playerButton
1547 end
1548
1549 function MainFrameFunctions:RemovePlayer(playerButton)
1550
1551 print(playerButton.PlayerName, 'got removed')
1552 tremove(self.PlayerSortingTable, playerButton.Position)
1553 playerButton:Hide()
1554
1555 tinsert(self.InactivePlayerButtons, playerButton)
1556 self.Players[playerButton.PlayerName] = nil
1557 end
1558
1559 function MainFrameFunctions:RemoveAllPlayers()
1560 for i = #self.PlayerSortingTable, 1, -1 do
1561 self:RemovePlayer(self.PlayerSortingTable[i])
1562 end
1563 end
1564
1565 function MainFrameFunctions:ButtonPositioning()
1566 local players = self.PlayerSortingTable
1567 local config = self.bgSizeConfig
1568 local columns = config.BarColumns
1569
1570
1571 local verticalSpacing = config.BarVerticalSpacing
1572 local growDownwards = (config.BarVerticalGrowdirection == "downwards")
1573
1574 local horizontalSpacing = config.BarHorizontalSpacing
1575
1576 local growRightwards = (config.BarHorizontalGrowdirection == "rightwards")
1577 local playerCount = #players
1578 local rowsPerColumn = math.ceil(playerCount/columns)
1579
1580 local playerNumber = 1
1581 local previousButton = self
1582
1583 local firstButtonInColumn
1584 for columNumber = 1, columns do
1585
1586 for rowNumber = 1, rowsPerColumn do
1587
1588
1589
1590 local playerButton = players[playerNumber]
1591
1592 playerButton.Position = playerNumber
1593
1594 playerButton:ClearAllPoints()
1595
1596
1597 if rowNumber == 1 and columNumber ~= 1 then
1598 if growRightwards then
1599 playerButton:SetPoint("TOPLEFT", firstButtonInColumn, "TOPRIGHT", horizontalSpacing, 0)
1600 else --growLeftwards
1601 playerButton:SetPoint("TOPRIGHT", firstButtonInColumn, "TOPLEFT", -horizontalSpacing, 0)
1602 end
1603 else
1604 if growDownwards then
1605 playerButton:SetPoint("TOPLEFT", previousButton, "BOTTOMLEFT", 0, -verticalSpacing)
1606 else --growUpwards
1607 playerButton:SetPoint("BOTTOMLEFT", previousButton, "TOPLEFT", 0, verticalSpacing)
1608 end
1609 end
1610
1611 if rowNumber == 1 then
1612 firstButtonInColumn = playerButton
1613 end
1614
1615 playerNumber = playerNumber + 1
1616 if playerNumber > playerCount then break end
1617
1618 previousButton = playerButton
1619 end
1620 end
1621 end
1622
1623 function MainFrameFunctions:CreateOrUpdatePlayer(name, race, classTag, specName)
1624
1625 local playerButton = self.Players[name]
1626 if playerButton then --already existing
1627 if playerButton.PlayerSpecName ~= specName then--its possible to change specName in battleground
1628 playerButton.PlayerSpecName = specName
1629 playerButton:SetSpecAndRole()
1630 self.resort = true
1631 end
1632
1633 playerButton.Status = 1 --1 means found, already existing
1634 else
1635 self.NewPlayerDetails[name] = { -- details of this new player
1636 PlayerClass = classTag,
1637 PlayerName = name,
1638 PlayerRace = LibRaces:GetRaceToken(race), --delifers are local independent token for relentless check
1639 PlayerSpecName = specName,
1640 PlayerClassColor = RAID_CLASS_COLORS[classTag],
1641 PlayerLevel = false
1642 }
1643 self.resort = true
1644 end
1645 end
1646
1647 --Rückwärts um keine Probleme mit tremove zu bekommen, wenn man mehr als einen Spieler in einem Schleifendurchlauf entfernt,
1648 -- da ansonsten die enemyButton.Position nicht mehr passen (sie sind zu hoch)
1649 function MainFrameFunctions:DeleteAndCreateNewPlayers()
1650 for i = #self.PlayerSortingTable, 1, -1 do
1651 local playerButton = self.PlayerSortingTable[i]
1652 if playerButton.Status == 2 then --no longer existing
1653 print(playerButton.PlayerName, 'doesnt exist anymore')
1654 self:RemovePlayer(playerButton)
1655 local targetEnemyButton = playerButton.Target
1656 if targetEnemyButton then -- if that no longer exiting ally targeted something update the button of its target
1657 targetEnemyButton:NoLongerTargetedBy(playerButton)
1658 end
1659
1660 self.resort = true
1661 else -- == 1 -- set to 2 for the next comparison
1662 playerButton.Status = 2
1663 end
1664 end
1665
1666 for name, playerDetails in pairs(self.NewPlayerDetails) do
1667 local playerButton = self:SetupButtonForNewPlayer(playerDetails)
1668
1669 -- set data for real players
1670 playerButton.Status = 2
1671
1672 playerButton.UnitIDs = {TargetedByEnemy = {}}
1673 if playerButton.PlayerIsEnemy then
1674 playerButton:UpdateRange(false)
1675 else
1676 playerButton:UpdateRange(true)
1677 end
1678
1679
1680 -- end set data for real enemies
1681 end
1682
1683 if self.resort then
1684 self:SortPlayers()
1685 end
1686
1687 if self.PlayerType == "Allies" then
1688 self:GROUP_ROSTER_UPDATE()
1689 end
1690 end
1691
1692 do
1693 local BlizzardsSortOrder = {}
1694 for i = 1, #CLASS_SORT_ORDER do -- Constants.lua
1695 BlizzardsSortOrder[CLASS_SORT_ORDER[i]] = i --key = ENGLISH CLASS NAME, value = number
1696 end
1697
1698 local function PlayerSortingByRoleClassName(playerA, playerB)-- a and b are playerButtons
1699 if playerA.PlayerRoleNumber == playerB.PlayerRoleNumber then
1700 if BlizzardsSortOrder[ playerA.PlayerClass ] == BlizzardsSortOrder[ playerB.PlayerClass ] then
1701 if playerA.PlayerName < playerB.PlayerName then return true end
1702 elseif BlizzardsSortOrder[ playerA.PlayerClass ] < BlizzardsSortOrder[ playerB.PlayerClass ] then return true end
1703 elseif playerA.PlayerRoleNumber < playerB.PlayerRoleNumber then return true end
1704 end
1705
1706 function MainFrameFunctions:SortPlayers()
1707 table.sort(self.PlayerSortingTable, PlayerSortingByRoleClassName)
1708 self:ButtonPositioning()
1709 end
1710 end
1711end
1712
1713
1714do
1715 local DefaultSettings = {
1716 profile = {
1717
1718 Font = "PT Sans Narrow Bold",
1719
1720 Locked = false,
1721 Debug = false,
1722
1723 DisableArenaFrames = false,
1724
1725 MyTarget_Color = {1, 1, 1, 1},
1726 MyFocus_Color = {0, 0.988235294117647, 0.729411764705882, 1},
1727 Highlight_Color = {1, 1, 0.5, 1},
1728
1729 Enemies = {
1730 Enabled = true,
1731
1732 ShowRealmnames = true,
1733 ConvertCyrillic = true,
1734 LevelText_Enabled = false,
1735 LevelText_OnlyShowIfNotMaxLevel = true,
1736 LevelText_Fontsize = 18,
1737 LevelText_Outline = "",
1738 LevelText_Textcolor = {1, 1, 1, 1},
1739 LevelText_EnableTextshadow = false,
1740 LevelText_TextShadowcolor = {0, 0, 0, 1},
1741
1742 RangeIndicator_Enabled = true,
1743 RangeIndicator_Range = 28767,
1744 RangeIndicator_Alpha = 0.55,
1745 RangeIndicator_Everything = false,
1746 RangeIndicator_Frames = {},
1747
1748 LeftButtonType = "Target",
1749 LeftButtonValue = "",
1750 RightButtonType = "Focus",
1751 RightButtonValue = "",
1752 MiddleButtonType = "Custom",
1753 MiddleButtonValue = "",
1754
1755 ["15"] = {
1756 Enabled = true,
1757
1758 Name_Fontsize = 13,
1759 Name_Outline = "",
1760 Name_Textcolor = {1, 1, 1, 1},
1761 Name_EnableTextshadow = true,
1762 Name_TextShadowcolor = {0, 0, 0, 1},
1763
1764 Position_X = false,
1765 Position_Y = false,
1766 BarWidth = 220,
1767 BarHeight = 28,
1768 BarVerticalGrowdirection = "downwards",
1769 BarVerticalSpacing = 1,
1770 BarColumns = 1,
1771 BarHorizontalGrowdirection = "rightwards",
1772 BarHorizontalSpacing = 100,
1773
1774 HealthBar_Texture = 'UI-StatusBar',
1775 HealthBar_Background = {0, 0, 0, 0.66},
1776
1777 PowerBar_Enabled = false,
1778 PowerBar_Height = 4,
1779 PowerBar_Texture = 'UI-StatusBar',
1780 PowerBar_Background = {0, 0, 0, 0.66},
1781
1782
1783 RoleIcon_Enabled = true,
1784 RoleIcon_Size = 13,
1785 RoleIcon_VerticalPosition = 2,
1786
1787 PlayerCount_Enabled = true,
1788 PlayerCount_Fontsize = 14,
1789 PlayerCount_Outline = "OUTLINE",
1790 PlayerCount_Textcolor = {1, 1, 1, 1},
1791 PlayerCount_EnableTextshadow = false,
1792 PlayerCount_TextShadowcolor = {0, 0, 0, 1},
1793
1794 Framescale = 1,
1795
1796 Spec_Enabled = true,
1797 Spec_Width = 36,
1798
1799 Spec_AuraDisplay_Enabled = true,
1800 Spec_AuraDisplay_ShowNumbers = true,
1801
1802 Spec_AuraDisplay_Cooldown_Fontsize = 12,
1803 Spec_AuraDisplay_Cooldown_Outline = "OUTLINE",
1804 Spec_AuraDisplay_Cooldown_EnableTextshadow = false,
1805 Spec_AuraDisplay_Cooldown_TextShadowcolor = {0, 0, 0, 1},
1806
1807
1808 SymbolicTargetindicator_Enabled = true,
1809
1810 NumericTargetindicator_Enabled = true,
1811 NumericTargetindicator_Fontsize = 18,
1812 NumericTargetindicator_Outline = "",
1813 NumericTargetindicator_Textcolor = {1, 1, 1, 1},
1814 NumericTargetindicator_EnableTextshadow = false,
1815 NumericTargetindicator_TextShadowcolor = {0, 0, 0, 1},
1816
1817 DrTracking_Enabled = true,
1818 DrTracking_HorizontalSpacing = 1,
1819 DrTracking_GrowDirection = "leftwards",
1820 DrTracking_Container_Color = {0, 0, 1, 1},
1821 DrTracking_Container_BorderThickness = 1,
1822 DrTracking_Container_BasicPoint = "RIGHT",
1823 DrTracking_Container_RelativeTo = "Button",
1824 DrTracking_Container_RelativePoint = "LEFT",
1825 DrTracking_Container_OffsetX = 1,
1826 DrTracking_DisplayType = "Countdowntext",
1827
1828 DrTracking_ShowNumbers = true,
1829
1830 DrTracking_Cooldown_Fontsize = 12,
1831 DrTracking_Cooldown_Outline = "OUTLINE",
1832 DrTracking_Cooldown_EnableTextshadow = false,
1833 DrTracking_Cooldown_TextShadowcolor = {0, 0, 0, 1},
1834
1835 DrTrackingFiltering_Enabled = false,
1836 DrTrackingFiltering_Filterlist = {},
1837
1838
1839 Auras_Enabled = true,
1840 Auras_ShowTooltips = false,
1841
1842 Auras_Buffs_Enabled = false,
1843 Auras_Buffs_Size = 15,
1844 Auras_Buffs_HorizontalGrowDirection = "leftwards",
1845 Auras_Buffs_HorizontalSpacing = 1,
1846 Auras_Buffs_VerticalGrowdirection = "upwards",
1847 Auras_Buffs_VerticalSpacing = 1,
1848 Auras_Buffs_IconsPerRow = 8,
1849 Auras_Buffs_Container_Point = "BOTTOMRIGHT",
1850 Auras_Buffs_Container_RelativeTo = "Button",
1851 Auras_Buffs_Container_RelativePoint = "BOTTOMLEFT",
1852 Auras_Buffs_Container_OffsetX = 2,
1853 Auras_Buffs_Container_OffsetY = 0,
1854
1855 Auras_Buffs_Fontsize = 12,
1856 Auras_Buffs_Outline = "OUTLINE",
1857 Auras_Buffs_Textcolor = {1, 1, 1, 1},
1858 Auras_Buffs_EnableTextshadow = true,
1859 Auras_Buffs_TextShadowcolor = {0, 0, 0, 1},
1860
1861 Auras_Buffs_ShowNumbers = true,
1862
1863 Auras_Buffs_Cooldown_Fontsize = 12,
1864 Auras_Buffs_Cooldown_Outline = "OUTLINE",
1865 Auras_Buffs_Cooldown_EnableTextshadow = false,
1866 Auras_Buffs_Cooldown_TextShadowcolor = {0, 0, 0, 1},
1867
1868 Auras_Buffs_Filtering_Enabled = true,
1869 Auras_Buffs_OnlyShowMine = true,
1870 Auras_Buffs_SpellIDFiltering_Enabled = false,
1871 Auras_Buffs_SpellIDFiltering_Filterlist = {},
1872
1873 Auras_Debuffs_Enabled = true,
1874 Auras_Debuffs_Size = 27,
1875 Auras_Debuffs_HorizontalGrowDirection = "leftwards",
1876 Auras_Debuffs_HorizontalSpacing = 1,
1877 Auras_Debuffs_VerticalGrowdirection = "upwards",
1878 Auras_Debuffs_VerticalSpacing = 1,
1879 Auras_Debuffs_IconsPerRow = 8,
1880 Auras_Debuffs_Container_Point = "RIGHT",
1881 Auras_Debuffs_Container_RelativeTo = "DRContainer",
1882 Auras_Debuffs_Container_RelativePoint = "LEFT",
1883 Auras_Debuffs_Container_OffsetX = 2,
1884 Auras_Debuffs_Container_OffsetY = 0,
1885
1886 Auras_Debuffs_Coloring_Enabled = true,
1887 Auras_Debuffs_DisplayType = "Frame",
1888 Auras_Debuffs_Fontsize = 12,
1889 Auras_Debuffs_Outline = "OUTLINE",
1890 Auras_Debuffs_Textcolor = {1, 1, 1, 1},
1891 Auras_Debuffs_EnableTextshadow = true,
1892 Auras_Debuffs_TextShadowcolor = {0, 0, 0, 1},
1893
1894 Auras_Debuffs_ShowNumbers = true,
1895
1896 Auras_Debuffs_Cooldown_Fontsize = 12,
1897 Auras_Debuffs_Cooldown_Outline = "OUTLINE",
1898 Auras_Debuffs_Cooldown_EnableTextshadow = false,
1899 Auras_Debuffs_Cooldown_TextShadowcolor = {0, 0, 0, 1},
1900
1901 Auras_Debuffs_Filtering_Enabled = true,
1902 Auras_Debuffs_OnlyShowMine = true,
1903 Auras_Debuffs_DebuffTypeFiltering_Enabled = false,
1904 Auras_Debuffs_DebuffTypeFiltering_Filterlist = {},
1905 Auras_Debuffs_SpellIDFiltering_Enabled = false,
1906 Auras_Debuffs_SpellIDFiltering_Filterlist = {},
1907
1908 ObjectiveAndRespawn_ObjectiveEnabled = true,
1909 ObjectiveAndRespawn_Width = 36,
1910 ObjectiveAndRespawn_BasicPoint = "RIGHT",
1911 ObjectiveAndRespawn_RelativeTo = "NumericTargetindicator",
1912 ObjectiveAndRespawn_RelativePoint = "LEFT",
1913 ObjectiveAndRespawn_OffsetX = -2,
1914
1915 ObjectiveAndRespawn_RespawnEnabled = true,
1916
1917 ObjectiveAndRespawn_Fontsize = 17,
1918 ObjectiveAndRespawn_Outline = "THICKOUTLINE",
1919 ObjectiveAndRespawn_Textcolor = {1, 1, 1, 1},
1920 ObjectiveAndRespawn_EnableTextshadow = false,
1921 ObjectiveAndRespawn_TextShadowcolor = {0, 0, 0, 1},
1922
1923 ObjectiveAndRespawn_ShowNumbers = true,
1924
1925 ObjectiveAndRespawn_Cooldown_Fontsize = 12,
1926 ObjectiveAndRespawn_Cooldown_Outline = "OUTLINE",
1927 ObjectiveAndRespawn_Cooldown_EnableTextshadow = false,
1928 ObjectiveAndRespawn_Cooldown_TextShadowcolor = {0, 0, 0, 1},
1929
1930 Trinket_Enabled = true,
1931 Trinket_BasicPoint = "LEFT",
1932 Trinket_RelativeTo = "Button",
1933 Trinket_RelativePoint = "RIGHT",
1934 Trinket_OffsetX = 1,
1935 Trinket_Width = 28,
1936 Trinket_ShowNumbers = true,
1937
1938 Trinket_Cooldown_Fontsize = 12,
1939 Trinket_Cooldown_Outline = "OUTLINE",
1940 Trinket_Cooldown_EnableTextshadow = false,
1941 Trinket_Cooldown_TextShadowcolor = {0, 0, 0, 1},
1942
1943 Racial_Enabled = true,
1944 Racial_BasicPoint = "LEFT",
1945 Racial_RelativeTo = "Trinket",
1946 Racial_RelativePoint = "RIGHT",
1947 Racial_OffsetX = 2,
1948 Racial_Width = 28,
1949 Racial_ShowNumbers = true,
1950
1951 Racial_Cooldown_Fontsize = 12,
1952 Racial_Cooldown_Outline = "OUTLINE",
1953 Racial_Cooldown_EnableTextshadow = false,
1954 Racial_Cooldown_TextShadowcolor = {0, 0, 0, 1},
1955
1956 RacialFiltering_Enabled = false,
1957 RacialFiltering_Filterlist = {}, --key = spellID, value = spellName or false
1958
1959 Notifications_Enabled = true,
1960 -- PositiveSound = [[Interface\AddOns\WeakAuras\Media\Sounds\BatmanPunch.ogg]],
1961 -- NegativeSound = [[Sound\Interface\UI_BattlegroundCountdown_Timer.ogg]],
1962 },
1963 ["40"] = {
1964 Enabled = true,
1965
1966 Name_Fontsize = 13,
1967 Name_Outline = "",
1968 Name_Textcolor = {1, 1, 1, 1},
1969 Name_EnableTextshadow = true,
1970 Name_TextShadowcolor = {0, 0, 0, 1},
1971
1972 Position_X = false,
1973 Position_Y = false,
1974 BarWidth = 220,
1975 BarHeight = 28,
1976 BarVerticalGrowdirection = "downwards",
1977 BarVerticalSpacing = 1,
1978 BarColumns = 1,
1979 BarHorizontalGrowdirection = "rightwards",
1980 BarHorizontalSpacing = 100,
1981
1982 HealthBar_Texture = 'UI-StatusBar',
1983 HealthBar_Background = {0, 0, 0, 0.66},
1984
1985 PowerBar_Enabled = false,
1986 PowerBar_Height = 4,
1987 PowerBar_Texture = 'UI-StatusBar',
1988 PowerBar_Background = {0, 0, 0, 0.66},
1989
1990
1991 RoleIcon_Enabled = true,
1992 RoleIcon_Size = 13,
1993 RoleIcon_VerticalPosition = 2,
1994
1995 PlayerCount_Enabled = true,
1996 PlayerCount_Fontsize = 14,
1997 PlayerCount_Outline = "OUTLINE",
1998 PlayerCount_Textcolor = {1, 1, 1, 1},
1999 PlayerCount_EnableTextshadow = false,
2000 PlayerCount_TextShadowcolor = {0, 0, 0, 1},
2001
2002 Framescale = 1,
2003
2004 Spec_Enabled = true,
2005 Spec_Width = 36,
2006
2007 Spec_AuraDisplay_Enabled = true,
2008 Spec_AuraDisplay_ShowNumbers = true,
2009
2010 Spec_AuraDisplay_Cooldown_Fontsize = 12,
2011 Spec_AuraDisplay_Cooldown_Outline = "OUTLINE",
2012 Spec_AuraDisplay_Cooldown_EnableTextshadow = false,
2013 Spec_AuraDisplay_Cooldown_TextShadowcolor = {0, 0, 0, 1},
2014
2015
2016 SymbolicTargetindicator_Enabled = true,
2017
2018 NumericTargetindicator_Enabled = true,
2019 NumericTargetindicator_Fontsize = 18,
2020 NumericTargetindicator_Outline = "",
2021 NumericTargetindicator_Textcolor = {1, 1, 1, 1},
2022 NumericTargetindicator_EnableTextshadow = false,
2023 NumericTargetindicator_TextShadowcolor = {0, 0, 0, 1},
2024
2025 DrTracking_Enabled = true,
2026 DrTracking_HorizontalSpacing = 1,
2027 DrTracking_GrowDirection = "leftwards",
2028 DrTracking_Container_Color = {0, 0, 1, 1},
2029 DrTracking_Container_BorderThickness = 1,
2030 DrTracking_Container_BasicPoint = "RIGHT",
2031 DrTracking_Container_RelativeTo = "Button",
2032 DrTracking_Container_RelativePoint = "Left",
2033 DrTracking_Container_OffsetX = 1,
2034 DrTracking_DisplayType = "Countdowntext",
2035
2036 DrTracking_ShowNumbers = true,
2037
2038 DrTracking_Cooldown_Fontsize = 12,
2039 DrTracking_Cooldown_Outline = "OUTLINE",
2040 DrTracking_Cooldown_EnableTextshadow = false,
2041 DrTracking_Cooldown_TextShadowcolor = {0, 0, 0, 1},
2042
2043 DrTrackingFiltering_Enabled = false,
2044 DrTrackingFiltering_Filterlist = {},
2045
2046
2047 Auras_Enabled = true,
2048 Auras_ShowTooltips = false,
2049
2050 Auras_Buffs_Enabled = true,
2051 Auras_Buffs_Size = 15,
2052 Auras_Buffs_HorizontalGrowDirection = "leftwards",
2053 Auras_Buffs_HorizontalSpacing = 1,
2054 Auras_Buffs_VerticalGrowdirection = "upwards",
2055 Auras_Buffs_VerticalSpacing = 1,
2056 Auras_Buffs_IconsPerRow = 8,
2057 Auras_Buffs_Container_Point = "BOTTOMRIGHT",
2058 Auras_Buffs_Container_RelativeTo = "Button",
2059 Auras_Buffs_Container_RelativePoint = "BOTTOMLEFT",
2060 Auras_Buffs_Container_OffsetX = 2,
2061 Auras_Buffs_Container_OffsetY = 0,
2062
2063 Auras_Buffs_Fontsize = 12,
2064 Auras_Buffs_Outline = "OUTLINE",
2065 Auras_Buffs_Textcolor = {1, 1, 1, 1},
2066 Auras_Buffs_EnableTextshadow = true,
2067 Auras_Buffs_TextShadowcolor = {0, 0, 0, 1},
2068
2069 Auras_Buffs_ShowNumbers = true,
2070
2071 Auras_Buffs_Cooldown_Fontsize = 12,
2072 Auras_Buffs_Cooldown_Outline = "OUTLINE",
2073 Auras_Buffs_Cooldown_EnableTextshadow = false,
2074 Auras_Buffs_Cooldown_TextShadowcolor = {0, 0, 0, 1},
2075
2076 Auras_Buffs_Filtering_Enabled = true,
2077 Auras_Buffs_OnlyShowMine = true,
2078 Auras_Buffs_SpellIDFiltering_Enabled = false,
2079 Auras_Buffs_SpellIDFiltering_Filterlist = {},
2080
2081 Auras_Debuffs_Enabled = true,
2082 Auras_Debuffs_Size = 15,
2083 Auras_Debuffs_HorizontalGrowDirection = "leftwards",
2084 Auras_Debuffs_HorizontalSpacing = 1,
2085 Auras_Debuffs_VerticalGrowdirection = "upwards",
2086 Auras_Debuffs_VerticalSpacing = 1,
2087 Auras_Debuffs_IconsPerRow = 8,
2088 Auras_Debuffs_Container_Point = "BOTTOMRIGHT",
2089 Auras_Debuffs_Container_RelativeTo = "BuffContainer",
2090 Auras_Debuffs_Container_RelativePoint = "BOTTOMLEFT",
2091 Auras_Debuffs_Container_OffsetX = 2,
2092 Auras_Debuffs_Container_OffsetY = 0,
2093
2094 Auras_Debuffs_Coloring_Enabled = true,
2095 Auras_Debuffs_DisplayType = "Frame",
2096 Auras_Debuffs_Fontsize = 12,
2097 Auras_Debuffs_Outline = "OUTLINE",
2098 Auras_Debuffs_Textcolor = {1, 1, 1, 1},
2099 Auras_Debuffs_EnableTextshadow = true,
2100 Auras_Debuffs_TextShadowcolor = {0, 0, 0, 1},
2101
2102 Auras_Debuffs_ShowNumbers = true,
2103
2104 Auras_Debuffs_Cooldown_Fontsize = 12,
2105 Auras_Debuffs_Cooldown_Outline = "OUTLINE",
2106 Auras_Debuffs_Cooldown_EnableTextshadow = false,
2107 Auras_Debuffs_Cooldown_TextShadowcolor = {0, 0, 0, 1},
2108
2109 Auras_Debuffs_Filtering_Enabled = true,
2110 Auras_Debuffs_OnlyShowMine = true,
2111 Auras_Debuffs_DebuffTypeFiltering_Enabled = true,
2112 Auras_Debuffs_DebuffTypeFiltering_Filterlist = {},
2113 Auras_Debuffs_SpellIDFiltering_Enabled = false,
2114 Auras_Debuffs_SpellIDFiltering_Filterlist = {},
2115
2116 Trinket_Enabled = true,
2117 Trinket_BasicPoint = "LEFT",
2118 Trinket_RelativeTo = "Button",
2119 Trinket_RelativePoint = "RIGHT",
2120 Trinket_OffsetX = 1,
2121 Trinket_Width = 28,
2122 Trinket_ShowNumbers = true,
2123
2124 Trinket_Cooldown_Fontsize = 12,
2125 Trinket_Cooldown_Outline = "OUTLINE",
2126 Trinket_Cooldown_EnableTextshadow = false,
2127 Trinket_Cooldown_TextShadowcolor = {0, 0, 0, 1},
2128
2129 Racial_Enabled = true,
2130 Racial_BasicPoint = "LEFT",
2131 Racial_RelativeTo = "Trinket",
2132 Racial_RelativePoint = "RIGHT",
2133 Racial_OffsetX = 1,
2134 Racial_Width = 28,
2135 Racial_ShowNumbers = true,
2136
2137 Racial_Cooldown_Fontsize = 12,
2138 Racial_Cooldown_Outline = "OUTLINE",
2139 Racial_Cooldown_EnableTextshadow = false,
2140 Racial_Cooldown_TextShadowcolor = {0, 0, 0, 1},
2141
2142 RacialFiltering_Enabled = false,
2143 RacialFiltering_Filterlist = {}, --key = spellID, value = spellName or false
2144 }
2145
2146 },
2147 Allies = {
2148 Enabled = true,
2149
2150 ShowRealmnames = true,
2151 ConvertCyrillic = true,
2152 LevelText_Enabled = false,
2153 LevelText_OnlyShowIfNotMaxLevel = true,
2154 LevelText_Fontsize = 18,
2155 LevelText_Outline = "",
2156 LevelText_Textcolor = {1, 1, 1, 1},
2157 LevelText_EnableTextshadow = false,
2158 LevelText_TextShadowcolor = {0, 0, 0, 1},
2159
2160 RangeIndicator_Enabled = true,
2161 RangeIndicator_Range = 34471,
2162 RangeIndicator_Alpha = 0.55,
2163 RangeIndicator_Everything = false,
2164 RangeIndicator_Frames = {},
2165
2166 LeftButtonType = "Target",
2167 LeftButtonValue = "",
2168 RightButtonType = "Focus",
2169 RightButtonValue = "",
2170 MiddleButtonType = "Custom",
2171 MiddleButtonValue = "",
2172
2173 ["15"] = {
2174 Enabled = true,
2175
2176 Name_Fontsize = 13,
2177 Name_Outline = "",
2178 Name_Textcolor = {1, 1, 1, 1},
2179 Name_EnableTextshadow = true,
2180 Name_TextShadowcolor = {0, 0, 0, 1},
2181
2182 Position_X = false,
2183 Position_Y = false,
2184 BarWidth = 220,
2185 BarHeight = 28,
2186 BarVerticalGrowdirection = "downwards",
2187 BarVerticalSpacing = 1,
2188 BarColumns = 1,
2189 BarHorizontalGrowdirection = "rightwards",
2190 BarHorizontalSpacing = 100,
2191
2192 HealthBar_Texture = 'UI-StatusBar',
2193 HealthBar_Background = {0, 0, 0, 0.66},
2194
2195 PowerBar_Enabled = false,
2196 PowerBar_Height = 4,
2197 PowerBar_Texture = 'UI-StatusBar',
2198 PowerBar_Background = {0, 0, 0, 0.66},
2199
2200
2201 RoleIcon_Enabled = true,
2202 RoleIcon_Size = 13,
2203 RoleIcon_VerticalPosition = 2,
2204
2205 PlayerCount_Enabled = true,
2206 PlayerCount_Fontsize = 14,
2207 PlayerCount_Outline = "OUTLINE",
2208 PlayerCount_Textcolor = {1, 1, 1, 1},
2209 PlayerCount_EnableTextshadow = false,
2210 PlayerCount_TextShadowcolor = {0, 0, 0, 1},
2211
2212 Framescale = 1,
2213
2214 Spec_Enabled = true,
2215 Spec_Width = 36,
2216
2217 Spec_AuraDisplay_Enabled = true,
2218 Spec_AuraDisplay_ShowNumbers = true,
2219
2220 Spec_AuraDisplay_Cooldown_Fontsize = 12,
2221 Spec_AuraDisplay_Cooldown_Outline = "OUTLINE",
2222 Spec_AuraDisplay_Cooldown_EnableTextshadow = false,
2223 Spec_AuraDisplay_Cooldown_TextShadowcolor = {0, 0, 0, 1},
2224
2225
2226 SymbolicTargetindicator_Enabled = true,
2227
2228 NumericTargetindicator_Enabled = true,
2229 NumericTargetindicator_Fontsize = 18,
2230 NumericTargetindicator_Outline = "",
2231 NumericTargetindicator_Textcolor = {1, 1, 1, 1},
2232 NumericTargetindicator_EnableTextshadow = false,
2233 NumericTargetindicator_TextShadowcolor = {0, 0, 0, 1},
2234
2235 DrTracking_Enabled = true,
2236 DrTracking_HorizontalSpacing = 1,
2237 DrTracking_GrowDirection = "rightwards",
2238 DrTracking_Container_Color = {0, 0, 1, 1},
2239 DrTracking_Container_BorderThickness = 1,
2240 DrTracking_Container_BasicPoint = "LEFT",
2241 DrTracking_Container_RelativeTo = "Button",
2242 DrTracking_Container_RelativePoint = "RIGHT",
2243 DrTracking_Container_OffsetX = 1,
2244 DrTracking_DisplayType = "Countdowntext",
2245
2246 DrTracking_ShowNumbers = true,
2247
2248 DrTracking_Cooldown_Fontsize = 12,
2249 DrTracking_Cooldown_Outline = "OUTLINE",
2250 DrTracking_Cooldown_EnableTextshadow = false,
2251 DrTracking_Cooldown_TextShadowcolor = {0, 0, 0, 1},
2252
2253 DrTrackingFiltering_Enabled = false,
2254 DrTrackingFiltering_Filterlist = {},
2255
2256
2257 Auras_Enabled = false,
2258 Auras_ShowTooltips = false,
2259
2260 Auras_Buffs_Enabled = false,
2261 Auras_Buffs_Size = 15,
2262 Auras_Buffs_HorizontalGrowDirection = "leftwards",
2263 Auras_Buffs_HorizontalSpacing = 1,
2264 Auras_Buffs_VerticalGrowdirection = "upwards",
2265 Auras_Buffs_VerticalSpacing = 1,
2266 Auras_Buffs_IconsPerRow = 8,
2267 Auras_Buffs_Container_Point = "BOTTOMRIGHT",
2268 Auras_Buffs_Container_RelativeTo = "Button",
2269 Auras_Buffs_Container_RelativePoint = "BOTTOMLEFT",
2270 Auras_Buffs_Container_OffsetX = 2,
2271 Auras_Buffs_Container_OffsetY = 0,
2272
2273 Auras_Buffs_Fontsize = 12,
2274 Auras_Buffs_Outline = "OUTLINE",
2275 Auras_Buffs_Textcolor = {1, 1, 1, 1},
2276 Auras_Buffs_EnableTextshadow = true,
2277 Auras_Buffs_TextShadowcolor = {0, 0, 0, 1},
2278
2279 Auras_Buffs_ShowNumbers = true,
2280
2281 Auras_Buffs_Cooldown_Fontsize = 12,
2282 Auras_Buffs_Cooldown_Outline = "OUTLINE",
2283 Auras_Buffs_Cooldown_EnableTextshadow = false,
2284 Auras_Buffs_Cooldown_TextShadowcolor = {0, 0, 0, 1},
2285
2286 Auras_Buffs_Filtering_Enabled = true,
2287 Auras_Buffs_OnlyShowMine = true,
2288 Auras_Buffs_SpellIDFiltering_Enabled = false,
2289 Auras_Buffs_SpellIDFiltering_Filterlist = {},
2290
2291 Auras_Debuffs_Enabled = true,
2292 Auras_Debuffs_Size = 15,
2293 Auras_Debuffs_HorizontalGrowDirection = "leftwards",
2294 Auras_Debuffs_HorizontalSpacing = 1,
2295 Auras_Debuffs_VerticalGrowdirection = "upwards",
2296 Auras_Debuffs_VerticalSpacing = 1,
2297 Auras_Debuffs_IconsPerRow = 8,
2298 Auras_Debuffs_Container_Point = "BOTTOMRIGHT",
2299 Auras_Debuffs_Container_RelativeTo = "BuffContainer",
2300 Auras_Debuffs_Container_RelativePoint = "BOTTOMLEFT",
2301 Auras_Debuffs_Container_OffsetX = 2,
2302 Auras_Debuffs_Container_OffsetY = 0,
2303
2304 Auras_Debuffs_Coloring_Enabled = true,
2305 Auras_Debuffs_DisplayType = "Frame",
2306 Auras_Debuffs_Fontsize = 12,
2307 Auras_Debuffs_Outline = "OUTLINE",
2308 Auras_Debuffs_Textcolor = {1, 1, 1, 1},
2309 Auras_Debuffs_EnableTextshadow = true,
2310 Auras_Debuffs_TextShadowcolor = {0, 0, 0, 1},
2311
2312 Auras_Debuffs_ShowNumbers = true,
2313
2314 Auras_Debuffs_Cooldown_Fontsize = 12,
2315 Auras_Debuffs_Cooldown_Outline = "OUTLINE",
2316 Auras_Debuffs_Cooldown_EnableTextshadow = false,
2317 Auras_Debuffs_Cooldown_TextShadowcolor = {0, 0, 0, 1},
2318
2319 Auras_Debuffs_Filtering_Enabled = true,
2320 Auras_Debuffs_OnlyShowMine = true,
2321 Auras_Debuffs_DebuffTypeFiltering_Enabled = true,
2322 Auras_Debuffs_DebuffTypeFiltering_Filterlist = {},
2323 Auras_Debuffs_SpellIDFiltering_Enabled = false,
2324 Auras_Debuffs_SpellIDFiltering_Filterlist = {},
2325
2326 ObjectiveAndRespawn_ObjectiveEnabled = true,
2327 ObjectiveAndRespawn_Width = 36,
2328 ObjectiveAndRespawn_BasicPoint = "RIGHT",
2329 ObjectiveAndRespawn_RelativeTo = "NumericTargetindicator",
2330 ObjectiveAndRespawn_RelativePoint = "LEFT",
2331 ObjectiveAndRespawn_OffsetX = -2,
2332
2333 ObjectiveAndRespawn_Width = 36,
2334 ObjectiveAndRespawn_Position = "LEFT",
2335
2336 ObjectiveAndRespawn_RespawnEnabled = true,
2337
2338 ObjectiveAndRespawn_Fontsize = 17,
2339 ObjectiveAndRespawn_Outline = "THICKOUTLINE",
2340 ObjectiveAndRespawn_Textcolor = {1, 1, 1, 1},
2341 ObjectiveAndRespawn_EnableTextshadow = false,
2342 ObjectiveAndRespawn_TextShadowcolor = {0, 0, 0, 1},
2343
2344 ObjectiveAndRespawn_ShowNumbers = true,
2345
2346 ObjectiveAndRespawn_Cooldown_Fontsize = 12,
2347 ObjectiveAndRespawn_Cooldown_Outline = "OUTLINE",
2348 ObjectiveAndRespawn_Cooldown_EnableTextshadow = false,
2349 ObjectiveAndRespawn_Cooldown_TextShadowcolor = {0, 0, 0, 1},
2350
2351 Trinket_Enabled = true,
2352 Trinket_BasicPoint = "RIGHT",
2353 Trinket_RelativeTo = "Button",
2354 Trinket_RelativePoint = "LEFT",
2355 Trinket_OffsetX = -1,
2356 Trinket_Width = 28,
2357 Trinket_ShowNumbers = true,
2358
2359 Trinket_Cooldown_Fontsize = 12,
2360 Trinket_Cooldown_Outline = "OUTLINE",
2361 Trinket_Cooldown_EnableTextshadow = false,
2362 Trinket_Cooldown_TextShadowcolor = {0, 0, 0, 1},
2363
2364 Racial_Enabled = true,
2365 Racial_BasicPoint = "RIGHT",
2366 Racial_RelativeTo = "Trinket",
2367 Racial_RelativePoint = "LEFT",
2368 Racial_OffsetX = 1,
2369 Racial_Width = 28,
2370 Racial_ShowNumbers = true,
2371
2372 Racial_Cooldown_Fontsize = 12,
2373 Racial_Cooldown_Outline = "OUTLINE",
2374 Racial_Cooldown_EnableTextshadow = false,
2375 Racial_Cooldown_TextShadowcolor = {0, 0, 0, 1},
2376
2377 RacialFiltering_Enabled = false,
2378 RacialFiltering_Filterlist = {}, --key = spellID, value = spellName or false
2379
2380 Notifications_Enabled = true,
2381 -- PositiveSound = [[Interface\AddOns\WeakAuras\Media\Sounds\BatmanPunch.ogg]],
2382 -- NegativeSound = [[Sound\Interface\UI_BattlegroundCountdown_Timer.ogg]],
2383 },
2384 ["40"] = {
2385 Enabled = true,
2386
2387 Name_Fontsize = 13,
2388 Name_Outline = "",
2389 Name_Textcolor = {1, 1, 1, 1},
2390 Name_EnableTextshadow = true,
2391 Name_TextShadowcolor = {0, 0, 0, 1},
2392
2393 Position_X = false,
2394 Position_Y = false,
2395 BarWidth = 220,
2396 BarHeight = 28,
2397 BarVerticalGrowdirection = "downwards",
2398 BarVerticalSpacing = 1,
2399 BarColumns = 1,
2400 BarHorizontalGrowdirection = "rightwards",
2401 BarHorizontalSpacing = 100,
2402
2403 HealthBar_Texture = 'UI-StatusBar',
2404 HealthBar_Background = {0, 0, 0, 0.66},
2405
2406 PowerBar_Enabled = false,
2407 PowerBar_Height = 4,
2408 PowerBar_Texture = 'UI-StatusBar',
2409 PowerBar_Background = {0, 0, 0, 0.66},
2410
2411
2412 RoleIcon_Enabled = true,
2413 RoleIcon_Size = 13,
2414 RoleIcon_VerticalPosition = 2,
2415
2416 PlayerCount_Enabled = true,
2417 PlayerCount_Fontsize = 14,
2418 PlayerCount_Outline = "OUTLINE",
2419 PlayerCount_Textcolor = {1, 1, 1, 1},
2420 PlayerCount_EnableTextshadow = false,
2421 PlayerCount_TextShadowcolor = {0, 0, 0, 1},
2422
2423 Framescale = 1,
2424
2425 Spec_Enabled = true,
2426 Spec_Width = 36,
2427
2428 Spec_AuraDisplay_Enabled = true,
2429 Spec_AuraDisplay_ShowNumbers = true,
2430
2431 Spec_AuraDisplay_Cooldown_Fontsize = 12,
2432 Spec_AuraDisplay_Cooldown_Outline = "OUTLINE",
2433 Spec_AuraDisplay_Cooldown_EnableTextshadow = false,
2434 Spec_AuraDisplay_Cooldown_TextShadowcolor = {0, 0, 0, 1},
2435
2436
2437 SymbolicTargetindicator_Enabled = true,
2438
2439 NumericTargetindicator_Enabled = true,
2440 NumericTargetindicator_Fontsize = 18,
2441 NumericTargetindicator_Outline = "",
2442 NumericTargetindicator_Textcolor = {1, 1, 1, 1},
2443 NumericTargetindicator_EnableTextshadow = false,
2444 NumericTargetindicator_TextShadowcolor = {0, 0, 0, 1},
2445
2446 DrTracking_Enabled = true,
2447 DrTracking_HorizontalSpacing = 1,
2448 DrTracking_GrowDirection = "rightwards",
2449 DrTracking_Container_Color = {0, 0, 1, 1},
2450 DrTracking_Container_BorderThickness = 1,
2451 DrTracking_Container_BasicPoint = "LEFT",
2452 DrTracking_Container_RelativeTo = "Button",
2453 DrTracking_Container_RelativePoint = "RIGHT",
2454 DrTracking_Container_OffsetX = 1,
2455 DrTracking_DisplayType = "Countdowntext",
2456
2457 DrTracking_ShowNumbers = true,
2458
2459 DrTracking_Cooldown_Fontsize = 12,
2460 DrTracking_Cooldown_Outline = "OUTLINE",
2461 DrTracking_Cooldown_EnableTextshadow = false,
2462 DrTracking_Cooldown_TextShadowcolor = {0, 0, 0, 1},
2463
2464 DrTrackingFiltering_Enabled = false,
2465 DrTrackingFiltering_Filterlist = {},
2466
2467
2468 Auras_Enabled = false,
2469 Auras_ShowTooltips = false,
2470
2471 Auras_Buffs_Enabled = true,
2472 Auras_Buffs_Size = 15,
2473 Auras_Buffs_HorizontalGrowDirection = "leftwards",
2474 Auras_Buffs_HorizontalSpacing = 1,
2475 Auras_Buffs_VerticalGrowdirection = "upwards",
2476 Auras_Buffs_VerticalSpacing = 1,
2477 Auras_Buffs_IconsPerRow = 8,
2478 Auras_Buffs_Container_Point = "BOTTOMRIGHT",
2479 Auras_Buffs_Container_RelativeTo = "Button",
2480 Auras_Buffs_Container_RelativePoint = "BOTTOMLEFT",
2481 Auras_Buffs_Container_OffsetX = 2,
2482 Auras_Buffs_Container_OffsetY = 0,
2483
2484 Auras_Buffs_Fontsize = 12,
2485 Auras_Buffs_Outline = "OUTLINE",
2486 Auras_Buffs_Textcolor = {1, 1, 1, 1},
2487 Auras_Buffs_EnableTextshadow = true,
2488 Auras_Buffs_TextShadowcolor = {0, 0, 0, 1},
2489
2490 Auras_Buffs_ShowNumbers = true,
2491
2492 Auras_Buffs_Cooldown_Fontsize = 12,
2493 Auras_Buffs_Cooldown_Outline = "OUTLINE",
2494 Auras_Buffs_Cooldown_EnableTextshadow = false,
2495 Auras_Buffs_Cooldown_TextShadowcolor = {0, 0, 0, 1},
2496
2497 Auras_Buffs_Filtering_Enabled = true,
2498 Auras_Buffs_OnlyShowMine = true,
2499 Auras_Buffs_SpellIDFiltering_Enabled = false,
2500 Auras_Buffs_SpellIDFiltering_Filterlist = {},
2501
2502 Auras_Debuffs_Enabled = true,
2503 Auras_Debuffs_Size = 15,
2504 Auras_Debuffs_HorizontalGrowDirection = "leftwards",
2505 Auras_Debuffs_HorizontalSpacing = 1,
2506 Auras_Debuffs_VerticalGrowdirection = "upwards",
2507 Auras_Debuffs_VerticalSpacing = 1,
2508 Auras_Debuffs_IconsPerRow = 8,
2509 Auras_Debuffs_Container_Point = "BOTTOMRIGHT",
2510 Auras_Debuffs_Container_RelativeTo = "BuffContainer",
2511 Auras_Debuffs_Container_RelativePoint = "BOTTOMLEFT",
2512 Auras_Debuffs_Container_OffsetX = 2,
2513 Auras_Debuffs_Container_OffsetY = 0,
2514
2515 Auras_Debuffs_Coloring_Enabled = true,
2516 Auras_Debuffs_DisplayType = "Frame",
2517 Auras_Debuffs_Fontsize = 12,
2518 Auras_Debuffs_Outline = "OUTLINE",
2519 Auras_Debuffs_Textcolor = {1, 1, 1, 1},
2520 Auras_Debuffs_EnableTextshadow = true,
2521 Auras_Debuffs_TextShadowcolor = {0, 0, 0, 1},
2522
2523 Auras_Debuffs_ShowNumbers = true,
2524
2525 Auras_Debuffs_Cooldown_Fontsize = 12,
2526 Auras_Debuffs_Cooldown_Outline = "OUTLINE",
2527 Auras_Debuffs_Cooldown_EnableTextshadow = false,
2528 Auras_Debuffs_Cooldown_TextShadowcolor = {0, 0, 0, 1},
2529
2530 Auras_Debuffs_Filtering_Enabled = true,
2531 Auras_Debuffs_OnlyShowMine = true,
2532 Auras_Debuffs_DebuffTypeFiltering_Enabled = true,
2533 Auras_Debuffs_DebuffTypeFiltering_Filterlist = {},
2534 Auras_Debuffs_SpellIDFiltering_Enabled = false,
2535 Auras_Debuffs_SpellIDFiltering_Filterlist = {},
2536
2537 Trinket_Enabled = true,
2538 Trinket_BasicPoint = "RIGHT",
2539 Trinket_RelativeTo = "Button",
2540 Trinket_RelativePoint = "LEFT",
2541 Trinket_OffsetX = 1,
2542 Trinket_Width = 28,
2543 Trinket_ShowNumbers = true,
2544
2545 Trinket_Cooldown_Fontsize = 12,
2546 Trinket_Cooldown_Outline = "OUTLINE",
2547 Trinket_Cooldown_EnableTextshadow = false,
2548 Trinket_Cooldown_TextShadowcolor = {0, 0, 0, 1},
2549
2550 Racial_Enabled = true,
2551 Racial_BasicPoint = "RIGHT",
2552 Racial_RelativeTo = "Trinket",
2553 Racial_RelativePoint = "LEFT",
2554 Racial_OffsetX = 1,
2555 Racial_Width = 28,
2556 Racial_ShowNumbers = true,
2557
2558 Racial_Cooldown_Fontsize = 12,
2559 Racial_Cooldown_Outline = "OUTLINE",
2560 Racial_Cooldown_EnableTextshadow = false,
2561 Racial_Cooldown_TextShadowcolor = {0, 0, 0, 1},
2562
2563 RacialFiltering_Enabled = false,
2564 RacialFiltering_Filterlist = {}, --key = spellID, value = spellName or false
2565 }
2566
2567 }
2568
2569 }
2570 }
2571 -- DefaultSettings.profile.Enemies = {[15] = DefaultSettings.profile, [40] = DefaultSettings.profile}
2572 -- DefaultSettings.profile.Allies = {[15] = DefaultSettings.profile, [40] = DefaultSettings.profile}
2573
2574 local function CreateMainFrame(playerType)
2575 local self = BattleGroundEnemies[playerType]
2576 self.Players = {} --index = name, value = button(table), contains enemyButtons
2577 self.PlayerSortingTable = {} --index = number, value = enemy name
2578 self.InactivePlayerButtons = {} --index = number, value = button(table)
2579 self.NewPlayerDetails = {} -- index = name, value = playerdetails, used for creation of new buttons, use (temporary) table to not create an unnecessary new button if another player left
2580 self.PlayerType = playerType
2581 self.NumPlayers = false
2582
2583 self.config = BattleGroundEnemies.db.profile[playerType]
2584
2585 for funcName, func in pairs(MainFrameFunctions) do
2586 self[funcName] = func
2587 end
2588
2589
2590 self:SetClampedToScreen(true)
2591 self:SetMovable(true)
2592 self:SetUserPlaced(true)
2593 self:SetResizable(true)
2594 self:SetToplevel(true)
2595
2596 self.PlayerCount = BattleGroundEnemies.MyCreateFontString(self)
2597 self.PlayerCount:SetAllPoints()
2598 self.PlayerCount:SetJustifyH("LEFT")
2599 end
2600
2601
2602 function BattleGroundEnemies:PLAYER_LOGIN()
2603 PlayerDetails.PlayerName = UnitName("player")
2604
2605 self.db = LibStub("AceDB-3.0"):New("BattleGroundEnemiesDB", DefaultSettings, true)
2606
2607 self.db.RegisterCallback(self, "OnProfileChanged", "ProfileChanged")
2608 self.db.RegisterCallback(self, "OnProfileCopied", "ProfileChanged")
2609 self.db.RegisterCallback(self, "OnProfileReset", "ProfileChanged")
2610
2611 CreateMainFrame("Allies")
2612 CreateMainFrame("Enemies")
2613
2614 self:SetupOptions()
2615
2616 --DBObjectLib:ResetProfile(noChildren, noCallbacks)
2617
2618
2619
2620 self:UnregisterEvent("PLAYER_LOGIN")
2621 end
2622end
2623
2624
2625function BattleGroundEnemies.Enemies:NAME_PLATE_UNIT_ADDED(unitID)
2626 local enemyButton = self:GetPlayerbuttonByUnitID(unitID)
2627 if enemyButton then
2628 enemyButton.UnitIDs.Nameplate = unitID
2629 enemyButton:FetchAnotherUnitID()
2630 end
2631end
2632
2633function BattleGroundEnemies.Enemies:NAME_PLATE_UNIT_REMOVED(unitID)
2634 --self:Debug(unitID)
2635 local enemyButton = self:GetPlayerbuttonByUnitID(unitID)
2636 if enemyButton then
2637 enemyButton.UnitIDs.Nameplate = false
2638 if enemyButton.UnitIDs.Active == unitID then enemyButton:FetchAnotherUnitID() end
2639 end
2640end
2641
2642function BattleGroundEnemies.Enemies:UNIT_HEALTH_FREQUENT(unitID) --gets health of nameplates, player, target, focus, raid1 to raid40, partymember
2643 local enemyButton = self:GetPlayerbuttonByUnitID(unitID)
2644 if enemyButton then --unit is a shown enemy
2645 enemyButton:UpdateHealth(unitID)
2646 end
2647end
2648
2649function BattleGroundEnemies.Enemies:UNIT_POWER_FREQUENT(unitID, powerToken) --gets power of nameplates, player, target, focus, raid1 to raid40, partymember
2650 local enemyButton = self:GetPlayerbuttonByUnitID(unitID)
2651 if enemyButton then --unit is a shown enemy
2652 enemyButton:UpdatePower(unitID, powerToken)
2653 end
2654end
2655
2656
2657
2658
2659--Notes about UnitIDs
2660--priority of unitIDs:
2661--1. Arena, detected by UNIT_HEALTH_FREQUENT (health upate), ARENA_OPPONENT_UPDATE (this units exist, don't exist anymore), we need to check for UnitExists() since there is a small time frame after the objective isn't on that target anymore where UnitExists returns false for that unitID
2662--2. nameplates, detected by UNIT_HEALTH_FREQUENT, NAME_PLATE_UNIT_ADDED, NAME_PLATE_UNIT_REMOVED
2663--3. player's target
2664--4. player's focus
2665--5. ally targets, UNIT_TARGET fires if the target changes, we need to check for UnitExists() since there is a small time frame after an ally lost that enemy where UnitExists returns false for that unitID
2666
2667
2668
2669function BattleGroundEnemies:ProfileChanged()
2670 self.Enemies:ApplyAllSettings()
2671 self.Allies:ApplyAllSettings()
2672end
2673
2674function BattleGroundEnemies:Debug(...)
2675 if self.db.profile.Debug then print("BGE:", ...) end
2676end
2677
2678do
2679 local TimeSinceLastOnUpdate = 0
2680 local UpdatePeroid = 2 --update every second
2681 function RequestTicker(self, elapsed) --OnUpdate runs if the frame RequestFrame is shown
2682 TimeSinceLastOnUpdate = TimeSinceLastOnUpdate + elapsed
2683 if TimeSinceLastOnUpdate > UpdatePeroid then
2684 RequestBattlefieldScoreData()
2685 TimeSinceLastOnUpdate = 0
2686 end
2687 end
2688 RequestFrame:SetScript("OnUpdate", RequestTicker)
2689end
2690
2691
2692--fires when a arena enemy appears and a frame is ready to be shown
2693function BattleGroundEnemies:ARENA_OPPONENT_UPDATE(unitID, unitEvent)
2694 --self:Debug("ARENA_OPPONENT_UPDATE", unitID, unitEvent, UnitName(unitID))
2695
2696 if unitEvent == "cleared" then --"unseen", "cleared" or "destroyed"
2697 local playerButton = self.ArenaEnemyIDToPlayerButton[unitID]
2698 if playerButton then
2699 --BattleGroundEnemies:Debug("ARENA_OPPONENT_UPDATE", playerButton.DisplayedName, "ObjectiveLost")
2700
2701 self.ArenaEnemyIDToPlayerButton[unitID] = nil
2702 playerButton.UnitIDs.Arena = false
2703 playerButton:UnregisterEvent("UNIT_AURA")
2704
2705 playerButton.ObjectiveAndRespawn:Reset()
2706
2707 if playerButton.PlayerIsEnemy then -- then this button is an ally button
2708 playerButton:FetchAnotherUnitID()
2709 end
2710 end
2711 else --seen, "unseen" or "destroyed"
2712 --self:Debug(UnitName(unitID))
2713 local playerButton = self:GetPlayerbuttonByUnitID(unitID)
2714 if playerButton then
2715 --self:Debug("Button exists")
2716 playerButton:ArenaOpponentShown(unitID)
2717 end
2718 end
2719end
2720
2721function BattleGroundEnemies:GetPlayerbuttonByUnitID(unitID)
2722 local uName, realm = UnitName(unitID)
2723 if realm then
2724 uName = uName.."-"..realm
2725 end
2726 return self.Enemies.Players[uName] or self.Allies.Players[uName]
2727end
2728
2729local CombatLogevents = {}
2730
2731function CombatLogevents.SPELL_AURA_APPLIED(self, srcName, destName, spellID, spellName, auraType)
2732 local playerButton = self.Enemies.Players[destName] or self.Allies.Players[destName]
2733 if playerButton then
2734 playerButton:AuraApplied(spellID, spellName, srcName, auraType)
2735 if Data.PvPTalentsReducingInterruptTime[spellName] then
2736 playerButton.Spec_AuraDisplay.HasAdditionalReducedInterruptTime = true
2737 end
2738 end
2739end
2740
2741function CombatLogevents.SPELL_AURA_APPLIED_DOSE(self, srcName, destName, spellID, spellName, auraType, amount)
2742 local playerButton = self.Enemies.Players[destName] or self.Allies.Players[destName]
2743 if playerButton then
2744 playerButton:AuraApplied(spellID, spellName, srcName, auraType, amount)
2745 end
2746end
2747
2748function CombatLogevents.SPELL_AURA_REFRESH(self, srcName, destName, spellID, spellName, auraType)
2749 local playerButton = self.Enemies.Players[destName] or self.Allies.Players[destName]
2750 if playerButton then
2751 playerButton:AuraRemoved(spellID, srcName)
2752 playerButton:AuraApplied(spellID, spellName, srcName, auraType)
2753 end
2754end
2755
2756function CombatLogevents.SPELL_AURA_REMOVED(self, srcName, destName, spellID, spellName, auraType)
2757 local playerButton = self.Enemies.Players[destName] or self.Allies.Players[destName]
2758 if playerButton then
2759 playerButton:AuraRemoved(spellID, srcName)
2760 if Data.PvPTalentsReducingInterruptTime[spellName] then
2761 playerButton.Spec_AuraDisplay.HasAdditionalReducedInterruptTime = false
2762 end
2763 end
2764end
2765
2766--CombatLogevents.SPELL_DISPEL = CombatLogevents.SPELL_AURA_REMOVED
2767
2768function CombatLogevents.SPELL_CAST_SUCCESS(self, srcName, destName, spellID)
2769
2770 local playerButton = self.Enemies.Players[srcName] or self.Allies.Players[srcName]
2771 if playerButton then
2772 if Data.RacialSpellIDtoCooldown[spellID] then --racial used, maybe?
2773 playerButton.Racial:RacialUsed(spellID)
2774 else
2775 playerButton.Trinket:TrinketCheck(spellID, true)
2776 end
2777 end
2778
2779 local playerButton = self.Enemies.Players[destName] or self.Allies.Players[destName]
2780 if playerButton then
2781 local defaultInterruptDuration = Data.Interruptdurations[spellID]
2782 if defaultInterruptDuration then -- check if enemy got interupted
2783 if playerButton.PlayerIsEnemy then
2784 local unitIDs = playerButton.UnitIDs
2785 local activeUnitID = unitIDs.Active
2786 if activeUnitID then
2787 if not unitIDs.CheckIfUnitExists or UnitExists(activeUnitID) then
2788 local _,_,_,_,_,_,_, notInterruptible = UnitChannelInfo(activeUnitID)
2789 if notInterruptible == false then --spell is interruptable
2790 playerButton.Spec_AuraDisplay:GotInterrupted(spellID, defaultInterruptDuration)
2791 end
2792 end
2793 end
2794 elseif playerButton.unit then -- its an ally, check if it has an unitID assigned
2795 local _,_,_,_,_,_,_, notInterruptible = UnitChannelInfo(playerButton.unit)
2796 if notInterruptible == false then --spell is interruptable
2797 playerButton.Spec_AuraDisplay:GotInterrupted(spellID, defaultInterruptDuration)
2798 end
2799 end
2800 end
2801 end
2802end
2803
2804function CombatLogevents.SPELL_INTERRUPT(self, _, destName, spellID, _, _)
2805 local playerButton = self.Enemies.Players[destName] or self.Allies.Players[destName]
2806 if playerButton then
2807 local defaultInterruptDuration = Data.Interruptdurations[spellID]
2808 if defaultInterruptDuration then
2809 playerButton.Spec_AuraDisplay:GotInterrupted(spellID, defaultInterruptDuration)
2810 end
2811 end
2812end
2813
2814function CombatLogevents.UNIT_DIED(self, _, destName, _, _, _)
2815 --self:Debug("subevent", destName, "UNIT_DIED")
2816 local playerButton = self.Enemies.Players[destName] or self.Allies.Players[destName]
2817 if playerButton then
2818 playerButton.ObjectiveAndRespawn:PlayerDied()
2819 end
2820end
2821
2822
2823function BattleGroundEnemies:COMBAT_LOG_EVENT_UNFILTERED(timestamp,subevent,hide,srcGUID,srcName,srcF1,srcF2,destGUID,destName,destF1,destF2,spellID,spellName,spellSchool, auraType)
2824 if CombatLogevents[subevent] then return CombatLogevents[subevent](self, srcName, destName, spellID, spellName, auraType) end
2825end
2826
2827
2828do
2829 local oldTarget
2830 function BattleGroundEnemies:PLAYER_TARGET_CHANGED()
2831 local playerButton = self:GetPlayerbuttonByUnitID("target")
2832
2833 if oldTarget then
2834 if oldTarget.PlayerIsEnemy then
2835 oldTarget.UnitIDs.TargetedByEnemy[PlayerButton] = nil
2836 oldTarget:UpdateTargetIndicators()
2837 oldTarget.UnitIDs.Target = false
2838 if oldTarget.UnitIDs.Active == "target" then oldTarget:FetchAnotherUnitID() end
2839 end
2840 oldTarget.MyTarget:Hide()
2841 end
2842
2843 if playerButton then --ally targets an existing enemy
2844 if playerButton.PlayerIsEnemy then
2845 playerButton.UnitIDs.TargetedByEnemy[PlayerButton] = true
2846 playerButton:UpdateTargetIndicators()
2847 playerButton.UnitIDs.Target = "target"
2848 playerButton:FetchAnotherUnitID()
2849 end
2850 playerButton.MyTarget:Show()
2851 oldTarget = playerButton
2852 else
2853 oldTarget = false
2854 end
2855 end
2856end
2857
2858do
2859 local oldFocus
2860 function BattleGroundEnemies:PLAYER_FOCUS_CHANGED()
2861 local playerButton = self:GetPlayerbuttonByUnitID("focus")
2862 if oldFocus then
2863 if oldFocus.PlayerIsEnemy then
2864 oldFocus.UnitIDs.Focus = false
2865 if oldFocus.UnitIDs.Active == "focus" then oldFocus:FetchAnotherUnitID() end
2866 end
2867 oldFocus.MyFocus:Hide()
2868 end
2869 if playerButton then
2870 if playerButton.PlayerIsEnemy then
2871 playerButton.UnitIDs.Focus = "focus"
2872 playerButton:FetchAnotherUnitID()
2873 end
2874 playerButton.MyFocus:Show()
2875 oldFocus = playerButton
2876 else
2877 oldFocus = false
2878 end
2879 end
2880end
2881
2882
2883function BattleGroundEnemies:UPDATE_MOUSEOVER_UNIT()
2884 local enemyButton = self.Enemies:GetPlayerbuttonByUnitID("mouseover")
2885 if enemyButton then --unit is a shown enemy
2886 enemyButton:UpdateAll("mouseover")
2887 end
2888end
2889
2890
2891
2892
2893-- function BattleGroundEnemies:LOSS_OF_CONTROL_ADDED()
2894 -- local numEvents = C_LossOfControl.GetNumEvents()
2895 -- for i = 1, numEvents do
2896 -- local locType, spellID, text, iconTexture, startTime, timeRemaining, duration, lockoutSchool, priority, displayType = C_LossOfControl.GetEventInfo(i)
2897 -- --self:Debug(C_LossOfControl.GetEventInfo(i))
2898 -- if not self.LOSS_OF_CONTROL then self.LOSS_OF_CONTROL = {} end
2899 -- self.LOSS_OF_CONTROL[spellID] = locType
2900 -- end
2901-- end
2902
2903
2904--fires when data requested by C_PvP.RequestCrowdControlSpell(unitID) is available
2905function BattleGroundEnemies:ARENA_CROWD_CONTROL_SPELL_UPDATE(unitID, spellID)
2906 local playerButton = self:GetPlayerbuttonByUnitID(unitID)
2907 if playerButton then
2908 playerButton.Trinket:TrinketCheck(spellID, false)
2909 end
2910 --if spellID ~= 72757 then --cogwheel (30 sec cooldown trigger by racial)
2911 --end
2912end
2913
2914--fires when a arenaX enemy used a trinket or racial to break cc, C_PvP.GetArenaCrowdControlInfo(unitID) shoudl be called afterwards to get used CCs
2915--this event is kinda stupid, it doesn't say which unit used which cooldown, it justs says that somebody used some sort of trinket
2916function BattleGroundEnemies:ARENA_COOLDOWNS_UPDATE()
2917 --if not self.db.profile.Trinket then return end
2918 for i = 1, 4 do
2919 local unitID = "arena"..i
2920 local playerButton = self:GetPlayerbuttonByUnitID(unitID)
2921 if playerButton then
2922 local spellID, startTime, duration = GetArenaCrowdControlInfo(unitID)
2923 if spellID then
2924 if (startTime ~= 0 and duration ~= 0) then
2925 playerButton.Trinket.Cooldown:SetCooldown(startTime/1000.0, duration/1000.0)
2926 else
2927 playerButton.Trinket.Cooldown:Clear()
2928 end
2929 end
2930 end
2931 end
2932end
2933
2934function BattleGroundEnemies:PlayerAlive()
2935 self:RegisterEvent("UPDATE_MOUSEOVER_UNIT")
2936 self:RegisterEvent("PLAYER_TARGET_CHANGED")
2937 self:RegisterEvent("PLAYER_FOCUS_CHANGED")
2938 self:RegisterEvent("UNIT_TARGET")
2939 --recheck the targets of groupmembers
2940 for allyName, allyButton in pairs(self.Allies.Players) do
2941 allyButton:UpdateTargets()
2942 end
2943 self.PlayerIsAlive = true
2944end
2945
2946function BattleGroundEnemies:PLAYER_ALIVE()
2947 if UnitIsGhost("player") then --Releases his ghost to a graveyard.
2948 self:UnregisterEvent("UPDATE_MOUSEOVER_UNIT")
2949 self:UnregisterEvent("PLAYER_TARGET_CHANGED")
2950 self:UnregisterEvent("PLAYER_FOCUS_CHANGED")
2951 self:UnregisterEvent("UNIT_TARGET")
2952 self.PlayerIsAlive = false
2953 else --alive (resed while not being a ghost)
2954 self:PlayerAlive()
2955 end
2956end
2957
2958function BattleGroundEnemies:UNIT_TARGET(unitID)
2959 --self:Debug("unitID:", unitID, "unit:", UnitName(unitID), "unittarget:", UnitName(unitID.."target"))
2960
2961 local playerButton = self:GetPlayerbuttonByUnitID(unitID)
2962 if playerButton and playerButton ~= PlayerButton then
2963 playerButton:UpdateTargets(unitID)
2964 end
2965end
2966
2967
2968BattleGroundEnemies.PLAYER_UNGHOST = BattleGroundEnemies.PlayerAlive --player is alive again
2969
2970
2971do
2972 local IsArena
2973
2974 do
2975 local RoleIcons = {
2976 HEALER = "Interface\\AddOns\\BattleGroundEnemies\\Images\\Healer",
2977 TANK = "Interface\\AddOns\\BattleGroundEnemies\\Images\\Tank",
2978 DAMAGER = "Interface\\AddOns\\BattleGroundEnemies\\Images\\Damager",
2979 }
2980
2981
2982 do
2983 local usersParent = {}
2984 local usersPetParent = {}
2985 local fakeParent
2986 local fakeFrame = CreateFrame("frame")
2987
2988 function BattleGroundEnemies:ToggleArenaFrames()
2989 if not self then self = BattleGroundEnemies end
2990
2991 if not InCombatLockdown() then
2992 --self:Debug("self.db.profile.DisableArenaFrames", self.db.profile.DisableArenaFrames)
2993 if self.db.profile.DisableArenaFrames then
2994 if CurrentMapID then
2995 if not fakeParent then
2996 for i = 1, 4 do
2997 local arenaFrame = _G["ArenaEnemyFrame"..i]
2998 usersParent[i] = arenaFrame:GetParent()
2999 arenaFrame:SetParent(fakeFrame)
3000 local arenaPetFrame = _G["ArenaEnemyFrame"..i.."PetFrame"]
3001 usersPetParent[i] = arenaPetFrame:GetParent()
3002 arenaPetFrame:SetParent(fakeFrame)
3003 end
3004 fakeParent = true
3005 fakeFrame:Hide()
3006 end
3007 elseif fakeParent then
3008 for i = 1, 4 do
3009 local arenaFrame = _G["ArenaEnemyFrame"..i]
3010 arenaFrame:SetParent(usersParent[i])
3011 local arenaPetFrame = _G["ArenaEnemyFrame"..i.."PetFrame"]
3012 arenaPetFrame:SetParent(usersPetParent[i])
3013 end
3014 fakeParent = false
3015 end
3016 elseif fakeParent then
3017 for i = 1, 4 do
3018 local arenaFrame = _G["ArenaEnemyFrame"..i]
3019 arenaFrame:SetParent(usersParent[i])
3020 local arenaPetFrame = _G["ArenaEnemyFrame"..i.."PetFrame"]
3021 arenaPetFrame:SetParent(usersPetParent[i])
3022 end
3023 fakeParent = false
3024 end
3025 else
3026 C_Timer.After(0.1, self.ToggleArenaFrames)
3027 end
3028 end
3029 end
3030
3031 local numArenaOpponents
3032
3033 local function ArenaEnemiesAtBeginn()
3034 if #BattleGroundEnemies.Enemies.PlayerSortingTable > 1 or #BattleGroundEnemies.Allies.PlayerSortingTable > 1 then --this ensures that we checked for enmys and the flag carrier will be shown (if its an enemy)
3035 for i = 1, numArenaOpponents do
3036 local unitID = "arena"..i
3037 --BattleGroundEnemies:Debug(UnitName(unitID))
3038 local playerButton = BattleGroundEnemies:GetPlayerbuttonByUnitID(unitID)
3039 if playerButton then
3040 --BattleGroundEnemies:Debug("Button exists")
3041 playerButton:ArenaOpponentShown(unitID)
3042 end
3043 end
3044 else
3045 C_Timer.After(2, ArenaEnemiesAtBeginn)
3046 end
3047 end
3048
3049 function BattleGroundEnemies:UPDATE_BATTLEFIELD_SCORE()
3050
3051 -- self:Debug(GetCurrentMapAreaID())
3052 -- self:Debug("UPDATE_BATTLEFIELD_SCORE")
3053 -- self:Debug("GetBattlefieldArenaFaction", GetBattlefieldArenaFaction())
3054 -- self:Debug("C_PvP.IsInBrawl", C_PvP.IsInBrawl())
3055 -- self:Debug("GetCurrentMapAreaID", GetCurrentMapAreaID())
3056 -- self:Debug("horde players:", GetBattlefieldTeamInfo(0))
3057 -- self:Debug("alliance players:", GetBattlefieldTeamInfo(1))
3058
3059
3060
3061 if not CurrentMapID then
3062 local wmf = WorldMapFrame
3063 if wmf and not wmf:IsShown() then
3064 SetMapToCurrentZone()
3065 local mapID = GetCurrentMapAreaID()
3066
3067 --self:Debug(mapID)
3068 if (mapID == -1 or mapID == 0) and not IsArena then --if this values occur GetCurrentMapAreaID() doesn't return valid values yet.
3069 return
3070 end
3071 CurrentMapID = mapID
3072 end
3073
3074 --self:Debug("test")
3075 if IsArena and not IsInBrawl() then
3076 self:Hide() --stopp the OnUpdateScript
3077 return
3078 end
3079
3080
3081 local MyBgFaction = GetBattlefieldArenaFaction() -- returns the playered faction 0 for horde, 1 for alliance
3082 --print("MyBgFaction:", MyBgFaction)
3083 if MyBgFaction == 0 then -- i am Horde
3084 self.EnemyFaction = 1 --Enemy is Alliance
3085 self.AllyFaction = 0
3086 else
3087 self.EnemyFaction = 0 --Enemy is Horde
3088 self.AllyFaction = 1
3089 end
3090
3091 if Data.BattlegroundspezificBuffs[CurrentMapID] then
3092 self.BattlegroundBuff = Data.BattlegroundspezificBuffs[CurrentMapID]
3093 end
3094
3095 BattleGroundEnemies.BattleGroundDebuffs = Data.BattlegroundspezificDebuffs[CurrentMapID]
3096
3097 --Check if we joined a match late and there are already arena unitids (flag-, orb-, or minecart-carriers) we wont get a ARENA_OPPONENT_UPDATE
3098 numArenaOpponents = GetNumArenaOpponents()-- returns valid data on PLAYER_ENTERING_WORLD
3099 --self:Debug(numArenaOpponents)
3100 if numArenaOpponents > 0 then
3101 C_Timer.After(2, ArenaEnemiesAtBeginn)
3102 end
3103
3104 BattleGroundEnemies:ToggleArenaFrames()
3105
3106 C_Timer.After(5, function() --Delay this check, since its happening sometimes that this data is not ready yet
3107 self.IsRatedBG = IsRatedBattleground()
3108 end)
3109
3110 --self:Debug("IsRatedBG", IsRatedBG)
3111 end
3112
3113
3114 local _, _, _, _, numEnemies = GetBattlefieldTeamInfo(self.EnemyFaction)
3115 local _, _, _, _, numAllies = GetBattlefieldTeamInfo(self.AllyFaction)
3116
3117 self:BGSizeCheck(numEnemies)
3118
3119 self.Enemies:UpdatePlayerCount(numEnemies)
3120 self.Allies:UpdatePlayerCount(numAllies)
3121
3122
3123
3124
3125 if InCombatLockdown() then return end
3126
3127
3128
3129
3130
3131
3132 wipe(self.Enemies.NewPlayerDetails) --use a local table to not create an unnecessary new button if another player left
3133 wipe(self.Allies.NewPlayerDetails) --use a local table to not create an unnecessary new button if another player left
3134 self.Enemies.resort = false
3135 self.Allies.resort = false
3136
3137 local numScores = GetNumBattlefieldScores()
3138 for i = 1, numScores do
3139 local name,_,_,_,_,faction,race, _, classTag,_,_,_,_,_,_,specName = GetBattlefieldScore(i)
3140 --name = name-realm, faction = 0 or 1, race = localized race e.g. "Mensch",classTag = e.g. "PALADIN", spec = localized specname e.g. "holy"
3141 --locale dependent are: race, specName
3142
3143 if faction and name and race and classTag and specName then
3144 --if name == PlayerDetails.PlayerName then EnemyFaction = EnemyFaction == 1 and 0 or 1 return end --support for the new brawl because GetBattlefieldArenaFaction() returns wrong data on that BG
3145 if name == PlayerDetails.PlayerName and faction == self.EnemyFaction then
3146 self.EnemyFaction = self.AllyFaction
3147 self.AllyFaction = faction
3148
3149 return
3150 end
3151
3152 self[faction == self.EnemyFaction and "Enemies" or "Allies"]:CreateOrUpdatePlayer(name, race, classTag, specName)
3153 end
3154 end
3155 self.Enemies:DeleteAndCreateNewPlayers()
3156 self.Allies:DeleteAndCreateNewPlayers()
3157
3158 end--functions end
3159 end-- do-end block end for locals of the function UPDATE_BATTLEFIELD_SCORE
3160
3161 function BattleGroundEnemies:PLAYER_ENTERING_WORLD()
3162 if self.TestmodeActive then --disable testmode
3163 self:DisableTestMode()
3164 end
3165
3166 CurrentMapID = false
3167
3168 local _, zone = IsInInstance()
3169 if zone == "pvp" or zone == "arena" then
3170 if zone == "arena" then
3171 IsArena = true
3172 end
3173 self:Show()
3174 -- self:Debug("PLAYER_ENTERING_WORLD")
3175 -- self:Debug("GetBattlefieldArenaFaction", GetBattlefieldArenaFaction())
3176 -- self:Debug("C_PvP.IsInBrawl", C_PvP.IsInBrawl())
3177 -- self:Debug("GetCurrentMapAreaID", GetCurrentMapAreaID())
3178
3179 self.PlayerIsAlive = true
3180 else
3181 self:ToggleArenaFrames()
3182 IsArena = false
3183 self:Hide()
3184 end
3185 end
3186end