Files
lunar-tear/server/internal/gameutil/exp.go
T
Ilya Groshev 02f511f40c Initial commit
2026-04-14 09:28:26 +03:00

20 lines
523 B
Go

package gameutil
// LevelAndCap returns the level for the given cumulative EXP based on
// the thresholds slice, and clamps EXP so it never exceeds the last
// threshold (max-level cap).
func LevelAndCap(exp int32, thresholds []int32) (level, capped int32) {
level = 1
for lvl := 1; lvl < len(thresholds); lvl++ {
if exp >= thresholds[lvl] {
level = int32(lvl)
} else {
break
}
}
if len(thresholds) > 0 && exp > thresholds[len(thresholds)-1] {
exp = thresholds[len(thresholds)-1]
}
return level, exp
}