diff --git a/GameServer/Game/Battle/BattleInstance.cs b/GameServer/Game/Battle/BattleInstance.cs index 969cdb2c..8924ffb4 100644 --- a/GameServer/Game/Battle/BattleInstance.cs +++ b/GameServer/Game/Battle/BattleInstance.cs @@ -67,7 +67,7 @@ namespace EggLink.DanhengServer.Game.Battle return list; } - public void AddBattleTarget(int key, int targetId, int progress, int totalProgress) + public void AddBattleTarget(int key, int targetId, int progress, int totalProgress = 0) { if (!BattleTargets.ContainsKey(key)) { diff --git a/GameServer/Game/Battle/BattleManager.cs b/GameServer/Game/Battle/BattleManager.cs index e1a835df..815cd017 100644 --- a/GameServer/Game/Battle/BattleManager.cs +++ b/GameServer/Game/Battle/BattleManager.cs @@ -161,6 +161,7 @@ namespace EggLink.DanhengServer.Game.Battle // call battle start Player.RogueManager!.GetRogueInstance()?.OnBattleStart(battleInstance); + Player.ChallengeManager!.ChallengeInstance?.OnBattleStart(battleInstance); Player.BattleInstance = battleInstance; Player.SendPacket(new PacketSceneCastSkillScRsp(req.CastEntityId, battleInstance)); @@ -206,6 +207,7 @@ namespace EggLink.DanhengServer.Game.Battle // call battle start Player.RogueManager!.GetRogueInstance()?.OnBattleStart(battleInstance); + Player.ChallengeManager!.ChallengeInstance?.OnBattleStart(battleInstance); Player.BattleInstance = battleInstance; diff --git a/GameServer/Game/Challenge/ChallengeEntityLoader.cs b/GameServer/Game/Challenge/ChallengeEntityLoader.cs index ec5a4088..d4005345 100644 --- a/GameServer/Game/Challenge/ChallengeEntityLoader.cs +++ b/GameServer/Game/Challenge/ChallengeEntityLoader.cs @@ -17,8 +17,8 @@ namespace EggLink.DanhengServer.Game.Challenge if (Scene.IsLoaded) return; // Get challenge instance - if (Player.ChallengeInstance == null) return; - ChallengeInstance instance = Player.ChallengeInstance; + if (Player.ChallengeManager!.ChallengeInstance == null) return; + ChallengeInstance instance = Player.ChallengeManager.ChallengeInstance; // Setup first stage var excel = instance.Excel; @@ -52,12 +52,10 @@ namespace EggLink.DanhengServer.Game.Challenge { return null; } - Console.WriteLine(0); // Get challenge instance - if (Player.ChallengeInstance == null) return null; - ChallengeInstance instance = Player.ChallengeInstance; - Console.WriteLine(1); + if (Player.ChallengeManager!.ChallengeInstance == null) return null; + ChallengeInstance instance = Player.ChallengeManager.ChallengeInstance; // Get current stage monster infos Dictionary challengeMonsters; @@ -73,17 +71,14 @@ namespace EggLink.DanhengServer.Game.Challenge { return null; } - Console.WriteLine(2); // Get challenge monster info if (!challengeMonsters.ContainsKey(info.ID)) return null; var challengeMonsterInfo = challengeMonsters[info.ID]; - Console.WriteLine(3); // Get excels from game data if (!GameData.NpcMonsterDataData.ContainsKey(challengeMonsterInfo.NpcMonsterId)) return null; NPCMonsterDataExcel npcMonsterExcel = GameData.NpcMonsterDataData[challengeMonsterInfo.NpcMonsterId]; - Console.WriteLine(4); // Create monster from group monster info EntityMonster entity = new EntityMonster(scene, info.ToPositionProto(), info.ToRotationProto(), group.Id, info.ID, npcMonsterExcel, info); diff --git a/GameServer/Game/Challenge/ChallengeInstance.cs b/GameServer/Game/Challenge/ChallengeInstance.cs index fd25ca2e..48ffaba1 100644 --- a/GameServer/Game/Challenge/ChallengeInstance.cs +++ b/GameServer/Game/Challenge/ChallengeInstance.cs @@ -128,19 +128,21 @@ namespace EggLink.DanhengServer.Game.Challenge { battle.Buffs.Add(new MazeBuff(Excel.MazeBuffID, -1, -1)); - if (StoryBuffs.Contains(CurrentStage - 1)) + if (StoryBuffs.Count >= CurrentStage) { - battle.Buffs.Add(new MazeBuff((CurrentStage - 1), -1, -1)); + int buffId = CurrentStage - 1; + battle.Buffs.Add(new MazeBuff(buffId, -1, -1)); } } if (Excel.StoryExcel != null) { - battle.AddBattleTarget(1, 10001, GetTotalScore(), 0); + battle.AddBattleTarget(1, 10001, GetTotalScore()); foreach (var id in Excel.StoryExcel.BattleTargetID!) { - battle.AddBattleTarget(5, id, GetTotalScore(), 0); + Console.WriteLine(id); + battle.AddBattleTarget(5, id, GetTotalScore()); } } } @@ -150,7 +152,7 @@ namespace EggLink.DanhengServer.Game.Challenge // End challenge if its done if (Status != (int)ChallengeStatus.ChallengeDoing) { - Player.ChallengeInstance = null; + Player.ChallengeManager!.ChallengeInstance = null; } } diff --git a/GameServer/Game/Challenge/ChallengeManager.cs b/GameServer/Game/Challenge/ChallengeManager.cs index 739b6364..09f62504 100644 --- a/GameServer/Game/Challenge/ChallengeManager.cs +++ b/GameServer/Game/Challenge/ChallengeManager.cs @@ -10,8 +10,13 @@ namespace EggLink.DanhengServer.Game.Challenge { public class ChallengeManager(PlayerInstance player) : BasePlayerManager(player) { + #region Properties + + public ChallengeInstance? ChallengeInstance { get; set; } public ChallengeData ChallengeData { get; private set; } = DatabaseHelper.Instance!.GetInstanceOrCreateNew(player.Uid); + #endregion + #region Management public void StartChallenge(int challengeId, HDLDGEPFMGL? /*StartChallengeStoryBuffInfo*/ storyBuffs) @@ -73,7 +78,7 @@ namespace EggLink.DanhengServer.Game.Challenge // Set challenge data for player ChallengeInstance instance = new ChallengeInstance(Player, Excel); - Player.ChallengeInstance = instance; + this.ChallengeInstance = instance; // Set first lineup before we enter scenes Player.LineupManager!.SetCurLineup(instance.CurrentExtraLineup); @@ -86,7 +91,7 @@ namespace EggLink.DanhengServer.Game.Challenge catch { // Reset lineup/instance if entering scene failed - Player.ChallengeInstance = null; + this.ChallengeInstance = null; // Send error packet Player.SendPacket(new PacketStartChallengeScRsp(2801)); @@ -133,14 +138,11 @@ namespace EggLink.DanhengServer.Game.Challenge ChallengeData.Instance.ScoreStage2 = instance.ScoreStage2; ChallengeData.Instance.StoryBuffs = instance.StoryBuffs; ChallengeData.Instance.BossBuffs = instance.BossBuffs; - - DatabaseHelper.Instance?.UpdateInstance(ChallengeData); } public void ClearInstance() { ChallengeData.Instance.ChallengeId = 0; - DatabaseHelper.Instance?.UpdateInstance(ChallengeData); } public void ResurrectInstance() @@ -152,7 +154,7 @@ namespace EggLink.DanhengServer.Game.Challenge { ChallengeConfigExcel Excel = GameData.ChallengeConfigData[ChallengeId]; ChallengeInstance instance = new ChallengeInstance(Player, Excel, ChallengeData.Instance); - Player.ChallengeInstance = instance; + this.ChallengeInstance = instance; } } } diff --git a/GameServer/Game/Player/PlayerInstance.cs b/GameServer/Game/Player/PlayerInstance.cs index 995d0795..41da273f 100644 --- a/GameServer/Game/Player/PlayerInstance.cs +++ b/GameServer/Game/Player/PlayerInstance.cs @@ -63,7 +63,6 @@ namespace EggLink.DanhengServer.Game.Player public TutorialData? TutorialData { get; private set; } public TutorialGuideData? TutorialGuideData { get; private set; } public SceneInstance? SceneInstance { get; private set; } - public ChallengeInstance? ChallengeInstance { get; set; } public ushort Uid { get; set; } public Connection? Connection { get; set; } public bool Initialized { get; set; } = false; diff --git a/GameServer/Server/Packet/Recv/Challenge/HandlerGetCurChallengeCsReq.cs b/GameServer/Server/Packet/Recv/Challenge/HandlerGetCurChallengeCsReq.cs index 57454963..ce080b76 100644 --- a/GameServer/Server/Packet/Recv/Challenge/HandlerGetCurChallengeCsReq.cs +++ b/GameServer/Server/Packet/Recv/Challenge/HandlerGetCurChallengeCsReq.cs @@ -14,9 +14,9 @@ namespace EggLink.DanhengServer.Server.Packet.Recv.Battle connection.SendPacket(new PacketGetCurChallengeScRsp(connection.Player!)); // Update data - if (connection.Player!.ChallengeInstance != null) + if (connection.Player!.ChallengeManager.ChallengeInstance != null) { - connection.Player.ChallengeInstance.OnUpdate(); + connection.Player.ChallengeManager.ChallengeInstance.OnUpdate(); } } } diff --git a/GameServer/Server/Packet/Recv/Challenge/HandlerLeaveChallengeCsReq.cs b/GameServer/Server/Packet/Recv/Challenge/HandlerLeaveChallengeCsReq.cs index 75ee0537..ce41e64b 100644 --- a/GameServer/Server/Packet/Recv/Challenge/HandlerLeaveChallengeCsReq.cs +++ b/GameServer/Server/Packet/Recv/Challenge/HandlerLeaveChallengeCsReq.cs @@ -19,7 +19,7 @@ namespace EggLink.DanhengServer.Server.Packet.Recv.Challenge player.LineupManager!.SetExtraLineup(ExtraLineupType.LineupChallenge, []); player.LineupManager.SetExtraLineup(ExtraLineupType.LineupChallenge2, []); - player.ChallengeInstance = null; + player.ChallengeManager!.ChallengeInstance = null; player.ChallengeManager!.ClearInstance(); // Leave scene diff --git a/GameServer/Server/Packet/Send/Challenge/PacketGetCurChallengeScRsp.cs b/GameServer/Server/Packet/Send/Challenge/PacketGetCurChallengeScRsp.cs index 26597a84..bf9836d9 100644 --- a/GameServer/Server/Packet/Send/Challenge/PacketGetCurChallengeScRsp.cs +++ b/GameServer/Server/Packet/Send/Challenge/PacketGetCurChallengeScRsp.cs @@ -10,9 +10,9 @@ namespace EggLink.DanhengServer.Server.Packet.Send.Battle { var proto = new GetCurChallengeScRsp() { }; - if (player.ChallengeInstance != null) + if (player.ChallengeManager!.ChallengeInstance != null) { - proto.CurChallenge = player.ChallengeInstance.ToProto(); + proto.CurChallenge = player.ChallengeManager.ChallengeInstance.ToProto(); } else { diff --git a/GameServer/Server/Packet/Send/Challenge/PacketStartChallengeScRsp.cs b/GameServer/Server/Packet/Send/Challenge/PacketStartChallengeScRsp.cs index 67c667c1..153e4d3e 100644 --- a/GameServer/Server/Packet/Send/Challenge/PacketStartChallengeScRsp.cs +++ b/GameServer/Server/Packet/Send/Challenge/PacketStartChallengeScRsp.cs @@ -19,9 +19,9 @@ namespace EggLink.DanhengServer.Server.Packet.Send.Challenge { StartChallengeScRsp proto = new StartChallengeScRsp() { }; - if (player.ChallengeInstance != null) + if (player.ChallengeManager!.ChallengeInstance != null) { - proto.CurChallenge = player.ChallengeInstance!.ToProto(); + proto.CurChallenge = player.ChallengeManager.ChallengeInstance.ToProto(); proto.Lineup = player.LineupManager!.GetExtraLineup(ExtraLineupType.LineupChallenge)!.ToProto(); } else