Files
bl/logic/service/player/base.go
昔念 026689f3ed ```
feat(cache): 添加复合键缓存操作支持

添加了基于 uint32+string 组合键的缓存操作方法,包括
GetByCompoundKey、SetByCompoundKey、DelByCompoundKey 和
ContainsByCompoundKey 方法,用于处理用户ID和会话ID的组合缓存场景

fix(vscode): 添加 cSpell 配置支持 struc 词汇

refactor(session): 移除过时的会话管理方法

移除了基于单一字符串键的会话管理方法,因为已迁移到使用
复合键的缓存操作方式
```
2026-01-19 18:51:56 +08:00

78 lines
1.9 KiB
Go

package player
import (
"blazing/common/utils"
"blazing/logic/service/common"
"blazing/logic/service/fight/info"
"blazing/modules/player/model"
"math/rand"
"time"
"github.com/gogf/gf/v2/util/grand"
)
type baseplayer struct {
//Fightinfo info.Fightinfo
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{
Random: rng,
Denominator: 1000,
DecayFactor: 0.10, // 15%衰减率
MinDecayNum: 1,
Guarantees: make(map[int]int),
}
return ret
}
// GetInfo 获取玩家基础信息
func (p *baseplayer) GetInfo() *model.PlayerInfo {
return p.Info
}
func (f *baseplayer) InvitePlayer(ff common.PlayerI) {
}
func (p *baseplayer) QuitFight() {
}
// SetFightC 设置玩家战斗控制器
func (f *baseplayer) SetFightC(fightController common.FightI) {
f.FightC = fightController
}
// GetPlayerCaptureContext 获取玩家捕捉上下文
func (f *baseplayer) GetPlayerCaptureContext() *info.PlayerCaptureContext {
return f.PlayerCaptureContext
}
// FindPet 根据捕捉时间查找宠物
// 返回值: (索引, 宠物信息, 是否找到)
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
})
}
// PetDel 删除指定宠物
// catchTime: 宠物的捕捉时间戳
func (f *Player) PetDel(catchTime uint32) {
index, olpet, ok := f.FindPet(catchTime)
if ok {
//先将背包更新
f.Service.Pet.UPdate(*olpet)
f.Service.Pet.Pet_del(catchTime)
f.Info.PetList = append(f.Info.PetList[:index], f.Info.PetList[index+1:]...)
}
}