mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* Refactor DeviceNetwork * Singleton * NetworkPayloads refactor * Reorganize DeviceNetworkSystem * Surveillance cameras * Fix code * Fix build * Fix test fail by rewriting entire singleton logic * Properly predict examine * Update DeviceNetworkSystem.API.cs * Update EntityTest.cs * Update DeviceNetworkSystem.cs * Alright I'll do this expensive check fine * Fix disposals debug assert * Implement device network static events support * Use frozen dictionaries for performance * Update SharedDeviceNetworkSystem.Payloads.cs * Parallel payload handling support * Fix some spagetti-code * Optimize NetworkPayload cancellation * Parallel payloads are now cancellable * Fix screens * Fix robotics console * Allow new methods for shared * Mail fix * Turret fix * Fix network system method usage + signal and borg fix * finally fix atmos devices OH MY GOOOD * Remove stupid parallelism from fax * Fix surveiollance cameras * Working on a single thing for 2 days straight award * Fix the test? * Update units.yml * Add IDevice interface because why not * Add more device network suffixes * Fix camera router failing test * yaml linter peak * Improve docs for DeviceNetworkHandlers * fix build * Update CartridgeLoaderSystem.Relay.cs * Remove parallel system and EntitySystem post init * Add more docs and also events * Remove unnecessary caching * Update DevicePayloadComponentSystem.cs * Back to entity events * Implement DeviceData * Remove serializable from payloads * Update DeviceData.cs * Add a prototype for a singleton * Fix tests * Fix air alarms * Update DeviceNetworkSystem.cs * Fix cameras * Make camera router event-less * Fix atmos sync payloads, add more docs * Remove singleton + instant packets * oops remove public access * Fix tests? * Why the hell overload effect makes puddle sparks * Apparently it was redundant * Update gates.yml * Finish documentation * Review * Mark relay properties as obsolete * Struct payloads support (#blazinglyfastmemorysafe) * Update DeviceNetworkTest.cs * Make device structs stuff better * Move address prefix to DeviceNetworkComponent * Locale fixes * Fix tests * Doesn't know boolean logic award * Update AtmosAlarmableSystem.cs * Fix address predicted examine * Partial fix to air alarmables * Fix deployable turrets UI * Fix firelocks, maybe * Apparently Activatable UI was enough lol * Fix surveillance cameras * Rename `QueuePacket` into `SendPacket` * Simplify DeviceData as much as possible * Update DeviceData.cs * Update FaxMachineComponent.cs * Remove DeviceData because its stupid * Update ScreenSystem.cs * Fix build (camera map broken still) * Fix map * fix usings * Review changes * Build fix
133 lines
4.7 KiB
C#
133 lines
4.7 KiB
C#
using Content.Server.Anomaly.Components;
|
|
using Content.Server.Beam;
|
|
using Content.Server.DeviceLinking.Systems;
|
|
using Content.Shared.Anomaly.Components;
|
|
using Content.Shared.DeviceLinking;
|
|
using Content.Shared.Emag.Systems;
|
|
using Robust.Shared.Random;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Server.Anomaly.Effects;
|
|
|
|
public sealed partial class TechAnomalySystem : EntitySystem
|
|
{
|
|
[Dependency] private DeviceLinkSystem _signal = default!;
|
|
[Dependency] private EntityLookupSystem _lookup = default!;
|
|
[Dependency] private IRobustRandom _random = default!;
|
|
[Dependency] private BeamSystem _beam = default!;
|
|
[Dependency] private IGameTiming _timing = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<TechAnomalyComponent, MapInitEvent>(OnTechMapInit);
|
|
SubscribeLocalEvent<TechAnomalyComponent, AnomalyPulseEvent>(OnPulse);
|
|
SubscribeLocalEvent<TechAnomalyComponent, AnomalySupercriticalEvent>(OnSupercritical);
|
|
SubscribeLocalEvent<TechAnomalyComponent, AnomalyStabilityChangedEvent>(OnStabilityChanged);
|
|
}
|
|
|
|
private void OnTechMapInit(Entity<TechAnomalyComponent> ent, ref MapInitEvent args)
|
|
{
|
|
ent.Comp.NextTimer = _timing.CurTime;
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
|
|
var query = EntityQueryEnumerator<TechAnomalyComponent, AnomalyComponent>();
|
|
while (query.MoveNext(out var uid, out var tech, out var anom))
|
|
{
|
|
if (_timing.CurTime < tech.NextTimer)
|
|
continue;
|
|
|
|
tech.NextTimer += TimeSpan.FromSeconds(tech.TimerFrequency);
|
|
|
|
_signal.InvokePort(uid, tech.TimerPort);
|
|
}
|
|
}
|
|
|
|
private void OnStabilityChanged(Entity<TechAnomalyComponent> tech, ref AnomalyStabilityChangedEvent args)
|
|
{
|
|
var links = MathHelper.Lerp(tech.Comp.LinkCountPerPulse.Min, tech.Comp.LinkCountPerPulse.Max, args.Severity);
|
|
CreateNewRandomLink(tech, (int)links);
|
|
}
|
|
|
|
private void CreateNewRandomLink(Entity<TechAnomalyComponent> tech, int count)
|
|
{
|
|
if (!TryComp<AnomalyComponent>(tech, out var anomaly))
|
|
return;
|
|
if (!TryComp<DeviceLinkSourceComponent>(tech, out var sourceComp))
|
|
return;
|
|
|
|
var range = MathHelper.Lerp(tech.Comp.LinkRadius.Min, tech.Comp.LinkRadius.Max, anomaly.Severity);
|
|
|
|
var devices = _lookup.GetEntitiesInRange<DeviceLinkSinkComponent>(Transform(tech).Coordinates, range);
|
|
if (devices.Count < 1)
|
|
return;
|
|
|
|
for (var i = 0; i < count; i++)
|
|
{
|
|
var device = _random.Pick(devices);
|
|
CreateNewLink(tech, (tech, sourceComp), device);
|
|
}
|
|
}
|
|
|
|
private void CreateNewLink(Entity<TechAnomalyComponent> tech, Entity<DeviceLinkSourceComponent> source, Entity<DeviceLinkSinkComponent> target)
|
|
{
|
|
var sourcePort = _random.Pick(source.Comp.Ports);
|
|
var sinkPort = _random.Pick(target.Comp.Ports);
|
|
|
|
_signal.SaveLinks(null, source, target,new()
|
|
{
|
|
(sourcePort, sinkPort),
|
|
});
|
|
_beam.TryCreateBeam(source, target, tech.Comp.LinkBeamProto);
|
|
}
|
|
|
|
private void OnSupercritical(Entity<TechAnomalyComponent> tech, ref AnomalySupercriticalEvent args)
|
|
{
|
|
// We remove the component so that the anomaly does not bind itself to other devices before self destroy.
|
|
RemComp<DeviceLinkSourceComponent>(tech);
|
|
|
|
var sources =
|
|
_lookup.GetEntitiesInRange<DeviceLinkSourceComponent>(Transform(tech).Coordinates,
|
|
tech.Comp.LinkRadius.Max);
|
|
|
|
var sinks =
|
|
_lookup.GetEntitiesInRange<DeviceLinkSinkComponent>(Transform(tech).Coordinates,
|
|
tech.Comp.LinkRadius.Max);
|
|
|
|
for (var i = 0; i < tech.Comp.LinkCountSupercritical; i++)
|
|
{
|
|
if (sources.Count < 1)
|
|
return;
|
|
|
|
if (sinks.Count < 1)
|
|
return;
|
|
|
|
var source = _random.Pick(sources);
|
|
sources.Remove(source);
|
|
|
|
var sink = _random.Pick(sinks);
|
|
sinks.Remove(sink);
|
|
|
|
if (_random.Prob(tech.Comp.EmagSupercritProbability))
|
|
{
|
|
var sourceEv = new GotEmaggedEvent(tech, EmagType.Access | EmagType.Interaction);
|
|
RaiseLocalEvent(source, ref sourceEv);
|
|
|
|
var sinkEv = new GotEmaggedEvent(tech, EmagType.Access | EmagType.Interaction);
|
|
RaiseLocalEvent(sink, ref sinkEv);
|
|
}
|
|
|
|
CreateNewLink(tech, source, sink);
|
|
}
|
|
}
|
|
|
|
private void OnPulse(Entity<TechAnomalyComponent> tech, ref AnomalyPulseEvent args)
|
|
{
|
|
_signal.InvokePort(tech.Owner, tech.Comp.PulsePort);
|
|
}
|
|
}
|