diff --git a/logic/controller/fight.go b/logic/controller/fight.go index caa3f360..d2887052 100644 --- a/logic/controller/fight.go +++ b/logic/controller/fight.go @@ -106,7 +106,7 @@ func (h Controller) UseSkill(data *fight.UseSkillInboundInfo, c *player.Player) // 战斗逃跑 func (h Controller) Escape(data *fight.EscapeFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { - c.FightC.Escape(c) + c.FightC.Over(c,info.BattleOverReason.PlayerEscape) return nil, 0 } diff --git a/logic/service/common/fight.go b/logic/service/common/fight.go index 7c52dccf..b0b4a7d7 100644 --- a/logic/service/common/fight.go +++ b/logic/service/common/fight.go @@ -6,9 +6,9 @@ import ( ) type FightI interface { - Escape(c PlayerI) //逃跑 - UseSkill(c PlayerI, id int32) //使用技能 - GetCurrPET(c PlayerI) *info.BattlePetEntity //当前精灵 + Over(c PlayerI, id info.EnumBattleOverReason) //逃跑 + UseSkill(c PlayerI, id int32) //使用技能 + GetCurrPET(c PlayerI) *info.BattlePetEntity //当前精灵 Ownerid() uint32 ReadyFight(c PlayerI) //是否准备战斗 ChangePet(c PlayerI, id uint32) diff --git a/logic/service/fight/BattleAction.go b/logic/service/fight/BattleAction.go index 20f5e013..b5b85bba 100644 --- a/logic/service/fight/BattleAction.go +++ b/logic/service/fight/BattleAction.go @@ -146,6 +146,23 @@ func (e *EscapeAction) Priority() int { return int(PlayerOperations.Escape) } +// EscapeAction 逃跑的战斗动作 +type OverTimeAction struct { + BaseAction + Reason info.FightOverInfo + Our common.PlayerI + Opp common.PlayerI +} + +func (e *OverTimeAction) GetInfo() info.FightOverInfo { + return e.Reason +} + +// Priority 返回动作优先级 +func (e *OverTimeAction) Priority() int { + return int(PlayerOperations.PlayerOffline) +} + // SystemGiveUpAction 系统强制放弃出手的动作 type SystemGiveUpAction struct { BaseAction diff --git a/logic/service/fight/fightc.go b/logic/service/fight/fightc.go index deaaecb8..2298184d 100644 --- a/logic/service/fight/fightc.go +++ b/logic/service/fight/fightc.go @@ -277,12 +277,11 @@ func (f *FightC) battleLoop() { case <-timeout: if _, exists := actions[f.Our.Player.GetInfo().UserID]; !exists { - actions[f.Our.Player.GetInfo().UserID] = &SystemGiveUpAction{ - BaseAction: NewBaseAction(f.Our.Player.GetInfo().UserID)} //系统选择出手 + f.Over(f.Opp.Player, info.BattleOverReason.PlayerOVerTime) } if _, exists := actions[f.Opp.Player.GetInfo().UserID]; !exists { - actions[f.Opp.Player.GetInfo().UserID] = &SystemGiveUpAction{BaseAction: NewBaseAction(f.Opp.Player.GetInfo().UserID)} //系统选择出手 + f.Over(f.Opp.Player, info.BattleOverReason.PlayerOVerTime) } } @@ -298,14 +297,13 @@ func (f *FightC) battleLoop() { BattleActionI[0], BattleActionI[1] = f.Compare(p1Action, p2Action) switch faction := BattleActionI[0].(type) { - case *EscapeAction: //优先逃跑 + case *PlayerOfflineAction: //单方掉线 f.Broadcast(func(ff *input.Input) { ff.Player.SendFightEndInfo(faction.Reason) //广播逃跑原因 }) f.closefight = true - - case *PlayerOfflineAction: //单方掉线 + case *EscapeAction: //优先逃跑 f.Broadcast(func(ff *input.Input) { ff.Player.SendFightEndInfo(faction.Reason) //广播逃跑原因 diff --git a/logic/service/fight/info/battle.go b/logic/service/fight/info/battle.go index 67b28c9d..62602870 100644 --- a/logic/service/fight/info/battle.go +++ b/logic/service/fight/info/battle.go @@ -62,9 +62,10 @@ type EnumBattleOverReason int var BattleOverReason = enum.New[struct { PlayerOffline EnumBattleOverReason `enum:"1"` //掉线 - PlayerEscape EnumBattleOverReason `enum:"2"` //逃跑 + PlayerOVerTime EnumBattleOverReason `enum:"2"` //超时 PlayerCaptureSuccess EnumBattleOverReason `enum:"3"` //捕捉成功 DefaultEnd EnumBattleOverReason `enum:"4"` //默认结束 + PlayerEscape EnumBattleOverReason `enum:"5"` //逃跑 }]() // 战斗模式 diff --git a/logic/service/fight/playeraction.go b/logic/service/fight/playeraction.go index 46fd5b80..afaf16b5 100644 --- a/logic/service/fight/playeraction.go +++ b/logic/service/fight/playeraction.go @@ -12,8 +12,8 @@ import ( "github.com/panjf2000/ants/v2" ) -// 玩家逃跑 -func (f *FightC) Escape(c common.PlayerI) { +// 玩家逃跑/无响应/掉线 +func (f *FightC) Over(c common.PlayerI, res info.EnumBattleOverReason) { ret := &EscapeAction{ BaseAction: NewBaseAction(c.GetInfo().UserID), Reason: info.FightOverInfo{ @@ -21,20 +21,12 @@ func (f *FightC) Escape(c common.PlayerI) { Reason: uint32(info.BattleOverReason.PlayerEscape), }, } + if c.GetInfo().UserID == f.ownerID { + ret.Reason.WinnerId = f.Opp.Player.GetInfo().UserID - f.actionChan <- ret -} - -// 玩家掉线 -func (f *FightC) Offline(c common.PlayerI) { - ret := &PlayerOfflineAction{ - BaseAction: NewBaseAction(c.GetInfo().UserID), - Reason: info.FightOverInfo{ - - Reason: uint32(info.BattleOverReason.PlayerOffline), - }, + } else { + ret.Reason.WinnerId = f.Our.Player.GetInfo().UserID } - f.actionChan <- ret } diff --git a/logic/service/player/player.go b/logic/service/player/player.go index cdd0a938..04638319 100644 --- a/logic/service/player/player.go +++ b/logic/service/player/player.go @@ -321,7 +321,7 @@ func (p *Player) Save() { Mainplayer.Delete(p.Info.UserID) share.ShareManager.DeleteUserOnline(p.Info.UserID) //设置用户登录服务器 if p.FightC != nil { - p.FightC.Escape(p) //玩家逃跑 + p.FightC.Over(p, info.BattleOverReason.PlayerOffline) //玩家逃跑 }