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

@@ -22,81 +22,14 @@ namespace Content.Server.Morgue.Components
[ComponentReference(typeof(EntityStorageComponent))]
[ComponentReference(typeof(IActivate))]
[ComponentReference(typeof(IStorageComponent))]
#pragma warning disable 618
public class BodyBagEntityStorageComponent : EntityStorageComponent, IExamine, IInteractUsing
#pragma warning restore 618
public class BodyBagEntityStorageComponent : EntityStorageComponent
{
public override string Name => "BodyBagEntityStorage";
[ViewVariables]
[ComponentDependency] private readonly AppearanceComponent? _appearance = null;
[ViewVariables] public ContainerSlot? LabelContainer { get; private set; }
protected override void Initialize()
{
base.Initialize();
_appearance?.SetData(BodyBagVisuals.Label, false);
LabelContainer = Owner.EnsureContainer<ContainerSlot>("body_bag_label", out _);
}
protected override bool AddToContents(IEntity entity)
{
if (entity.HasComponent<SharedBodyComponent>() && !EntitySystem.Get<StandingStateSystem>().IsDown(entity.Uid)) return false;
return base.AddToContents(entity);
}
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
{
if (inDetailsRange)
{
if (LabelContainer?.ContainedEntity != null && LabelContainer.ContainedEntity.TryGetComponent<PaperComponent>(out var paper))
{
message.AddText(Loc.GetString("body-bag-entity-storage-component-on-examine-details", ("paper", paper.Content)));
}
}
}
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
{
if (LabelContainer == null) return false;
if (LabelContainer.ContainedEntity != null)
{
Owner.PopupMessage(eventArgs.User, Loc.GetString("body-bag-entity-storage-component-interact-using-already-attached"));
return false;
}
var handsComponent = eventArgs.User.GetComponent<HandsComponent>();
if (!handsComponent.Drop(eventArgs.Using, LabelContainer))
{
return false;
}
_appearance?.SetData(BodyBagVisuals.Label, true);
Owner.PopupMessage(eventArgs.User, Loc.GetString("body-bag-entity-storage-component-interact-using-success",("entity", eventArgs.Using)));
return true;
}
public void RemoveLabel(IEntity user)
{
if (LabelContainer == null) return;
var ent = LabelContainer.ContainedEntity;
if(ent is null)
return;
if (user.TryGetComponent(out HandsComponent? hands))
{
hands.PutInHandOrDrop(ent.GetComponent<ItemComponent>());
_appearance?.SetData(BodyBagVisuals.Label, false);
}
else if (LabelContainer.Remove(ent))
{
ent.Transform.Coordinates = Owner.Transform.Coordinates;
_appearance?.SetData(BodyBagVisuals.Label, false);
}
}
}
}

View File

@@ -17,7 +17,6 @@ namespace Content.Server.Morgue
base.Initialize();
SubscribeLocalEvent<CrematoriumEntityStorageComponent, GetAlternativeVerbsEvent>(AddCremateVerb);
SubscribeLocalEvent<BodyBagEntityStorageComponent, GetAlternativeVerbsEvent>(AddRemoveLabelVerb);
}
private void AddCremateVerb(EntityUid uid, CrematoriumEntityStorageComponent component, GetAlternativeVerbsEvent args)
@@ -32,22 +31,6 @@ namespace Content.Server.Morgue
args.Verbs.Add(verb);
}
/// <summary>
/// This adds the "remove label" verb to the list of verbs. Yes, this is a stupid function name, but it's
/// consistent with other get-verb event handlers.
/// </summary>
private void AddRemoveLabelVerb(EntityUid uid, BodyBagEntityStorageComponent component, GetAlternativeVerbsEvent args)
{
if (args.Hands == null || !args.CanAccess || !args.CanInteract || component.LabelContainer?.ContainedEntity == null)
return;
Verb verb = new();
verb.Text = Loc.GetString("remove-label-verb-get-data-text");
// TODO VERB ICON Add cancel/X icon? or maybe just use the pick-up or eject icon?
verb.Act = () => component.RemoveLabel(args.User);
args.Verbs.Add(verb);
}
public override void Update(float frameTime)
{
_accumulatedFrameTime += frameTime;