Skip to content

Commit

Permalink
DEAR GOD
Browse files Browse the repository at this point in the history
  • Loading branch information
MilonPL committed Oct 28, 2024
1 parent 905d686 commit 02b8ca5
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 253 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Runtime.CompilerServices;
using Content.Shared.CartridgeLoader.Cartridges;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
Expand Down
1 change: 0 additions & 1 deletion Content.Client/Nyanotrasen/Mail/MailSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public sealed class MailJobVisualizerSystem : VisualizerSystem<MailComponent>
{
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly SpriteSystem _stateManager = default!;
[Dependency] private readonly SpriteSystem _spriteSystem = default!;

protected override void OnAppearanceChange(EntityUid uid, MailComponent component, ref AppearanceChangeEvent args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ public sealed partial class MailComponent : SharedMailComponent
/// </summary>
public bool IsEnabled = true;

public CancellationTokenSource? priorityCancelToken;
public CancellationTokenSource? PriorityCancelToken;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ public sealed partial class MailTeleporterComponent : Component
{

// Not starting accumulator at 0 so mail carriers have some deliveries to make shortly after roundstart.
[DataField("accumulator")]
[DataField]
public float Accumulator = 285f;

[DataField("teleportInterval")]
[DataField]
public TimeSpan TeleportInterval = TimeSpan.FromMinutes(5);

/// <summary>
/// The sound that's played when new mail arrives.
/// </summary>
[DataField("teleportSound")]
[DataField]
public SoundSpecifier TeleportSound = new SoundPathSpecifier("/Audio/Effects/teleport_arrival.ogg");

/// <summary>
Expand All @@ -36,10 +36,10 @@ public sealed partial class MailTeleporterComponent : Component
/// to determine how many deliveries will be teleported in.
/// It does not determine unique recipients. That is random.
/// </summary>
[DataField("candidatesPerDelivery")]
[DataField]
public int CandidatesPerDelivery = 8;

[DataField("minimumDeliveriesPerTeleport")]
[DataField]
public int MinimumDeliveriesPerTeleport = 1;

/// <summary>
Expand All @@ -58,45 +58,45 @@ public sealed partial class MailTeleporterComponent : Component
/// This is just a simple check to see if anyone's been picking up the
/// mail lately to prevent entity bloat for the sake of performance.
/// </remarks>
[DataField("maximumUndeliveredParcels")]
[DataField]
public int MaximumUndeliveredParcels = 5;

/// <summary>
/// Any item that breaks or is destroyed in less than this amount of
/// damage is one of the types of items considered fragile.
/// </summary>
[DataField("fragileDamageThreshold")]
[DataField]
public int FragileDamageThreshold = 10;

/// <summary>
/// What's the bonus for delivering a fragile package intact?
/// </summary>
[DataField("fragileBonus")]
[DataField]
public int FragileBonus = 100;

/// <summary>
/// What's the malus for failing to deliver a fragile package?
/// </summary>
[DataField("fragileMalus")]
[DataField]
public int FragileMalus = -100;

/// <summary>
/// What's the chance for any one delivery to be marked as priority mail?
/// </summary>
[DataField("priorityChance")]
[DataField]
public float PriorityChance = 0.1f;

/// <summary>
/// How long until a priority delivery is considered as having failed
/// if not delivered?
/// </summary>
[DataField("priorityDuration")]
public TimeSpan priorityDuration = TimeSpan.FromMinutes(5);
[DataField]
public TimeSpan PriorityDuration = TimeSpan.FromMinutes(5);

/// <summary>
/// What's the bonus for delivering a priority package on time?
/// </summary>
[DataField("priorityBonus")]
[DataField]
public int PriorityBonus = 250;

/// <summary>
Expand All @@ -110,13 +110,13 @@ public sealed partial class MailTeleporterComponent : Component
/// What's the bonus for delivering a large package intact?
/// </summary>
[DataField]
public int LargeBonus = 1500; //DeltaV; 5000 to 1500
public int LargeBonus = 1500; // DeltaV; 5000 to 1500

/// <summary>
/// What's the malus for failing to deliver a large package?
/// </summary>
[DataField]
public int LargeMalus = -500; //DeltaV; -250 to -500
public int LargeMalus = -500; // DeltaV; -250 to -500
// End Frontier: Large mail
}
}
52 changes: 26 additions & 26 deletions Content.Server/Nyanotrasen/Mail/MailCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public sealed class MailToCommand : IConsoleCommand
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;

private readonly string _blankMailPrototype = "MailAdminFun";
private readonly string _blankLargeMailPrototype = "MailLargeAdminFun"; // Frontier: large mail
private readonly string _container = "storagebase";
private readonly string _mailContainer = "contents";
private const string BlankMailPrototype = "MailAdminFun";
private const string BlankLargeMailPrototype = "MailLargeAdminFun"; // Frontier: large mail
private const string Container = "storagebase";
private const string MailContainer = "contents";


public async void Execute(IConsoleShell shell, string argStr, string[] args)
Expand All @@ -45,82 +45,85 @@ public async void Execute(IConsoleShell shell, string argStr, string[] args)
return;
}

if (!Boolean.TryParse(args[2], out var isFragile))
if (!bool.TryParse(args[2], out var isFragile))
{
shell.WriteError(Loc.GetString("shell-invalid-bool"));
return;
}

if (!Boolean.TryParse(args[3], out var isPriority))
if (!bool.TryParse(args[3], out var isPriority))
{
shell.WriteError(Loc.GetString("shell-invalid-bool"));
return;
}

// Frontier: Large Mail
bool isLarge = false;
if (args.Length > 4 && !Boolean.TryParse(args[4], out isLarge))
var isLarge = false;
if (args.Length > 4 && !bool.TryParse(args[4], out isLarge))
{
shell.WriteError(Loc.GetString("shell-invalid-bool"));
return;
}
var mailPrototype = isLarge ? _blankLargeMailPrototype : _blankMailPrototype;
var mailPrototype = isLarge ? BlankLargeMailPrototype : BlankMailPrototype;
// End Frontier


var _mailSystem = _entitySystemManager.GetEntitySystem<MailSystem>();
var _containerSystem = _entitySystemManager.GetEntitySystem<SharedContainerSystem>();
var mailSystem = _entitySystemManager.GetEntitySystem<MailSystem>();
var containerSystem = _entitySystemManager.GetEntitySystem<SharedContainerSystem>();

if (!_entityManager.TryGetComponent(recipientUid, out MailReceiverComponent? mailReceiver))
if (!_entityManager.HasComponent<MailReceiverComponent>(recipientUid))
{
shell.WriteLine(Loc.GetString("command-mailto-no-mailreceiver", ("requiredComponent", nameof(MailReceiverComponent))));
return;
}

if (!_prototypeManager.HasIndex<EntityPrototype>(mailPrototype)) // Frontier: _blankMailPrototype<mailPrototype
{
shell.WriteLine(Loc.GetString("command-mailto-no-blankmail", ("blankMail", mailPrototype))); // Frontier: _blankMailPrototype<mailPrototype
shell.WriteLine(Loc.GetString("command-mailto-no-blankmail", ("blankMail", mailPrototype))); // Frontier: _blankMailPrototype<mailPrototype
return;
}

if (!_containerSystem.TryGetContainer(containerUid, _container, out var targetContainer))
if (!containerSystem.TryGetContainer(containerUid, Container, out var targetContainer))
{
shell.WriteLine(Loc.GetString("command-mailto-invalid-container", ("requiredContainer", _container)));
shell.WriteLine(Loc.GetString("command-mailto-invalid-container", ("requiredContainer", Container)));
return;
}

if (!_mailSystem.TryGetMailRecipientForReceiver(mailReceiver, out MailRecipient? recipient))
if (!mailSystem.TryGetMailRecipientForReceiver(recipientUid, out var recipient))
{
shell.WriteLine(Loc.GetString("command-mailto-unable-to-receive"));
return;
}

if (!_mailSystem.TryGetMailTeleporterForReceiver(mailReceiver, out MailTeleporterComponent? teleporterComponent))
if (!mailSystem.TryGetMailTeleporterForReceiver(recipientUid, out var teleporterComponent, out var teleporterUid))
{
shell.WriteLine(Loc.GetString("command-mailto-no-teleporter-found"));
return;
}

var coordinates = _entityManager.GetComponent<TransformComponent>(containerUid).Coordinates;
var mailUid = _entityManager.SpawnEntity(mailPrototype, _entityManager.GetComponent<TransformComponent>(containerUid).Coordinates); // Frontier: _blankMailPrototype<mailPrototype
var mailContents = _containerSystem.EnsureContainer<Container>(mailUid, _mailContainer);
var mailContents = containerSystem.EnsureContainer<Container>(mailUid, MailContainer);

if (!_entityManager.TryGetComponent(mailUid, out MailComponent? mailComponent))
if (!_entityManager.TryGetComponent<MailComponent>(mailUid, out var mailComponent))
{
shell.WriteLine(Loc.GetString("command-mailto-bogus-mail", ("blankMail", mailPrototype), ("requiredMailComponent", nameof(MailComponent)))); // Frontier: _blankMailPrototype<mailPrototype
return;
}

foreach (var entity in targetContainer.ContainedEntities.ToArray())
_containerSystem.Insert(entity, mailContents);
{
containerSystem.Insert(entity, mailContents);
}

mailComponent.IsFragile = isFragile;
mailComponent.IsPriority = isPriority;
mailComponent.IsLarge = isLarge; //Frontier Mail

_mailSystem.SetupMail(mailUid, teleporterComponent, recipient.Value);
mailSystem.SetupMail(mailUid, teleporterComponent, recipient.Value);

var teleporterQueue = _containerSystem.EnsureContainer<Container>(teleporterComponent.Owner, "queued");
_containerSystem.Insert(mailUid, teleporterQueue);
var teleporterQueue = containerSystem.EnsureContainer<Container>((EntityUid)teleporterUid, "queued");
containerSystem.Insert(mailUid, teleporterQueue);
shell.WriteLine(Loc.GetString("command-mailto-success", ("timeToTeleport", teleporterComponent.TeleportInterval.TotalSeconds - teleporterComponent.Accumulator)));
}
}
Expand All @@ -133,12 +136,9 @@ public sealed class MailNowCommand : IConsoleCommand
public string Help => Loc.GetString("command-mailnow-help", ("command", Command));

[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;

public async void Execute(IConsoleShell shell, string argStr, string[] args)
{
var _mailSystem = _entitySystemManager.GetEntitySystem<MailSystem>();

foreach (var mailTeleporter in _entityManager.EntityQuery<MailTeleporterComponent>())
{
mailTeleporter.Accumulator += (float) mailTeleporter.TeleportInterval.TotalSeconds - mailTeleporter.Accumulator;
Expand Down
Loading

0 comments on commit 02b8ca5

Please sign in to comment.