```
feat(fight): 增加战斗模式枚举并重构战斗逻辑判断 - 引入完整的 BattleMode 枚举定义,替代原有的 BattleStatus,明确区分各类战斗场景 - 在多个控制器中替换对旧 Status 字段的依赖,统一使用 Mode 判断战斗状态 - 修复部分函数调用前未检查 FightC 是否为空的问题,增加 ErrBattleEnded 错误返回 - 调整
This commit is contained in:
@@ -11,27 +11,34 @@ import (
|
||||
|
||||
// 准备战斗
|
||||
func (h Controller) OnReadyToFight(data *fight.ReadyToFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
|
||||
if c.FightC == nil {
|
||||
return nil, errorcode.ErrorCodes.ErrBattleEnded
|
||||
}
|
||||
c.FightC.ReadyFight(c)
|
||||
return nil, -1
|
||||
}
|
||||
|
||||
// 使用技能包
|
||||
func (h Controller) UseSkill(data *fight.UseSkillInInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
if c.FightC != nil {
|
||||
c.FightC.UseSkill(c, int32(data.SkillId))
|
||||
if c.FightC == nil {
|
||||
return nil, errorcode.ErrorCodes.ErrBattleEnded
|
||||
}
|
||||
|
||||
c.FightC.UseSkill(c, int32(data.SkillId))
|
||||
return nil, 0
|
||||
}
|
||||
|
||||
// 战斗逃跑
|
||||
func (h Controller) Escape(data *fight.EscapeFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
if atomic.LoadUint32(&c.Fightinfo.Status) == 0 {
|
||||
|
||||
if c.FightC == nil {
|
||||
return nil, errorcode.ErrorCodes.ErrBattleEnded
|
||||
}
|
||||
|
||||
if atomic.LoadUint32(&c.Fightinfo.Mode) == 0 {
|
||||
|
||||
return nil, errorcode.ErrorCodes.ErrBattleNotStarted //,没开始对战
|
||||
}
|
||||
if atomic.LoadUint32(&c.Fightinfo.Status) == 1 { //用户对战不能逃跑
|
||||
if atomic.LoadUint32(&c.Fightinfo.Mode) == 1 { //用户对战不能逃跑
|
||||
|
||||
return nil, errorcode.ErrorCodes.ErrCannotFleePlayerBattle
|
||||
}
|
||||
@@ -41,33 +48,39 @@ func (h Controller) Escape(data *fight.EscapeFightInboundInfo, c *player.Player)
|
||||
|
||||
// 切换精灵
|
||||
func (h Controller) ChangePet(data *fight.ChangePetInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
if c.FightC != nil {
|
||||
c.FightC.ChangePet(c, data.CatchTime)
|
||||
if c.FightC == nil {
|
||||
return nil, errorcode.ErrorCodes.ErrBattleEnded
|
||||
}
|
||||
|
||||
c.FightC.ChangePet(c, data.CatchTime)
|
||||
return nil, -1
|
||||
}
|
||||
|
||||
// 切换精灵
|
||||
func (h Controller) Capture(data *fight.CatchMonsterInboundInfo, c *player.Player) (result *info.CatchMonsterOutboundInfo, err errorcode.ErrorCode) {
|
||||
|
||||
if c.FightC == nil {
|
||||
return nil, errorcode.ErrorCodes.ErrBattleEnded
|
||||
}
|
||||
c.FightC.Capture(c, data.CapsuleId)
|
||||
return nil, -1
|
||||
}
|
||||
|
||||
// 加载进度
|
||||
func (h Controller) LoadPercent(data *fight.LoadPercentInboundInfo, c *player.Player) (result *info.LoadPercentOutboundInfo, err errorcode.ErrorCode) {
|
||||
if c.FightC != nil {
|
||||
|
||||
c.FightC.LoadPercent(c, int32(data.Percent))
|
||||
if c.FightC == nil {
|
||||
return nil, errorcode.ErrorCodes.ErrBattleEnded
|
||||
}
|
||||
|
||||
c.FightC.LoadPercent(c, int32(data.Percent))
|
||||
return nil, -1
|
||||
}
|
||||
func (h Controller) UsePetItemInboundInfo(data *fight.UsePetItemInboundInfo, c *player.Player) (result *info.UsePetIteminfo, err errorcode.ErrorCode) {
|
||||
if c.FightC != nil {
|
||||
|
||||
c.FightC.UseItem(c, data.CatchTime, data.ItemId)
|
||||
if c.FightC == nil {
|
||||
return nil, errorcode.ErrorCodes.ErrBattleEnded
|
||||
}
|
||||
|
||||
c.FightC.UseItem(c, data.CatchTime, data.ItemId)
|
||||
|
||||
return nil, -1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user