Browse Source

fix: 🐛 fix the bug about numOfNoHpStudent

tags/v0.1.0
shangfengh 2 years ago
parent
commit
1bf3e65bf6
4 changed files with 75 additions and 70 deletions
  1. +5
    -2
      docs/版本更新说明.md
  2. +64
    -62
      logic/GameClass/GameObj/Map/Map.cs
  3. +2
    -2
      logic/Gaming/ActionManager.cs
  4. +4
    -4
      logic/Gaming/CharacterManager.cs

+ 5
- 2
docs/版本更新说明.md View File

@@ -52,6 +52,9 @@
- docs:更新了 游戏机制与平衡性调整更新草案.pdf - docs:更新了 游戏机制与平衡性调整更新草案.pdf
- feat:游戏机制与平衡性调整已完成 - feat:游戏机制与平衡性调整已完成


# 5月20日更新
# 5月20日18:00更新
- docs:更新了 游戏机制与平衡性调整更新(基本不变版).pdf - docs:更新了 游戏机制与平衡性调整更新(基本不变版).pdf
- fix:修复了Pubnish技能眩晕时长的错误
- fix:修复了Pubnish技能眩晕时长的错误

# 5月20日23:30更新
- fix:修复了学习已经完成的作业会卡死的问题

+ 64
- 62
logic/GameClass/GameObj/Map/Map.cs View File

@@ -11,58 +11,14 @@ namespace GameClass.GameObj
private readonly Dictionary<uint, XY> birthPointList; // 出生点列表 private readonly Dictionary<uint, XY> birthPointList; // 出生点列表
public Dictionary<uint, XY> BirthPointList => birthPointList; public Dictionary<uint, XY> 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; private uint numOfRepairedGenerators = 0;
public uint NumOfRepairedGenerators public uint NumOfRepairedGenerators
{ {
get => Interlocked.CompareExchange(ref numOfDeceasedStudent, 0, 0);
get => Interlocked.CompareExchange(ref numOfRepairedGenerators, 0, 0);
} }
public void AddNumOfRepairedGenerators() public void AddNumOfRepairedGenerators()
{ {
uint value = Interlocked.Increment(ref numOfDeceasedStudent);
uint value = Interlocked.Increment(ref numOfRepairedGenerators);
if (value == GameData.numOfGeneratorRequiredForEmergencyExit) if (value == GameData.numOfGeneratorRequiredForEmergencyExit)
{ {
GameObjLockDict[GameObjType.EmergencyExit].EnterWriteLock(); GameObjLockDict[GameObjType.EmergencyExit].EnterWriteLock();
@@ -93,33 +49,79 @@ namespace GameClass.GameObj
} }
} }
} }

private uint numOfDeceasedStudent = 0; private uint numOfDeceasedStudent = 0;
public uint NumOfDeceasedStudent public uint NumOfDeceasedStudent
{ {
get => numOfDeceasedStudent;
set
{
lock (lockForNum)
{
numOfDeceasedStudent = value;
WhenStudentNumChange();
}
}
get => Interlocked.CompareExchange(ref numOfDeceasedStudent, 0, 0);
} }
private uint numOfEscapedStudent = 0; private uint numOfEscapedStudent = 0;
public uint NumOfEscapedStudent 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<GameObjType, IList<IGameObj>> gameObjDict; private Dictionary<GameObjType, IList<IGameObj>> gameObjDict;
public Dictionary<GameObjType, IList<IGameObj>> GameObjDict => gameObjDict; public Dictionary<GameObjType, IList<IGameObj>> GameObjDict => gameObjDict;
private Dictionary<GameObjType, ReaderWriterLockSlim> gameObjLockDict; private Dictionary<GameObjType, ReaderWriterLockSlim> gameObjLockDict;


+ 2
- 2
logic/Gaming/ActionManager.cs View File

@@ -163,7 +163,7 @@ namespace Gaming
if (doorwayForEscape != null && doorwayForEscape.IsOpen()) if (doorwayForEscape != null && doorwayForEscape.IsOpen())
{ {
player.AddScore(GameData.StudentScoreEscape); player.AddScore(GameData.StudentScoreEscape);
++gameMap.NumOfEscapedStudent;
gameMap.MapEscapeStudent();
player.RemoveFromGame(PlayerStateType.Escaped); player.RemoveFromGame(PlayerStateType.Escaped);
return true; return true;
} }
@@ -173,7 +173,7 @@ namespace Gaming
if (emergencyExit != null && emergencyExit.IsOpen) if (emergencyExit != null && emergencyExit.IsOpen)
{ {
player.AddScore(GameData.StudentScoreEscape); player.AddScore(GameData.StudentScoreEscape);
++gameMap.NumOfEscapedStudent;
gameMap.MapEscapeStudent();
player.RemoveFromGame(PlayerStateType.Escaped); player.RemoveFromGame(PlayerStateType.Escaped);
return true; return true;
} }


+ 4
- 4
logic/Gaming/CharacterManager.cs View File

@@ -240,6 +240,7 @@ namespace Gaming
} }
player.SetPlayerState(PlayerStateType.Addicted); player.SetPlayerState(PlayerStateType.Addicted);
long threadNum = player.StateNum; long threadNum = player.StateNum;
gameMap.MapAddictStudent();
new Thread new Thread
(() => (() =>
{ {
@@ -255,6 +256,7 @@ namespace Gaming
timeInterval: GameData.frameDuration, timeInterval: GameData.frameDuration,
() => () =>
{ {
gameMap.MapRescueStudent();
if (player.GamingAddiction == player.MaxGamingAddiction && gameMap.Timer.IsGaming) if (player.GamingAddiction == player.MaxGamingAddiction && gameMap.Timer.IsGaming)
{ {
ghost.AddScore(GameData.TrickerScoreStudentDie); ghost.AddScore(GameData.TrickerScoreStudentDie);
@@ -397,9 +399,8 @@ namespace Gaming


public void Die(Student player) public void Die(Student player)
{ {
#if DEBUG
Debugger.Output(player, "die."); Debugger.Output(player, "die.");
#endif
if (player.PlayerState == PlayerStateType.Deceased) return; if (player.PlayerState == PlayerStateType.Deceased) return;
player.RemoveFromGame(PlayerStateType.Deceased); player.RemoveFromGame(PlayerStateType.Deceased);


@@ -430,9 +431,8 @@ namespace Gaming
} }
return; return;
} }
++gameMap.NumOfDeceasedStudent;
gameMap.MapDieStudent();
} }

} }
} }
} }

Loading…
Cancel
Save