2024-01-30 22:52:35 -07:00
|
|
|
using Content.Server.Atmos.EntitySystems;
|
2023-09-28 07:48:59 -07:00
|
|
|
using Content.Server.Chat.Managers;
|
2023-04-25 20:23:14 -04:00
|
|
|
using Content.Server.GameTicking.Rules.Components;
|
2024-01-30 22:52:35 -07:00
|
|
|
using Robust.Server.GameObjects;
|
|
|
|
|
using Robust.Shared.Random;
|
Refactor antag rule code (#23445)
* Initial Pass, Rev, Thief
* Zombie initial pass
* Rebase, Traitor
* Nukeops, More overloads
* Revert RevolutionaryRuleComponent
* Use TryRoundStartAttempt, Rewrite nukie spawning
* Comments, Add task scheduler to GameRuleSystem
* Zombie initial testing done
* Sort methods, rework GameRuleTask
* Add CCVar, Initial testing continues
* Might as well get rid of the obsolete logging
* Oops, i dont know how to log apparently
* Suggested formatting fixes
* Suggested changes
* Fix merge issues
* Minor optimisation
* Allowed thief to choose other antags
* Review changes
* Spawn items on floor first, then inserting
* minor tweaks
* Shift as much as possible to ProtoId<>
* Remove unneeded
* Add exclusive antag attribute
* Fix merge issues
* Minor formatting fix
* Convert to struct
* Cleanup
* Review cleanup (need to test a lot)
* Some fixes, (mostly) tested
* oop
* Pass tests (for real)
---------
Co-authored-by: Rainfall <rainfey0+git@gmail.com>
Co-authored-by: AJCM <AJCM@tutanota.com>
2024-02-29 06:25:10 +00:00
|
|
|
using Robust.Shared.Timing;
|
2021-12-21 21:23:29 +01:00
|
|
|
|
|
|
|
|
namespace Content.Server.GameTicking.Rules;
|
|
|
|
|
|
2023-10-17 19:42:47 -07:00
|
|
|
public abstract partial class GameRuleSystem<T> : EntitySystem where T : IComponent
|
2021-12-21 21:23:29 +01:00
|
|
|
{
|
2024-01-30 22:52:35 -07:00
|
|
|
[Dependency] protected readonly IRobustRandom RobustRandom = default!;
|
2023-09-28 07:48:59 -07:00
|
|
|
[Dependency] protected readonly IChatManager ChatManager = default!;
|
2023-04-28 23:14:15 -04:00
|
|
|
[Dependency] protected readonly GameTicker GameTicker = default!;
|
Refactor antag rule code (#23445)
* Initial Pass, Rev, Thief
* Zombie initial pass
* Rebase, Traitor
* Nukeops, More overloads
* Revert RevolutionaryRuleComponent
* Use TryRoundStartAttempt, Rewrite nukie spawning
* Comments, Add task scheduler to GameRuleSystem
* Zombie initial testing done
* Sort methods, rework GameRuleTask
* Add CCVar, Initial testing continues
* Might as well get rid of the obsolete logging
* Oops, i dont know how to log apparently
* Suggested formatting fixes
* Suggested changes
* Fix merge issues
* Minor optimisation
* Allowed thief to choose other antags
* Review changes
* Spawn items on floor first, then inserting
* minor tweaks
* Shift as much as possible to ProtoId<>
* Remove unneeded
* Add exclusive antag attribute
* Fix merge issues
* Minor formatting fix
* Convert to struct
* Cleanup
* Review cleanup (need to test a lot)
* Some fixes, (mostly) tested
* oop
* Pass tests (for real)
---------
Co-authored-by: Rainfall <rainfey0+git@gmail.com>
Co-authored-by: AJCM <AJCM@tutanota.com>
2024-02-29 06:25:10 +00:00
|
|
|
[Dependency] protected readonly IGameTiming Timing = default!;
|
2021-12-21 21:23:29 +01:00
|
|
|
|
2024-01-30 22:52:35 -07:00
|
|
|
// Not protected, just to be used in utility methods
|
|
|
|
|
[Dependency] private readonly AtmosphereSystem _atmosphere = default!;
|
|
|
|
|
[Dependency] private readonly MapSystem _map = default!;
|
|
|
|
|
|
2021-12-21 21:23:29 +01:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
SubscribeLocalEvent<T, GameRuleAddedEvent>(OnGameRuleAdded);
|
|
|
|
|
SubscribeLocalEvent<T, GameRuleStartedEvent>(OnGameRuleStarted);
|
|
|
|
|
SubscribeLocalEvent<T, GameRuleEndedEvent>(OnGameRuleEnded);
|
2021-12-21 21:23:29 +01:00
|
|
|
}
|
|
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
private void OnGameRuleAdded(EntityUid uid, T component, ref GameRuleAddedEvent args)
|
2022-02-15 20:06:28 -07:00
|
|
|
{
|
2023-04-25 20:23:14 -04:00
|
|
|
if (!TryComp<GameRuleComponent>(uid, out var ruleData))
|
2022-02-15 20:06:28 -07:00
|
|
|
return;
|
2023-04-25 20:23:14 -04:00
|
|
|
Added(uid, component, ruleData, args);
|
2022-02-15 20:06:28 -07:00
|
|
|
}
|
|
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
private void OnGameRuleStarted(EntityUid uid, T component, ref GameRuleStartedEvent args)
|
2021-12-21 21:23:29 +01:00
|
|
|
{
|
2023-04-25 20:23:14 -04:00
|
|
|
if (!TryComp<GameRuleComponent>(uid, out var ruleData))
|
2021-12-21 21:23:29 +01:00
|
|
|
return;
|
2023-04-25 20:23:14 -04:00
|
|
|
Started(uid, component, ruleData, args);
|
2021-12-21 21:23:29 +01:00
|
|
|
}
|
|
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
private void OnGameRuleEnded(EntityUid uid, T component, ref GameRuleEndedEvent args)
|
2023-04-24 01:20:51 -04:00
|
|
|
{
|
2023-04-25 20:23:14 -04:00
|
|
|
if (!TryComp<GameRuleComponent>(uid, out var ruleData))
|
2023-04-24 16:21:05 +10:00
|
|
|
return;
|
2023-04-25 20:23:14 -04:00
|
|
|
Ended(uid, component, ruleData, args);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-28 07:48:59 -07:00
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Called when the gamerule is added
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual void Added(EntityUid uid, T component, GameRuleComponent gameRule, GameRuleAddedEvent args)
|
|
|
|
|
{
|
2023-04-24 01:20:51 -04:00
|
|
|
|
|
|
|
|
}
|
2022-07-10 18:48:41 -07:00
|
|
|
|
|
|
|
|
/// <summary>
|
2023-04-25 20:23:14 -04:00
|
|
|
/// Called when the gamerule begins
|
2021-12-21 21:23:29 +01:00
|
|
|
/// </summary>
|
2023-04-25 20:23:14 -04:00
|
|
|
protected virtual void Started(EntityUid uid, T component, GameRuleComponent gameRule, GameRuleStartedEvent args)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2021-12-21 21:23:29 +01:00
|
|
|
|
|
|
|
|
/// <summary>
|
2023-04-25 20:23:14 -04:00
|
|
|
/// Called when the gamerule ends
|
2021-12-21 21:23:29 +01:00
|
|
|
/// </summary>
|
2023-04-25 20:23:14 -04:00
|
|
|
protected virtual void Ended(EntityUid uid, T component, GameRuleComponent gameRule, GameRuleEndedEvent args)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2023-04-24 01:20:51 -04:00
|
|
|
|
2023-04-24 16:21:05 +10:00
|
|
|
/// <summary>
|
2023-04-25 20:23:14 -04:00
|
|
|
/// Called on an active gamerule entity in the Update function
|
2023-04-24 16:21:05 +10:00
|
|
|
/// </summary>
|
2023-04-25 20:23:14 -04:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-21 21:23:29 +01:00
|
|
|
}
|