Move force pausing to EndGame method

This commit is contained in:
Gustas
2023-02-17 11:06:41 +02:00
committed by Matthias Mailänder
parent 19613ed833
commit 20a16ad5f8
4 changed files with 9 additions and 17 deletions

View File

@@ -182,7 +182,7 @@ namespace OpenRA.Network
var pause = order.TargetString == "Pause"; var pause = order.TargetString == "Pause";
// Prevent injected unpause orders from restarting a finished game // Prevent injected unpause orders from restarting a finished game
if (orderManager.World.PauseStateLocked && !pause) if (orderManager.World.IsGameOver && !pause)
break; break;
if (orderManager.World.Paused != pause && world != null && world.LobbyInfo.NonBotClients.Count() > 1) if (orderManager.World.Paused != pause && world != null && world.LobbyInfo.NonBotClients.Count() > 1)

View File

@@ -223,12 +223,7 @@ namespace OpenRA.Scripting
FatalErrorOccurred = true; FatalErrorOccurred = true;
World.AddFrameEndTask(w => World.AddFrameEndTask(w => World.EndGame());
{
World.EndGame();
World.SetPauseState(true);
World.PauseStateLocked = true;
});
} }
public void RegisterMapActor(string name, Actor a) public void RegisterMapActor(string name, Actor a)

View File

@@ -68,15 +68,19 @@ namespace OpenRA
public Player LocalPlayer { get; private set; } public Player LocalPlayer { get; private set; }
public event Action GameOver = () => { }; public event Action GameOver = () => { };
/// <Remarks> Should only be set in <see cref="EndGame"/></Remarks>
public bool IsGameOver { get; private set; } public bool IsGameOver { get; private set; }
public void EndGame() public void EndGame()
{ {
if (!IsGameOver) if (!IsGameOver)
{ {
SetPauseState(true);
IsGameOver = true; IsGameOver = true;
foreach (var t in WorldActor.TraitsImplementing<IGameOver>()) foreach (var t in WorldActor.TraitsImplementing<IGameOver>())
t.GameOver(this); t.GameOver(this);
gameInfo.FinalGameTick = WorldTick; gameInfo.FinalGameTick = WorldTick;
GameOver(); GameOver();
} }
@@ -381,7 +385,6 @@ namespace OpenRA
public bool Paused { get; internal set; } public bool Paused { get; internal set; }
public bool PredictedPaused { get; internal set; } public bool PredictedPaused { get; internal set; }
public bool PauseStateLocked { get; set; }
public int WorldTick { get; private set; } public int WorldTick { get; private set; }
@@ -393,7 +396,7 @@ namespace OpenRA
public void SetPauseState(bool paused) public void SetPauseState(bool paused)
{ {
if (PauseStateLocked) if (IsGameOver)
return; return;
IssueOrder(Order.FromTargetString("PauseGame", paused ? "Pause" : "UnPause", false)); IssueOrder(Order.FromTargetString("PauseGame", paused ? "Pause" : "UnPause", false));
@@ -615,8 +618,6 @@ namespace OpenRA
public void OutOfSync() public void OutOfSync()
{ {
EndGame(); EndGame();
SetPauseState(true);
PauseStateLocked = true;
} }
} }

View File

@@ -165,12 +165,8 @@ namespace OpenRA.Mods.Common.Traits
{ {
Game.RunAfterDelay(Info.GameOverDelay, () => Game.RunAfterDelay(Info.GameOverDelay, () =>
{ {
if (!Game.IsCurrentWorld(player.World)) if (Game.IsCurrentWorld(player.World))
return; player.World.EndGame();
player.World.EndGame();
player.World.SetPauseState(true);
player.World.PauseStateLocked = true;
}); });
} }
} }