Cache player level in OvaleData.
Johnny C. Lam [10-25-12 - 14:48]
Cache player level in OvaleData.
This avoids calling UnitLevel("player") except for player entering the
world.
git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@621 d5049fe3-3747-40f7-a4b5-f36d6801af5f
diff --git a/OvaleCondition.lua b/OvaleCondition.lua
index fbdb35d..5dd990a 100644
--- a/OvaleCondition.lua
+++ b/OvaleCondition.lua
@@ -1690,7 +1690,14 @@ OvaleCondition.conditions=
-- if Level(more 33) Spell(tiger_palm)
level = function(condition)
- return compare(UnitLevel(getTarget(condition.target)), condition[1], condition[2])
+ local level
+ local target = getTarget(condition.target)
+ if target == "player" then
+ level = OvaleData.level
+ else
+ level = UnitLevel(target)
+ end
+ return compare(level, condition[1], condition[2])
end,
--- Get the current amount of health points of the target.
@@ -1843,7 +1850,7 @@ OvaleCondition.conditions=
mastery = function(condition)
local mastery = 0
- if UnitLevel("player") >= 80 then
+ if OvaleData.level >= 80 then
mastery = GetMasteryEffect()
end
return compare(mastery, condition[1], condition[2])
@@ -2035,10 +2042,11 @@ OvaleCondition.conditions=
relativelevel = function(condition)
local difference
local target = getTarget(condition.target)
- if UnitLevel(target) == -1 then
+ local targetLevel = UnitLevel(target)
+ if targetLevel < 0 then
difference = 3
else
- difference = UnitLevel(target) - UnitLevel("player")
+ difference = targetLevel - OvaleData.level
end
return compare(difference, condition[1], condition[2])
end,
diff --git a/OvaleData.lua b/OvaleData.lua
index 24ea9b9..0a74e08 100644
--- a/OvaleData.lua
+++ b/OvaleData.lua
@@ -21,6 +21,7 @@ local BOOKTYPE_SPELL, BOOKTYPE_PET = BOOKTYPE_SPELL, BOOKTYPE_PET
OvaleData.spellList = {}
OvaleData.firstInit = false
OvaleData.className = nil
+OvaleData.level = nil
--allows to fill the player talent tables on first use
OvaleData.listeTalentsRemplie = false
--key: talentId / value: points in this talent
@@ -254,17 +255,19 @@ function OvaleData:OnEnable()
end
self:FirstInit()
- self:RegisterEvent("PLAYER_TALENT_UPDATE")
- self:RegisterEvent("CHARACTER_POINTS_CHANGED")
+ self:RegisterEvent("CHARACTER_POINTS_CHANGED")
+ self:RegisterEvent("PLAYER_LEVEL_UP")
+ self:RegisterEvent("PLAYER_TALENT_UPDATE")
self:RegisterEvent("SPELLS_CHANGED")
self:RegisterEvent("UNIT_PET")
end
function OvaleData:OnDisable()
self:UnregisterEvent("UNIT_PET")
- self:UnregisterEvent("SPELLS_CHANGED")
- self:UnregisterEvent("PLAYER_TALENT_UPDATE")
- self:UnregisterEvent("CHARACTER_POINTS_CHANGED")
+ self:UnregisterEvent("SPELLS_CHANGED")
+ self:UnregisterEvent("PLAYER_TALENT_UPDATE")
+ self:UnregisterEvent("PLAYER_LEVEL_UP")
+ self:UnregisterEvent("CHARACTER_POINTS_CHANGED")
end
function OvaleData:CHARACTER_POINTS_CHANGED()
@@ -272,6 +275,15 @@ function OvaleData:CHARACTER_POINTS_CHANGED()
-- Ovale:Print("CHARACTER_POINTS_CHANGED")
end
+function OvaleData:PLAYER_LEVEL_UP(event, level, ...)
+ level = tonumber(level)
+ if level then
+ self.level = level
+ else
+ self.level = self.level + 1
+ end
+end
+
function OvaleData:PLAYER_TALENT_UPDATE(event)
Ovale:debugPrint("compile", event)
self:RemplirListeTalents()
@@ -414,6 +426,7 @@ function OvaleData:FirstInit()
local playerClass, englishClass = UnitClass("player")
self.className = englishClass
+ self.level = UnitLevel("player")
self:RemplirListeTalents()
self:FillSpellList()
diff --git a/OvaleFuture.lua b/OvaleFuture.lua
index 9c67dd3..865506e 100644
--- a/OvaleFuture.lua
+++ b/OvaleFuture.lua
@@ -232,7 +232,7 @@ function OvaleFuture:AddSpellToList(spellId, lineId, startTime, endTime, channel
self.lastSpellAP[spellId] = UnitAttackPower("player")
self.lastSpellSP[spellId] = GetSpellBonusDamage(2)
self.lastSpellDM[spellId] = OvaleAura:GetDamageMultiplier(spellId)
- if UnitLevel("player") < 80 then
+ if OvaleData.level < 80 then
self.lastSpellMastery[spellId] = 0
else
self.lastSpellMastery[spellId] = GetMasteryEffect()