fix(pet): 修复宠物融合与删除逻辑中的数据访问问题 - 在 PET_FUSION 控制器中注释掉调试代码并修正融合时使用的捕获时间参数 - 优化 player 模块中 Pet_del 方法的切片删除逻辑,避免潜在的数据竞争 - 修复 fight loop 中对手宠物列表的错误引用 - 调整数据库查询条件,将 id 字段从关键字搜索移至精确匹配字段 - 宠物服务中添加插入失败时的重试机制,并默认 free 状态为 1 ```
74 lines
1.7 KiB
Go
74 lines
1.7 KiB
Go
package player
|
||
|
||
import (
|
||
"blazing/common/utils"
|
||
"blazing/logic/service/common"
|
||
"blazing/logic/service/fight/info"
|
||
"blazing/modules/blazing/model"
|
||
"math/rand"
|
||
"time"
|
||
|
||
"github.com/gogf/gf/v2/util/grand"
|
||
)
|
||
|
||
type baseplayer struct {
|
||
Info *model.PlayerInfo
|
||
//canFight uint32
|
||
FightC common.FightI //绑定战斗标识 替代本身的是否战斗标记 //IsFighting bool
|
||
*info.PlayerCaptureContext
|
||
}
|
||
|
||
// NewPlayerCaptureContext 创建用户捕捉上下文(每次登录调用)
|
||
func newbaseplayer() baseplayer {
|
||
rng := rand.New(rand.NewSource(time.Now().UnixNano() + int64(grand.Intn(1000000))))
|
||
ret := baseplayer{}
|
||
ret.PlayerCaptureContext = &info.PlayerCaptureContext{
|
||
rng,
|
||
1000,
|
||
0.10, // 15%衰减率
|
||
1,
|
||
make(map[int]int),
|
||
}
|
||
return ret
|
||
}
|
||
func (p *baseplayer) GetInfo() *model.PlayerInfo {
|
||
|
||
return p.Info
|
||
}
|
||
func (f *baseplayer) SetFightC(ff common.FightI) {
|
||
|
||
f.FightC = ff
|
||
}
|
||
|
||
func (f *baseplayer) GetPlayerCaptureContext() *info.PlayerCaptureContext {
|
||
return f.PlayerCaptureContext
|
||
}
|
||
|
||
func (f *baseplayer) FindPet(CatchTime uint32) (int, *model.PetInfo, bool) {
|
||
|
||
return utils.FindWithIndex(f.Info.PetList, func(item model.PetInfo) bool {
|
||
return item.CatchTime == CatchTime
|
||
})
|
||
}
|
||
func (f *Player) Pet_del(CatchTime uint32) {
|
||
//println("删除精灵1", CatchTime)
|
||
index, _, ok := f.FindPet(CatchTime)
|
||
if ok {
|
||
// println("删除精灵", CatchTime)
|
||
copy(f.Info.PetList[index:], f.Info.PetList[index+1:])
|
||
f.Info.PetList = f.Info.PetList[:len(f.Info.PetList)-1]
|
||
f.Service.Pet.Pet_del(CatchTime)
|
||
}
|
||
|
||
}
|
||
|
||
// // 计算整数的二进制1的个数(Integer.bitCount)
|
||
// func bitsCount(n int) int {
|
||
// count := 0
|
||
// for n > 0 {
|
||
// count += n & 1
|
||
// n >>= 1
|
||
// }
|
||
// return count
|
||
// }
|