Advertisement
Guest User

Untitled

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