Skip to content

Commit

Permalink
Improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
gouletr committed Sep 5, 2023
1 parent c83abee commit a4b78c8
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 42 deletions.
95 changes: 61 additions & 34 deletions Damnation/Damnation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ function Damnation:OnInitialize()
end

function Damnation:OnEnable()
self.className = select(2, UnitClass("player"))
self.canTank = self.className == "WARRIOR" or self.className == "DRUID" or self.className == "PALADIN"
self:SetMode(self.db.profile.mode)
end

Expand All @@ -44,80 +46,105 @@ end
function Damnation:SetMode(mode)
self:UnregisterEvent("UNIT_AURA")
self:UnregisterEvent("PLAYER_REGEN_ENABLED")
if mode == "on" or (mode == "auto" and self:CanTank()) then
if mode == "on" or (mode == "auto" and self.canTank) then
self:RegisterEvent("UNIT_AURA")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
self:ManageBuffs()
end
end

function Damnation:CanTank()
local _, className = UnitClass("player")
if className == "WARRIOR" then
return true, className
elseif className == "DRUID" then
return true, className
elseif className == "PALADIN" then
return true, className
end
return false, className
end

function Damnation:IsTanking()
local canTank, className = self:CanTank()
if not canTank then
if not self.canTank then
return false
end

if className == "WARRIOR" then
if self.className == "WARRIOR" then
local _, tanking = GetShapeshiftFormInfo(2) -- Defensive Stance
return tanking
elseif className == "DRUID" then
elseif self.className == "DRUID" then
local _, tanking = GetShapeshiftFormInfo(1) -- Bear/Dire Bear Form
return tanking
elseif className == "PALADIN" then
return self:HasBuff(25780) -- Righteous Fury
elseif self.className == "PALADIN" then
self:GetActiveBuffs()
return self.activeBuffs[25780] ~= nil -- Righteous Fury
end

return false
end

function Damnation:HasBuff(spellId)
for i=1,40 do
local name, _, _, _, _, _, _, _, _, id = UnitBuff("player", i)
if id == spellId then
return true, name, i
function Damnation:GetActiveBuffs()
if self.activeBuffs == nil then
self.activeBuffs = {}
for i=1,256 do
local name, _, _, _, _, _, _, _, _, spellID = UnitBuff("player", i)
if name == nil or spellID == nil then
break
end
self.activeBuffs[spellID] = {name = name, index = i}
end
end
return false, nil, nil
end

function Damnation:RemoveBuff(spellId)
local hasBuff, name, index = self:HasBuff(spellId)
if hasBuff then
CancelUnitBuff("player", index)
function Damnation:RemoveBuff(spellID)
if InCombatLockdown() then
self.activeBuffs = nil
return false
end

self:GetActiveBuffs()
local activeBuff = self.activeBuffs[spellID]
if activeBuff ~= nil then
CancelUnitBuff("player", activeBuff.index)
if self.db.profile.announce then
print(COLOR_GOLD..self:GetName()..COLOR_RESET.." has removed "..name..".")
print(COLOR_GOLD..self:GetName()..COLOR_RESET.." has removed "..activeBuff.name..".")
end
end
return true
end

function Damnation:ManageBuffs()
if InCombatLockdown() then
self.activeBuffs = nil
return
end

if self.db.profile.mode == "on" or (self.db.profile.mode == "auto" and self:IsTanking()) then
for k,v in ipairs(self.SalvationSpellIds) do self:RemoveBuff(v) end
-- Remove Salvation
for k,v in ipairs(self.SalvationSpellIDs) do
if self:RemoveBuff(v) == false then
break
end
end

-- Remove Intellect
if self.db.profile.intellect then
for k,v in ipairs(self.IntellectSpellIds) do self:RemoveBuff(v) end
for k,v in ipairs(self.IntellectSpellIDs) do
if self:RemoveBuff(v) == false then
break
end
end
end

-- Remove Spirit
if self.db.profile.spirit then
for k,v in ipairs(self.SpiritSpellIds) do self:RemoveBuff(v) end
for k,v in ipairs(self.SpiritSpellIDs) do
if self:RemoveBuff(v) == false then
break
end
end
end

-- Remove Wisdom
if self.db.profile.wisdom then
for k,v in ipairs(self.WisdomSpellIds) do self:RemoveBuff(v) end
for k,v in ipairs(self.WisdomSpellIDs) do
if self:RemoveBuff(v) == false then
break
end
end
end
end

self.activeBuffs = nil
end

function Damnation:UNIT_AURA(unit)
Expand Down
16 changes: 8 additions & 8 deletions Damnation/DamnationData.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ local addonName, addon = ...
local Damnation = addon.Damnation

if WOW_PROJECT_ID == WOW_PROJECT_CLASSIC then
Damnation.SalvationSpellIds = {
Damnation.SalvationSpellIDs = {
1038, -- Blessing of Salvation
25895, -- Greater Blessing of Salvation
}
Damnation.IntellectSpellIds = {
Damnation.IntellectSpellIDs = {
1459, -- Arcane Intellect (Rank 1)
1460, -- Arcane Intellect (Rank 2)
1461, -- Arcane Intellect (Rank 3)
10156, -- Arcane Intellect (Rank 4)
10157, -- Arcane Intellect (Rank 5)
23028, -- Arcane Brilliance
}
Damnation.SpiritSpellIds = {
Damnation.SpiritSpellIDs = {
14752, -- Divine Spirit (Rank 1)
14818, -- Divine Spirit (Rank 2)
14819, -- Divine Spirit (Rank 3)
27841, -- Divine Spirit (Rank 4)
27681, -- Prayer of Spirit
}
Damnation.WisdomSpellIds = {
Damnation.WisdomSpellIDs = {
19742, -- Blessing of Wisdom (Rank 1)
19850, -- Blessing of Wisdom (Rank 2)
19852, -- Blessing of Wisdom (Rank 3)
Expand All @@ -32,11 +32,11 @@ if WOW_PROJECT_ID == WOW_PROJECT_CLASSIC then
25918, -- Greater Blessing of Wisdom (Rank 2)
}
elseif WOW_PROJECT_ID == WOW_PROJECT_BURNING_CRUSADE_CLASSIC then
Damnation.SalvationSpellIds = {
Damnation.SalvationSpellIDs = {
1038, -- Blessing of Salvation
25895, -- Greater Blessing of Salvation
}
Damnation.IntellectSpellIds = {
Damnation.IntellectSpellIDs = {
1459, -- Arcane Intellect (Rank 1)
1460, -- Arcane Intellect (Rank 2)
1461, -- Arcane Intellect (Rank 3)
Expand All @@ -46,7 +46,7 @@ elseif WOW_PROJECT_ID == WOW_PROJECT_BURNING_CRUSADE_CLASSIC then
23028, -- Arcane Brilliance (Rank 1)
27127, -- Arcane Brilliance (Rank 2)
}
Damnation.SpiritSpellIds = {
Damnation.SpiritSpellIDs = {
14752, -- Divine Spirit (Rank 1)
14818, -- Divine Spirit (Rank 2)
14819, -- Divine Spirit (Rank 3)
Expand All @@ -55,7 +55,7 @@ elseif WOW_PROJECT_ID == WOW_PROJECT_BURNING_CRUSADE_CLASSIC then
27681, -- Prayer of Spirit (Rank 1)
32999, -- Prayer of Spirit (Rank 2)
}
Damnation.WisdomSpellIds = {
Damnation.WisdomSpellIDs = {
19742, -- Blessing of Wisdom (Rank 1)
19850, -- Blessing of Wisdom (Rank 2)
19852, -- Blessing of Wisdom (Rank 3)
Expand Down

0 comments on commit a4b78c8

Please sign in to comment.