Files
bl/logic/controller/pet_ev.go
昔念 10af34fdad
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
```
refactor(controller): 移除独立的服务模块并将结构体定义内联到控制器中

移除了 egg、leiyi、pet 和 systemtime 独立服务包中的结构体定义,
将所有 C2S 和 S2C 结构体直接定义在相应的控制器文件中,同时更新了
导入路径和服务调用方式,统一使用 common.TomeeHeader 并优化了代码组织结构。

BREAKING CHANGE: 结构体定义从独立的服务包移动到控制器文件内部
2026-03-04 02:24:25 +08:00

59 lines
1.6 KiB
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 controller
import (
"blazing/common/socket/errorcode"
"blazing/logic/service/common"
"blazing/logic/service/fight"
"blazing/logic/service/player"
"github.com/samber/lo"
)
// PetEVDiy 自定义分配宠物努力值EV
// data: 包含宠物捕获时间和EV分配数据的输入信息
// c: 当前玩家对象
// 返回: 分配结果和错误码
func (h Controller) PetEVDiy(data *PetEV, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
_, currentPet, found := c.FindPet(data.CacthTime)
if !found {
return nil, errorcode.ErrorCodes.Err10401
}
// 分配超过510的数据
if lo.Sum(data.EVs[:]) > 510 {
return nil, errorcode.ErrorCodes.Err10401
}
for i, evValue := range data.EVs {
// 分配超过255的数据
if evValue > 255 {
return nil, errorcode.ErrorCodes.Err10401
}
// 分配比之前点数少的
if evValue < currentPet.Ev[i] {
return nil, errorcode.ErrorCodes.Err10401
}
}
if lo.Sum(data.EVs[:]) < lo.Sum(currentPet.Ev[:]) {
return nil, errorcode.ErrorCodes.Err10401
}
usedEV := lo.Sum(data.EVs[:]) - lo.Sum(currentPet.Ev[:])
// 加的比池子还多
if int64(usedEV) > c.Info.EVPool {
return nil, errorcode.ErrorCodes.Err10401
}
currentPet.Ev = data.EVs
currentPet.CalculatePetPane(false)
c.Info.EVPool -= int64(usedEV)
// result = &pet.S2C_50001{}
// result.UseEV = -int32(usedEV)
return result, 0
}
type PetEV struct {
Head common.TomeeHeader `cmd:"50001" struc:"skip"`
CacthTime uint32 `description:"捕捉时间" codec:"cacthTime"`
EVs [6]uint32 `description:"属性" codec:"evs"`
}