refactor: 将物品和货币相关字段从uint32改为int64以支持更大数值范围
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
This commit is contained in:
@@ -119,9 +119,9 @@ func (m *PlayerInfo) GetTask(i int) TaskStatus {
|
||||
}
|
||||
|
||||
type PlayerInfo struct {
|
||||
ExpPool uint32 `struc:"skip" json:"exp_pool"` // 累计经验池
|
||||
ExpPool int64 `struc:"skip" json:"exp_pool"` // 累计经验池
|
||||
|
||||
OnlineTime uint32 `struc:"skip" json:"online_time"` //在线分钟数
|
||||
OnlineTime int64 `struc:"skip" json:"online_time"` //在线分钟数
|
||||
// OutInfo 字段
|
||||
UserID uint32 `struc:"uint32" json:"user_id"` // 米米号 通过sid拿到
|
||||
RegisterTime uint32 `struc:"uint32" json:"register_time"` // 注册时间(秒时间戳)
|
||||
@@ -133,13 +133,13 @@ type PlayerInfo struct {
|
||||
Color uint32 `struc:"uint32" json:"color"` // 机器人颜色RGB颜色值(uint32,实际为3个uint8)
|
||||
Texture uint32 `struc:"uint32" json:"texture"` // 固定0
|
||||
Energy uint32 `struc:"uint32" default:"3000" json:"energy"` // 固定3000
|
||||
Coins uint32 `struc:"uint32" json:"coins"` // 赛尔豆
|
||||
EVPool uint32 `struc:"uint32" json:"ev_pool"` //累计学习力
|
||||
Coins int64 `struc:"uint32" json:"coins"` // 赛尔豆
|
||||
EVPool int64 `struc:"uint32" json:"ev_pool"` //累计学习力
|
||||
FightBadge uint32 `struc:"uint32" json:"fight_badge"` // 固定0
|
||||
MapID uint32 `struc:"uint32" default:"1" json:"map_id"` // 上线地图ID
|
||||
Pos Pos `json:"pos"` // 坐标
|
||||
TimeToday uint32 `struc:"uint32" default:"0" json:"time_today"` // 已消耗时间(秒)
|
||||
TimeLimit uint32 `struc:"uint32" default:"43200" json:"time_limit"` // 总电池限制(秒)
|
||||
TimeToday int64 `struc:"uint32" default:"0" json:"time_today"` // 已消耗时间(秒)
|
||||
TimeLimit int64 `struc:"uint32" default:"43200" json:"time_limit"` // 总电池限制(秒)
|
||||
IsClothHalfDay byte `struc:"byte" json:"is_cloth_half_day"` // 活动标志0/1
|
||||
IsRoomHalfDay byte `struc:"byte" json:"is_room_half_day"` // 活动标志0/1
|
||||
IFortressHalfDay byte `struc:"byte" json:"i_fortress_half_day"` // 活动标志0/1
|
||||
|
||||
@@ -15,7 +15,7 @@ type Item struct {
|
||||
BindPet uint32 `json:"bind_pet"` //绑定的精灵
|
||||
|
||||
// 物品数量,
|
||||
ItemCnt int32 `json:"item_cnt"`
|
||||
ItemCnt int64 `json:"item_cnt"`
|
||||
}
|
||||
|
||||
type SingleItemInfo struct {
|
||||
|
||||
@@ -65,13 +65,13 @@ type PetInfo struct {
|
||||
Level uint32 `fieldDesc:"等级" `
|
||||
|
||||
// 当前等级已获得经验(@UInt long → uint32)
|
||||
Exp uint32
|
||||
Exp int64 `struc:"uint32"`
|
||||
|
||||
// 当前等级所需经验(@UInt long → uint32)
|
||||
LvExp uint32
|
||||
LvExp int64 `struc:"uint32"`
|
||||
|
||||
// 升到下一级的经验(@UInt long → uint32)
|
||||
NextLvExp uint32
|
||||
NextLvExp int64 `struc:"uint32"`
|
||||
|
||||
// 当前生命(@UInt long → uint32)
|
||||
Hp uint32
|
||||
@@ -128,7 +128,7 @@ const (
|
||||
// 功能:为宠物6个EV值增加增量,保证单个≤255、总和≤510
|
||||
// 参数:evadd - 6个EV字段的增量数组(长度必须为6)
|
||||
// 返回:error - 参数非法/逻辑异常时返回错误;bool - 是否触发了超额削减(方便业务监控)
|
||||
func (pet *PetInfo) AddEV(ev_add []uint32) (bool, error) {
|
||||
func (pet *PetInfo) AddEV(ev_add []int64) (bool, error) {
|
||||
// 1. 参数安全校验:避免数组越界panic
|
||||
if len(ev_add) != evFieldCount {
|
||||
return false, fmt.Errorf("evadd长度必须为%d,当前为%d", evFieldCount, len(ev_add))
|
||||
@@ -141,7 +141,7 @@ func (pet *PetInfo) AddEV(ev_add []uint32) (bool, error) {
|
||||
var tempEV [evFieldCount]uint32
|
||||
for i := 0; i < evFieldCount; i++ {
|
||||
// 直接累加增量
|
||||
tempEV[i] = pet.Ev[i] + ev_add[i]
|
||||
tempEV[i] = pet.Ev[i] + uint32(ev_add[i])
|
||||
// 单项不超过255
|
||||
if tempEV[i] > maxSingleEV {
|
||||
tempEV[i] = maxSingleEV
|
||||
@@ -342,7 +342,7 @@ func (petinfo *PetInfo) Update(isup bool) {
|
||||
// calculateExperience 计算指定等级和种族值所需的经验值
|
||||
// level: 当前等级
|
||||
// baseValue: 种族值
|
||||
func calculateExperience(level uint32, baseValue uint32) uint32 {
|
||||
func calculateExperience(level uint32, baseValue uint32) int64 {
|
||||
// 计算 A 部分:向上取整(3.75 * a * (a + 1))
|
||||
partA := math.Ceil(3.75 * float64(level) * float64(level+1))
|
||||
|
||||
@@ -354,7 +354,7 @@ func calculateExperience(level uint32, baseValue uint32) uint32 {
|
||||
|
||||
// 总经验是两部分之和,并向上取整
|
||||
totalExp := math.Ceil(partA + partB)
|
||||
return uint32(totalExp)
|
||||
return int64(totalExp)
|
||||
}
|
||||
|
||||
// PetEffectInfo 精灵特性信息结构
|
||||
|
||||
Reference in New Issue
Block a user