0.1.214: Schnappschuss merkt Stufe und EP (beim Abmelden liefert der Client 0)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016onJCSHLwhs9udhC9ZLzk9
This commit is contained in:
Lacustat
2026-10-30 22:44:45 +01:00
co-authored by Claude Sonnet 5.5
parent 585a03470f
commit e74674abc5
2 changed files with 24 additions and 4 deletions
+23 -3
View File
@@ -45,6 +45,19 @@ local function Turned()
return db.turned[key]
end
-- Stufe und EP merken, solange sie lesbar sind (beim Abmelden liefert der Client 0)
local cur = {}
function Snap:Cache()
local lv = UnitLevel and UnitLevel("player") or 0
if type(lv) == "number" and lv > 0 then
cur.level = lv
cur.xp = UnitXP and UnitXP("player") or 0
cur.xpMax = UnitXPMax and UnitXPMax("player") or 0
local s = _G.FreewoodSnapshot
if s then s.level, s.xp, s.xpMax = cur.level, cur.xp, cur.xpMax end
end
end
-- Schnappschuss schreiben (Stufe und EP immer frisch, erledigte Quests aus den gemerkten Abgaben)
function Snap:Write()
if not _G.UnitName then return end
@@ -59,6 +72,7 @@ function Snap:Write()
local _, classToken = UnitClass("player")
local _, raceToken = UnitRace("player")
local old = _G.FreewoodSnapshot
self:Cache()
_G.FreewoodSnapshot = {
format = 1,
name = UnitName("player"),
@@ -67,9 +81,9 @@ function Snap:Write()
race = raceToken,
classId = Codex.PlayerClassID and Codex.PlayerClassID() or nil,
raceId = Codex.PlayerRaceID and Codex.PlayerRaceID() or nil,
level = UnitLevel("player"),
xp = UnitXP and UnitXP("player") or 0,
xpMax = UnitXPMax and UnitXPMax("player") or 0,
level = cur.level or (old and old.level) or 0,
xp = cur.xp or (old and old.xp) or 0,
xpMax = cur.xpMax or (old and old.xpMax) or 0,
saved = time(),
serverList = old and old.serverList or nil, -- Zeitpunkt der letzten Serverantwort
count = table.getn(ids),
@@ -113,6 +127,10 @@ function Snap:OnAddon(prefix, text, channel, sender)
end
end
function Snap:OnXp()
self:Cache()
end
function Snap:OnLogout()
self:Write()
end
@@ -127,6 +145,7 @@ function Snap:Start()
FW:RegisterEvent("CHAT_MSG_ADDON", self.OnAddon, self)
FW:RegisterEvent("PLAYER_LOGOUT", self.OnLogout, self)
FW:RegisterEvent("PLAYER_LEVEL_UP", self.OnLevel, self)
FW:RegisterEvent("PLAYER_XP_UPDATE", self.OnXp, self)
if C_Timer and C_Timer.After then
C_Timer.After(ASK_DELAY, function()
Snap:Write()
@@ -140,6 +159,7 @@ function Snap:Stop()
FW:UnregisterEvent("CHAT_MSG_ADDON", self)
FW:UnregisterEvent("PLAYER_LOGOUT", self)
FW:UnregisterEvent("PLAYER_LEVEL_UP", self)
FW:UnregisterEvent("PLAYER_XP_UPDATE", self)
end
_G.SLASH_FWSNAP1 = "/fwsnap"