Advertisement
TehFurbolg

Blessed.lua - Warrior not working

Aug 8th, 2011
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.12 KB | None | 0 0
  1. --[[
  2. Blessed
  3. by Ailae of Emeriss-EU
  4.  
  5. Credits to zork (of Roth UI) for texture.
  6. ]]
  7.  
  8. local pguid
  9. local locked = true
  10.  
  11. -- default position
  12. local defaults = {
  13. framePoint = "CENTER",
  14. xOfs = 0,
  15. yOfs = -150,
  16. }
  17. local db
  18.  
  19. -- cosmetics
  20. local iconSize = 36
  21.  
  22. local Blessed = CreateFrame("Frame", nil, UIParent)
  23. Blessed:RegisterEvent("ADDON_LOADED")
  24.  
  25. Blessed:SetScript("OnEvent", function(self, event, ...)
  26. self[event](self, ...)
  27. end)
  28.  
  29. -- Add a prefix
  30. local function Print(...)
  31. print("|cff00aaffBlessed:|r", ...)
  32. end
  33.  
  34. -- Format: [spell] = (duration)
  35. local spells = {
  36. [1044] = 6, -- Hand of Freedom
  37. [1022] = 10, -- Hand of Protection
  38. [6940] = 12, -- Hand of Sacrifice
  39. [1038] = 10, -- Hand of Salvation
  40. [53563] = 300, -- Light's Beacon
  41. [54428] = 9, -- Divine Plea
  42. [53657] = 60, -- Judgement of the Pure (Rank 3, but who hasn't got 3/3 in this?)
  43. [87342] = 20, -- Holy Shield
  44. [84963] = 12, -- Inquisition
  45. [82327] = 10, -- Holy Radiance
  46. -- [88819] = 12, -- Daybreak
  47. [85433] = 10, -- Sacred Duty
  48. [94686] = 15, -- Crusader
  49. [54149] = 15, -- Infusion of Light
  50. [91155] = 120, -- Core of Ripeness
  51. [498] = 12, -- Divine Protection
  52. [86150] = 18, -- Guardian of Ancient Kings
  53. [91024] = 20, -- Theralion's Mirror
  54. [74241] = 12, -- Power Torrent
  55. [74243] = 10, -- Windwalk
  56. [86627] = 10, -- Incite (Warrior)
  57. [871] = 12, -- Shield Wall
  58. }
  59.  
  60. local INQUISITION = GetSpellInfo(84963)
  61. local colors = setmetatable({
  62. DEATHKNIGHT = "c41e3a",
  63. DRUID = "ff7c0a",
  64. HUNTER = "aad372",
  65. MAGE = "68ccef",
  66. PALADIN = "f48cba",
  67. PRIEST = "ffffff",
  68. ROGUE = "fff468",
  69. SHAMAN = "0070dd",
  70. WARLOCK = "9382c9",
  71. WARRIOR = "c69b6d",
  72. }, { __index = function()
  73. return "ffffff"
  74. end
  75. })
  76.  
  77. -- Empty tables for our frames
  78. local frames = {}
  79. local framePool = {}
  80.  
  81. function Blessed:Init()
  82. self:SetBackdrop({
  83. bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
  84. insets = {top = 0, left = 0, bottom = 0, right = 0},
  85. })
  86. self:SetBackdropColor(1, 1, 1, 0)
  87.  
  88. self:SetWidth(iconSize)
  89. self:SetHeight(iconSize)
  90. self:SetPoint(db.framePoint, db.xOfs, db.yOfs)
  91.  
  92. self:SetMovable(true)
  93.  
  94. self:SetScript("OnMouseDown", function()
  95. if(IsShiftKeyDown() and not locked) then
  96. self:ClearAllPoints()
  97. self:StartMoving()
  98. end
  99. end)
  100.  
  101. self:SetScript("OnMouseUp", function()
  102. self:StopMovingOrSizing()
  103. db.framePoint, _, _, db.xOfs, db.yOfs = self:GetPoint()
  104. end)
  105.  
  106. local text = self:CreateFontString(nil, "OVERLAY")
  107. text:SetFontObject(SystemFont_Shadow_Med1)
  108. text:SetPoint("TOP", self, "TOP", 0, 16)
  109. text:SetTextColor(1, 0.82, 0)
  110. self.header = text
  111. end
  112.  
  113. function Blessed:ADDON_LOADED(name)
  114. if name ~= "Blessed" then return end
  115. self:UnregisterEvent("ADDON_LOADED")
  116.  
  117. BlessedDB = BlessedDB or defaults
  118. db = BlessedDB
  119.  
  120. local class = select(2, UnitClass("player"))
  121. if class then
  122. self:RegisterEvent("PLAYER_ENTERING_WORLD")
  123. self:Init()
  124.  
  125. SLASH_Blessed1 = "/blessed"
  126. SlashCmdList.Blessed = function(input)
  127. local input = string.lower(input)
  128. if (input == "test") then
  129. self:SetupIcon(54428, "Test Icon", pguid)
  130. Print("Showing test-timer.")
  131. elseif (input == "lock") then
  132. if locked then
  133. self.header:SetText("Blessed")
  134. self:SetBackdropColor(1, 1, 1, 0.25)
  135. Print("Unlocked. Press down SHIFT and drag the square to move.")
  136. else
  137. self.header:SetText("")
  138. self:SetBackdropColor(1, 1, 1, 0)
  139. Print("Locked.")
  140. end
  141. locked = not locked
  142. self:EnableMouse(not locked)
  143. elseif input == "size" then
  144. Print("Active frames:", #frames)
  145. Print("Pool:", #framePool)
  146. Print("Total:", #frames+#framePool)
  147. else
  148. Print("Incorrect or no command given. Please use '/blessed test' (display a test-timer) or '/blessed lock' (to toggle lock).")
  149. end
  150. end
  151. else
  152. Print("This addon has no use for any other class than a Paladin, you should consider disabling it for this character.")
  153. end
  154. end
  155.  
  156. -- Only activate buff-tracking if the player is a paladin
  157. function Blessed:PLAYER_ENTERING_WORLD()
  158. self:UnregisterEvent("PLAYER_ENTERING_WORLD")
  159. self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  160.  
  161. pguid = UnitGUID("player")
  162.  
  163. -- this is to make sure talents are loaded or if we need
  164. -- to delay the check
  165. if (GetNumTalentTabs() == 0) then
  166. self:RegisterEvent("PLAYER_ALIVE")
  167. else
  168. self:UpdateDurations()
  169. end
  170.  
  171. self.PLAYER_ALIVE = self.UpdateDurations
  172.  
  173. self:RegisterEvent("CHARACTER_POINTS_CHANGED")
  174. self:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
  175. end
  176.  
  177. -- Check talents for updates
  178. function Blessed:UpdateDurations()
  179. -- Hand of Freedom
  180. local rank, maxRank = select(5, GetTalentInfo(3, 4))
  181. if rank == maxRank then
  182. spells[1044] = 10
  183. else
  184. spells[1044] = 6
  185. end
  186. self:UnregisterEvent("PLAYER_ALIVE")
  187. end
  188.  
  189. -- Perform checks for all these events
  190. Blessed.CHARACTER_POINTS_CHANGED = Blessed.UpdateDurations
  191. Blessed.ACTIVE_TALENT_GROUP_CHANGED = Blessed.UpdateDurations
  192.  
  193. -- Handle stuff, plx
  194. function Blessed:COMBAT_LOG_EVENT_UNFILTERED(timestamp, combatEvent, hideCaster, sourceGUID, sourceName, sourceFlags, sourceFlagsTwo, destGUID, destName, destFlags, destFlagsTwo, spellID, ...)
  195. if sourceGUID ~= pguid or not spells[spellID] then return end
  196.  
  197. if (combatEvent == "SPELL_AURA_REMOVED") then
  198. self:RemoveFrame(spellID, false)
  199. elseif (combatEvent == "SPELL_AURA_APPLIED") then
  200. self:SetupIcon(spellID, destName, destGUID)
  201. elseif (combatEvent == "SPELL_AURA_REFRESH") then
  202. self:RemoveFrame(spellID, true)
  203. self:SetupIcon(spellID, destName, destGUID)
  204. end
  205. end
  206.  
  207. -- Reanchor frames
  208. function Blessed:UpdateFrames()
  209. if #frames == 0 then return end
  210.  
  211. for i, frame in pairs(frames) do
  212. frame:ClearAllPoints()
  213. if i > 1 then
  214. frame:SetPoint("LEFT", frames[i - 1], "RIGHT", 15, 0)
  215. else
  216. frame:SetPoint("CENTER", self, "CENTER")
  217. end
  218. end
  219. end
  220.  
  221. -- Remove bar
  222. function Blessed:RemoveFrame(spellID, refresh)
  223. if #frames == 0 then return end
  224.  
  225. for i, frame in pairs(frames) do
  226. if frame.id == spellID then
  227. frame:Hide()
  228. table.remove(frames, i)
  229. table.insert(framePool, frame)
  230. self:UpdateFrames()
  231. end
  232. end
  233. end
  234.  
  235. -- Update barinfo
  236. local function update(self, elapsed)
  237. self.duration = self.duration - elapsed
  238. self.update = self.update - elapsed
  239. if self.update > 0 then return end
  240.  
  241. self.update = self.update + 1
  242.  
  243. if self.duration > 60 then
  244. self.timer:SetFormattedText("%.0fm", ceil(self.duration/60))
  245. else
  246. self.timer:SetFormattedText("%.0f", floor(self.duration))
  247. end
  248.  
  249. if self.duration <= 0 then
  250. Blessed:RemoveFrame(self.id)
  251. elseif self.duration <= 5 then
  252. self.timer:SetTextColor(1, 0, 0)
  253. end
  254. end
  255.  
  256. -- Framemananger, return a new frame if there's no old frame available
  257. function Blessed:GetFrame()
  258. if (#framePool > 0) then
  259. return table.remove(framePool, 1)
  260. end
  261.  
  262. local frame = CreateFrame("Frame", nil, UIParent)
  263. frame:SetSize(iconSize, iconSize)
  264. frame:SetPoint("CENTER", self)
  265.  
  266. -- Icon
  267. frame.icon = frame:CreateTexture(nil, "ARTWORK")
  268. frame.icon:SetSize(iconSize, iconSize)
  269. frame.icon:SetTexCoord(0.03, 0.97, 0.02, 0.97)
  270. frame.icon:SetAllPoints(frame)
  271.  
  272. -- Targettext
  273. frame.target = frame:CreateFontString(nil, "OVERLAY")
  274. frame.target:SetFontObject(SystemFont_Shadow_Med1)
  275. frame.target:SetPoint("BOTTOM", frame, "TOP", 0, 5)
  276. frame.target:SetTextColor(1, 1, 1)
  277. frame.target:SetShadowOffset(1, -1)
  278.  
  279. -- Timertext
  280. frame.timer = frame:CreateFontString(nil, "OVERLAY")
  281. frame.timer:SetFontObject(SystemFont_Shadow_Large)
  282. frame.timer:SetPoint("TOP", frame, "BOTTOM", 0, -5)
  283. frame.timer:SetTextColor(1, 1, 1)
  284. frame.timer:SetShadowOffset(1, -1)
  285.  
  286. -- Cooldown-model (beta)
  287. frame.cd = CreateFrame("Cooldown", nil, frame, "CooldownFrameTemplate")
  288. frame.cd:SetSize(iconSize, iconSize)
  289. frame.cd:SetPoint("TOPLEFT", frame, "TOPLEFT", 2, -2)
  290. frame.cd:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -2, 2)
  291. frame.cd.noCooldownCount = true -- prevent OmniCC if present
  292.  
  293. -- Border
  294. frame.border = frame:CreateTexture(nil, "OVERLAY")
  295. frame.border:SetParent(frame)
  296. frame.border:SetTexture('Interface\\AddOns\\Blessed\\simplesquare_roth')
  297. frame.border:SetPoint('TOPRIGHT', frame, 2, 2)
  298. frame.border:SetPoint('BOTTOMLEFT', frame, -2, -2)
  299. frame.border:SetVertexColor(0.3, 0.3, 0.3)
  300.  
  301. return frame
  302. end
  303.  
  304. -- Setup a timer
  305. function Blessed:SetupIcon(spellID, targetName, targetGUID)
  306. local frame = self:GetFrame()
  307. local duration = spells[spellID]
  308.  
  309. if spellID == 84963 then
  310. duration = select(6, UnitAura("player", INQUISITION))
  311. end
  312.  
  313. local icon = select(3, GetSpellInfo(spellID))
  314. local class = select(2, GetPlayerInfoByGUID(targetGUID))
  315.  
  316. frame.icon:SetTexture(icon)
  317. frame.target:SetFormattedText("|cff%s%s|r", colors[class], targetGUID ~= pguid and string.sub(targetName, 0, 3) or "You!")
  318.  
  319. if duration > 60 then
  320. frame.timer:SetFormattedText("%.0fm", ceil(duration/60))
  321. else
  322. frame.timer:SetFormattedText("%.0f", floor(duration))
  323. end
  324. frame.timer:SetTextColor(1, 1, 1)
  325.  
  326. frame.duration = duration
  327. frame.id = spellID
  328. frame.update = 1
  329. frame.cd:SetCooldown(GetTime(), duration)
  330. table.insert(frames, frame)
  331.  
  332. frame:SetScript("OnUpdate", update)
  333.  
  334. self:UpdateFrames()
  335. frame:Show()
  336. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement