Files
tbd-station-14/Content.Server/StationEvents/Events/StationEventSystem.cs
Ed e522bbf90d New event: Approaching unknown shuttle (#24490)
* setup codebase

* Add first shuttle

* tak

* sync striker

* sync 2

* pipipi

* Preloaded roundstart shuttles!

* Make it abstract "PreloaderGrid" not "PreloaderShuttle"

* to do

* added china cuisin shuttle

* fixes

* add disaster evacpod

* remove enemy

* final shuttles

* weight 5 -> 10

* move data to component

* remove autotrailer touching

* doc, respath

* fix frozen positioning

* fixes + cvar

* finally

* fix evacpod

* remove blacklistrules

* remove `UnknownShuttleSpawnRule`, refactor `LoadMapRule` to support preloaded grids

* use tryload

* cleanup

* fixes

* use preloadedgrid for loneops

* weight unknown shuttles differently (preliminal)

* leftover

* cleanup and raffling

* partial review

* singleton gridpreloader no station coupling

* fix grid atmoses

* `roleLoadout` support for `LoadoutComponent`, fix missing gear

* weighting changes

* init logic fix

---------

Co-authored-by: Kara <lunarautomaton6@gmail.com>
2024-05-10 04:35:59 -07:00

131 lines
4.7 KiB
C#

using System.Linq;
using Content.Server.Administration.Logs;
using Content.Server.Chat.Systems;
using Content.Server.GameTicking.Components;
using Content.Server.GameTicking.Rules;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.Station.Systems;
using Content.Server.StationEvents.Components;
using Content.Shared.Database;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
namespace Content.Server.StationEvents.Events;
/// <summary>
/// An abstract entity system inherited by all station events for their behavior.
/// </summary>
public abstract class StationEventSystem<T> : GameRuleSystem<T> where T : IComponent
{
[Dependency] protected readonly IAdminLogManager AdminLogManager = default!;
[Dependency] protected readonly IMapManager MapManager = 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()
{
base.Initialize();
Sawmill = Logger.GetSawmill("stationevents");
}
/// <inheritdoc/>
protected override void Added(EntityUid uid, T component, GameRuleComponent gameRule, GameRuleAddedEvent args)
{
base.Added(uid, component, gameRule, args);
if (!TryComp<StationEventComponent>(uid, out var stationEvent))
return;
AdminLogManager.Add(LogType.EventAnnounced, $"Event added / announced: {ToPrettyString(uid)}");
if (stationEvent.StartAnnouncement != null)
{
ChatSystem.DispatchGlobalAnnouncement(Loc.GetString(stationEvent.StartAnnouncement), playSound: false, colorOverride: Color.Gold);
}
Audio.PlayGlobal(stationEvent.StartAudio, Filter.Broadcast(), true);
stationEvent.StartTime = Timing.CurTime + stationEvent.StartDelay;
}
/// <inheritdoc/>
protected override void Started(EntityUid uid, T component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
base.Started(uid, component, gameRule, args);
if (!TryComp<StationEventComponent>(uid, out var stationEvent))
return;
AdminLogManager.Add(LogType.EventStarted, LogImpact.High, $"Event started: {ToPrettyString(uid)}");
if (stationEvent.Duration != null)
{
var duration = stationEvent.MaxDuration == null
? stationEvent.Duration
: TimeSpan.FromSeconds(RobustRandom.NextDouble(stationEvent.Duration.Value.TotalSeconds,
stationEvent.MaxDuration.Value.TotalSeconds));
stationEvent.EndTime = Timing.CurTime + duration;
}
}
/// <inheritdoc/>
protected override void Ended(EntityUid uid, T component, GameRuleComponent gameRule, GameRuleEndedEvent args)
{
base.Ended(uid, component, gameRule, args);
if (!TryComp<StationEventComponent>(uid, out var stationEvent))
return;
AdminLogManager.Add(LogType.EventStopped, $"Event ended: {ToPrettyString(uid)}");
if (stationEvent.EndAnnouncement != null)
{
ChatSystem.DispatchGlobalAnnouncement(Loc.GetString(stationEvent.EndAnnouncement), playSound: false, colorOverride: Color.Gold);
}
Audio.PlayGlobal(stationEvent.EndAudio, Filter.Broadcast(), true);
}
/// <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)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<StationEventComponent, GameRuleComponent>();
while (query.MoveNext(out var uid, out var stationEvent, out var ruleData))
{
if (!GameTicker.IsGameRuleAdded(uid, ruleData))
continue;
if (!GameTicker.IsGameRuleActive(uid, ruleData) && Timing.CurTime >= stationEvent.StartTime)
{
GameTicker.StartGameRule(uid, ruleData);
}
else if (stationEvent.EndTime != null && Timing.CurTime >= stationEvent.EndTime && GameTicker.IsGameRuleActive(uid, ruleData))
{
GameTicker.EndGameRule(uid, ruleData);
}
}
}
#region Helper Functions
protected void ForceEndSelf(EntityUid uid, GameRuleComponent? component = null)
{
GameTicker.EndGameRule(uid, component);
}
#endregion
}