using JetBrains.Annotations; namespace Content.Server.GameTicking.Rules; [PublicAPI] public abstract class GameRuleSystem : EntitySystem { [Dependency] protected GameTicker GameTicker = default!; /// /// Whether this GameRule is currently enabled or not. /// Be sure to check this before doing anything rule-specific. /// public bool Enabled { get; protected set; } = false; /// /// When the GameRule prototype with this ID is added, this system will be enabled. /// When it gets removed, this system will be disabled. /// public new abstract string Prototype { get; } public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnGameRuleAdded); SubscribeLocalEvent(OnGameRuleStarted); SubscribeLocalEvent(OnGameRuleEnded); } private void OnGameRuleAdded(GameRuleAddedEvent ev) { if (ev.Rule.ID != Prototype) return; Enabled = true; } 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; Ended(); } /// /// Called when the game rule has been started.. /// public abstract void Started(); /// /// Called when the game rule has ended.. /// public abstract void Ended(); }