@@ -1,6 +1,6 @@
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Content.Server.StationRecords;
|
||||
using Content.Shared.Delivery;
|
||||
using Content.Shared.Power.EntitySystems;
|
||||
using Content.Server.StationRecords;
|
||||
using Content.Shared.EntityTable;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
@@ -16,7 +16,7 @@ public sealed partial class DeliverySystem
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly EntityTableSystem _entityTable = default!;
|
||||
[Dependency] private readonly PowerReceiverSystem _power = default!;
|
||||
[Dependency] private readonly SharedPowerReceiverSystem _power = default!;
|
||||
|
||||
private void InitializeSpawning()
|
||||
{
|
||||
@@ -28,16 +28,14 @@ public sealed partial class DeliverySystem
|
||||
ent.Comp.NextDelivery = _timing.CurTime + ent.Comp.MinDeliveryCooldown; // We want an early wave of mail so cargo doesn't have to wait
|
||||
}
|
||||
|
||||
private void SpawnDelivery(Entity<DeliverySpawnerComponent?> ent, int amount)
|
||||
protected override void SpawnDeliveries(Entity<DeliverySpawnerComponent?> ent)
|
||||
{
|
||||
if (!Resolve(ent.Owner, ref ent.Comp))
|
||||
return;
|
||||
|
||||
var coords = Transform(ent).Coordinates;
|
||||
|
||||
_audio.PlayPvs(ent.Comp.SpawnSound, ent.Owner);
|
||||
|
||||
for (int i = 0; i < amount; i++)
|
||||
for (int i = 0; i < ent.Comp.ContainedDeliveryAmount; i++)
|
||||
{
|
||||
var spawns = _entityTable.GetSpawns(ent.Comp.Table);
|
||||
|
||||
@@ -46,9 +44,12 @@ public sealed partial class DeliverySystem
|
||||
Spawn(id, coords);
|
||||
}
|
||||
}
|
||||
|
||||
ent.Comp.ContainedDeliveryAmount = 0;
|
||||
Dirty(ent);
|
||||
}
|
||||
|
||||
private void SpawnStationDeliveries(Entity<CargoDeliveryDataComponent> ent)
|
||||
private void AdjustStationDeliveries(Entity<CargoDeliveryDataComponent> ent)
|
||||
{
|
||||
if (!TryComp<StationRecordsComponent>(ent, out var records))
|
||||
return;
|
||||
@@ -72,7 +73,7 @@ public sealed partial class DeliverySystem
|
||||
{
|
||||
foreach (var spawner in spawners)
|
||||
{
|
||||
SpawnDelivery(spawner, deliveryCount);
|
||||
AddDeliveriesToSpawner(spawner, deliveryCount);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -87,18 +88,18 @@ public sealed partial class DeliverySystem
|
||||
}
|
||||
for (int j = 0; j < spawners.Count; j++)
|
||||
{
|
||||
SpawnDelivery(spawners[j], amounts[j]);
|
||||
AddDeliveriesToSpawner(spawners[j], amounts[j]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private List<EntityUid> GetValidSpawners(Entity<CargoDeliveryDataComponent> ent)
|
||||
private List<Entity<DeliverySpawnerComponent>> GetValidSpawners(Entity<CargoDeliveryDataComponent> ent)
|
||||
{
|
||||
var validSpawners = new List<EntityUid>();
|
||||
var validSpawners = new List<Entity<DeliverySpawnerComponent>>();
|
||||
|
||||
var spawners = EntityQueryEnumerator<DeliverySpawnerComponent>();
|
||||
while (spawners.MoveNext(out var spawnerUid, out _))
|
||||
while (spawners.MoveNext(out var spawnerUid, out var spawnerComp))
|
||||
{
|
||||
var spawnerStation = _station.GetOwningStation(spawnerUid);
|
||||
|
||||
@@ -108,12 +109,23 @@ public sealed partial class DeliverySystem
|
||||
if (!_power.IsPowered(spawnerUid))
|
||||
continue;
|
||||
|
||||
validSpawners.Add(spawnerUid);
|
||||
if (spawnerComp.ContainedDeliveryAmount >= spawnerComp.MaxContainedDeliveryAmount)
|
||||
continue;
|
||||
|
||||
validSpawners.Add((spawnerUid, spawnerComp));
|
||||
}
|
||||
|
||||
return validSpawners;
|
||||
}
|
||||
|
||||
private void AddDeliveriesToSpawner(Entity<DeliverySpawnerComponent> ent, int amount)
|
||||
{
|
||||
ent.Comp.ContainedDeliveryAmount += Math.Clamp(amount, 0, ent.Comp.MaxContainedDeliveryAmount - ent.Comp.ContainedDeliveryAmount);
|
||||
_audio.PlayPvs(ent.Comp.SpawnSound, ent.Owner);
|
||||
UpdateDeliverySpawnerVisuals(ent, ent.Comp.ContainedDeliveryAmount);
|
||||
Dirty(ent);
|
||||
}
|
||||
|
||||
private void UpdateSpawner(float frameTime)
|
||||
{
|
||||
var dataQuery = EntityQueryEnumerator<CargoDeliveryDataComponent>();
|
||||
@@ -125,7 +137,7 @@ public sealed partial class DeliverySystem
|
||||
continue;
|
||||
|
||||
deliveryData.NextDelivery += _random.Next(deliveryData.MinDeliveryCooldown, deliveryData.MaxDeliveryCooldown); // Random cooldown between min and max
|
||||
SpawnStationDeliveries((uid, deliveryData));
|
||||
AdjustStationDeliveries((uid, deliveryData));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user