Files
bl/logic/controller/pet_ev.go

77 lines
1.9 KiB
Go
Raw Normal View History

package controller
import (
"blazing/common/socket/errorcode"
"blazing/logic/service/common"
"blazing/logic/service/fight"
"blazing/logic/service/player"
2026-03-31 08:19:53 +08:00
)
2026-03-31 08:19:53 +08:00
const (
petEVMaxTotal uint32 = 510
petEVMaxSingle uint32 = 255
)
// PetEVDiy 自定义分配宠物努力值EV
// data: 包含宠物捕获时间和EV分配数据的输入信息
// c: 当前玩家对象
// 返回: 分配结果和错误码
func (h Controller) PetEVDiy(data *PetEV, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
2026-04-15 00:07:36 +08:00
slot, found := c.FindPetBagSlot(data.CacthTime)
if !found {
return nil, errorcode.ErrorCodes.Err10401
}
2026-04-15 00:07:36 +08:00
currentPet := slot.PetInfoPtr()
if currentPet == nil {
return nil, errorcode.ErrorCodes.Err10401
}
2026-03-31 08:19:53 +08:00
var targetTotal uint32
var currentTotal uint32
for i, evValue := range data.EVs {
2026-03-31 08:19:53 +08:00
currentEV := currentPet.Ev[i]
// 单项分配不能超过上限。
if evValue > petEVMaxSingle {
return nil, errorcode.ErrorCodes.Err10401
}
2026-03-31 08:19:53 +08:00
targetTotal += evValue
if targetTotal > petEVMaxTotal {
return nil, errorcode.ErrorCodes.Err10401
}
2026-03-31 08:19:53 +08:00
// 不允许回退已分配的努力值。
if evValue < currentEV {
return nil, errorcode.ErrorCodes.Err10401
}
currentTotal += currentEV
}
2026-03-31 08:19:53 +08:00
usedEV := targetTotal - currentTotal
if usedEV == 0 {
return result, 0
}
2026-03-31 08:19:53 +08:00
// 新增分配不能超过玩家累计学习力池。
if int64(usedEV) > c.Info.EVPool {
return nil, errorcode.ErrorCodes.Err10401
}
2026-03-31 08:19:53 +08:00
currentPet.Ev = data.EVs
2026-03-23 22:00:05 +08:00
currentPet.CalculatePetPane(100)
c.Info.EVPool -= int64(usedEV)
// result = &pet.S2C_50001{}
// result.UseEV = -int32(usedEV)
return result, 0
}
2026-04-05 23:13:06 +08:00
// PetEV 定义请求或响应数据结构。
type PetEV struct {
Head common.TomeeHeader `cmd:"50001" struc:"skip"`
CacthTime uint32 `description:"捕捉时间" codec:"cacthTime"`
EVs [6]uint32 `description:"属性" codec:"evs"`
}