Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 49.28 KB | None | 0 0
  1. local L = LibStub("AceLocale-3.0"):GetLocale("BattleGroundEnemys")
  2.  
  3. if type(L) ~= "table" then print("|cdc1c1c7fBattleGroundEnemys:|r ERROR: Please restart WoW.") return end
  4.  
  5. local DRData = LibStub("DRData-1.0")
  6. local LibRaces = LibStub("LibRaces-1.0")
  7.  
  8. local DRstates = {
  9. [1] = {
  10. color = { 0, 1, 0, 1}, --green (next cc in DR time will be only half duration)
  11. diminishFaktor = 1
  12. },
  13. [2] = {
  14. color = { 1, 1, 0, 1}, --yellow (next cc in DR time will be only 1/4 duration)
  15. diminishFaktor = 0.5
  16. },
  17. [3] = {
  18. color = { 1, 0, 0, 1}, --red (next cc in DR time will not apply, player is immune)
  19. diminishFaktor = 0.25
  20. }
  21. }
  22.  
  23. local _G = _G
  24. local CheckInteractDistance = CheckInteractDistance
  25. local DoRemainingStuffWhenOutOfCombat = {}
  26. local IsSpellKnown, GetSpellInfo, GetSpellTexture, IsRatedBattleground = IsSpellKnown, GetSpellInfo, GetSpellTexture, IsRatedBattleground
  27. local RequestBattlefieldScoreData = RequestBattlefieldScoreData
  28. local UnitGUID = UnitGUID
  29. local GetTime = GetTime
  30. local GetBattlefieldArenaFaction = GetBattlefieldArenaFaction
  31. local UnitHealth = UnitHealth
  32. local UnitHealthMax = UnitHealthMax
  33. local UnitInRange = UnitInRange
  34. --CompactRaidFrame informations:
  35. --UnitID to CompactRaidFrame: Frame CompactRaidFrameX = unitID raidX
  36.  
  37. local BrawlCheck
  38.  
  39. BattleGroundEnemys = CreateFrame("Frame", "BattleGroundEnemys", UIParent)
  40.  
  41. BattleGroundEnemys.InactivePlayerButtons = {} --index = number, value = button(table)
  42.  
  43. BattleGroundEnemys.Players = {} --index = name, value = button(table), contains buttons
  44. BattleGroundEnemys.PlayerSortingTable = {} --index = number, value = name
  45. BattleGroundEnemys.ActiveUnitIDs = {} -- index = unitID, value = index(used in Table BattleGroundEnemys.Players)
  46. local Classes = {}
  47.  
  48. local Settings = {
  49. Debug = false,
  50. Test = false,
  51. ButtonSize = {
  52. Width = 190,
  53. Height = 28
  54. },
  55. Locked = false,
  56. MaxPlayers = 15,
  57. BG_MAPS = {},
  58. BlizzSort = {},
  59. DefaultScale = 1
  60. }
  61.  
  62. local PlayerGUID
  63. local currentMapId
  64. local Aura_Types = {
  65. DEFAULT = 0,
  66. OBJECTIVE = 1
  67. }
  68.  
  69.  
  70.  
  71. BattleGroundEnemys.PlayerButtonYPositions = {} --a list of possible button positions from index 1 = top to xxx == bottom
  72. for i = 1, Settings.MaxPlayers do
  73. BattleGroundEnemys.PlayerButtonYPositions[i] = (26 - ( i * (Settings.ButtonSize.Height + 1)))
  74. end
  75.  
  76.  
  77.  
  78. BattleGroundEnemys.TrinketnumberToDisplayspellID = {--key = which first row honor talent, value = fileID(used for SetTexture())
  79. 195710, -- 1: Honorable Medallion, 3. min. CD, detected by Combatlog
  80. 208683, -- 2: Gladiator's Medallion, 2 min. CD, detected by Combatlog
  81. 214027, -- 3: Adaptation, 1 min. CD, detected by Aura 195901
  82. 196029 -- 4: Relentless
  83. }
  84. BattleGroundEnemys.spellIDToCooldown = {
  85.  
  86. [42292] = 120, --Old pvp trinket use effect?
  87. [7744] = 30, -- Will of the Forsaken (Undead)
  88. [59752] = 30, -- human
  89. [20594] = 30, --dwarf
  90. [195710] = 180, -- Honorable Medallion, 3 min. CD
  91. [208683] = 120, -- Gladiator's Medallion, 2 min. CD
  92. [195901] = 60, -- Adaptation PvP Talent
  93.  
  94. }
  95.  
  96.  
  97. BattleGroundEnemys.spellIDToTrinketnumber = {}
  98. BattleGroundEnemys.spellIDToTrinketFileId = {}
  99. BattleGroundEnemys.TrinketnumberToFileId = {}
  100. for i = 1, #BattleGroundEnemys.TrinketnumberToDisplayspellID do
  101. local spellID = BattleGroundEnemys.TrinketnumberToDisplayspellID[i]
  102. BattleGroundEnemys.spellIDToTrinketnumber[spellID] = i
  103. BattleGroundEnemys.spellIDToTrinketFileId[spellID] = GetSpellTexture(spellID)
  104. BattleGroundEnemys.TrinketnumberToFileId[i] = GetSpellTexture(spellID)
  105. end
  106.  
  107.  
  108.  
  109. BattleGroundEnemys.defaults = {}
  110.  
  111. local SpellidToSpellname = {
  112. [156618] = (GetSpellInfo(156618)), -- Horde Flag
  113. [156621] = (GetSpellInfo(156621)), -- Alliance Flag
  114. [34976] = (GetSpellInfo(34976)), -- Netherstorm Flag
  115. [141210] = (GetSpellInfo(141210)), -- Horde Mine Cart
  116. [140876] = (GetSpellInfo(140876)), -- Alliance Mine Cart
  117. [46392] = (GetSpellInfo(46392)), -- Focused Assault
  118. [46393] = (GetSpellInfo(46393)), -- Brutal Assault
  119. [121164] = (GetSpellInfo(121164)), -- Orb of Power, Blue
  120. [121175] = (GetSpellInfo(121175)), -- Orb of Power, Purple
  121. [121177] = (GetSpellInfo(121177)), -- Orb of Power, Orange
  122. [121176] = (GetSpellInfo(121176)) -- Orb of Power, Green
  123. }
  124.  
  125.  
  126. --Battleground specific stuff (flags, orbs, debuffs)
  127. -- BGS that don't have specific stuff like flags, orbs, carts. Basically everything without arenaframes
  128.  
  129. --mapID[736] -- The Battle for Gilneas
  130. --mapID[860] -- Silvershard Mines
  131. --mapID[512] -- Strand of the Ancients
  132. --mapID[540] -- Isle of Conquest
  133. --mapID[461] -- Arathi Basin
  134. --mapID[401] -- Alterac Valley
  135.  
  136.  
  137. BattlegroundspezificBuffs = { --key = mapID, value = table with key = faction(0 for hode, 1 for alliance) value spellID of the flag, minecart
  138. [443] = { -- Warsong Gulch
  139. [0] = 156621, -- Alliance Flag
  140. [1] = 156618 -- Horde Flag
  141. },
  142. [482] = { -- Eye of the Storm
  143. [0] = 34976, -- Netherstorm Flag
  144. [1] = 34976 -- Netherstorm Flag
  145. },
  146. [626] = { -- Twin Peaks
  147. [0] = 156621, -- Alliance Flag
  148. [1] = 156618 -- Horde Flag
  149. },
  150. [935] = { -- Deepwind Gorge
  151. [0] = 140876, -- Alliance Mine Cart
  152. [1] = 141210 -- Horde Mine Cart
  153. }
  154. }
  155.  
  156.  
  157. BattlegroundspezificDebuffs = { --key = mapID, value = table with key = number and value = debuff name
  158. [443] = { -- Warsong Gulch
  159. SpellidToSpellname[46392], -- Focused Assault
  160. SpellidToSpellname[46393] -- Brutal Assault
  161. },
  162. [482] = { -- Eye of the Storm
  163. SpellidToSpellname[46392], -- Focused Assault
  164. SpellidToSpellname[46393] -- Brutal Assault
  165. },
  166. [626] = { -- Twin Peaks
  167. SpellidToSpellname[46392], -- Focused Assault
  168. SpellidToSpellname[46393] -- Brutal Assault
  169. },
  170. [935] = { -- Deepwind Gorge
  171. SpellidToSpellname[46392], -- Focused Assault
  172. SpellidToSpellname[46393] -- Brutal Assault
  173. },
  174. [856] = { -- Temple of Kotmogu
  175. SpellidToSpellname[121164], -- Orb of Power, Blue
  176. SpellidToSpellname[121175], -- Orb of Power, Purple
  177. SpellidToSpellname[121177], -- Orb of Power, Orange
  178. SpellidToSpellname[121176] -- Orb of Power, Green
  179. }
  180. }
  181.  
  182. local BattlegroundBuff --contains the battleground specific enemy buff to watchout for of the current active battlefield
  183. local BattleGroundDebuffs = {} --contains battleground specific enemy debbuffs to watchout for of the current active battlefield
  184. local ArenaIDToPlayername = {}
  185.  
  186. -- local Aura_Overrides = {
  187. -- -- orbs
  188. -- [121164] = "Interface/ICONS/inv_misc_enchantedpearlF", -- Blue Orb
  189. -- [121175] = "Interface/ICONS/inv_misc_enchantedpearlD", -- Purple Orb
  190. -- [121177] = "Interface/ICONS/inv_misc_enchantedpearlC", -- Orange Orb
  191. -- [121176] = "Interface/ICONS/inv_misc_enchantedpearlA" -- Green Orb
  192. -- }
  193.  
  194.  
  195.  
  196.  
  197. -- "Interface\\WorldStateFrame\\HordeFlag"
  198. -- "Interface\\WorldStateFrame\\AllianceFlag"
  199. -- "Interface\\Minimap\\Vehicle-SilvershardMines-MineCart" -- neutral_flag
  200. -- "Interface\\Minimap\\Vehicle-SilvershardMines-MineCartRed"
  201. -- "Interface\\Minimap\\Vehicle-SilvershardMines-MineCartBlue"
  202.  
  203.  
  204. local CCduration={
  205. --[[ INCAPACITATES ]]--
  206. incapacitate = {
  207. -- Druid
  208. [ 99] = 3, -- Incapacitating Roar (talent)
  209. [236025] = 6, -- Main (Honor talent)
  210. [236026] = 6, -- Main (Honor talent)
  211. -- Hunter
  212. [213691] = 4, -- Scatter Shot
  213. -- Mage
  214. [ 118] = 8, -- Polymorph
  215. [ 28272] = 8, -- Polymorph (pig)
  216. [ 28271] = 8, -- Polymorph (turtle)
  217. [ 61305] = 8, -- Polymorph (black cat)
  218. [ 61721] = 8, -- Polymorph (rabbit)
  219. [ 61780] = 8, -- Polymorph (turkey)
  220. [126819] = 8, -- Polymorph (procupine)
  221. [161353] = 8, -- Polymorph (bear cub)
  222. [161354] = 8, -- Polymorph (monkey)
  223. [161355] = 8, -- Polymorph (penguin)
  224. [161372] = 8, -- Polymorph (peacock)
  225. [ 82691] = 8, -- Ring of Frost
  226. -- Monk
  227. [115078] = 4, -- Paralysis
  228. -- Paladin
  229. [ 20066] = 8, -- Repentance
  230. -- Priest
  231. [ 64044] = 4, -- Psychic Horror (Horror effect)
  232. -- Rogue
  233. [ 1776] = 4, -- Gouge
  234. [ 6770] = 8, -- Sap
  235. -- Shaman
  236. [ 51514] = 8, -- Hex
  237. [211004] = 8, -- Hex (spider)
  238. [210873] = 8, -- Hex (raptor)
  239. [211015] = 8, -- Hex (cockroach)
  240. [211010] = 8, -- Hex (snake)
  241. -- Warlock
  242. [ 6789] = 3, -- Mortal Coil
  243. -- Pandaren
  244. [107079] = 4 -- Quaking Palm
  245. },
  246.  
  247. --[[ SILENCES ]]--
  248. silence = {
  249. -- Death Knight
  250. [ 47476] = 5, -- Strangulate
  251. -- Hunter
  252. [202933] = 4, -- Spider Sting (pvp talent)
  253. -- Mage
  254. -- Paladin
  255. [ 31935] = 3, -- Avenger's Shield
  256. -- Priest
  257. [ 15487] = 5, -- Silence
  258. -- Rogue
  259. [ 1330] = 3, -- Garrote
  260. -- Blood Elf
  261. [ 25046] = 2, -- Arcane Torrent (Energy version)
  262. [ 28730] = 2, -- Arcane Torrent (Priest/Mage/Lock version)
  263. [ 50613] = 2, -- Arcane Torrent (Runic power version)
  264. [ 69179] = 2, -- Arcane Torrent (Rage version)
  265. [ 80483] = 2, -- Arcane Torrent (Focus version)
  266. [129597] = 2, -- Arcane Torrent (Monk version)
  267. [155145] = 2, -- Arcane Torrent (Paladin version)
  268. [202719] = 2 -- Arcane Torrent (DH version)
  269. },
  270.  
  271. --[[ DISORIENTS ]]--
  272. disorient = {
  273. -- Druid
  274. [ 33786] = 6, -- Cyclone
  275. [209753] = 6, -- Cyclone (Balance)
  276. -- Hunter
  277. [186387] = 4, -- Bursting Shot
  278. -- Mage
  279. [ 31661] = 3, -- Dragon's Breath
  280. -- Paladin
  281. [105421] = 6, -- Blinding Light -- FIXME: is this the right category? Its missing from blizzard's list
  282. -- Priest
  283. --[ 8122] = 6, -- Psychic Scream
  284. -- Rogue
  285. [ 2094] = 8, -- Blind
  286. -- Warlock
  287. [ 5782] = 6 -- Fear -- probably unused
  288. },
  289.  
  290. --[[ STUNS ]]--
  291. stun = {
  292. -- Death Knight
  293. [108194] = 5, -- Asphyxiate (talent for unholy)
  294. [221562] = 5, -- Asphyxiate (baseline for blood)
  295. [207171] = 4, -- Winter is Coming (Remorseless winter stun)
  296. -- Demon Hunter
  297. [179057] = 5, -- Chaos Nova
  298. [200166] = 3, -- Metamorphosis
  299. [205630] = 6, -- Illidan's Grasp, primary effect
  300. [211881] = 2, -- Fel Eruption
  301. -- Druid
  302. [ 5211] = 5, -- Mighty Bash
  303. -- Monk
  304. [120086] = 4, -- Fists of Fury (with Heavy-Handed Strikes, pvp talent)
  305. [232055] = 3, -- Fists of Fury (new ID in 7.1)
  306. [119381] = 5, -- Leg Sweep
  307. -- Paladin
  308. [ 853] = 6, -- Hammer of Justice
  309. -- Priest
  310. [200200] = 5, -- Holy word: Chastise
  311. -- Rogue
  312. [ 1833] = 4, -- Cheap Shot
  313. -- Shaman
  314. [118345] = 4, -- Pulverize (Primal Earth Elemental)
  315. [118905] = 5, -- Static Charge (Capacitor Totem)
  316. [204399] = 2, -- Earthfury (pvp talent)
  317. -- Warlock
  318. [ 89766] = 4, -- Axe Toss (Felguard)
  319. [ 30283] = 4, -- Shadowfury
  320. -- Warrior
  321. [132168] = 3, -- Shockwave
  322. [132169] = 4, -- Storm Bolt
  323. -- Tauren
  324. [ 20549] = 2 -- War Stomp
  325. },
  326.  
  327. --[[ ROOTS ]]--
  328. root = {
  329. -- Death Knight
  330. [ 96294] = 4, -- Chains of Ice (Chilblains Root)
  331. [204085] = 4, -- Deathchill (pvp talent)
  332. -- Druid
  333. [ 339] = 8, -- Entangling Roots
  334. [102359] = 8, -- Mass Entanglement (talent)
  335. [ 45334] = 4, -- Immobilized (wild charge, bear form)
  336. -- Hunter
  337. [200108] = 3, -- Ranger's Net
  338. [212638] = 6, -- tracker's net
  339. [201158] = 4, -- Super Sticky Tar (Expert Trapper, Hunter talent, Tar Trap effect)
  340. -- Mage
  341. [ 122] = 8, -- Frost Nova
  342. [ 33395] = 8, -- Freeze (Water Elemental)
  343. [228600] = 4, -- Glacial spike (talent)
  344. -- Shaman
  345. [ 64695] = 8 -- Earthgrab Totem
  346. }
  347. }
  348.  
  349.  
  350. BattleGroundEnemys.Interruptdurations = {
  351. [6552] = 4, -- [Warrior] Pummel
  352. [96231] = 4, -- [Paladin] Rebuke
  353. [231665] = 3, -- [Paladin] Avengers Shield
  354. [147362] = 3, -- [Hunter] Countershot
  355. [187707] = 3, -- [Hunter] Muzzle
  356. [1766] = 5, -- [Rogue] Kick
  357. [183752] = 3, -- [DH] Consume Magic
  358. [47528] = 3, -- [DK] Mind Freeze
  359. [91802] = 2, -- [DK] Shambling Rush
  360. [57994] = 3, -- [Shaman] Wind Shear
  361. [115781] = 6, -- [Warlock] Optical Blast
  362. [19647] = 6, -- [Warlock] Spell Lock
  363. [212619] = 6, -- [Warlock] Call Felhunter
  364. [132409] = 6, -- [Warlock] Spell Lock
  365. [171138] = 6, -- [Warlock] Shadow Lock
  366. [2139] = 6, -- [Mage] Counterspell
  367. [116705] = 4, -- [Monk] Spear Hand Strike
  368. [106839] = 4, -- [Feral] Skull Bash
  369. [93985] = 4, -- [Feral] Skull Bash
  370. }
  371.  
  372.  
  373.  
  374. local Special_Auras = {
  375. DEAD = 8326
  376. }
  377.  
  378.  
  379.  
  380.  
  381. local Range_Spells = {
  382. DEATHKNIGHT = 49576, -- Death Grip
  383. DRUID = 339, -- Entangling Roots
  384. HUNTER = 75, -- Auto Shot
  385. MAGE = 2139, -- Counterspell
  386. MONK = 117952, -- Crackling Jade L
  387. PALADIN = 20271, -- Judgment
  388. PRIEST = 585, -- Smite
  389. ROGUE = 6770, -- Sap
  390. SHAMAN = 403, -- Lightning Bolt
  391. WARLOCK = 689, -- Drain Life
  392. WARRIOR = 100, -- Charge
  393. DEMONHUNTER = 162794 -- CHaos Strike
  394. }
  395. local RangeCheckSpell
  396. local SpellRange
  397.  
  398. for i = 1, #CLASS_SORT_ORDER do -- Constants.lua
  399. Settings.BlizzSort[ CLASS_SORT_ORDER[i] ] = i --key = name, value = number
  400. end
  401.  
  402. for classId = 1, MAX_CLASSES do --example classes[EnglishClass][SpecName].
  403. local _, classTag = GetClassInfoByID(classId)
  404. local numSpec = GetNumSpecializationsForClassID(classId)
  405.  
  406. Classes[classTag] = {}
  407. for i = 1, numSpec do
  408. local id,name,_,icon,role = GetSpecializationInfoForClassID(classId, i)
  409. if role == "DAMAGER" then
  410. Classes[classTag][name] = {role = 3}
  411. elseif role == "HEALER" then
  412. Classes[classTag][name] = {role = 1}
  413. elseif role == "TANK"
  414. then Classes[classTag][name] = {role = 2}
  415. end
  416. Classes[classTag][name].icon = icon
  417. end
  418. end
  419.  
  420.  
  421.  
  422. local function Print(...) print("|cffffff7fBattleGroundEnemys:|r", ...) end
  423. local function Debug(...)
  424. if Settings.Debug then
  425. print("|cffffff7fXentiDebug:|r", ...)
  426. end
  427. end
  428.  
  429. if L then
  430. --Print(L["MESSAGES_WELCOME1"]) useless message
  431. --Print(L["MESSAGES_WELCOME2"])
  432. end
  433.  
  434. function BattleGroundEnemys:OnAddonLoaded()
  435. self.dbi = LibStub("AceDB-3.0"):New("BattleGroundEnemysDB", self.defaults)
  436. self.dbi.RegisterCallback(self, "OnProfileChanged", "UpdateFrame")
  437. self.dbi.RegisterCallback(self, "OnProfileCopied", "UpdateFrame")
  438. self.dbi.RegisterCallback(self, "OnProfileReset", "UpdateFrame")
  439.  
  440. self.LSM = LibStub("LibSharedMedia-3.0")
  441. self.LSM:Register("font", "Arialn", "Fonts/ARIALN.TTF")
  442. --button.Name:SetFont("Fonts/ARIALN.TTF", 12, "")
  443.  
  444. self.db = setmetatable(self.dbi.profile, {
  445. __newindex = function(t, index, value)
  446. if type(value) == "table" then
  447. rawset(self.defaults.profile, index, value)
  448. end
  449. rawset(t, index, value)
  450. end})
  451. end
  452.  
  453. function BattleGroundEnemys:UpdateFrame()
  454. self.db = self.dbi.profile
  455.  
  456. if BattleGroundEnemys:GetScale() ~= self.db.frameScale then
  457. BattleGroundEnemys:SetScale(self.db.frameScale)
  458. end
  459.  
  460. -- doing button width check here! :)
  461. for i = 1, Settings.MaxPlayers do
  462. -- Debug("Create Button ", i)
  463. if BattleGroundEnemys.PlayerButtons[i] then
  464. local width, height = BattleGroundEnemys.PlayerButtons[i]:GetSize()
  465.  
  466. if width ~= self.db.barWidth then
  467. BattleGroundEnemys.PlayerButtons[i]:SetSize(self.db.barWidth, height)
  468. end
  469.  
  470. BattleGroundEnemys.PlayerButtons[i].Name:SetFont(self.LSM:Fetch(self.LSM.MediaType.FONT, self.db.globalFont), (self.db.useGlobalFontSize and self.db.globalFontSize or 12))
  471. end
  472. end
  473. end
  474.  
  475.  
  476. -- Updates the TargetedBy tables.
  477. function BattleGroundEnemys:UnitTargetChanged(unitID)
  478.  
  479. local uName, realm = UnitName(unitID.."target")
  480.  
  481. if realm then
  482. uName = uName.."-"..realm
  483. end
  484.  
  485. for name, playerButton in pairs(self.Players) do
  486. if name == uName then
  487. playerButton.PlayerDetails.TargetedBy[unitID] = true --unit targets this enemy now
  488. self:UpdateTargetIndicators(playerButton)
  489. elseif playerButton.PlayerDetails.TargetedBy[unitID] then --this player targeted previously this enemy
  490. playerButton.PlayerDetails.TargetedBy[unitID] = nil --unit no longer targets this enemy
  491. self:UpdateTargetIndicators(playerButton)
  492. end
  493. end
  494. end
  495.  
  496. -- Shows/Hides targeting indicators for a button
  497. function BattleGroundEnemys:UpdateTargetIndicators(playerButton)
  498.  
  499.  
  500. local i = 1
  501. for unitID in pairs(playerButton.PlayerDetails.TargetedBy) do
  502. local indicator = playerButton.TargetIndicators[i]
  503. if not indicator then
  504. indicator = CreateFrame("frame",nil,playerButton.Health)
  505. playerButton.TargetIndicators[i] = indicator
  506. indicator:SetSize(8,10)
  507. 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
  508. indicator:SetBackdrop({
  509. bgFile = "Interface/Buttons/WHITE8X8",
  510. edgeFile = "Interface/Buttons/WHITE8X8",
  511. edgeSize = 1,
  512. })
  513. indicator:SetBackdropBorderColor(0,0,0,1)
  514. end
  515. local className,class = UnitClass(unitID)
  516. local c = RAID_CLASS_COLORS[class or "PRIEST"]
  517. indicator:SetBackdropColor(c.r,c.g,c.b)
  518. indicator:Show()
  519. i = i+1
  520. end
  521. while playerButton.TargetIndicators[i] do --hide no longer used ones
  522. playerButton.TargetIndicators[i]:Hide()
  523. i = i+1
  524. end
  525. end
  526.  
  527. function BattleGroundEnemys:Initialize()
  528.  
  529.  
  530. local _, playerClass = UnitClass("player")
  531. local spellID = Range_Spells[playerClass]
  532. if spellID then
  533. if IsSpellKnown(spellID) then
  534. local name, rank, fileId, castTime, minRange, maxRange, spellId = GetSpellInfo(spellID)
  535. RangeCheckSpell = spellName
  536. SpellRange = maxRange
  537. end
  538. end
  539.  
  540. Debug("RangeCheckSpell ", RangeCheckSpell)
  541. end
  542.  
  543. function BattleGroundEnemys:CreateFrame()
  544. -- BattleGroundEnemys.Main = BattleGroundEnemys
  545.  
  546. BattleGroundEnemys:SetSize(200, 200)
  547. BattleGroundEnemys:SetClampedToScreen(true)
  548. BattleGroundEnemys:SetMovable(true)
  549. BattleGroundEnemys:SetUserPlaced(true)
  550. BattleGroundEnemys:SetResizable(true)
  551. BattleGroundEnemys:SetToplevel(true)
  552. BattleGroundEnemys:SetScale(self.db.frameScale)
  553. --BattleGroundEnemys:SetScript("OnHide", function()print("BattleGroundEnemys OnHide")end)
  554.  
  555. _G["BattleGroundEnemys"]:ClearAllPoints()
  556. if not self.db.x and not self.db.y then
  557. _G["BattleGroundEnemys"]:SetPoint("CENTER")
  558. else
  559. local scale = _G["BattleGroundEnemys"]:GetEffectiveScale()
  560. _G["BattleGroundEnemys"]:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", self.db.x / scale, self.db.y / scale)
  561. end
  562. end
  563.  
  564. --DR Handling
  565.  
  566. function BattleGroundEnemys:RelentlessCheck(playerButton, drCat, spellID)
  567.  
  568. if not CCduration[drCat] then
  569. return
  570. end
  571. local normalDuration = CCduration[drCat][spellID]
  572. if not normalDuration then
  573. return
  574. end
  575. if playerButton.PlayerDetails.Insi then
  576. return
  577. end
  578. if not playerButton.PlayerDetails.UnitID then
  579. return
  580. end
  581.  
  582. local spellName = GetSpellInfo(spellID)
  583. local _,_,_,_,_,actuallDuration = UnitDebuff(playerButton.PlayerDetails.UnitID, spellName)
  584.  
  585. if not actuallDuration then
  586. return
  587. end
  588. local Racefaktor = 1
  589. if drCat == "stun" and playerButton.PlayerDetails.Race == "Orc" then
  590. Racefaktor = 0.8 --Hardiness
  591. end
  592.  
  593.  
  594. --local diminish = actualduraion/(Racefaktor * normalDuration * Trinketfaktor)
  595. --local trinketFaktor * diminish = actuallDuration/(Racefaktor * normalDuration)
  596. --trinketTimesDiminish = trinketFaktor * diminish
  597. --trinketTimesDiminish = without relentless : 1, 0.5, 0,25, with relentless: 0.8, 0.4, 0.2
  598. local trinketTimesDiminish = (actuallDuration/(Racefaktor * normalDuration))
  599.  
  600. if trinketTimesDiminish == 0.8 or trinketTimesDiminish == 0.4 or trinketTimesDiminish == 0.2 then --Relentless
  601. playerButton.PlayerDetails.Insi = 4
  602. playerButton.Insi.Icon:SetTexture(self.TrinketnumberToFileId[4])
  603. end
  604.  
  605. end
  606.  
  607.  
  608.  
  609. function BattleGroundEnemys:UpdateDR(playerButton, spellID, operation)
  610.  
  611. local drCat = DRData:GetSpellCategory(spellID)
  612. --print(operation, spellID)
  613. if not drCat then return end
  614.  
  615. local playerButtonPlayerDetailsDRTracking = playerButton.PlayerDetails.DRTracking
  616. if not playerButtonPlayerDetailsDRTracking[drCat] then
  617. playerButtonPlayerDetailsDRTracking[drCat] = {}
  618. end
  619. local playerButtonPlayerDetailsDRTrackingDRCat = playerButtonPlayerDetailsDRTracking[drCat]
  620. if not playerButtonPlayerDetailsDRTrackingDRCat.status then
  621. playerButtonPlayerDetailsDRTrackingDRCat.status = 0
  622. end
  623. if operation == "applied" then
  624. playerButtonPlayerDetailsDRTrackingDRCat.status = playerButtonPlayerDetailsDRTrackingDRCat.status + 1
  625. if playerButtonPlayerDetailsDRTrackingDRCat.status == 4 then
  626. playerButtonPlayerDetailsDRTrackingDRCat.status = 3
  627. end
  628.  
  629. self:RelentlessCheck(playerButton, drCat, spellID)
  630.  
  631. elseif operation == "refresh" then --if a DR Debuff refreshs the new Debuff is atleast half duration, maybe even 0.25
  632. if playerButtonPlayerDetailsDRTrackingDRCat.status == 0 then
  633. playerButtonPlayerDetailsDRTrackingDRCat.status = 1
  634. end
  635. playerButtonPlayerDetailsDRTrackingDRCat.status = playerButtonPlayerDetailsDRTrackingDRCat.status + 1
  636. if playerButtonPlayerDetailsDRTrackingDRCat.status == 4 then
  637. playerButtonPlayerDetailsDRTrackingDRCat.status = 3
  638. end
  639. local fileID = GetSpellTexture(spellID)
  640. --print(name, playerButtonPlayerDetailsDRTrackingDRCat.status)
  641. playerButton.DR[drCat].Icon:SetTexture(fileID)
  642. playerButton.DR[drCat]:SetBackdropBorderColor(unpack(DRstates[playerButtonPlayerDetailsDRTrackingDRCat.status].color))
  643. playerButton.DR[drCat].Cooldown:SetCooldown(GetTime(), DRData:GetResetTime(drCat))
  644. playerButton.DR[drCat].Cooldown:SetHideCountdownNumbers(false)
  645.  
  646. self:RelentlessCheck(playerButton, drCat, spellID)
  647.  
  648. else --operation == "removed"
  649. 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
  650. playerButtonPlayerDetailsDRTrackingDRCat.status = 1
  651. end
  652. local fileID = GetSpellTexture(spellID)
  653. --print(name, playerButtonPlayerDetailsDRTrackingDRCat.status)
  654. playerButton.DR[drCat].Icon:SetTexture(fileID)
  655. playerButton.DR[drCat]:SetBackdropBorderColor(unpack(DRstates[playerButtonPlayerDetailsDRTrackingDRCat.status].color))
  656. playerButton.DR[drCat].Cooldown:SetCooldown(GetTime(), DRData:GetResetTime(drCat))
  657. playerButton.DR[drCat].Cooldown:SetHideCountdownNumbers(false)
  658. end
  659. end
  660.  
  661. function BattleGroundEnemys:LeftSidePositioning(playerButton)
  662. local active = 0
  663. for categorie, v in pairs(DRData:GetCategories()) do
  664. if ( playerButton.DR[categorie]:GetAlpha() == 1 ) then
  665. playerButton.DR[categorie]:ClearAllPoints()
  666.  
  667. local ystart = -4
  668. if playerButton.Objective.Icon:GetTexture() then
  669. ystart = -44
  670. end
  671. if ( active == 0 ) then
  672. playerButton.DR[categorie]:SetPoint("RIGHT", playerButton.Spec, "LEFT", ystart, 0)
  673. else
  674. playerButton.DR[categorie]:SetPoint("RIGHT", playerButton.Spec, "LEFT", ystart - (active * (Settings.ButtonSize.Height + 2)), 0)
  675. end
  676. active = active + 1
  677.  
  678. end
  679. end
  680. end
  681.  
  682.  
  683. function BattleGroundEnemys:COMBAT_LOG_EVENT_UNFILTERED(timestamp,subevent,hide,srcGUID,srcName,srcF1,srcF2,destGUID,destName,destF1,destF2,spellID,spellName,spellSchool,...)
  684. if subevent == "SPELL_CAST_SUCCESS" then
  685. if not self.spellIDToTrinketnumber[spellID] or not self.Players[srcName] then
  686. return
  687. end
  688. local playerButton = self.Players[srcName]
  689. if self.spellIDToTrinketnumber[spellID] then
  690. playerButton.PlayerDetails.Insi = self.spellIDToTrinketnumber[spellID]
  691. playerButton.Insi.Icon:SetTexture(self.spellIDToTrinketFileId[spellID])
  692. -- TODO RACIALS, MAYBE?
  693. playerButton.Insi.Cooldown:SetCooldown(GetTime(), self.spellIDToCooldown[spellID])
  694. playerButton.Insi.Cooldown:SetHideCountdownNumbers(false)
  695. end
  696. elseif subevent == "SPELL_INTERRUPT" then
  697. local extraspellID = ...
  698. local playerButton = self.Players[destName]
  699. if playerButton and self.Interruptdurations[extraspellID] then
  700. local fileID = GetSpellTexture(extraspellID)
  701. playerButton.Spec.Icon:SetTexture(fileID)
  702. playerButton.Spec.Cooldown:SetCooldown(GetTime(), self.Interruptdurations[extraspellID])
  703. playerButton.Insi.Cooldown:SetHideCountdownNumbers(false)
  704. self:InterruptGained(playerButton, extraspellID)
  705. end
  706. elseif subevent == "SPELL_AURA_APPLIED" then
  707. local auraType = ...
  708. local playerButton = self.Players[destName]
  709. if playerButton then
  710. if spellID == 195901 then --adaptation
  711. playerButton.PlayerDetails.Insi = 3
  712. playerButton.Insi.Icon:SetTexture(BattleGroundEnemys.TrinketnumberToFileId[3])
  713. playerButton.Insi.Cooldown:SetCooldown(GetTime(), 60)
  714. elseif auraType == "DEBUFF" then
  715. self:UpdateDR(playerButton, spellID, "applied")
  716. end
  717. end
  718. elseif subevent == "SPELL_AURA_REFRESH" then
  719. local auraType = ...
  720. local playerButton = self.Players[destName]
  721. if playerButton then
  722. if auraType == "DEBUFF" then
  723. self:UpdateDR(playerButton, spellID, "refresh")
  724. end
  725. end
  726. elseif subevent == "SPELL_AURA_REMOVED" then
  727. local auraType = ...
  728. local playerButton = self.Players[destName]
  729. if playerButton then
  730. if auraType == "DEBUFF" then
  731. self:UpdateDR(playerButton, spellID, "removed")
  732. end
  733. end
  734. elseif subevent == "UNIT_DIED" then
  735. local playerButton = self.Players[destName]
  736. if playerButton then
  737. self:ShowRespawnTimer(playerButton, 27)
  738. end
  739. end
  740. end
  741.  
  742. function BattleGroundEnemys:SavePosition()
  743. if not InCombatLockdown() then
  744. local f = _G["BattleGroundEnemys"]
  745. f:StopMovingOrSizing()
  746. local scale = f:GetEffectiveScale()
  747. self.db.x= f:GetLeft() * scale
  748. self.db.y = f:GetTop() * scale
  749. end
  750. end
  751.  
  752. function BattleGroundEnemys:ShowRespawnTimer(playerButton,duration)
  753. if not IsRatedBattleground() then
  754. return
  755. end
  756. playerButton.Respawn.Cooldown:SetCooldown(GetTime(), duration)
  757. playerButton.Respawn.Cooldown:SetHideCountdownNumbers(false)
  758. playerButton.Respawn:Show()
  759. end
  760.  
  761. function BattleGroundEnemys:CreateNewPlayerButton()
  762. local button = CreateFrame('Button', nil, BattleGroundEnemys, 'SecureActionButtonTemplate')
  763. button:SetSize(self.db.barWidth, Settings.ButtonSize.Height)
  764. button:SetBackdrop({
  765. bgFile = "Interface/Buttons/WHITE8X8",
  766. edgeFile = 'Interface/Buttons/WHITE8X8',
  767. edgeSize = 1,
  768. })
  769. button:SetBackdropBorderColor(0, 0, 0, 1)
  770. button:SetBackdropColor(0,0,0,.28)
  771.  
  772.  
  773. -- events/scripts
  774. button:RegisterForClicks('AnyUp')
  775. button:RegisterForDrag('LeftButton')
  776. button:SetAttribute('type1','macro')
  777. button:SetAttribute('type2','macro')
  778.  
  779. button:SetScript('OnDragStart', function() return BattleGroundEnemys.db.locked or BattleGroundEnemys:StartMoving() end)
  780. button:SetScript('OnDragStop', function() BattleGroundEnemys:StopMovingOrSizing() BattleGroundEnemys:SavePosition() end)
  781. button:SetScript('OnEvent', function(self, event, unitID) --for unit event UNIT_AURA
  782. --print("hallo")
  783. BattleGroundEnemys:UpdateBattlegroundSpecifics(button, unitID)
  784. end)
  785.  
  786. -- health
  787. button.Health = CreateFrame('StatusBar', nil, button)
  788. button.Health:SetPoint('TOPLEFT', 1, -1)
  789. button.Health:SetPoint('BOTTOMRIGHT', -1, 1)
  790. button.Health:SetStatusBarTexture('Interface\\TargetingFrame\\UI-StatusBar')--button.Health:SetStatusBarTexture(137012)
  791. button.Health:SetMinMaxValues(0, 1)
  792.  
  793. -- name
  794. button.Name = button.Health:CreateFontString()
  795. button.Name:SetPoint('TOPLEFT', 5, 0)
  796. button.Name:SetPoint('BOTTOMRIGHT')
  797. button.Name:SetFont(self.LSM:Fetch(self.LSM.MediaType.FONT, self.db.globalFont), (self.db.useGlobalFontSize and self.db.globalFontSize or 12))
  798. button.Name:SetJustifyH('LEFT')
  799. button.Name:SetTextColor(1, 1, 1)
  800. button.Name:SetShadowColor(0, 0, 0, 1)
  801. button.Name:SetShadowOffset(1, -1)
  802. button.Name:SetDrawLayer('ARTWORK', 2)
  803. -- extended info (e.g. orb debuff)
  804. button.SetInfo = function(info) button.Info:SetText(info) end
  805. button.Info = button.Health:CreateFontString()
  806.  
  807. -- spec
  808. button.Spec = CreateFrame('Frame', nil, button)
  809. button.Spec:SetPoint('RIGHT', button, 'LEFT',-1,0);
  810. button.Spec:SetSize(36,26);
  811.  
  812. button.Spec.Icon = button.Spec:CreateTexture('ARTWORK',2)
  813. button.Spec.Icon:SetPoint('CENTER', button.Spec, 'CENTER',0,0);
  814. button.Spec.Icon:SetSize(36,26);
  815. button.Spec.Icon:SetTexCoord( 4/64, (4+56)/64, 12/64, (12+40)/64 );
  816.  
  817. button.Spec.Cooldown = CreateFrame("Cooldown", nil, button.Spec)
  818. button.Spec.Cooldown:SetAllPoints()
  819. button.Spec.Cooldown:SetSwipeTexture('Interface/Buttons/WHITE8X8')
  820. button.Spec.Cooldown:SetSwipeColor(0, 0, 0, 0.75)
  821.  
  822. -- button.Spec.Cooldown:SetScript("OnHide", function(self)
  823. -- button.DR[categorie]:SetAlpha(0)
  824. -- button.Spec.Icon:SetTexture(button.PlayerDetails.Icon)
  825. -- end)
  826.  
  827.  
  828. -- Diminishing Returns
  829. button.DR = {}
  830. for categorie, v in pairs(DRData:GetCategories()) do
  831.  
  832. button.DR[categorie] = CreateFrame("Frame", nil, button)
  833. button.DR[categorie]:SetSize(Settings.ButtonSize.Height, Settings.ButtonSize.Height)
  834. button.DR[categorie]:SetAlpha(0)
  835. button.DR[categorie]:SetBackdrop({
  836. bgFile = "Interface/Buttons/WHITE8X8",
  837. edgeFile = 'Interface/Buttons/WHITE8X8',
  838. edgeSize = 1,
  839. })
  840. button.DR[categorie]:SetBackdropColor(0,0,0,0)
  841. button.DR[categorie].Icon = button.DR[categorie]:CreateTexture(nil, "BACKGROUND")
  842. --button.DR[categorie].Icon:SetTexture('Interface/Icons/Spell_Nature_Polymorph')
  843. button.DR[categorie].Icon:SetAllPoints()
  844. -- button.DR[categorie].Border = button.DR[categorie]:CreateTexture(nil, "ARTWORK")
  845. -- button.DR[categorie].Border:SetTexture('Interface/BUTTONS/UI-Quickslot-Depress')
  846. -- button.DR[categorie].Border:SetAllPoints()
  847. button.DR[categorie].Cooldown = CreateFrame("Cooldown", nil, button.DR[categorie])
  848. button.DR[categorie].Cooldown:ClearAllPoints()
  849. button.DR[categorie].Cooldown:SetPoint("TOPLEFT", 1, -1)
  850. button.DR[categorie].Cooldown:SetPoint("BOTTOMRIGHT", -1, 1)
  851. button.DR[categorie].Cooldown:SetDrawBling(false)
  852. button.DR[categorie].Cooldown:SetSwipeColor(0,0,0,0.5)
  853.  
  854.  
  855.  
  856. -- for _, region in next, {button.DR[categorie].Cooldown:GetRegions()} do
  857. -- if ( region:GetObjectType() == "FontString" ) then
  858. -- region:SetFont("Fonts\\FRIZQT__.TTF", , "OUTLINE")
  859. -- end
  860. -- end
  861.  
  862.  
  863.  
  864. button.DR[categorie].Cooldown:SetScript("OnShow", function(self)
  865. button.DR[categorie]:SetAlpha(1)
  866. BattleGroundEnemys:LeftSidePositioning(button)
  867. end)
  868.  
  869. button.DR[categorie].Cooldown:SetScript("OnHide", function(self)
  870. button.DR[categorie]:SetAlpha(0)
  871. BattleGroundEnemys:LeftSidePositioning(button)
  872. if button.PlayerDetails.DRTracking[categorie] then
  873. button.PlayerDetails.DRTracking[categorie].status = 0
  874. end
  875. end)
  876. end
  877.  
  878.  
  879. -- objective
  880. button.Objective = CreateFrame('Frame', nil, button)
  881. button.Objective:SetPoint('RIGHT', button, 'LEFT',-40,0);
  882. button.Objective:SetSize(36,26);
  883.  
  884. button.Objective.Icon = button.Objective:CreateTexture(nil, "BORDER")
  885. button.Objective.Icon:SetAllPoints()
  886. button.Objective.Icon:SetTexCoord( 4/64, 59/64, 12/64, 52/64 );
  887.  
  888.  
  889. button.Objective.AuraText = button.Objective:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  890. button.Objective.AuraText:SetWidth(50)
  891. button.Objective.AuraText:SetPoint("CENTER", button.Objective.Icon, "CENTER", 0, 0)
  892. button.Objective.AuraText:SetJustifyH("CENTER")
  893. button.Objective.AuraText:SetShadowOffset(0, 0)
  894. button.Objective.AuraText:SetShadowColor(0, 0, 0, 0)
  895. button.Objective.AuraText:SetTextColor(1, 1, 1, 1)
  896. button.Objective.AuraText:SetFont('Fonts/ARIALN.TTF', 16, 'THINOUTLINE')
  897.  
  898. -- trinket
  899. button.Insi = CreateFrame('Frame', nil, button)
  900. button.Insi:SetPoint('LEFT', button, 'RIGHT', 1, 0)
  901. button.Insi:SetSize(26, 26)
  902.  
  903. button.Insi.Icon = button.Insi:CreateTexture()
  904. button.Insi.Icon:SetAllPoints()
  905. button.Insi.Icon:SetTexCoord(0.075, 0.925, 0.075, 0.925)
  906.  
  907. button.Insi.Cooldown = CreateFrame("Cooldown", nil, button.Insi)
  908.  
  909. -- for _, region in next, {button.Insi.Cooldown:GetRegions()} do
  910. -- if ( region:GetObjectType() == "FontString" ) then
  911. -- region:SetFont("Fonts\\FRIZQT__.TTF", 14, "OUTLINE")
  912. -- end
  913. -- end
  914.  
  915.  
  916. button.Insi.Cooldown:SetAllPoints()
  917. button.Insi.Cooldown:SetSwipeTexture('Interface/Buttons/WHITE8X8')
  918. button.Insi.Cooldown:SetSwipeColor(0, 0, 0, 0.75)
  919.  
  920. -- Respawn
  921. button.Respawn = CreateFrame('Frame', nil, button)
  922. button.Respawn:SetPoint('LEFT', button, 'RIGHT', 30, 0);
  923. button.Respawn:SetSize(26, 26)
  924. button.Respawn:Hide()
  925.  
  926. button.Respawn.Icon = button.Respawn:CreateTexture()
  927. button.Respawn.Icon:SetAllPoints()
  928. button.Respawn.Icon:SetTexCoord(0.075,0.925,0.075,0.925);
  929. button.Respawn.Icon:SetTexture(GetSpellTexture(8326))
  930.  
  931. button.Respawn.Cooldown = CreateFrame("Cooldown", nil, button.Respawn)
  932. button.Respawn.Cooldown:SetAllPoints()
  933. button.Respawn.Cooldown:SetSwipeTexture('Interface/Buttons/WHITE8X8')
  934. button.Respawn.Cooldown:SetSwipeColor(0, 0, 0, 0.75)
  935. button.Respawn.Cooldown:SetReverse(true)
  936.  
  937. button.Respawn.Cooldown:SetScript("OnHide", function(self)
  938. button.Respawn:Hide()
  939. end)
  940.  
  941.  
  942. button.TargetIndicators = {}
  943. button.PlayerDetails = {}
  944.  
  945. return button
  946. end
  947.  
  948. function BattleGroundEnemys.PlayerSortingByRoleClassName(a, b)
  949. local detailsPlayerA = BattleGroundEnemys.Players[a].PlayerDetails
  950. local detailsPlayerB = BattleGroundEnemys.Players[b].PlayerDetails
  951. if detailsPlayerA.RoleSpec == detailsPlayerB.RoleSpec then
  952. if Settings.BlizzSort[ detailsPlayerA.Class ] == Settings.BlizzSort[ detailsPlayerB.Class ] then
  953. if a < b then return true end
  954. elseif Settings.BlizzSort[ detailsPlayerA.Class ] < Settings.BlizzSort[ detailsPlayerB.Class ] then return true end
  955. elseif detailsPlayerA.RoleSpec < detailsPlayerB.RoleSpec then return true end
  956. end
  957.  
  958. local numArenaOpponents, doArenaframeStuff, EnemyFaction
  959. function BattleGroundEnemys:UPDATE_BATTLEFIELD_SCORE()
  960.  
  961.  
  962. -- print("UPDATE_BATTLEFIELD_SCORE")
  963. -- print("GetBattlefieldArenaFaction", GetBattlefieldArenaFaction())
  964. -- print("C_PvP.IsInBrawl", C_PvP.IsInBrawl())
  965. -- print("GetCurrentMapAreaID", GetCurrentMapAreaID())
  966.  
  967. if not BrawlCheck or C_PvP.IsInBrawl() then
  968. self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  969. self:RegisterEvent("UPDATE_MOUSEOVER_UNIT")
  970. self:RegisterEvent("PLAYER_TARGET_CHANGED")
  971. self:RegisterEvent("PLAYER_FOCUS_CHANGED")
  972. self:RegisterEvent("UNIT_TARGET")
  973. self:RegisterEvent("UNIT_HEALTH_FREQUENT")
  974. self:RegisterEvent("NAME_PLATE_UNIT_ADDED")
  975. self:RegisterEvent("ARENA_OPPONENT_UPDATE")
  976. self:RegisterEvent("ARENA_CROWD_CONTROL_SPELL_UPDATE")
  977. self:RegisterEvent("ARENA_COOLDOWNS_UPDATE")
  978. BrawlCheck = false
  979. else
  980. self:UnregisterEvent("UPDATE_BATTLEFIELD_SCORE")
  981. return --no valid zone
  982. end
  983.  
  984. if not currentMapId or currentMapId == -1 then
  985. local wmf = WorldMapFrame
  986. if wmf and not wmf:IsShown() then
  987. SetMapToCurrentZone()
  988. currentMapId = GetCurrentMapAreaID()
  989. end
  990.  
  991. local MyBgFaction = GetBattlefieldArenaFaction() -- returns the playered faction; 0 for horde, 1 for alliance
  992. if MyBgFaction == 0 then
  993. EnemyFaction = 1 --Enemy is Alliance
  994. else
  995. EnemyFaction = 0 --Enemy is Horde
  996. end
  997. if BattlegroundspezificBuffs[currentMapId] then
  998. BattlegroundBuff = BattlegroundspezificBuffs[currentMapId][EnemyFaction]
  999. end
  1000. if BattlegroundspezificDebuffs[currentMapId] then
  1001. BattleGroundDebuffs = BattlegroundspezificDebuffs[currentMapId]
  1002. end
  1003. --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
  1004. numArenaOpponents = GetNumArenaOpponents()-- returns valid data on PLAYER_ENTERING_WORLD
  1005.  
  1006. if numArenaOpponents > 0 then
  1007. doArenaframeStuff = true --do stuff after sorting
  1008. end
  1009. end
  1010.  
  1011.  
  1012. if InCombatLockdown() then return end
  1013. local NumPlayers = GetNumBattlefieldScores()
  1014. --print("NumPlayers = "..NumPlayers)
  1015.  
  1016. if NumPlayers and NumPlayers <= Settings.MaxPlayers *2 and NumPlayers > 0 then
  1017. self:Show()
  1018. else
  1019. self:Hide()
  1020. return
  1021. end
  1022.  
  1023. local newPlayerDetails = {}
  1024. local change = false
  1025. for i = 1, NumPlayers do
  1026. local name,_,_,_,_,faction,race, _, classTag,_,_,_,_,_,_,spec = GetBattlefieldScore(i)
  1027. --name = name-realm, faction = 0 or 1, race = localized race e.g. "",classTag = e.g. "PALADIN", spec = localized specname e.g. "holy"
  1028. --locale dependent are: race, spec
  1029.  
  1030. if faction == EnemyFaction and name and race and classTag and spec then
  1031. local playerButton = self.Players[name]
  1032. if playerButton then --already existing
  1033. playerButton.PlayerDetails.Status = 1 --1 means found, already existing
  1034. if playerButton.PlayerDetails.Spec ~= spec then--its possible to change spec in battleground
  1035. playerButton.PlayerDetails.Spec = spec
  1036. playerButton.Spec.Icon:SetTexture(Classes[classTag][spec].icon)
  1037. playerButton.PlayerDetails.RoleSpec = Classes[classTag][spec].role
  1038. playerButton.PlayerDetails.SpecIcon = Classes[classTag][spec].icon
  1039.  
  1040. change = true
  1041. end
  1042. else
  1043. newPlayerDetails[name] = { -- details of this new player
  1044. Race = LibRaces:GetRaceToken(race), --delifers are local independent token for relentless check
  1045. Class = classTag,
  1046. Spec = spec,
  1047. TargetedBy = {},
  1048. DRTracking = {},
  1049. RoleSpec = Classes[classTag][spec].role,
  1050. SpecIcon = Classes[classTag][spec].icon,
  1051. }
  1052.  
  1053. change = true
  1054. end
  1055. end
  1056. end
  1057. for name, playerButton in pairs(self.Players) do
  1058. if playerButton.PlayerDetails.Status == 2 then --no longer existing
  1059.  
  1060. table.remove(self.PlayerSortingTable, playerButton.Position)
  1061. playerButton:Hide()
  1062.  
  1063. table.insert(self.InactivePlayerButtons, playerButton)
  1064. self.Players[name] = nil
  1065.  
  1066. change = true
  1067. end
  1068. end
  1069. for name, playerDetails in pairs(newPlayerDetails) do
  1070. local playerButton = self.InactivePlayerButtons[#self.InactivePlayerButtons]
  1071.  
  1072. if playerButton then --recycle a previous used button
  1073. table.remove(self.InactivePlayerButtons, #self.InactivePlayerButtons)
  1074. --Cleanup previous shown stuff of another player
  1075. playerButton.Insi.Icon:SetTexture(nil)
  1076. playerButton.Insi.Cooldown:Clear() --reset Trinket Cooldown
  1077. playerButton:SetBackdropBorderColor(0, 0, 0, 1) --reset possible shown target indicator
  1078. else --no recycleable buttons remaining => create a new one
  1079. playerButton = self:CreateNewPlayerButton()
  1080. end
  1081.  
  1082. playerButton.PlayerDetails = playerDetails
  1083. playerButton:SetAttribute('macrotext1',
  1084. '/cleartarget\n'..
  1085. '/targetexact '..name
  1086. );
  1087.  
  1088. playerButton:SetAttribute('macrotext2',
  1089. '/targetexact '..name..'\n'..
  1090. '/focus\n'..
  1091. '/targetlasttarget'
  1092. );
  1093.  
  1094. playerButton.Spec.Icon:SetTexture(playerDetails.SpecIcon)
  1095.  
  1096. local c = RAID_CLASS_COLORS[playerDetails.Class]
  1097. playerButton.Health:SetStatusBarColor(c.r,c.g,c.b)
  1098. playerButton.Health:SetValue(1)
  1099.  
  1100. if self.db.showRealm then
  1101. playerButton.Name:SetText(name)
  1102. else
  1103. playerButton.Name:SetText(name:match("[^%-]*"))
  1104. end
  1105. table.insert(self.PlayerSortingTable, name)
  1106.  
  1107.  
  1108. playerButton:Show()
  1109. self.Players[name] = playerButton
  1110. end
  1111.  
  1112. if change then
  1113. table.sort(self.PlayerSortingTable, self.PlayerSortingByRoleClassName)
  1114. for number, name in ipairs(self.PlayerSortingTable) do
  1115. local playerButton = self.Players[name]
  1116. playerButton.Position = number
  1117. playerButton.PlayerDetails.Status = 2
  1118. playerButton:SetPoint("TOP", 0, self.PlayerButtonYPositions[number])
  1119. end
  1120. end
  1121.  
  1122.  
  1123. if doArenaframeStuff then
  1124. for i = 1, numArenaOpponents do
  1125. local unitID = "arena"..i
  1126.  
  1127.  
  1128. local uName, realm = UnitName(unitID)
  1129. if realm then
  1130. uName = uName.."-"..realm
  1131. end
  1132. local playerButton = self.Players[uName]
  1133. if playerButton then
  1134. if BattlegroundBuff then
  1135. playerButton.Objective.Icon:SetTexture(GetSpellTexture(BattlegroundBuff))
  1136. end
  1137. C_PvP.RequestCrowdControlSpell(unitID)
  1138. ArenaIDToPlayername[unitID] = uName
  1139. playerButton:RegisterUnitEvent("UNIT_AURA", unitID)
  1140. playerButton.PlayerDetails.BGSpecific = false
  1141. end
  1142. end
  1143. doArenaframeStuff = false
  1144. end
  1145. end
  1146.  
  1147.  
  1148. function BattleGroundEnemys:ScanUnit(unitID)
  1149. local uName, realm = UnitName(unitID)
  1150. if realm then
  1151. uName = uName.."-"..realm
  1152. end
  1153.  
  1154. local playerButton = self.Players[uName]
  1155.  
  1156. if playerButton then
  1157. playerDetails = playerButton.PlayerDetails
  1158.  
  1159. -- Range CHeck
  1160. if self:RangeCheck(unitID) then
  1161. playerButton:SetAlpha(1)
  1162. else
  1163. playerButton:SetAlpha(0.55)
  1164. end
  1165.  
  1166. --health update
  1167. local health, maxHealth = UnitHealth(unitID), UnitHealthMax(unitID)
  1168. playerButton.Health:SetValue(health/maxHealth)
  1169.  
  1170. --unitID and GUID update
  1171. if playerDetails.UnitID then -- if player has a unitID he always has a guid assigned, not vice-versa
  1172. if not playerDetails.GUID == UnitGUID(playerDetails.UnitID) then --the currently assigned unitID doesn't fit to this player anymore
  1173. playerButton.PlayerDetails.UnitID = unitID --the current unitID isn't this player anymore, update it
  1174. end
  1175. else
  1176. if not playerDetails.GUID then
  1177. playerDetails.GUID = UnitGUID(unitID)
  1178. end
  1179.  
  1180. playerDetails.UnitID = unitID
  1181. end
  1182. end
  1183.  
  1184. --self:UpdatePlayerWithAssignedUnitID(player)
  1185. end
  1186.  
  1187.  
  1188. function BattleGroundEnemys:UpdateBattlegroundSpecifics(playerButton, unitID)
  1189. for i = 1, #BattleGroundDebuffs do
  1190. local name, _, _, count, _, _, _, _, _, _, spellID, _, _, _, _, value1, value2, value3 = UnitDebuff(unitID, BattleGroundDebuffs[i])
  1191. if currentMapId == 856 then --Temple of Kotmogu, Orbs
  1192. if value2 then
  1193. if not playerButton.PlayerDetails.BGSpecific then
  1194. --player just got the debuff
  1195. playerButton.Objective.Icon:SetTexture(GetSpellTexture(spellID))
  1196. --print("Texture set")
  1197. end
  1198. if value2 ~= playerButton.PlayerDetails.BGSpecific then
  1199. playerButton.Objective.AuraText:SetText(value2)
  1200. playerButton.PlayerDetails.BGSpecific = value2
  1201. end
  1202. break
  1203. end
  1204. else
  1205. if count then -- Focused Assault, Brutal Assault
  1206. if count ~= playerButton.PlayerDetails.BGSpecific then
  1207. playerButton.Objective.AuraText:SetText(count)
  1208. playerButton.PlayerDetails.BGSpecific = count
  1209. end
  1210. break
  1211. end
  1212. end
  1213. end
  1214. end
  1215.  
  1216.  
  1217. function BattleGroundEnemys:UpdatePlayerWithAssignedUnitID(playerButton)
  1218. local playerDetails = playerButton.PlayerDetails
  1219. local unitID = playerDetails.UnitID
  1220. if UnitGUID(unitID) == playerDetails.GUID then
  1221.  
  1222. -- RespawnTimer
  1223. if UnitIsDead(unitID) then
  1224. self:ShowRespawnTimer(playerButton, 26);
  1225. end
  1226. -- Range CHeck
  1227. if self:RangeCheck(unitID) then
  1228. playerButton:SetAlpha(1)
  1229. else
  1230. playerButton:SetAlpha(0.55)
  1231. end
  1232.  
  1233. local health, maxHealth = UnitHealth(unitID), UnitHealthMax(unitID)
  1234. playerButton.Health:SetValue(health/maxHealth)
  1235. else -- unitID doesn't fit to that player anymore
  1236. playerDetails.UnitID = nil;
  1237. end
  1238. end
  1239.  
  1240. function BattleGroundEnemys:RangeCheck(unitID)
  1241. local maxRange
  1242. --local inRange, checkedRange = UnitInRange(unitID)
  1243. --if inRange and checkedRange then --maximum 40 yards away
  1244. --maxRange = 40 -- inDefaultRange
  1245. if CheckInteractDistance(unitID, 1) then -- 1: Inspect = 28 yards
  1246. maxRange = 28
  1247. if CheckInteractDistance(unitID, 3) then -- 3: Duel = 7 yards
  1248. maxRange = 7
  1249. end
  1250. end
  1251. return maxRange
  1252. end
  1253.  
  1254.  
  1255. local TimeSinceLastOnUpdate = 0
  1256. local UpdatePeroid = 1 --update every second
  1257. function BattleGroundEnemys:OnUpdate(elapsed) --OnUpdate runs if the frame BattleGroundEnemys is shown
  1258. TimeSinceLastOnUpdate = TimeSinceLastOnUpdate + elapsed
  1259. if TimeSinceLastOnUpdate > UpdatePeroid then
  1260. local wssf = WorldStateScoreFrame
  1261. if wssf and not wssf:IsShown() then
  1262. RequestBattlefieldScoreData() --When the requested data is available UPDATE_BATTLEFIELD_SCORE fires
  1263. end
  1264. for name, playerButton in pairs(BattleGroundEnemys.Players) do
  1265. if playerButton.PlayerDetails.UnitID then
  1266. BattleGroundEnemys:UpdatePlayerWithAssignedUnitID(playerButton)
  1267. else
  1268. playerButton:SetAlpha(0.55)
  1269. end
  1270. end
  1271.  
  1272. TimeSinceLastOnUpdate = 0
  1273. end
  1274. end
  1275.  
  1276. local OnUpdateFrame = CreateFrame("Frame")
  1277. OnUpdateFrame:SetScript("OnUpdate", BattleGroundEnemys.OnUpdate)
  1278.  
  1279. local currentTarget
  1280. function BattleGroundEnemys:OnEvent(event, ...)
  1281. --if not (InBattleground) then return end
  1282.  
  1283. if event == "PLAYER_LOGIN" then
  1284. PlayerGUID = UnitGUID("player")
  1285. self:UnregisterEvent("PLAYER_LOGIN")
  1286.  
  1287.  
  1288. self:OnAddonLoaded()
  1289. self:Initialize()
  1290. self:CreateFrame()
  1291.  
  1292.  
  1293. elseif event == "COMBAT_LOG_EVENT_UNFILTERED" then
  1294. self:COMBAT_LOG_EVENT_UNFILTERED(...)
  1295. elseif event == "UNIT_AURA" then
  1296. --print("UNIT_AURA")
  1297. local unitID = ...
  1298. local uName, realm = UnitName(unitID)
  1299. if realm then
  1300. uName = uName.."-"..realm
  1301. end
  1302. local playerButton = self.Players[uName]
  1303. if playerButton then
  1304. self:UpdateBattlegroundSpecifics(playerButton, unitID)
  1305. end
  1306. elseif event == "PLAYER_TARGET_CHANGED" then
  1307. local uName, realm = UnitName("target")
  1308. if realm then
  1309. uName = uName.."-"..realm
  1310. end
  1311.  
  1312. if currentTarget and self.Players[currentTarget]then --player no longer targets this unit
  1313. self.Players[currentTarget]:SetBackdropBorderColor(0, 0, 0, 1)
  1314. end
  1315.  
  1316. local playerButton = self.Players[uName]
  1317. if playerButton then --player targets this unit now
  1318. playerButton:SetBackdropBorderColor(17, 27, 161, 1)
  1319. currentTarget = uName
  1320. end
  1321. self:ScanUnit("target")
  1322. self:UnitTargetChanged("player")
  1323. elseif event == "PLAYER_FOCUS_CHANGED" then
  1324. self:ScanUnit("focus")
  1325. elseif event == "UPDATE_MOUSEOVER_UNIT" then
  1326. self:ScanUnit("mouseover")
  1327. elseif event == "UNIT_TARGET" then
  1328. local unitID = ...
  1329. self:ScanUnit(unitID.."target")
  1330. if unitID:match("^raid%d+$") and UnitGUID(unitID) ~= PlayerGUID then
  1331. --print("target changed")
  1332. self:UnitTargetChanged(unitID)
  1333. end
  1334. elseif event == "UPDATE_BATTLEFIELD_SCORE" then
  1335. self:UPDATE_BATTLEFIELD_SCORE()
  1336. elseif event == "UNIT_HEALTH_FREQUENT" then --gets health of nameplates, player, target, focus, raid1 to raid40, partymember
  1337. self:ScanUnit(...)-- ... is unitID
  1338. elseif event == "NAME_PLATE_UNIT_ADDED" then
  1339. self:ScanUnit(...)--... is unitID
  1340. elseif event == "ARENA_OPPONENT_UPDATE" then
  1341. local unitID, unitEvent = ...
  1342.  
  1343. local uName, realm = UnitName(unitID)
  1344. if realm then
  1345. uName = uName.."-"..realm
  1346. end
  1347. if not uName then uName = ArenaIDToPlayername[unitID] end --when unitEvent == "cleared" then unitName is nil
  1348. --print("ARENA_OPPONENT_UPDATE", unitID, uName, unitEvent)
  1349. local playerButton = self.Players[uName]
  1350. if playerButton then
  1351. if unitEvent ~= "cleared" then
  1352. --print("Hallo")
  1353. -- "unseen", "seen" or "destroyed"
  1354.  
  1355. if BattlegroundBuff then
  1356. playerButton.Objective.Icon:SetTexture(GetSpellTexture(BattlegroundBuff))
  1357. end
  1358. C_PvP.RequestCrowdControlSpell(unitID)
  1359. ArenaIDToPlayername[unitID] = uName
  1360. playerButton:RegisterUnitEvent("UNIT_AURA", unitID)
  1361. else
  1362. playerButton.Objective.Icon:SetTexture(nil)
  1363. --print("Settexture nil")
  1364. playerButton.Objective.AuraText:SetText("")
  1365. ArenaIDToPlayername[unitID] = nil
  1366. playerButton:UnregisterAllEvents()
  1367. end
  1368.  
  1369. playerButton.PlayerDetails.BGSpecific = false
  1370. end
  1371.  
  1372. elseif event == "ARENA_CROWD_CONTROL_SPELL_UPDATE" then
  1373. local unitID, spellID = ...
  1374. if spellID ~= 72757 then --cogwheel (30 sec cooldown trigger)
  1375. local uName, realm = UnitName(unitID)
  1376. if realm then
  1377. uName = uName.."-"..realm
  1378. end
  1379. local playerButton = self.Players[uName]
  1380. if playerButton and self.spellIDToTrinketnumber[spellID] then
  1381. playerButton.PlayerDetails.Insi = self.spellIDToTrinketnumber[spellID]
  1382. playerButton.Insi.Icon:SetTexture(self.spellIDToTrinketFileId[spellID])
  1383. --playerButton.Insi.Icon:Show()
  1384. end
  1385. end
  1386. --print("ARENA_CROWD_CONTROL_SPELL_UPDATE fired")
  1387. 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
  1388. for i = 1, 4 do
  1389. local uName, realm = UnitName("arena"..i)
  1390. if realm then
  1391. uName = uName.."-"..realm
  1392. end
  1393. if uName then
  1394. local playerButton = self.Players[uName]
  1395. if playerButton then
  1396. local spellID, startTime, duration = C_PvP.GetArenaCrowdControlInfo("arena"..i)
  1397. if spellID then
  1398. if (startTime ~= 0 and duration ~= 0) then
  1399. playerButton.Insi.Cooldown:SetCooldown(startTime/1000.0, duration/1000.0)
  1400. playerButton.Insi.Cooldown:SetHideCountdownNumbers(false)
  1401. else
  1402. playerButton.Insi.Cooldown:Clear()
  1403. end
  1404. end
  1405. end
  1406. end
  1407. end
  1408. --print("ARENA_COOLDOWNS_UPDATE fired")
  1409. elseif event == "PLAYER_ENTERING_WORLD" then
  1410. local _, zone = IsInInstance()
  1411. if zone == "pvp" or zone == "arena" then
  1412. if zone == "arena" then
  1413. BrawlCheck = true
  1414. end
  1415.  
  1416. -- print("PLAYER_ENTERING_WORLD")
  1417. -- print("GetBattlefieldArenaFaction", GetBattlefieldArenaFaction())
  1418. -- print("C_PvP.IsInBrawl", C_PvP.IsInBrawl())
  1419. -- print("GetCurrentMapAreaID", GetCurrentMapAreaID())
  1420.  
  1421. wipe(self.PlayerSortingTable)
  1422. for name, playerButton in pairs(self.Players) do
  1423. table.insert(self.InactivePlayerButtons, playerButton) --to make them usable again
  1424. playerButton:Hide()
  1425. self.Players[name] = nil
  1426. end
  1427.  
  1428. OnUpdateFrame:Show()
  1429. self:RegisterEvent("UPDATE_BATTLEFIELD_SCORE")
  1430. else
  1431. self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  1432. self:UnregisterEvent("UPDATE_MOUSEOVER_UNIT")
  1433. self:UnregisterEvent("PLAYER_TARGET_CHANGED")
  1434. self:UnregisterEvent("PLAYER_FOCUS_CHANGED")
  1435. self:UnregisterEvent("UNIT_TARGET")
  1436. self:UnregisterEvent("UNIT_HEALTH_FREQUENT")
  1437. self:UnregisterEvent("UPDATE_BATTLEFIELD_SCORE")
  1438. self:UnregisterEvent("NAME_PLATE_UNIT_ADDED")
  1439. self:UnregisterEvent("ARENA_OPPONENT_UPDATE")--fires when a arena enemy appears and a frame is ready to be shown
  1440. self:UnregisterEvent("ARENA_CROWD_CONTROL_SPELL_UPDATE") --fires when data requested by C_PvP.RequestCrowdControlSpell(unitID) is available
  1441. 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
  1442.  
  1443. BrawlCheck = false
  1444. OnUpdateFrame:Hide()
  1445. self:Hide()
  1446. end
  1447. end
  1448. end
  1449.  
  1450.  
  1451.  
  1452. BattleGroundEnemys:RegisterEvent("ADDON_LOADED")
  1453. BattleGroundEnemys:RegisterEvent("PLAYER_LOGIN")
  1454. BattleGroundEnemys:RegisterEvent("PLAYER_ENTERING_WORLD")
  1455. BattleGroundEnemys:SetScript("OnEvent", BattleGroundEnemys.OnEvent)
  1456. --BattleGroundEnemys:RegisterEvent("UNIT_HEALTH_FREQUENT")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement