refactor: 优化代码结构和逻辑

This commit is contained in:
xinian
2026-03-31 08:19:53 +08:00
committed by cnb
parent b4a8048b85
commit d6d03a576d
21 changed files with 1166 additions and 1080 deletions

View File

@@ -5,8 +5,11 @@ import (
"blazing/logic/service/common"
"blazing/logic/service/fight"
"blazing/logic/service/player"
)
"github.com/samber/lo"
const (
petEVMaxTotal uint32 = 510
petEVMaxSingle uint32 = 255
)
// PetEVDiy 自定义分配宠物努力值EV
@@ -18,30 +21,39 @@ func (h Controller) PetEVDiy(data *PetEV, c *player.Player) (result *fight.NullO
if !found {
return nil, errorcode.ErrorCodes.Err10401
}
// 分配超过510的数据
if lo.Sum(data.EVs[:]) > 510 {
return nil, errorcode.ErrorCodes.Err10401
}
var targetTotal uint32
var currentTotal uint32
for i, evValue := range data.EVs {
// 分配超过255的数据
if evValue > 255 {
currentEV := currentPet.Ev[i]
// 单项分配不能超过上限。
if evValue > petEVMaxSingle {
return nil, errorcode.ErrorCodes.Err10401
}
// 分配比之前点数少的
if evValue < currentPet.Ev[i] {
targetTotal += evValue
if targetTotal > petEVMaxTotal {
return nil, errorcode.ErrorCodes.Err10401
}
}
if lo.Sum(data.EVs[:]) < lo.Sum(currentPet.Ev[:]) {
return nil, errorcode.ErrorCodes.Err10401
// 不允许回退已分配的努力值。
if evValue < currentEV {
return nil, errorcode.ErrorCodes.Err10401
}
currentTotal += currentEV
}
usedEV := lo.Sum(data.EVs[:]) - lo.Sum(currentPet.Ev[:])
// 加的比池子还多
usedEV := targetTotal - currentTotal
if usedEV == 0 {
return result, 0
}
// 新增分配不能超过玩家累计学习力池。
if int64(usedEV) > c.Info.EVPool {
return nil, errorcode.ErrorCodes.Err10401
}
currentPet.Ev = data.EVs
currentPet.CalculatePetPane(100)
c.Info.EVPool -= int64(usedEV)