game/common/utils/util.go

29 lines
392 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package utils
import "math"
// 模板结构语法拒绝T{}但能接受TValue[T].V
type TValue[T any] struct {
V T
}
func Tie[T any](ret bool, v1, v2 T) T {
if ret {
return v1
}
return v2
}
func VipLevel(sumExp int32) (lv, exp int32) {
lv = 1
exp = 100
for {
if sumExp < exp {
return lv, sumExp
}
sumExp -= exp
lv++
exp = int32(math.Pow(float64(lv), 1.6))
}
}