* Ported sprites from eris * Added yml * lid open/close logic * interactivity * Working on new secret stash component * Object will drop on destruction * Can get item and examine message * Reagent container and some cleaning * Moved potted plant to stash * New base prefab * Now you can deconstruct toilet * Small fixes * Fixed unknown components errors * Fixed grammar errors Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> * Now use prob * More grammar * Update Content.Server/Construction/Conditions/ToiletLidClosed.cs Aaaaaaaa Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * No delays * Amazing sound design * Moved sound to mono * Toilet viz Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
120 lines
4.2 KiB
C#
120 lines
4.2 KiB
C#
#nullable enable
|
|
using Content.Server.GameObjects.Components.GUI;
|
|
using Content.Server.Interfaces.GameObjects.Components.Items;
|
|
using Content.Shared.GameObjects.EntitySystems;
|
|
using Content.Shared.Interfaces;
|
|
using Robust.Server.GameObjects.Components.Container;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
using Robust.Shared.Localization;
|
|
using Robust.Shared.Serialization;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Content.Server.GameObjects.Components.Items.Storage
|
|
{
|
|
/// <summary>
|
|
/// Logic for secret single slot stash, like plant pot or toilet cistern
|
|
/// </summary>
|
|
[RegisterComponent]
|
|
public class SecretStashComponent : Component, IDestroyAct
|
|
{
|
|
public override string Name => "SecretStash";
|
|
|
|
[ViewVariables] private int _maxItemSize;
|
|
[ViewVariables] private string _secretPartName = "";
|
|
|
|
[ViewVariables] private ContainerSlot _itemContainer = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
_itemContainer = ContainerManagerComponent.Ensure<ContainerSlot>("stash", Owner, out _);
|
|
}
|
|
public override void ExposeData(ObjectSerializer serializer)
|
|
{
|
|
base.ExposeData(serializer);
|
|
serializer.DataField(ref _maxItemSize, "maxItemSize", (int) ReferenceSizes.Pocket);
|
|
serializer.DataField(ref _secretPartName, "secretPartName", Loc.GetString("{0:theName}"));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tries to hide item inside secret stash from hands of user
|
|
/// </summary>
|
|
/// <param name="user"></param>
|
|
/// <param name="itemToHide"></param>
|
|
/// <returns>True if item was hidden inside stash</returns>
|
|
public bool TryHideItem(IEntity user, IEntity itemToHide)
|
|
{
|
|
if (_itemContainer.ContainedEntity != null)
|
|
{
|
|
Owner.PopupMessage(user, Loc.GetString("There's already something in here?!"));
|
|
return false;
|
|
}
|
|
|
|
if (!itemToHide.TryGetComponent(out ItemComponent? item))
|
|
return false;
|
|
|
|
if (item.Size > _maxItemSize)
|
|
{
|
|
Owner.PopupMessage(user,
|
|
Loc.GetString("{0:TheName} is too big to fit in {1}!", itemToHide, _secretPartName));
|
|
return false;
|
|
}
|
|
|
|
if (!user.TryGetComponent(out IHandsComponent? hands))
|
|
return false;
|
|
|
|
if (!hands.Drop(itemToHide, _itemContainer))
|
|
return false;
|
|
|
|
Owner.PopupMessage(user, Loc.GetString("You hide {0:theName} in {1}.", itemToHide, _secretPartName));
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Try get item and place it in users hand
|
|
/// If user can't take it by hands, will drop item from container
|
|
/// </summary>
|
|
/// <param name="user"></param>
|
|
/// <returns>True if user recieved item</returns>
|
|
public bool TryGetItem(IEntity user)
|
|
{
|
|
if (_itemContainer.ContainedEntity == null)
|
|
return false;
|
|
|
|
Owner.PopupMessage(user, Loc.GetString("There was something inside {0}!", _secretPartName));
|
|
|
|
if (user.TryGetComponent(out HandsComponent? hands))
|
|
{
|
|
if (!_itemContainer.ContainedEntity.TryGetComponent(out ItemComponent? item))
|
|
return false;
|
|
hands.PutInHandOrDrop(item);
|
|
}
|
|
else if (_itemContainer.Remove(_itemContainer.ContainedEntity))
|
|
{
|
|
_itemContainer.ContainedEntity.Transform.Coordinates = Owner.Transform.Coordinates;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Is there something inside secret stash item container?
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool HasItemInside()
|
|
{
|
|
return _itemContainer.ContainedEntity != null;
|
|
}
|
|
|
|
public void OnDestroy(DestructionEventArgs eventArgs)
|
|
{
|
|
// drop item inside
|
|
if (_itemContainer.ContainedEntity != null)
|
|
{
|
|
_itemContainer.ContainedEntity.Transform.Coordinates = Owner.Transform.Coordinates;
|
|
}
|
|
}
|
|
}
|
|
}
|