Sort by critpercent and casts are now working; new class 'SpellTable'
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
|
||||
local addonName, Details222 = ...
|
||||
local Details = Details
|
||||
local detailsFramework = DetailsFramework
|
||||
|
||||
--this are the fields from spellTable that can be summed
|
||||
local spellTable_FieldsToSum = {
|
||||
["counter"] = true,
|
||||
["total"] = true,
|
||||
["c_amt"] = true,
|
||||
["c_min"] = true,
|
||||
["c_max"] = true,
|
||||
["c_total"] = true,
|
||||
["n_amt"] = true,
|
||||
["n_total"] = true,
|
||||
["n_min"] = true,
|
||||
["n_max"] = true,
|
||||
["successful_casted"] = true,
|
||||
["g_amt"] = true,
|
||||
["g_dmg"] = true,
|
||||
["r_amt"] = true,
|
||||
["r_dmg"] = true,
|
||||
["b_amt"] = true,
|
||||
["b_dmg"] = true,
|
||||
["a_amt"] = true,
|
||||
["a_dmg"] = true,
|
||||
["totalabsorb"] = true,
|
||||
["absorbed"] = true,
|
||||
["overheal"] = true,
|
||||
["totaldenied"] = true,
|
||||
}
|
||||
|
||||
---@class spelltablemixin
|
||||
---@field GetCritPercent fun(spellTable: spelltable) : number
|
||||
---@field GetCritAverage fun(spellTable: spelltable) : number
|
||||
---@field SumSpellTables fun(spellTables: spelltable[], targetTable: table)
|
||||
---@field GetCastsAmount fun(spellTable: spelltable, actorName: string, combatObject: combat)
|
||||
|
||||
Details.SpellTableMixin = {
|
||||
---return the critical hits percent
|
||||
---@param spellTable spelltable
|
||||
---@return number
|
||||
GetCritPercent = function(spellTable)
|
||||
return (spellTable.c_amt / math.max(spellTable.counter, 0.0001)) * 100
|
||||
end,
|
||||
|
||||
---return the average value of critical hits
|
||||
---@param spellTable spelltable
|
||||
---@return number
|
||||
GetCritAverage = function(spellTable)
|
||||
return spellTable.c_total / math.max(spellTable.c_amt, 0.0001)
|
||||
end,
|
||||
|
||||
---return the amount of casts the spell had
|
||||
---@param spellTable spelltable
|
||||
---@param actorName string
|
||||
---@param combatObject combat
|
||||
---@return number
|
||||
GetCastsAmount = function(spellTable, actorName, combatObject)
|
||||
return combatObject:GetSpellCastAmount(actorName, spellTable.id)
|
||||
end,
|
||||
|
||||
---get the array of spelltables and sum each spellTable with the first spellTable found or on targetTable
|
||||
---only sum the keys found in the spellTable_FieldsToSum table
|
||||
---@param spellTables spelltable[]
|
||||
---@param targetTable table
|
||||
SumSpellTables = function(spellTables, targetTable)
|
||||
local amtSpellTables = #spellTables
|
||||
|
||||
if (amtSpellTables == 0) then
|
||||
return
|
||||
end
|
||||
|
||||
targetTable = targetTable or spellTables[1]
|
||||
|
||||
for i = 1, amtSpellTables do
|
||||
local spellTable = spellTables[i]
|
||||
if (spellTable) then
|
||||
for key, value in pairs(spellTable) do
|
||||
---@cast key string
|
||||
---@cast value number
|
||||
if (spellTable_FieldsToSum[key]) then
|
||||
targetTable[key] = (targetTable[key] or 0) + value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
}
|
||||
|
||||
--detailsFramework:Mixin(Details, Details.SpellTableMixin)
|
||||
Reference in New Issue
Block a user