Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local L = LibStub("AceLocale-3.0"):GetLocale("BattleGroundEnemys")
- if type(L) ~= "table" then print("|cdc1c1c7fBattleGroundEnemys:|r ERROR: Please restart WoW.") return end
- local DRData = LibStub("DRData-1.0")
- local LibRaces = LibStub("LibRaces-1.0")
- local DRstates = {
- [1] = {
- color = { 0, 1, 0, 1}, --green (next cc in DR time will be only half duration)
- diminishFaktor = 1
- },
- [2] = {
- color = { 1, 1, 0, 1}, --yellow (next cc in DR time will be only 1/4 duration)
- diminishFaktor = 0.5
- },
- [3] = {
- color = { 1, 0, 0, 1}, --red (next cc in DR time will not apply, player is immune)
- diminishFaktor = 0.25
- }
- }
- local _G = _G
- local CheckInteractDistance = CheckInteractDistance
- local DoRemainingStuffWhenOutOfCombat = {}
- local IsSpellKnown, GetSpellInfo, GetSpellTexture, IsRatedBattleground = IsSpellKnown, GetSpellInfo, GetSpellTexture, IsRatedBattleground
- local RequestBattlefieldScoreData = RequestBattlefieldScoreData
- local UnitGUID = UnitGUID
- local GetTime = GetTime
- local GetBattlefieldArenaFaction = GetBattlefieldArenaFaction
- local UnitHealth = UnitHealth
- local UnitHealthMax = UnitHealthMax
- local UnitInRange = UnitInRange
- --CompactRaidFrame informations:
- --UnitID to CompactRaidFrame: Frame CompactRaidFrameX = unitID raidX
- local BrawlCheck
- BattleGroundEnemys = CreateFrame("Frame", "BattleGroundEnemys", UIParent)
- BattleGroundEnemys.InactivePlayerButtons = {} --index = number, value = button(table)
- BattleGroundEnemys.Players = {} --index = name, value = button(table), contains buttons
- BattleGroundEnemys.PlayerSortingTable = {} --index = number, value = name
- BattleGroundEnemys.ActiveUnitIDs = {} -- index = unitID, value = index(used in Table BattleGroundEnemys.Players)
- local Classes = {}
- local Settings = {
- Debug = false,
- Test = false,
- ButtonSize = {
- Width = 190,
- Height = 28
- },
- Locked = false,
- MaxPlayers = 15,
- BG_MAPS = {},
- BlizzSort = {},
- DefaultScale = 1
- }
- local PlayerGUID
- local currentMapId
- local Aura_Types = {
- DEFAULT = 0,
- OBJECTIVE = 1
- }
- BattleGroundEnemys.PlayerButtonYPositions = {} --a list of possible button positions from index 1 = top to xxx == bottom
- for i = 1, Settings.MaxPlayers do
- BattleGroundEnemys.PlayerButtonYPositions[i] = (26 - ( i * (Settings.ButtonSize.Height + 1)))
- end
- BattleGroundEnemys.TrinketnumberToDisplayspellID = {--key = which first row honor talent, value = fileID(used for SetTexture())
- 195710, -- 1: Honorable Medallion, 3. min. CD, detected by Combatlog
- 208683, -- 2: Gladiator's Medallion, 2 min. CD, detected by Combatlog
- 214027, -- 3: Adaptation, 1 min. CD, detected by Aura 195901
- 196029 -- 4: Relentless
- }
- BattleGroundEnemys.spellIDToCooldown = {
- [42292] = 120, --Old pvp trinket use effect?
- [7744] = 30, -- Will of the Forsaken (Undead)
- [59752] = 30, -- human
- [20594] = 30, --dwarf
- [195710] = 180, -- Honorable Medallion, 3 min. CD
- [208683] = 120, -- Gladiator's Medallion, 2 min. CD
- [195901] = 60, -- Adaptation PvP Talent
- }
- BattleGroundEnemys.spellIDToTrinketnumber = {}
- BattleGroundEnemys.spellIDToTrinketFileId = {}
- BattleGroundEnemys.TrinketnumberToFileId = {}
- for i = 1, #BattleGroundEnemys.TrinketnumberToDisplayspellID do
- local spellID = BattleGroundEnemys.TrinketnumberToDisplayspellID[i]
- BattleGroundEnemys.spellIDToTrinketnumber[spellID] = i
- BattleGroundEnemys.spellIDToTrinketFileId[spellID] = GetSpellTexture(spellID)
- BattleGroundEnemys.TrinketnumberToFileId[i] = GetSpellTexture(spellID)
- end
- BattleGroundEnemys.defaults = {}
- local SpellidToSpellname = {
- [156618] = (GetSpellInfo(156618)), -- Horde Flag
- [156621] = (GetSpellInfo(156621)), -- Alliance Flag
- [34976] = (GetSpellInfo(34976)), -- Netherstorm Flag
- [141210] = (GetSpellInfo(141210)), -- Horde Mine Cart
- [140876] = (GetSpellInfo(140876)), -- Alliance Mine Cart
- [46392] = (GetSpellInfo(46392)), -- Focused Assault
- [46393] = (GetSpellInfo(46393)), -- Brutal Assault
- [121164] = (GetSpellInfo(121164)), -- Orb of Power, Blue
- [121175] = (GetSpellInfo(121175)), -- Orb of Power, Purple
- [121177] = (GetSpellInfo(121177)), -- Orb of Power, Orange
- [121176] = (GetSpellInfo(121176)) -- Orb of Power, Green
- }
- --Battleground specific stuff (flags, orbs, debuffs)
- -- BGS that don't have specific stuff like flags, orbs, carts. Basically everything without arenaframes
- --mapID[736] -- The Battle for Gilneas
- --mapID[860] -- Silvershard Mines
- --mapID[512] -- Strand of the Ancients
- --mapID[540] -- Isle of Conquest
- --mapID[461] -- Arathi Basin
- --mapID[401] -- Alterac Valley
- BattlegroundspezificBuffs = { --key = mapID, value = table with key = faction(0 for hode, 1 for alliance) value spellID of the flag, minecart
- [443] = { -- Warsong Gulch
- [0] = 156621, -- Alliance Flag
- [1] = 156618 -- Horde Flag
- },
- [482] = { -- Eye of the Storm
- [0] = 34976, -- Netherstorm Flag
- [1] = 34976 -- Netherstorm Flag
- },
- [626] = { -- Twin Peaks
- [0] = 156621, -- Alliance Flag
- [1] = 156618 -- Horde Flag
- },
- [935] = { -- Deepwind Gorge
- [0] = 140876, -- Alliance Mine Cart
- [1] = 141210 -- Horde Mine Cart
- }
- }
- BattlegroundspezificDebuffs = { --key = mapID, value = table with key = number and value = debuff name
- [443] = { -- Warsong Gulch
- SpellidToSpellname[46392], -- Focused Assault
- SpellidToSpellname[46393] -- Brutal Assault
- },
- [482] = { -- Eye of the Storm
- SpellidToSpellname[46392], -- Focused Assault
- SpellidToSpellname[46393] -- Brutal Assault
- },
- [626] = { -- Twin Peaks
- SpellidToSpellname[46392], -- Focused Assault
- SpellidToSpellname[46393] -- Brutal Assault
- },
- [935] = { -- Deepwind Gorge
- SpellidToSpellname[46392], -- Focused Assault
- SpellidToSpellname[46393] -- Brutal Assault
- },
- [856] = { -- Temple of Kotmogu
- SpellidToSpellname[121164], -- Orb of Power, Blue
- SpellidToSpellname[121175], -- Orb of Power, Purple
- SpellidToSpellname[121177], -- Orb of Power, Orange
- SpellidToSpellname[121176] -- Orb of Power, Green
- }
- }
- local BattlegroundBuff --contains the battleground specific enemy buff to watchout for of the current active battlefield
- local BattleGroundDebuffs = {} --contains battleground specific enemy debbuffs to watchout for of the current active battlefield
- local ArenaIDToPlayername = {}
- -- local Aura_Overrides = {
- -- -- orbs
- -- [121164] = "Interface/ICONS/inv_misc_enchantedpearlF", -- Blue Orb
- -- [121175] = "Interface/ICONS/inv_misc_enchantedpearlD", -- Purple Orb
- -- [121177] = "Interface/ICONS/inv_misc_enchantedpearlC", -- Orange Orb
- -- [121176] = "Interface/ICONS/inv_misc_enchantedpearlA" -- Green Orb
- -- }
- -- "Interface\\WorldStateFrame\\HordeFlag"
- -- "Interface\\WorldStateFrame\\AllianceFlag"
- -- "Interface\\Minimap\\Vehicle-SilvershardMines-MineCart" -- neutral_flag
- -- "Interface\\Minimap\\Vehicle-SilvershardMines-MineCartRed"
- -- "Interface\\Minimap\\Vehicle-SilvershardMines-MineCartBlue"
- local CCduration={
- --[[ INCAPACITATES ]]--
- incapacitate = {
- -- Druid
- [ 99] = 3, -- Incapacitating Roar (talent)
- [236025] = 6, -- Main (Honor talent)
- [236026] = 6, -- Main (Honor talent)
- -- Hunter
- [213691] = 4, -- Scatter Shot
- -- Mage
- [ 118] = 8, -- Polymorph
- [ 28272] = 8, -- Polymorph (pig)
- [ 28271] = 8, -- Polymorph (turtle)
- [ 61305] = 8, -- Polymorph (black cat)
- [ 61721] = 8, -- Polymorph (rabbit)
- [ 61780] = 8, -- Polymorph (turkey)
- [126819] = 8, -- Polymorph (procupine)
- [161353] = 8, -- Polymorph (bear cub)
- [161354] = 8, -- Polymorph (monkey)
- [161355] = 8, -- Polymorph (penguin)
- [161372] = 8, -- Polymorph (peacock)
- [ 82691] = 8, -- Ring of Frost
- -- Monk
- [115078] = 4, -- Paralysis
- -- Paladin
- [ 20066] = 8, -- Repentance
- -- Priest
- [ 64044] = 4, -- Psychic Horror (Horror effect)
- -- Rogue
- [ 1776] = 4, -- Gouge
- [ 6770] = 8, -- Sap
- -- Shaman
- [ 51514] = 8, -- Hex
- [211004] = 8, -- Hex (spider)
- [210873] = 8, -- Hex (raptor)
- [211015] = 8, -- Hex (cockroach)
- [211010] = 8, -- Hex (snake)
- -- Warlock
- [ 6789] = 3, -- Mortal Coil
- -- Pandaren
- [107079] = 4 -- Quaking Palm
- },
- --[[ SILENCES ]]--
- silence = {
- -- Death Knight
- [ 47476] = 5, -- Strangulate
- -- Hunter
- [202933] = 4, -- Spider Sting (pvp talent)
- -- Mage
- -- Paladin
- [ 31935] = 3, -- Avenger's Shield
- -- Priest
- [ 15487] = 5, -- Silence
- -- Rogue
- [ 1330] = 3, -- Garrote
- -- Blood Elf
- [ 25046] = 2, -- Arcane Torrent (Energy version)
- [ 28730] = 2, -- Arcane Torrent (Priest/Mage/Lock version)
- [ 50613] = 2, -- Arcane Torrent (Runic power version)
- [ 69179] = 2, -- Arcane Torrent (Rage version)
- [ 80483] = 2, -- Arcane Torrent (Focus version)
- [129597] = 2, -- Arcane Torrent (Monk version)
- [155145] = 2, -- Arcane Torrent (Paladin version)
- [202719] = 2 -- Arcane Torrent (DH version)
- },
- --[[ DISORIENTS ]]--
- disorient = {
- -- Druid
- [ 33786] = 6, -- Cyclone
- [209753] = 6, -- Cyclone (Balance)
- -- Hunter
- [186387] = 4, -- Bursting Shot
- -- Mage
- [ 31661] = 3, -- Dragon's Breath
- -- Paladin
- [105421] = 6, -- Blinding Light -- FIXME: is this the right category? Its missing from blizzard's list
- -- Priest
- --[ 8122] = 6, -- Psychic Scream
- -- Rogue
- [ 2094] = 8, -- Blind
- -- Warlock
- [ 5782] = 6 -- Fear -- probably unused
- },
- --[[ STUNS ]]--
- stun = {
- -- Death Knight
- [108194] = 5, -- Asphyxiate (talent for unholy)
- [221562] = 5, -- Asphyxiate (baseline for blood)
- [207171] = 4, -- Winter is Coming (Remorseless winter stun)
- -- Demon Hunter
- [179057] = 5, -- Chaos Nova
- [200166] = 3, -- Metamorphosis
- [205630] = 6, -- Illidan's Grasp, primary effect
- [211881] = 2, -- Fel Eruption
- -- Druid
- [ 5211] = 5, -- Mighty Bash
- -- Monk
- [120086] = 4, -- Fists of Fury (with Heavy-Handed Strikes, pvp talent)
- [232055] = 3, -- Fists of Fury (new ID in 7.1)
- [119381] = 5, -- Leg Sweep
- -- Paladin
- [ 853] = 6, -- Hammer of Justice
- -- Priest
- [200200] = 5, -- Holy word: Chastise
- -- Rogue
- [ 1833] = 4, -- Cheap Shot
- -- Shaman
- [118345] = 4, -- Pulverize (Primal Earth Elemental)
- [118905] = 5, -- Static Charge (Capacitor Totem)
- [204399] = 2, -- Earthfury (pvp talent)
- -- Warlock
- [ 89766] = 4, -- Axe Toss (Felguard)
- [ 30283] = 4, -- Shadowfury
- -- Warrior
- [132168] = 3, -- Shockwave
- [132169] = 4, -- Storm Bolt
- -- Tauren
- [ 20549] = 2 -- War Stomp
- },
- --[[ ROOTS ]]--
- root = {
- -- Death Knight
- [ 96294] = 4, -- Chains of Ice (Chilblains Root)
- [204085] = 4, -- Deathchill (pvp talent)
- -- Druid
- [ 339] = 8, -- Entangling Roots
- [102359] = 8, -- Mass Entanglement (talent)
- [ 45334] = 4, -- Immobilized (wild charge, bear form)
- -- Hunter
- [200108] = 3, -- Ranger's Net
- [212638] = 6, -- tracker's net
- [201158] = 4, -- Super Sticky Tar (Expert Trapper, Hunter talent, Tar Trap effect)
- -- Mage
- [ 122] = 8, -- Frost Nova
- [ 33395] = 8, -- Freeze (Water Elemental)
- [228600] = 4, -- Glacial spike (talent)
- -- Shaman
- [ 64695] = 8 -- Earthgrab Totem
- }
- }
- BattleGroundEnemys.Interruptdurations = {
- [6552] = 4, -- [Warrior] Pummel
- [96231] = 4, -- [Paladin] Rebuke
- [231665] = 3, -- [Paladin] Avengers Shield
- [147362] = 3, -- [Hunter] Countershot
- [187707] = 3, -- [Hunter] Muzzle
- [1766] = 5, -- [Rogue] Kick
- [183752] = 3, -- [DH] Consume Magic
- [47528] = 3, -- [DK] Mind Freeze
- [91802] = 2, -- [DK] Shambling Rush
- [57994] = 3, -- [Shaman] Wind Shear
- [115781] = 6, -- [Warlock] Optical Blast
- [19647] = 6, -- [Warlock] Spell Lock
- [212619] = 6, -- [Warlock] Call Felhunter
- [132409] = 6, -- [Warlock] Spell Lock
- [171138] = 6, -- [Warlock] Shadow Lock
- [2139] = 6, -- [Mage] Counterspell
- [116705] = 4, -- [Monk] Spear Hand Strike
- [106839] = 4, -- [Feral] Skull Bash
- [93985] = 4, -- [Feral] Skull Bash
- }
- local Special_Auras = {
- DEAD = 8326
- }
- local Range_Spells = {
- DEATHKNIGHT = 49576, -- Death Grip
- DRUID = 339, -- Entangling Roots
- HUNTER = 75, -- Auto Shot
- MAGE = 2139, -- Counterspell
- MONK = 117952, -- Crackling Jade L
- PALADIN = 20271, -- Judgment
- PRIEST = 585, -- Smite
- ROGUE = 6770, -- Sap
- SHAMAN = 403, -- Lightning Bolt
- WARLOCK = 689, -- Drain Life
- WARRIOR = 100, -- Charge
- DEMONHUNTER = 162794 -- CHaos Strike
- }
- local RangeCheckSpell
- local SpellRange
- for i = 1, #CLASS_SORT_ORDER do -- Constants.lua
- Settings.BlizzSort[ CLASS_SORT_ORDER[i] ] = i --key = name, value = number
- end
- for classId = 1, MAX_CLASSES do --example classes[EnglishClass][SpecName].
- local _, classTag = GetClassInfoByID(classId)
- local numSpec = GetNumSpecializationsForClassID(classId)
- Classes[classTag] = {}
- for i = 1, numSpec do
- local id,name,_,icon,role = GetSpecializationInfoForClassID(classId, i)
- if role == "DAMAGER" then
- Classes[classTag][name] = {role = 3}
- elseif role == "HEALER" then
- Classes[classTag][name] = {role = 1}
- elseif role == "TANK"
- then Classes[classTag][name] = {role = 2}
- end
- Classes[classTag][name].icon = icon
- end
- end
- local function Print(...) print("|cffffff7fBattleGroundEnemys:|r", ...) end
- local function Debug(...)
- if Settings.Debug then
- print("|cffffff7fXentiDebug:|r", ...)
- end
- end
- if L then
- --Print(L["MESSAGES_WELCOME1"]) useless message
- --Print(L["MESSAGES_WELCOME2"])
- end
- function BattleGroundEnemys:OnAddonLoaded()
- self.dbi = LibStub("AceDB-3.0"):New("BattleGroundEnemysDB", self.defaults)
- self.dbi.RegisterCallback(self, "OnProfileChanged", "UpdateFrame")
- self.dbi.RegisterCallback(self, "OnProfileCopied", "UpdateFrame")
- self.dbi.RegisterCallback(self, "OnProfileReset", "UpdateFrame")
- self.LSM = LibStub("LibSharedMedia-3.0")
- self.LSM:Register("font", "Arialn", "Fonts/ARIALN.TTF")
- --button.Name:SetFont("Fonts/ARIALN.TTF", 12, "")
- self.db = setmetatable(self.dbi.profile, {
- __newindex = function(t, index, value)
- if type(value) == "table" then
- rawset(self.defaults.profile, index, value)
- end
- rawset(t, index, value)
- end})
- end
- function BattleGroundEnemys:UpdateFrame()
- self.db = self.dbi.profile
- if BattleGroundEnemys:GetScale() ~= self.db.frameScale then
- BattleGroundEnemys:SetScale(self.db.frameScale)
- end
- -- doing button width check here! :)
- for i = 1, Settings.MaxPlayers do
- -- Debug("Create Button ", i)
- if BattleGroundEnemys.PlayerButtons[i] then
- local width, height = BattleGroundEnemys.PlayerButtons[i]:GetSize()
- if width ~= self.db.barWidth then
- BattleGroundEnemys.PlayerButtons[i]:SetSize(self.db.barWidth, height)
- end
- BattleGroundEnemys.PlayerButtons[i].Name:SetFont(self.LSM:Fetch(self.LSM.MediaType.FONT, self.db.globalFont), (self.db.useGlobalFontSize and self.db.globalFontSize or 12))
- end
- end
- end
- -- Updates the TargetedBy tables.
- function BattleGroundEnemys:UnitTargetChanged(unitID)
- local uName, realm = UnitName(unitID.."target")
- if realm then
- uName = uName.."-"..realm
- end
- for name, playerButton in pairs(self.Players) do
- if name == uName then
- playerButton.PlayerDetails.TargetedBy[unitID] = true --unit targets this enemy now
- self:UpdateTargetIndicators(playerButton)
- elseif playerButton.PlayerDetails.TargetedBy[unitID] then --this player targeted previously this enemy
- playerButton.PlayerDetails.TargetedBy[unitID] = nil --unit no longer targets this enemy
- self:UpdateTargetIndicators(playerButton)
- end
- end
- end
- -- Shows/Hides targeting indicators for a button
- function BattleGroundEnemys:UpdateTargetIndicators(playerButton)
- local i = 1
- for unitID in pairs(playerButton.PlayerDetails.TargetedBy) do
- local indicator = playerButton.TargetIndicators[i]
- if not indicator then
- indicator = CreateFrame("frame",nil,playerButton.Health)
- playerButton.TargetIndicators[i] = indicator
- indicator:SetSize(8,10)
- 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
- indicator:SetBackdrop({
- bgFile = "Interface/Buttons/WHITE8X8",
- edgeFile = "Interface/Buttons/WHITE8X8",
- edgeSize = 1,
- })
- indicator:SetBackdropBorderColor(0,0,0,1)
- end
- local className,class = UnitClass(unitID)
- local c = RAID_CLASS_COLORS[class or "PRIEST"]
- indicator:SetBackdropColor(c.r,c.g,c.b)
- indicator:Show()
- i = i+1
- end
- while playerButton.TargetIndicators[i] do --hide no longer used ones
- playerButton.TargetIndicators[i]:Hide()
- i = i+1
- end
- end
- function BattleGroundEnemys:Initialize()
- local _, playerClass = UnitClass("player")
- local spellID = Range_Spells[playerClass]
- if spellID then
- if IsSpellKnown(spellID) then
- local name, rank, fileId, castTime, minRange, maxRange, spellId = GetSpellInfo(spellID)
- RangeCheckSpell = spellName
- SpellRange = maxRange
- end
- end
- Debug("RangeCheckSpell ", RangeCheckSpell)
- end
- function BattleGroundEnemys:CreateFrame()
- -- BattleGroundEnemys.Main = BattleGroundEnemys
- BattleGroundEnemys:SetSize(200, 200)
- BattleGroundEnemys:SetClampedToScreen(true)
- BattleGroundEnemys:SetMovable(true)
- BattleGroundEnemys:SetUserPlaced(true)
- BattleGroundEnemys:SetResizable(true)
- BattleGroundEnemys:SetToplevel(true)
- BattleGroundEnemys:SetScale(self.db.frameScale)
- --BattleGroundEnemys:SetScript("OnHide", function()print("BattleGroundEnemys OnHide")end)
- _G["BattleGroundEnemys"]:ClearAllPoints()
- if not self.db.x and not self.db.y then
- _G["BattleGroundEnemys"]:SetPoint("CENTER")
- else
- local scale = _G["BattleGroundEnemys"]:GetEffectiveScale()
- _G["BattleGroundEnemys"]:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", self.db.x / scale, self.db.y / scale)
- end
- end
- --DR Handling
- function BattleGroundEnemys:RelentlessCheck(playerButton, drCat, spellID)
- if not CCduration[drCat] then
- return
- end
- local normalDuration = CCduration[drCat][spellID]
- if not normalDuration then
- return
- end
- if playerButton.PlayerDetails.Insi then
- return
- end
- if not playerButton.PlayerDetails.UnitID then
- return
- end
- local spellName = GetSpellInfo(spellID)
- local _,_,_,_,_,actuallDuration = UnitDebuff(playerButton.PlayerDetails.UnitID, spellName)
- if not actuallDuration then
- return
- end
- local Racefaktor = 1
- if drCat == "stun" and playerButton.PlayerDetails.Race == "Orc" then
- Racefaktor = 0.8 --Hardiness
- end
- --local diminish = actualduraion/(Racefaktor * normalDuration * Trinketfaktor)
- --local trinketFaktor * diminish = actuallDuration/(Racefaktor * normalDuration)
- --trinketTimesDiminish = trinketFaktor * diminish
- --trinketTimesDiminish = without relentless : 1, 0.5, 0,25, with relentless: 0.8, 0.4, 0.2
- local trinketTimesDiminish = (actuallDuration/(Racefaktor * normalDuration))
- if trinketTimesDiminish == 0.8 or trinketTimesDiminish == 0.4 or trinketTimesDiminish == 0.2 then --Relentless
- playerButton.PlayerDetails.Insi = 4
- playerButton.Insi.Icon:SetTexture(self.TrinketnumberToFileId[4])
- end
- end
- function BattleGroundEnemys:UpdateDR(playerButton, spellID, operation)
- local drCat = DRData:GetSpellCategory(spellID)
- --print(operation, spellID)
- if not drCat then return end
- local playerButtonPlayerDetailsDRTracking = playerButton.PlayerDetails.DRTracking
- if not playerButtonPlayerDetailsDRTracking[drCat] then
- playerButtonPlayerDetailsDRTracking[drCat] = {}
- end
- local playerButtonPlayerDetailsDRTrackingDRCat = playerButtonPlayerDetailsDRTracking[drCat]
- if not playerButtonPlayerDetailsDRTrackingDRCat.status then
- playerButtonPlayerDetailsDRTrackingDRCat.status = 0
- end
- if operation == "applied" then
- playerButtonPlayerDetailsDRTrackingDRCat.status = playerButtonPlayerDetailsDRTrackingDRCat.status + 1
- if playerButtonPlayerDetailsDRTrackingDRCat.status == 4 then
- playerButtonPlayerDetailsDRTrackingDRCat.status = 3
- end
- self:RelentlessCheck(playerButton, drCat, spellID)
- elseif operation == "refresh" then --if a DR Debuff refreshs the new Debuff is atleast half duration, maybe even 0.25
- if playerButtonPlayerDetailsDRTrackingDRCat.status == 0 then
- playerButtonPlayerDetailsDRTrackingDRCat.status = 1
- end
- playerButtonPlayerDetailsDRTrackingDRCat.status = playerButtonPlayerDetailsDRTrackingDRCat.status + 1
- if playerButtonPlayerDetailsDRTrackingDRCat.status == 4 then
- playerButtonPlayerDetailsDRTrackingDRCat.status = 3
- end
- local fileID = GetSpellTexture(spellID)
- --print(name, playerButtonPlayerDetailsDRTrackingDRCat.status)
- playerButton.DR[drCat].Icon:SetTexture(fileID)
- playerButton.DR[drCat]:SetBackdropBorderColor(unpack(DRstates[playerButtonPlayerDetailsDRTrackingDRCat.status].color))
- playerButton.DR[drCat].Cooldown:SetCooldown(GetTime(), DRData:GetResetTime(drCat))
- playerButton.DR[drCat].Cooldown:SetHideCountdownNumbers(false)
- self:RelentlessCheck(playerButton, drCat, spellID)
- else --operation == "removed"
- if playerButtonPlayerDetailsDRTrackingDRCat.status == 0 then --it happens that we don't get the applied or refresh event, probably because of range. Set the status to 1 in this case
- playerButtonPlayerDetailsDRTrackingDRCat.status = 1
- end
- local fileID = GetSpellTexture(spellID)
- --print(name, playerButtonPlayerDetailsDRTrackingDRCat.status)
- playerButton.DR[drCat].Icon:SetTexture(fileID)
- playerButton.DR[drCat]:SetBackdropBorderColor(unpack(DRstates[playerButtonPlayerDetailsDRTrackingDRCat.status].color))
- playerButton.DR[drCat].Cooldown:SetCooldown(GetTime(), DRData:GetResetTime(drCat))
- playerButton.DR[drCat].Cooldown:SetHideCountdownNumbers(false)
- end
- end
- function BattleGroundEnemys:LeftSidePositioning(playerButton)
- local active = 0
- for categorie, v in pairs(DRData:GetCategories()) do
- if ( playerButton.DR[categorie]:GetAlpha() == 1 ) then
- playerButton.DR[categorie]:ClearAllPoints()
- local ystart = -4
- if playerButton.Objective.Icon:GetTexture() then
- ystart = -44
- end
- if ( active == 0 ) then
- playerButton.DR[categorie]:SetPoint("RIGHT", playerButton.Spec, "LEFT", ystart, 0)
- else
- playerButton.DR[categorie]:SetPoint("RIGHT", playerButton.Spec, "LEFT", ystart - (active * (Settings.ButtonSize.Height + 2)), 0)
- end
- active = active + 1
- end
- end
- end
- function BattleGroundEnemys:COMBAT_LOG_EVENT_UNFILTERED(timestamp,subevent,hide,srcGUID,srcName,srcF1,srcF2,destGUID,destName,destF1,destF2,spellID,spellName,spellSchool,...)
- if subevent == "SPELL_CAST_SUCCESS" then
- if not self.spellIDToTrinketnumber[spellID] or not self.Players[srcName] then
- return
- end
- local playerButton = self.Players[srcName]
- if self.spellIDToTrinketnumber[spellID] then
- playerButton.PlayerDetails.Insi = self.spellIDToTrinketnumber[spellID]
- playerButton.Insi.Icon:SetTexture(self.spellIDToTrinketFileId[spellID])
- -- TODO RACIALS, MAYBE?
- playerButton.Insi.Cooldown:SetCooldown(GetTime(), self.spellIDToCooldown[spellID])
- playerButton.Insi.Cooldown:SetHideCountdownNumbers(false)
- end
- elseif subevent == "SPELL_INTERRUPT" then
- local extraspellID = ...
- local playerButton = self.Players[destName]
- if playerButton and self.Interruptdurations[extraspellID] then
- local fileID = GetSpellTexture(extraspellID)
- playerButton.Spec.Icon:SetTexture(fileID)
- playerButton.Spec.Cooldown:SetCooldown(GetTime(), self.Interruptdurations[extraspellID])
- playerButton.Insi.Cooldown:SetHideCountdownNumbers(false)
- self:InterruptGained(playerButton, extraspellID)
- end
- elseif subevent == "SPELL_AURA_APPLIED" then
- local auraType = ...
- local playerButton = self.Players[destName]
- if playerButton then
- if spellID == 195901 then --adaptation
- playerButton.PlayerDetails.Insi = 3
- playerButton.Insi.Icon:SetTexture(BattleGroundEnemys.TrinketnumberToFileId[3])
- playerButton.Insi.Cooldown:SetCooldown(GetTime(), 60)
- elseif auraType == "DEBUFF" then
- self:UpdateDR(playerButton, spellID, "applied")
- end
- end
- elseif subevent == "SPELL_AURA_REFRESH" then
- local auraType = ...
- local playerButton = self.Players[destName]
- if playerButton then
- if auraType == "DEBUFF" then
- self:UpdateDR(playerButton, spellID, "refresh")
- end
- end
- elseif subevent == "SPELL_AURA_REMOVED" then
- local auraType = ...
- local playerButton = self.Players[destName]
- if playerButton then
- if auraType == "DEBUFF" then
- self:UpdateDR(playerButton, spellID, "removed")
- end
- end
- elseif subevent == "UNIT_DIED" then
- local playerButton = self.Players[destName]
- if playerButton then
- self:ShowRespawnTimer(playerButton, 27)
- end
- end
- end
- function BattleGroundEnemys:SavePosition()
- if not InCombatLockdown() then
- local f = _G["BattleGroundEnemys"]
- f:StopMovingOrSizing()
- local scale = f:GetEffectiveScale()
- self.db.x= f:GetLeft() * scale
- self.db.y = f:GetTop() * scale
- end
- end
- function BattleGroundEnemys:ShowRespawnTimer(playerButton,duration)
- if not IsRatedBattleground() then
- return
- end
- playerButton.Respawn.Cooldown:SetCooldown(GetTime(), duration)
- playerButton.Respawn.Cooldown:SetHideCountdownNumbers(false)
- playerButton.Respawn:Show()
- end
- function BattleGroundEnemys:CreateNewPlayerButton()
- local button = CreateFrame('Button', nil, BattleGroundEnemys, 'SecureActionButtonTemplate')
- button:SetSize(self.db.barWidth, Settings.ButtonSize.Height)
- button:SetBackdrop({
- bgFile = "Interface/Buttons/WHITE8X8",
- edgeFile = 'Interface/Buttons/WHITE8X8',
- edgeSize = 1,
- })
- button:SetBackdropBorderColor(0, 0, 0, 1)
- button:SetBackdropColor(0,0,0,.28)
- -- events/scripts
- button:RegisterForClicks('AnyUp')
- button:RegisterForDrag('LeftButton')
- button:SetAttribute('type1','macro')
- button:SetAttribute('type2','macro')
- button:SetScript('OnDragStart', function() return BattleGroundEnemys.db.locked or BattleGroundEnemys:StartMoving() end)
- button:SetScript('OnDragStop', function() BattleGroundEnemys:StopMovingOrSizing() BattleGroundEnemys:SavePosition() end)
- button:SetScript('OnEvent', function(self, event, unitID) --for unit event UNIT_AURA
- --print("hallo")
- BattleGroundEnemys:UpdateBattlegroundSpecifics(button, unitID)
- end)
- -- health
- button.Health = CreateFrame('StatusBar', nil, button)
- button.Health:SetPoint('TOPLEFT', 1, -1)
- button.Health:SetPoint('BOTTOMRIGHT', -1, 1)
- button.Health:SetStatusBarTexture('Interface\\TargetingFrame\\UI-StatusBar')--button.Health:SetStatusBarTexture(137012)
- button.Health:SetMinMaxValues(0, 1)
- -- name
- button.Name = button.Health:CreateFontString()
- button.Name:SetPoint('TOPLEFT', 5, 0)
- button.Name:SetPoint('BOTTOMRIGHT')
- button.Name:SetFont(self.LSM:Fetch(self.LSM.MediaType.FONT, self.db.globalFont), (self.db.useGlobalFontSize and self.db.globalFontSize or 12))
- button.Name:SetJustifyH('LEFT')
- button.Name:SetTextColor(1, 1, 1)
- button.Name:SetShadowColor(0, 0, 0, 1)
- button.Name:SetShadowOffset(1, -1)
- button.Name:SetDrawLayer('ARTWORK', 2)
- -- extended info (e.g. orb debuff)
- button.SetInfo = function(info) button.Info:SetText(info) end
- button.Info = button.Health:CreateFontString()
- -- spec
- button.Spec = CreateFrame('Frame', nil, button)
- button.Spec:SetPoint('RIGHT', button, 'LEFT',-1,0);
- button.Spec:SetSize(36,26);
- button.Spec.Icon = button.Spec:CreateTexture('ARTWORK',2)
- button.Spec.Icon:SetPoint('CENTER', button.Spec, 'CENTER',0,0);
- button.Spec.Icon:SetSize(36,26);
- button.Spec.Icon:SetTexCoord( 4/64, (4+56)/64, 12/64, (12+40)/64 );
- button.Spec.Cooldown = CreateFrame("Cooldown", nil, button.Spec)
- button.Spec.Cooldown:SetAllPoints()
- button.Spec.Cooldown:SetSwipeTexture('Interface/Buttons/WHITE8X8')
- button.Spec.Cooldown:SetSwipeColor(0, 0, 0, 0.75)
- -- button.Spec.Cooldown:SetScript("OnHide", function(self)
- -- button.DR[categorie]:SetAlpha(0)
- -- button.Spec.Icon:SetTexture(button.PlayerDetails.Icon)
- -- end)
- -- Diminishing Returns
- button.DR = {}
- for categorie, v in pairs(DRData:GetCategories()) do
- button.DR[categorie] = CreateFrame("Frame", nil, button)
- button.DR[categorie]:SetSize(Settings.ButtonSize.Height, Settings.ButtonSize.Height)
- button.DR[categorie]:SetAlpha(0)
- button.DR[categorie]:SetBackdrop({
- bgFile = "Interface/Buttons/WHITE8X8",
- edgeFile = 'Interface/Buttons/WHITE8X8',
- edgeSize = 1,
- })
- button.DR[categorie]:SetBackdropColor(0,0,0,0)
- button.DR[categorie].Icon = button.DR[categorie]:CreateTexture(nil, "BACKGROUND")
- --button.DR[categorie].Icon:SetTexture('Interface/Icons/Spell_Nature_Polymorph')
- button.DR[categorie].Icon:SetAllPoints()
- -- button.DR[categorie].Border = button.DR[categorie]:CreateTexture(nil, "ARTWORK")
- -- button.DR[categorie].Border:SetTexture('Interface/BUTTONS/UI-Quickslot-Depress')
- -- button.DR[categorie].Border:SetAllPoints()
- button.DR[categorie].Cooldown = CreateFrame("Cooldown", nil, button.DR[categorie])
- button.DR[categorie].Cooldown:ClearAllPoints()
- button.DR[categorie].Cooldown:SetPoint("TOPLEFT", 1, -1)
- button.DR[categorie].Cooldown:SetPoint("BOTTOMRIGHT", -1, 1)
- button.DR[categorie].Cooldown:SetDrawBling(false)
- button.DR[categorie].Cooldown:SetSwipeColor(0,0,0,0.5)
- -- for _, region in next, {button.DR[categorie].Cooldown:GetRegions()} do
- -- if ( region:GetObjectType() == "FontString" ) then
- -- region:SetFont("Fonts\\FRIZQT__.TTF", , "OUTLINE")
- -- end
- -- end
- button.DR[categorie].Cooldown:SetScript("OnShow", function(self)
- button.DR[categorie]:SetAlpha(1)
- BattleGroundEnemys:LeftSidePositioning(button)
- end)
- button.DR[categorie].Cooldown:SetScript("OnHide", function(self)
- button.DR[categorie]:SetAlpha(0)
- BattleGroundEnemys:LeftSidePositioning(button)
- if button.PlayerDetails.DRTracking[categorie] then
- button.PlayerDetails.DRTracking[categorie].status = 0
- end
- end)
- end
- -- objective
- button.Objective = CreateFrame('Frame', nil, button)
- button.Objective:SetPoint('RIGHT', button, 'LEFT',-40,0);
- button.Objective:SetSize(36,26);
- button.Objective.Icon = button.Objective:CreateTexture(nil, "BORDER")
- button.Objective.Icon:SetAllPoints()
- button.Objective.Icon:SetTexCoord( 4/64, 59/64, 12/64, 52/64 );
- button.Objective.AuraText = button.Objective:CreateFontString(nil, "OVERLAY", "GameFontNormal")
- button.Objective.AuraText:SetWidth(50)
- button.Objective.AuraText:SetPoint("CENTER", button.Objective.Icon, "CENTER", 0, 0)
- button.Objective.AuraText:SetJustifyH("CENTER")
- button.Objective.AuraText:SetShadowOffset(0, 0)
- button.Objective.AuraText:SetShadowColor(0, 0, 0, 0)
- button.Objective.AuraText:SetTextColor(1, 1, 1, 1)
- button.Objective.AuraText:SetFont('Fonts/ARIALN.TTF', 16, 'THINOUTLINE')
- -- trinket
- button.Insi = CreateFrame('Frame', nil, button)
- button.Insi:SetPoint('LEFT', button, 'RIGHT', 1, 0)
- button.Insi:SetSize(26, 26)
- button.Insi.Icon = button.Insi:CreateTexture()
- button.Insi.Icon:SetAllPoints()
- button.Insi.Icon:SetTexCoord(0.075, 0.925, 0.075, 0.925)
- button.Insi.Cooldown = CreateFrame("Cooldown", nil, button.Insi)
- -- for _, region in next, {button.Insi.Cooldown:GetRegions()} do
- -- if ( region:GetObjectType() == "FontString" ) then
- -- region:SetFont("Fonts\\FRIZQT__.TTF", 14, "OUTLINE")
- -- end
- -- end
- button.Insi.Cooldown:SetAllPoints()
- button.Insi.Cooldown:SetSwipeTexture('Interface/Buttons/WHITE8X8')
- button.Insi.Cooldown:SetSwipeColor(0, 0, 0, 0.75)
- -- Respawn
- button.Respawn = CreateFrame('Frame', nil, button)
- button.Respawn:SetPoint('LEFT', button, 'RIGHT', 30, 0);
- button.Respawn:SetSize(26, 26)
- button.Respawn:Hide()
- button.Respawn.Icon = button.Respawn:CreateTexture()
- button.Respawn.Icon:SetAllPoints()
- button.Respawn.Icon:SetTexCoord(0.075,0.925,0.075,0.925);
- button.Respawn.Icon:SetTexture(GetSpellTexture(8326))
- button.Respawn.Cooldown = CreateFrame("Cooldown", nil, button.Respawn)
- button.Respawn.Cooldown:SetAllPoints()
- button.Respawn.Cooldown:SetSwipeTexture('Interface/Buttons/WHITE8X8')
- button.Respawn.Cooldown:SetSwipeColor(0, 0, 0, 0.75)
- button.Respawn.Cooldown:SetReverse(true)
- button.Respawn.Cooldown:SetScript("OnHide", function(self)
- button.Respawn:Hide()
- end)
- button.TargetIndicators = {}
- button.PlayerDetails = {}
- return button
- end
- function BattleGroundEnemys.PlayerSortingByRoleClassName(a, b)
- local detailsPlayerA = BattleGroundEnemys.Players[a].PlayerDetails
- local detailsPlayerB = BattleGroundEnemys.Players[b].PlayerDetails
- if detailsPlayerA.RoleSpec == detailsPlayerB.RoleSpec then
- if Settings.BlizzSort[ detailsPlayerA.Class ] == Settings.BlizzSort[ detailsPlayerB.Class ] then
- if a < b then return true end
- elseif Settings.BlizzSort[ detailsPlayerA.Class ] < Settings.BlizzSort[ detailsPlayerB.Class ] then return true end
- elseif detailsPlayerA.RoleSpec < detailsPlayerB.RoleSpec then return true end
- end
- local numArenaOpponents, doArenaframeStuff, EnemyFaction
- function BattleGroundEnemys:UPDATE_BATTLEFIELD_SCORE()
- -- print("UPDATE_BATTLEFIELD_SCORE")
- -- print("GetBattlefieldArenaFaction", GetBattlefieldArenaFaction())
- -- print("C_PvP.IsInBrawl", C_PvP.IsInBrawl())
- -- print("GetCurrentMapAreaID", GetCurrentMapAreaID())
- if not BrawlCheck or C_PvP.IsInBrawl() then
- self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
- self:RegisterEvent("UPDATE_MOUSEOVER_UNIT")
- self:RegisterEvent("PLAYER_TARGET_CHANGED")
- self:RegisterEvent("PLAYER_FOCUS_CHANGED")
- self:RegisterEvent("UNIT_TARGET")
- self:RegisterEvent("UNIT_HEALTH_FREQUENT")
- self:RegisterEvent("NAME_PLATE_UNIT_ADDED")
- self:RegisterEvent("ARENA_OPPONENT_UPDATE")
- self:RegisterEvent("ARENA_CROWD_CONTROL_SPELL_UPDATE")
- self:RegisterEvent("ARENA_COOLDOWNS_UPDATE")
- BrawlCheck = false
- else
- self:UnregisterEvent("UPDATE_BATTLEFIELD_SCORE")
- return --no valid zone
- end
- if not currentMapId or currentMapId == -1 then
- local wmf = WorldMapFrame
- if wmf and not wmf:IsShown() then
- SetMapToCurrentZone()
- currentMapId = GetCurrentMapAreaID()
- end
- local MyBgFaction = GetBattlefieldArenaFaction() -- returns the playered faction; 0 for horde, 1 for alliance
- if MyBgFaction == 0 then
- EnemyFaction = 1 --Enemy is Alliance
- else
- EnemyFaction = 0 --Enemy is Horde
- end
- if BattlegroundspezificBuffs[currentMapId] then
- BattlegroundBuff = BattlegroundspezificBuffs[currentMapId][EnemyFaction]
- end
- if BattlegroundspezificDebuffs[currentMapId] then
- BattleGroundDebuffs = BattlegroundspezificDebuffs[currentMapId]
- end
- --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
- numArenaOpponents = GetNumArenaOpponents()-- returns valid data on PLAYER_ENTERING_WORLD
- if numArenaOpponents > 0 then
- doArenaframeStuff = true --do stuff after sorting
- end
- end
- if InCombatLockdown() then return end
- local NumPlayers = GetNumBattlefieldScores()
- --print("NumPlayers = "..NumPlayers)
- if NumPlayers and NumPlayers <= Settings.MaxPlayers *2 and NumPlayers > 0 then
- self:Show()
- else
- self:Hide()
- return
- end
- local newPlayerDetails = {}
- local change = false
- for i = 1, NumPlayers do
- local name,_,_,_,_,faction,race, _, classTag,_,_,_,_,_,_,spec = GetBattlefieldScore(i)
- --name = name-realm, faction = 0 or 1, race = localized race e.g. "",classTag = e.g. "PALADIN", spec = localized specname e.g. "holy"
- --locale dependent are: race, spec
- if faction == EnemyFaction and name and race and classTag and spec then
- local playerButton = self.Players[name]
- if playerButton then --already existing
- playerButton.PlayerDetails.Status = 1 --1 means found, already existing
- if playerButton.PlayerDetails.Spec ~= spec then--its possible to change spec in battleground
- playerButton.PlayerDetails.Spec = spec
- playerButton.Spec.Icon:SetTexture(Classes[classTag][spec].icon)
- playerButton.PlayerDetails.RoleSpec = Classes[classTag][spec].role
- playerButton.PlayerDetails.SpecIcon = Classes[classTag][spec].icon
- change = true
- end
- else
- newPlayerDetails[name] = { -- details of this new player
- Race = LibRaces:GetRaceToken(race), --delifers are local independent token for relentless check
- Class = classTag,
- Spec = spec,
- TargetedBy = {},
- DRTracking = {},
- RoleSpec = Classes[classTag][spec].role,
- SpecIcon = Classes[classTag][spec].icon,
- }
- change = true
- end
- end
- end
- for name, playerButton in pairs(self.Players) do
- if playerButton.PlayerDetails.Status == 2 then --no longer existing
- table.remove(self.PlayerSortingTable, playerButton.Position)
- playerButton:Hide()
- table.insert(self.InactivePlayerButtons, playerButton)
- self.Players[name] = nil
- change = true
- end
- end
- for name, playerDetails in pairs(newPlayerDetails) do
- local playerButton = self.InactivePlayerButtons[#self.InactivePlayerButtons]
- if playerButton then --recycle a previous used button
- table.remove(self.InactivePlayerButtons, #self.InactivePlayerButtons)
- --Cleanup previous shown stuff of another player
- playerButton.Insi.Icon:SetTexture(nil)
- playerButton.Insi.Cooldown:Clear() --reset Trinket Cooldown
- playerButton:SetBackdropBorderColor(0, 0, 0, 1) --reset possible shown target indicator
- else --no recycleable buttons remaining => create a new one
- playerButton = self:CreateNewPlayerButton()
- end
- playerButton.PlayerDetails = playerDetails
- playerButton:SetAttribute('macrotext1',
- '/cleartarget\n'..
- '/targetexact '..name
- );
- playerButton:SetAttribute('macrotext2',
- '/targetexact '..name..'\n'..
- '/focus\n'..
- '/targetlasttarget'
- );
- playerButton.Spec.Icon:SetTexture(playerDetails.SpecIcon)
- local c = RAID_CLASS_COLORS[playerDetails.Class]
- playerButton.Health:SetStatusBarColor(c.r,c.g,c.b)
- playerButton.Health:SetValue(1)
- if self.db.showRealm then
- playerButton.Name:SetText(name)
- else
- playerButton.Name:SetText(name:match("[^%-]*"))
- end
- table.insert(self.PlayerSortingTable, name)
- playerButton:Show()
- self.Players[name] = playerButton
- end
- if change then
- table.sort(self.PlayerSortingTable, self.PlayerSortingByRoleClassName)
- for number, name in ipairs(self.PlayerSortingTable) do
- local playerButton = self.Players[name]
- playerButton.Position = number
- playerButton.PlayerDetails.Status = 2
- playerButton:SetPoint("TOP", 0, self.PlayerButtonYPositions[number])
- end
- end
- if doArenaframeStuff then
- for i = 1, numArenaOpponents do
- local unitID = "arena"..i
- local uName, realm = UnitName(unitID)
- if realm then
- uName = uName.."-"..realm
- end
- local playerButton = self.Players[uName]
- if playerButton then
- if BattlegroundBuff then
- playerButton.Objective.Icon:SetTexture(GetSpellTexture(BattlegroundBuff))
- end
- C_PvP.RequestCrowdControlSpell(unitID)
- ArenaIDToPlayername[unitID] = uName
- playerButton:RegisterUnitEvent("UNIT_AURA", unitID)
- playerButton.PlayerDetails.BGSpecific = false
- end
- end
- doArenaframeStuff = false
- end
- end
- function BattleGroundEnemys:ScanUnit(unitID)
- local uName, realm = UnitName(unitID)
- if realm then
- uName = uName.."-"..realm
- end
- local playerButton = self.Players[uName]
- if playerButton then
- playerDetails = playerButton.PlayerDetails
- -- Range CHeck
- if self:RangeCheck(unitID) then
- playerButton:SetAlpha(1)
- else
- playerButton:SetAlpha(0.55)
- end
- --health update
- local health, maxHealth = UnitHealth(unitID), UnitHealthMax(unitID)
- playerButton.Health:SetValue(health/maxHealth)
- --unitID and GUID update
- if playerDetails.UnitID then -- if player has a unitID he always has a guid assigned, not vice-versa
- if not playerDetails.GUID == UnitGUID(playerDetails.UnitID) then --the currently assigned unitID doesn't fit to this player anymore
- playerButton.PlayerDetails.UnitID = unitID --the current unitID isn't this player anymore, update it
- end
- else
- if not playerDetails.GUID then
- playerDetails.GUID = UnitGUID(unitID)
- end
- playerDetails.UnitID = unitID
- end
- end
- --self:UpdatePlayerWithAssignedUnitID(player)
- end
- function BattleGroundEnemys:UpdateBattlegroundSpecifics(playerButton, unitID)
- for i = 1, #BattleGroundDebuffs do
- local name, _, _, count, _, _, _, _, _, _, spellID, _, _, _, _, value1, value2, value3 = UnitDebuff(unitID, BattleGroundDebuffs[i])
- if currentMapId == 856 then --Temple of Kotmogu, Orbs
- if value2 then
- if not playerButton.PlayerDetails.BGSpecific then
- --player just got the debuff
- playerButton.Objective.Icon:SetTexture(GetSpellTexture(spellID))
- --print("Texture set")
- end
- if value2 ~= playerButton.PlayerDetails.BGSpecific then
- playerButton.Objective.AuraText:SetText(value2)
- playerButton.PlayerDetails.BGSpecific = value2
- end
- break
- end
- else
- if count then -- Focused Assault, Brutal Assault
- if count ~= playerButton.PlayerDetails.BGSpecific then
- playerButton.Objective.AuraText:SetText(count)
- playerButton.PlayerDetails.BGSpecific = count
- end
- break
- end
- end
- end
- end
- function BattleGroundEnemys:UpdatePlayerWithAssignedUnitID(playerButton)
- local playerDetails = playerButton.PlayerDetails
- local unitID = playerDetails.UnitID
- if UnitGUID(unitID) == playerDetails.GUID then
- -- RespawnTimer
- if UnitIsDead(unitID) then
- self:ShowRespawnTimer(playerButton, 26);
- end
- -- Range CHeck
- if self:RangeCheck(unitID) then
- playerButton:SetAlpha(1)
- else
- playerButton:SetAlpha(0.55)
- end
- local health, maxHealth = UnitHealth(unitID), UnitHealthMax(unitID)
- playerButton.Health:SetValue(health/maxHealth)
- else -- unitID doesn't fit to that player anymore
- playerDetails.UnitID = nil;
- end
- end
- function BattleGroundEnemys:RangeCheck(unitID)
- local maxRange
- --local inRange, checkedRange = UnitInRange(unitID)
- --if inRange and checkedRange then --maximum 40 yards away
- --maxRange = 40 -- inDefaultRange
- if CheckInteractDistance(unitID, 1) then -- 1: Inspect = 28 yards
- maxRange = 28
- if CheckInteractDistance(unitID, 3) then -- 3: Duel = 7 yards
- maxRange = 7
- end
- end
- return maxRange
- end
- local TimeSinceLastOnUpdate = 0
- local UpdatePeroid = 1 --update every second
- function BattleGroundEnemys:OnUpdate(elapsed) --OnUpdate runs if the frame BattleGroundEnemys is shown
- TimeSinceLastOnUpdate = TimeSinceLastOnUpdate + elapsed
- if TimeSinceLastOnUpdate > UpdatePeroid then
- local wssf = WorldStateScoreFrame
- if wssf and not wssf:IsShown() then
- RequestBattlefieldScoreData() --When the requested data is available UPDATE_BATTLEFIELD_SCORE fires
- end
- for name, playerButton in pairs(BattleGroundEnemys.Players) do
- if playerButton.PlayerDetails.UnitID then
- BattleGroundEnemys:UpdatePlayerWithAssignedUnitID(playerButton)
- else
- playerButton:SetAlpha(0.55)
- end
- end
- TimeSinceLastOnUpdate = 0
- end
- end
- local OnUpdateFrame = CreateFrame("Frame")
- OnUpdateFrame:SetScript("OnUpdate", BattleGroundEnemys.OnUpdate)
- local currentTarget
- function BattleGroundEnemys:OnEvent(event, ...)
- --if not (InBattleground) then return end
- if event == "PLAYER_LOGIN" then
- PlayerGUID = UnitGUID("player")
- self:UnregisterEvent("PLAYER_LOGIN")
- self:OnAddonLoaded()
- self:Initialize()
- self:CreateFrame()
- elseif event == "COMBAT_LOG_EVENT_UNFILTERED" then
- self:COMBAT_LOG_EVENT_UNFILTERED(...)
- elseif event == "UNIT_AURA" then
- --print("UNIT_AURA")
- local unitID = ...
- local uName, realm = UnitName(unitID)
- if realm then
- uName = uName.."-"..realm
- end
- local playerButton = self.Players[uName]
- if playerButton then
- self:UpdateBattlegroundSpecifics(playerButton, unitID)
- end
- elseif event == "PLAYER_TARGET_CHANGED" then
- local uName, realm = UnitName("target")
- if realm then
- uName = uName.."-"..realm
- end
- if currentTarget and self.Players[currentTarget]then --player no longer targets this unit
- self.Players[currentTarget]:SetBackdropBorderColor(0, 0, 0, 1)
- end
- local playerButton = self.Players[uName]
- if playerButton then --player targets this unit now
- playerButton:SetBackdropBorderColor(17, 27, 161, 1)
- currentTarget = uName
- end
- self:ScanUnit("target")
- self:UnitTargetChanged("player")
- elseif event == "PLAYER_FOCUS_CHANGED" then
- self:ScanUnit("focus")
- elseif event == "UPDATE_MOUSEOVER_UNIT" then
- self:ScanUnit("mouseover")
- elseif event == "UNIT_TARGET" then
- local unitID = ...
- self:ScanUnit(unitID.."target")
- if unitID:match("^raid%d+$") and UnitGUID(unitID) ~= PlayerGUID then
- --print("target changed")
- self:UnitTargetChanged(unitID)
- end
- elseif event == "UPDATE_BATTLEFIELD_SCORE" then
- self:UPDATE_BATTLEFIELD_SCORE()
- elseif event == "UNIT_HEALTH_FREQUENT" then --gets health of nameplates, player, target, focus, raid1 to raid40, partymember
- self:ScanUnit(...)-- ... is unitID
- elseif event == "NAME_PLATE_UNIT_ADDED" then
- self:ScanUnit(...)--... is unitID
- elseif event == "ARENA_OPPONENT_UPDATE" then
- local unitID, unitEvent = ...
- local uName, realm = UnitName(unitID)
- if realm then
- uName = uName.."-"..realm
- end
- if not uName then uName = ArenaIDToPlayername[unitID] end --when unitEvent == "cleared" then unitName is nil
- --print("ARENA_OPPONENT_UPDATE", unitID, uName, unitEvent)
- local playerButton = self.Players[uName]
- if playerButton then
- if unitEvent ~= "cleared" then
- --print("Hallo")
- -- "unseen", "seen" or "destroyed"
- if BattlegroundBuff then
- playerButton.Objective.Icon:SetTexture(GetSpellTexture(BattlegroundBuff))
- end
- C_PvP.RequestCrowdControlSpell(unitID)
- ArenaIDToPlayername[unitID] = uName
- playerButton:RegisterUnitEvent("UNIT_AURA", unitID)
- else
- playerButton.Objective.Icon:SetTexture(nil)
- --print("Settexture nil")
- playerButton.Objective.AuraText:SetText("")
- ArenaIDToPlayername[unitID] = nil
- playerButton:UnregisterAllEvents()
- end
- playerButton.PlayerDetails.BGSpecific = false
- end
- elseif event == "ARENA_CROWD_CONTROL_SPELL_UPDATE" then
- local unitID, spellID = ...
- if spellID ~= 72757 then --cogwheel (30 sec cooldown trigger)
- local uName, realm = UnitName(unitID)
- if realm then
- uName = uName.."-"..realm
- end
- local playerButton = self.Players[uName]
- if playerButton and self.spellIDToTrinketnumber[spellID] then
- playerButton.PlayerDetails.Insi = self.spellIDToTrinketnumber[spellID]
- playerButton.Insi.Icon:SetTexture(self.spellIDToTrinketFileId[spellID])
- --playerButton.Insi.Icon:Show()
- end
- end
- --print("ARENA_CROWD_CONTROL_SPELL_UPDATE fired")
- elseif event == "ARENA_COOLDOWNS_UPDATE" then --this event is kinda stupid, it doesn't say which unit used a cooldown, it justs says that somebody used a trinket
- for i = 1, 4 do
- local uName, realm = UnitName("arena"..i)
- if realm then
- uName = uName.."-"..realm
- end
- if uName then
- local playerButton = self.Players[uName]
- if playerButton then
- local spellID, startTime, duration = C_PvP.GetArenaCrowdControlInfo("arena"..i)
- if spellID then
- if (startTime ~= 0 and duration ~= 0) then
- playerButton.Insi.Cooldown:SetCooldown(startTime/1000.0, duration/1000.0)
- playerButton.Insi.Cooldown:SetHideCountdownNumbers(false)
- else
- playerButton.Insi.Cooldown:Clear()
- end
- end
- end
- end
- end
- --print("ARENA_COOLDOWNS_UPDATE fired")
- elseif event == "PLAYER_ENTERING_WORLD" then
- local _, zone = IsInInstance()
- if zone == "pvp" or zone == "arena" then
- if zone == "arena" then
- BrawlCheck = true
- end
- -- print("PLAYER_ENTERING_WORLD")
- -- print("GetBattlefieldArenaFaction", GetBattlefieldArenaFaction())
- -- print("C_PvP.IsInBrawl", C_PvP.IsInBrawl())
- -- print("GetCurrentMapAreaID", GetCurrentMapAreaID())
- wipe(self.PlayerSortingTable)
- for name, playerButton in pairs(self.Players) do
- table.insert(self.InactivePlayerButtons, playerButton) --to make them usable again
- playerButton:Hide()
- self.Players[name] = nil
- end
- OnUpdateFrame:Show()
- self:RegisterEvent("UPDATE_BATTLEFIELD_SCORE")
- else
- self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
- self:UnregisterEvent("UPDATE_MOUSEOVER_UNIT")
- self:UnregisterEvent("PLAYER_TARGET_CHANGED")
- self:UnregisterEvent("PLAYER_FOCUS_CHANGED")
- self:UnregisterEvent("UNIT_TARGET")
- self:UnregisterEvent("UNIT_HEALTH_FREQUENT")
- self:UnregisterEvent("UPDATE_BATTLEFIELD_SCORE")
- self:UnregisterEvent("NAME_PLATE_UNIT_ADDED")
- self:UnregisterEvent("ARENA_OPPONENT_UPDATE")--fires when a arena enemy appears and a frame is ready to be shown
- self:UnregisterEvent("ARENA_CROWD_CONTROL_SPELL_UPDATE") --fires when data requested by C_PvP.RequestCrowdControlSpell(unitID) is available
- 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
- BrawlCheck = false
- OnUpdateFrame:Hide()
- self:Hide()
- end
- end
- end
- BattleGroundEnemys:RegisterEvent("ADDON_LOADED")
- BattleGroundEnemys:RegisterEvent("PLAYER_LOGIN")
- BattleGroundEnemys:RegisterEvent("PLAYER_ENTERING_WORLD")
- BattleGroundEnemys:SetScript("OnEvent", BattleGroundEnemys.OnEvent)
- --BattleGroundEnemys:RegisterEvent("UNIT_HEALTH_FREQUENT")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement