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