Files
wwdpublic/Content.Server/Mail/MailCommands.cs
Mnemotechnican b254b8505c Feat: Port All Delta-V Mail Improvements (#1011)
# Description
Showing some love to our hard-working couriers.

This cherry-picks the following PRs from delta-v:
- https://github.com/DeltaV-Station/Delta-v/pull/1472 - Adds a
MailMetrics PDA cartridge for couriers and the LO
- https://github.com/DeltaV-Station/Delta-v/pull/1652 - Ports mail
tweaks from frontier to delta-v, adding large packages, RPDs (mail
cannons), and more mail
- https://github.com/DeltaV-Station/Delta-v/pull/1788 - Adding a couple
more packages
- https://github.com/DeltaV-Station/Delta-v/pull/1925 - Fixing the
non-functional "last known location" part of mail descriptions

Some mail items, such as the opporozidone syringe and rainbow
joints/blunts, had to be disabled because we don't have them (yet?)

<details><summary><h1>Media</h1></summary>
<p>

![image](https://github.com/user-attachments/assets/2299ffc3-17ce-4743-886c-7705e8789e96)

![image](https://github.com/user-attachments/assets/a2ee1a07-d765-41e7-8f70-f94a50412398)

![image](https://github.com/user-attachments/assets/03b16b8e-0eff-4332-99ad-d4a201ee8f2b)

![image](https://github.com/user-attachments/assets/44d2e5c2-db79-4d8d-8877-693648edd35d)

![image](https://github.com/user-attachments/assets/f3d7bdbb-fc14-4f2f-bf30-aa54fdf49099)

![image](https://github.com/user-attachments/assets/b1e4c53f-c9d8-496b-a72e-f4f4b702e368)

</p>
</details>

---

# Changelog
🆑
- add: The Courier and Logistics Officer now have a new program in their
PDA for tracking mail delivery performance, including earnings and
percent of packages opened, damaged, or expired.
- add: The list of possible mail packages has been greately expanded,
and now includes large parcels.
- add: The CourierDrobe now offers a rapid mail delivery device, along
with capsules for it.

---------

Signed-off-by: Adeinitas <147965189+adeinitas@users.noreply.github.com>
Co-authored-by: portfiend <109661617+portfiend@users.noreply.github.com>
Co-authored-by: byte <50130120+huckleton@users.noreply.github.com>
Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com>
Co-authored-by: Adeinitas <147965189+adeinitas@users.noreply.github.com>
Co-authored-by: ErhardSteinhauer <65374927+ErhardSteinhauer@users.noreply.github.com>
Co-authored-by: Dvir <dvirf01@gmail.com>
Co-authored-by: Dvir <39403717+dvir001@users.noreply.github.com>
Co-authored-by: Whatstone <166147148+whatston3@users.noreply.github.com>
Co-authored-by: Whatstone <whatstone3@gmail.com>
Co-authored-by: Danger Revolution! <142105406+DangerRevolution@users.noreply.github.com>
Co-authored-by: Milon <plmilonpl@gmail.com>
# Conflicts:
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Launchers/launchers.yml
2024-10-19 13:49:46 +07:00

143 lines
5.7 KiB
C#

using System.Linq;
using Robust.Shared.Console;
using Robust.Shared.Containers;
using Robust.Shared.Prototypes;
using Content.Shared.Administration;
using Content.Server.Administration;
using Content.Server.Mail.Components;
using Content.Server.Mail.Systems;
namespace Content.Server.Mail;
[AdminCommand(AdminFlags.Fun)]
public sealed class MailToCommand : IConsoleCommand
{
public string Command => "mailto";
public string Description => Loc.GetString("command-mailto-description", ("requiredComponent", nameof(MailReceiverComponent)));
public string Help => Loc.GetString("command-mailto-help", ("command", Command));
[Dependency] private readonly IEntityManager _entityManager = default!;
[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";
public async void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length < 4)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return;
}
if (!EntityUid.TryParse(args[0], out var recipientUid))
{
shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number"));
return;
}
if (!EntityUid.TryParse(args[1], out var containerUid))
{
shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number"));
return;
}
if (!bool.TryParse(args[2], out var isFragile) || !bool.TryParse(args[3], out var isPriority))
{
shell.WriteError(Loc.GetString("shell-invalid-bool"));
return;
}
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 mailSystem = _entitySystemManager.GetEntitySystem<MailSystem>();
var containerSystem = _entitySystemManager.GetEntitySystem<SharedContainerSystem>();
if (!_entityManager.TryGetComponent(recipientUid, out MailReceiverComponent? mailReceiver))
{
shell.WriteLine(Loc.GetString("command-mailto-no-mailreceiver", ("requiredComponent", nameof(MailReceiverComponent))));
return;
}
if (!_prototypeManager.HasIndex<EntityPrototype>(mailPrototype))
{
shell.WriteLine(Loc.GetString("command-mailto-no-blankmail", ("blankMail", mailPrototype)));
return;
}
if (!containerSystem.TryGetContainer(containerUid, _container, out var targetContainer))
{
shell.WriteLine(Loc.GetString("command-mailto-invalid-container", ("requiredContainer", _container)));
return;
}
if (!mailSystem.TryGetMailRecipientForReceiver(mailReceiver, out MailRecipient? recipient))
{
shell.WriteLine(Loc.GetString("command-mailto-unable-to-receive"));
return;
}
if (!mailSystem.TryGetMailTeleporterForReceiver(mailReceiver, out MailTeleporterComponent? teleporterComponent))
{
shell.WriteLine(Loc.GetString("command-mailto-no-teleporter-found"));
return;
}
var mailUid = _entityManager.SpawnEntity(mailPrototype, _entityManager.GetComponent<TransformComponent>(containerUid).Coordinates);
var mailContents = containerSystem.EnsureContainer<Container>(mailUid, _mailContainer);
if (!_entityManager.TryGetComponent(mailUid, out MailComponent? mailComponent))
{
shell.WriteLine(Loc.GetString("command-mailto-bogus-mail", ("blankMail", mailPrototype), ("requiredMailComponent", nameof(MailComponent))));
return;
}
foreach (var entity in targetContainer.ContainedEntities.ToArray())
containerSystem.Insert(entity, mailContents);
mailComponent.IsFragile = isFragile;
mailComponent.IsPriority = isPriority;
mailComponent.IsLarge = isLarge;
mailSystem.SetupMail(mailUid, teleporterComponent, recipient.Value);
var teleporterQueue = containerSystem.EnsureContainer<Container>(teleporterComponent.Owner, "queued");
containerSystem.Insert(mailUid, teleporterQueue);
shell.WriteLine(Loc.GetString("command-mailto-success", ("timeToTeleport", teleporterComponent.TeleportInterval.TotalSeconds - teleporterComponent.Accumulator)));
}
}
[AdminCommand(AdminFlags.Fun)]
public sealed class MailNowCommand : IConsoleCommand
{
public string Command => "mailnow";
public string Description => Loc.GetString("command-mailnow");
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 entitySystem = _entitySystemManager.GetEntitySystem<MailSystem>();
foreach (var mailTeleporter in _entityManager.EntityQuery<MailTeleporterComponent>())
{
mailTeleporter.Accumulator += (float) mailTeleporter.TeleportInterval.TotalSeconds - mailTeleporter.Accumulator;
}
shell.WriteLine(Loc.GetString("command-mailnow-success"));
}
}