From 16901157b8d0b6eb4b1a58e0463f457442c6a720 Mon Sep 17 00:00:00 2001 From: Schaka Date: Tue, 26 Jan 2016 14:05:55 +0100 Subject: [PATCH] fix arenaidentify module to include cooldowns --- Gladdy.lua | 134 ++++++++++++++++---------------------- Modules/ArenaIdentify.lua | 18 ++--- 2 files changed, 67 insertions(+), 85 deletions(-) diff --git a/Gladdy.lua b/Gladdy.lua index e33d3d8..435deb9 100644 --- a/Gladdy.lua +++ b/Gladdy.lua @@ -403,7 +403,6 @@ function Gladdy:JoinedArena() self:RegisterEvent("UPDATE_MOUSEOVER_UNIT") self:RegisterEvent("UNIT_TARGET") - self:ScheduleRepeatingTimer("Sync", 1, self) self:ScheduleRepeatingTimer("UpdateUnits", 0.25, self) self:RegisterComm("Gladdy") @@ -767,23 +766,6 @@ function Gladdy:UNIT_TARGET(event, uid) end end -function Gladdy:Sync() - for k, v in pairs(self.buttons) do - if (v.guid ~= "") then - if (not v._health or not v._power or v.health ~= v._health or v.power ~= v._power) then - local message = ("%s,%s,%s,%s,%s,%s,%d,%d,%d,%d,%d"):format( - v.name, v.guid, v.class, v.classLoc, v.raceLoc, v.spec, - v.health, v.healthMax, v.power, v.powerMax, v.powerType - ) - - v._health = v.health - v._power = v.power - --self:SendCommMessage("Gladdy", message, "PARTY", nil, "ALERT") - end - end - end -end - function Gladdy:OnCommReceived(prefix, message, dest, sender) -- hack, to avoid faulty messages from ArenaIdentify (not server sent) if dest ~= "WHISPER" then return end @@ -913,7 +895,7 @@ function Gladdy:DetectSpec(unit, spec) icon.texture:SetTexture(self.spellTextures[k]) icon.spellId = k button.spellCooldownFrame["icon" .. button.lastCooldownSpell] = icon - button.lastCooldownSpell = button.lastCooldownSpell + 1 + button.lastCooldownSpell = button.lastCooldownSpell + 1 end end --end @@ -956,6 +938,54 @@ function Gladdy:IsValid(uid) end end +function Gladdy:UpdateCooldowns(button) + local class = button.class + local race = button.race + + if (self.db.cooldown) then + for k,v in pairs(self.cooldownSpells[class]) do + if (type(v) ~= "table" or (type(v) == "table" and v.spec == nil and v.notSpec == nil)) then + -- see if we have shared cooldowns without a cooldown defined + -- e.g. hunter traps have shared cooldowns, so only display one trap instead all of them + local sharedCD = false + if (type(v) == "table" and v.sharedCD ~= nil and v.sharedCD.cd == nil) then + for spellId, _ in pairs(v.sharedCD) do + for i=1, button.lastCooldownSpell do + local icon = button.spellCooldownFrame["icon" .. i] + if (icon.spellId == spellId) then + sharedCD = true + end + end + end + end + + if (not sharedCD) then + local icon = button.spellCooldownFrame["icon" .. button.lastCooldownSpell] + icon:Show() + icon.spellId = k + icon.texture:SetTexture(self.spellTextures[k]) + button.spellCooldownFrame["icon" .. button.lastCooldownSpell] = icon + button.lastCooldownSpell = button.lastCooldownSpell + 1 + end + end + end + ---- + -- RACE FUNCTIONALITY + ---- + + for k,v in pairs(self.cooldownSpells[race]) do + if (type(v) ~= "table" or (type(v) == "table" and v.spec == nil and v.notSpec == nil)) then + local icon = button.spellCooldownFrame["icon" .. button.lastCooldownSpell] + icon:Show() + icon.spellId = k + icon.texture:SetTexture(self.spellTextures[k]) + button.spellCooldownFrame["icon" .. button.lastCooldownSpell] = icon + button.lastCooldownSpell = button.lastCooldownSpell + 1 + end + end + end +end + function Gladdy:UpdateGUID(guid, uid) local unit = self.guids[guid] if (not unit) then @@ -965,69 +995,19 @@ function Gladdy:UpdateGUID(guid, uid) unit = self:EnemySpotted(name, guid, class, classLoc, raceLoc) end if unit then - local button = self.buttons[unit] - local classLoc, class = UnitClass(uid) - local raceLoc, race = UnitRace(uid) - -- update cooldown tracker - if button then - button.race = race - button.lastCooldownSpell = 1 - if (self.db.cooldown) then - for k,v in pairs(self.cooldownSpells[class]) do - --if (self.db.cooldownList[k] ~= false and self.db.cooldownList[class] ~= false) then - if (type(v) ~= "table" or (type(v) == "table" and v.spec == nil and v.notSpec == nil)) then - -- see if we have shared cooldowns without a cooldown defined - -- e.g. hunter traps have shared cooldowns, so only display one trap instead all of them - local sharedCD = false - if (type(v) == "table" and v.sharedCD ~= nil and v.sharedCD.cd == nil) then - for spellId, _ in pairs(v.sharedCD) do - for i=1, button.lastCooldownSpell do - local icon = button.spellCooldownFrame["icon" .. i] - if (icon.spellId == spellId) then - sharedCD = true - end - end - end - end - - if (not sharedCD) then - local icon = button.spellCooldownFrame["icon" .. button.lastCooldownSpell] - icon:Show() - icon.spellId = k - icon.texture:SetTexture(self.spellTextures[k]) - button.spellCooldownFrame["icon" .. button.lastCooldownSpell] = icon - button.lastCooldownSpell = button.lastCooldownSpell + 1 - end - end - --end - end - ---- - -- RACE FUNCTIONALITY - ---- - - for k,v in pairs(self.cooldownSpells[race]) do - if (type(v) ~= "table" or (type(v) == "table" and v.spec == nil and v.notSpec == nil)) then - if (not sharedCD) then - local icon = button.spellCooldownFrame["icon" .. button.lastCooldownSpell] - icon:Show() - icon.spellId = k - icon.texture:SetTexture(self.spellTextures[k]) - button.spellCooldownFrame["icon" .. button.lastCooldownSpell] = icon - button.lastCooldownSpell = button.lastCooldownSpell + 1 - end - end - end + local button = self.buttons[unit] + local classLoc, class = UnitClass(uid) + local raceLoc, race = UnitRace(uid) + -- update cooldown tracker + if button then + button.race = race + button.lastCooldownSpell = 1 + self:UpdateCooldowns(button) end - end end self:UNIT_AURA(nil, uid) self:UNIT_HEALTH(nil, uid) self:UNIT_POWER(nil, uid) --- if select(1, UnitChannelInfo(uid)) then --- self:UNIT_SPELLCAST_CHANNEL_START(nil, uid) --- else --- self:UNIT_SPELLCAST_START(nil, uid) --- end end diff --git a/Modules/ArenaIdentify.lua b/Modules/ArenaIdentify.lua index 3901f1b..119490b 100644 --- a/Modules/ArenaIdentify.lua +++ b/Modules/ArenaIdentify.lua @@ -58,12 +58,13 @@ function ArenaIdentify:Print(msg) end function ArenaIdentify:SendGladdyMessage(msg) - local name, guid, class, classLoc, raceLoc, spec, health, healthMax, power, powerMax, powerType = string.split(",", msg) + local name, guid, class, classLoc, raceLoc, race, health, healthMax, power, powerMax, powerType = string.split(",", msg) if (Gladdy.guids[guid]) then return end local unit = Gladdy:EnemySpotted(name, guid, class, classLoc, raceLoc) local button = Gladdy.buttons[unit] if (not button) then return end + button.race = race button.lastCooldownSpell = 1 button.health = health button.healthMax = healthMax @@ -72,6 +73,7 @@ function ArenaIdentify:SendGladdyMessage(msg) button.powerMax = powerMax button.powerType = powerType Gladdy:SendMessage("UNIT_POWER", unit, tonumber(power), tonumber(powerMax), tonumber(powerType)) + Gladdy:UpdateCooldowns(button) end function ArenaIdentify:ScanUnits() @@ -118,8 +120,8 @@ function ArenaIdentify:ScanUnit(unit) local name, _ = UnitName(unit) local classLoc, class = UnitClass(unit) local powerType = UnitPowerType(unit) or 0 - local raceLoc, _ = UnitRace(unit) - Gladdy.db.scanTable[GetRealmName()][guid] = string.format("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s", name, guid, class, classLoc, raceLoc, "", "100", "100", "100", "100", powerType) + local raceLoc, race = UnitRace(unit) + Gladdy.db.scanTable[GetRealmName()][guid] = string.format("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s", name, guid, class, classLoc, raceLoc, race, "100", "100", "100", "100", powerType) Gladdy.db.guidsByName[GetRealmName()][name] = guid alreadySaved[guid] = true end @@ -201,19 +203,19 @@ function ArenaIdentify:COMBAT_LOG_EVENT_UNFILTERED(event, timestamp, eventType, if( not alreadyFound[sourceGUID] and instanceType == "arena" and self:GuidInParty(sourceGUID)==0) then local data = Gladdy.db.scanTable[GetRealmName()][sourceGUID] if data ~= nil then - local name, guid, class, classLoc, raceLoc, spec, health, healthMax, power, powerMax, powerType = string.split(",", data) + local name, guid, class, classLoc, raceLoc, race, health, healthMax, power, powerMax, powerType = string.split(",", data) alreadyFound[sourceGUID] = true --v.name, v.guid, v.class, v.classLoc, v.raceLoc, v.spec, v.health, v.healthMax, v.power, v.powerMax, v.powerType - local msg = string.format("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s", name, guid, class, classLoc, raceLoc, "", health, healthMax, power, powerMax, powerType) + local msg = string.format("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s", name, guid, class, classLoc, raceLoc, race, health, healthMax, power, powerMax, powerType) self:SendGladdyMessage(msg) end elseif( not alreadyFound[destGUID] and instanceType == "arena" and self:GuidInParty(destGUID)==0) then local data = Gladdy.db.scanTable[GetRealmName()][destGUID] if data ~= nil then - local name, guid, class, classLoc, raceLoc, spec, health, healthMax, power, powerMax, powerType = string.split(",", data) + local name, guid, class, classLoc, raceLoc, race, health, healthMax, power, powerMax, powerType = string.split(",", data) alreadyFound[destGUID] = true --v.name, v.guid, v.class, v.classLoc, v.raceLoc, v.spec, v.health, v.healthMax, v.power, v.powerMax, v.powerType - local msg = string.format("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s", name, guid, class, classLoc, raceLoc, "", health, healthMax, power, powerMax, powerType) + local msg = string.format("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s", name, guid, class, classLoc, raceLoc, race, health, healthMax, power, powerMax, powerType) self:SendGladdyMessage(msg) end end @@ -231,7 +233,7 @@ function ArenaIdentify:Scoreboard() local guid = Gladdy.db.guidsByName[GetRealmName()][name] if not alreadyFound[guid] and instanceType == "arena" and self:GuidInParty(guid)==0 and UnitGUID("player") ~= guid then alreadyFound[guid] = true - local msg = string.format("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s", name, guid, class, classLoc, raceLoc, "", "100", "100", "100", "100", "0") + local msg = Gladdy.db.guidsByName[GetRealmName()][guid] self:SendGladdyMessage(msg) end end