Skip to content

Commit

Permalink
fix arenaidentify module to include cooldowns
Browse files Browse the repository at this point in the history
  • Loading branch information
Schaka committed Jan 26, 2016
1 parent ddcb44b commit 1690115
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 85 deletions.
134 changes: 57 additions & 77 deletions Gladdy.lua
Expand Up @@ -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")

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
18 changes: 10 additions & 8 deletions Modules/ArenaIdentify.lua
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 1690115

Please sign in to comment.