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

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

94 lines
2.6 KiB
Go

package controller
import (
"blazing/common/socket/errorcode"
"sync/atomic"
"blazing/logic/service/common"
"blazing/logic/service/fight"
"blazing/logic/service/fight/info"
"blazing/logic/service/player"
)
// 接收战斗或者取消战斗的包
func (h Controller) OnPlayerHandleFightInvite(data *fight.HandleFightInviteInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
if c.GetSpace().Owner.UserID == c.Info.UserID {
return nil, errorcode.ErrorCodes.ErrSystemError
}
if c.GetSpace().Owner.UserID == data.UserID {
return nil, errorcode.ErrorCodes.ErrSystemError
}
if !atomic.CompareAndSwapUint32(&c.Fightinfo.Mode, 0, data.Mode) { //邀请前提是自己没在战斗
return nil, errorcode.ErrorCodes.ErrInBattle
}
//c.Fightinfo.Status = info.BattleMode.FIGHT_WITH_NPC
resp := &info.S2C_NOTE_HANDLE_FIGHT_INVITE{
UserID: c.Info.UserID,
Nick: c.Info.Nick,
}
for _, v := range c.HavePVPinfo {
if v.GetInfo().UserID == data.UserID && v.Getfightinfo().Mode == data.Mode {
resp.Result = data.Flag
// 检查邀请者的邀请是否有效(对方已取消邀请)
if v.Getfightinfo().Status == 0 {
resp.Result = 4 // 邀请已取消
v.SendPackCmd(2502, &resp)
atomic.StoreUint32(&c.Fightinfo.Mode, 0)
return
}
_, err = fight.NewFight(v, c, func(foi *info.FightOverInfo) {
})
if err <= 0 { //成功发起对战
c.HavePVPinfo = make([]common.PlayerI, 0)
return
} else {
resp.Result = 3
v.SendPackCmd(2502, &resp)
atomic.StoreUint32(&c.Fightinfo.Mode, 0)
return
}
}
}
atomic.StoreUint32(&c.Fightinfo.Status, 0)
return
}
// 邀请其他人进行战斗
func (h Controller) OnPlayerInviteOtherFight(data *fight.InviteToFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
if c.GetSpace().Owner.UserID == c.Info.UserID {
return nil, errorcode.ErrorCodes.ErrSystemError
}
if c.GetSpace().Owner.ChallengerID == c.Info.UserID {
return nil, errorcode.ErrorCodes.ErrSystemError
}
if c.GetSpace().Owner.UserID == data.UserID {
return nil, errorcode.ErrorCodes.ErrSystemError
}
// c.Fightinfo.PlayerID = data.UserID
c.Fightinfo.Mode = data.Mode
c.Fightinfo.Status = 1
// c.Fightinfo.Type = 0
v, ok := c.GetSpace().User.Load(data.UserID)
if ok {
v.InvitePlayer(c)
}
return nil, 0
}
// 取消队列
func (h Controller) OnPlayerCanceledOtherInviteFight(data *fight.InviteFightCancelInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
atomic.StoreUint32(&c.Fightinfo.Mode, 0) //设置状态为0
return
}