From 935ab332e67d820f3c6a7a2e9cfc4a3bc514ea61 Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Sat, 16 Mar 2013 08:03:04 +0000 Subject: [PATCH] Make code more DRY: get class and player GUID from the proper modules. Use OvalePaperDoll.class and OvaleGUID.player instead of calling UnitClass() and UnitGUID() in various modules that need the information. Make playerGUID private in the modules that use it since it isn't accessed outside of the individual modules. git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@772 d5049fe3-3747-40f7-a4b5-f36d6801af5f --- OvaleAura.lua | 15 ++++++++------- OvaleComboPoints.lua | 30 ++++++++++++++++-------------- OvaleFuture.lua | 11 +++++++---- OvaleSpellDamage.lua | 11 ++++++----- OvaleSwing.lua | 23 +++++++++++------------ 5 files changed, 48 insertions(+), 42 deletions(-) diff --git a/OvaleAura.lua b/OvaleAura.lua index 1e754fc..6ae59b4 100644 --- a/OvaleAura.lua +++ b/OvaleAura.lua @@ -16,20 +16,21 @@ OvaleAura = Ovale:NewModule("OvaleAura", "AceEvent-3.0") -- OvaleAura.aura = {} OvaleAura.serial = 0 -OvaleAura.playerGUID = nil -- -- local baseDamageMultiplier = 1 +local playerGUID = nil local pairs, select, strfind = pairs, select, string.find local UnitAura = UnitAura +local UnitGUID = UnitGUID -- -- Events -- function OvaleAura:OnEnable() - self.playerGUID = UnitGUID("player") + playerGUID = OvaleGUID.player self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED") self:RegisterEvent("UNIT_AURA") end @@ -53,7 +54,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 == playerGUID and (event == "SPELL_AURA_APPLIED" or event == "SPELL_AURA_REFRESH" or event == "SPELL_AURA_APPLIED_DOSE") then local aura = self:GetAuraByGUID(destGUID, spellId, true) if aura then aura.spellHasteMultiplier = OvalePaperDoll:GetSpellHasteMultiplier() @@ -72,7 +73,7 @@ end function OvaleAura:UNIT_AURA(event, unitId) if unitId == "player" then - self:UpdateAuras("player", self.playerGUID) + self:UpdateAuras("player", playerGUID) elseif unitId then self:UpdateAuras(unitId) end @@ -135,7 +136,7 @@ function OvaleAura:UpdateAuras(unitId, unitGUID) return end if not unitGUID and unitId == "player" then - unitGUID = self.playerGUID + unitGUID = playerGUID end if not unitGUID then unitGUID = UnitGUID(unitId) @@ -303,8 +304,8 @@ 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] + self:UpdateAuras("player", playerGUID) + local auraTable = self.aura[playerGUID] 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 7193b72..3fd6866 100644 --- a/OvaleComboPoints.lua +++ b/OvaleComboPoints.lua @@ -13,24 +13,22 @@ local _, Ovale = ... OvaleComboPoints = Ovale:NewModule("OvaleComboPoints", "AceEvent-3.0") -- -local strfind = string.find local GetComboPoints = GetComboPoints -local UnitClass, UnitGUID = UnitClass, UnitGUID +local UnitGUID = UnitGUID local MAX_COMBO_POINTS = MAX_COMBO_POINTS -local _, className = UnitClass("player") +local playerGUID = nil +local targetGUID = nil -- -- OvaleComboPoints.combo = 0 -OvaleComboPoints.playerGUID = nil -OvaleComboPoints.targetGUID = nil -- -- function OvaleComboPoints:OnEnable() - self.playerGUID = UnitGUID("player") - if className == "ROGUE" or className == "DRUID" then + 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") @@ -39,7 +37,7 @@ function OvaleComboPoints:OnEnable() end function OvaleComboPoints:OnDisable() - if className == "ROGUE" or className == "DRUID" then + 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") @@ -47,10 +45,6 @@ function OvaleComboPoints:OnDisable() end end -function OvaleComboPoints:Refresh() - self.combo = GetComboPoints("player") or 0 -end - --[[ A rogue's Seal Fate or a druid's Primal Fury are passive abilities that grant an extra combo point when a combo-point generator critically strikes the target. @@ -65,7 +59,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 == playerGUID and destGUID == targetGUID then if event == "SPELL_DAMAGE" then local spellId, _, _, _, _, _, _, _, _, critical = select(12, ...) local si = OvaleData.spellInfo[spellId] @@ -84,7 +78,7 @@ function OvaleComboPoints:PLAYER_ENTERING_WORLD(event) end function OvaleComboPoints:PLAYER_TARGET_CHANGED(event) - self.targetGUID = UnitGUID("target") + targetGUID = UnitGUID("target") self:Refresh() end @@ -94,4 +88,12 @@ function OvaleComboPoints:UNIT_COMBO_POINTS(event, ...) self:Refresh() end end + +function OvaleComboPoints:Refresh() + self.combo = GetComboPoints("player") or 0 +end + +function OvaleComboPoints:Debug() + Ovale:Print("Player has " .. self.combo .. " combo points on target " ..targetGUID.. ".") +end -- diff --git a/OvaleFuture.lua b/OvaleFuture.lua index 7dd9e69..3c9753d 100644 --- a/OvaleFuture.lua +++ b/OvaleFuture.lua @@ -25,9 +25,12 @@ local UnitBuff = UnitBuff local UnitCastingInfo = UnitCastingInfo local UnitChannelInfo = UnitChannelInfo local UnitGUID = UnitGUID +local UnitName = UnitName -- The spells that the player is casting or has cast but are still in-flight toward their targets. local lastSpell = {} +local playerGUID = nil +local playerName = nil -- -- @@ -40,7 +43,6 @@ OvaleFuture.lastSpellSP = {} OvaleFuture.lastSpellDM = {} OvaleFuture.lastSpellCombo = {} OvaleFuture.lastSpellMastery = {} -OvaleFuture.playerGUID = nil OvaleFuture.nextSpellTarget = nil OvaleFuture.nextSpellLineID = nil -- Debugging: spell ID to trace @@ -50,7 +52,8 @@ OvaleFuture.traceSpellId = nil -- Events -- function OvaleFuture:OnEnable() - self.playerGUID = UnitGUID("player") + playerGUID = OvaleGUID.player + playerName = UnitName("player") self:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED") self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED") self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED") @@ -198,7 +201,7 @@ function OvaleFuture:COMBAT_LOG_EVENT_UNFILTERED(event, ...) SPELL_PERIODIC_DAMAGE SPELL_PERIODIC_DAMAGE]] - if sourceGUID == self.playerGUID then + if sourceGUID == playerGUID then --Called when a missile reached or missed its target --Update lastSpell accordingly --Do not use SPELL_CAST_SUCCESS because it is sent when the missile has not reached the target @@ -329,7 +332,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(UnitName("player"), OvaleAura.playerGUID, scored, 1) + Ovale:SendScoreToDamageMeter(playerName, playerGUID, scored, 1) end end end diff --git a/OvaleSpellDamage.lua b/OvaleSpellDamage.lua index 1a72de5..1d1edf2 100644 --- a/OvaleSpellDamage.lua +++ b/OvaleSpellDamage.lua @@ -13,19 +13,20 @@ local _, Ovale = ... OvaleSpellDamage = Ovale:NewModule("OvaleSpellDamage", "AceEvent-3.0") -- -local select, strfind = select, string.find -local UnitGUID = UnitGUID +local select = select +local strfind = string.find + +local playerGUID = nil -- -- OvaleSpellDamage.value = {} -OvaleSpellDamage.playerGUID = nil -- -- Events -- function OvaleSpellDamage:OnEnable() - self.playerGUID = UnitGUID("player") + playerGUID = OvaleGUID.player self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED") end @@ -36,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 == playerGUID 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/OvaleSwing.lua b/OvaleSwing.lua index 0f9950e..30663ca 100644 --- a/OvaleSwing.lua +++ b/OvaleSwing.lua @@ -35,25 +35,24 @@ OvaleSwing.swingmode = nil -- -- -local autoshotname = GetSpellInfo(75) -local resetspells = { -} -local delayspells = { - [GetSpellInfo(1464)] = true, -- Slam -} -local resetautoshotspells = { -} -local _, playerclass = UnitClass('player') - local unpack = unpack local math_abs = math.abs local GetSpellInfo, GetTime, UnitAttackSpeed = GetSpellInfo, GetTime, UnitAttackSpeed local UnitDamage, UnitRangedDamage = UnitDamage, UnitRangedDamage local BOOKTYPE_SPELL = BOOKTYPE_SPELL + +local playerGUID = nil +local autoshotname = GetSpellInfo(75) +local resetspells = {} +local delayspells = { + [GetSpellInfo(1464)] = true, -- Slam +} +local resetautoshotspells = {} -- -- function OvaleSwing:OnEnable() + playerGUID = OvaleGUID.player self.ohNext = false -- fired when autoattack is enabled/disabled. self:RegisterEvent("PLAYER_ENTER_COMBAT") @@ -77,7 +76,7 @@ end function OvaleSwing:PLAYER_ENTER_COMBAT() local _,_,offhandlow, offhandhigh = UnitDamage('player') - if math_abs(offhandlow - offhandhigh) <= 0.1 or playerclass == "DRUID" then + if math_abs(offhandlow - offhandhigh) <= 0.1 or OvalePaperDoll.class == "DRUID" then self.dual = false else self.dual = true @@ -101,7 +100,7 @@ function OvaleSwing:STOP_AUTOREPEAT_SPELL() end function OvaleSwing:COMBAT_LOG_EVENT_UNFILTERED(event, timestamp, eventName, srcGUID, srcName, srcFlags, dstName, dstGUID, dstFlags, ...) - if srcName == UnitName("player") then + if srcGUID == playerGUID then if eventName == "SWING_DAMAGE" or eventName == "SWING_MISSED" then self:MeleeSwing(Ovale.now) end -- 1.7.9.5