2022-02-15 15:01:45 +11:00
|
|
|
using Content.Server.Cargo.Components;
|
|
|
|
|
using Content.Server.Power.Components;
|
|
|
|
|
using Content.Shared.Cargo;
|
2023-05-21 06:09:31 -04:00
|
|
|
using Content.Shared.Cargo.Components;
|
|
|
|
|
using Content.Shared.DeviceLinking;
|
2022-02-15 15:01:45 +11:00
|
|
|
using Robust.Shared.Audio;
|
2023-05-21 06:09:31 -04:00
|
|
|
using Robust.Shared.Utility;
|
2022-02-15 15:01:45 +11:00
|
|
|
|
2022-06-03 10:56:11 -05:00
|
|
|
namespace Content.Server.Cargo.Systems;
|
2022-02-15 15:01:45 +11:00
|
|
|
|
|
|
|
|
public sealed partial class CargoSystem
|
|
|
|
|
{
|
|
|
|
|
private void InitializeTelepad()
|
|
|
|
|
{
|
2022-05-12 03:24:24 -07:00
|
|
|
SubscribeLocalEvent<CargoTelepadComponent, ComponentInit>(OnInit);
|
2022-02-15 15:01:45 +11:00
|
|
|
SubscribeLocalEvent<CargoTelepadComponent, PowerChangedEvent>(OnTelepadPowerChange);
|
2022-04-24 13:54:25 +10:00
|
|
|
// Shouldn't need re-anchored event
|
2022-02-15 15:01:45 +11:00
|
|
|
SubscribeLocalEvent<CargoTelepadComponent, AnchorStateChangedEvent>(OnTelepadAnchorChange);
|
|
|
|
|
}
|
|
|
|
|
private void UpdateTelepad(float frameTime)
|
|
|
|
|
{
|
2023-05-21 06:09:31 -04:00
|
|
|
var query = EntityQueryEnumerator<CargoTelepadComponent>();
|
|
|
|
|
while (query.MoveNext(out var uid, out var comp))
|
2022-02-15 15:01:45 +11:00
|
|
|
{
|
|
|
|
|
// Don't EntityQuery for it as it's not required.
|
2023-05-21 06:09:31 -04:00
|
|
|
TryComp<AppearanceComponent>(uid, out var appearance);
|
2022-02-15 15:01:45 +11:00
|
|
|
|
2022-06-23 14:36:47 +10:00
|
|
|
if (comp.CurrentState == CargoTelepadState.Unpowered)
|
2022-02-15 15:01:45 +11:00
|
|
|
{
|
|
|
|
|
comp.CurrentState = CargoTelepadState.Idle;
|
2023-05-21 06:09:31 -04:00
|
|
|
_appearance.SetData(uid, CargoTelepadVisuals.State, CargoTelepadState.Idle, appearance);
|
|
|
|
|
comp.Accumulator = comp.Delay;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!TryComp<DeviceLinkSinkComponent>(uid, out var sinkComponent) ||
|
|
|
|
|
sinkComponent.LinkedSources.FirstOrNull() is not { } console ||
|
|
|
|
|
!HasComp<CargoOrderConsoleComponent>(console))
|
|
|
|
|
{
|
2022-02-15 15:01:45 +11:00
|
|
|
comp.Accumulator = comp.Delay;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
comp.Accumulator -= frameTime;
|
|
|
|
|
|
|
|
|
|
// Uhh listen teleporting takes time and I just want the 1 float.
|
|
|
|
|
if (comp.Accumulator > 0f)
|
|
|
|
|
{
|
|
|
|
|
comp.CurrentState = CargoTelepadState.Idle;
|
2023-05-21 06:09:31 -04:00
|
|
|
_appearance.SetData(uid, CargoTelepadVisuals.State, CargoTelepadState.Idle, appearance);
|
2022-02-15 15:01:45 +11:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-21 06:09:31 -04:00
|
|
|
var station = _station.GetOwningStation(console);
|
2022-06-23 14:36:47 +10:00
|
|
|
|
|
|
|
|
if (!TryComp<StationCargoOrderDatabaseComponent>(station, out var orderDatabase) ||
|
|
|
|
|
orderDatabase.Orders.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
comp.Accumulator += comp.Delay;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-21 06:09:31 -04:00
|
|
|
var xform = Transform(uid);
|
2024-01-19 13:02:28 +11:00
|
|
|
if (FulfillNextOrder(orderDatabase, xform.Coordinates, comp.PrinterOutput))
|
2022-06-23 14:36:47 +10:00
|
|
|
{
|
2023-05-21 06:09:31 -04:00
|
|
|
_audio.PlayPvs(_audio.GetSound(comp.TeleportSound), uid, AudioParams.Default.WithVolume(-8f));
|
2024-01-19 13:02:28 +11:00
|
|
|
UpdateOrders(station.Value, orderDatabase);
|
2022-06-23 14:36:47 +10:00
|
|
|
|
2023-03-05 04:27:30 +00:00
|
|
|
comp.CurrentState = CargoTelepadState.Teleporting;
|
2023-05-21 06:09:31 -04:00
|
|
|
_appearance.SetData(uid, CargoTelepadVisuals.State, CargoTelepadState.Teleporting, appearance);
|
2022-06-23 14:36:47 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
comp.Accumulator += comp.Delay;
|
2022-02-15 15:01:45 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-12 03:24:24 -07:00
|
|
|
private void OnInit(EntityUid uid, CargoTelepadComponent telepad, ComponentInit args)
|
|
|
|
|
{
|
2023-05-07 08:07:24 +02:00
|
|
|
_linker.EnsureSinkPorts(uid, telepad.ReceiverPort);
|
2022-05-12 03:24:24 -07:00
|
|
|
}
|
|
|
|
|
|
2023-05-21 06:09:31 -04:00
|
|
|
private void SetEnabled(EntityUid uid, CargoTelepadComponent component, ApcPowerReceiverComponent? receiver = null,
|
2022-02-15 15:01:45 +11:00
|
|
|
TransformComponent? xform = null)
|
|
|
|
|
{
|
|
|
|
|
// False due to AllCompsOneEntity test where they may not have the powerreceiver.
|
2023-05-21 06:09:31 -04:00
|
|
|
if (!Resolve(uid, ref receiver, ref xform, false))
|
|
|
|
|
return;
|
2022-02-15 15:01:45 +11:00
|
|
|
|
|
|
|
|
var disabled = !receiver.Powered || !xform.Anchored;
|
|
|
|
|
|
|
|
|
|
// Setting idle state should be handled by Update();
|
2023-05-21 06:09:31 -04:00
|
|
|
if (disabled)
|
|
|
|
|
return;
|
2022-02-15 15:01:45 +11:00
|
|
|
|
2023-05-21 06:09:31 -04:00
|
|
|
TryComp<AppearanceComponent>(uid, out var appearance);
|
2022-02-15 15:01:45 +11:00
|
|
|
component.CurrentState = CargoTelepadState.Unpowered;
|
2023-05-21 06:09:31 -04:00
|
|
|
_appearance.SetData(uid, CargoTelepadVisuals.State, CargoTelepadState.Unpowered, appearance);
|
2022-02-15 15:01:45 +11:00
|
|
|
}
|
|
|
|
|
|
2022-10-15 15:08:15 +11:00
|
|
|
private void OnTelepadPowerChange(EntityUid uid, CargoTelepadComponent component, ref PowerChangedEvent args)
|
2022-02-15 15:01:45 +11:00
|
|
|
{
|
2023-05-21 06:09:31 -04:00
|
|
|
SetEnabled(uid, component);
|
2022-02-15 15:01:45 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnTelepadAnchorChange(EntityUid uid, CargoTelepadComponent component, ref AnchorStateChangedEvent args)
|
|
|
|
|
{
|
2023-05-21 06:09:31 -04:00
|
|
|
SetEnabled(uid, component);
|
2022-02-15 15:01:45 +11:00
|
|
|
}
|
|
|
|
|
}
|