diff --git a/Delete-Character.lua b/Delete-Character.lua index 29b9ba8..85b392a 100644 --- a/Delete-Character.lua +++ b/Delete-Character.lua @@ -8,6 +8,8 @@ Utility to delete old chars ]] +--for version 29 + -- Configuration ========== local dateformat = "%Y-%m-%d, %H:%M" diff --git a/HistOffline.lua b/HistOffline.lua index 20d2f5f..86d74d1 100644 --- a/HistOffline.lua +++ b/HistOffline.lua @@ -134,6 +134,8 @@ playerNames = {} -- Get name from ID. for acc,_ in pairs(History_SV["Default"]) do accounts[acc] = {} + accounts[acc].worlds = {} + accounts[acc].hasblankworlds = false accounts[acc].player = {} accounts[acc].playerIDs = {} -- intermediate table for sorting. WIP. Controls presentation order accounts[acc].playerIDs_vet= {} --subset of names which are >L50 @@ -154,6 +156,17 @@ for acc,_ in pairs(History_SV["Default"]) do DLC_names = lingua[accounts[acc].lang].DLC_names DLC_Location_names = lingua[accounts[acc].lang].DLC_Location_names Ach_Detail = lingua[accounts[acc].lang].Ach_Detail +-- load worlds + nworlds = 0 + if History_SV["Default"][acc]["$AccountWide"]["worlds"] ~= nil then + for i,j in pairs(History_SV["Default"][acc]["$AccountWide"]["worlds"]) do + nworlds = nworlds +1 + table.insert(accounts[acc].worlds, i) + end + end + +-- insert marker for older chars +-- table.insert(accounts[acc].worlds, "##NEITHER##") -- Load Character Data @@ -200,6 +213,14 @@ for acc,_ in pairs(History_SV["Default"]) do else me.timeplayed = math.floor(thischar.timeplayed/60) end + -- world + + if thischar.world == nil then + accounts[acc].hasblankworlds = true -- causes display of "##NEITHER## + else + me.world = thischar.world -- server + end + end table.sort(accounts[acc].playerIDs,function(a,b) return (playerNames[a] < playerNames[b]) end) @@ -249,7 +270,8 @@ end iup.fill{} } -- Top Level Panels - accounts[acc].mode_zbox = iup.zbox{} -- display main panel containing tabs and dungeons + accounts[acc].world_zbox = iup.zbox{} -- display main panel containing worlds (servers) + accounts[acc].mode_zbox = iup.zbox{} -- display submain panel containing tabs and dungeons accounts[acc].char_tabs = iup.tabs{} -- Top level of Char_Tabs, Character Info in Here accounts[acc].dung_tabs = iup.tabs{} -- Top level of Dung_Tabs, Dungeon Info in Here @@ -369,7 +391,7 @@ end --================= START OF CHARACTER MODE DISPLAY --- Creates boxes, stage from names to allow optional sorting in future. +-- Creates boxes, stage from names to allow sorting for _,playerID in ipairs(accounts[acc].playerIDs) do local me = accounts[acc].player[playerID] -- shorter reference: our code local thischar = History_SV["Default"][acc]["$AccountWide"]["data"][playerID] -- shorter reference: History DB diff --git a/history.lua b/history.lua index 719358b..7504a5d 100644 --- a/history.lua +++ b/history.lua @@ -12,11 +12,11 @@ hist = { } --GetWorldName() local function log_truncate(max) ---Limit log to max + --Limit log to max for _ = max, (#hist.SV.log-1) do table.remove(hist.SV.log,1) if hist.debug then - d("Truncated log. Size now: " .. tostring(#hist.SV.log)) + d("Truncated log. Size now: " .. tostring(#hist.SV.log)) end end end @@ -24,61 +24,61 @@ end local function log(text) - table.insert(hist.SV.log,{["TimeStamp"]=GetTimeStamp(), - ["text"] = text, - ["Char"] = hist.playerName, - ["CharID"] = hist.playerID, - ["world"] = GetWorldName(), - }) +table.insert(hist.SV.log,{["TimeStamp"]=GetTimeStamp(), + ["text"] = text, + ["Char"] = hist.playerName, + ["CharID"] = hist.playerID, + ["world"] = GetWorldName(), + }) end local function log_me(text) -- per char log - table.insert(hist.me.log,{["TimeStamp"]=GetTimeStamp(), - ["text"] = text, - }) +table.insert(hist.me.log,{["TimeStamp"]=GetTimeStamp(), +["text"] = text, +}) end local Keep_Achievement = function (cat) -- is this an achievement we want to save? - if cat == 9 or cat == 8 or cat == 3 or cat == 4 or cat == 5 or cat == nil then - return false - end - return true +if cat == 9 or cat == 8 or cat == 3 or cat == 4 or cat == 5 or cat == nil then +return false +end +return true end local function get_start () -- get better start date from Achievements - -- Check Achievements - local earliest_time = 0 - local earliest_Achievement - for id, ach in pairs(hist.me.ach) do - if earliest_time == 0 then - earliest_time = ach.time - earliest_Achievement = id - elseif earliest_time > ach.time then - earliest_time = ach.time - end - end + -- Check Achievements + local earliest_time = 0 + local earliest_Achievement + for id, ach in pairs(hist.me.ach) do + if earliest_time == 0 then + earliest_time = ach.time + earliest_Achievement = id + elseif earliest_time > ach.time then + earliest_time = ach.time + end +end - if earliest_time == 0 then -- No Achievements - earliest_time = GetTimeStamp() - end +if earliest_time == 0 then -- No Achievements + earliest_time = GetTimeStamp() +end - if hist.me.Created == nil then - hist.me.Created = earliest_time - elseif hist.me.Created > earliest_time then -- Quest was earlier, then reset to earlier - if hist.debug then - d("Start Time Reset for " .. hist.playerName) - end - log ("Start Time Reset.") - hist.me.Created = earliest_time - end +if hist.me.Created == nil then + hist.me.Created = earliest_time + elseif hist.me.Created > earliest_time then -- Quest was earlier, then reset to earlier + if hist.debug then +d("Start Time Reset for " .. hist.playerName) +end + log ("Start Time Reset.") + hist.me.Created = earliest_time + end end local function Achievement(_, name, points, id, link) local description local category_id = GetCategoryInfoFromAchievementId(id) local category_name =GetAchievementCategoryInfo(category_id) - _,description,_,_,_,_,_= GetAchievementInfo(id) + _,description,_,_,_,_,_= GetAchievementInfo(id) if Keep_Achievement(category_id) then hist.me.ach[id] = {} hist.me.ach[id].Category_ID = category_id @@ -89,16 +89,16 @@ local function Achievement(_, name, points, id, link) hist.me.ach[id].description = zo_strformat(description) hist.me.ach[id].link = link - if hist.debug then - d("Achievement Awarded:.. ") - d(hist.me.ach[id]) - end + if hist.debug then + d("Achievement Awarded:.. ") + d(hist.me.ach[id]) + end end end local function log_clear() - hist.SV.log = {} - log("Cleared") +hist.SV.log = {} +log("Cleared") end function load_history() -- load up historic Achievements. @@ -110,10 +110,10 @@ function load_history() local flag = 0 for i = 1,2000 do name,description,points,_,completed,adate,atime= GetAchievementInfo(i) - if completed then - local category_id = GetCategoryInfoFromAchievementId(i) -- nill if bad - if Keep_Achievement(category_id) then - if hist.me.ach[i] == nil then + if completed then + local category_id = GetCategoryInfoFromAchievementId(i) -- nil if bad + if Keep_Achievement(category_id) then + if hist.me.ach[i] == nil then hist.me.ach[i] = {} hist.me.ach[i].Category_ID = category_id hist.me.ach[i].Category = GetAchievementCategoryInfo(category_id) @@ -123,21 +123,21 @@ function load_history() hist.me.ach[i].description = zo_strformat(description) hist.me.ach[i].link = GetAchievementLink(i) count = count + 1 + end + else + reject = reject +1 end - else - reject = reject +1 end end - end - log("Added " .. tostring(count) .. " historic achievements.") - if hist.debug then + log("Added " .. tostring(count) .. " historic achievements.") + if hist.debug then d("Added " .. count .. " achievements.") d("Rejected " .. reject .. " achievements.") end end local function fix() -- fix links etc for any old data -local description + local description hist.me.ach_updates = nil log("Request to fix Achievement data") local obsolete = 0 @@ -164,7 +164,7 @@ local description end local function new_map() - local map = zo_strformat("<<C:1>>",GetMapName()) +local map = zo_strformat("<<C:1>>",GetMapName()) if hist.me.maps[map] == nil then hist.me.maps[map] = {} hist.me.maps[map].firstvisitdate = GetTimeStamp() @@ -204,13 +204,13 @@ local function levelup(_, unitTag,_) hist.me.base_level = GetUnitLevel("player") hist.me.veteran_level = GetUnitVeteranRank("player") - -- Duplication of info, but easier to work with + -- 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 + hist.me .maps[map].timeslevel = hist.me.maps[map].timeslevel + 1 end @@ -219,12 +219,12 @@ local function levelup(_, unitTag,_) hist.me.level = hist.me.base_level + hist.me.veteran_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 - } + hist.me.levels[hist.me.level] = { + begin = GetTimeStamp(), + time = 0, -- Accumulated time in Minutes + Ach_Points = GetEarnedAchievementPoints(), + deaths = 0 + } --Update Level data with map if hist.me.levels[hist.me.level].map == nil then @@ -268,54 +268,51 @@ end local function gendertext() if (GetUnitGender("player") == GENDER_MALE) - then return "M" + then return "M" end if (GetUnitGender("player") == GENDER_FEMALE) - then return "F" + then return "F" end - return "U" end + local function setup_char() - log("Set up: " .. hist.playerName ) - hist.SV.data[hist.playerID] = {} -- initialise data for current char, using unique GUID - hist.me = hist.SV.data[hist.playerID] - hist.me.name=hist.playerName - - hist.me.Class = zo_strformat("<<C:1>>",GetUnitClass("player")) - hist.me.Race = zo_strformat("<<C:1>>",GetUnitRace("player")) - hist.me.Gender = gendertext() - 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.world = GetWorldName() - hist.me.Alliance = zo_strformat("<<C:1>>",GetAllianceName(GetUnitAlliance("player"))) - hist.me.ach={} - hist.me.maps={} - hist.me.log={} - - hist.me.levels = {} - hist.me.levels[hist.me.level] = { - begin = GetTimeStamp(), - time = 0, -- Accumulated time in Minutes - Ach_Points = GetEarnedAchievementPoints(), - deaths = 0 + log("Set up: " .. hist.playerName ) + hist.SV.data[hist.playerID] = {} -- initialise data for current char, using unique GUID + hist.me = hist.SV.data[hist.playerID] + hist.me.name=hist.playerName + hist.me.Class = zo_strformat("<<C:1>>",GetUnitClass("player")) + hist.me.Race = zo_strformat("<<C:1>>",GetUnitRace("player")) + hist.me.Gender = gendertext() + 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.world = GetWorldName() + hist.me.Alliance = zo_strformat("<<C:1>>",GetAllianceName(GetUnitAlliance("player"))) + hist.me.ach={} + hist.me.maps={} + hist.me.log={} + + hist.me.levels = {} + hist.me.levels[hist.me.level] = { + begin = GetTimeStamp(), + time = 0, -- Accumulated time in Minutes + Ach_Points = GetEarnedAchievementPoints(), + deaths = 0 } -- end of defaults - hist.me["LoadTime"] = GetTimeStamp() - load_history() - get_start() - log_me("Started") + hist.me["LoadTime"] = GetTimeStamp() + load_history() + get_start() + log_me("Started") end local function Dead() -- Per Level - if hist.me.levels[hist.me.level] == nil then - log("err: dead at " .. hist.me.level) - return + if hist.me.levels[hist.me.level] ~= nil then + hist.me.levels[hist.me.base_level].deaths = hist.me.levels[hist.me.base_level].deaths +1 -- low level deaths end - hist.me.levels[hist.me.base_level].deaths = hist.me.levels[hist.me.base_level].deaths +1 -- Per Map local map = new_map() @@ -326,9 +323,9 @@ local function Dead() hist.me.maps[map].firstdeathlevel = hist.me.level local msg = "First Death in map " .. map log (msg) - if hist.debug then - d("First Death in map " ..map) - end + if hist.debug then + d("First Death in map " ..map) + end end hist.me.maps[map].deaths = hist.me.maps[map].deaths +1 @@ -336,19 +333,21 @@ local function Dead() hist.me.maps[map].firstdeathdate = GetTimeStamp() end - if hist.world.CP_Level == 0 then return + if hist.world.CP_Level == 0 then + d("Death: world CP level == 0,aborting processing of CP" ) + return end - - - + + + if hist.world.CP[hist.world.CP_Level] ~= nil then hist.world.CP[hist.world.CP_Level].deaths = hist.world.CP[hist.world.CP_Level].deaths +1 else - local msg = "Died but CP entry for " .. tostring(hist.world.CP_Level) .. " was nil." - log (msg) - if hist.debug then - d(msg) - end + local msg = "Died but CP entry for " .. tostring(hist.world.CP_Level) .. " was nil." + log (msg) + if hist.debug then + d(msg) + end end end @@ -359,8 +358,8 @@ del_old_categories = function() log("Deleting old categories for " .. player.name) for ID, ach in pairs (player.ach) do if not (Keep_Achievement (ach["Category_ID"])) then - player.ach[ID] = nil - count = count +1 + player.ach[ID] = nil + count = count +1 end end end @@ -370,7 +369,7 @@ end del_old_levels = function () for playerID, player in pairs (hist.SV.data) do - -- remove levels without maps- these are probably CP and dud anyway. + -- remove levels without maps- these are probably CP and dud anyway. log("Deleting old levels for " .. player.name) local dud = 0 for key,L in pairs (player.levels) do @@ -380,7 +379,7 @@ del_old_levels = function () 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 + local cpkey = key-50 -- max level now set to 50, so everything beyon if hist.world.CP[cpkey] == nil then hist.world.CP[cpkey] = {} hist.world.CP[cpkey].begin = L.begin @@ -400,7 +399,7 @@ del_old_levels = function () end function hist.Initialise(_, addOnName) - if (hist.name ~= addOnName) then return end +if (hist.name ~= addOnName) then return end -- find computed time difference. local now = GetTimeStamp() @@ -412,53 +411,59 @@ function hist.Initialise(_, addOnName) hist.playerName = GetUnitName("player") hist.playerID = GetCurrentCharacterId() - -- Load the saved variables - hist.SV = ZO_SavedVars:NewAccountWide("History_SV", 1, nil, nil) + -- Load the saved variables + hist.SV = ZO_SavedVars:NewAccountWide("History_SV", 1, nil, nil) if hist.SV.log == nil then - hist.SV.log = {} - log("hist.SV.log created") + hist.SV.log = {} + log("hist.SV.log created") end if hist.SV.worlds == nil then - hist.SV.worlds = {} + hist.SV.worlds = {} end if hist.SV.worlds[GetWorldName()] == nil then - hist.SV.worlds[GetWorldName()] = {} + hist.SV.worlds[GetWorldName()] = {} end - + hist.world = hist.SV.worlds[GetWorldName()] if hist.world.CP == nil then - hist.world.CP = {} + hist.world.CP = {} end - - --- if hist.SV.CP == nil then --- hist.SV.CP = {} --- end hist.world.CP_Level = GetPlayerChampionPointsEarned() if (hist.SV.data == nil ) then - hist.SV.data = {} - log("hist.SV.data created") + hist.SV.data = {} + log("hist.SV.data created") end if (hist.SV.old ~= nil) then -- Delete legacy data that we never used anyway - hist.SV.old = nil + hist.SV.old = nil end hist.SV.CP_Level = nil - + -- once only move of CP data to new location. if hist.SV.CP ~= nil then - hist.world.CP = hist.SV.CP - hist.SV.CP = nil + hist.world.CP = hist.SV.CP + hist.SV.CP = nil end - - + + + -- CP leveling screwed, after all of this .. at least make current + + if hist.world.CP[hist.world.CP_Level] == nil then + hist.world.CP[hist.world.CP_Level] = {} + hist.world.CP[hist.world.CP_Level].begin= GetTimeStamp() + hist.world.CP[hist.world.CP_Level].playerID = hist.playerID + hist.world.CP[hist.world.CP_Level].map = "BORKY" + hist.world.CP[hist.world.CP_Level].deaths =0 + hist.world.CP[hist.world.CP_Level].time=0 + hist.world.CP[hist.world.CP_Level].borked = true + end --remove old achievement categories if hist.SV.cleaned1 == nil then @@ -466,32 +471,32 @@ function hist.Initialise(_, addOnName) del_old_levels() hist.SV.cleaned1 = 1 end - + if (hist.SV.start_version == nil ) then - hist.SV.start_version = hist.version + hist.SV.start_version = hist.version end hist.SV.this_version = hist.version - --- hist.SV.version -- Used by ZOS System, dont touch + --- hist.SV.version -- Used by ZOS System, dont touch if hist.SV.data[hist.playerID] == nil then if debug then - log("No data found for PlayerID") + log("No data found for PlayerID") end -- Ok playerID may be nil, but we might still have data under player name -- In which case we rename it, otherwise it is a new char. if hist.SV.data[hist.playerName] == nil then - --No name, no ID, must be new. - setup_char() + --No name, no ID, must be new. + setup_char() else - -- Ok old name data, fix it. - log("New data format, saving " .. hist.playerName .. " as " .. hist.playerID) - hist.SV.data[hist.playerID] = hist.SV.data[hist.playerName] - hist.SV.data[hist.playerID].name = hist.playerName + -- Ok old name data, fix it. + log("New data format, saving " .. hist.playerName .. " as " .. hist.playerID) + hist.SV.data[hist.playerID] = hist.SV.data[hist.playerName] + hist.SV.data[hist.playerID].name = hist.playerName - hist.SV.data[hist.playerName] = nil -- and on the eighth day God invented Lua + hist.SV.data[hist.playerName] = nil -- and on the eighth day God invented Lua end end @@ -509,68 +514,68 @@ function hist.Initialise(_, addOnName) if hist.me.levels == nil then - hist.me.levels = {} + hist.me.levels = {} end if hist.me.maps == nil then - hist.me.maps = {} + hist.me.maps = {} end if hist.me.log == nil then -- special events we want to keep, like name changes - hist.me.log = {} + hist.me.log = {} end if hist.debug then - log_truncate(500) + log_truncate(500) else - log_truncate(20) + log_truncate(20) end hist.SV.lang=GetCVar("language.2") -- For offline use if hist.me.logins == nil then - hist.me.logins = 0 + hist.me.logins = 0 end hist.me.logins = hist.me.logins +1 -- count them. hist.me["LoginTime"] = GetTimeStamp() if hist.me["ReloadTime"] == nil then - hist.me["ReloadTime"] = GetTimeStamp() + hist.me["ReloadTime"] = GetTimeStamp() end if hist.me["ReloadTime"] + 80080 <= GetTimeStamp() then -- 23 hours or more have past - load_history() -- pickup anything that might be missed - hist.me["ReloadTime"] = GetTimeStamp() - log ("Startup: Timed check on missed achievements.") + load_history() -- pickup anything that might be missed + hist.me["ReloadTime"] = GetTimeStamp() + log ("Startup: Timed check on missed achievements.") end if hist.me.name ~= hist.playerName then - log("Changed Name, Was " .. hist.me.name) - log_me("Changed Name, Was " .. hist.me.name) - hist.me.name = hist.playerName + log("Changed Name, Was " .. hist.me.name) + log_me("Changed Name, Was " .. hist.me.name) + hist.me.name = hist.playerName end if hist.me.Race ~= zo_strformat("<<C:1>>",GetUnitRace("player")) then - log("Changed Race, Was " .. hist.me.Race) - log_me("Changed Race, Was " .. hist.me.Race) - hist.me.Race = zo_strformat("<<C:1>>",GetUnitRace("player")) + log("Changed Race, Was " .. hist.me.Race) + log_me("Changed Race, Was " .. hist.me.Race) + hist.me.Race = zo_strformat("<<C:1>>",GetUnitRace("player")) end if hist.me.Gender ~= gendertext() then - log("Changed Gender, Was " .. hist.me.Gender) - log_me("Changed Gender, Was " .. hist.me.Gender) - hist.me.Gender = gendertext() + log("Changed Gender, Was " .. hist.me.Gender) + log_me("Changed Gender, Was " .. hist.me.Gender) + hist.me.Gender = gendertext() end 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) EVENT_MANAGER:RegisterForEvent(hist.name, EVENT_CHAMPION_LEVEL_ACHIEVED , CP_Achieved) --- EVENT_MANAGER:RegisterForEvent(hist.name, EVENT_VETERAN_RANK_UPDATE, levelup) + -- EVENT_MANAGER:RegisterForEvent(hist.name, EVENT_VETERAN_RANK_UPDATE, levelup) EVENT_MANAGER:RegisterForEvent(hist.name, EVENT_PLAYER_ACTIVATED, Activated) --- EVENT_MANAGER:RegisterForEvent(hist.name, EVENT_PLAYER_DEACTIVATED, Activated) + -- EVENT_MANAGER:RegisterForEvent(hist.name, EVENT_PLAYER_DEACTIVATED, Activated) EVENT_MANAGER:RegisterForEvent(hist.name, EVENT_PLAYER_DEAD, Dead) EVENT_MANAGER:RegisterForEvent(hist.name, EVENT_ZONE_CHANGED, new_map) hist.initialised = true