Advertisement
berlin

Interrupt Tracker

Aug 8th, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.44 KB | None | 0 0
  1. local spells = {
  2.     [1766]   = 15,  -- kick
  3.     [6552]   = 15,  -- pummel
  4.     [2139]   = 20,  -- counterspell
  5.     [19647]  = 24,  -- spell lock
  6.     [103135] = 24,  -- spell lock (gos)
  7.     [115782] = 24,  -- optical blast
  8.     [47528]  = 15,  -- mind freeze
  9.     [57994]  = 12,  -- wind shear
  10.     [34490]  = 24,  -- silencing shot
  11.     [147362] = 24,  -- counter shot
  12.     [96231]  = 15,  -- rebuke
  13.     [80964]  = 15,  -- skull bash (cat)
  14.     [80965]  = 15,  -- skull bash (bear)
  15.     [116705] = 15,  -- spear hand strike
  16.     [15487]  = 45,  -- priest silence
  17.     [47476]  = 60,  -- strangulate
  18.     [108194] = 30,  -- asphyxiate
  19.     [8122]   = 30,  -- psychic scream
  20.     [19503]  = 30,  -- scatter shot
  21.     [23920]  = 25,  -- spell reflect
  22.     [114028] = 60,  -- aoe reflect
  23.     [48707]  = 45,  -- ams
  24. }
  25. local frameStack
  26. local firstTimer, lastTimer
  27. local events = CreateFrame("Frame")
  28.  
  29. local function Reposition(timer)
  30.     timer.frame:ClearAllPoints()
  31.     if timer == firstTimer then
  32.         timer.frame:SetPoint("TOPRIGHT", "ChatFrame1", 61, 3)
  33.     else
  34.         timer.frame:SetPoint("LEFT", timer.prev.frame, 32, 0)
  35.     end
  36. end
  37.  
  38. local function HideFrame(frame)
  39.     if frame:IsShown() and not frame:IsVisible() then
  40.         return
  41.     end
  42.     local timer = frame.timer
  43.     if not timer.prev then
  44.         firstTimer = timer.next
  45.     else
  46.         timer.prev.next = timer.next
  47.     end
  48.     if not timer.next then
  49.         lastTimer = timer.prev
  50.     else
  51.         timer.next.prev = timer.prev
  52.         Reposition(timer.next)
  53.     end
  54.     frame.timer = nil
  55.     frame.next = frameStack
  56.     frameStack = frame
  57. end
  58.  
  59. local function GetFrame()
  60.     local frame = frameStack
  61.     if frame then
  62.         frameStack = frame.next
  63.     else
  64.         frame = CreateFrame("Cooldown", nil, UIParent, "CooldownFrameTemplate")
  65.         frame:SetSize(30, 30)
  66.         frame.icon = frame:CreateTexture(nil, "BACKGROUND")
  67.         frame.icon:SetAllPoints()
  68.         frame:SetScript("OnHide", HideFrame)
  69.     end
  70.     return frame
  71. end
  72.  
  73. local function ShowCooldown(spellID, unitID)
  74.     local frame = GetFrame()
  75.     local _, _, texture = GetSpellInfo(spellID)
  76.     frame.icon:SetTexture(texture)
  77.     frame.icon:SetTexCoord(.08, .92, .08, .92)
  78.     local timer = {spellID = spellID, unitID = unitID, frame = frame}
  79.     if not firstTimer then
  80.         firstTimer = timer
  81.         lastTimer = timer
  82.     else
  83.         timer.prev = lastTimer
  84.         lastTimer.next = timer
  85.         lastTimer = timer
  86.     end
  87.     frame.timer = timer
  88.     CooldownFrame_SetTimer(frame, GetTime(), spells[spellID], 1)
  89.     Reposition(timer)
  90. end
  91.  
  92. local function ResetCooldown(spellID, unitID)
  93.     local timer = firstTimer
  94.     while timer do
  95.         if timer.spellID == spellID and timer.unitID == unitID then
  96.             timer.frame:SetCooldown(0, 0)
  97.             break
  98.         end
  99.         timer = timer.next
  100.     end
  101. end
  102.  
  103. function events:UNIT_SPELLCAST_SUCCEEDED(unitID, spell, rank, lineID, spellID)
  104.     if not unitID:find("arena") then return end
  105.     if spells[spellID] then
  106.         ShowCooldown(spellID, unitID)
  107.     end
  108. end
  109.  
  110. local lastSpellID, lastSourceGUID
  111. function events:COMBAT_LOG_EVENT_UNFILTERED(...)
  112.     local timestamp, event, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags,
  113.         destGUID, destName, destFlags, destRaidFlags, spellID, spellName = ...
  114.     local isSourceEnemy = (bit.band(sourceFlags, COMBATLOG_OBJECT_REACTION_HOSTILE) == COMBATLOG_OBJECT_REACTION_HOSTILE)
  115.     if event ~= "SPELL_CAST_SUCCESS" or not isSourceEnemy then
  116.         return
  117.     end
  118.     if spells[spellID] then
  119.         if lastSpellID == spellID and lastSourceGUID == sourceGUID then -- check for duplicates
  120.             return
  121.         end
  122.         ShowCooldown(spellID, sourceGUID)
  123.         lastSpellID, lastSourceGUID = spellID, sourceGUID
  124.     end
  125. end
  126.  
  127. function events:PLAYER_ENTERING_WORLD()
  128.     local _, instanceType = GetInstanceInfo()
  129.     if instanceType == "arena" then
  130.         self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  131.         self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
  132.     else
  133.         self:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")
  134.         self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  135.     end
  136.     local timer = firstTimer
  137.     while timer do
  138.         timer.frame:Hide()
  139.         timer = timer.next
  140.     end
  141. end
  142.  
  143. events:SetScript("OnEvent", function(self, event, ...) return self[event](self, ...) end)
  144. events:RegisterEvent("PLAYER_ENTERING_WORLD")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement