2022-07-10 18:48:41 -07:00
|
|
|
using Content.Server.Administration.Logs;
|
|
|
|
|
using Content.Server.Chat.Systems;
|
2024-08-10 23:09:33 -07:00
|
|
|
using Content.Server.GameTicking;
|
2022-07-10 18:48:41 -07:00
|
|
|
using Content.Server.GameTicking.Rules;
|
|
|
|
|
using Content.Server.Station.Systems;
|
2023-04-25 20:23:14 -04:00
|
|
|
using Content.Server.StationEvents.Components;
|
2022-07-10 18:48:41 -07:00
|
|
|
using Content.Shared.Database;
|
2024-06-04 11:53:24 +00:00
|
|
|
using Content.Shared.GameTicking.Components;
|
2023-11-27 22:12:34 +11:00
|
|
|
using Robust.Shared.Audio.Systems;
|
2022-07-10 18:48:41 -07:00
|
|
|
using Robust.Shared.Player;
|
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
namespace Content.Server.StationEvents.Events;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// An abstract entity system inherited by all station events for their behavior.
|
|
|
|
|
/// </summary>
|
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
|
|
|
public abstract class StationEventSystem<T> : GameRuleSystem<T> where T : IComponent
|
2022-07-10 18:48:41 -07:00
|
|
|
{
|
2023-04-25 20:23:14 -04:00
|
|
|
[Dependency] protected readonly IAdminLogManager AdminLogManager = default!;
|
|
|
|
|
[Dependency] protected readonly IPrototypeManager PrototypeManager = default!;
|
|
|
|
|
[Dependency] protected readonly ChatSystem ChatSystem = default!;
|
|
|
|
|
[Dependency] protected readonly SharedAudioSystem Audio = default!;
|
|
|
|
|
[Dependency] protected readonly StationSystem StationSystem = default!;
|
|
|
|
|
|
|
|
|
|
protected ISawmill Sawmill = default!;
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
2023-04-24 01:20:51 -04:00
|
|
|
{
|
2023-04-25 20:23:14 -04:00
|
|
|
base.Initialize();
|
2023-04-24 01:20:51 -04:00
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
Sawmill = Logger.GetSawmill("stationevents");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
protected override void Added(EntityUid uid, T component, GameRuleComponent gameRule, GameRuleAddedEvent args)
|
|
|
|
|
{
|
|
|
|
|
base.Added(uid, component, gameRule, args);
|
2023-04-24 01:20:51 -04:00
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
if (!TryComp<StationEventComponent>(uid, out var stationEvent))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
AdminLogManager.Add(LogType.EventAnnounced, $"Event added / announced: {ToPrettyString(uid)}");
|
|
|
|
|
|
2024-08-10 23:09:33 -07:00
|
|
|
// we don't want to send to players who aren't in game (i.e. in the lobby)
|
|
|
|
|
Filter allPlayersInGame = Filter.Empty().AddWhere(GameTicker.UserHasJoinedGame);
|
|
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
if (stationEvent.StartAnnouncement != null)
|
2024-08-10 23:09:33 -07:00
|
|
|
ChatSystem.DispatchFilteredAnnouncement(allPlayersInGame, Loc.GetString(stationEvent.StartAnnouncement), playSound: false, colorOverride: stationEvent.StartAnnouncementColor);
|
2022-07-10 18:48:41 -07:00
|
|
|
|
2024-08-10 23:09:33 -07:00
|
|
|
Audio.PlayGlobal(stationEvent.StartAudio, allPlayersInGame, true);
|
2023-04-25 20:23:14 -04:00
|
|
|
}
|
2022-07-10 18:48:41 -07:00
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
/// <inheritdoc/>
|
|
|
|
|
protected override void Started(EntityUid uid, T component, GameRuleComponent gameRule, GameRuleStartedEvent args)
|
|
|
|
|
{
|
|
|
|
|
base.Started(uid, component, gameRule, args);
|
2022-07-10 18:48:41 -07:00
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
if (!TryComp<StationEventComponent>(uid, out var stationEvent))
|
|
|
|
|
return;
|
2022-07-10 18:48:41 -07:00
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
AdminLogManager.Add(LogType.EventStarted, LogImpact.High, $"Event started: {ToPrettyString(uid)}");
|
2023-04-28 23:15:06 -04:00
|
|
|
|
|
|
|
|
if (stationEvent.Duration != null)
|
|
|
|
|
{
|
|
|
|
|
var duration = stationEvent.MaxDuration == null
|
|
|
|
|
? stationEvent.Duration
|
|
|
|
|
: TimeSpan.FromSeconds(RobustRandom.NextDouble(stationEvent.Duration.Value.TotalSeconds,
|
|
|
|
|
stationEvent.MaxDuration.Value.TotalSeconds));
|
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
|
|
|
stationEvent.EndTime = Timing.CurTime + duration;
|
2023-04-28 23:15:06 -04:00
|
|
|
}
|
2023-04-25 20:23:14 -04:00
|
|
|
}
|
2022-07-10 18:48:41 -07:00
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
/// <inheritdoc/>
|
|
|
|
|
protected override void Ended(EntityUid uid, T component, GameRuleComponent gameRule, GameRuleEndedEvent args)
|
|
|
|
|
{
|
|
|
|
|
base.Ended(uid, component, gameRule, args);
|
2022-07-10 18:48:41 -07:00
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
if (!TryComp<StationEventComponent>(uid, out var stationEvent))
|
|
|
|
|
return;
|
2022-07-10 18:48:41 -07:00
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
AdminLogManager.Add(LogType.EventStopped, $"Event ended: {ToPrettyString(uid)}");
|
2022-07-10 18:48:41 -07:00
|
|
|
|
2024-08-10 23:09:33 -07:00
|
|
|
// we don't want to send to players who aren't in game (i.e. in the lobby)
|
|
|
|
|
Filter allPlayersInGame = Filter.Empty().AddWhere(GameTicker.UserHasJoinedGame);
|
|
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
if (stationEvent.EndAnnouncement != null)
|
2024-08-10 23:09:33 -07:00
|
|
|
ChatSystem.DispatchFilteredAnnouncement(allPlayersInGame, Loc.GetString(stationEvent.EndAnnouncement), playSound: false, colorOverride: stationEvent.EndAnnouncementColor);
|
2022-07-10 18:48:41 -07:00
|
|
|
|
2024-08-10 23:09:33 -07:00
|
|
|
Audio.PlayGlobal(stationEvent.EndAudio, allPlayersInGame, true);
|
2023-04-25 20:23:14 -04:00
|
|
|
}
|
2023-04-24 16:21:05 +10:00
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Called every tick when this event is running.
|
|
|
|
|
/// Events are responsible for their own lifetime, so this handles starting and ending after time.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
{
|
2023-04-28 23:15:06 -04:00
|
|
|
base.Update(frameTime);
|
|
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
var query = EntityQueryEnumerator<StationEventComponent, GameRuleComponent>();
|
|
|
|
|
while (query.MoveNext(out var uid, out var stationEvent, out var ruleData))
|
|
|
|
|
{
|
|
|
|
|
if (!GameTicker.IsGameRuleAdded(uid, ruleData))
|
|
|
|
|
continue;
|
2022-07-10 18:48:41 -07:00
|
|
|
|
2024-06-02 12:52:40 -04:00
|
|
|
if (!GameTicker.IsGameRuleActive(uid, ruleData) && !HasComp<DelayedStartRuleComponent>(uid))
|
|
|
|
|
{
|
|
|
|
|
GameTicker.StartGameRule(uid, ruleData);
|
|
|
|
|
}
|
|
|
|
|
else if (stationEvent.EndTime != null && Timing.CurTime >= stationEvent.EndTime && GameTicker.IsGameRuleActive(uid, ruleData))
|
2022-07-10 18:48:41 -07:00
|
|
|
{
|
2023-04-25 20:23:14 -04:00
|
|
|
GameTicker.EndGameRule(uid, ruleData);
|
2022-07-10 18:48:41 -07:00
|
|
|
}
|
|
|
|
|
}
|
2023-04-25 20:23:14 -04:00
|
|
|
}
|
|
|
|
|
}
|