mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* Scope creep my ass * why was this shit not pushed???? * gone... * fix that * review plus buildd * asfsafsafsafsafas * grug * burber * I'll fix this later * shrimply die * also this * it's snerf or snuthin * assaads * round snend * aaaa * fix this shit for real * actually, don't start GameRules until MapInit now that I think aboot it. * forgot u * don't actually need this part nullable * Deffer comp removal * one liner * do that too * chungus * Honestly makes more sense here, plus WHY are we doing all that shit on "GameRuleAdded" rather than GameRuleStarted(?) * deferred removal :V * aaaaaaaaaaaaaaa * whhop * Whoop * better * landmine that I placed for myself then forgot about lmao * cleanup * FUCKING `!` * gotovo * amogus * please don't check by metadata I beg * waawsasfdfsasfa * sfafsasfafsas * fdsaasffsasfa * code * fix * fasasffasfasfsad * chungaas * I may be stupid * gra * graaaaaaaaaaaaaaaaa * comment * gra * clearing is not predicted and would require major refactors, so don't cache on client. * lame shit :P * last holes * nukeopsfsafsasafsfafsa * why was that shit public bruh * bubrbgwahrghfaka * dynamic * revert change that did nothing lmao
144 lines
5.2 KiB
C#
144 lines
5.2 KiB
C#
using Content.Server.Cargo.Systems;
|
|
using Content.Server.Chat.Systems;
|
|
using Content.Server.Station.Systems;
|
|
using Content.Shared.Cargo.Components;
|
|
using Content.Shared.Cargo.Prototypes;
|
|
using Content.Shared.Chat;
|
|
using Content.Shared.Delivery;
|
|
using Content.Shared.FingerprintReader;
|
|
using Content.Shared.Labels.EntitySystems;
|
|
using Content.Shared.StationRecords;
|
|
using Content.Shared.StationRecords.Systems;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.Containers;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
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 CargoSystem _cargo = default!;
|
|
[Dependency] private SharedAppearanceSystem _appearance = default!;
|
|
[Dependency] private SharedAudioSystem _audio = default!;
|
|
[Dependency] private StationRecordsSystem _records = default!;
|
|
[Dependency] private ServerStationSystem _station = default!;
|
|
[Dependency] private FingerprintReaderSystem _fingerprintReader = default!;
|
|
[Dependency] private LabelSystem _label = default!;
|
|
[Dependency] private SharedContainerSystem _container = default!;
|
|
[Dependency] private ChatSystem _chat = default!;
|
|
|
|
/// <summary>
|
|
/// Default reason to use if the penalization is triggered
|
|
/// </summary>
|
|
private static readonly LocId DefaultMessage = "delivery-penalty-default-reason";
|
|
|
|
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);
|
|
|
|
if (_station.GetStationInMap(Transform(ent).MapID) is not { } stationId)
|
|
return;
|
|
|
|
if (!_records.TryGetRandomRecord<GeneralStationRecord>(stationId, out var entry, seedEntity: ent))
|
|
return;
|
|
|
|
ent.Comp.RecipientName = entry.Name;
|
|
ent.Comp.RecipientJobTitle = entry.JobTitle;
|
|
ent.Comp.RecipientStation = stationId;
|
|
|
|
_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;
|
|
|
|
var stationAccountEnt = (ent.Comp.RecipientStation.Value, account);
|
|
|
|
var multiplier = GetDeliveryMultiplier(ent!); // Resolve so we know it's got the component
|
|
|
|
_cargo.UpdateBankAccount(
|
|
stationAccountEnt,
|
|
(int)(ent.Comp.BaseSpesoReward * multiplier),
|
|
_cargo.CreateAccountDistribution((ent.Comp.RecipientStation.Value, account)));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Runs the penalty logic: Announcing the penalty and calculating how much to charge the designated account
|
|
/// </summary>
|
|
/// <param name="ent">The delivery for which to run the penalty.</param>
|
|
/// <param name="reason">The penalty reason, displayed in front of the message.</param>
|
|
protected override void HandlePenalty(Entity<DeliveryComponent> ent, string? reason = null)
|
|
{
|
|
if (!TryComp<StationBankAccountComponent>(ent.Comp.RecipientStation, out var stationAccount))
|
|
return;
|
|
|
|
if (ent.Comp.WasPenalized)
|
|
return;
|
|
|
|
if (!ProtoMan.Resolve(ent.Comp.PenaltyBankAccount, out var accountInfo))
|
|
return;
|
|
|
|
var multiplier = GetDeliveryMultiplier(ent);
|
|
|
|
var localizedAccountName = Loc.GetString(accountInfo.Name);
|
|
|
|
reason ??= Loc.GetString(DefaultMessage);
|
|
|
|
var dist = new Dictionary<ProtoId<CargoAccountPrototype>, double>()
|
|
{
|
|
{ ent.Comp.PenaltyBankAccount, 1.0 }
|
|
};
|
|
|
|
var penaltyAccountBalance = stationAccount.Accounts[ent.Comp.PenaltyBankAccount];
|
|
var calculatedPenalty = (int)(ent.Comp.BaseSpesoPenalty * multiplier);
|
|
|
|
// Prevents cargo from going into negatives
|
|
if (calculatedPenalty > penaltyAccountBalance )
|
|
calculatedPenalty = Math.Max(0, penaltyAccountBalance);
|
|
|
|
_cargo.UpdateBankAccount(
|
|
(ent.Comp.RecipientStation.Value, stationAccount),
|
|
-calculatedPenalty,
|
|
dist);
|
|
|
|
var message = Loc.GetString("delivery-penalty-message", ("reason", reason), ("spesos", calculatedPenalty), ("account", localizedAccountName.ToUpper()));
|
|
_chat.TrySendInGameICMessage(ent, message, InGameICChatType.Speak, hideChat: true);
|
|
|
|
ent.Comp.WasPenalized = true;
|
|
DirtyField(ent.Owner, ent.Comp, nameof(DeliveryComponent.WasPenalized));
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
|
|
UpdateSpawner(frameTime);
|
|
}
|
|
}
|