refactor: 将物品和货币相关字段从uint32改为int64以支持更大数值范围
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
This commit is contained in:
@@ -65,13 +65,13 @@ type PetInfo struct {
|
||||
Level uint32 `fieldDesc:"等级" `
|
||||
|
||||
// 当前等级已获得经验(@UInt long → uint32)
|
||||
Exp uint32
|
||||
Exp int64 `struc:"uint32"`
|
||||
|
||||
// 当前等级所需经验(@UInt long → uint32)
|
||||
LvExp uint32
|
||||
LvExp int64 `struc:"uint32"`
|
||||
|
||||
// 升到下一级的经验(@UInt long → uint32)
|
||||
NextLvExp uint32
|
||||
NextLvExp int64 `struc:"uint32"`
|
||||
|
||||
// 当前生命(@UInt long → uint32)
|
||||
Hp uint32
|
||||
@@ -128,7 +128,7 @@ const (
|
||||
// 功能:为宠物6个EV值增加增量,保证单个≤255、总和≤510
|
||||
// 参数:evadd - 6个EV字段的增量数组(长度必须为6)
|
||||
// 返回:error - 参数非法/逻辑异常时返回错误;bool - 是否触发了超额削减(方便业务监控)
|
||||
func (pet *PetInfo) AddEV(ev_add []uint32) (bool, error) {
|
||||
func (pet *PetInfo) AddEV(ev_add []int64) (bool, error) {
|
||||
// 1. 参数安全校验:避免数组越界panic
|
||||
if len(ev_add) != evFieldCount {
|
||||
return false, fmt.Errorf("evadd长度必须为%d,当前为%d", evFieldCount, len(ev_add))
|
||||
@@ -141,7 +141,7 @@ func (pet *PetInfo) AddEV(ev_add []uint32) (bool, error) {
|
||||
var tempEV [evFieldCount]uint32
|
||||
for i := 0; i < evFieldCount; i++ {
|
||||
// 直接累加增量
|
||||
tempEV[i] = pet.Ev[i] + ev_add[i]
|
||||
tempEV[i] = pet.Ev[i] + uint32(ev_add[i])
|
||||
// 单项不超过255
|
||||
if tempEV[i] > maxSingleEV {
|
||||
tempEV[i] = maxSingleEV
|
||||
@@ -342,7 +342,7 @@ func (petinfo *PetInfo) Update(isup bool) {
|
||||
// calculateExperience 计算指定等级和种族值所需的经验值
|
||||
// level: 当前等级
|
||||
// baseValue: 种族值
|
||||
func calculateExperience(level uint32, baseValue uint32) uint32 {
|
||||
func calculateExperience(level uint32, baseValue uint32) int64 {
|
||||
// 计算 A 部分:向上取整(3.75 * a * (a + 1))
|
||||
partA := math.Ceil(3.75 * float64(level) * float64(level+1))
|
||||
|
||||
@@ -354,7 +354,7 @@ func calculateExperience(level uint32, baseValue uint32) uint32 {
|
||||
|
||||
// 总经验是两部分之和,并向上取整
|
||||
totalExp := math.Ceil(partA + partB)
|
||||
return uint32(totalExp)
|
||||
return int64(totalExp)
|
||||
}
|
||||
|
||||
// PetEffectInfo 精灵特性信息结构
|
||||
|
||||
Reference in New Issue
Block a user