Files
bl/logic/service/player/done.go
昔念 ec14ab11c0 feat(fight): 优化战斗逻辑与奖励事件处理
- 在 `fight_boss.go` 中,调整了玩家挑战 Boss 的奖励事件注册逻辑,
  并在战斗结束后正确取消事件监听。
- 修改了多个技能效果文件(`effect_13.go`、`effect_38.go`、`effect_49.go`),
  增强状态持续时间计算和数据安全性。
- 更新 `player/done.go` 中的 `SPT` 方法签名以返回监听器实例。
- 调整数据库操作方法,将 `Update` 替换为 `Save` 以确保数据一致性。
- 修复菜单排序语法问题,统一使用字符串形式的排序表达式。
2025-11-17 13:37:08 +08:00

74 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 (
"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
// 注册胜利次数
func (d *Done) SPT(mapid, bossid, count uint32, fn func()) *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 { //说明没有触发过
v.Results = append(v.Results, count) //把本次的记录添加
fn()
}
}
})
}
// 分发事件 ,指定事件+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
}