Advertisement
Guest User

interruptbarprimaris

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