fix cargo teleporter (#27255)
* fix cargo teleporter * don't delete orders * basado
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Cargo.Components;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Content.Server.Station.Components;
|
||||
using Content.Shared.Cargo;
|
||||
using Content.Shared.Cargo.Components;
|
||||
using Content.Shared.DeviceLinking;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Cargo.Systems;
|
||||
@@ -13,10 +17,44 @@ public sealed partial class CargoSystem
|
||||
private void InitializeTelepad()
|
||||
{
|
||||
SubscribeLocalEvent<CargoTelepadComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<CargoTelepadComponent, ComponentShutdown>(OnShutdown);
|
||||
SubscribeLocalEvent<CargoTelepadComponent, PowerChangedEvent>(OnTelepadPowerChange);
|
||||
// Shouldn't need re-anchored event
|
||||
SubscribeLocalEvent<CargoTelepadComponent, AnchorStateChangedEvent>(OnTelepadAnchorChange);
|
||||
SubscribeLocalEvent<FulfillCargoOrderEvent>(OnTelepadFulfillCargoOrder);
|
||||
}
|
||||
|
||||
private void OnTelepadFulfillCargoOrder(ref FulfillCargoOrderEvent args)
|
||||
{
|
||||
var query = EntityQueryEnumerator<CargoTelepadComponent, TransformComponent>();
|
||||
while (query.MoveNext(out var uid, out var tele, out var xform))
|
||||
{
|
||||
if (tele.CurrentState != CargoTelepadState.Idle)
|
||||
continue;
|
||||
|
||||
if (!this.IsPowered(uid, EntityManager))
|
||||
continue;
|
||||
|
||||
if (_station.GetOwningStation(uid, xform) != args.Station)
|
||||
continue;
|
||||
|
||||
// todo cannot be fucking asked to figure out device linking rn but this shouldn't just default to the first port.
|
||||
if (!TryComp<DeviceLinkSinkComponent>(uid, out var sinkComponent) ||
|
||||
sinkComponent.LinkedSources.FirstOrNull() is not { } console ||
|
||||
console != args.OrderConsole.Owner)
|
||||
continue;
|
||||
|
||||
for (var i = 0; i < args.Order.OrderQuantity; i++)
|
||||
{
|
||||
tele.CurrentOrders.Add(args.Order);
|
||||
}
|
||||
tele.Accumulator = tele.Delay;
|
||||
args.Handled = true;
|
||||
args.FulfillmentEntity = uid;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateTelepad(float frameTime)
|
||||
{
|
||||
var query = EntityQueryEnumerator<CargoTelepadComponent>();
|
||||
@@ -33,14 +71,6 @@ public sealed partial class CargoSystem
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!TryComp<DeviceLinkSinkComponent>(uid, out var sinkComponent) ||
|
||||
sinkComponent.LinkedSources.FirstOrNull() is not { } console ||
|
||||
!HasComp<CargoOrderConsoleComponent>(console))
|
||||
{
|
||||
comp.Accumulator = comp.Delay;
|
||||
continue;
|
||||
}
|
||||
|
||||
comp.Accumulator -= frameTime;
|
||||
|
||||
// Uhh listen teleporting takes time and I just want the 1 float.
|
||||
@@ -51,21 +81,22 @@ public sealed partial class CargoSystem
|
||||
continue;
|
||||
}
|
||||
|
||||
var station = _station.GetOwningStation(console);
|
||||
|
||||
if (!TryComp<StationCargoOrderDatabaseComponent>(station, out var orderDatabase) ||
|
||||
orderDatabase.Orders.Count == 0)
|
||||
if (comp.CurrentOrders.Count == 0)
|
||||
{
|
||||
comp.Accumulator += comp.Delay;
|
||||
continue;
|
||||
}
|
||||
|
||||
var xform = Transform(uid);
|
||||
if (FulfillNextOrder(orderDatabase, xform.Coordinates, comp.PrinterOutput))
|
||||
var currentOrder = comp.CurrentOrders.First();
|
||||
if (FulfillOrder(currentOrder, xform.Coordinates, comp.PrinterOutput))
|
||||
{
|
||||
_audio.PlayPvs(_audio.GetSound(comp.TeleportSound), uid, AudioParams.Default.WithVolume(-8f));
|
||||
UpdateOrders(station.Value, orderDatabase);
|
||||
|
||||
if (_station.GetOwningStation(uid) is { } station)
|
||||
UpdateOrders(station);
|
||||
|
||||
comp.CurrentOrders.Remove(currentOrder);
|
||||
comp.CurrentState = CargoTelepadState.Teleporting;
|
||||
_appearance.SetData(uid, CargoTelepadVisuals.State, CargoTelepadState.Teleporting, appearance);
|
||||
}
|
||||
@@ -79,6 +110,29 @@ public sealed partial class CargoSystem
|
||||
_linker.EnsureSinkPorts(uid, telepad.ReceiverPort);
|
||||
}
|
||||
|
||||
private void OnShutdown(Entity<CargoTelepadComponent> ent, ref ComponentShutdown args)
|
||||
{
|
||||
if (ent.Comp.CurrentOrders.Count == 0)
|
||||
return;
|
||||
|
||||
if (_station.GetStations().Count == 0)
|
||||
return;
|
||||
|
||||
if (_station.GetOwningStation(ent) is not { } station)
|
||||
{
|
||||
station = _random.Pick(_station.GetStations().Where(HasComp<StationCargoOrderDatabaseComponent>).ToList());
|
||||
}
|
||||
|
||||
if (!TryComp<StationCargoOrderDatabaseComponent>(station, out var db) ||
|
||||
!TryComp<StationDataComponent>(station, out var data))
|
||||
return;
|
||||
|
||||
foreach (var order in ent.Comp.CurrentOrders)
|
||||
{
|
||||
TryFulfillOrder((station, data), order, db);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetEnabled(EntityUid uid, CargoTelepadComponent component, ApcPowerReceiverComponent? receiver = null,
|
||||
TransformComponent? xform = null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user