package controller import ( "blazing/common/socket/errorcode" "blazing/logic/service/common" "blazing/logic/service/fight" "blazing/logic/service/player" ) 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) { slot, found := c.FindPetBagSlot(data.CacthTime) if !found { return nil, errorcode.ErrorCodes.Err10401 } currentPet := slot.PetInfoPtr() if currentPet == nil { return nil, errorcode.ErrorCodes.Err10401 } var targetTotal uint32 var currentTotal uint32 for i, evValue := range data.EVs { currentEV := currentPet.Ev[i] // 单项分配不能超过上限。 if evValue > petEVMaxSingle { return nil, errorcode.ErrorCodes.Err10401 } targetTotal += evValue if targetTotal > petEVMaxTotal { return nil, errorcode.ErrorCodes.Err10401 } // 不允许回退已分配的努力值。 if evValue < currentEV { return nil, errorcode.ErrorCodes.Err10401 } currentTotal += currentEV } 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) // result = &pet.S2C_50001{} // result.UseEV = -int32(usedEV) return result, 0 } // PetEV 定义请求或响应数据结构。 type PetEV struct { Head common.TomeeHeader `cmd:"50001" struc:"skip"` CacthTime uint32 `description:"捕捉时间" codec:"cacthTime"` EVs [6]uint32 `description:"属性" codec:"evs"` }