diff --git a/history.lua b/history.lua
index b239dd4..febb5a2 100644
--- a/history.lua
+++ b/history.lua
@@ -1,6 +1,6 @@
hist = {
name = "history",
- version = "25",
+ version = "26",
initialised = false,
SV={},
L={},
@@ -38,6 +38,13 @@ local function log_me(text) -- per char log
})
end
+local Keep_Acheivement = function (cat) -- is this an acheivement we want to save?
+ if cat == 8 or cat == 3 or cat == 5 then
+ return false
+ end
+ return true
+end
+
local function get_start () -- get better start date from Achievements
-- Check Achievements
local earliest_time = 0
@@ -68,11 +75,12 @@ end
local function Achievement(_, name, points, id, link)
local description
- local category_id = GetCategoryInfoFromAchievementId(id)
+ local cat = GetCategoryInfoFromAchievementId(id)
local category_name =GetAchievementCategoryInfo(category_id)
_,description,_,_,_,_,_= GetAchievementInfo(id)
+ if Keep_Acheivement(cat) then
hist.me.ach[id]={
- ["Category_ID"] = category_id,
+ ["Category_ID"] = cat,
["Category"] = category_name,
["time"] = GetTimeStamp(),
["points"] = points,
@@ -85,6 +93,7 @@ local function Achievement(_, name, points, id, link)
d("Achievement Awarded:.. ")
d(hist.me.ach[id])
end
+ end
end
local function log_clear()
@@ -92,7 +101,7 @@ local function log_clear()
log("Cleared")
end
function load_history()
--- load up historic Achievements for Category 7 (Dungeons)
+-- load up historic Achievements
log("Request to load historic Dungeon Achievements")
local name,points,description,completed,adate,atime
local cat
@@ -101,8 +110,7 @@ function load_history()
name,description,points,_,completed,adate,atime= GetAchievementInfo(i)
if completed then
cat,_,_ =GetCategoryInfoFromAchievementId(i)
--- if cat == 7 then
- if true then
+ if Keep_Acheivement(cat) then
if hist.me.ach[i] == nil then
-- log("Added historic achievement " ..i .. " " .. name)
local category_id = GetCategoryInfoFromAchievementId(i)
@@ -155,8 +163,15 @@ local function new_map()
end
local function Activated()
+ hist.me.timeplayed_last = hist.me.timeplayed
hist.me.timeplayed = math.floor(GetSecondsPlayed() /60)
- hist.me.levels[hist.me.level].time = hist.me.timeplayed
+ if hist.me.levels[hist.me.level] ~= nil then
+ hist.me.levels[hist.me.level].time = hist.me.timeplayed
+ end
+
+ if hist.SV.CP_Level > 0 and hist.SV.CP[hist.SV.CP_Level] ~= nil then
+ hist.SV.CP[hist.SV.CP_Level].time = hist.SV.CP[hist.SV.CP_Level].time + hist.me.timeplayed - hist.me.timeplayed_last
+ end
local map = new_map()
if hist.me.maps[map].visit == nil then
@@ -168,17 +183,35 @@ end
local function levelup(_, unitTag,_)
- if unitTag == "player" then
- local oldlevel = hist.me.level
- hist.me.level = GetUnitLevel("player") + GetUnitVeteranRank("player")
- log("Levelled up. Was " .. oldlevel .. " now " .. hist.me.level)
+ if unitTag ~= "player" then
+ return
+ end
+
+ hist.me.base_level = GetUnitLevel("player")
+ hist.me.veteran_level = GetUnitVeteranRank("player")
+
+ -- Duplication of info, but easier to work with
+ local map = new_map()
+ if hist.me.maps[map].timeslevel == nil then
+ hist.me.maps[map].timeslevel = 1
+ hist.me.maps[map].firstlevel = hist.me.level
+ else
+ hist.me.maps[map].timeslevel = hist.me.maps[map].timeslevel + 1
+ end
+
+
+ if hist.me.veteran_level > 0 then return end
+
+ hist.me.level = hist.me.base_level
+
+ log("Level up to " .. hist.me.level)
hist.me.levels[hist.me.level] = {
begin = GetTimeStamp(),
time = 0, -- Accumulated time in Minutes
Ach_Points = GetEarnedAchievementPoints(),
deaths = 0
}
- local map = new_map()
+
--Update Level data with map
if hist.me.levels[hist.me.level].map == nil then
hist.me.levels[hist.me.level].map = map
@@ -189,76 +222,38 @@ local function levelup(_, unitTag,_)
d(msg)
end
end
-
-
-
- -- Duplication of info, but easier to work with
- if hist.me.maps[map].timeslevel == nil then
- hist.me.maps[map].timeslevel = 1
- hist.me.maps[map].firstlevel = hist.me.level
- else
- hist.me.maps[map].timeslevel = hist.me.maps[map].timeslevel + 1
- end
-
- if hist.debug then
- d("Hist: Leveled:.. ")
- d(hist.me.level)
- end
- else -- not "player"
- if hist.debug then
- d("Hist: Got Levelup Event, but not for me")
- d(unitTag)
- end
- end
end
local function CP_Levelup(_,unitTag, old, new)
- if unitTag == "player" then
- local oldlevel = hist.me.CP.level
- hist.me.level = GetUnitLevel("player") + GetUnitVeteranRank("player")
- log("CP Gained was " .. old .. ", now " .. new .. ", level: " .. hist.me.level)
- hist.me.levels[hist.me.level] = {
- begin = GetTimeStamp(),
- time = 0, -- Accumulated time in Minutes
- Ach_Points = GetEarnedAchievementPoints(),
- deaths = 0
- }
- local map = new_map()
- --Update Level data with map
- if hist.me.levels[hist.me.level].map == nil then
- hist.me.levels[hist.me.level].map = map
+ if unitTag ~= "player" then
+ return
+ end
- local msg = "First CP Gained in map " .. map
- log (msg)
- if hist.debug then
- d(msg)
- end
- end
+ hist.SV.CP_Level=tonumber(new) -- unclear of type, coerce
+ log("CP Gained was " .. old .. ", now " .. new)
+ hist.SV.CP[hist.SV.CP_Level] = {}
+ hist.SV.CP[hist.SV.CP_Level].begin= GetTimeStamp()
+ hist.SV.CP[hist.SV.CP_Level].playerID = hist.playerID
+ hist.SV.CP[hist.SV.CP_Level].map = map
+ hist.SV.CP[hist.SV.CP_Level].deaths =0
+ hist.SV.CP[hist.SV.CP_Level].time=0
+ hist.me.base_level = GetUnitLevel("player")
+ hist.me.veteran_level = GetUnitVeteranRank("player")
+ hist.me.level = hist.me.base_level + hist.me.veteran_level
- -- Duplication of info, but easier to work with
- if hist.me.maps[map].timeslevel == nil then
- hist.me.maps[map].timeslevel = 1
- hist.me.maps[map].firstlevel = hist.me.level
- else
- hist.me.maps[map].timeslevel = hist.me.maps[map].timeslevel + 1
- end
-
- if hist.debug then
- d("Hist: CP Gained:.. ")
- d(hist.me.level)
- end
+ if hist.debug then
end
+ log("CP_Level up to " .. new)
+
end
local function CP_Achieved(_,_)
log("Achieved Champion Rank.")
- hist.me.CP.FirstLocation = new_map()
- hist.me.CP.FirstTime = GetTimeStamp()
-
end
+
local function gendertext()
if (GetUnitGender("player") == GENDER_MALE)
then return "M"
@@ -279,13 +274,14 @@ local function setup_char()
hist.me.Class = zo_strformat("<<C:1>>",GetUnitClass("player"))
hist.me.Race = zo_strformat("<<C:1>>",GetUnitRace("player"))
hist.me.Gender = gendertext()
- hist.me.level = GetUnitLevel("player") + GetUnitVeteranRank("player")
+ hist.me.base_level = GetUnitLevel("player")
+ hist.me.veteran_level = GetUnitVeteranRank("player")
+ hist.me.level = hist.me.base_level + hist.me.veteran_level
hist.me.Alliance = zo_strformat("<<C:1>>",GetAllianceName(GetUnitAlliance("player")))
hist.me.ach={}
hist.me.maps={}
hist.me.log={}
- hist.me.CP={}
- hist.me.CP.level =0
+
hist.me.levels = {}
hist.me.levels[hist.me.level] = {
begin = GetTimeStamp(),
@@ -302,7 +298,11 @@ end
local function Dead()
-- Per Level
- hist.me.levels[hist.me.level].deaths = hist.me.levels[hist.me.level].deaths +1
+ if hist.me.levels[hist.me.base_level] == nil then
+ log("err: dead at " .. hist.me.base_level)
+ return
+ end
+ hist.me.levels[hist.me.base_level].deaths = hist.me.levels[hist.me.base_level].deaths +1
-- Per Map
local map = new_map()
@@ -322,8 +322,23 @@ local function Dead()
if hist.me.maps[map].firstdeathdate == nil then
hist.me.maps[map].firstdeathdate = GetTimeStamp()
end
+
+ if hist.SV.CP[hist.SV.CP_Level] ~= nil then
+ hist.SV.CP[hist.SV.CP_Level].deaths = hist.SV.CP[hist.SV.CP_Level].deaths +1
+ end
+
end
+del_old_categories = function()
+ log("Unwanted Category information Purged for all chars.")
+ for playerID, player in pairs (hist.SV.data) do
+ for ID, ach in pairs (player.ach) do
+ if Keep_Acheivement (ach["Category_ID"]) then
+ player.ach[ID] = nil
+ end
+ end
+ end
+end
function hist.Initialise(_, addOnName)
if (hist.name ~= addOnName) then return end
@@ -338,15 +353,30 @@ function hist.Initialise(_, addOnName)
hist.playerName = GetUnitName("player")
hist.playerID = GetCurrentCharacterId()
- local level = GetUnitLevel("player") + GetUnitVeteranRank("player")
-- Load the saved variables
hist.SV = ZO_SavedVars:NewAccountWide("History_SV", 1, nil, nil)
+ --remove old acheivement categories
+
+ if hist.SV.catcleaned == nil then
+ del_old_categories()
+ hist.SV.catcleaned = 1
+ end
+
if hist.SV.log == nil then
hist.SV.log = {}
log("hist.SV.log created")
end
+ if hist.SV.CP == nil then
+ hist.SV.CP = {}
+ end
+
+ if hist.SV.CP_Level == nil then
+ hist.SV.CP_Level = 0
+ end
+
+
if (hist.SV.data == nil ) then
hist.SV.data = {}
log("hist.SV.data created")
@@ -384,46 +414,30 @@ function hist.Initialise(_, addOnName)
end
hist.me = hist.SV.data[hist.playerID]
- if hist.me.level == nil then -- fix if doesn't exist
- hist.me.level = level
- end
+
+ hist.me.CP = nil
+ hist.me.craft = nil
+
+ hist.me.base_level = GetUnitLevel("player")
+ hist.me.veteran_level = GetUnitVeteranRank("player")
+ hist.me.level = hist.me.base_level + hist.me.veteran_level
+
+ hist.SV.CP_Level = GetPlayerChampionPointsEarned()
+
if hist.me.levels == nil then
- hist.me.levels = {}
- end
- if hist.me.craft == nil then
- hist.me.craft = {}
+ hist.me.levels = {}
end
+
if hist.me.maps == nil then
hist.me.maps = {}
end
- if hist.me.CP == nil then
- hist.me.CP = {}
- hist.me.CP.level =0
- end
-
if hist.me.log == nil then -- special events we want to keep, like name changes
hist.me.log = {}
end
-
-
- -- fix missed level, leveled up with addon disabled
- if hist.me.level ~= level then -- ignore CP level events
- if level<= 50 then
- log("Missed level, Was " .. hist.me.level .. " now " .. level)
- end
- hist.me.level = level
- hist.me.levels[hist.me.level] = {
- begin = GetTimeStamp(),
- time = 0, -- Accumulated time in Minutes
- Ach_Points = GetEarnedAchievementPoints(),
- deaths = 0
- }
- end
-
if hist.debug then
log_truncate(500)
else
@@ -467,7 +481,49 @@ function hist.Initialise(_, addOnName)
hist.me.Gender = gendertext()
end
+ --[[
+ -- remove levels without maps- these are probably CP and dud anyway.
+ local dud = 0
+ for key,L in pairs (hist.me.levels) do
+ if L.map == nil then
+ dud = dud +1
+ hist.me.levels[key] = nil
+ else
+
+ if key > 66 then -- is CP move to accountwide if not already there
+ local cpkey = key-50 -- max level now set to 50, so everything beyon
+ if hist.SV.CP[cpkey] == nil then
+ hist.SV.CP[cpkey] = {}
+ hist.SV.CP[cpkey].begin = L.begin
+ hist.SV.CP[cpkey].map = L.map
+ hist.SV.CP[cpkey].deaths = L.deaths
+ hist.SV.CP[cpkey].playerID = hist.playerID
+ hist.SV.CP[cpkey].time = L.time
+ log(cpkey .. " moved to CP")
+ hist.me.levels[key] = nil -- and delete old
+ else
+ log(key .. " not moved to CP")
+ end
+ end
+ end
+ end
+ --]]
+
+ --[[
+ hist.me.levels[hist.me.level] = {
+ begin = GetTimeStamp(),
+ time = 0, -- Accumulated time in Minutes
+ Ach_Points = GetEarnedAchievementPoints(),
+ deaths = 0
+ }
+
+ hist.SV.CP[new].begin= GetTimeStamp()
+ hist.SV.CP[new].playerID = hist.playerID
+ hist.SV.CP[new].map = map
+ hist.SV.CP[new].deaths =0
+ hist.SV.CP[new].time=0
+ --]]
EVENT_MANAGER:RegisterForEvent(hist.name, EVENT_ACHIEVEMENT_AWARDED, Achievement)
EVENT_MANAGER:RegisterForEvent(hist.name, EVENT_LEVEL_UPDATE, levelup)
EVENT_MANAGER:RegisterForEvent(hist.name, EVENT_CHAMPION_POINT_UPDATE, CP_Levelup)