From 9de1f3f90b2d94215f14458a11a951cb143a8dc2 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Mon, 15 Apr 2024 18:59:10 +0200 Subject: [PATCH] feat(xp): xp update without reseting last event --- xp/level.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/xp/level.go b/xp/level.go index 2ec6106..14d0e95 100644 --- a/xp/level.go +++ b/xp/level.go @@ -56,3 +56,18 @@ func onLastEventUpdate(c *Copaing) { c.Save() c.SetLastEvent() } + +func onXPUpdate(c *Copaing) { + h := c.HourSinceLastEvent() + l := Lose(h, c.XP) + xp := c.XPAlreadyRemoved() + if l-xp < 0 { + utils.SendWarn("lose - xp already removed is negative", "lose", l, "xp", xp) + c.XP = 0 + c.AddXPAlreadyRemoved(0) + } else { + c.XP -= l - c.XPAlreadyRemoved() + c.AddXPAlreadyRemoved(l - xp) + } + c.Save() +}