Files
tbd-station-14/Content.Server/Delivery/DeliverySystem.cs
Nemanja 12b75beeab Departmental Economy (#36445)
* Cargo Accounts, Request Consoles, and lock boxes

* Funding Allocation Computer

* final changes

* test fix

* remove dumb code

* ScarKy0 review

* first cour

* second cour

* Update machines.yml

* review

---------

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>
Co-authored-by: Milon <milonpl.git@proton.me>
2025-04-13 15:22:36 +02:00

89 lines
2.9 KiB
C#

using Content.Server.Cargo.Systems;
using Content.Server.Station.Systems;
using Content.Server.StationRecords.Systems;
using Content.Shared.Cargo.Components;
using Content.Shared.Delivery;
using Content.Shared.FingerprintReader;
using Content.Shared.Labels.EntitySystems;
using Content.Shared.StationRecords;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
namespace Content.Server.Delivery;
/// <summary>
/// System for managing deliveries spawned by the mail teleporter.
/// This covers for mail spawning, as well as granting cargo money.
/// </summary>
public sealed partial class DeliverySystem : SharedDeliverySystem
{
[Dependency] private readonly CargoSystem _cargo = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly StationRecordsSystem _records = default!;
[Dependency] private readonly StationSystem _station = default!;
[Dependency] private readonly FingerprintReaderSystem _fingerprintReader = default!;
[Dependency] private readonly LabelSystem _label = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DeliveryComponent, MapInitEvent>(OnMapInit);
InitializeSpawning();
}
private void OnMapInit(Entity<DeliveryComponent> ent, ref MapInitEvent args)
{
_container.EnsureContainer<Container>(ent, ent.Comp.Container);
var stationId = _station.GetStationInMap(Transform(ent).MapID);
if (stationId == null)
return;
_records.TryGetRandomRecord<GeneralStationRecord>(stationId.Value, out var entry);
if (entry == null)
return;
ent.Comp.RecipientName = entry.Name;
ent.Comp.RecipientJobTitle = entry.JobTitle;
ent.Comp.RecipientStation = stationId.Value;
_appearance.SetData(ent, DeliveryVisuals.JobIcon, entry.JobIcon);
_label.Label(ent, ent.Comp.RecipientName);
if (TryComp<FingerprintReaderComponent>(ent, out var reader) && entry.Fingerprint != null)
{
_fingerprintReader.AddAllowedFingerprint((ent.Owner, reader), entry.Fingerprint);
}
Dirty(ent);
}
protected override void GrantSpesoReward(Entity<DeliveryComponent?> ent)
{
if (!Resolve(ent, ref ent.Comp))
return;
if (!TryComp<StationBankAccountComponent>(ent.Comp.RecipientStation, out var account))
return;
_cargo.UpdateBankAccount(
(ent.Comp.RecipientStation.Value, account),
ent.Comp.SpesoReward,
_cargo.CreateAccountDistribution(account.PrimaryAccount, account, account.PrimaryCut));
}
public override void Update(float frameTime)
{
base.Update(frameTime);
UpdateSpawner(frameTime);
}
}