ECS secret stash and toilet (#5685)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -1,54 +1,23 @@
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Plants.Systems;
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Plants.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction wrapper for <see cref="SecretStashComponent"/>.
|
||||
/// Gently rustle after each interaction with plant.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class PottedPlantHideComponent : Component, IInteractUsing, IInteractHand
|
||||
[Friend(typeof(PottedPlantHideSystem))]
|
||||
public class PottedPlantHideComponent : Component
|
||||
{
|
||||
public override string Name => "PottedPlantHide";
|
||||
|
||||
[ViewVariables] private SecretStashComponent _secretStash = default!;
|
||||
[DataField("rustleSound")] private SoundSpecifier _rustleSound = new SoundPathSpecifier("/Audio/Effects/plant_rustle.ogg");
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_secretStash = Owner.EnsureComponent<SecretStashComponent>();
|
||||
}
|
||||
|
||||
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
Rustle();
|
||||
return _secretStash.TryHideItem(eventArgs.User, eventArgs.Using);
|
||||
}
|
||||
|
||||
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
|
||||
{
|
||||
Rustle();
|
||||
|
||||
var gotItem = _secretStash.TryGetItem(eventArgs.User);
|
||||
if (!gotItem)
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("potted-plant-hide-component-interact-hand-got-no-item-message"));
|
||||
}
|
||||
|
||||
return gotItem;
|
||||
}
|
||||
|
||||
private void Rustle()
|
||||
{
|
||||
SoundSystem.Play(Filter.Pvs(Owner), _rustleSound.GetSound(), Owner, AudioHelpers.WithVariation(0.25f));
|
||||
}
|
||||
[DataField("rustleSound")]
|
||||
public SoundSpecifier RustleSound = new SoundPathSpecifier("/Audio/Effects/plant_rustle.ogg");
|
||||
}
|
||||
}
|
||||
|
||||
75
Content.Server/Plants/Systems/PottedPlantHideSystem.cs
Normal file
75
Content.Server/Plants/Systems/PottedPlantHideSystem.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using Content.Server.Plants.Components;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Server.Storage.EntitySystems;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Interaction;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Plants.Systems
|
||||
{
|
||||
public class PottedPlantHideSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SecretStashSystem _stashSystem = default!;
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<PottedPlantHideComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<PottedPlantHideComponent, InteractUsingEvent>(OnInteractUsing);
|
||||
SubscribeLocalEvent<PottedPlantHideComponent, InteractHandEvent>(OnInteractHand);
|
||||
}
|
||||
|
||||
private void OnInit(EntityUid uid, PottedPlantHideComponent component, ComponentInit args)
|
||||
{
|
||||
EntityManager.EnsureComponent<SecretStashComponent>(uid);
|
||||
}
|
||||
|
||||
private void OnInteractUsing(EntityUid uid, PottedPlantHideComponent component, InteractUsingEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
// standard interaction checks
|
||||
if (!_blocker.CanInteract(args.User)) return;
|
||||
|
||||
Rustle(uid, component);
|
||||
args.Handled = _stashSystem.TryHideItem(uid, args.User, args.Used);
|
||||
}
|
||||
|
||||
private void OnInteractHand(EntityUid uid, PottedPlantHideComponent component, InteractHandEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
// standard interaction checks
|
||||
if (!_blocker.CanInteract(args.User)) return;
|
||||
|
||||
Rustle(uid, component);
|
||||
|
||||
var gotItem = _stashSystem.TryGetItem(uid, args.User);
|
||||
if (!gotItem)
|
||||
{
|
||||
var msg = Loc.GetString("potted-plant-hide-component-interact-hand-got-no-item-message");
|
||||
_popupSystem.PopupEntity(msg, uid, Filter.Entities(args.User));
|
||||
}
|
||||
|
||||
args.Handled = gotItem;
|
||||
}
|
||||
|
||||
private void Rustle(EntityUid uid, PottedPlantHideComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
return;
|
||||
|
||||
SoundSystem.Play(Filter.Pvs(uid), component.RustleSound.GetSound(), uid, AudioHelpers.WithVariation(0.25f));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user