* shitcode init * biocoding, SpawnTableOnUse, Moving shit to shared * server :( * fixes * ok works * Discard changes to Content.Shared/Interaction/Events/GettingUsedAttemptEvent.cs * Discard changes to Content.Shared/Forensics/Components/FingerprintMaskComponent.cs * Discard changes to Content.Shared/Forensics/Components/FingerprintComponent.cs * Discard changes to Content.Server/Forensics/Systems/ForensicsSystem.cs * Discard changes to Content.Server/StationRecords/Systems/StationRecordsSystem.cs * Discard changes to Content.Server/Storage/EntitySystems/SpawnItemsOnUseSystem.cs * Discard changes to Content.Shared/Interaction/Events/GettingUsedAttemptEvent.cs * big stuff * preperation * temperory spawning thing for testing * Update CargoDeliveryDataComponent.cs * kinda proper spawning idk god save me * cleanup (kinda) * preparation 2.0 * stuff i think * entity table work * renames * spawn ratio based on players * comment * letter tables * more spam * package tables * comment * biocodedn't * builds correctly * cleaning * Update deliveries_tables.yml * labels * package sprites * mail teleporter * revert testing value * fix test * fix other test * i love tests * mail teleporter enabled by default * random cooldowns * fixtures * Discard changes to Content.Shared/FingerprintReader/FingerprintReaderComponent.cs * Discard changes to Content.Shared/FingerprintReader/FingerprintReaderSystem.cs * Discard changes to Content.Shared/Interaction/Events/GettingUsedAttemptEvent.cs * Discard changes to Resources/Locale/en-US/fingerprint-reader/fingerprint-reader.ftl * clean * fuck paper scrap * oops * fuck SpawnTableOnUse * mail teleporter board in QM locker + addressed review * oops * clean * sound on delivery spawn * address review * partial review address * partial review addressing * addressing partial review * pratarial revivew address * misprediction hell * stuff * more stuff * unrelated * TODO * link * partial review * DirtyField --------- Co-authored-by: Milon <milonpl.git@proton.me>
127 lines
4.0 KiB
C#
127 lines
4.0 KiB
C#
using Content.Server.Power.EntitySystems;
|
|
using Content.Server.StationRecords;
|
|
using Content.Shared.Delivery;
|
|
using Content.Shared.EntityTable;
|
|
using Robust.Shared.Random;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Server.Delivery;
|
|
|
|
/// <summary>
|
|
/// System for managing deliveries spawned by the mail teleporter.
|
|
/// This covers for spawning deliveries.
|
|
/// </summary>
|
|
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!;
|
|
|
|
private void InitializeSpawning()
|
|
{
|
|
SubscribeLocalEvent<CargoDeliveryDataComponent, MapInitEvent>(OnDataMapInit);
|
|
}
|
|
|
|
private void OnDataMapInit(Entity<CargoDeliveryDataComponent> ent, ref MapInitEvent args)
|
|
{
|
|
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)
|
|
{
|
|
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++)
|
|
{
|
|
var spawns = _entityTable.GetSpawns(ent.Comp.Table);
|
|
|
|
foreach (var id in spawns)
|
|
{
|
|
Spawn(id, coords);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void SpawnStationDeliveries(Entity<CargoDeliveryDataComponent> ent)
|
|
{
|
|
if (!TryComp<StationRecordsComponent>(ent, out var records))
|
|
return;
|
|
|
|
var spawners = GetValidSpawners(ent);
|
|
|
|
// Skip if theres no spawners available
|
|
if (spawners.Count == 0)
|
|
return;
|
|
|
|
// We take the amount of mail calculated based on player amount or the minimum, whichever is higher.
|
|
// We don't want stations with less than the player ratio to not get mail at all
|
|
var deliveryCount = Math.Max(records.Records.Keys.Count / ent.Comp.PlayerToDeliveryRatio, ent.Comp.MinimumDeliverySpawn);
|
|
|
|
if (!ent.Comp.DistributeRandomly)
|
|
{
|
|
foreach (var spawner in spawners)
|
|
{
|
|
SpawnDelivery(spawner, deliveryCount);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
int[] amounts = new int[spawners.Count];
|
|
|
|
// Distribute items randomly
|
|
for (int i = 0; i < deliveryCount; i++)
|
|
{
|
|
var randomListIndex = _random.Next(spawners.Count);
|
|
amounts[randomListIndex]++;
|
|
}
|
|
for (int j = 0; j < spawners.Count; j++)
|
|
{
|
|
SpawnDelivery(spawners[j], amounts[j]);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private List<EntityUid> GetValidSpawners(Entity<CargoDeliveryDataComponent> ent)
|
|
{
|
|
var validSpawners = new List<EntityUid>();
|
|
|
|
var spawners = EntityQueryEnumerator<DeliverySpawnerComponent>();
|
|
while (spawners.MoveNext(out var spawnerUid, out _))
|
|
{
|
|
var spawnerStation = _station.GetOwningStation(spawnerUid);
|
|
|
|
if (spawnerStation != ent.Owner)
|
|
continue;
|
|
|
|
if (!_power.IsPowered(spawnerUid))
|
|
continue;
|
|
|
|
validSpawners.Add(spawnerUid);
|
|
}
|
|
|
|
return validSpawners;
|
|
}
|
|
|
|
private void UpdateSpawner(float frameTime)
|
|
{
|
|
var dataQuery = EntityQueryEnumerator<CargoDeliveryDataComponent>();
|
|
var curTime = _timing.CurTime;
|
|
|
|
while (dataQuery.MoveNext(out var uid, out var deliveryData))
|
|
{
|
|
if (deliveryData.NextDelivery > curTime)
|
|
continue;
|
|
|
|
deliveryData.NextDelivery += _random.Next(deliveryData.MinDeliveryCooldown, deliveryData.MaxDeliveryCooldown); // Random cooldown between min and max
|
|
SpawnStationDeliveries((uid, deliveryData));
|
|
}
|
|
}
|
|
}
|