Separate game rule enabling and game rule starting (#6168)
This commit is contained in:
@@ -35,14 +35,14 @@ public sealed class DeathMatchRuleSystem : GameRuleSystem
|
||||
SubscribeLocalEvent<DamageChangedEvent>(OnHealthChanged);
|
||||
}
|
||||
|
||||
public override void Added()
|
||||
public override void Started()
|
||||
{
|
||||
_chatManager.DispatchServerAnnouncement(Loc.GetString("rule-death-match-added-announcement"));
|
||||
|
||||
_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
|
||||
}
|
||||
|
||||
public override void Removed()
|
||||
public override void Ended()
|
||||
{
|
||||
_deadCheckTimer = null;
|
||||
_restartTimer = null;
|
||||
|
||||
@@ -27,8 +27,9 @@ public abstract class GameRuleSystem : EntitySystem
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<GameRuleAddedEvent>(OnGameRuleAdded);
|
||||
SubscribeLocalEvent<GameRuleRemovedEvent>(OnGameRuleRemoved);
|
||||
|
||||
SubscribeLocalEvent<GameRuleStartedEvent>(OnGameRuleStarted);
|
||||
SubscribeLocalEvent<GameRuleEndedEvent>(OnGameRuleEnded);
|
||||
}
|
||||
|
||||
private void OnGameRuleAdded(GameRuleAddedEvent ev)
|
||||
@@ -37,25 +38,32 @@ public abstract class GameRuleSystem : EntitySystem
|
||||
return;
|
||||
|
||||
Enabled = true;
|
||||
Added();
|
||||
}
|
||||
|
||||
private void OnGameRuleRemoved(GameRuleRemovedEvent ev)
|
||||
private void OnGameRuleStarted(GameRuleStartedEvent ev)
|
||||
{
|
||||
if (ev.Rule.ID != Prototype)
|
||||
return;
|
||||
|
||||
Started();
|
||||
}
|
||||
|
||||
private void OnGameRuleEnded(GameRuleEndedEvent ev)
|
||||
{
|
||||
if (ev.Rule.ID != Prototype)
|
||||
return;
|
||||
|
||||
Enabled = false;
|
||||
Removed();
|
||||
Ended();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the game rule has been added and this system has been enabled.
|
||||
/// Called when the game rule has been started..
|
||||
/// </summary>
|
||||
public abstract void Added();
|
||||
public abstract void Started();
|
||||
|
||||
/// <summary>
|
||||
/// Called when the game rule has been removed and this system has been disabled.
|
||||
/// Called when the game rule has ended..
|
||||
/// </summary>
|
||||
public abstract void Removed();
|
||||
public abstract void Ended();
|
||||
}
|
||||
|
||||
@@ -28,12 +28,12 @@ public class InactivityTimeRestartRuleSystem : GameRuleSystem
|
||||
SubscribeLocalEvent<GameRunLevelChangedEvent>(RunLevelChanged);
|
||||
}
|
||||
|
||||
public override void Added()
|
||||
public override void Started()
|
||||
{
|
||||
_playerManager.PlayerStatusChanged += PlayerStatusChanged;
|
||||
}
|
||||
|
||||
public override void Removed()
|
||||
public override void Ended()
|
||||
{
|
||||
_playerManager.PlayerStatusChanged -= PlayerStatusChanged;
|
||||
|
||||
|
||||
@@ -26,13 +26,13 @@ public sealed class MaxTimeRestartRuleSystem : GameRuleSystem
|
||||
SubscribeLocalEvent<GameRunLevelChangedEvent>(RunLevelChanged);
|
||||
}
|
||||
|
||||
public override void Added()
|
||||
public override void Started()
|
||||
{
|
||||
if(GameTicker.RunLevel == GameRunLevel.InRound)
|
||||
RestartTimer();
|
||||
}
|
||||
|
||||
public override void Removed()
|
||||
public override void Ended()
|
||||
{
|
||||
RoundMaxTime = TimeSpan.FromMinutes(5);
|
||||
RoundEndDelay = TimeSpan.FromMinutes(10);
|
||||
|
||||
@@ -9,12 +9,12 @@ public class SandboxRuleSystem : GameRuleSystem
|
||||
|
||||
public override string Prototype => "Sandbox";
|
||||
|
||||
public override void Added()
|
||||
public override void Started()
|
||||
{
|
||||
_sandbox.IsSandboxEnabled = true;
|
||||
}
|
||||
|
||||
public override void Removed()
|
||||
public override void Ended()
|
||||
{
|
||||
_sandbox.IsSandboxEnabled = false;
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ public sealed class SuspicionRuleSystem : GameRuleSystem
|
||||
}
|
||||
}
|
||||
|
||||
public override void Added()
|
||||
public override void Started()
|
||||
{
|
||||
_playerManager.PlayerStatusChanged += PlayerManagerOnPlayerStatusChanged;
|
||||
|
||||
@@ -223,7 +223,7 @@ public sealed class SuspicionRuleSystem : GameRuleSystem
|
||||
Timer.SpawnRepeating(DeadCheckDelay, CheckWinConditions, _checkTimerCancel.Token);
|
||||
}
|
||||
|
||||
public override void Removed()
|
||||
public override void Ended()
|
||||
{
|
||||
_doorSystem.AccessType = SharedDoorSystem.AccessTypes.Id;
|
||||
EndTime = null;
|
||||
|
||||
@@ -202,14 +202,14 @@ public class TraitorDeathMatchRuleSystem : GameRuleSystem
|
||||
ev.AddLine(string.Join('\n', lines));
|
||||
}
|
||||
|
||||
public override void Added()
|
||||
public override void Started()
|
||||
{
|
||||
_restarter.RoundMaxTime = TimeSpan.FromMinutes(30);
|
||||
_restarter.RestartTimer();
|
||||
_safeToEndRound = true;
|
||||
}
|
||||
|
||||
public override void Removed()
|
||||
public override void Ended()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -53,13 +53,13 @@ public class TraitorRuleSystem : GameRuleSystem
|
||||
SubscribeLocalEvent<RoundEndTextAppendEvent>(OnRoundEndText);
|
||||
}
|
||||
|
||||
public override void Added()
|
||||
public override void Started()
|
||||
{
|
||||
// This seems silly, but I'll leave it.
|
||||
_chatManager.DispatchServerAnnouncement(Loc.GetString("rule-traitor-added-announcement"));
|
||||
}
|
||||
|
||||
public override void Removed()
|
||||
public override void Ended()
|
||||
{
|
||||
_traitors.Clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user