From 77ce937bf198d9ebd5796dd921ac6bc2aa44b76b Mon Sep 17 00:00:00 2001 From: StopWuyu Date: Sat, 1 Nov 2025 11:56:39 +0800 Subject: [PATCH] refactor: use `event` instead of multiple call back --- GameServer/Game/Battle/BattleManager.cs | 15 +++------------ .../Definitions/BaseChallengeInstance.cs | 1 + .../Challenge/Instances/ChallengeBossInstance.cs | 2 ++ .../Instances/ChallengeMemoryInstance.cs | 2 ++ .../Challenge/Instances/ChallengePeakInstance.cs | 2 ++ .../Challenge/Instances/ChallengeStoryInstance.cs | 2 ++ GameServer/Game/Mission/MissionManager.cs | 2 +- GameServer/Game/Rogue/BaseRogueInstance.cs | 2 ++ 8 files changed, 15 insertions(+), 13 deletions(-) diff --git a/GameServer/Game/Battle/BattleManager.cs b/GameServer/Game/Battle/BattleManager.cs index e2fd3936..aa5fc382 100644 --- a/GameServer/Game/Battle/BattleManager.cs +++ b/GameServer/Game/Battle/BattleManager.cs @@ -314,6 +314,7 @@ public class BattleManager(PlayerInstance player) : BasePlayerManager(player) GridFightOptions = new BattleGridFightOptions(curSection, inst, Player) }; + battleInstance.OnBattleEnd += inst.EndBattle; Player.BattleInstance = battleInstance; Player.QuestManager!.OnBattleStart(battleInstance); @@ -404,22 +405,12 @@ public class BattleManager(PlayerInstance player) : BasePlayerManager(player) Player.BattleInstance = null; - await Player.MissionManager!.OnBattleFinish(req, battle); - if (Player.RogueManager?.GetRogueInstance() != null) - await Player.RogueManager!.GetRogueInstance()!.OnBattleEnd(battle, req); - - if (Player.ChallengeManager?.ChallengeInstance != null) - await Player.ChallengeManager!.ChallengeInstance.OnBattleEnd(battle, req); + battle.OnBattleEnd += Player.MissionManager!.OnBattleFinish; + await battle.TriggerOnBattleEnd(); if (Player.ActivityManager!.TrialActivityInstance != null && req.EndStatus == BattleEndStatus.BattleEndWin) await Player.ActivityManager.TrialActivityInstance.EndActivity(TrialActivityStatus.Finish); - if (Player.GridFightManager?.GridFightInstance != null && - battle.GridFightOptions != null) - { - await Player.GridFightManager!.GridFightInstance!.EndBattle(battle); - } - await Player.SendPacket(new PacketPVEBattleResultScRsp(req, Player, battle)); } } \ No newline at end of file diff --git a/GameServer/Game/Challenge/Definitions/BaseChallengeInstance.cs b/GameServer/Game/Challenge/Definitions/BaseChallengeInstance.cs index 66f52f41..b7f01a94 100644 --- a/GameServer/Game/Challenge/Definitions/BaseChallengeInstance.cs +++ b/GameServer/Game/Challenge/Definitions/BaseChallengeInstance.cs @@ -13,6 +13,7 @@ public abstract class BaseChallengeInstance(PlayerInstance player, ChallengeData public virtual void OnBattleStart(BattleInstance battle) { + battle.OnBattleEnd += OnBattleEnd; } public virtual async ValueTask OnBattleEnd(BattleInstance battle, PVEBattleResultCsReq req) diff --git a/GameServer/Game/Challenge/Instances/ChallengeBossInstance.cs b/GameServer/Game/Challenge/Instances/ChallengeBossInstance.cs index 000bbd95..6970f588 100644 --- a/GameServer/Game/Challenge/Instances/ChallengeBossInstance.cs +++ b/GameServer/Game/Challenge/Instances/ChallengeBossInstance.cs @@ -178,6 +178,8 @@ public class ChallengeBossInstance(PlayerInstance player, ChallengeDataPb data) public override void OnBattleStart(BattleInstance battle) { + base.OnBattleStart(battle); + battle.RoundLimit = Config.ChallengeCountDown; battle.Buffs.Add(new MazeBuff(Config.MazeBuffID, 1, -1) diff --git a/GameServer/Game/Challenge/Instances/ChallengeMemoryInstance.cs b/GameServer/Game/Challenge/Instances/ChallengeMemoryInstance.cs index 6d2849b4..be88f890 100644 --- a/GameServer/Game/Challenge/Instances/ChallengeMemoryInstance.cs +++ b/GameServer/Game/Challenge/Instances/ChallengeMemoryInstance.cs @@ -84,6 +84,8 @@ public class ChallengeMemoryInstance(PlayerInstance player, ChallengeDataPb data public override void OnBattleStart(BattleInstance battle) { + base.OnBattleStart(battle); + battle.RoundLimit = (int)Data.Memory.RoundsLeft; battle.Buffs.Add(new MazeBuff(Config.MazeBuffID, 1, -1) diff --git a/GameServer/Game/Challenge/Instances/ChallengePeakInstance.cs b/GameServer/Game/Challenge/Instances/ChallengePeakInstance.cs index 64388396..1e3244f1 100644 --- a/GameServer/Game/Challenge/Instances/ChallengePeakInstance.cs +++ b/GameServer/Game/Challenge/Instances/ChallengePeakInstance.cs @@ -68,6 +68,8 @@ public class ChallengePeakInstance(PlayerInstance player, ChallengeDataPb data) public override void OnBattleStart(BattleInstance battle) { + base.OnBattleStart(battle); + foreach (var peakBuff in Data.Peak.Buffs) battle.Buffs.Add(new MazeBuff((int)peakBuff, 1, -1) { diff --git a/GameServer/Game/Challenge/Instances/ChallengeStoryInstance.cs b/GameServer/Game/Challenge/Instances/ChallengeStoryInstance.cs index 65891a70..e622b47b 100644 --- a/GameServer/Game/Challenge/Instances/ChallengeStoryInstance.cs +++ b/GameServer/Game/Challenge/Instances/ChallengeStoryInstance.cs @@ -108,6 +108,8 @@ public class ChallengeStoryInstance(PlayerInstance player, ChallengeDataPb data) public override void OnBattleStart(BattleInstance battle) { + base.OnBattleStart(battle); + battle.RoundLimit = Config.ChallengeCountDown; battle.Buffs.Add(new MazeBuff(Config.MazeBuffID, 1, -1) diff --git a/GameServer/Game/Mission/MissionManager.cs b/GameServer/Game/Mission/MissionManager.cs index 9df5ac68..4daa230a 100644 --- a/GameServer/Game/Mission/MissionManager.cs +++ b/GameServer/Game/Mission/MissionManager.cs @@ -596,7 +596,7 @@ public class MissionManager(PlayerInstance player) : BasePlayerManager(player) #region Handlers - public async ValueTask OnBattleFinish(PVEBattleResultCsReq req, BattleInstance instance) + public async ValueTask OnBattleFinish(BattleInstance instance, PVEBattleResultCsReq req) { foreach (var mission in GetRunningSubMissionIdList()) { diff --git a/GameServer/Game/Rogue/BaseRogueInstance.cs b/GameServer/Game/Rogue/BaseRogueInstance.cs index 6dc9f459..17fa5483 100644 --- a/GameServer/Game/Rogue/BaseRogueInstance.cs +++ b/GameServer/Game/Rogue/BaseRogueInstance.cs @@ -495,6 +495,8 @@ public abstract class BaseRogueInstance(PlayerInstance player, RogueSubModeEnum foreach (var miracle in RogueMiracles.Values) miracle.OnStartBattle(battle); foreach (var buff in RogueBuffs) buff.OnStartBattle(battle); + + battle.OnBattleEnd += OnBattleEnd; } public abstract ValueTask OnBattleEnd(BattleInstance battle, PVEBattleResultCsReq req);