mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* Remove all IPrototypeManager instances * Remove redundant IComponentFactory instances too * Found some stragglers * DestructibleSystem.PrototypeManager: no dependency * not based
118 lines
3.6 KiB
C#
118 lines
3.6 KiB
C#
using Content.Server.Atmos.EntitySystems;
|
|
using Content.Shared.GameTicking.Components;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.Random;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Server.GameTicking.Rules;
|
|
|
|
public abstract partial class GameRuleSystem<T> : EntitySystem where T : IComponent
|
|
{
|
|
[Dependency] protected IGameTiming Timing = default!;
|
|
[Dependency] protected IRobustRandom RobustRandom = default!;
|
|
[Dependency] protected GameTicker GameTicker = default!;
|
|
|
|
// Not protected, just to be used in utility methods
|
|
[Dependency] private AtmosphereSystem _atmosphere = default!;
|
|
[Dependency] private MapSystem _map = default!;
|
|
|
|
[Dependency] protected EntityQuery<GameRuleComponent> GameRuleQuery = default!;
|
|
[Dependency] protected EntityQuery<T> RuleQuery = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<T, GameRuleAddedEvent>(OnGameRuleAdded);
|
|
SubscribeLocalEvent<T, GameRuleStartedEvent>(OnGameRuleStarted);
|
|
SubscribeLocalEvent<T, GameRuleEndedEvent>(OnGameRuleEnded);
|
|
SubscribeLocalEvent<RoundEndTextAppendEvent>(OnRoundEndTextAppend);
|
|
}
|
|
|
|
private void OnGameRuleAdded(EntityUid uid, T component, ref GameRuleAddedEvent args)
|
|
{
|
|
if (!GameRuleQuery.TryComp(uid, out var ruleData))
|
|
return;
|
|
|
|
Added(uid, component, ruleData, args);
|
|
}
|
|
|
|
private void OnGameRuleStarted(EntityUid uid, T component, ref GameRuleStartedEvent args)
|
|
{
|
|
if (!GameRuleQuery.TryComp(uid, out var ruleData))
|
|
return;
|
|
|
|
Started(uid, component, ruleData, args);
|
|
}
|
|
|
|
private void OnGameRuleEnded(EntityUid uid, T component, ref GameRuleEndedEvent args)
|
|
{
|
|
if (!GameRuleQuery.TryComp(uid, out var ruleData))
|
|
return;
|
|
|
|
Ended(uid, component, ruleData, args);
|
|
}
|
|
|
|
private void OnRoundEndTextAppend(RoundEndTextAppendEvent ev)
|
|
{
|
|
var query = QueryAllRules();
|
|
while (query.MoveNext(out var uid, out var comp, out var ruleData))
|
|
{
|
|
AppendRoundEndText(uid, comp, ruleData, ref ev);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Called when the gamerule is added
|
|
/// </summary>
|
|
protected virtual void Added(EntityUid uid, T component, GameRuleComponent gameRule, GameRuleAddedEvent args)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Called when the gamerule begins
|
|
/// </summary>
|
|
protected virtual void Started(EntityUid uid, T component, GameRuleComponent gameRule, GameRuleStartedEvent args)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Called when the gamerule ends
|
|
/// </summary>
|
|
protected virtual void Ended(EntityUid uid, T component, GameRuleComponent gameRule, GameRuleEndedEvent args)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Called at the end of a round when text needs to be added for a game rule.
|
|
/// </summary>
|
|
protected virtual void AppendRoundEndText(EntityUid uid, T component, GameRuleComponent gameRule, ref RoundEndTextAppendEvent args)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Called on an active gamerule entity in the Update function
|
|
/// </summary>
|
|
protected virtual void ActiveTick(EntityUid uid, T component, GameRuleComponent gameRule, float frameTime)
|
|
{
|
|
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
|
|
var query = EntityQueryEnumerator<T, GameRuleComponent>();
|
|
while (query.MoveNext(out var uid, out var comp1, out var comp2))
|
|
{
|
|
if (!GameTicker.IsGameRuleActive(uid, comp2))
|
|
continue;
|
|
|
|
ActiveTick(uid, comp1, comp2, frameTime);
|
|
}
|
|
}
|
|
}
|