From c338d5c02fed5252cbff1f6cfa152d5378f36a50 Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Tue, 19 Mar 2013 23:31:18 +0000 Subject: [PATCH] Enhance OvaleGUID to also track GUIDs when unitIDs change. Use a table to hold unitID-to-GUID mappings and provide a new method GetGUID(unitId) to access the table from other modules. Make some public properties private and create methods to access the data in those tables. git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@799 d5049fe3-3747-40f7-a4b5-f36d6801af5f --- OvaleAura.lua | 21 +++++-------- OvaleComboPoints.lua | 22 ++----------- OvaleCondition.lua | 8 ++--- OvaleFrame.lua | 4 +-- OvaleFuture.lua | 10 +++--- OvaleGUID.lua | 83 +++++++++++++++++++++++++++++--------------------- OvaleSpellDamage.lua | 5 +-- OvaleState.lua | 7 ++--- OvaleSwing.lua | 5 +-- 9 files changed, 74 insertions(+), 91 deletions(-) diff --git a/OvaleAura.lua b/OvaleAura.lua index 28a83ce..c8c1778 100644 --- a/OvaleAura.lua +++ b/OvaleAura.lua @@ -24,10 +24,8 @@ local pairs = pairs local select = select local strfind = string.find local API_UnitAura = UnitAura -local API_UnitGUID = UnitGUID local self_baseDamageMultiplier = 1 -local self_playerGUID = nil local self_pool = OvalePool:NewPool("OvaleAura_pool") local self_aura = {} local self_serial = 0 @@ -117,7 +115,6 @@ end -- function OvaleAura:OnEnable() - self_playerGUID = OvaleGUID.player self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED") self:RegisterEvent("PLAYER_ENTERING_WORLD") self:RegisterEvent("UNIT_AURA") @@ -148,7 +145,7 @@ function OvaleAura:COMBAT_LOG_EVENT_UNFILTERED(event, ...) self:UpdateAuras(unitId, destGUID) end - if sourceGUID == self_playerGUID and (event == "SPELL_AURA_APPLIED" or event == "SPELL_AURA_REFRESH" or event == "SPELL_AURA_APPLIED_DOSE") then + if sourceGUID == OvaleGUID:GetGUID("player") and (event == "SPELL_AURA_APPLIED" or event == "SPELL_AURA_REFRESH" or event == "SPELL_AURA_APPLIED_DOSE") then if self:GetAuraByGUID(destGUID, spellId, true) then local aura = self_aura[destGUID][spellId].mine aura.spellHasteMultiplier = OvalePaperDoll:GetSpellHasteMultiplier() @@ -164,7 +161,7 @@ end function OvaleAura:UNIT_AURA(event, unitId) if unitId == "player" then - self:UpdateAuras("player", self_playerGUID) + self:UpdateAuras("player", OvaleGUID:GetGUID("player")) elseif unitId then self:UpdateAuras(unitId) end @@ -182,11 +179,8 @@ function OvaleAura:UpdateAuras(unitId, unitGUID) if not unitId then return end - if not unitGUID and unitId == "player" then - unitGUID = self_playerGUID - end if not unitGUID then - unitGUID = API_UnitGUID(unitId) + unitGUID = OvaleGUID:GetGUID(unitId) end if not unitGUID then return @@ -298,11 +292,11 @@ function OvaleAura:GetAuraByGUID(guid, spellId, mine, unitId) end function OvaleAura:GetAura(unitId, spellId, mine) - return self:GetAuraByGUID(API_UnitGUID(unitId), spellId, mine, unitId) + return self:GetAuraByGUID(OvaleGUID:GetGUID(unitId), spellId, mine, unitId) end function OvaleAura:GetStealable(unitId) - local auraTable = self_aura[API_UnitGUID(unitId)] + local auraTable = self_aura[OvaleGUID:GetGUID(unitId)] if not auraTable then return nil end @@ -355,8 +349,9 @@ function OvaleAura:GetDamageMultiplier(spellId) if spellId then local si = OvaleData.spellInfo[spellId] if si and si.damageAura then - self:UpdateAuras("player", self_playerGUID) - local auraTable = self_aura[self_playerGUID] + local guid = OvaleGUID:GetGUID("player") + self:UpdateAuras("player", guid) + local auraTable = self_aura[guid] if auraTable then for filter, filterInfo in pairs(si.damageAura) do for auraSpellId, multiplier in pairs(filterInfo) do diff --git a/OvaleComboPoints.lua b/OvaleComboPoints.lua index 5d72a20..1d20692 100644 --- a/OvaleComboPoints.lua +++ b/OvaleComboPoints.lua @@ -19,11 +19,7 @@ local OvaleGUID = Ovale.OvaleGUID local OvalePaperDoll = Ovale.OvalePaperDoll local API_GetComboPoints = GetComboPoints -local API_UnitGUID = UnitGUID local MAX_COMBO_POINTS = MAX_COMBO_POINTS - -local self_playerGUID = nil -local self_targetGUID = nil -- -- @@ -32,11 +28,8 @@ OvaleComboPoints.combo = 0 -- function OvaleComboPoints:OnEnable() - self_playerGUID = OvaleGUID.player if OvalePaperDoll.class == "ROGUE" or OvalePaperDoll.class == "DRUID" then self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED") - self:RegisterEvent("PLAYER_ENTERING_WORLD") - self:RegisterEvent("PLAYER_TARGET_CHANGED") self:RegisterEvent("UNIT_COMBO_POINTS") end end @@ -44,8 +37,6 @@ end function OvaleComboPoints:OnDisable() if OvalePaperDoll.class == "ROGUE" or OvalePaperDoll.class == "DRUID" then self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED") - self:UnregisterEvent("PLAYER_ENTERING_WORLD") - self:UnregisterEvent("PLAYER_TARGET_CHANGED") self:UnregisterEvent("UNIT_COMBO_POINTS") end end @@ -64,7 +55,7 @@ the number of extra combo points to add, e.g., critcombo=1. --]] function OvaleComboPoints:COMBAT_LOG_EVENT_UNFILTERED(event, ...) local _, event, _, sourceGUID, _, _, _, destGUID = ... - if sourceGUID == self_playerGUID and destGUID == self_targetGUID then + if sourceGUID == OvaleGUID:GetGUID("player") and destGUID == OvaleGUID:GetGUID("target") then if event == "SPELL_DAMAGE" then local spellId, _, _, _, _, _, _, _, _, critical = select(12, ...) local si = OvaleData.spellInfo[spellId] @@ -78,15 +69,6 @@ function OvaleComboPoints:COMBAT_LOG_EVENT_UNFILTERED(event, ...) end end -function OvaleComboPoints:PLAYER_ENTERING_WORLD(event) - self:PLAYER_TARGET_CHANGED(event) -end - -function OvaleComboPoints:PLAYER_TARGET_CHANGED(event) - self_targetGUID = API_UnitGUID("target") - self:Refresh() -end - function OvaleComboPoints:UNIT_COMBO_POINTS(event, ...) local unitId = ... if unitId == "player" then @@ -99,6 +81,6 @@ function OvaleComboPoints:Refresh() end function OvaleComboPoints:Debug() - Ovale:Print("Player has " .. self.combo .. " combo points on target " ..self_targetGUID.. ".") + Ovale:Print("Player has " .. self.combo .. " combo points on target " .. OvaleGUID:GetGUID("target") .. ".") end -- diff --git a/OvaleCondition.lua b/OvaleCondition.lua index 4e70855..2fa3b24 100644 --- a/OvaleCondition.lua +++ b/OvaleCondition.lua @@ -18,6 +18,7 @@ local OvaleAura = Ovale.OvaleAura local OvaleData = Ovale.OvaleData local OvaleEnemies = Ovale.OvaleEnemies local OvaleEquipement = Ovale.OvaleEquipement +local OvaleGUID = Ovale.OvaleGUID local OvaleFuture = Ovale.OvaleFuture local OvalePaperDoll = Ovale.OvalePaperDoll local OvaleSpellDamage = Ovale.OvaleSpellDamage @@ -55,7 +56,6 @@ local API_UnitCreatureType = UnitCreatureType local API_UnitDebuff = UnitDebuff local API_UnitDetailedThreatSituation = UnitDetailedThreatSituation local API_UnitExists = UnitExists -local API_UnitGUID = UnitGUID local API_UnitHealth = UnitHealth local API_UnitHealthMax = UnitHealthMax local API_UnitIsDead = UnitIsDead @@ -211,7 +211,7 @@ end -- Returns nil if the debuff is not present local function getOtherAura(spellId, suppTime, excludingTarget) if excludingTarget then - excludingTarget = API_UnitGUID(excludingTarget) + excludingTarget = OvaleGUID:GetGUID(excludingTarget) end return OvaleState:GetExpirationTimeOnAnyTarget(spellId, excludingTarget) end @@ -414,9 +414,9 @@ end local function getTargetDead(target) local second = math.floor(OvaleState.maintenant) - if self_targetGUID[target] ~= API_UnitGUID(target) then + if self_targetGUID[target] ~= OvaleGUID:GetGUID(target) then self_lastSaved[target] = nil - self_targetGUID[target] = API_UnitGUID(target) + self_targetGUID[target] = OvaleGUID:GetGUID(target) if self_savedHealth[target] then wipe(self_savedHealth[target]) else diff --git a/OvaleFrame.lua b/OvaleFrame.lua index 4c7e91a..7e52f50 100644 --- a/OvaleFrame.lua +++ b/OvaleFrame.lua @@ -18,6 +18,7 @@ do local OvaleCompile = Ovale.OvaleCompile local OvaleCondition = Ovale.OvaleCondition local OvaleData = Ovale.OvaleData + local OvaleGUID = Ovale.OvaleGUID local OvaleOptions = Ovale.OvaleOptions local OvaleState = Ovale.OvaleState @@ -29,7 +30,6 @@ do local API_CreateFrame = CreateFrame local API_GetSpellInfo = GetSpellInfo local API_GetTime = GetTime - local API_UnitGUID = UnitGUID -- -- @@ -269,7 +269,7 @@ do if spellTarget == "target" or not spellTarget then spellTarget = target end - OvaleState:AddSpellToStack(spellId, start, start + castTime, nextCast, false, API_UnitGUID(spellTarget)) + OvaleState:AddSpellToStack(spellId, start, start + castTime, nextCast, false, OvaleGUID:GetGUID(spellTarget)) start, ending, priorite, element = OvaleBestAction:Compute(node) icons[2]:Update(element, start, OvaleBestAction:GetActionInfo(element)) else diff --git a/OvaleFuture.lua b/OvaleFuture.lua index 9a6f13a..23fd101 100644 --- a/OvaleFuture.lua +++ b/OvaleFuture.lua @@ -34,7 +34,6 @@ local API_UnitName = UnitName -- The spells that the player is casting or has cast but are still in-flight toward their targets. local self_lastSpell = {} -local self_playerGUID = nil local self_playerName = nil -- @@ -57,7 +56,6 @@ OvaleFuture.traceSpellId = nil -- Events -- function OvaleFuture:OnEnable() - self_playerGUID = OvaleGUID.player self_playerName = API_UnitName("player") self:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED") self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED") @@ -129,7 +127,7 @@ function OvaleFuture:UNIT_SPELLCAST_SENT(event, unit, spell, rank, target, lineI if target == API_UnitName("target") then targetGUID = API_UnitGUID("target") else - targetGUID = OvaleGUID.nameToGUID[target] + targetGUID = OvaleGUID:GetGUIDForName(target) end self.nextSpellTarget = targetGUID self.nextSpellLineID = lineId @@ -205,8 +203,8 @@ function OvaleFuture:COMBAT_LOG_EVENT_UNFILTERED(event, ...) SPELL_AURA_APPLIED SPELL_PERIODIC_DAMAGE SPELL_PERIODIC_DAMAGE]] - - if sourceGUID == self_playerGUID then + + if sourceGUID == OvaleGUID:GetGUID("player") then --Called when a missile reached or missed its target --Update self_lastSpell accordingly --Do not use SPELL_CAST_SUCCESS because it is sent when the missile has not reached the target @@ -337,7 +335,7 @@ function OvaleFuture:AddSpellToList(spellId, lineId, startTime, endTime, channel if scored~=nil then Ovale.score = Ovale.score + scored Ovale.maxScore = Ovale.maxScore + 1 - Ovale:SendScoreToDamageMeter(self_playerName, self_playerGUID, scored, 1) + Ovale:SendScoreToDamageMeter(self_playerName, OvaleGUID:GetGUID("player"), scored, 1) end end end diff --git a/OvaleGUID.lua b/OvaleGUID.lua index b98d79b..327ee5d 100644 --- a/OvaleGUID.lua +++ b/OvaleGUID.lua @@ -20,77 +20,88 @@ local strsub = string.sub local API_GetNumGroupMembers = GetNumGroupMembers local API_UnitGUID = UnitGUID local API_UnitName = UnitName --- --- -OvaleGUID.unitId = {} -OvaleGUID.guid = {} -OvaleGUID.player = nil -OvaleGUID.nameToGUID = {} -OvaleGUID.nameToUnit = {} --- +self_unitId = {} +self_guid = {} +self_nameToGUID = {} +self_nameToUnit = {} +-- -- function OvaleGUID:OnEnable() self:Update("player") - self:RegisterEvent("PLAYER_LOGIN") - self:RegisterEvent("UNIT_TARGET") - self:RegisterEvent("GROUP_ROSTER_UPDATE") - self:RegisterEvent("UNIT_PET") self:RegisterEvent("ARENA_OPPONENT_UPDATE") + self:RegisterEvent("GROUP_ROSTER_UPDATE") + self:RegisterEvent("INSTANCE_ENCOUNTER_ENGAGE_UNIT") self:RegisterEvent("PLAYER_FOCUS_CHANGED") + self:RegisterEvent("PLAYER_LOGIN") + self:RegisterEvent("PLAYER_TARGET_CHANGED") + self:RegisterEvent("UNIT_PET") + self:RegisterEvent("UNIT_TARGET") self:RegisterEvent("UPDATE_MOUSEOVER_UNIT") - self:RegisterEvent("INSTANCE_ENCOUNTER_ENGAGE_UNIT") end function OvaleGUID:OnDisable() - self:UnregisterEvent("PLAYER_LOGIN") - self:UnregisterEvent("UNIT_TARGET") - self:UnregisterEvent("GROUP_ROSTER_UPDATE") - self:UnregisterEvent("UNIT_PET") self:UnregisterEvent("ARENA_OPPONENT_UPDATE") + self:UnregisterEvent("GROUP_ROSTER_UPDATE") + self:UnregisterEvent("INSTANCE_ENCOUNTER_ENGAGE_UNIT") self:UnregisterEvent("PLAYER_FOCUS_CHANGED") + self:UnregisterEvent("PLAYER_LOGIN") + self:UnregisterEvent("PLAYER_TARGET_CHANGED") + self:UnregisterEvent("UNIT_PET") + self:UnregisterEvent("UNIT_TARGET") self:UnregisterEvent("UPDATE_MOUSEOVER_UNIT") - self:UnregisterEvent("INSTANCE_ENCOUNTER_ENGAGE_UNIT") end function OvaleGUID:Update(unitId) --self:Print("Update " .. unitId) local guid = API_UnitGUID(unitId) - local previousGuid = self.guid[unitId] - if unitId == "player" then - self.player = guid - end + local previousGuid = self_guid[unitId] if previousGuid ~= guid then if previousGuid then - self.unitId[previousGuid][unitId] = nil - if not next(self.unitId[previousGuid]) then - self.unitId[previousGuid] = nil + self_unitId[previousGuid][unitId] = nil + if not next(self_unitId[previousGuid]) then + self_unitId[previousGuid] = nil end end - self.guid[unitId] = guid + self_guid[unitId] = guid if guid then - if not self.unitId[guid] then - self.unitId[guid] = {} + if not self_unitId[guid] then + self_unitId[guid] = {} end Ovale:DebugPrint("guid", "GUID "..guid.." is ".. unitId) - self.unitId[guid][unitId] = true + self_unitId[guid][unitId] = true end end local name = API_UnitName(unitId) - if name and (not self.nameToGUID[name] or unitId == "target" - or self.nameToUnit[name] == "mouseover") then - self.nameToGUID[name] = guid - self.nameToUnit[name] = unitId + if name and (not self_nameToGUID[name] or unitId == "target" + or self_nameToUnit[name] == "mouseover") then + self_nameToGUID[name] = guid + self_nameToUnit[name] = unitId + end +end + +function OvaleGUID:GetGUID(unitId) + if not self_guid[unitId] then + self_guid[unitId] = API_UnitGUID(unitId) end + return self_guid[unitId] +end + +function OvaleGUID:GetGUIDForName(name) + return self_nameToGUID[name] end function OvaleGUID:GetUnitId(guid) - local unitIdTable = self.unitId[guid] + local unitIdTable = self_unitId[guid] if not unitIdTable then return nil end return next(unitIdTable) end +function OvaleGUID:GetUnitIdForName(name) + return self_nameToUnit[name] +end + function OvaleGUID:UpdateWithTarget(unitId) self:Update(unitId) self:Update(unitId.."target") @@ -100,6 +111,10 @@ function OvaleGUID:PLAYER_LOGIN(event) self:Update("player") end +function OvaleGUID:PLAYER_TARGET_CHANGED(event) + self:UNIT_TARGET(event, "player") +end + function OvaleGUID:UNIT_TARGET(event, unitId) self:Update(unitId .. "target") if unitId == "player" then diff --git a/OvaleSpellDamage.lua b/OvaleSpellDamage.lua index 621fd3b..e9bbd8e 100644 --- a/OvaleSpellDamage.lua +++ b/OvaleSpellDamage.lua @@ -18,8 +18,6 @@ local OvaleGUID = Ovale.OvaleGUID local select = select local strfind = string.find - -local self_playerGUID = nil -- -- @@ -29,7 +27,6 @@ OvaleSpellDamage.value = {} -- Events -- function OvaleSpellDamage:OnEnable() - self_playerGUID = OvaleGUID.player self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED") end @@ -40,7 +37,7 @@ end function OvaleSpellDamage:COMBAT_LOG_EVENT_UNFILTERED(event, ...) local time, event, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags = select(1, ...) - if sourceGUID == self_playerGUID then + if sourceGUID == OvaleGUID:GetGUID("player") then if strfind(event, "SPELL_PERIODIC_DAMAGE")==1 or strfind(event, "SPELL_DAMAGE")==1 then local spellId, spellName, spellSchool, amount = select(12, ...) self.value[spellId] = amount diff --git a/OvaleState.lua b/OvaleState.lua index a175ddf..cb93cd8 100644 --- a/OvaleState.lua +++ b/OvaleState.lua @@ -29,7 +29,6 @@ local tostring = tostring local API_GetRuneCooldown = GetRuneCooldown local API_GetRuneType = GetRuneType local API_GetSpellInfo = GetSpellInfo -local API_UnitGUID = UnitGUID local API_UnitHealth = UnitHealth local API_UnitHealthMax = UnitHealthMax local API_UnitPower = UnitPower @@ -382,7 +381,7 @@ function OvaleState:AddSpellToStack(spellId, startCast, endCast, nextCast, nocd, if target == "target" then auraGUID = targetGUID else - auraGUID = API_UnitGUID(target) + auraGUID = OvaleGUID:GetGUID(target) end -- Set the duration to the proper length if it's a DoT. @@ -511,7 +510,7 @@ function OvaleState:GetComputedSpellCD(spellId) end function OvaleState:AddEclipse(endCast, spellId) - local newAura = self:NewAura(OvaleGUID.player, spellId) + local newAura = self:NewAura(OvaleGUID:GetGUID("player"), spellId) newAura.start = endCast + 0.5 newAura.stacks = 1 newAura.ending = nil @@ -529,7 +528,7 @@ function OvaleState:GetAuraByGUID(guid, spellId, mine, target) end function OvaleState:GetAura(target, spellId, mine) - return self:GetAuraByGUID(API_UnitGUID(target), spellId, mine, target) + return self:GetAuraByGUID(OvaleGUID:GetGUID(target), spellId, mine, target) end function OvaleState:GetExpirationTimeOnAnyTarget(spellId, excludingTarget) diff --git a/OvaleSwing.lua b/OvaleSwing.lua index b90e118..312012c 100644 --- a/OvaleSwing.lua +++ b/OvaleSwing.lua @@ -34,8 +34,6 @@ local API_UnitDamage = UnitDamage local API_UnitRangedDamage = UnitRangedDamage local BOOKTYPE_SPELL = BOOKTYPE_SPELL -local self_playerGUID = nil - local OVALE_AUTOSHOT_NAME = API_GetSpellInfo(75) local OVALE_RESET_SPELLS = {} local OVALE_DELAY_SPELLS = { @@ -58,7 +56,6 @@ OvaleSwing.swingmode = nil -- function OvaleSwing:OnEnable() - self_playerGUID = OvaleGUID.player self.ohNext = false -- fired when autoattack is enabled/disabled. self:RegisterEvent("PLAYER_ENTER_COMBAT") @@ -106,7 +103,7 @@ function OvaleSwing:STOP_AUTOREPEAT_SPELL() end function OvaleSwing:COMBAT_LOG_EVENT_UNFILTERED(event, timestamp, eventName, srcGUID, srcName, srcFlags, dstName, dstGUID, dstFlags, ...) - if srcGUID == self_playerGUID then + if srcGUID == OvaleGUID:GetGUID("player") then if eventName == "SWING_DAMAGE" or eventName == "SWING_MISSED" then self:MeleeSwing(Ovale.now) end -- 1.7.9.5