Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions addons/scoreboard/damagedb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ local MergedPlayer = require 'mergedplayer'

local DamageDB = {
db = T{},
filter = T{}
filter = T{},
last_update = {}
}

--[[
Expand Down Expand Up @@ -79,11 +80,13 @@ function DamageDB:_get_player(mob, player_name)
if not self.db[mob] then
self.db[mob] = T{}
end

if not self.db[mob][player_name] then
self.db[mob][player_name] = Player:new{name = player_name}
end


self.last_update[mob] = os.time()

return self.db[mob][player_name]
end

Expand Down Expand Up @@ -128,6 +131,24 @@ end

function DamageDB:reset()
self.db = T{}
self.last_update = {}
end


-- Removes mob entries that haven't received data in max_age_seconds.
-- Returns true if any mobs were pruned.
function DamageDB:prune(max_age_seconds)
local now = os.time()
local pruned = false
for mob, _ in pairs(self.db) do
local ts = self.last_update[mob]
if ts and (now - ts) > max_age_seconds then
self.db[mob] = nil
self.last_update[mob] = nil
pruned = true
end
end
return pruned
end


Expand Down
4 changes: 3 additions & 1 deletion addons/scoreboard/data/settings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" ?>
<settings>
<!--
<!--
This file controls the settings for the Scoreboard plugin.
Settings in the <global> section apply to all characters

Expand All @@ -9,13 +9,15 @@
posY - y coordinate for position
numPlayers - The maximum number of players to display damage for
bgTransparency - Transparency level for the background. 0-255 range
logPeriod - Minutes to keep mob entries before pruning (0 = keep forever)
-->
<global>
<posX>10</posX>
<posY>250</posY>
<bgTransparency>200</bgTransparency>
<numPlayers>8</numPlayers>
<UpdateFrequency>0.5</UpdateFrequency>
<logPeriod>0</logPeriod>
</global>

<!--
Expand Down
39 changes: 10 additions & 29 deletions addons/scoreboard/mergedplayer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -209,24 +209,12 @@ end
function MergedPlayer:wsavg()
local wsdmg = 0
local wscount = 0
--[[
for _, p in pairs(self.players) do
for _, dmgtable in pairs(p.ws) do
for _, dmg in pairs(dmgtable) do
wsdmg = wsdmg + dmg
wscount = wscount + 1
end
end
end
]]


for _, p in pairs(self.players) do
for _, dmg in pairs(p.ws) do
wsdmg = wsdmg + dmg
wscount = wscount + 1
end
wsdmg = wsdmg + p.ws_total
wscount = wscount + p.ws_count
end

if wscount > 0 then
return {wsdmg / wscount, wscount}
else
Expand All @@ -236,12 +224,12 @@ end

function MergedPlayer:wsacc()
local hits, misses = 0, 0

for _, p in ipairs(self.players) do
hits = hits + table.length(p.ws)
hits = hits + p.ws_count
misses = misses + p.ws_misses
end

local total = hits + misses
if total > 0 then
return {hits / total, total}
Expand All @@ -254,16 +242,9 @@ end
function MergedPlayer:merge(other)
self.damage = self.damage + other.damage

for ws_id, values in pairs(other.ws) do
if self.ws[ws_id] then
for _, value in ipairs(values) do
self.ws[ws_id]:append(value)
end
else
self.ws[ws_id] = table.copy(values)
end
end

self.ws_total = self.ws_total + other.ws_total
self.ws_count = self.ws_count + other.ws_count

self.m_hits = self.m_hits + other.m_hits
self.m_misses = self.m_misses + other.m_misses
self.m_min = math.min(self.m_min, other.m_min)
Expand Down
13 changes: 4 additions & 9 deletions addons/scoreboard/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ function Player:new (o)
local attrs = {
clock = nil, -- specific DPS clock for this player
damage = 0, -- total damage done by this player
ws = T{}, -- table of all WS and their corresponding damage
ws_total = 0, -- sum of all WS damage
ws_count = 0, -- number of WS landed
ws_misses = 0, -- total ws misses
m_hits = 0, -- total melee hits
m_misses = 0, -- total melee misses
Expand Down Expand Up @@ -67,14 +68,8 @@ end


function Player:add_ws_damage(ws_name, damage)
--[[
if not self.ws[ws_name] then
self.ws[ws_name] = L{}
end

self.ws[ws_name]:append(damage)
]]
self.ws:append(damage)
self.ws_count = self.ws_count + 1
self.ws_total = self.ws_total + damage
self.damage = self.damage + damage
end

Expand Down
11 changes: 10 additions & 1 deletion addons/scoreboard/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ Command list:
//sb stat acc Shows accuracy for everyone
//sb stat crit Flippant Only show crit rate for Flippant

* SET <flag> <value>
Sets a configuration variable in-game and saves it to settings.xml.
Run //sb help for the full list of valid flags.
Examples:
//sb set LogPeriod 30 Prune mob entries after 30 minutes of inactivity
//sb set LogPeriod 0 Disable pruning (keep mob entries forever)

The settings file, located in addons/scoreboard/data/settings.xml, contains
additional configuration options:
* posX - x coordinate for position
Expand All @@ -99,7 +106,9 @@ additional configuration options:
* showallidps - Set to true to display the alliance DPS, false otherwise.
* resetfilters - Set to true if you want filters reset when you "//sb reset", false otherwise.
* showfellow - Set to true to display your adventuring fellow's DPS, false otherwise.

* logPeriod - Minutes to keep mob entries before pruning (0 = keep forever).
Can also be changed in-game with //sb set LogPeriod <minutes>.

Caveats:
* DPS is an approximation, although I tested it manually and found it to
be very accurate. Because DPS accumulation is based on the game's notion
Expand Down
Loading