Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local spells = {
- [1766] = 15, -- kick
- [6552] = 15, -- pummel
- [2139] = 20, -- counterspell
- [19647] = 24, -- spell lock
- [103135] = 24, -- spell lock (gos)
- [115782] = 24, -- optical blast
- [47528] = 15, -- mind freeze
- [57994] = 12, -- wind shear
- [34490] = 24, -- silencing shot
- [147362] = 24, -- counter shot
- [96231] = 15, -- rebuke
- [80964] = 15, -- skull bash (cat)
- [80965] = 15, -- skull bash (bear)
- [116705] = 15, -- spear hand strike
- [15487] = 45, -- priest silence
- [47476] = 60, -- strangulate
- [108194] = 30, -- asphyxiate
- [8122] = 30, -- psychic scream
- [19503] = 30, -- scatter shot
- [23920] = 25, -- spell reflect
- [114028] = 60, -- aoe reflect
- [48707] = 45, -- ams
- }
- local frameStack
- local firstTimer, lastTimer
- local events = CreateFrame("Frame")
- local function Reposition(timer)
- timer.frame:ClearAllPoints()
- if timer == firstTimer then
- timer.frame:SetPoint("TOPRIGHT", "ChatFrame1", 61, 3)
- else
- timer.frame:SetPoint("LEFT", timer.prev.frame, 32, 0)
- end
- end
- local function HideFrame(frame)
- if frame:IsShown() and not frame:IsVisible() then
- return
- end
- local timer = frame.timer
- if not timer.prev then
- firstTimer = timer.next
- else
- timer.prev.next = timer.next
- end
- if not timer.next then
- lastTimer = timer.prev
- else
- timer.next.prev = timer.prev
- Reposition(timer.next)
- end
- frame.timer = nil
- frame.next = frameStack
- frameStack = frame
- end
- local function GetFrame()
- local frame = frameStack
- if frame then
- frameStack = frame.next
- else
- frame = CreateFrame("Cooldown", nil, UIParent, "CooldownFrameTemplate")
- frame:SetSize(30, 30)
- frame.icon = frame:CreateTexture(nil, "BACKGROUND")
- frame.icon:SetAllPoints()
- frame:SetScript("OnHide", HideFrame)
- end
- return frame
- end
- local function ShowCooldown(spellID, unitID)
- local frame = GetFrame()
- local _, _, texture = GetSpellInfo(spellID)
- frame.icon:SetTexture(texture)
- frame.icon:SetTexCoord(.08, .92, .08, .92)
- local timer = {spellID = spellID, unitID = unitID, frame = frame}
- if not firstTimer then
- firstTimer = timer
- lastTimer = timer
- else
- timer.prev = lastTimer
- lastTimer.next = timer
- lastTimer = timer
- end
- frame.timer = timer
- CooldownFrame_SetTimer(frame, GetTime(), spells[spellID], 1)
- Reposition(timer)
- end
- local function ResetCooldown(spellID, unitID)
- local timer = firstTimer
- while timer do
- if timer.spellID == spellID and timer.unitID == unitID then
- timer.frame:SetCooldown(0, 0)
- break
- end
- timer = timer.next
- end
- end
- function events:UNIT_SPELLCAST_SUCCEEDED(unitID, spell, rank, lineID, spellID)
- if not unitID:find("arena") then return end
- if spells[spellID] then
- ShowCooldown(spellID, unitID)
- end
- end
- local lastSpellID, lastSourceGUID
- function events:COMBAT_LOG_EVENT_UNFILTERED(...)
- local timestamp, event, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags,
- destGUID, destName, destFlags, destRaidFlags, spellID, spellName = ...
- local isSourceEnemy = (bit.band(sourceFlags, COMBATLOG_OBJECT_REACTION_HOSTILE) == COMBATLOG_OBJECT_REACTION_HOSTILE)
- if event ~= "SPELL_CAST_SUCCESS" or not isSourceEnemy then
- return
- end
- if spells[spellID] then
- if lastSpellID == spellID and lastSourceGUID == sourceGUID then -- check for duplicates
- return
- end
- ShowCooldown(spellID, sourceGUID)
- lastSpellID, lastSourceGUID = spellID, sourceGUID
- end
- end
- function events:PLAYER_ENTERING_WORLD()
- local _, instanceType = GetInstanceInfo()
- if instanceType == "arena" then
- self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
- self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
- else
- self:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")
- self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
- end
- local timer = firstTimer
- while timer do
- timer.frame:Hide()
- timer = timer.next
- end
- end
- events:SetScript("OnEvent", function(self, event, ...) return self[event](self, ...) end)
- events:RegisterEvent("PLAYER_ENTERING_WORLD")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement