Files
bl/logic/service/player/base.go
昔念 f76587f952 feat(pet): 实现精灵融合功能并优化相关逻辑
新增精灵融合接口及处理逻辑,支持主副精灵融合生成新精灵,并消耗金币与材料。
同时调整了战斗技能选择流程、修复地图热度统计安全问题以及完善宠物删除机制。

- 添加 `PetFusion` 控制器方法实现融合核心逻辑
- 新增 `C2S_PetFusion` 和 `PetFusionInfo` 结构体用于通信
- 修正战斗中技能随机选取后立即返回的问题
- 修复太空站进入/离开时对地图热度的并发访问风险
-
2025-11-26 01:33:48 +08:00

72 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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) {
index, _, ok := f.FindPet(CatchTime)
if ok {
f.Info.PetList = append(f.Info.PetList[:index], f.Info.PetList[index+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
// }