ECS secret stash and toilet (#5685)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -1,180 +1,34 @@
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Act;
|
||||
using Content.Server.Buckle.Components;
|
||||
using Content.Server.Chat.Managers;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Server.Tools;
|
||||
using Content.Server.Tools.Components;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Body.Part;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Toilet;
|
||||
using Content.Shared.Tools;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Toilet
|
||||
{
|
||||
[RegisterComponent]
|
||||
#pragma warning disable 618
|
||||
public class ToiletComponent : Component, IInteractUsing,
|
||||
IInteractHand, IMapInit, IExamine, ISuicideAct
|
||||
#pragma warning restore 618
|
||||
[ComponentProtoName("Toilet")]
|
||||
public sealed class ToiletComponent : Component, ISuicideAct
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
|
||||
public sealed override string Name => "Toilet";
|
||||
|
||||
private const float PryLidTime = 1f;
|
||||
|
||||
private bool _isPrying = false;
|
||||
[DataField("pryLidTime")]
|
||||
public float PryLidTime = 1f;
|
||||
|
||||
[DataField("pryingQuality", customTypeSerializer:typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
|
||||
private string _pryingQuality = "Prying";
|
||||
public string PryingQuality = "Prying";
|
||||
|
||||
[ViewVariables] public bool LidOpen { get; private set; }
|
||||
[ViewVariables] public bool IsSeatUp { get; private set; }
|
||||
[DataField("toggleSound")]
|
||||
public SoundSpecifier ToggleSound = new SoundPathSpecifier("/Audio/Effects/toilet_seat_down.ogg");
|
||||
|
||||
[ViewVariables] private SecretStashComponent _secretStash = default!;
|
||||
|
||||
[DataField("toggleSound")] SoundSpecifier _toggleSound = new SoundPathSpecifier("/Audio/Effects/toilet_seat_down.ogg");
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_secretStash = Owner.EnsureComponent<SecretStashComponent>();
|
||||
}
|
||||
|
||||
public void MapInit()
|
||||
{
|
||||
// roll is toilet seat will be up or down
|
||||
var random = IoCManager.Resolve<IRobustRandom>();
|
||||
IsSeatUp = random.Prob(0.5f);
|
||||
UpdateSprite();
|
||||
}
|
||||
|
||||
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
// are player trying place or lift of cistern lid?
|
||||
if (_entMan.TryGetComponent(eventArgs.Using, out ToolComponent? tool)
|
||||
&& tool.Qualities.Contains(_pryingQuality))
|
||||
{
|
||||
// check if someone is already prying this toilet
|
||||
if (_isPrying)
|
||||
return false;
|
||||
_isPrying = true;
|
||||
|
||||
if (!await EntitySystem.Get<ToolSystem>().UseTool(eventArgs.Using, eventArgs.User, Owner, 0f, PryLidTime, _pryingQuality))
|
||||
{
|
||||
_isPrying = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
_isPrying = false;
|
||||
|
||||
// all cool - toggle lid
|
||||
LidOpen = !LidOpen;
|
||||
UpdateSprite();
|
||||
|
||||
return true;
|
||||
}
|
||||
// maybe player trying to hide something inside cistern?
|
||||
else if (LidOpen)
|
||||
{
|
||||
return _secretStash.TryHideItem(eventArgs.User, eventArgs.Using);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
|
||||
{
|
||||
// trying get something from stash?
|
||||
if (LidOpen)
|
||||
{
|
||||
var gotItem = _secretStash.TryGetItem(eventArgs.User);
|
||||
|
||||
if (gotItem)
|
||||
return true;
|
||||
}
|
||||
|
||||
// just want to up/down seat?
|
||||
// check that nobody seats on seat right now
|
||||
if (_entMan.TryGetComponent(Owner, out StrapComponent? strap))
|
||||
{
|
||||
if (strap.BuckledEntities.Count != 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
ToggleToiletSeat();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Examine(FormattedMessage message, bool inDetailsRange)
|
||||
{
|
||||
if (inDetailsRange && LidOpen)
|
||||
{
|
||||
if (_secretStash.HasItemInside())
|
||||
{
|
||||
message.AddMarkup(Loc.GetString("toilet-component-on-examine-found-hidden-item"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ToggleToiletSeat()
|
||||
{
|
||||
IsSeatUp = !IsSeatUp;
|
||||
SoundSystem.Play(Filter.Pvs(Owner), _toggleSound.GetSound(), Owner, AudioHelpers.WithVariation(0.05f));
|
||||
|
||||
UpdateSprite();
|
||||
}
|
||||
|
||||
private void UpdateSprite()
|
||||
{
|
||||
if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(ToiletVisuals.LidOpen, LidOpen);
|
||||
appearance.SetData(ToiletVisuals.SeatUp, IsSeatUp);
|
||||
}
|
||||
}
|
||||
public bool LidOpen = false;
|
||||
public bool IsSeatUp = false;
|
||||
public bool IsPrying = false;
|
||||
|
||||
// todo: move me to ECS
|
||||
SuicideKind ISuicideAct.Suicide(EntityUid victim, IChatManager chat)
|
||||
{
|
||||
// check that victim even have head
|
||||
if (_entMan.TryGetComponent<SharedBodyComponent?>(victim, out var body) &&
|
||||
body.HasPartOfType(BodyPartType.Head))
|
||||
{
|
||||
var othersMessage = Loc.GetString("toilet-component-suicide-head-message-others", ("victim",Name: _entMan.GetComponent<MetaDataComponent>(victim).EntityName),("owner", Name: _entMan.GetComponent<MetaDataComponent>(Owner).EntityName));
|
||||
victim.PopupMessageOtherClients(othersMessage);
|
||||
|
||||
var selfMessage = Loc.GetString("toilet-component-suicide-head-message", ("owner", Name: _entMan.GetComponent<MetaDataComponent>(Owner).EntityName));
|
||||
victim.PopupMessage(selfMessage);
|
||||
|
||||
return SuicideKind.Asphyxiation;
|
||||
}
|
||||
else
|
||||
{
|
||||
var othersMessage = Loc.GetString("toilet-component-suicide-message-others",("victim", Name: _entMan.GetComponent<MetaDataComponent>(victim).EntityName),("owner", Name: _entMan.GetComponent<MetaDataComponent>(Owner).EntityName));
|
||||
victim.PopupMessageOtherClients(othersMessage);
|
||||
|
||||
var selfMessage = Loc.GetString("toilet-component-suicide-message", ("owner",Name: _entMan.GetComponent<MetaDataComponent>(Owner).EntityName));
|
||||
victim.PopupMessage(selfMessage);
|
||||
|
||||
return SuicideKind.Blunt;
|
||||
}
|
||||
return EntitySystem.Get<ToiletSystem>().Suicide(Owner, victim, this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user