2025-09-21 14:56:37 +00:00
|
|
|
|
package player
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
2025-11-23 23:38:03 +00:00
|
|
|
|
"blazing/common/utils"
|
2025-09-21 14:56:37 +00:00
|
|
|
|
"blazing/logic/service/common"
|
|
|
|
|
|
"blazing/logic/service/fight/info"
|
|
|
|
|
|
"blazing/modules/blazing/model"
|
|
|
|
|
|
"math/rand"
|
|
|
|
|
|
"time"
|
2025-11-23 23:38:03 +00:00
|
|
|
|
|
|
|
|
|
|
"github.com/gogf/gf/v2/util/grand"
|
2025-09-21 14:56:37 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type baseplayer struct {
|
2025-11-19 00:09:12 +00:00
|
|
|
|
Info *model.PlayerInfo
|
|
|
|
|
|
//canFight uint32
|
|
|
|
|
|
FightC common.FightI //绑定战斗标识 替代本身的是否战斗标记 //IsFighting bool
|
2025-09-21 14:56:37 +00:00
|
|
|
|
*info.PlayerCaptureContext
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// NewPlayerCaptureContext 创建用户捕捉上下文(每次登录调用)
|
|
|
|
|
|
func newbaseplayer() baseplayer {
|
2025-11-23 23:38:03 +00:00
|
|
|
|
rng := rand.New(rand.NewSource(time.Now().UnixNano() + int64(grand.Intn(1000000))))
|
2025-09-21 14:56:37 +00:00
|
|
|
|
ret := baseplayer{}
|
|
|
|
|
|
ret.PlayerCaptureContext = &info.PlayerCaptureContext{
|
|
|
|
|
|
rng,
|
|
|
|
|
|
1000,
|
|
|
|
|
|
0.10, // 15%衰减率
|
|
|
|
|
|
1,
|
|
|
|
|
|
make(map[int]int),
|
|
|
|
|
|
}
|
|
|
|
|
|
return ret
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
|
// GetInfo 获取玩家基础信息
|
|
|
|
|
|
func (p *baseplayer) GetInfo() *model.PlayerInfo {
|
2025-09-21 14:56:37 +00:00
|
|
|
|
return p.Info
|
|
|
|
|
|
}
|
2025-11-18 22:16:55 +00:00
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
|
// SetFightC 设置玩家战斗控制器
|
|
|
|
|
|
func (f *baseplayer) SetFightC(fightController common.FightI) {
|
|
|
|
|
|
f.FightC = fightController
|
2025-09-21 14:56:37 +00:00
|
|
|
|
}
|
2025-11-18 23:41:31 +00:00
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
|
// GetPlayerCaptureContext 获取玩家捕捉上下文
|
2025-09-21 14:56:37 +00:00
|
|
|
|
func (f *baseplayer) GetPlayerCaptureContext() *info.PlayerCaptureContext {
|
|
|
|
|
|
return f.PlayerCaptureContext
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
|
// FindPet 根据捕捉时间查找宠物
|
|
|
|
|
|
// 返回值: (索引, 宠物信息, 是否找到)
|
|
|
|
|
|
func (f *baseplayer) FindPet(catchTime uint32) (int, *model.PetInfo, bool) {
|
2025-11-23 23:38:03 +00:00
|
|
|
|
return utils.FindWithIndex(f.Info.PetList, func(item model.PetInfo) bool {
|
2025-12-24 19:03:11 +08:00
|
|
|
|
return item.CatchTime == catchTime
|
2025-11-23 23:38:03 +00:00
|
|
|
|
})
|
|
|
|
|
|
}
|
2025-12-24 19:03:11 +08:00
|
|
|
|
|
|
|
|
|
|
// Pet_del 删除指定宠物
|
|
|
|
|
|
// catchTime: 宠物的捕捉时间戳
|
|
|
|
|
|
func (f *Player) Pet_del(catchTime uint32) {
|
|
|
|
|
|
index, _, ok := f.FindPet(catchTime)
|
2025-11-26 01:33:48 +08:00
|
|
|
|
if ok {
|
2025-12-06 01:41:38 +08:00
|
|
|
|
copy(f.Info.PetList[index:], f.Info.PetList[index+1:])
|
|
|
|
|
|
f.Info.PetList = f.Info.PetList[:len(f.Info.PetList)-1]
|
2025-12-24 19:03:11 +08:00
|
|
|
|
f.Service.Pet.Pet_del(catchTime)
|
2025-11-26 01:33:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-23 23:38:03 +00:00
|
|
|
|
|
2025-11-15 22:17:43 +00:00
|
|
|
|
// // 计算整数的二进制1的个数(Integer.bitCount)
|
|
|
|
|
|
// func bitsCount(n int) int {
|
|
|
|
|
|
// count := 0
|
|
|
|
|
|
// for n > 0 {
|
|
|
|
|
|
// count += n & 1
|
|
|
|
|
|
// n >>= 1
|
|
|
|
|
|
// }
|
|
|
|
|
|
// return count
|
|
|
|
|
|
// }
|