Cargo: pizza & bureaucracy (#5123)

* add paper label component

* git mv

* rename namespace

* add cargo printouts

* more crates

* directly attach paper

* comment typo
This commit is contained in:
Leon Friedrich
2021-11-11 02:15:23 +13:00
committed by GitHub
parent b8d8f48b11
commit 88df3d8b10
33 changed files with 384 additions and 162 deletions

View File

@@ -1,9 +1,12 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Content.Server.Access.Components;
using Content.Server.Access.Systems;
using Content.Server.Cargo.Components;
using Content.Shared.Cargo;
using Content.Shared.GameTicking;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.Cargo
{
@@ -43,6 +46,9 @@ namespace Content.Server.Cargo
public CargoOrderDatabase StationOrderDatabase => GetOrderDatabase(0);
[Dependency] private readonly IdCardSystem _idCardSystem = default!;
[Dependency] private readonly AccessReaderSystem _accessReaderSystem = default!;
public override void Initialize()
{
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
@@ -171,12 +177,25 @@ namespace Content.Server.Cargo
return true;
}
public bool ApproveOrder(int id, int orderNumber)
public bool ApproveOrder(EntityUid uid, EntityUid approver, int id, int orderNumber, AccessReader? reader = null)
{
// does the approver have permission to approve orders?
if (Resolve(uid, ref reader) && !_accessReaderSystem.IsAllowed(reader, approver))
return false;
// get the approver's name
_idCardSystem.TryFindIdCard(approver, out var idCard);
var approverName = idCard?.FullName ?? string.Empty;
if (!TryGetOrderDatabase(id, out var database))
return false;
if (!database.ApproveOrder(orderNumber))
if (!database.TryGetOrder(orderNumber, out var order))
return false;
if (!database.ApproveOrder(approverName, orderNumber))
return false;
SyncComponentsWithId(id);
return true;
}

View File

@@ -1,7 +1,9 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Server.Access.Systems;
using Content.Shared.Cargo;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
namespace Content.Server.Cargo
@@ -84,7 +86,7 @@ namespace Content.Server.Cargo
/// Approves an order in the database.
/// </summary>
/// <param name="order">The order to be approved.</param>
public bool ApproveOrder(int orderNumber)
public bool ApproveOrder(string approver, int orderNumber)
{
if (CurrentOrderSize == MaxOrderSize ||
!_orders.TryGetValue(orderNumber, out var order) ||
@@ -104,6 +106,8 @@ namespace Content.Server.Cargo
}
order.Approved = true;
order.Approver = approver;
CurrentOrderSize += order.Amount;
return true;
}

View File

@@ -135,6 +135,10 @@ namespace Content.Server.Cargo.Components
break;
}
var uid = msg.Session.AttachedEntityUid;
if (uid == null)
break;
PrototypeManager.TryIndex(order.ProductId, out CargoProductPrototype? product);
if (product == null!)
break;
@@ -143,13 +147,14 @@ namespace Content.Server.Cargo.Components
(capacity.CurrentCapacity == capacity.MaxCapacity
|| capacity.CurrentCapacity + order.Amount > capacity.MaxCapacity
|| !_cargoConsoleSystem.CheckBalance(_bankAccount.Id, (-product.PointCost) * order.Amount)
|| !_cargoConsoleSystem.ApproveOrder(orders.Database.Id, msg.OrderNumber)
|| !_cargoConsoleSystem.ApproveOrder(Owner.Uid, uid.Value, orders.Database.Id, msg.OrderNumber)
|| !_cargoConsoleSystem.ChangeBalance(_bankAccount.Id, (-product.PointCost) * order.Amount))
)
{
SoundSystem.Play(Filter.Local(), _errorSound.GetSound(), Owner, AudioParams.Default);
break;
}
UpdateUIState();
break;
}
@@ -189,12 +194,7 @@ namespace Content.Server.Cargo.Components
orders.Database.ClearOrderCapacity();
foreach (var order in approvedOrders)
{
if (!PrototypeManager.TryIndex(order.ProductId, out CargoProductPrototype? product))
continue;
for (var i = 0; i < order.Amount; i++)
{
telepadComponent.QueueTeleport(product);
}
telepadComponent.QueueTeleport(order);
}
}
}

View File

@@ -1,13 +1,20 @@
using System;
using System.Collections.Generic;
using Content.Server.Labels.Components;
using Content.Server.Paper;
using Content.Server.Power.Components;
using Content.Shared.Cargo;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Sound;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Cargo.Components
{
@@ -17,14 +24,23 @@ namespace Content.Server.Cargo.Components
[RegisterComponent]
public class CargoTelepadComponent : Component
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
public override string Name => "CargoTelepad";
private const float TeleportDuration = 0.5f;
private const float TeleportDelay = 15f;
private List<CargoProductPrototype> _teleportQueue = new List<CargoProductPrototype>();
private List<CargoOrderData> _teleportQueue = new();
private CargoTelepadState _currentState = CargoTelepadState.Unpowered;
[DataField("teleportSound")] private SoundSpecifier _teleportSound = new SoundPathSpecifier("/Audio/Machines/phasein.ogg");
/// <summary>
/// The paper-type prototype to spawn with the order information.
/// </summary>
[DataField("printerOutput", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string PrinterOutput = "Paper";
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
@@ -39,9 +55,12 @@ namespace Content.Server.Cargo.Components
}
}
public void QueueTeleport(CargoProductPrototype product)
public void QueueTeleport(CargoOrderData order)
{
_teleportQueue.Add(product);
for (var i = 0; i < order.Amount; i++)
{
_teleportQueue.Add(order);
}
TeleportLoop();
}
@@ -79,7 +98,7 @@ namespace Content.Server.Cargo.Components
if (!Deleted && !Owner.Deleted && _currentState == CargoTelepadState.Teleporting && _teleportQueue.Count > 0)
{
SoundSystem.Play(Filter.Pvs(Owner), _teleportSound.GetSound(), Owner, AudioParams.Default.WithVolume(-8f));
Owner.EntityManager.SpawnEntity(_teleportQueue[0].Product, Owner.Transform.Coordinates);
SpawnProduct(_teleportQueue[0]);
_teleportQueue.RemoveAt(0);
if (Owner.TryGetComponent<SpriteComponent>(out var spriteComponent) && spriteComponent.LayerCount > 0)
spriteComponent.LayerSetState(0, "idle");
@@ -92,6 +111,38 @@ namespace Content.Server.Cargo.Components
}
}
/// <summary>
/// Spawn the product and a piece of paper. Attempt to attach the paper to the product.
/// </summary>
private void SpawnProduct(CargoOrderData data)
{
// spawn the order
if (!_prototypeManager.TryIndex(data.ProductId, out CargoProductPrototype? prototype))
return;
var product = Owner.EntityManager.SpawnEntity(prototype.Product, Owner.Transform.Coordinates);
// spawn a piece of paper.
var printed = Owner.EntityManager.SpawnEntity(PrinterOutput, Owner.Transform.Coordinates);
if (!_entityManager.TryGetComponent(printed.Uid, out PaperComponent paper))
return;
// fill in the order data
printed.Name = Loc.GetString("cargo-console-paper-print-name", ("orderNumber", data.OrderNumber));
paper.SetContent(Loc.GetString(
"cargo-console-paper-print-text",
("orderNumber", data.OrderNumber),
("requester", data.Requester),
("reason", data.Reason),
("approver", data.Approver)));
// attempt to attach the label
if (_entityManager.TryGetComponent(product.Uid, out PaperLabelComponent label) &&
_entityManager.TryGetComponent(product.Uid, out SharedItemSlotsComponent slots))
{
EntitySystem.Get<SharedItemSlotsSystem>().TryInsertContent(slots, printed, label.LabelSlot);
}
}
private enum CargoTelepadState { Unpowered, Idle, Charging, Teleporting };
}
}