Turns GameTicker into an EntitySystem. (#4197)
* GameTicker turned into an EntitySystem * Turns ClientGameTicker into an EntitySystem, turn NetMessages into events * Change event names to be more consistent with the rest. * YAML linter uses the dummy gameticker CVar override. * Fix game ticker initialization order * Dummy ticker won't spawn players. * Fix character creation test
This commit is contained in:
committed by
GitHub
parent
15fb554c28
commit
d3a611164b
@@ -1,9 +1,10 @@
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.GameTicking.Rules
|
||||
{
|
||||
[PublicAPI]
|
||||
public abstract class GameRule
|
||||
public abstract class GameRule : IEntityEventSubscriber
|
||||
{
|
||||
public virtual void Added()
|
||||
{
|
||||
|
||||
@@ -26,7 +26,6 @@ namespace Content.Server.GameTicking.Rules
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||
[Dependency] private readonly IGameTicker _gameTicker = default!;
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
|
||||
private CancellationTokenSource? _checkTimerCancel;
|
||||
@@ -91,7 +90,7 @@ namespace Content.Server.GameTicking.Rules
|
||||
|
||||
_chatManager.DispatchServerAnnouncement(Loc.GetString("Restarting in {0} seconds.", restartDelay));
|
||||
|
||||
Timer.Spawn(TimeSpan.FromSeconds(restartDelay), () => _gameTicker.RestartRound());
|
||||
Timer.Spawn(TimeSpan.FromSeconds(restartDelay), () => EntitySystem.Get<GameTicker>().RestartRound());
|
||||
}
|
||||
|
||||
private void PlayerManagerOnPlayerStatusChanged(object? sender, SessionStatusEventArgs e)
|
||||
|
||||
@@ -3,6 +3,7 @@ using System;
|
||||
using System.Threading;
|
||||
using Content.Server.Chat.Managers;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Timer = Robust.Shared.Timing.Timer;
|
||||
@@ -11,9 +12,9 @@ namespace Content.Server.GameTicking.Rules
|
||||
{
|
||||
public class RuleInactivityTimeRestart : GameRule
|
||||
{
|
||||
[Dependency] private readonly IGameTicker _gameTicker = default!;
|
||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
|
||||
private CancellationTokenSource _timerCancel = new();
|
||||
|
||||
@@ -24,7 +25,7 @@ namespace Content.Server.GameTicking.Rules
|
||||
{
|
||||
base.Added();
|
||||
|
||||
_gameTicker.OnRunLevelChanged += RunLevelChanged;
|
||||
_entityManager.EventBus.SubscribeEvent<GameRunLevelChangedEvent>(EventSource.Local, this, RunLevelChanged);
|
||||
_playerManager.PlayerStatusChanged += PlayerStatusChanged;
|
||||
}
|
||||
|
||||
@@ -32,7 +33,7 @@ namespace Content.Server.GameTicking.Rules
|
||||
{
|
||||
base.Removed();
|
||||
|
||||
_gameTicker.OnRunLevelChanged -= RunLevelChanged;
|
||||
_entityManager.EventBus.UnsubscribeEvents(this);
|
||||
_playerManager.PlayerStatusChanged -= PlayerStatusChanged;
|
||||
|
||||
StopTimer();
|
||||
@@ -52,16 +53,17 @@ namespace Content.Server.GameTicking.Rules
|
||||
|
||||
private void TimerFired()
|
||||
{
|
||||
_gameTicker.EndRound(Loc.GetString("Time has run out!"));
|
||||
var gameticker = EntitySystem.Get<GameTicker>();
|
||||
gameticker.EndRound(Loc.GetString("Time has run out!"));
|
||||
|
||||
_chatManager.DispatchServerAnnouncement(Loc.GetString("Restarting in {0} seconds.", (int) RoundEndDelay.TotalSeconds));
|
||||
|
||||
Timer.Spawn(RoundEndDelay, () => _gameTicker.RestartRound());
|
||||
Timer.Spawn(RoundEndDelay, () => gameticker.RestartRound());
|
||||
}
|
||||
|
||||
private void RunLevelChanged(GameRunLevelChangedEventArgs args)
|
||||
private void RunLevelChanged(GameRunLevelChangedEvent args)
|
||||
{
|
||||
switch (args.NewRunLevel)
|
||||
switch (args.New)
|
||||
{
|
||||
case GameRunLevel.InRound:
|
||||
RestartTimer();
|
||||
@@ -75,7 +77,7 @@ namespace Content.Server.GameTicking.Rules
|
||||
|
||||
private void PlayerStatusChanged(object? sender, SessionStatusEventArgs e)
|
||||
{
|
||||
if (_gameTicker.RunLevel != GameRunLevel.InRound)
|
||||
if (EntitySystem.Get<GameTicker>().RunLevel != GameRunLevel.InRound)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Content.Server.Chat.Managers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Timer = Robust.Shared.Timing.Timer;
|
||||
@@ -9,8 +10,8 @@ namespace Content.Server.GameTicking.Rules
|
||||
{
|
||||
public sealed class RuleMaxTimeRestart : GameRule
|
||||
{
|
||||
[Dependency] private readonly IGameTicker _gameTicker = default!;
|
||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
|
||||
private CancellationTokenSource _timerCancel = new();
|
||||
|
||||
@@ -21,14 +22,14 @@ namespace Content.Server.GameTicking.Rules
|
||||
{
|
||||
base.Added();
|
||||
|
||||
_gameTicker.OnRunLevelChanged += RunLevelChanged;
|
||||
_entityManager.EventBus.SubscribeEvent<GameRunLevelChangedEvent>(EventSource.Local, this, RunLevelChanged);
|
||||
}
|
||||
|
||||
public override void Removed()
|
||||
{
|
||||
base.Removed();
|
||||
|
||||
_gameTicker.OnRunLevelChanged -= RunLevelChanged;
|
||||
_entityManager.EventBus.UnsubscribeEvents(this);
|
||||
StopTimer();
|
||||
}
|
||||
|
||||
@@ -46,16 +47,16 @@ namespace Content.Server.GameTicking.Rules
|
||||
|
||||
private void TimerFired()
|
||||
{
|
||||
_gameTicker.EndRound(Loc.GetString("Time has run out!"));
|
||||
EntitySystem.Get<GameTicker>().EndRound(Loc.GetString("Time has run out!"));
|
||||
|
||||
_chatManager.DispatchServerAnnouncement(Loc.GetString("Restarting in {0} seconds.", (int) RoundEndDelay.TotalSeconds));
|
||||
|
||||
Timer.Spawn(RoundEndDelay, () => _gameTicker.RestartRound());
|
||||
Timer.Spawn(RoundEndDelay, () => EntitySystem.Get<GameTicker>().RestartRound());
|
||||
}
|
||||
|
||||
private void RunLevelChanged(GameRunLevelChangedEventArgs args)
|
||||
private void RunLevelChanged(GameRunLevelChangedEvent args)
|
||||
{
|
||||
switch (args.NewRunLevel)
|
||||
switch (args.New)
|
||||
{
|
||||
case GameRunLevel.InRound:
|
||||
RestartTimer();
|
||||
|
||||
@@ -30,7 +30,6 @@ namespace Content.Server.GameTicking.Rules
|
||||
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||
[Dependency] private readonly IGameTicker _gameTicker = default!;
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
@@ -152,12 +151,13 @@ namespace Content.Server.GameTicking.Rules
|
||||
break;
|
||||
}
|
||||
|
||||
_gameTicker.EndRound(text);
|
||||
var gameTicker = EntitySystem.Get<GameTicker>();
|
||||
gameTicker.EndRound(text);
|
||||
|
||||
_chatManager.DispatchServerAnnouncement(Loc.GetString("Restarting in {0} seconds.", (int) RoundEndDelay.TotalSeconds));
|
||||
_checkTimerCancel.Cancel();
|
||||
|
||||
Timer.Spawn(RoundEndDelay, () => _gameTicker.RestartRound());
|
||||
Timer.Spawn(RoundEndDelay, () => gameTicker.RestartRound());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user