mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 13:37:47 +03:00
<!-- This is a semi-strict format, you can add/remove sections as needed but the order/format should be kept the same Remove these comments before submitting --> # Description <!-- Explain this PR in as much detail as applicable Some example prompts to consider: How might this affect the game? The codebase? What might be some alternatives to this? How/Who does this benefit/hurt [the game/codebase]? --> I forgot about it. --- # Changelog <!-- You can add an author after the `🆑` to change the name that appears in the changelog (ex: `🆑 Death`) Leaving it blank will default to your GitHub display name This includes all available types for the changelog --> 🆑 Aviu00 - fix: Fix silo being out of range. (cherry picked from commit 34c2bbca74b5a10d6a8466e728cc48b0acda5655)
85 lines
3.1 KiB
C#
85 lines
3.1 KiB
C#
using System.Linq;
|
|
using Content.Server.Lathe;
|
|
using Content.Server.Station.Components;
|
|
using Content.Shared.DeviceLinking;
|
|
using Content.Shared.Lathe;
|
|
using Content.Shared.Materials;
|
|
using Robust.Server.GameStates;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Server.Materials;
|
|
|
|
public sealed class MaterialSiloSystem : SharedMaterialSiloSystem
|
|
{
|
|
[Dependency] private readonly LatheSystem _lathe = default!;
|
|
[Dependency] private readonly PvsOverrideSystem _pvs = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<BecomesStationComponent, MapInitEvent>(OnMapInit);
|
|
SubscribeLocalEvent<MaterialSiloComponent, MaterialAmountChangedEvent>(OnMaterialAmountChanged);
|
|
SubscribeLocalEvent<MaterialSiloComponent, ComponentStartup>(OnStartup);
|
|
SubscribeLocalEvent<MaterialSiloComponent, ComponentShutdown>(OnShutdown);
|
|
}
|
|
|
|
private void OnMaterialAmountChanged(Entity<MaterialSiloComponent> ent, ref MaterialAmountChangedEvent args)
|
|
{
|
|
// Spawning a timer because SetUiState in UpdateUserInterfaceState is being networked before
|
|
// silo's MaterialStorageComponent state gets handled.
|
|
// That causes lathe ui recipe list to not update properly.
|
|
Timer.Spawn(20,
|
|
() =>
|
|
{
|
|
if (!TryComp(ent, out DeviceLinkSourceComponent? source))
|
|
return;
|
|
|
|
foreach (var utilizerSet in source.Outputs.Where(x => x.Key == SourcePort).Select(x => x.Value))
|
|
{
|
|
foreach (var utilizer in utilizerSet)
|
|
{
|
|
if (TryComp(utilizer, out LatheComponent? lathe))
|
|
_lathe.UpdateUserInterfaceState(utilizer, lathe);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
private void OnMapInit(Entity<BecomesStationComponent> ent, ref MapInitEvent args)
|
|
{
|
|
Entity<DeviceLinkSourceComponent>? silo = null;
|
|
var siloQuery = AllEntityQuery<MaterialSiloComponent, MaterialStorageComponent, TransformComponent, DeviceLinkSourceComponent>();
|
|
while (siloQuery.MoveNext(out var siloEnt, out _, out _, out var siloXform, out var source))
|
|
{
|
|
if (siloXform.GridUid != ent)
|
|
continue;
|
|
|
|
silo = (siloEnt, source);
|
|
break;
|
|
}
|
|
|
|
if (silo == null)
|
|
return;
|
|
|
|
var utilizerQuery = AllEntityQuery<MaterialSiloUtilizerComponent, MaterialStorageComponent, TransformComponent, DeviceLinkSinkComponent>();
|
|
while (utilizerQuery.MoveNext(out var utilizer, out _, out var storage, out var utilizerXform, out var sink))
|
|
{
|
|
if (utilizerXform.GridUid != ent)
|
|
continue;
|
|
|
|
DeviceLink.LinkDefaults(null, silo.Value, utilizer, silo.Value.Comp, sink);
|
|
}
|
|
}
|
|
|
|
private void OnStartup(Entity<MaterialSiloComponent> ent, ref ComponentStartup args)
|
|
{
|
|
_pvs.AddGlobalOverride(ent);
|
|
}
|
|
|
|
private void OnShutdown(Entity<MaterialSiloComponent> ent, ref ComponentShutdown args)
|
|
{
|
|
_pvs.RemoveGlobalOverride(ent);
|
|
}
|
|
}
|