Advertisement
Marty1881

Untitled

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