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,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 };
}
}