Files
tbd-station-14/Content.Server/GameTicking/Rules/GameRuleSystem.cs
Kara b9a0894d7c Event refactor (#9589)
* Station event refactor

* Remove clientside `IStationEventManager`

we can just use prototypes

* Basic API idea

* Cruft

* first attempt at epicness

* okay yeah this shit is really clean

* sort out minor stuff

* Convert `BreakerFlip`

* `BureaucraticError` + general cleanup

* `DiseaseOutbreak`

* `FalseAlarm`

* `GasLeak`

* `KudzuGrowth`

* `MeteorSwarm`

* `MouseMigration`

* misc errors

* `PowerGridCheck`

* `RandomSentience`

* `VentClog`

* `VentCritters`

* `ZombieOutbreak`

* Rewrite basic event scheduler

* Minor fixes and logging

* ooooops

* errors + fix

* linter

* completions, `RuleStarted` property, update loop fixes

* Tweaks

* Fix #9462

* Basic scheduler update fix, and fixes #8174

* Add test

* UI cleanup

* really this was just for testing
2022-07-10 20:48:41 -05:00

95 lines
2.7 KiB
C#

using Content.Server.GameTicking.Rules.Configurations;
using JetBrains.Annotations;
namespace Content.Server.GameTicking.Rules;
[PublicAPI]
public abstract class GameRuleSystem : EntitySystem
{
[Dependency] protected GameTicker GameTicker = default!;
/// <summary>
/// Whether this GameRule is currently added or not.
/// Be sure to check this before doing anything rule-specific.
/// </summary>
public bool RuleAdded { get; protected set; }
/// <summary>
/// Whether this game rule has been started after being added.
/// You probably want to check this before doing any update loop stuff.
/// </summary>
public bool RuleStarted { get; protected set; }
/// <summary>
/// When the GameRule prototype with this ID is added, this system will be enabled.
/// When it gets removed, this system will be disabled.
/// </summary>
public new abstract string Prototype { get; }
/// <summary>
/// Holds the current configuration after the event has been added.
/// This should not be getting accessed before the event is enabled, as usual.
/// </summary>
public GameRuleConfiguration Configuration = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<GameRuleAddedEvent>(OnGameRuleAdded);
SubscribeLocalEvent<GameRuleStartedEvent>(OnGameRuleStarted);
SubscribeLocalEvent<GameRuleEndedEvent>(OnGameRuleEnded);
}
private void OnGameRuleAdded(GameRuleAddedEvent ev)
{
if (ev.Rule.Configuration.Id != Prototype)
return;
Configuration = ev.Rule.Configuration;
RuleAdded = true;
Added();
}
private void OnGameRuleStarted(GameRuleStartedEvent ev)
{
if (ev.Rule.Configuration.Id != Prototype)
return;
RuleStarted = true;
Started();
}
private void OnGameRuleEnded(GameRuleEndedEvent ev)
{
if (ev.Rule.Configuration.Id != Prototype)
return;
RuleAdded = false;
RuleStarted = false;
Ended();
}
/// <summary>
/// Called when the game rule has been added.
/// You should avoid using this in favor of started--they are not the same thing.
/// </summary>
/// <remarks>
/// This is virtual because it doesn't actually have to be used, and most of the time shouldn't be.
/// </remarks>
public virtual void Added() { }
/// <summary>
/// Called when the game rule has been started.
/// </summary>
public abstract void Started();
/// <summary>
/// Called when the game rule has ended.
/// </summary>
public abstract void Ended();
}