Skip to content

Commit 4ef8547

Browse files
committed
Fixed segmenting issue
+ Attunements should now be properly removed when done + Fixed issue where attunement tracking would impact damage calculations + Note: Use total segment for attunements
1 parent 5d6e173 commit 4ef8547

File tree

2 files changed

+59
-24
lines changed

2 files changed

+59
-24
lines changed

src/SkadaAttunes/SkadaAttunes.lua

+58-23
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ L["Timer frequency"] = "Timer frequency"
1111
L["Use kill events"] = "Use kill events"
1212
L["Use damage events"] = "Use damage events"
1313
L["Show item level"] = "Show item level"
14+
L["Show item id"] = "Show item id"
1415
L["Server attunement variables not loaded"] = "Server attunement variables not loaded"
1516

1617
local Skada = Skada
17-
SkadaAttunes = Skada:NewModule(L["Attunements"])
18+
SkadaAttunes = Skada:NewModule(L["Attunements"], "AceTimer-3.0")
1819

1920
local function chat(msg)
2021
DEFAULT_CHAT_FRAME:AddMessage(msg)
@@ -109,13 +110,15 @@ local function addOrUpdatePlayerAttune(player, id, progress)
109110

110111
if progress < 100 then
111112
local name, link, _, itemLevel, _, _, _, _, _, icon = GetItemInfo(id)
113+
local unknown = false
112114

113115
if not itemLevel then
114116
itemLevel = 0
115117
end
116118

117119
if not name then
118-
name = "Unknown item (" .. id .. ")"
120+
unknown = true
121+
name = "Unknown item"
119122
end
120123

121124
if not icon then
@@ -126,6 +129,10 @@ local function addOrUpdatePlayerAttune(player, id, progress)
126129
name = "[" .. itemLevel .. "] " .. name
127130
end
128131

132+
if unknown or Skada.db.profile.modules.attuneshowitemid then
133+
name = name .. ' (' .. id .. ')'
134+
end
135+
129136
if not player.attunes[id] then
130137
player.attunes[id] = {
131138
id = id,
@@ -147,28 +154,43 @@ local function addOrUpdatePlayerAttune(player, id, progress)
147154
end
148155
end
149156

157+
local function get_player(set, playerId, playerName)
158+
for _, player in ipairs(set.players) do
159+
if player.id == playerId then
160+
return player
161+
end
162+
end
163+
164+
return Skada:get_player(set, playerId, playerName)
165+
end
166+
150167
local function updateAttuneProgress(set, attuneEvent, forceRefresh)
151168
if not set then
152169
return
153170
end
154171

155172
-- Get the player.
156-
local player = Skada:get_player(set, attuneEvent.playerId, attuneEvent.playerName)
173+
local player = get_player(set, attuneEvent.playerId, attuneEvent.playerName)
157174
if player then
175+
local changed = false
158176
local inProgress = getInProgressAttunes(forceRefresh)
159177

160178
for _, attune in ipairs(inProgress) do
161-
addOrUpdatePlayerAttune(player, attune.id, attune.progress)
179+
changed = addOrUpdatePlayerAttune(player, attune.id, attune.progress) or changed
162180
end
163181

164182
for id, _ in pairs(player.attunes) do
165183
if not tableContainsProperty(inProgress, "id", id) then
166184
removePlayerAttune(player, id)
185+
changed = true
167186
end
168187
end
169188

170-
set.numAttunes = player.numAttunes
171-
Skada:UpdateDisplay(true)
189+
if changed then
190+
player.last = time()
191+
set.numAttunes = player.numAttunes
192+
Skada:UpdateDisplay(true)
193+
end
172194
end
173195
end
174196

@@ -186,12 +208,6 @@ local function OnAttuneProgress(timestamp, eventtype, srcGUID, srcName, srcFlags
186208
attuneProgressEvent.playerId = UnitGUID("player")
187209
attuneProgressEvent.playerName = UnitName("player")
188210

189-
-- Create new set if not exists
190-
if not Skada.total then
191-
Skada.total = {players = {}, name = L["Total"], starttime = time(), ["time"] = 0, last_action = time()}
192-
Skada.db.profile.total = Skada.total
193-
end
194-
195211
local forceRefresh = false
196212
if eventtype == 'PLAYER_XP_UPDATE' then
197213
forceRefresh = true
@@ -248,16 +264,24 @@ local function mod_tooltip(win, id, _, tooltip)
248264
end
249265
end
250266

251-
function SkadaAttunes:Update(win,set)
252-
local max = 0
267+
function SkadaAttunes:Update(win, set)
268+
-- Only update the total/current segments
269+
if set ~= Skada.total and set ~= Skada.current then
270+
return
271+
end
272+
273+
win.metadata.maxvalue = 100
253274

254275
-- Aggregate the data.
255276
local tmp = {}
256-
for i, player in ipairs(set.players) do
277+
for _, player in ipairs(set.players) do
257278
if player.numAttunes > 0 then
258279
for id, attune in pairs(player.attunes) do
259280
if not tmp[id] then
260-
tmp[id] = {id = attune.id, progress = attune.progress, name = attune.name, icon = attune.icon, link = attune.link}
281+
-- Extra check to remove old attunes
282+
if ItemAttuneHas[id] or 0 < 100 then
283+
tmp[id] = {id = attune.id, progress = attune.progress, name = attune.name, icon = attune.icon, link = attune.link}
284+
end
261285
else
262286
tmp[id].progress = attune.progress
263287
end
@@ -276,20 +300,20 @@ function SkadaAttunes:Update(win,set)
276300
d.id = id
277301
d.icon = attune.icon
278302

279-
if attune.progress > max then
280-
max = attune.progress
281-
end
282303
nr = nr + 1
283304
end
284305

285-
win.metadata.maxvalue = 100
306+
-- Clean up old stuff
307+
--[[ for i = nr, #win.dataset, 1 do
308+
win.dataset[i].id = nil
309+
end ]]
286310
end
287311

288312

289313
function SkadaAttunes:OnEnable()
290-
SkadaAttunes.metadata = {tooltip = mod_tooltip}
314+
SkadaAttunes.metadata = {tooltip = mod_tooltip, wipestale = 1}
291315

292-
updateTimer = Skada:ScheduleRepeatingTimer(OnTimerTick, 1)
316+
updateTimer = self:ScheduleRepeatingTimer(OnTimerTick, 1)
293317

294318
Skada:RegisterForCL(OnAttuneProgress, 'PLAYER_XP_UPDATE', {src_is_interesting = true})
295319

@@ -338,7 +362,6 @@ function SkadaAttunes:AddSetAttributes(set)
338362
set.numAttunes = 0
339363

340364
local inProgress = getInProgressAttunes()
341-
-- Also add to set total damage taken.
342365
set.numAttunes = #inProgress
343366
end
344367
end
@@ -367,6 +390,14 @@ local opts = {
367390
set = function() Skada.db.profile.modules.attuneshowitemlevel = not Skada.db.profile.modules.attuneshowitemlevel end,
368391
order = 1
369392
},
393+
394+
showitemid = {
395+
type = "toggle",
396+
name = L["Show item id"],
397+
get = function() return Skada.db.profile.modules.attuneshowitemid end,
398+
set = function() Skada.db.profile.modules.attuneshowitemid = not Skada.db.profile.modules.attuneshowitemid end,
399+
order = 2
400+
},
370401
},
371402
},
372403

@@ -473,6 +504,10 @@ function SkadaAttunes:OnInitialize()
473504
Skada.db.profile.modules.attuneshowitemlevel = true
474505
end
475506

507+
if Skada.db.profile.modules.attuneshowitemid == nil then
508+
Skada.db.profile.modules.attuneshowitemid = false
509+
end
510+
476511
if Skada.db.profile.modules.attuneblocklist == nil then
477512
Skada.db.profile.modules.attuneblocklist = {}
478513
end

src/SkadaAttunes/SkadaAttunes.toc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## Title: Skada |r[|caaedc99fAttunes|r]
33
## Notes: Adds attunement tracking to Skada
44
## Author: Imevul
5-
## Version: 1.0.3
5+
## Version: 1.0.4
66
## Dependencies: Skada
77

88
SkadaAttunes.lua

0 commit comments

Comments
 (0)