refactor: 优化代码结构和逻辑
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user