Advertisement
Guest User

Untitled

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