Skip to content

Commit

Permalink
centcom emag + centom ftl radar
Browse files Browse the repository at this point in the history
  • Loading branch information
Rxup committed Oct 30, 2023
1 parent 6e939d9 commit 33d3890
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 6 deletions.
111 changes: 105 additions & 6 deletions Content.Server/Backmen/Arrivals/CentcommSystem.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
using System.Numerics;
using Content.Server.Chat.Managers;
using Content.Server.Chat.Systems;
using Content.Server.GameTicking;
using Content.Server.GameTicking.Events;
using Content.Server.Popups;
using Content.Server.Power.EntitySystems;
using Content.Server.Salvage.Expeditions;
using Content.Server.Shuttle.Components;
using Content.Server.Shuttles.Components;
using Content.Server.Shuttles.Events;
using Content.Server.Shuttles.Systems;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Shared.Backmen.Abilities;
using Content.Shared.Cargo.Components;
using Content.Shared.CCVar;
using Content.Shared.Emag.Components;
using Content.Shared.Emag.Systems;
using Content.Shared.GameTicking;
using Content.Shared.Shuttles.Components;
using Robust.Server.GameObjects;
using Robust.Server.Maps;
using Robust.Shared.Audio;
using Robust.Shared.Configuration;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;

namespace Content.Server.Backmen.Arrivals;

public sealed class FtlCentComAnnounce : EntityEventArgs
{
public Entity<ShuttleComponent> Source { get; set; }
}

public sealed class CentcommSystem : EntitySystem
{
[Dependency] private readonly PopupSystem _popup = default!;
Expand All @@ -34,6 +45,10 @@ public sealed class CentcommSystem : EntitySystem
[Dependency] private readonly ShuttleSystem _shuttle = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly ShuttleConsoleSystem _console = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly ChatSystem _chat = default!;
[Dependency] private readonly TransformSystem _transformSystem = default!;
private ISawmill _sawmill = default!;


Expand All @@ -46,16 +61,96 @@ public override void Initialize()
base.Initialize();
_sawmill = Logger.GetSawmill("centcom");
SubscribeLocalEvent<ActorComponent, CentcomFtlAction>(OnFtlActionUsed);
SubscribeLocalEvent<PreGameMapLoad>(OnPreGameMapLoad, after: new[]{typeof(StationSystem)});
SubscribeLocalEvent<RoundStartingEvent>(OnCentComInit, before: new []{ typeof(EmergencyShuttleSystem) });
SubscribeLocalEvent<PreGameMapLoad>(OnPreGameMapLoad, after: new[] { typeof(StationSystem) });
SubscribeLocalEvent<RoundStartingEvent>(OnCentComInit, before: new[] { typeof(EmergencyShuttleSystem) });
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnCleanup);
SubscribeLocalEvent<ShuttleConsoleComponent, GotEmaggedEvent>(OnShuttleConsoleEmaged);
SubscribeLocalEvent<FTLCompletedEvent>(OnFTLCompleted);
SubscribeLocalEvent<FtlCentComAnnounce>(OnFtlAnnounce);
_cfg.OnValueChanged(CCVars.GridFill, OnGridFillChange);
}

private void OnFtlAnnounce(FtlCentComAnnounce ev)
{
if (!CentComGrid.IsValid())
{
return; // not loaded centcom
}

var transformQuery = EntityQueryEnumerator<TransformComponent, IFFConsoleComponent>();

var shuttleName = "Неизвестный";

while (transformQuery.MoveNext(out var owner, out var transformComponent, out var iff))
{
if (transformComponent.GridUid != ev.Source)
{
continue;
}

var f = iff.AllowedFlags;
if (f.HasFlag(IFFFlags.Hide))
{
continue;
}

var name = MetaData(ev.Source).EntityName;
if (string.IsNullOrWhiteSpace(name))
{
continue;
}

shuttleName = name;
}

_chat.DispatchStationAnnouncement(CentComGrid,
$"Внимание! Радары обнаружили {shuttleName} шаттл, входящий в космическое пространство объекта Центрального Командования!",
"Радар", colorOverride: Color.Crimson);
}

private void OnFTLCompleted(ref FTLCompletedEvent ev)
{
if (!CentComGrid.IsValid())
{
return; // not loaded centcom
}

if (ev.MapUid != _mapManager.GetMapEntityId(CentComMap))
{
return; // not centcom
}

if (!TryComp<ShuttleComponent>(ev.Entity, out var shuttleComponent))
{
return;
}

QueueLocalEvent(new FtlCentComAnnounce
{
Source = (ev.Entity, shuttleComponent!)
});
}

private static readonly SoundSpecifier SparkSound = new SoundCollectionSpecifier("sparks");

[ValidatePrototypeId<EntityPrototype>]
private const string StationShuttleConsole = "ComputerShuttle";

private void OnShuttleConsoleEmaged(Entity<ShuttleConsoleComponent> ent, ref GotEmaggedEvent args)
{
if (Prototype(ent)?.ID != StationShuttleConsole)
{
return;
}

if (!this.IsPowered(ent, EntityManager))
return;

_audio.PlayPvs(SparkSound, ent);
_popupSystem.PopupEntity(Loc.GetString("cloning-pod-component-upgrade-emag-requirement"), ent);
args.Handled = true;
EnsureComp<EmaggedComponent>(ent); // для обновления консоли нужно чтобы компонент был до вызыва RefreshShuttleConsoles
_console.RefreshShuttleConsoles();
}

private void OnGridFillChange(bool obj)
Expand Down Expand Up @@ -85,11 +180,13 @@ public void EnsureCentcom(bool force = false)
{
return;
}

_sawmill.Info("EnsureCentcom");
if (CentComGrid.IsValid())
{
return;
}

_sawmill.Info("Start load centcom");

if (CentComMap == MapId.Nullspace)
Expand Down Expand Up @@ -143,6 +240,7 @@ private void OnCentComInit(RoundStartingEvent ev)
{
return;
}

EnsureCentcom();
}

Expand Down Expand Up @@ -172,7 +270,8 @@ private void OnFtlActionUsed(EntityUid uid, ActorComponent component, CentcomFtl

TransformComponent shuttle;

if (TryComp<DroneConsoleComponent>(pilotComponent.Console, out var droneConsoleComponent) && droneConsoleComponent.Entity != null)
if (TryComp<DroneConsoleComponent>(pilotComponent.Console, out var droneConsoleComponent) &&
droneConsoleComponent.Entity != null)
{
shuttle = Transform(droneConsoleComponent.Entity.Value);
}
Expand All @@ -184,11 +283,11 @@ private void OnFtlActionUsed(EntityUid uid, ActorComponent component, CentcomFtl

if (!TryComp<ShuttleComponent>(shuttle.GridUid, out var comp) || HasComp<FTLComponent>(shuttle.GridUid) || (
HasComp<BecomesStationComponent>(shuttle.GridUid) &&
!(
!(
HasComp<SalvageShuttleComponent>(shuttle.GridUid) ||
HasComp<CargoShuttleComponent>(shuttle.GridUid)
)
))
)
))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@
- type: IconSmooth
key: walls
base: riveted
- type: Reflect
reflectProb: 1

0 comments on commit 33d3890

Please sign in to comment.