```
feat(fight): 增加战斗模式枚举并重构战斗逻辑判断 - 引入完整的 BattleMode 枚举定义,替代原有的 BattleStatus,明确区分各类战斗场景 - 在多个控制器中替换对旧 Status 字段的依赖,统一使用 Mode 判断战斗状态 - 修复部分函数调用前未检查 FightC 是否为空的问题,增加 ErrBattleEnded 错误返回 - 调整
This commit is contained in:
@@ -17,6 +17,10 @@ import (
|
||||
// 都需要通过2419包广播更新擂台状态
|
||||
func (h Controller) ARENA_SET_OWENR(data *fight.ARENA_SET_OWENR, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
|
||||
if !c.CanFight() {
|
||||
return nil, errorcode.ErrorCodes.ErrPokemonNotEligible
|
||||
}
|
||||
c.Fightinfo.Mode = 0 //取消队列匹配
|
||||
if atomic.CompareAndSwapUint32(&c.GetSpace().Owner.Flag, 0, 1) {
|
||||
|
||||
c.GetSpace().Owner.UserID = c.GetInfo().UserID //添加用户ID
|
||||
@@ -42,14 +46,28 @@ func (h Controller) ARENA_FIGHT_OWENR(data *fight.ARENA_FIGHT_OWENR, c *player.P
|
||||
if !c.CanFight() {
|
||||
return nil, errorcode.ErrorCodes.ErrNoEligiblePokemon
|
||||
}
|
||||
|
||||
if c.Info.UserID == c.GetSpace().Owner.UserID {
|
||||
return nil, errorcode.ErrorCodes.ErrNoEligiblePokemon
|
||||
}
|
||||
//原子操作,修改擂台状态
|
||||
if atomic.CompareAndSwapUint32(&c.GetSpace().Owner.Flag, 1, 2) {
|
||||
//成功发起擂台挑战后才修改我放状态
|
||||
c.Fightinfo.Mode = info.BattleMode.SINGLE_MODE
|
||||
c.Fightinfo.Status = info.BattleStatus.FIGHT_WITH_PLAYER
|
||||
c.Fightinfo.Status = info.BattleMode.FIGHT_ARENA
|
||||
|
||||
_, err = fight.NewFight(c, c.GetSpace().ARENA_Player, func(foi *info.FightOverInfo) { //我方邀请擂主挑战,我方先手
|
||||
|
||||
if foi.Reason != 0 && foi.WinnerId == c.GetInfo().UserID { //异常退出
|
||||
c.GetSpace().ARENA_Player = nil
|
||||
c.GetSpace().Owner.Reset()
|
||||
|
||||
c.GetSpace().Broadcast(c, 2419, &c.GetSpace().Owner)
|
||||
c.SendPackCmd(2419, &c.GetSpace().Owner)
|
||||
|
||||
}
|
||||
//todo 擂主输了,那就直接让他放弃擂台
|
||||
|
||||
}) ///开始对战,房主方以及被邀请方
|
||||
|
||||
if err <= 0 { //发起战斗成功
|
||||
@@ -58,10 +76,10 @@ func (h Controller) ARENA_FIGHT_OWENR(data *fight.ARENA_FIGHT_OWENR, c *player.P
|
||||
//c.SendPackCmd(2419, &c.GetSpace().Owner)
|
||||
} else {
|
||||
//发起失败,改回1
|
||||
c.GetSpace().Owner.HostWins = 0 //连胜重置
|
||||
c.GetSpace().Owner.UserID = c.GetInfo().UserID //添加用户ID
|
||||
c.GetSpace().Owner.Nick = c.GetInfo().Nick
|
||||
c.GetSpace().ARENA_Player = c //添加用户
|
||||
// c.GetSpace().Owner.HostWins = 0 //连胜重置
|
||||
// c.GetSpace().Owner.UserID = c.GetInfo().UserID //添加用户ID
|
||||
// c.GetSpace().Owner.Nick = c.GetInfo().Nick
|
||||
// c.GetSpace().ARENA_Player = c //添加用户
|
||||
atomic.StoreUint32(&c.GetSpace().Owner.Flag, 1)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user