Advertisement
Guest User

davechapally

a guest
Jul 27th, 2009
18,386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.17 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, [16979] = 15, [1766] = 10, [47528] = 10, [49576] = 25, [48827] = 30, [10308] = 40, [49203] = 60, [8643] = 20, [10890] = 27, [31224] = 60, [47476] = 120, [49231] = 6, [57994] = 6, }
  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. -- 16979 Feral Charge
  23. -- 1766 Kick
  24. -- 47528 Mind Freeze
  25. -- 49576 Death Grip
  26. -- 48827 Avenger's Shield
  27. -- 10308 Hammer of Justice
  28. -- 49203 Hungering Cold
  29. -- 8643 Kidney Shot
  30. -- 10880 Psychic Scream
  31. -- 31224 Cloak of Shadows
  32. -- 47476 Strangulate
  33. -- 57994 Wind Shock
  34. -----------------------------------------------------
  35.  
  36. local order = {6552, 2139, 19647, 16979, 1766, 47528, 49576, 48827, 10308, 49203, 8643, 10890, 31224, 47476, 57994}
  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:SetAllPoints(true)
  78. cd:SetFrameStrata("MEDIUM")
  79. cd:Hide()
  80.  
  81. local texture = btn:CreateTexture(nil,"BACKGROUND")
  82. texture:SetAllPoints(true)
  83. texture:SetTexture(abilities[ability].icon)
  84. texture:SetTexCoord(0.07,0.9,0.07,0.90)
  85.  
  86. local text = cd:CreateFontString(nil,"ARTWORK")
  87. text:SetFont(STANDARD_TEXT_FONT,18,"OUTLINE")
  88. text:SetTextColor(1,1,0,1)
  89. text:SetPoint("LEFT",btn,"LEFT",2,0)
  90.  
  91. btn.texture = texture
  92. btn.text = text
  93. btn.duration = abilities[ability].duration
  94. btn.cd = cd
  95.  
  96. bar[ability] = btn
  97.  
  98. x = x + 30
  99. end
  100. end
  101.  
  102. local function InterruptBar_SavePosition()
  103. local point, _, relativePoint, xOfs, yOfs = bar:GetPoint()
  104. if not InterruptBarDB.Position then
  105. InterruptBarDB.Position = {}
  106. end
  107. InterruptBarDB.Position.point = point
  108. InterruptBarDB.Position.relativePoint = relativePoint
  109. InterruptBarDB.Position.xOfs = xOfs
  110. InterruptBarDB.Position.yOfs = yOfs
  111. end
  112.  
  113. local function InterruptBar_LoadPosition()
  114. if InterruptBarDB.Position then
  115. bar:SetPoint(InterruptBarDB.Position.point,UIParent,InterruptBarDB.Position.relativePoint,InterruptBarDB.Position.xOfs,InterruptBarDB.Position.yOfs)
  116. else
  117. bar:SetPoint("CENTER", UIParent, "CENTER")
  118. end
  119. end
  120.  
  121. local function InterruptBar_UpdateBar()
  122. bar:SetScale(InterruptBarDB.scale)
  123. if InterruptBarDB.hidden then
  124. for _,v in ipairs(order) do bar[v]:Hide() end
  125. else
  126. for _,v in ipairs(order) do bar[v]:Show() end
  127. end
  128. if InterruptBarDB.lock then
  129. bar:EnableMouse(false)
  130. else
  131. bar:EnableMouse(true)
  132. end
  133. end
  134.  
  135. local function InterruptBar_CreateBar()
  136. bar = CreateFrame("Frame", nil, UIParent)
  137. bar:SetMovable(true)
  138. bar:SetWidth(120)
  139. bar:SetHeight(30)
  140. bar:SetClampedToScreen(true)
  141. bar:SetScript("OnMouseDown",function(self,button) if button == "LeftButton" then self:StartMoving() end end)
  142. bar:SetScript("OnMouseUp",function(self,button) if button == "LeftButton" then self:StopMovingOrSizing() InterruptBar_SavePosition() end end)
  143. bar:Show()
  144.  
  145. InterruptBar_AddIcons()
  146. InterruptBar_UpdateBar()
  147. InterruptBar_LoadPosition()
  148. end
  149.  
  150. local function InterruptBar_UpdateText(text,cooldown)
  151. if cooldown < 10 then
  152. if cooldown <= 0.5 then
  153. text:SetText("")
  154. else
  155. text:SetFormattedText(" %d",cooldown)
  156. end
  157. else
  158. text:SetFormattedText("%d",cooldown)
  159. end
  160. if cooldown < 6 then
  161. text:SetTextColor(1,0,0,1)
  162. else
  163. text:SetTextColor(1,1,0,1)
  164. end
  165. end
  166.  
  167. local function InterruptBar_StopAbility(ref,ability)
  168. if InterruptBarDB.hidden then ref:Hide() end
  169. if activetimers[ability] then activetimers[ability] = nil end
  170. ref.text:SetText("")
  171. ref.cd:Hide()
  172. end
  173.  
  174. local time = 0
  175. local function InterruptBar_OnUpdate(self, elapsed)
  176. time = time + elapsed
  177. if time > 0.25 then
  178. getsize()
  179. for ability,ref in pairs(activetimers) do
  180. ref.cooldown = ref.start + ref.duration - GetTime()
  181. if ref.cooldown <= 0 then
  182. InterruptBar_StopAbility(ref,ability)
  183. else
  184. InterruptBar_UpdateText(ref.text,floor(ref.cooldown+0.5))
  185. end
  186. end
  187. if size == 0 then frame:SetScript("OnUpdate",nil) end
  188. time = time - 0.25
  189. end
  190. end
  191.  
  192. local function InterruptBar_StartTimer(ref,ability)
  193. if InterruptBarDB.hidden then
  194. ref:Show()
  195. end
  196. if not activetimers[ability] then
  197. local duration
  198. activetimers[ability] = ref
  199. ref.cd:Show()
  200. ref.cd:SetCooldown(GetTime()-0.40,ref.duration)
  201. ref.start = GetTime()
  202. InterruptBar_UpdateText(ref.text,ref.duration)
  203. end
  204. frame:SetScript("OnUpdate",InterruptBar_OnUpdate)
  205. end
  206.  
  207. local function InterruptBar_COMBAT_LOG_EVENT_UNFILTERED(...)
  208. local spellID, ability, useSecondDuration
  209. return function(_, eventtype, _, srcName, srcFlags, _, dstName, dstFlags, id)
  210. if (band(srcFlags, 0x00000040) == 0x00000040 and eventtype == "SPELL_CAST_SUCCESS") then
  211. spellID = id
  212. else
  213. return
  214. end
  215. useSecondDuration = false
  216. if spellID == 49376 then spellID = 16979; useSecondDuration = true end -- Feral Charge - Cat -> Feral Charge - Bear
  217. ability = GetSpellInfo(spellID)
  218. if abilities[ability] then
  219. if useSecondDuration and spellID == 16979 then
  220. bar[ability].duration = 30
  221. elseif spellID == 16979 then
  222. bar[ability].duration = 15
  223. end
  224. InterruptBar_StartTimer(bar[ability],ability)
  225. end
  226. end
  227. end
  228.  
  229. InterruptBar_COMBAT_LOG_EVENT_UNFILTERED = InterruptBar_COMBAT_LOG_EVENT_UNFILTERED()
  230.  
  231. local function InterruptBar_ResetAllTimers()
  232. for _,ability in ipairs(order) do
  233. InterruptBar_StopAbility(bar[ability])
  234. end
  235. active = 0
  236. end
  237.  
  238. local function InterruptBar_PLAYER_ENTERING_WORLD(self)
  239. InterruptBar_ResetAllTimers()
  240. end
  241.  
  242. local function InterruptBar_Reset()
  243. InterruptBarDB = { scale = 1, hidden = false, lock = false }
  244. InterruptBar_UpdateBar()
  245. InterruptBar_LoadPosition()
  246. end
  247.  
  248. local function InterruptBar_Test()
  249. for _,ability in ipairs(order) do
  250. InterruptBar_StartTimer(bar[ability],ability)
  251. end
  252. end
  253.  
  254. local cmdfuncs = {
  255. scale = function(v) InterruptBarDB.scale = v; InterruptBar_UpdateBar() end,
  256. hidden = function() InterruptBarDB.hidden = not InterruptBarDB.hidden; InterruptBar_UpdateBar() end,
  257. lock = function() InterruptBarDB.lock = not InterruptBarDB.lock; InterruptBar_UpdateBar() end,
  258. reset = function() InterruptBar_Reset() end,
  259. test = function() InterruptBar_Test() end,
  260. }
  261.  
  262. local cmdtbl = {}
  263. function InterruptBar_Command(cmd)
  264. for k in ipairs(cmdtbl) do
  265. cmdtbl[k] = nil
  266. end
  267. for v in gmatch(cmd, "[^ ]+") do
  268. tinsert(cmdtbl, v)
  269. end
  270. local cb = cmdfuncs[cmdtbl[1]]
  271. if cb then
  272. local s = tonumber(cmdtbl[2])
  273. cb(s)
  274. else
  275. ChatFrame1:AddMessage("InterruptBar Options | /ib <option>",0,1,0)
  276. ChatFrame1:AddMessage("-- scale <number> | value: " .. InterruptBarDB.scale,0,1,0)
  277. ChatFrame1:AddMessage("-- hidden (toggle) | value: " .. tostring(InterruptBarDB.hidden),0,1,0)
  278. ChatFrame1:AddMessage("-- lock (toggle) | value: " .. tostring(InterruptBarDB.lock),0,1,0)
  279. ChatFrame1:AddMessage("-- test (execute)",0,1,0)
  280. ChatFrame1:AddMessage("-- reset (execute)",0,1,0)
  281. end
  282. end
  283.  
  284. local function InterruptBar_OnLoad(self)
  285. self:RegisterEvent("PLAYER_ENTERING_WORLD")
  286. self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  287. if not InterruptBarDB.scale then InterruptBarDB.scale = 1 end
  288. if not InterruptBarDB.hidden then InterruptBarDB.hidden = false end
  289. if not InterruptBarDB.lock then InterruptBarDB.lock = false end
  290. InterruptBar_CreateBar()
  291.  
  292. SlashCmdList["InterruptBar"] = InterruptBar_Command
  293. SLASH_InterruptBar1 = "/ib"
  294.  
  295. ChatFrame1:AddMessage("Interrupt Bar by Kollektiv. Type /ib for options.",0,1,0)
  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