Guest User

WorldBossStatus.lua

a guest
Sep 21st, 2016
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.50 KB | None | 0 0
  1. local L = LibStub("AceLocale-3.0"):GetLocale("WorldBossStatus")
  2. WorldBossStatus = LibStub("AceAddon-3.0"):NewAddon("WorldBossStatus", "AceConsole-3.0", "AceEvent-3.0" );
  3.  
  4. local trackableCurrencies = {
  5. { id = 1273, legacy = false },
  6. { id = 392, legacy = true },
  7. { id = 823, legacy = true },
  8. { id = 824, legacy = true },
  9. { id = 994, legacy = true },
  10. { id = 1129, legacy = true },
  11. { id = 697, legacy = true },
  12. { id = 777, legacy = true },
  13. { id = 752, legacy = true },
  14. { id = 738, legacy = true },
  15. { id = 776, legacy = true }}
  16.  
  17.  
  18.  
  19.  
  20. --Honor Points = 392
  21. --Apexis Crystal = 823
  22. --Garison Resouces = 824
  23. --Seal of Tempered Fate = 994
  24.  
  25. for key,value in pairs(trackableCurrencies) do
  26. value.name, _, value.texture = GetCurrencyInfo(value.id)
  27. end
  28.  
  29. local textures = {}
  30.  
  31. textures.worldBossStatus = "Interface\\TARGETINGFRAME\\UI-RaidTargetingIcon_8.png"
  32. textures.alliance = "|TInterface\\FriendsFrame\\PlusManz-Alliance:18|t"
  33. textures.horde = "|TInterface\\FriendsFrame\\PlusManz-Horde:18|t"
  34. textures.bossDefeated = "|TInterface\\WorldMap\\Skull_64Red:18|t"
  35. textures.bossAvailable = "|TInterface\\WorldMap\\Skull_64Grey:18|t"
  36. textures.quest = "|TInterface\\Minimap\\OBJECTICONS:20:20:0:0:256:192:32:64:20:48|t"
  37.  
  38. local addonName = "WordBossStatus";
  39. local LDB = LibStub("LibDataBroker-1.1", true)
  40. local LDBIcon = LDB and LibStub("LibDBIcon-1.0", true)
  41. local LibQTip = LibStub('LibQTip-1.0')
  42.  
  43. local red = { r = 1.0, g = 0.2, b = 0.2 }
  44. local blue = { r = 0.4, g = 0.4, b = 1.0 }
  45. local green = { r = 0.2, g = 1.0, b = 0.2 }
  46. local yellow = { r = 1.0, g = 1.0, b = 0.2 }
  47. local gray = { r = 0.5, g = 0.5, b = 0.5 }
  48. local black = { r = 0.0, g = 0.0, b = 0.0 }
  49. local white = { r = 1.0, g = 1.0, b = 1.0 }
  50. local frame
  51.  
  52. local WOD_WORLD_BOSSES = {
  53. --TODO have questid
  54. { creatureIndex = 1, encounterIndex = 1790, legacy = false}, --"Ana-Mouz",
  55. { creatureIndex = 1, encounterIndex = 1770, legacy = false}, --"Humongris",
  56. { creatureIndex = 1, encounterIndex = 1783, legacy = false}, --"Na'zak the Fiend",
  57.  
  58. { creatureIndex = 1, encounterIndex = 1774, questId = 43193, legacy = false}, --"Calamir",
  59. { creatureIndex = 1, encounterIndex = 1789, questId = 43448, legacy = false}, --"Drugon the Frostblood",
  60. { creatureIndex = 1, encounterIndex = 1795, questId = 43985, legacy = false}, --"Flotsam",
  61. { creatureIndex = 1, encounterIndex = 1769, questId = 43192, legacy = false}, --"Levantus",
  62. { creatureIndex = 1, encounterIndex = 1749, questId = 42270, legacy = false}, --"Nithogg",
  63. { creatureIndex = 1, encounterIndex = 1763, questId = 42779, legacy = false}, --"Shar'thos", --The Sleeping Corruption
  64. { creatureIndex = 1, encounterIndex = 1756, questId = 42269, legacy = false, name = L["The Soultakers"]}, --"The Soultakers",
  65. { creatureIndex = 1, encounterIndex = 1796, questId = 44287, legacy = false}, --"Withered J'im",
  66.  
  67. { creatureIndex = 1, encounterIndex = 1452, questId = 94015, legacy = true },
  68. { creatureIndex = 1, encounterIndex = 1262, questId = 37464, legacy = true }, -- Rukhmar
  69. { creatureIndex = 1, encounterIndex = 1211, questId = 37462, legacy = true }, -- Tarlna the Ageless
  70. { creatureIndex = 1, encounterIndex = 1291, questId = 37462, legacy = true }, --37460
  71. { legacy = true, creatureIndex = 1, encounterIndex = 861 },
  72. { legacy = true, name = L["The Celestials"] },
  73. { legacy = true, creatureIndex = 1, encounterIndex = 826 },
  74. { legacy = true, creatureIndex = 1, encounterIndex = 814 },
  75. { legacy = true, creatureIndex = 1, encounterIndex = 725 },
  76. { legacy = true, creatureIndex = 1, encounterIndex = 691 } }
  77.  
  78. for _, boss in pairs(WOD_WORLD_BOSSES) do
  79. if not boss.name then
  80. _, boss.name = EJ_GetCreatureInfo(boss.creatureIndex, boss.encounterIndex)
  81. end
  82. end
  83.  
  84. local HOLIDAY_BOSS = nil
  85.  
  86. local WorldBossStatusLauncher = LDB:NewDataObject(addonName, {
  87. type = "data source",
  88. text = L["World Boss Status"],
  89. label = "WorldBossStatus",
  90. tocname = "WorldBossStatus",
  91. --"launcher",
  92. icon = textures.worldBossStatus,
  93. OnClick = function(clickedframe, button)
  94. WorldBossStatus:ShowOptions()
  95. end,
  96. OnEnter = function(self)
  97. frame = self
  98. WorldBossStatus:ShowToolTip()
  99. end,
  100. })
  101.  
  102. local defaults = {
  103. realm = {
  104. characters = {
  105. },
  106. },
  107. global = {
  108. realms = {
  109. },
  110. MinimapButton = {
  111. hide = false,
  112. },
  113. displayOptions = {
  114. showHintLine = true,
  115. showLegend = true,
  116. showMinimapButton = true,
  117. },
  118. characterOptions = {
  119. levelRestriction = true,
  120. minimumLevel = 110,
  121. removeInactive = true,
  122. inactivityThreshold = 28,
  123. include = 3,
  124. },
  125. bossOptions = {
  126. hideBoss = {
  127. },
  128. trackLegacyBosses = false,
  129. disableHoldidayBossTracking = false,
  130. },
  131. bonusRollOptions = {
  132. trackWeeklyQuests = true,
  133. trackedCurrencies = {
  134. [1129] = true,
  135. },
  136. trackLegacyCurrencies = false,
  137. },
  138. },
  139. };
  140.  
  141. local options = {
  142. handler = WorldBossStatus,
  143. type = "group",
  144. args = {
  145. features = {
  146. handler = WorldBossStatus,
  147. type = 'group',
  148. name = L["General Options"],
  149. desc = "",
  150. order = 10,
  151. args = {
  152. displayOptions = {
  153. type = 'group',
  154. inline = true,
  155. name = L["Display Options"],
  156. desc = "",
  157. order = 1,
  158. args = {
  159. showMiniMapButton = {
  160. type = "toggle",
  161. name = L["Minimap Button"],
  162. desc = L["Toggles the display of the minimap button."],
  163. get = "IsShowMinimapButton",
  164. set = "ToggleMinimapButton",
  165. order=1,
  166. },
  167. showHintLine = {
  168. type = "toggle",
  169. name = L["Hint Line"],
  170. desc = L["Toggles the display of the hint line."],
  171. get = function(info)
  172. return WorldBossStatus.db.global.displayOptions.showHintLine
  173. end,
  174. set = function(info, value)
  175. WorldBossStatus.db.global.displayOptions.showHintLine = value
  176. end,
  177. order = 2,
  178. },
  179. },
  180. },
  181.  
  182. },
  183. },
  184. characterOptions = {
  185. handler = WorldBossStatus,
  186. type = 'group',
  187. name = L["Character Options"],
  188. desc = "",
  189. order = 20,
  190. args = {
  191. inlcudeCharactersOptions = {
  192. type = 'group',
  193. inline = true,
  194. name = L["Show Characters"],
  195. desc = "",
  196. order = 1,
  197. args = {
  198. realmOption = {
  199. type = "toggle",
  200. name = L["On this realm"],
  201. desc = L["Show characters on this realm."],
  202. get = function(info)
  203. return WorldBossStatus.db.global.characterOptions.include == 2
  204. end,
  205. set = function(info, value)
  206. if value then
  207. WorldBossStatus.db.global.characterOptions.include = 2
  208. else
  209. WorldBossStatus.db.global.characterOptions.include = 1
  210. end
  211. end,
  212. order=1,
  213. },
  214. accountOption = {
  215. type = "toggle",
  216. name = L["On this account"],
  217. desc = L["Show characters on this WoW account."],
  218. get = function(info)
  219. return WorldBossStatus.db.global.characterOptions.include == 3
  220. end,
  221. set = function(info, value)
  222. if value then
  223. WorldBossStatus.db.global.characterOptions.include = 3
  224. else
  225. WorldBossStatus.db.global.characterOptions.include = 1
  226. end
  227. end,
  228. order=2,
  229. },
  230. },
  231. },
  232. characterLevelOptions = {
  233. type= "group",
  234. inline = true,
  235. name = L["Level Restriction"],
  236. desc = "",
  237. order=5,
  238. args = {
  239. enableLevelRestriction = {
  240. type = "toggle",
  241. name = L["Enable"],
  242. desc = L["Enable level restriction."],
  243. get = function(info)
  244. return WorldBossStatus.db.global.characterOptions.levelRestriction
  245. end,
  246. set = function(info, value)
  247. WorldBossStatus.db.global.characterOptions.levelRestriction = value
  248. end,
  249. order=1,
  250. },
  251. minimumLevelOption = {
  252. type = "range",
  253. name = L["Minimum Level"],
  254. desc = L["Show characters this level and higher."],
  255. step = 1, min = 1, max = 110,
  256. order = 2,
  257. get = function(info)
  258. return WorldBossStatus.db.global.characterOptions.minimumLevel
  259. end,
  260. set = function(info, value)
  261. WorldBossStatus.db.global.characterOptions.minimumLevel = value
  262. end,
  263. disabled = function()
  264. return not WorldBossStatus.db.global.characterOptions.levelRestriction
  265. end,
  266. },
  267. },
  268. },
  269. hideInactiveOptions = {
  270. type= "group",
  271. inline = true,
  272. name = L["Hide Inactive Characters"],
  273. desc = "",
  274. order=6,
  275. args = {
  276. purgeInactiveCharacters = {
  277. type = "toggle",
  278. name = L["Enable"],
  279. desc = L["Enable hiding inactive characters."],
  280. get = function(info)
  281. return WorldBossStatus.db.global.characterOptions.removeInactive
  282. end,
  283. set = function(info, value)
  284. WorldBossStatus.db.global.characterOptions.removeInactive = value
  285. end,
  286. order=1,
  287. },
  288. inactivityThresholdOption = {
  289. type = "range",
  290. name = L["Inactivity Threshold (days)"],
  291. desc = L["Hide characters that have been inactive for this many days."],
  292. step = 1, min = 14, max = 42,
  293. order = 2,
  294. get = function(info)
  295. return WorldBossStatus.db.global.characterOptions.inactivityThreshold
  296. end,
  297. set = function(info, value)
  298. WorldBossStatus.db.global.characterOptions.inactivityThreshold = value
  299. end,
  300. disabled = function()
  301. return not WorldBossStatus.db.global.characterOptions.removeInactive
  302. end,
  303. },
  304. },
  305. },
  306. trackedCharactersOption = {
  307. type = "group",
  308. inline = true,
  309. name = L["Remove Tracked Characters"],
  310. desc = "",
  311. order = 7,
  312. args = {
  313. realmSelect = {
  314. type = "select",
  315. name = L["Realm"],
  316. desc = L["Select a realm to remove a tracked character from."],
  317. order = 1,
  318. values = function()
  319. local realmList = {}
  320.  
  321. for realm in pairs(WorldBossStatus.db.global.realms) do
  322. realmList[realm] = realm
  323. end
  324.  
  325. return realmList
  326. end,
  327. get = function(info)
  328. return selectedRealm
  329. end,
  330. set = function(info, value)
  331. selectedRealm = value
  332. selectedCharacter = nil
  333. end,
  334. },
  335. characterSelect = {
  336. type = "select",
  337. name = L["Character"],
  338. desc = L["Select the tracked character to remove."],
  339. order = 2,
  340. disabled = function()
  341. return selectedRealm == nil
  342. end,
  343. values = function()
  344. local list = {}
  345. local realmInfo = WorldBossStatus.db.global.realms[selectedRealm]
  346. if realmInfo then
  347. local characters = realmInfo.characters
  348.  
  349. for key,value in pairs(characters) do
  350. list[key] = key
  351. end
  352. end
  353. return list
  354. end,
  355. get = function(info)
  356. return selectedCharacter
  357. end,
  358. set = function(info, value)
  359. selectedCharacter = value
  360. end,
  361. },
  362. removeAction = {
  363. type = "execute",
  364. name = L["Remove"],
  365. desc = L["Click to remove the selected tracked character."],
  366. order = 3,
  367. disabled = function()
  368. return selectedRealm == nil or selectedCharacter == nil
  369. end,
  370. func = function()
  371.  
  372. local realmInfo = WorldBossStatus.db.global.realms[selectedRealm]
  373. local characterInfo = realmInfo.characters[selectedCharacter]
  374. local count = 0
  375.  
  376. if not realmInfo then
  377. return
  378. end
  379.  
  380. if characterInfo then
  381. realmInfo.characters[selectedCharacter] = nil
  382. end
  383.  
  384. for key,value in pairs(realmInfo.characters) do
  385. count = count + 1
  386. end
  387.  
  388. if count == 0 then
  389. WorldBossStatus.db.global.realms[selectedRealm] = nil
  390. end
  391. end,
  392. },
  393. },
  394. },
  395. }
  396. },
  397. bossTracking = {
  398. type = "group",
  399. name = L["Boss Options"],
  400. handler = WorldBossStatus,
  401. desc = "",
  402. order = 30,
  403. args = {
  404. trackHoldidayBosses = {
  405. type = "toggle",
  406. name = L["Track holiday bosses"],
  407. desc = L["Automatically track holiday bosses during world events."],
  408. get = function(info)
  409. return not WorldBossStatus.db.global.bossOptions.disableHoldidayBossTracking
  410. end,
  411. set = function(info, value)
  412. WorldBossStatus.db.global.bossOptions.disableHoldidayBossTracking = not value
  413. end,
  414. order=1,
  415. },
  416. trackedBosses = {
  417. type = "multiselect",
  418. name = L["Tracked Bosses"],
  419. desc = L["Select the world bosses you would like to track."],
  420. width = "full",
  421. values = "GetWorldBossOptions",
  422. get = function(info, key)
  423. return not WorldBossStatus.db.global.bossOptions.hideBoss[WOD_WORLD_BOSSES[key].name]
  424. end,
  425. set = function(info, key, value)
  426. WorldBossStatus.db.global.bossOptions.hideBoss[WOD_WORLD_BOSSES[key].name] = not value
  427. end,
  428. order=2
  429. },
  430. trackLegacyBosses = {
  431. type = "toggle",
  432. name = L["Track legacy bosses"],
  433. desc = L["Enable tracking of older legacy world bosses."],
  434. get = function(info)
  435. return WorldBossStatus.db.global.bossOptions.trackLegacyBosses
  436. end,
  437. set = function(info, value)
  438. WorldBossStatus.db.global.bossOptions.trackLegacyBosses = value
  439. end,
  440. order=3,
  441. },
  442. trackedLegacyBosses = {
  443. type = "multiselect",
  444. name = L["Tracked Legacy Bosses"],
  445. desc = L["Select the legacy world bosses you would like to track."],
  446. width = "full",
  447. values = "GetLegacyWorldBossOptions",
  448. get = function(info, key)
  449. return not WorldBossStatus.db.global.bossOptions.hideBoss[WOD_WORLD_BOSSES[key].name]
  450. end,
  451. set = function(info, key, value)
  452. WorldBossStatus.db.global.bossOptions.hideBoss[WOD_WORLD_BOSSES[key].name] = not value
  453. end,
  454. disabled = function()
  455. return not WorldBossStatus.db.global.bossOptions.trackLegacyBosses
  456. end,
  457. order=4
  458. },
  459. }
  460. },
  461. bonusRollTracking = {
  462. type = "group",
  463. --inline = true,
  464. handler = WorldBossStatus,
  465. name = L["Bonus Roll Options"],
  466. desc = "",
  467. order = 40,
  468. args = {
  469. trackQuests = {
  470. type = "toggle",
  471. name = L["Track weekly quests"],
  472. desc = L["Enable tracking the weekly 'Sealing Fate' quests."],
  473. width = "full",
  474. get = function(info)
  475. return WorldBossStatus.db.global.bonusRollOptions.trackWeeklyQuests
  476. end,
  477. set = function(info, value)
  478. WorldBossStatus.db.global.bonusRollOptions.trackWeeklyQuests = value
  479. end,
  480. order=1,
  481. },
  482. trackedCurrencies = {
  483. type = "multiselect",
  484. name = L["Tracked Currencies"],
  485. desc = L["Select the currencies you would like to track."],
  486. width = "full",
  487. values = "GetCurrencyOptions",
  488. get = function(info, key)
  489. return WorldBossStatus.db.global.bonusRollOptions.trackedCurrencies[trackableCurrencies[key].id]
  490. end,
  491. set = function(info, key, value)
  492. WorldBossStatus.db.global.bonusRollOptions.trackedCurrencies[trackableCurrencies[key].id] = value
  493. end,
  494. order=2,
  495. },
  496.  
  497. trackLegacyCurrency = {
  498. type = "toggle",
  499. name = L["Track legacy currencies"],
  500. desc = L["Enable tracking of older legacy bonus roll currencies."],
  501. get = function(info)
  502. return WorldBossStatus.db.global.bonusRollOptions.trackLegacyCurrencies
  503. end,
  504. set = function(info, value)
  505. WorldBossStatus.db.global.bonusRollOptions.trackLegacyCurrencies = value
  506. end,
  507. order=3,
  508. },
  509. trackedLegacyCurrencies = {
  510. type = "multiselect",
  511. name = L["Tracked Legacy Currencies"],
  512. desc = L["Select the legacy currencies you would like to track."],
  513. width = "full",
  514. values = "GetLegacyCurrencyOptions",
  515. get = function(info, key)
  516. return WorldBossStatus.db.global.bonusRollOptions.trackedCurrencies[trackableCurrencies[key].id]
  517. end,
  518. set = function(info, key, value)
  519. WorldBossStatus.db.global.bonusRollOptions.trackedCurrencies[trackableCurrencies[key].id] = value
  520. end,
  521. disabled = function()
  522. return not WorldBossStatus.db.global.bonusRollOptions.trackLegacyCurrencies
  523. end,
  524. order=4,
  525. },
  526. }
  527. }
  528. }
  529. }
  530.  
  531. function WorldBossStatus:GetCurrencyOptions()
  532. local itemsList = {}
  533.  
  534. for key,value in pairs(trackableCurrencies) do
  535. if not value.legacy then
  536. itemsList[key] = "|T"..value.texture..":14:14:0:0:64:64:4:60:4:60|t "..value.name
  537. end
  538. end
  539.  
  540. return itemsList
  541. end
  542.  
  543. function WorldBossStatus:GetLegacyCurrencyOptions()
  544. local itemsList = {}
  545.  
  546. for key,value in pairs(trackableCurrencies) do
  547. if (value.legacy) then
  548. itemsList[key] = "|T"..value.texture..":14:14:0:0:64:64:4:60:4:60|t "..value.name
  549. end
  550. end
  551.  
  552. return itemsList
  553. end
  554.  
  555. function WorldBossStatus:GetWorldBossOptions()
  556. local itemsList = {}
  557.  
  558. for key,value in pairs(WOD_WORLD_BOSSES) do
  559. if not value.legacy then
  560. itemsList[key] = value.name
  561. end
  562. end
  563.  
  564. return itemsList
  565. end
  566.  
  567. function WorldBossStatus:GetLegacyWorldBossOptions()
  568. local itemsList = {}
  569.  
  570. for key,value in pairs(WOD_WORLD_BOSSES) do
  571. if value.legacy then
  572. itemsList[key] = value.name
  573. end
  574. end
  575.  
  576. return itemsList
  577.  
  578. end
  579.  
  580. local function CleanupCharacters()
  581. local threshold = WorldBossStatus.db.global.characterOptions.inactivityThreshold * (24 * 60 * 60)
  582.  
  583. if not WorldBossStatus.db.global.characterOptions.removeInactive or threshold == 0 then
  584. return
  585. end
  586.  
  587.  
  588. for realm in pairs(WorldBossStatus.db.global.realms) do
  589. local realmInfo = self.db.global.realms[realm]
  590. local characters = nil
  591.  
  592. if realmInfo then
  593. local characters = realmInfo.characters
  594.  
  595. for key,value in pairs(characters) do
  596. if value.lastUpdate and value.lastUpdate < time() - threshold then
  597. value = nil
  598. end
  599. end
  600.  
  601. end
  602. end
  603.  
  604. end
  605.  
  606. function WorldBossStatus:DisplayCharacterInTooltip(characterName, characterInfo)
  607. local tooltip = WorldBossStatus.tooltip
  608. local line = tooltip:AddLine()
  609. local factionIcon = ""
  610. local coins = 0
  611. local seals = 0
  612.  
  613. if characterInfo.faction and characterInfo.faction == "Alliance" then
  614. factionIcon = textures.alliance
  615. elseif characterInfo.faction and characterInfo.faction == "Horde" then
  616. factionIcon = textures.horde
  617. end
  618.  
  619. tooltip:SetCell(line, 2, factionIcon.." "..characterName)
  620.  
  621. if (characterInfo.bonusRolls) then
  622. coins = characterInfo.bonusRolls.questCurrency
  623. seals = characterInfo.bonusRolls.rolls
  624. end
  625.  
  626. column = 2
  627.  
  628. for key,currency in pairs(trackableCurrencies) do
  629. if (not currency.legacy or WorldBossStatus.db.global.bonusRollOptions.trackLegacyCurrencies) and WorldBossStatus.db.global.bonusRollOptions.trackedCurrencies[currency.id] then
  630. column = column + 1
  631. if (characterInfo.bonusRolls and characterInfo.bonusRolls.currency and characterInfo.bonusRolls.currency[currency.id]) then
  632. tooltip:SetCell(line, column, characterInfo.bonusRolls.currency[currency.id], nil, "RIGHT")
  633. end
  634. end
  635. end
  636.  
  637.  
  638. if (WorldBossStatus.db.global.bonusRollOptions.trackWeeklyQuests) then
  639. local seals = nil
  640. column = column +1
  641.  
  642. if characterInfo.bonusRolls.sealsCollected then
  643. if time() < characterInfo.bonusRolls.questsReset then
  644. seals = characterInfo.bonusRolls.sealsCollected.."/3"
  645. else
  646. seals = "0/3"
  647. end
  648. end
  649.  
  650. if seals then
  651. tooltip:SetCell(line, column, seals)
  652. end
  653. end
  654.  
  655. column = column + 1
  656.  
  657. if HOLIDAY_BOSS and not WorldBossStatus.db.global.bossOptions.disableHoldidayBossTracking then
  658. local boss = HOLIDAY_BOSS
  659. local defeated = (characterInfo.holidayBossKills and characterInfo.holidayBossKills[boss] and characterInfo.holidayBossKills[boss] > time())
  660.  
  661. if defeated then
  662. tooltip:SetCell(line, column, textures.bossDefeated)
  663. else
  664. tooltip:SetCell(line, column, textures.bossAvailable )
  665. end
  666.  
  667. if characterInfo.class then
  668. local color = RAID_CLASS_COLORS[characterInfo.class]
  669. tooltip:SetCellTextColor(line, 2, color.r, color.g, color.b)
  670. end
  671.  
  672. column = column+1
  673. end
  674.  
  675. for _, boss in pairs(WOD_WORLD_BOSSES) do
  676. if (not boss.legacy or WorldBossStatus.db.global.bossOptions.trackLegacyBosses) and not WorldBossStatus.db.global.bossOptions.hideBoss[boss.name] then
  677. local defeated = (characterInfo.bossKills[boss.name] and characterInfo.bossKills[boss.name] > time())
  678.  
  679. if defeated then
  680. tooltip:SetCell(line, column, textures.bossDefeated)
  681. else
  682. tooltip:SetCell(line, column, textures.bossAvailable )
  683. end
  684.  
  685. column = column+1
  686. end
  687. end
  688.  
  689. if characterInfo.class then
  690. local color = RAID_CLASS_COLORS[characterInfo.class]
  691. tooltip:SetCellTextColor(line, 2, color.r, color.g, color.b)
  692. end
  693.  
  694. end
  695.  
  696.  
  697. function WorldBossStatus:IsShowMinimapButton(info)
  698. return not self.db.global.MinimapButton.hide
  699. end
  700.  
  701. function WorldBossStatus:ToggleMinimapButton(info, value)
  702. self.db.global.MinimapButton.hide = not value
  703.  
  704. if self.db.global.MinimapButton.hide then
  705. LDBIcon:Hide(addonName)
  706. else
  707. LDBIcon:Show(addonName)
  708. end
  709.  
  710. LDBIcon:Refresh(addonName)
  711. LDBIcon:Refresh(addonName)
  712. end
  713.  
  714. function WorldBossStatus:ShowOptions()
  715. InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
  716. InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
  717. end
  718.  
  719. function WorldBossStatus:OnInitialize()
  720. self.db = LibStub("AceDB-3.0"):New("WorldBossStatusDB", defaults, true)
  721.  
  722. LDBIcon:Register(addonName, WorldBossStatusLauncher, self.db.global.MinimapButton)
  723.  
  724. local wbscfg = LibStub("AceConfig-3.0")
  725. wbscfg:RegisterOptionsTable("World Boss Status", options)
  726. wbscfg:RegisterOptionsTable("World Boss Status Features", options.args.features)
  727. wbscfg:RegisterOptionsTable("World Boss Status Characters", options.args.characterOptions)
  728. wbscfg:RegisterOptionsTable("World Boss Status Bosses", options.args.bossTracking)
  729. wbscfg:RegisterOptionsTable("World Boss Status Bonus Rolls", options.args.bonusRollTracking)
  730.  
  731.  
  732. local wbsdia = LibStub("AceConfigDialog-3.0")
  733.  
  734. self.optionsFrame = wbsdia:AddToBlizOptions("World Boss Status Features", L["World Boss Status"])
  735. wbsdia:AddToBlizOptions("World Boss Status Characters", L["Characters"], L["World Boss Status"])
  736. wbsdia:AddToBlizOptions("World Boss Status Bosses", L["Bosses"], L["World Boss Status"])
  737. wbsdia:AddToBlizOptions("World Boss Status Bonus Rolls", L["Bonus Rolls"], L["World Boss Status"])
  738.  
  739. RequestRaidInfo()
  740. end
  741.  
  742. local function ShowHeader(tooltip, marker, headerName)
  743. line = tooltip:AddHeader()
  744.  
  745. if (marker) then
  746. tooltip:SetCell(line, 1, marker)
  747. end
  748.  
  749. tooltip:SetCell(line, 2, headerName, nil, nil, nil, nil, nil, 50)
  750. tooltip:SetCellTextColor(line, 2, yellow.r, yellow.g, yellow.b)
  751.  
  752. column = 2
  753.  
  754. for key,currency in pairs(trackableCurrencies) do
  755. if (not currency.legacy or WorldBossStatus.db.global.bonusRollOptions.trackLegacyCurrencies) and WorldBossStatus.db.global.bonusRollOptions.trackedCurrencies[currency.id] then
  756. column = column + 1
  757. tooltip:SetCell(line, column, "|T"..currency.texture..":0|t", nil, "RIGHT")
  758. end
  759. end
  760.  
  761. if (WorldBossStatus.db.global.bonusRollOptions.trackWeeklyQuests) then
  762. column = column + 1
  763. tooltip:SetCell(line, column, textures.quest, nil, "CENTER")
  764. end
  765.  
  766. column = column + 1
  767.  
  768. if HOLIDAY_BOSS and not WorldBossStatus.db.global.bossOptions.disableHoldidayBossTracking then
  769. tooltip:SetCell(line, column, HOLIDAY_BOSS, "CENTER")
  770. tooltip:SetCellTextColor(line, column, yellow.r, yellow.g, yellow.b)
  771. column = column+1
  772. end
  773.  
  774. for _, boss in pairs(WOD_WORLD_BOSSES) do
  775. if (not boss.legacy or WorldBossStatus.db.global.bossOptions.trackLegacyBosses) and not WorldBossStatus.db.global.bossOptions.hideBoss[boss.name] then
  776. tooltip:SetCell(line, column, boss.name, "CENTER")
  777. tooltip:SetCellTextColor(line, column, yellow.r, yellow.g, yellow.b)
  778. column = column+1
  779. end
  780. end
  781.  
  782. return line
  783. end
  784.  
  785. function WorldBossStatus:DisplayRealmInToolip(realmName)
  786. local realmInfo = self.db.global.realms[realmName]
  787. local characters = nil
  788. local collapsed = false
  789. local epoch = time() - (WorldBossStatus.db.global.characterOptions.inactivityThreshold * 24 * 60 * 60)
  790.  
  791. if realmInfo then
  792. characters = realmInfo.characters
  793. collapsed = realmInfo.collapsed
  794. end
  795.  
  796. local characterNames = {}
  797. local currentCharacterName = UnitName("player")
  798. local currentRealmName = GetRealmName()
  799. local tooltip = WorldBossStatus.tooltip
  800. local levelRestriction = WorldBossStatus.db.global.characterOptions.levelRestruction or false;
  801. local minimumLevel = 1
  802.  
  803. if WorldBossStatus.db.global.characterOptions.levelRestriction then
  804. minimumLevel = WorldBossStatus.db.global.characterOptions.minimumLevel
  805. if not minimumLevel then minimumLevel = 90 end
  806. end
  807.  
  808. if not characters then
  809. return
  810. end
  811.  
  812. for k,v in pairs(characters) do
  813. local inlcude = true
  814. if (realmName ~= currentRealmName or k ~= currentCharacterName) and
  815. (not WorldBossStatus.db.global.characterOptions.removeInactive or v.lastUpdate > epoch) and
  816. (v.level >= minimumLevel) then
  817. table.insert(characterNames, k);
  818. end
  819. end
  820.  
  821. if (table.getn(characterNames) == 0) then
  822. return
  823. end
  824.  
  825. table.sort(characterNames)
  826.  
  827. tooltip:AddSeparator(2,0,0,0,0)
  828.  
  829. if not collapsed then
  830. line = ShowHeader(tooltip, "|TInterface\\Buttons\\UI-MinusButton-Up:16|t", realmName)
  831.  
  832. tooltip:AddSeparator(3,0,0,0,0)
  833.  
  834. for k,v in pairs(characterNames) do
  835. WorldBossStatus:DisplayCharacterInTooltip(v, characters[v])
  836. end
  837.  
  838. tooltip:AddSeparator(1, 1, 1, 1, 1.0)
  839. else
  840. line = ShowHeader(tooltip, "|TInterface\\Buttons\\UI-PlusButton-Up:16|t", realmName)
  841. end
  842.  
  843. tooltip:SetCellTextColor(line, 2, yellow.r, yellow.g, yellow.b)
  844. tooltip:SetCellScript(line, 1, "OnMouseUp", RealmOnClick, realmName)
  845. end
  846.  
  847. function RealmOnClick(cell, realmName)
  848. WorldBossStatus.db.global.realms[realmName].collapsed = not WorldBossStatus.db.global.realms[realmName].collapsed
  849. WorldBossStatus:ShowToolTip()
  850. end
  851.  
  852. function WorldBossStatus:ShowToolTip()
  853. local tooltip = WorldBossStatus.tooltip
  854. local characterName = UnitName("player")
  855. local bossKills = WorldBossStatus:GetWorldBossKills()
  856. local holidayBossKills = WorldBossStatus:GetHolidayBossKills()
  857. local characters = WorldBossStatus.db.realm.characters
  858. local class, className = UnitClass("player")
  859. local includeCharacters = WorldBossStatus.db.global.characterOptions.include or 3
  860. local showHint = WorldBossStatus.db.global.displayOptions.showHintLine
  861.  
  862. if LibQTip:IsAcquired("WorldBossStatusTooltip") and tooltip then
  863. tooltip:Clear()
  864. else
  865. local columnCount = 3
  866.  
  867. RequestLFDPlayerLockInfo()
  868. WorldBossStatus:UpdateWorldBossKills();
  869.  
  870. if HOLIDAY_BOSS and not WorldBossStatus.db.global.bossOptions.disableHoldidayBossTracking then
  871. columnCount = columnCount + 1
  872. end
  873.  
  874. for _, boss in pairs(WOD_WORLD_BOSSES) do
  875. if (not boss.legacy or WorldBossStatus.db.global.bossOptions.trackLegacyBosses) and not WorldBossStatus.db.global.bossOptions.hideBoss[boss.name] then
  876. columnCount = columnCount + 1
  877. end
  878. end
  879.  
  880. for key,currency in pairs(trackableCurrencies) do
  881. if (not currency.legacy or WorldBossStatus.db.global.bonusRollOptions.trackLegacyCurrencies) and WorldBossStatus.db.global.bonusRollOptions.trackedCurrencies[currency.id] then
  882. columnCount = columnCount + 1
  883. end
  884. end
  885.  
  886. if WorldBossStatus.db.global.bonusRollOptions.trackWeeklyQuests then
  887. columnCount = columnCount + 1
  888. end
  889.  
  890. tooltip = LibQTip:Acquire("WorldBossStatusTooltip", columnCount, "CENTER", "LEFT", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER", "CENTER")
  891. WorldBossStatus.tooltip = tooltip
  892. end
  893.  
  894. line = tooltip:AddHeader(" ")
  895. tooltip:SetCell(1, 1, "|TInterface\\TARGETINGFRAME\\UI-RaidTargetingIcon_8:16|t "..L["World Boss Status"], nil, "LEFT", tooltip:GetColumnCount())
  896. tooltip:AddSeparator(6,0,0,0,0)
  897. ShowHeader(tooltip, nil, L["Character"])
  898. tooltip:AddSeparator(6,0,0,0,0)
  899.  
  900. local info = WorldBossStatus:GetCharacterInfo()
  901. WorldBossStatus:DisplayCharacterInTooltip(characterName, info)
  902. tooltip:AddSeparator(6,0,0,0,0)
  903. tooltip:AddSeparator(1, 1, 1, 1, 1.0)
  904.  
  905. if includeCharacters > 1 then
  906. WorldBossStatus:DisplayRealmInToolip(GetRealmName())
  907. end
  908.  
  909. if includeCharacters == 3 then
  910. realmNames = {}
  911.  
  912. for k,v in pairs(WorldBossStatus.db.global.realms) do
  913. if (k ~= GetRealmName()) then
  914. table.insert(realmNames, k);
  915. end
  916. end
  917.  
  918. for k,v in pairs(realmNames) do
  919. WorldBossStatus:DisplayRealmInToolip(v)
  920. end
  921. end
  922.  
  923. if showHint then
  924. local HIGHLIGHT_START = "\124cffffff00\124h"
  925. local HIGHLIGHT_END = "\124h\124r"
  926. line = tooltip:AddLine(" ")
  927. local hint = ""
  928. tooltip:SetCell(tooltip:GetLineCount(), 1, hint, nil, "LEFT", tooltip:GetColumnCount())
  929. else
  930. line = tooltip:AddLine(" ")
  931. tooltip:SetCell(tooltip:GetLineCount(), 1, L["Click to open the options menu"], nil, "LEFT", tooltip:GetColumnCount())
  932. end
  933.  
  934. if (frame) then
  935. tooltip:SetAutoHideDelay(0.01, frame)
  936. tooltip:SmartAnchorTo(frame)
  937. end
  938.  
  939. tooltip:UpdateScrolling()
  940. tooltip:Show()
  941. end
  942.  
  943. function WorldBossStatus:SaveCharacterInfo()
  944. local characterName = UnitName("player")
  945. local realmName = GetRealmName()
  946.  
  947. if not self.db.global.realms then
  948. self.db.global.realms = {}
  949. end
  950.  
  951. local realmInfo = self.db.global.realms[realmName]
  952.  
  953. if not realmInfo then
  954. realmInfo = {}
  955. realmInfo.characters = {}
  956. end
  957.  
  958. realmInfo.characters[characterName] = WorldBossStatus:GetCharacterInfo()
  959.  
  960.  
  961. self.db.global.realms[realmName] = realmInfo
  962. end
  963.  
  964. function WorldBossStatus:GetCharacterInfo()
  965. local characterInfo = {}
  966. local class, className = UnitClass("player")
  967. local level = UnitLevel("player")
  968. local englishFaction, localizedFaction = UnitFactionGroup("player")
  969.  
  970. characterInfo.bossKills = WorldBossStatus:GetWorldBossKills()
  971. characterInfo.holidayBossKills = WorldBossStatus:GetHolidayBossKills()
  972. characterInfo.lastUpdate = time()
  973. characterInfo.class = className
  974. characterInfo.level = level
  975. characterInfo.faction = englishFaction
  976. characterInfo.bonusRolls = WorldBossStatus:GetBonusRollsStatus()
  977.  
  978. return characterInfo
  979. end
  980.  
  981. function WorldBossStatus:GetHolidayBossKills()
  982. local holidayBossStatus = {}
  983. local num = GetNumRandomDungeons()
  984. HOLIDAY_BOSS = nil
  985.  
  986. --RequestLFDPlayerLockInfo()
  987.  
  988. for i=1, num do
  989. local dungeonID, name = GetLFGRandomDungeonInfo(i);
  990. local _, _, _, _, _, _, _, _, _, _, _, _, _,desc, isHoliday = GetLFGDungeonInfo(dungeonID)
  991.  
  992. if isHoliday and dungeonID ~= 828 and desc ~= "" then
  993. local doneToday = GetLFGDungeonRewards(dungeonID)
  994. HOLIDAY_BOSS = name
  995. if doneToday then
  996. local expires = time() + GetQuestResetTime()
  997. holidayBossStatus[name] = expires
  998. end
  999. end
  1000. end
  1001.  
  1002. return holidayBossStatus
  1003. end
  1004.  
  1005. function WorldBossStatus:GetBonusRollsStatus()
  1006. local bonusRolls = {}
  1007.  
  1008. bonusRolls.currency = {}
  1009.  
  1010. for key,value in pairs(trackableCurrencies) do
  1011. _, balance = GetCurrencyInfo(value.id)
  1012. bonusRolls.currency[value.id] = balance
  1013. end
  1014.  
  1015. --37455 = Immense Fortune of Gold
  1016. --37457 = Tremendous Garrison Resources
  1017. --37459 = Monumental Honor
  1018. --37453 = Mountain of Apexis Crystals
  1019. --37454 = Piles of Gold
  1020. --37456 = Stockpiled Garrison Resources
  1021. --37458 = Extended Honor
  1022. --37452 = Heap of Apexis Crystals
  1023. --36054 = Sealing Fate: Gold
  1024. --36056 = Garrison Resources
  1025. --36057 = Sealing Fate: Honor
  1026. --36055 = Sealing Fate: Apexis Crystals
  1027. --36058 = Seal of Tempered Fate: Armory
  1028.  
  1029. bonusRolls.sealsCollected = 0
  1030.  
  1031. --Stage 1 Quests
  1032. if IsQuestFlaggedCompleted(36054) then
  1033. bonusRolls.sealsCollected = bonusRolls.sealsCollected + 1
  1034. end
  1035.  
  1036. if IsQuestFlaggedCompleted(36056) then
  1037. bonusRolls.sealsCollected = bonusRolls.sealsCollected + 1
  1038. end
  1039.  
  1040. if IsQuestFlaggedCompleted(36057) then
  1041. bonusRolls.sealsCollected = bonusRolls.sealsCollected + 1
  1042. end
  1043.  
  1044. if IsQuestFlaggedCompleted(36055) then
  1045. bonusRolls.sealsCollected = bonusRolls.sealsCollected + 1
  1046. end
  1047.  
  1048.  
  1049. --Stage 2 Quests
  1050. if IsQuestFlaggedCompleted(37454) then
  1051. bonusRolls.sealsCollected = bonusRolls.sealsCollected + 1
  1052. end
  1053.  
  1054. if IsQuestFlaggedCompleted(37456) then
  1055. bonusRolls.sealsCollected = bonusRolls.sealsCollected + 1
  1056. end
  1057.  
  1058. if IsQuestFlaggedCompleted(37458) then
  1059. bonusRolls.sealsCollected = bonusRolls.sealsCollected + 1
  1060. end
  1061.  
  1062. if IsQuestFlaggedCompleted(37452) then
  1063. bonusRolls.sealsCollected = bonusRolls.sealsCollected + 1
  1064. end
  1065.  
  1066.  
  1067. --Stage 3 Quests
  1068. if IsQuestFlaggedCompleted(37455) then
  1069. bonusRolls.sealsCollected = bonusRolls.sealsCollected + 1
  1070. end
  1071.  
  1072. if IsQuestFlaggedCompleted(37457) then
  1073. bonusRolls.sealsCollected = bonusRolls.sealsCollected + 1
  1074. end
  1075.  
  1076. if IsQuestFlaggedCompleted(37459) then
  1077. bonusRolls.sealsCollected = bonusRolls.sealsCollected + 1
  1078. end
  1079.  
  1080. if IsQuestFlaggedCompleted(37453) then
  1081. bonusRolls.sealsCollected = bonusRolls.sealsCollected + 1
  1082. end
  1083.  
  1084. --Armory Quest (Dwarven Bunker / War Mill)
  1085. if IsQuestFlaggedCompleted(36058) then
  1086. bonusRolls.sealsCollected = bonusRolls.sealsCollected + 1
  1087. end
  1088.  
  1089. bonusRolls.questsReset = WorldBossStatus:GetWeeklyQuestResetTime()
  1090.  
  1091. return bonusRolls
  1092. end
  1093.  
  1094. function WorldBossStatus:GetWeeklyQuestResetTime()
  1095. local TUESDAY = 2
  1096. local WEDNESDAY = 3
  1097. local THURSDAY = 4
  1098. local regionResets = {["US"] = TUESDAY, ["EU"] = WEDNESDAY, ["CN"] = THURSDAY, ["KR"] = THURSDAY, ["TW"] = THURSDAY};
  1099.  
  1100. --local region = GetCVar("realmList"):match("^(%a+)%."):upper()
  1101. local region = GetCVar("portal"):upper()
  1102. local resetWeekDay = regionResets[region]
  1103. local offset = WorldBossStatus:GetRealmOffset()
  1104.  
  1105. --WorldBossStatus:Print("Realm offset is: "..offset)
  1106.  
  1107. local nextReset = time() + GetQuestResetTime()
  1108.  
  1109. --WorldBossStatus:Print("Daily reset for "..region.. " in "..nextReset - time() .." seconds")
  1110.  
  1111. if not resetWeekDay then
  1112. return nil
  1113. end
  1114.  
  1115. while tonumber(date("%w", nextReset + offset)) ~= resetWeekDay do
  1116. nextReset = nextReset + (24 * 60 *60)
  1117. end
  1118.  
  1119. --WorldBossStatus:Print("Weekly reset for "..region.. " in "..nextReset - time() .." seconds")
  1120.  
  1121. return nextReset
  1122. end
  1123.  
  1124. function WorldBossStatus:GetRealmOffset()
  1125. local localDate = date("*t", time())
  1126. local realmDate = date("*t", time())
  1127.  
  1128. realmDate.wday, realmDate.month, realmDate.day, realmDate.year = CalendarGetDate();
  1129. realmDate.hour, realmDate.min = GetGameTime()
  1130.  
  1131. local localTime = time{year=localDate.year, month=localDate.month, day=localDate.day, hour=localDate.hour}
  1132. local realmTime = time{year=realmDate.year, month=realmDate.month, day=realmDate.day, hour=realmDate.hour}
  1133. local offset = realmTime - localTime
  1134.  
  1135. return offset
  1136. end
  1137.  
  1138. function WorldBossStatus:GetWorldBossKills()
  1139. local bossKills = {}
  1140. local num = GetNumSavedWorldBosses()
  1141.  
  1142. for _, v in pairs(WOD_WORLD_BOSSES) do
  1143. local expires = WorldBossStatus:GetWeeklyQuestResetTime()
  1144. if v.questId and IsQuestFlaggedCompleted(v.questId) then
  1145. bossKills[v.name] = expires
  1146. end
  1147. end
  1148.  
  1149. for i = 1, num do
  1150. local name, worldBossID, reset = GetSavedWorldBossInfo(i)
  1151. local expires = time() + reset
  1152.  
  1153. bossKills[name] = expires
  1154. end
  1155.  
  1156. return bossKills
  1157. end
  1158.  
  1159. function WorldBossStatus:UPDATE_INSTANCE_INFO()
  1160. WorldBossStatus:SaveCharacterInfo()
  1161. if LibQTip:IsAcquired("WorldBossStatusTooltip") and WorldBossStatus.tooltip then
  1162. WorldBossStatus:ShowToolTip()
  1163. end
  1164. end
  1165.  
  1166. function WorldBossStatus:LFG_UPDATE_RANDOM_INFO()
  1167. WorldBossStatus:SaveCharacterInfo()
  1168. if LibQTip:IsAcquired("WorldBossStatusTooltip") and WorldBossStatus.tooltip then
  1169. WorldBossStatus:ShowToolTip()
  1170. end
  1171. end
  1172.  
  1173. function WorldBossStatus:LFG_COMPLETION_REWARD()
  1174. RequestLFDPlayerLockInfo()
  1175. end
  1176.  
  1177. oldLogout = Logout;
  1178. oldQuit = Quit;
  1179.  
  1180. function WorldBossStatus:UpdateWorldBossKills()
  1181. RequestRaidInfo();
  1182. end
  1183.  
  1184.  
  1185. function Quit()
  1186. WorldBossStatus:UpdateWorldBossKills()
  1187. oldQuit();
  1188. end
  1189.  
  1190. function Logout()
  1191. WorldBossStatus:UpdateWorldBossKills()
  1192. oldLogout();
  1193. end
  1194.  
  1195. function WorldBossStatus:OnEnable()
  1196. self:RegisterEvent("UPDATE_INSTANCE_INFO");
  1197. self:RegisterEvent("LFG_UPDATE_RANDOM_INFO");
  1198. self:RegisterEvent("LFG_COMPLETION_REWARD");
  1199. end
  1200.  
  1201. function WorldBossStatus:OnDisable()
  1202. Self:UnregisterEvent("UPDATE_INSTANCE_INFO");
  1203. Self:UnregisterEvent("LFG_UPDATE_RANDOM_INFO");
  1204. Self:UnregisterEvent("LFG_COMPLETION_REWARD");
  1205. end
Add Comment
Please, Sign In to add comment