Files
bl/logic/service/player/done.go
昔念 e54d4bacaa ```
feat(fight): 增加战斗模式枚举并重构战斗逻辑判断

- 引入完整的 BattleMode 枚举定义,替代原有的 BattleStatus,明确区分各类战斗场景
- 在多个控制器中替换对旧 Status 字段的依赖,统一使用 Mode 判断战斗状态
- 修复部分函数调用前未检查 FightC 是否为空的问题,增加 ErrBattleEnded 错误返回
- 调整
2025-11-21 02:40:27 +08:00

78 lines
1.7 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 (
"github.com/badu/bus"
"github.com/samber/lo"
"blazing/modules/blazing/model"
)
type Done struct {
*Player //对玩家进行操作
*bus.Topic[*model.MilestoneEX]
}
func NewDone(P *Player) Done {
return Done{
Player: P,
Topic: bus.NewTopic[*model.MilestoneEX](),
}
}
// 注册地图BOSS完成事件
// MAPID 地图ID
// BOSSID 地图BOSSID
// 注册胜利次数
// 监听器返回奖励是否发送完成,完成就done
func (d *Done) SPT(mapid, bossid, count uint32, fn func() bool) *bus.Listener[*model.MilestoneEX] {
return d.Topic.Sub(func(v *model.MilestoneEX) {
if v.DoneType == model.MilestoneMode.BOSS && EqualBasicSlice(v.Args, []uint32{mapid, bossid}) && v.Count == count {
_, ok := lo.Find(v.Args, func(v1 uint32) bool { //寻找是否触发过
return v1 == count
})
if !ok { //说明没有触发过
if fn() {
v.Results = append(v.Results, count) //把本次的记录添加
}
}
}
})
}
// 分发事件 ,指定事件+1 并触发是否完成
func (d *Done) Exec(Donetype model.EnumMilestone, id []uint32) {
d.Service.Done.Exec(Donetype, id, func(t *model.MilestoneEX) bool {
d.Topic.Pub(t) //异步发送,然后给事件+1
t.Count++
// d.Topic.PubAsyncCallBack(s, func() { //如果没执行完,说明奖励没发完,直接掉线
// d.Service.Done.Exec(s) //给计数器加1
// }) //提交触发里程碑奖励
return true
}) //给计数器加1
}
// 方法1手动遍历性能最优
func EqualBasicSlice[T int | string | bool | uint32](a, b []T) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}