From 1bf3e65bf64d4bd3de57accaa38045baf1ea6b76 Mon Sep 17 00:00:00 2001 From: shangfengh <3495281661@qq.com> Date: Sat, 20 May 2023 23:53:40 +0800 Subject: [PATCH] fix: :bug: fix the bug about numOfNoHpStudent --- docs/版本更新说明.md | 7 +- logic/GameClass/GameObj/Map/Map.cs | 126 +++++++++++++++-------------- logic/Gaming/ActionManager.cs | 4 +- logic/Gaming/CharacterManager.cs | 8 +- 4 files changed, 75 insertions(+), 70 deletions(-) diff --git a/docs/版本更新说明.md b/docs/版本更新说明.md index ef292ea..a060c73 100644 --- a/docs/版本更新说明.md +++ b/docs/版本更新说明.md @@ -52,6 +52,9 @@ - docs:更新了 游戏机制与平衡性调整更新草案.pdf - feat:游戏机制与平衡性调整已完成 -# 5月20日更新 +# 5月20日18:00更新 - docs:更新了 游戏机制与平衡性调整更新(基本不变版).pdf -- fix:修复了Pubnish技能眩晕时长的错误 \ No newline at end of file +- fix:修复了Pubnish技能眩晕时长的错误 + +# 5月20日23:30更新 +- fix:修复了学习已经完成的作业会卡死的问题 \ No newline at end of file diff --git a/logic/GameClass/GameObj/Map/Map.cs b/logic/GameClass/GameObj/Map/Map.cs index a0278a3..4d81852 100644 --- a/logic/GameClass/GameObj/Map/Map.cs +++ b/logic/GameClass/GameObj/Map/Map.cs @@ -11,58 +11,14 @@ namespace GameClass.GameObj private readonly Dictionary birthPointList; // 出生点列表 public Dictionary BirthPointList => birthPointList; - private readonly object lockForNum = new(); - private void WhenStudentNumChange() - { - if (numOfDeceasedStudent + numOfEscapedStudent == GameData.numOfStudent) - { - Timer.IsGaming = false; - return; - } - - if (GameData.numOfStudent - numOfDeceasedStudent - numOfEscapedStudent == 1) - { - GameObjLockDict[GameObjType.Character].EnterReadLock(); - try - { - foreach (Character player in GameObjDict[GameObjType.Character]) - if (player.PlayerState == PlayerStateType.Addicted) - { - Timer.IsGaming = false; - break; - } - } - finally - { - GameObjLockDict[GameObjType.Character].ExitReadLock(); - } - if (Timer.IsGaming) - { - GameObjLockDict[GameObjType.EmergencyExit].EnterWriteLock(); - try - { - foreach (EmergencyExit emergencyExit in GameObjDict[GameObjType.EmergencyExit]) - if (emergencyExit.CanOpen) - { - emergencyExit.IsOpen = true; - break; - } - } - finally - { - GameObjLockDict[GameObjType.EmergencyExit].ExitWriteLock(); - } - } - } - } private uint numOfRepairedGenerators = 0; public uint NumOfRepairedGenerators { - get => Interlocked.CompareExchange(ref numOfDeceasedStudent, 0, 0); + get => Interlocked.CompareExchange(ref numOfRepairedGenerators, 0, 0); } public void AddNumOfRepairedGenerators() { - uint value = Interlocked.Increment(ref numOfDeceasedStudent); + uint value = Interlocked.Increment(ref numOfRepairedGenerators); if (value == GameData.numOfGeneratorRequiredForEmergencyExit) { GameObjLockDict[GameObjType.EmergencyExit].EnterWriteLock(); @@ -93,33 +49,79 @@ namespace GameClass.GameObj } } } + private uint numOfDeceasedStudent = 0; public uint NumOfDeceasedStudent { - get => numOfDeceasedStudent; - set - { - lock (lockForNum) - { - numOfDeceasedStudent = value; - WhenStudentNumChange(); - } - } + get => Interlocked.CompareExchange(ref numOfDeceasedStudent, 0, 0); } private uint numOfEscapedStudent = 0; public uint NumOfEscapedStudent { - get => numOfEscapedStudent; - set + get => Interlocked.CompareExchange(ref numOfEscapedStudent, 0, 0); + } + private uint numOfNoHpStudent = 0; + public uint NumOfNoHpStudent + { + get => Interlocked.CompareExchange(ref numOfNoHpStudent, 0, 0); + } + private uint numOfRemovedStudent = 0; + public uint NumOfRemovedStudent + { + get => Interlocked.CompareExchange(ref numOfRemovedStudent, 0, 0); + } + + public void MapEscapeStudent() + { + if (Interlocked.Increment(ref numOfNoHpStudent) == GameData.numOfStudent) { - lock (lockForNum) - { - numOfEscapedStudent = value; - WhenStudentNumChange(); - } + Timer.IsGaming = false; + return; + } + Interlocked.Increment(ref numOfEscapedStudent); + if (Interlocked.Increment(ref numOfRemovedStudent) == GameData.numOfStudent - 1) + OpenEmergencyExit(); + } + public void MapDieStudent() + { + if (Interlocked.Increment(ref numOfNoHpStudent) == GameData.numOfStudent) + { + Timer.IsGaming = false; + return; + } + Interlocked.Increment(ref numOfDeceasedStudent); + if (Interlocked.Increment(ref numOfRemovedStudent) == GameData.numOfStudent - 1) + OpenEmergencyExit(); + } + public void MapAddictStudent() + { + if (Interlocked.Increment(ref numOfNoHpStudent) == GameData.numOfStudent) + Timer.IsGaming = false; + } + public void MapRescueStudent() + { + Interlocked.Decrement(ref numOfNoHpStudent); + } + + private void OpenEmergencyExit() + { + GameObjLockDict[GameObjType.EmergencyExit].EnterReadLock(); + try + { + foreach (EmergencyExit emergencyExit in GameObjDict[GameObjType.EmergencyExit]) + if (emergencyExit.CanOpen) + { + emergencyExit.IsOpen = true; + break; + } + } + finally + { + GameObjLockDict[GameObjType.EmergencyExit].ExitReadLock(); } } + private Dictionary> gameObjDict; public Dictionary> GameObjDict => gameObjDict; private Dictionary gameObjLockDict; diff --git a/logic/Gaming/ActionManager.cs b/logic/Gaming/ActionManager.cs index 461e8bf..58fd7ed 100644 --- a/logic/Gaming/ActionManager.cs +++ b/logic/Gaming/ActionManager.cs @@ -163,7 +163,7 @@ namespace Gaming if (doorwayForEscape != null && doorwayForEscape.IsOpen()) { player.AddScore(GameData.StudentScoreEscape); - ++gameMap.NumOfEscapedStudent; + gameMap.MapEscapeStudent(); player.RemoveFromGame(PlayerStateType.Escaped); return true; } @@ -173,7 +173,7 @@ namespace Gaming if (emergencyExit != null && emergencyExit.IsOpen) { player.AddScore(GameData.StudentScoreEscape); - ++gameMap.NumOfEscapedStudent; + gameMap.MapEscapeStudent(); player.RemoveFromGame(PlayerStateType.Escaped); return true; } diff --git a/logic/Gaming/CharacterManager.cs b/logic/Gaming/CharacterManager.cs index 140bd70..afe8144 100644 --- a/logic/Gaming/CharacterManager.cs +++ b/logic/Gaming/CharacterManager.cs @@ -240,6 +240,7 @@ namespace Gaming } player.SetPlayerState(PlayerStateType.Addicted); long threadNum = player.StateNum; + gameMap.MapAddictStudent(); new Thread (() => { @@ -255,6 +256,7 @@ namespace Gaming timeInterval: GameData.frameDuration, () => { + gameMap.MapRescueStudent(); if (player.GamingAddiction == player.MaxGamingAddiction && gameMap.Timer.IsGaming) { ghost.AddScore(GameData.TrickerScoreStudentDie); @@ -397,9 +399,8 @@ namespace Gaming public void Die(Student player) { -#if DEBUG Debugger.Output(player, "die."); -#endif + if (player.PlayerState == PlayerStateType.Deceased) return; player.RemoveFromGame(PlayerStateType.Deceased); @@ -430,9 +431,8 @@ namespace Gaming } return; } - ++gameMap.NumOfDeceasedStudent; + gameMap.MapDieStudent(); } - } } } \ No newline at end of file