Guest User

Untitled

a guest
Aug 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.90 KB | None | 0 0
  1. ----------------------------------------------------
  2. -- Interrupt Bar by Kollektiv
  3. ----------------------------------------------------
  4.  
  5. InterruptBarDB = InterruptBarDB or { scale = 1, hidden = false, lock = false, }
  6. local abilities = {}
  7. local order
  8. local band = bit.band
  9.  
  10. local spellids = {[6552] = 10, [2139] = 24, [19647] = 24, [1766] = 10, [47528] = 10, [57994] = 6, [47476] = 120, [2094] = 180, [85285] = 10, [80964] = 10}
  11. for spellid,time in pairs(spellids) do
  12. local name,_,spellicon = GetSpellInfo(spellid)
  13. abilities[name] = { icon = spellicon, duration = time }
  14. end
  15.  
  16. -----------------------------------------------------
  17. -- Edit this table to change the order
  18. -----------------------------------------------------
  19. -- 6552 Pummel
  20. -- 2139 Counterspell
  21. -- 19647 Spell Lock
  22. -- 1766 Kick
  23. -- 47528 Mind Freeze
  24. -- 57994 Wind Shear
  25. -- 85285 Rebuke
  26. -- 47476 Strangulate
  27. -- 2094 Blind
  28. -- 80964 Skull Bash
  29.  
  30. -----------------------------------------------------
  31.  
  32. local order = {6552, 2139, 19647, 1766, 47528, 57994, 85285, 2094, 80964}
  33.  
  34. -----------------------------------------------------
  35. -----------------------------------------------------
  36.  
  37. for k,v in ipairs(order) do order[k] = GetSpellInfo(v) end
  38.  
  39. local frame
  40. local bar
  41.  
  42. local GetTime = GetTime
  43. local ipairs = ipairs
  44. local pairs = pairs
  45. local select = select
  46. local floor = floor
  47. local band = bit.band
  48. local GetSpellInfo = GetSpellInfo
  49.  
  50. local GROUP_UNITS = bit.bor(0x00000010, 0x00000400)
  51.  
  52. local activetimers = {}
  53.  
  54. local size = 0
  55. local function getsize()
  56. size = 0
  57. for k in pairs(activetimers) do
  58. size = size + 1
  59. end
  60. end
  61.  
  62. local function InterruptBar_AddIcons()
  63. local x = -45
  64. for _,ability in ipairs(order) do
  65. local btn = CreateFrame("Frame",nil,bar)
  66. btn:SetWidth(30)
  67. btn:SetHeight(30)
  68. btn:SetPoint("CENTER",bar,"CENTER",x,0)
  69. btn:SetFrameStrata("LOW")
  70.  
  71. local cd = CreateFrame("Cooldown",nil,btn)
  72. cd.noomnicc = true
  73. cd:SetAllPoints(true)
  74. cd:SetFrameStrata("MEDIUM")
  75. cd:Hide()
  76.  
  77. local texture = btn:CreateTexture(nil,"BACKGROUND")
  78. texture:SetAllPoints(true)
  79. texture:SetTexture(abilities[ability].icon)
  80. texture:SetTexCoord(0.07,0.9,0.07,0.90)
  81.  
  82. local text = cd:CreateFontString(nil,"ARTWORK")
  83. text:SetFont(STANDARD_TEXT_FONT,18,"OUTLINE")
  84. text:SetTextColor(1,1,0,1)
  85. text:SetPoint("LEFT",btn,"LEFT",2,0)
  86.  
  87. btn.texture = texture
  88. btn.text = text
  89. btn.duration = abilities[ability].duration
  90. btn.cd = cd
  91.  
  92. bar[ability] = btn
  93.  
  94. x = x + 30
  95. end
  96. end
  97.  
  98. local function InterruptBar_SavePosition()
  99. local point, _, relativePoint, xOfs, yOfs = bar:GetPoint()
  100. if not InterruptBarDB.Position then
  101. InterruptBarDB.Position = {}
  102. end
  103. InterruptBarDB.Position.point = point
  104. InterruptBarDB.Position.relativePoint = relativePoint
  105. InterruptBarDB.Position.xOfs = xOfs
  106. InterruptBarDB.Position.yOfs = yOfs
  107. end
  108.  
  109. local function InterruptBar_LoadPosition()
  110. if InterruptBarDB.Position then
  111. bar:SetPoint(InterruptBarDB.Position.point,UIParent,InterruptBarDB.Position.relativePoint,InterruptBarDB.Position.xOfs,InterruptBarDB.Position.yOfs)
  112. else
  113. bar:SetPoint("CENTER", UIParent, "CENTER")
  114. end
  115. end
  116.  
  117. local function InterruptBar_UpdateBar()
  118. bar:SetScale(InterruptBarDB.scale)
  119. if InterruptBarDB.hidden then
  120. for _,v in ipairs(order) do bar[v]:Hide() end
  121. else
  122. for _,v in ipairs(order) do bar[v]:Show() end
  123. end
  124. if InterruptBarDB.lock then
  125. bar:EnableMouse(false)
  126. else
  127. bar:EnableMouse(true)
  128. end
  129. end
  130.  
  131. local function InterruptBar_CreateBar()
  132. bar = CreateFrame("Frame", nil, UIParent)
  133. bar:SetMovable(true)
  134. bar:SetWidth(120)
  135. bar:SetHeight(30)
  136. bar:SetClampedToScreen(true)
  137. bar:SetScript("OnMouseDown",function(self,button) if button == "LeftButton" then self:StartMoving() end end)
  138. bar:SetScript("OnMouseUp",function(self,button) if button == "LeftButton" then self:StopMovingOrSizing() InterruptBar_SavePosition() end end)
  139. bar:Show()
  140.  
  141. InterruptBar_AddIcons()
  142. InterruptBar_UpdateBar()
  143. InterruptBar_LoadPosition()
  144. end
  145.  
  146. local function InterruptBar_UpdateText(text,cooldown)
  147. if cooldown < 10 then
  148. if cooldown <= 0.5 then
  149. text:SetText("")
  150. else
  151. text:SetFormattedText(" %d",cooldown)
  152. end
  153. else
  154. text:SetFormattedText("%d",cooldown)
  155. end
  156. if cooldown < 6 then
  157. text:SetTextColor(1,0,0,1)
  158. else
  159. text:SetTextColor(1,1,0,1)
  160. end
  161. end
  162.  
  163. local function InterruptBar_StopAbility(ref,ability)
  164. if InterruptBarDB.hidden then ref:Hide() end
  165. if activetimers[ability] then activetimers[ability] = nil end
  166. ref.text:SetText("")
  167. ref.cd:Hide()
  168. end
  169.  
  170. local time = 0
  171. local function InterruptBar_OnUpdate(self, elapsed)
  172. time = time + elapsed
  173. if time > 0.25 then
  174. getsize()
  175. for ability,ref in pairs(activetimers) do
  176. ref.cooldown = ref.start + ref.duration - GetTime()
  177. if ref.cooldown <= 0 then
  178. InterruptBar_StopAbility(ref,ability)
  179. else
  180. InterruptBar_UpdateText(ref.text,floor(ref.cooldown+0.5))
  181. end
  182. end
  183. if size == 0 then frame:SetScript("OnUpdate",nil) end
  184. time = time - 0.25
  185. end
  186. end
  187.  
  188. local function InterruptBar_StartTimer(ref,ability)
  189. if InterruptBarDB.hidden then
  190. ref:Show()
  191. end
  192. if not activetimers[ability] then
  193. local duration
  194. activetimers[ability] = ref
  195. ref.cd:Show()
  196. ref.cd:SetCooldown(GetTime()-0.40,ref.duration)
  197. ref.start = GetTime()
  198. InterruptBar_UpdateText(ref.text,ref.duration)
  199. end
  200. frame:SetScript("OnUpdate",InterruptBar_OnUpdate)
  201. end
  202.  
  203. local function InterruptBar_COMBAT_LOG_EVENT_UNFILTERED(...)
  204. local spellID, ability, useSecondDuration
  205. return function(_, eventtype, _, srcName, srcFlags, _, dstName, dstFlags, id)
  206. if (band(srcFlags, 0x00000040) == 0x00000040 and eventtype == "SPELL_CAST_SUCCESS") then
  207. spellID = id
  208. else
  209. return
  210. end
  211. useSecondDuration = false
  212. if spellID == 49376 then spellID = 16979; useSecondDuration = true end -- Feral Charge - Cat -> Feral Charge - Bear
  213. ability = GetSpellInfo(spellID)
  214. if abilities[ability] then
  215. if useSecondDuration and spellID == 16979 then
  216. bar[ability].duration = 30
  217. elseif spellID == 16979 then
  218. bar[ability].duration = 15
  219. end
  220. InterruptBar_StartTimer(bar[ability],ability)
  221. end
  222. end
  223. end
  224.  
  225. InterruptBar_COMBAT_LOG_EVENT_UNFILTERED = InterruptBar_COMBAT_LOG_EVENT_UNFILTERED()
  226.  
  227. local function InterruptBar_ResetAllTimers()
  228. for _,ability in ipairs(order) do
  229. InterruptBar_StopAbility(bar[ability])
  230. end
  231. active = 0
  232. end
  233.  
  234. local function InterruptBar_PLAYER_ENTERING_WORLD(self)
  235. InterruptBar_ResetAllTimers()
  236. end
  237.  
  238. local function InterruptBar_Reset()
  239. InterruptBarDB = { scale = 1, hidden = false, lock = false }
  240. InterruptBar_UpdateBar()
  241. InterruptBar_LoadPosition()
  242. end
  243.  
  244. local function InterruptBar_Test()
  245. for _,ability in ipairs(order) do
  246. InterruptBar_StartTimer(bar[ability],ability)
  247. end
  248. end
  249.  
  250. local cmdfuncs = {
  251. scale = function(v) InterruptBarDB.scale = v; InterruptBar_UpdateBar() end,
  252. hidden = function() InterruptBarDB.hidden = not InterruptBarDB.hidden; InterruptBar_UpdateBar() end,
  253. lock = function() InterruptBarDB.lock = not InterruptBarDB.lock; InterruptBar_UpdateBar() end,
  254. reset = function() InterruptBar_Reset() end,
  255. test = function() InterruptBar_Test() end,
  256. }
  257.  
  258. local cmdtbl = {}
  259. function InterruptBar_Command(cmd)
  260. for k in ipairs(cmdtbl) do
  261. cmdtbl[k] = nil
  262. end
  263. for v in gmatch(cmd, "[^ ]+") do
  264. tinsert(cmdtbl, v)
  265. end
  266. local cb = cmdfuncs[cmdtbl[1]]
  267. if cb then
  268. local s = tonumber(cmdtbl[2])
  269. cb(s)
  270. else
  271. ChatFrame1:AddMessage("InterruptBar Options | /ib <option>",0,1,0)
  272. ChatFrame1:AddMessage("-- scale <number> | value: " .. InterruptBarDB.scale,0,1,0)
  273. ChatFrame1:AddMessage("-- hidden (toggle) | value: " .. tostring(InterruptBarDB.hidden),0,1,0)
  274. ChatFrame1:AddMessage("-- lock (toggle) | value: " .. tostring(InterruptBarDB.lock),0,1,0)
  275. ChatFrame1:AddMessage("-- test (execute)",0,1,0)
  276. ChatFrame1:AddMessage("-- reset (execute)",0,1,0)
  277. end
  278. end
  279.  
  280. local function InterruptBar_OnLoad(self)
  281. self:RegisterEvent("PLAYER_ENTERING_WORLD")
  282. self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  283. if not InterruptBarDB.scale then InterruptBarDB.scale = 1 end
  284. if not InterruptBarDB.hidden then InterruptBarDB.hidden = false end
  285. if not InterruptBarDB.lock then InterruptBarDB.lock = false end
  286. InterruptBar_CreateBar()
  287.  
  288. SlashCmdList["InterruptBar"] = InterruptBar_Command
  289. SLASH_InterruptBar1 = "/ib"
  290.  
  291. ChatFrame1:AddMessage("Interrupt Bar by Kollektiv. Type /ib for options.",0,1,0)
  292. end
  293.  
  294. local eventhandler = {
  295. ["VARIABLES_LOADED"] = function(self) InterruptBar_OnLoad(self) end,
  296. ["PLAYER_ENTERING_WORLD"] = function(self) InterruptBar_PLAYER_ENTERING_WORLD(self) end,
  297. ["COMBAT_LOG_EVENT_UNFILTERED"] = function(self,...) InterruptBar_COMBAT_LOG_EVENT_UNFILTERED(...) end,
  298. }
  299.  
  300. local function InterruptBar_OnEvent(self,event,...)
  301. eventhandler[event](self,...)
  302. end
  303.  
  304. frame = CreateFrame("Frame",nil,UIParent)
  305. frame:SetScript("OnEvent",InterruptBar_OnEvent)
  306. frame:RegisterEvent("VARIABLES_LOADED")
Add Comment
Please, Sign In to add comment