Quicklog/DataStore.lua

210 lines
5.2 KiB
Lua

local name, addon = ...
local stores = {}
local methods_store = {}
local methods_source = {}
local methods_dest = {}
local testUnits = { 'TARGET' }
local UnitGUID, UnitClass, CopyTable = UnitGUID, UnitClass, CopyTable
local function findClass(guid)
for i = 1, #testUnits do
if(UnitGUID(testUnits[i])==guid) then
local _, class = UnitClass(testUnits[i])
return class
end
end
end
local function setClass(src, unitName, unitGuid)
if(unitName and not src['class']) then
local _, class = UnitClass(unitName)
if(not class) then
class = findClass(unitGuid)
end
if(class) then
src['class'] = class
end
end
end
local defaultSpell = {
['count'] = 0,
['crits'] = 0,
['total'] = 0,
['totalHeal'] = 0,
['totalAbsorbed'] = 0,
['totalOverheal'] = 0,
['min'] = 0,
['max'] = 0
}
local defaultSource = {
['dest'] = {},
['total'] = 0,
['totalHeal'] = 0,
['totalOverheal'] = 0,
['totalAbsorbed'] = 0,
}
local function GetDefaultSource(data, offset)
local offset = offset or 5
local src = CopyTable(defaultSource)
if(data) then
if(data:HasExtraSource()) then
offset = 16
-- return GetDefaultSource(data, 16)
end
src[1] = data[offset]
src[2] = data[offset + 1]
src['guid'] = data[offset]
src['name'] = data[offset + 1]
src['flags'] = data[offset + 2]
setClass(src, data[offset + 1], data[offset])
if(not src[2]) then
print("no src name", offset, data:HasExtraSource())
print(unpack(data))
end
end
return src
end
local defaultDestination = {
['spells'] = {},
['spellsHeal'] = {},
['spellsAbsorbed'] = {},
['total'] = 0,
['totalHeal'] = 0,
['totalAbsorbed'] = 0,
}
local function GetDefaultDestination(data)
local dest = CopyTable(defaultDestination)
dest[1] = data[9]
dest[2] = data[10]
dest['guid'] = data[9]
dest['name'] = data[10]
dest['flags'] = data[11]
setClass(dest, data[10], data[9])
return dest
end
--dest2:addAbsorbSpell(extraSpellID, extraSpellName, extraSchool, amount)
local function addSpell(data)
-- spellId[4], spellName, spellSchool, amount, overhealing, absorbed, critical
-- spellId[4], spellName, spellSchool, amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing, isOffHand
local unit = data[1]
local total = data[2]
local spells
if(total == 'totalAbsorbed') then
spells = unit['spellsAbsorbed']
elseif(total == 'totalHeal') then
spells = unit['spellsHeal']
else
spells = unit['spells']
end
local isHeal = data[3]
-- local data = {...}
if(data[4]) then
local amount = data[7]
-- if(not spells[data[4]]) then print('new spell', data[5]) end
local spell = spells[data[4]] or CopyTable(defaultSpell)
spell['spellName'] = data[5]
spell['spellSchool'] = data[6]
spell[total] = spell[total] + amount
spell['count'] = spell['count'] + 1
if(isHeal) then
--overhealing, absorbed, critical
if(data[8]) then
spell['totalOverheal'] = spell['totalOverheal'] + data[8]
end
if(data[10]) then
spell['crits'] = spell['crits'] + 1
end
else
--overkill, school, resisted, blocked, absorbed, critical, glancing, crushing, isOffHand
if(data[13]) then
spell['crits'] = spell['crits'] + 1
end
end
if(amount > spell['max']) then
spell['max'] = amount
end
if(amount < spell['min'] or spell['min'] == 0) then
spell['min'] = amount
end
-- spell['eventinfo'] = spell['eventinfo'] or {}
-- spell['eventinfo'][#spell['eventinfo'] + 1] = data
spells[data[4]] = spell
unit:addTotal(total, amount)
else
print('no spellId')
end
return spells
end
function methods_source:addTotal(total, amount)
self[total] = self[total] + amount
end
function methods_dest:addTotal(total, amount)
self[total] = self[total] + amount
end
function methods_dest:addAbsorbSpell(...)
local data = {self, 'totalAbsorbed', false, ...}
-- self['spellsAbsorbed'] =
addSpell(data)
end
function methods_dest:addSpell(...)
local data = {self, 'total', false, ...}
-- self['spells'] =
addSpell(data)
end
function methods_dest:addHealSpell(...)
local data = {self, 'totalHeal', true, ...}
-- self['spellsHeal'] =
addSpell(data)
end
function methods_source:GetDestination(destGuid)
if(destGuid) then
local dest
for k, v in pairs(self['dest']) do
if(k == destGuid) then
dest = v
break
end
end
dest = dest or GetDefaultDestination(self['data'])
for k, v in pairs(methods_dest) do
dest[k] = v
end
dest['sourceGuid'] = self['guid']
self['dest'][destGuid] = dest
return dest
end
end
function methods_store:GetSourceEmpty(data)
local guid = "Unknown"
self['source'][guid] = self['source'][guid] or GetDefaultSource(data)
local src = self['source'][guid]
src[2] = "<Unknown>"
src[1] = "Unknown"
src['data'] = data
for k, v in pairs(methods_source) do
src[k] = v
end
return src
end
function methods_store:GetSource(guid, data, offset, ignore)
if(guid and (ignore or data[4] == false)) then
self['source'][guid] = self['source'][guid] or GetDefaultSource(data, offset)
local src = self['source'][guid]
src['data'] = data
for k, v in pairs(methods_source) do
src[k] = v
end
return src
end
end
function addon:GetStore(seg)
if(not stores[seg]) then
-- print('new store')
stores[seg] = seg
for k, v in pairs(methods_store) do
stores[seg][k] = v
end
end
return stores[seg]
end