```
feat(fight): 增加战斗模式枚举并重构战斗逻辑判断 - 引入完整的 BattleMode 枚举定义,替代原有的 BattleStatus,明确区分各类战斗场景 - 在多个控制器中替换对旧 Status 字段的依赖,统一使用 Mode 判断战斗状态 - 修复部分函数调用前未检查 FightC 是否为空的问题,增加 ErrBattleEnded 错误返回 - 调整
This commit is contained in:
@@ -8,8 +8,8 @@ import (
|
||||
|
||||
type AI_player struct {
|
||||
baseplayer
|
||||
petinfo []model.PetInfo //精灵信息
|
||||
|
||||
petinfo []model.PetInfo //精灵信息
|
||||
CanCapture int
|
||||
}
|
||||
|
||||
func (p *AI_player) Getfightinfo() info.Fightinfo {
|
||||
|
||||
@@ -24,7 +24,8 @@ func NewDone(P *Player) Done {
|
||||
// MAPID 地图ID
|
||||
// BOSSID 地图BOSSID
|
||||
// 注册胜利次数
|
||||
func (d *Done) SPT(mapid, bossid, count uint32, fn func()) *bus.Listener[*model.MilestoneEX] {
|
||||
// 监听器返回奖励是否发送完成,完成就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 {
|
||||
@@ -34,8 +35,11 @@ func (d *Done) SPT(mapid, bossid, count uint32, fn func()) *bus.Listener[*model.
|
||||
return v1 == count
|
||||
})
|
||||
if !ok { //说明没有触发过
|
||||
v.Results = append(v.Results, count) //把本次的记录添加
|
||||
fn()
|
||||
|
||||
if fn() {
|
||||
v.Results = append(v.Results, count) //把本次的记录添加
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,13 +4,20 @@ import (
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/fight/info"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
func (p *Player) JoinFight(fn func(p common.PlayerI) bool) errorcode.ErrorCode {
|
||||
//加入队列前就开始判断一次
|
||||
if !p.CanFight() {
|
||||
|
||||
return errorcode.ErrorCodes.ErrNoEligiblePokemon
|
||||
|
||||
}
|
||||
if p.GetSpace().Owner.UserID == p.Info.UserID {
|
||||
return errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
//修复发包进入,如果此时是擂台主
|
||||
|
||||
p.GetSpace().User.Range(func(key uint32, v common.PlayerI) bool {
|
||||
|
||||
@@ -24,7 +31,11 @@ func (p *Player) JoinFight(fn func(p common.PlayerI) bool) errorcode.ErrorCode {
|
||||
ttt := fn(v)
|
||||
if ttt {
|
||||
|
||||
atomic.StoreUint32(&v.(*Player).Fightinfo.Mode, 0)
|
||||
atomic.StoreUint32(&p.Fightinfo.Mode, 0)
|
||||
|
||||
}
|
||||
|
||||
// lw = value
|
||||
return ttt //如果发起成功就停止,否则继续遍历队列
|
||||
}
|
||||
|
||||
@@ -103,8 +103,6 @@ func (p *Player) Getfightinfo() info.Fightinfo {
|
||||
return p.Fightinfo
|
||||
}
|
||||
func (p *Player) QuitFight() {
|
||||
//将战斗标记设置为0 这里的标记是
|
||||
atomic.StoreUint32(&p.Fightinfo.Status, 0)
|
||||
|
||||
p.FightC = nil
|
||||
|
||||
@@ -116,11 +114,14 @@ func (p *Player) GetSpace() *space.Space {
|
||||
// 0无战斗,1PVP,2,BOOS,3PVE
|
||||
func (p *Player) CanFight() bool {
|
||||
|
||||
// if atomic.CompareAndSwapUint32(&p.Fightinfo.Status, 0, staus) { //先判断是否竞态条件被挑战
|
||||
if len(p.Info.PetList) == 0 {
|
||||
atomic.StoreUint32(&p.Fightinfo.Mode, 0)
|
||||
return false
|
||||
|
||||
//成功,继续判断
|
||||
}
|
||||
|
||||
if p.FightC != nil {
|
||||
atomic.StoreUint32(&p.Fightinfo.Mode, 0)
|
||||
return false
|
||||
|
||||
}
|
||||
@@ -133,7 +134,7 @@ func (p *Player) CanFight() bool {
|
||||
}
|
||||
}
|
||||
// 遍历完所有宠物,都没有血量大于0的,才不能战斗
|
||||
|
||||
atomic.StoreUint32(&p.Fightinfo.Mode, 0)
|
||||
return false
|
||||
// }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user