mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-06-09 15:06:34 +02:00
086479313f
* "fixes" it but the logic just needs to be rewritten. * init commit * almost there * commit * Scrounger * actually spawn the ghost roles, and better assertion behavior! * update the warning because I know someone is gonna touch it * hhng * fix Traitor assignment * Prune the list and ignore dummy antags * game test * skip dummy antag * crisaskjfshj * It's time, it's fucking time * fixing the secret gamemode bug once and for all. * docs * burger * dssdgdsgds * so hungry for test fails * job whitelist * review --------- Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
122 lines
3.8 KiB
C#
122 lines
3.8 KiB
C#
using Content.Server.Atmos.EntitySystems;
|
|
using Content.Server.Chat.Managers;
|
|
using Content.Shared.GameTicking.Components;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.Prototypes;
|
|
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 readonly IGameTiming Timing = default!;
|
|
[Dependency] protected readonly IPrototypeManager Proto = default!;
|
|
[Dependency] protected readonly IRobustRandom RobustRandom = default!;
|
|
[Dependency] protected readonly GameTicker GameTicker = default!;
|
|
|
|
// Not protected, just to be used in utility methods
|
|
[Dependency] private readonly AtmosphereSystem _atmosphere = default!;
|
|
[Dependency] private readonly MapSystem _map = default!;
|
|
|
|
[Dependency] protected readonly EntityQuery<GameRuleComponent> GameRuleQuery = default!;
|
|
[Dependency] protected readonly 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);
|
|
}
|
|
}
|
|
}
|