diff --git a/CodexSnapshot.lua b/CodexSnapshot.lua index dab59f0..54f9d37 100644 --- a/CodexSnapshot.lua +++ b/CodexSnapshot.lua @@ -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" diff --git a/Freewood-OctoWoW-Codex.toc b/Freewood-OctoWoW-Codex.toc index 86d3703..d293777 100644 --- a/Freewood-OctoWoW-Codex.toc +++ b/Freewood-OctoWoW-Codex.toc @@ -3,7 +3,7 @@ ## Notes: Learns quests, creatures and drops while you play: who gives and takes a quest, rewards, objectives, drop chances. ## Notes-deDE: Lernt beim Spielen Quests, Kreaturen und Beute: wer eine Quest vergibt und annimmt, Belohnungen, Ziele, Drop-Chancen. ## Author: Lacustat -## Version: 0.1.213 +## Version: 0.1.214 ## Dependencies: Freewood-OctoWoW-Core ## SavedVariablesPerCharacter: FreewoodSnapshot ## OptionalDeps: Freewood-OctoWoW-CodexData, Freewood-OctoWoW-ForeverData