Toilet Upgrade (needs review) (#22133)
* Toilet Draft * fixes * toilets now have secret stash to place items in cistern. * fixes * plungers now unblock toilets. * fix sprite * new sprites and fix * fixes * improve seat sprites. * fix * removed visualisersystem changed to genericvisualizers * flush sound for toilets and copyright for toilet sprites. * fix atrributions * fixes * fix datafield flushtime * sprite improvements * fixes * multiple changes * fix * fix * fixes remove vv * moved stash related functions to secret stash system from toilet. * fix * fix * changes for recent review. * fix * fix
This commit is contained in:
40
Content.Shared/Toilet/Components/ToiletComponent.cs
Normal file
40
Content.Shared/Toilet/Components/ToiletComponent.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Toilet.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Toilets that can be flushed, seats toggled up and down, items hidden in cistern.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
public sealed partial class ToiletComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Toggles seat state.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public bool ToggleSeat;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Sound to play when toggling toilet seat.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public SoundSpecifier SeatSound = new SoundPathSpecifier("/Audio/Effects/toilet_seat_down.ogg");
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum ToiletVisuals : byte
|
||||
{
|
||||
SeatVisualState,
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum SeatVisualState : byte
|
||||
{
|
||||
SeatUp,
|
||||
SeatDown
|
||||
}
|
||||
}
|
||||
|
||||
109
Content.Shared/Toilet/Systems/SharedToiletSystem.cs
Normal file
109
Content.Shared/Toilet/Systems/SharedToiletSystem.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using Content.Shared.Buckle.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Verbs;
|
||||
using Content.Shared.Plunger.Components;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Utility;
|
||||
using Content.Shared.Toilet.Components;
|
||||
|
||||
namespace Content.Shared.Toilet.Systems
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles sprite changes for both toilet seat up and down as well as for lid open and closed. Handles interactions with hidden stash
|
||||
/// </summary>
|
||||
|
||||
public abstract class SharedToiletSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ToiletComponent, MapInitEvent>(OnMapInit);
|
||||
SubscribeLocalEvent<ToiletComponent, GetVerbsEvent<AlternativeVerb>>(OnToggleSeatVerb);
|
||||
SubscribeLocalEvent<ToiletComponent, ActivateInWorldEvent>(OnActivateInWorld);
|
||||
}
|
||||
|
||||
private void OnMapInit(EntityUid uid, ToiletComponent component, MapInitEvent args)
|
||||
{
|
||||
if (_random.Prob(0.5f))
|
||||
component.ToggleSeat = true;
|
||||
|
||||
if (_random.Prob(0.3f))
|
||||
{
|
||||
TryComp<PlungerUseComponent>(uid, out var plunger);
|
||||
|
||||
if (plunger == null)
|
||||
return;
|
||||
|
||||
plunger.NeedsPlunger = true;
|
||||
}
|
||||
|
||||
UpdateAppearance(uid);
|
||||
Dirty(uid, component);
|
||||
}
|
||||
|
||||
public bool CanToggle(EntityUid uid)
|
||||
{
|
||||
return TryComp<StrapComponent>(uid, out var strap) && strap.BuckledEntities.Count == 0;
|
||||
}
|
||||
|
||||
private void OnToggleSeatVerb(EntityUid uid, ToiletComponent component, GetVerbsEvent<AlternativeVerb> args)
|
||||
{
|
||||
if (!args.CanInteract || !args.CanAccess || !CanToggle(uid) || args.Hands == null)
|
||||
return;
|
||||
|
||||
AlternativeVerb toggleVerb = new()
|
||||
{
|
||||
Act = () => ToggleToiletSeat(uid, args.User, component)
|
||||
};
|
||||
|
||||
if (component.ToggleSeat)
|
||||
{
|
||||
toggleVerb.Text = Loc.GetString("toilet-seat-close");
|
||||
toggleVerb.Icon =
|
||||
new SpriteSpecifier.Texture(new ResPath("/Textures/Interface/VerbIcons/close.svg.192dpi.png"));
|
||||
}
|
||||
else
|
||||
{
|
||||
toggleVerb.Text = Loc.GetString("toilet-seat-open");
|
||||
toggleVerb.Icon =
|
||||
new SpriteSpecifier.Texture(new ResPath("/Textures/Interface/VerbIcons/open.svg.192dpi.png"));
|
||||
}
|
||||
args.Verbs.Add(toggleVerb);
|
||||
}
|
||||
|
||||
private void OnActivateInWorld(EntityUid uid, ToiletComponent comp, ActivateInWorldEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
args.Handled = true;
|
||||
ToggleToiletSeat(uid, args.User, comp);
|
||||
}
|
||||
|
||||
public void ToggleToiletSeat(EntityUid uid, EntityUid? user = null, ToiletComponent? component = null, MetaDataComponent? meta = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
return;
|
||||
|
||||
component.ToggleSeat = !component.ToggleSeat;
|
||||
|
||||
_audio.PlayPredicted(component.SeatSound, uid, uid);
|
||||
UpdateAppearance(uid, component);
|
||||
Dirty(uid, component, meta);
|
||||
}
|
||||
|
||||
private void UpdateAppearance(EntityUid uid, ToiletComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
return;
|
||||
|
||||
_appearance.SetData(uid, ToiletVisuals.SeatVisualState, component.ToggleSeat ? SeatVisualState.SeatUp : SeatVisualState.SeatDown);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.Tools;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Shared.Toilet
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed partial class ToiletComponent : Component
|
||||
{
|
||||
[DataField("pryLidTime")]
|
||||
public float PryLidTime = 1f;
|
||||
|
||||
[DataField("pryingQuality", customTypeSerializer:typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
|
||||
public string PryingQuality = "Prying";
|
||||
|
||||
[DataField("toggleSound")]
|
||||
public SoundSpecifier ToggleSound = new SoundPathSpecifier("/Audio/Effects/toilet_seat_down.ogg");
|
||||
|
||||
[DataField("lidOpen")]
|
||||
public bool LidOpen = false;
|
||||
|
||||
[DataField("isSeatUp")]
|
||||
public bool IsSeatUp = false;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed partial class ToiletPryDoAfterEvent : SimpleDoAfterEvent
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Toilet;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum ToiletVisuals
|
||||
{
|
||||
LidOpen,
|
||||
SeatUp
|
||||
}
|
||||
Reference in New Issue
Block a user