Files
bl/logic/service/player/done.go
2025-11-16 20:48:12 +00:00

66 lines
1.4 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]
}
// 注册地图BOSS完成事件
// MAPID 地图ID
// BOSSID 地图BOSSID
// 注册胜利次数
func (d *Done) SPT(mapid, bossid, count uint32, fn func()) {
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 { //说明没有触发过
v.Results = append(v.Results, count) //把本次的记录添加
fn()
}
}
})
}
// 分发事件 ,指定事件+1 并触发是否完成
func (d *Done) Pub(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
}