Mortician's Menagerie (#2391)
* Body bags! * Morgue Trays and the Crematorium! Reorganised body bags to be under Morgue, not Medical * Fix. Things outside of EntityStorageComponents now use the Try*Storage() not just *Storage() methods - Allows mobs to be trapped in a morgue/crematorium whose tray can't open. * Fix tests. Modernise component dependency and nullability. * Update Content.Server/GameObjects/Components/Morgue/MorgueTrayComponent.cs Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
#nullable enable
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
using Content.Server.GameObjects.Components.Items.Storage;
|
||||
using Content.Server.GameObjects.Components.Paper;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces.GameObjects.Components.Items;
|
||||
using Content.Shared.GameObjects.Components.Body;
|
||||
using Content.Shared.GameObjects.Components.Morgue;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.Verbs;
|
||||
using Content.Shared.Interfaces;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.ComponentDependencies;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Morgue
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(EntityStorageComponent))]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
[ComponentReference(typeof(IStorageComponent))]
|
||||
public class BodyBagEntityStorageComponent : EntityStorageComponent, IExamine, IInteractUsing
|
||||
{
|
||||
public override string Name => "BodyBagEntityStorage";
|
||||
|
||||
[ViewVariables]
|
||||
[ComponentDependency] private AppearanceComponent? _appearance = null;
|
||||
|
||||
[ViewVariables] public ContainerSlot? LabelContainer { get; private set; }
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_appearance?.SetData(BodyBagVisuals.Label, false);
|
||||
LabelContainer = ContainerManagerComponent.Ensure<ContainerSlot>("body_bag_label", Owner, out _);
|
||||
}
|
||||
|
||||
protected override bool AddToContents(IEntity entity)
|
||||
{
|
||||
if (entity.HasComponent<IBody>() && !EntitySystem.Get<StandingStateSystem>().IsDown(entity)) 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("The label reads: {0}", paper.Content));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
if (LabelContainer == null) return false;
|
||||
|
||||
if (LabelContainer.ContainedEntity != null)
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("There's already a label attached."));
|
||||
return false;
|
||||
}
|
||||
|
||||
var handsComponent = eventArgs.User.GetComponent<IHandsComponent>();
|
||||
if (!handsComponent.Drop(eventArgs.Using, LabelContainer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_appearance?.SetData(BodyBagVisuals.Label, true);
|
||||
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("You attach {0:theName} to the body bag.", eventArgs.Using));
|
||||
return true;
|
||||
}
|
||||
|
||||
public void RemoveLabel(IEntity user)
|
||||
{
|
||||
if (LabelContainer == null) return;
|
||||
|
||||
if (user.TryGetComponent(out HandsComponent? hands))
|
||||
{
|
||||
hands.PutInHandOrDrop(LabelContainer.ContainedEntity.GetComponent<ItemComponent>());
|
||||
_appearance?.SetData(BodyBagVisuals.Label, false);
|
||||
}
|
||||
else if (LabelContainer.Remove(LabelContainer.ContainedEntity))
|
||||
{
|
||||
LabelContainer.ContainedEntity.Transform.Coordinates = Owner.Transform.Coordinates;
|
||||
_appearance?.SetData(BodyBagVisuals.Label, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Verb]
|
||||
private sealed class RemoveLabelVerb : Verb<BodyBagEntityStorageComponent>
|
||||
{
|
||||
protected override void GetData(IEntity user, BodyBagEntityStorageComponent component, VerbData data)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(user) || component.LabelContainer?.ContainedEntity == null)
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
data.Text = Loc.GetString("Remove label");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Activate(IEntity user, BodyBagEntityStorageComponent component)
|
||||
{
|
||||
component.RemoveLabel(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
#nullable enable
|
||||
using Content.Server.GameObjects.Components.Items.Storage;
|
||||
using Content.Shared.GameObjects.Components.Morgue;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.Verbs;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Timers;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Morgue
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(MorgueEntityStorageComponent))]
|
||||
[ComponentReference(typeof(EntityStorageComponent))]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
[ComponentReference(typeof(IStorageComponent))]
|
||||
public class CrematoriumEntityStorageComponent : MorgueEntityStorageComponent, IExamine
|
||||
{
|
||||
public override string Name => "CrematoriumEntityStorage";
|
||||
|
||||
[ViewVariables]
|
||||
public bool Cooking { get; private set; }
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private int _burnMilis = 3000;
|
||||
|
||||
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
|
||||
{
|
||||
if (Appearance == null) return;
|
||||
|
||||
if (inDetailsRange)
|
||||
{
|
||||
if (Appearance.TryGetData(CrematoriumVisuals.Burning, out bool isBurning) && isBurning)
|
||||
{
|
||||
message.AddMarkup(Loc.GetString("The {0:theName} is [color=red]active[/color]!\n", Owner));
|
||||
}
|
||||
|
||||
if (Appearance.TryGetData(MorgueVisuals.HasContents, out bool hasContents) && hasContents)
|
||||
{
|
||||
message.AddMarkup(Loc.GetString("The content light is [color=green]on[/color], there's something in here."));
|
||||
}
|
||||
else
|
||||
{
|
||||
message.AddText(Loc.GetString("The content light is off, there's nothing in here."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Cremate()
|
||||
{
|
||||
if (Cooking) return;
|
||||
|
||||
Appearance?.SetData(CrematoriumVisuals.Burning, true);
|
||||
Cooking = true;
|
||||
|
||||
Timer.Spawn(_burnMilis, () =>
|
||||
{
|
||||
Appearance?.SetData(CrematoriumVisuals.Burning, false);
|
||||
Cooking = false;
|
||||
|
||||
for (var i = Contents.ContainedEntities.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var item = Contents.ContainedEntities[i];
|
||||
Contents.Remove(item);
|
||||
item.Delete();
|
||||
}
|
||||
|
||||
var ash = Owner.EntityManager.SpawnEntity("Ash", Owner.Transform.Coordinates);
|
||||
Contents.Insert(ash);
|
||||
|
||||
TryOpenStorage(Owner);
|
||||
|
||||
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Machines/ding.ogg", Owner);
|
||||
});
|
||||
}
|
||||
|
||||
[Verb]
|
||||
private sealed class CremateVerb : Verb<CrematoriumEntityStorageComponent>
|
||||
{
|
||||
protected override void GetData(IEntity user, CrematoriumEntityStorageComponent component, VerbData data)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(user) || component.Cooking)
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
data.Text = Loc.GetString("Cremate");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Activate(IEntity user, CrematoriumEntityStorageComponent component)
|
||||
{
|
||||
component.Cremate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
#nullable enable
|
||||
using Content.Server.GameObjects.Components.Items.Storage;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.Components.Body;
|
||||
using Content.Shared.GameObjects.Components.Morgue;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.Interfaces;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Utility;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.ComponentDependencies;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Morgue
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(EntityStorageComponent))]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
[ComponentReference(typeof(IStorageComponent))]
|
||||
public class MorgueEntityStorageComponent : EntityStorageComponent, IExamine
|
||||
{
|
||||
public override string Name => "MorgueEntityStorage";
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private string? _trayPrototypeId;
|
||||
|
||||
[ViewVariables]
|
||||
private IEntity? _tray;
|
||||
|
||||
[ViewVariables]
|
||||
public ContainerSlot? TrayContainer { get; private set; }
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool DoSoulBeep = true;
|
||||
|
||||
[ViewVariables]
|
||||
[ComponentDependency] protected readonly AppearanceComponent? Appearance = null;
|
||||
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
Appearance?.SetData(MorgueVisuals.Open, false);
|
||||
TrayContainer = ContainerManagerComponent.Ensure<ContainerSlot>("morgue_tray", Owner, out _);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
serializer.DataField(ref _trayPrototypeId, "trayPrototype", "");
|
||||
serializer.DataField(ref DoSoulBeep, "doSoulBeep", true);
|
||||
}
|
||||
|
||||
public override Vector2 ContentsDumpPosition()
|
||||
{
|
||||
if (_tray != null) return _tray.Transform.WorldPosition;
|
||||
return base.ContentsDumpPosition();
|
||||
}
|
||||
|
||||
protected override bool AddToContents(IEntity entity)
|
||||
{
|
||||
if (entity.HasComponent<IBody>() && !EntitySystem.Get<StandingStateSystem>().IsDown(entity)) return false;
|
||||
return base.AddToContents(entity);
|
||||
}
|
||||
|
||||
public override bool CanOpen(IEntity user, bool silent = false)
|
||||
{
|
||||
if (!Owner.InRangeUnobstructed(
|
||||
Owner.Transform.Coordinates.Offset(Owner.Transform.LocalRotation.GetCardinalDir()),
|
||||
collisionMask: CollisionGroup.Impassable | CollisionGroup.VaultImpassable
|
||||
))
|
||||
{
|
||||
if(!silent) Owner.PopupMessage(user, Loc.GetString("There's no room for the tray to extend!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.CanOpen(user, silent);
|
||||
}
|
||||
|
||||
protected override void OpenStorage()
|
||||
{
|
||||
Appearance?.SetData(MorgueVisuals.Open, true);
|
||||
Appearance?.SetData(MorgueVisuals.HasContents, false);
|
||||
Appearance?.SetData(MorgueVisuals.HasMob, false);
|
||||
Appearance?.SetData(MorgueVisuals.HasSoul, false);
|
||||
|
||||
if (_tray == null)
|
||||
{
|
||||
_tray = Owner.EntityManager.SpawnEntity(_trayPrototypeId, Owner.Transform.Coordinates);
|
||||
var trayComp = _tray.EnsureComponent<MorgueTrayComponent>();
|
||||
trayComp.Morgue = Owner;
|
||||
EntityQuery = new IntersectingEntityQuery(_tray);
|
||||
}
|
||||
else
|
||||
{
|
||||
TrayContainer?.Remove(_tray);
|
||||
}
|
||||
|
||||
_tray.Transform.WorldPosition = Owner.Transform.WorldPosition + Owner.Transform.LocalRotation.GetCardinalDir().ToVec();
|
||||
_tray.Transform.AttachParent(Owner);
|
||||
|
||||
base.OpenStorage();
|
||||
}
|
||||
|
||||
private void CheckContents()
|
||||
{
|
||||
var count = 0;
|
||||
var hasMob = false;
|
||||
var hasSoul = false;
|
||||
foreach (var entity in Contents.ContainedEntities)
|
||||
{
|
||||
count++;
|
||||
if (!hasMob && entity.HasComponent<IBody>()) hasMob = true;
|
||||
if (!hasSoul && entity.TryGetComponent<BasicActorComponent>(out var actor) && actor.playerSession != null) hasSoul = true;
|
||||
}
|
||||
Appearance?.SetData(MorgueVisuals.HasContents, count > 0);
|
||||
Appearance?.SetData(MorgueVisuals.HasMob, hasMob);
|
||||
Appearance?.SetData(MorgueVisuals.HasSoul, hasSoul);
|
||||
}
|
||||
|
||||
protected override void CloseStorage()
|
||||
{
|
||||
base.CloseStorage();
|
||||
|
||||
Appearance?.SetData(MorgueVisuals.Open, false);
|
||||
CheckContents();
|
||||
|
||||
if (_tray != null)
|
||||
{
|
||||
TrayContainer?.Insert(_tray);
|
||||
}
|
||||
}
|
||||
|
||||
//Called every 10 seconds
|
||||
public void Update()
|
||||
{
|
||||
CheckContents();
|
||||
|
||||
if(DoSoulBeep && Appearance !=null && Appearance.TryGetData(MorgueVisuals.HasSoul, out bool hasSoul) && hasSoul)
|
||||
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Weapons/Guns/EmptyAlarm/smg_empty_alarm.ogg", Owner);
|
||||
}
|
||||
|
||||
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
|
||||
{
|
||||
if (Appearance == null) return;
|
||||
|
||||
if (inDetailsRange)
|
||||
{
|
||||
if (Appearance.TryGetData(MorgueVisuals.HasSoul, out bool hasSoul) && hasSoul)
|
||||
{
|
||||
message.AddMarkup(Loc.GetString("The content light is [color=green]green[/color], this body might still be saved!"));
|
||||
}
|
||||
else if (Appearance.TryGetData(MorgueVisuals.HasMob, out bool hasMob) && hasMob)
|
||||
{
|
||||
message.AddMarkup(Loc.GetString("The content light is [color=red]red[/color], there's a dead body in here! Oh wait..."));
|
||||
}
|
||||
else if (Appearance.TryGetData(MorgueVisuals.HasContents, out bool hasContents) && hasContents)
|
||||
{
|
||||
message.AddMarkup(Loc.GetString("The content light is [color=yellow]yellow[/color], there's something in here."));
|
||||
} else
|
||||
{
|
||||
message.AddMarkup(Loc.GetString("The content light is off, there's nothing in here."));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Morgue
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
public class MorgueTrayComponent : Component, IActivate
|
||||
{
|
||||
public override string Name => "MorgueTray";
|
||||
|
||||
[ViewVariables]
|
||||
public IEntity Morgue { get; set; }
|
||||
|
||||
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
if(Morgue != null && !Morgue.Deleted && Morgue.TryGetComponent<MorgueEntityStorageComponent>(out var comp))
|
||||
{
|
||||
comp.Activate(new ActivateEventArgs()
|
||||
{
|
||||
User = eventArgs.User,
|
||||
Target = Morgue
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user