mirror of
https://github.com/Walter-Sparrow/lunar-tear.git
synced 2026-07-02 05:43:41 +03:00
20 lines
523 B
Go
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
|
|
}
|