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:
brainfood1183
2024-03-31 04:21:18 +01:00
committed by GitHub
parent 80c4d3ea0f
commit 5f063d2d6d
51 changed files with 890 additions and 465 deletions

View File

@@ -22,9 +22,14 @@ public sealed partial class StrapComponent : Component
/// Entities that this strap accepts and can buckle
/// If null it accepts any entity
/// </summary>
[DataField]
[ViewVariables]
public EntityWhitelist? AllowedEntities;
[DataField, ViewVariables(VVAccess.ReadWrite)]
public EntityWhitelist? Whitelist;
/// <summary>
/// Entities that this strap does not accept and cannot buckle.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public EntityWhitelist? Blacklist;
/// <summary>
/// The change in position to the strapped mob

View File

@@ -221,8 +221,8 @@ public abstract partial class SharedBuckleSystem
}
// Does it pass the Whitelist
if (strapComp.AllowedEntities != null &&
!strapComp.AllowedEntities.IsValid(userUid, EntityManager))
if (strapComp.Whitelist != null &&
!strapComp.Whitelist.IsValid(buckleUid, EntityManager) || strapComp.Blacklist?.IsValid(buckleUid, EntityManager) == true)
{
if (_netManager.IsServer)
_popup.PopupEntity(Loc.GetString("buckle-component-cannot-fit-message"), userUid, buckleUid, PopupType.Medium);

View File

@@ -1,4 +1,5 @@
using Robust.Shared.Audio;
using Content.Shared.Whitelist;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
@@ -17,6 +18,18 @@ public abstract partial class SharedDisposalUnitComponent : Component
[ViewVariables(VVAccess.ReadWrite), DataField("soundFlush")]
public SoundSpecifier? FlushSound = new SoundPathSpecifier("/Audio/Machines/disposalflush.ogg");
/// <summary>
/// Blacklists (prevents) entities listed from being placed inside.
/// </summary>
[DataField]
public EntityWhitelist? Blacklist;
/// <summary>
/// Whitelists (allows) entities listed from being placed inside.
/// </summary>
[DataField]
public EntityWhitelist? Whitelist;
/// <summary>
/// Sound played when an object is inserted into the disposal unit.
/// </summary>
@@ -33,20 +46,20 @@ public abstract partial class SharedDisposalUnitComponent : Component
/// <summary>
/// State for this disposals unit.
/// </summary>
[DataField("state")]
[DataField]
public DisposalsPressureState State;
// TODO: Just make this use vaulting.
/// <summary>
/// We'll track whatever just left disposals so we know what collision we need to ignore until they stop intersecting our BB.
/// </summary>
[ViewVariables, DataField("recentlyEjected")]
[ViewVariables, DataField]
public List<EntityUid> RecentlyEjected = new();
/// <summary>
/// Next time the disposal unit will be pressurized.
/// </summary>
[DataField("nextPressurized", customTypeSerializer:typeof(TimeOffsetSerializer))]
[DataField(customTypeSerializer:typeof(TimeOffsetSerializer))]
public TimeSpan NextPressurized = TimeSpan.Zero;
/// <summary>
@@ -58,63 +71,60 @@ public abstract partial class SharedDisposalUnitComponent : Component
/// <summary>
/// How long it takes from the start of a flush animation to return the sprite to normal.
/// </summary>
[DataField("flushDelay")]
[DataField]
public TimeSpan FlushDelay = TimeSpan.FromSeconds(3);
[DataField("mobsCanEnter")]
public bool MobsCanEnter = true;
/// <summary>
/// Removes the pressure requirement for flushing.
/// </summary>
[DataField("disablePressure"), ViewVariables(VVAccess.ReadWrite)]
[DataField, ViewVariables(VVAccess.ReadWrite)]
public bool DisablePressure;
/// <summary>
/// Last time that an entity tried to exit this disposal unit.
/// Last time that an entity tried to exit this disposal unit.
/// </summary>
[ViewVariables]
public TimeSpan LastExitAttempt;
[DataField("autoEngageEnabled")]
[DataField]
public bool AutomaticEngage = true;
[ViewVariables(VVAccess.ReadWrite)]
[DataField("autoEngageTime")]
[DataField]
public TimeSpan AutomaticEngageTime = TimeSpan.FromSeconds(30);
/// <summary>
/// Delay from trying to enter disposals ourselves.
/// Delay from trying to enter disposals ourselves.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("entryDelay")]
[DataField]
public float EntryDelay = 0.5f;
/// <summary>
/// Delay from trying to shove someone else into disposals.
/// Delay from trying to shove someone else into disposals.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public float DraggedEntryDelay = 2.0f;
/// <summary>
/// Container of entities inside this disposal unit.
/// Container of entities inside this disposal unit.
/// </summary>
[ViewVariables] public Container Container = default!;
// TODO: Network power shit instead fam.
[ViewVariables, DataField("powered")]
[ViewVariables, DataField]
public bool Powered;
/// <summary>
/// Was the disposals unit engaged for a manual flush.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("engaged")]
[ViewVariables(VVAccess.ReadWrite), DataField]
public bool Engaged;
/// <summary>
/// Next time this unit will flush. Is the lesser of <see cref="FlushDelay"/> and <see cref="AutomaticEngageTime"/>
/// </summary>
[ViewVariables, DataField("nextFlush", customTypeSerializer:typeof(TimeOffsetSerializer))]
[ViewVariables, DataField(customTypeSerializer:typeof(TimeOffsetSerializer))]
public TimeSpan? NextFlush;
[Serializable, NetSerializable]
@@ -130,8 +140,8 @@ public abstract partial class SharedDisposalUnitComponent : Component
{
UnAnchored,
Anchored,
Flushing,
Charging
OverlayFlushing,
OverlayCharging
}
[Serializable, NetSerializable]

View File

@@ -1,12 +1,10 @@
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Body.Components;
using Content.Shared.Disposal.Components;
using Content.Shared.DoAfter;
using Content.Shared.DragDrop;
using Content.Shared.Emag.Systems;
using Content.Shared.Item;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using Content.Shared.Throwing;
using Robust.Shared.Audio;
using Robust.Shared.Physics.Components;
@@ -26,7 +24,6 @@ public abstract class SharedDisposalUnitSystem : EntitySystem
{
[Dependency] protected readonly IGameTiming GameTiming = default!;
[Dependency] protected readonly MetaDataSystem Metadata = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] protected readonly SharedJointSystem Joints = default!;
protected static TimeSpan ExitAttemptDelay = TimeSpan.FromSeconds(0.5);
@@ -112,19 +109,21 @@ public abstract class SharedDisposalUnitSystem : EntitySystem
if (!Transform(uid).Anchored)
return false;
// TODO: Probably just need a disposable tag.
var storable = HasComp<ItemComponent>(entity);
if (!storable && !HasComp<BodyComponent>(entity))
return false;
//Check if the entity is a mob and if mobs can be inserted
if (TryComp<MobStateComponent>(entity, out var damageState) && !component.MobsCanEnter)
if (component.Blacklist?.IsValid(entity, EntityManager) == true)
return false;
if (TryComp<PhysicsComponent>(entity, out var physics) && (physics.CanCollide || storable))
return true;
if (component.Whitelist != null && component.Whitelist?.IsValid(entity, EntityManager) != true)
return false;
if (TryComp<PhysicsComponent>(entity, out var physics) && (physics.CanCollide) || storable)
return true;
else
return false;
return damageState != null && (!component.MobsCanEnter || _mobState.IsDead(entity, damageState));
}
public abstract void DoInsertDisposalUnit(EntityUid uid, EntityUid toInsert, EntityUid user, SharedDisposalUnitComponent? disposal = null);

View File

@@ -0,0 +1,17 @@
using Content.Shared.Storage.Components;
using Robust.Shared.Audio;
namespace Content.Shared.Plants
{
/// <summary>
/// Interaction wrapper for <see cref="SecretStashComponent"/>.
/// Gently rustle after each interaction with plant.
/// </summary>
[RegisterComponent]
[Access(typeof(PottedPlantHideSystem))]
public sealed partial class PottedPlantHideComponent : Component
{
[DataField("rustleSound")]
public SoundSpecifier RustleSound = new SoundPathSpecifier("/Audio/Effects/plant_rustle.ogg");
}
}

View File

@@ -0,0 +1,63 @@
using Content.Shared.Popups;
using Content.Shared.Storage.Components;
using Content.Shared.Storage.EntitySystems;
using Content.Shared.Interaction;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
namespace Content.Shared.Plants
{
public sealed class PottedPlantHideSystem : EntitySystem
{
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly SecretStashSystem _stashSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = 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;
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;
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, args.User);
}
args.Handled = gotItem;
}
private void Rustle(EntityUid uid, PottedPlantHideComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
_audio.PlayPvs(component.RustleSound, uid, AudioParams.Default.WithVariation(0.25f));
}
}
}

View File

@@ -0,0 +1,18 @@
using Robust.Shared.GameStates;
namespace Content.Shared.Plunger.Components
{
/// <summary>
/// Allows entity to unblock target entity with PlungerUseComponent.
/// </summary>
[RegisterComponent, NetworkedComponent,AutoGenerateComponentState]
public sealed partial class PlungerComponent : Component
{
/// <summary>
/// Duration of plunger doafter event.
/// </summary>
[DataField]
[AutoNetworkedField]
public float PlungeDuration = 2f;
}
}

View File

@@ -0,0 +1,42 @@
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Content.Shared.Random;
using Robust.Shared.Prototypes;
namespace Content.Shared.Plunger.Components
{
/// <summary>
/// Entity can interact with plungers.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class PlungerUseComponent : Component
{
/// <summary>
/// If true entity has been plungered.
/// </summary>
[DataField]
[AutoNetworkedField]
public bool Plunged;
/// <summary>
/// If true entity can interact with plunger.
/// </summary>
[DataField]
[AutoNetworkedField]
public bool NeedsPlunger = false;
/// <summary>
/// A weighted random entity prototype containing the different loot that rummaging can provide.
/// </summary>
[DataField]
[AutoNetworkedField]
public ProtoId<WeightedRandomEntityPrototype> PlungerLoot = "PlungerLoot";
/// <summary>
/// Sound played on rummage completion.
/// </summary>
[DataField]
public SoundSpecifier Sound = new SoundPathSpecifier("/Audio/Effects/Fluids/glug.ogg");
}
}

View File

@@ -0,0 +1,10 @@
using Content.Shared.DoAfter;
using Robust.Shared.Serialization;
namespace Content.Shared.Plunger;
[Serializable, NetSerializable]
public sealed partial class PlungerDoAfterEvent : SimpleDoAfterEvent
{
}

View File

@@ -0,0 +1,79 @@
using Content.Shared.DoAfter;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Plunger.Components;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Timing;
using Content.Shared.Random.Helpers;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Content.Shared.Random;
namespace Content.Shared.Plunger.Systems;
/// <summary>
/// Plungers can be used to unblock entities with PlungerUseComponent.
/// </summary>
public sealed class PlungerSystem : EntitySystem
{
[Dependency] protected readonly IPrototypeManager _proto = default!;
[Dependency] protected readonly IRobustRandom _random = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
public override void Initialize()
{
SubscribeLocalEvent<PlungerComponent, AfterInteractEvent>(OnInteract);
SubscribeLocalEvent<PlungerComponent, PlungerDoAfterEvent>(OnDoAfter);
}
private void OnInteract(EntityUid uid, PlungerComponent component, AfterInteractEvent args)
{
if (args.Handled)
return;
if (!args.CanReach || args.Target is not { Valid: true } target)
return;
if (!TryComp<PlungerUseComponent>(args.Target, out var plunger))
return;
if (plunger.NeedsPlunger)
return;
_doAfter.TryStartDoAfter(new DoAfterArgs(EntityManager, args.User, component.PlungeDuration, new PlungerDoAfterEvent(), uid, target, uid)
{
BreakOnMove = true,
BreakOnDamage = true,
MovementThreshold = 1.0f,
});
args.Handled = true;
}
private void OnDoAfter(EntityUid uid, PlungerComponent component, DoAfterEvent args)
{
if (args.Cancelled || args.Handled || args.Args.Target == null)
return;
if (args.Target is not { Valid: true } target)
return;
if (!TryComp(target, out PlungerUseComponent? plunge))
return;
_popup.PopupClient(Loc.GetString("plunger-unblock", ("target", target)), args.User, args.User, PopupType.Medium);
plunge.Plunged = true;
var spawn = _proto.Index<WeightedRandomEntityPrototype>(plunge.PlungerLoot).Pick(_random);
_audio.PlayPredicted(plunge.Sound, uid, uid);
Spawn(spawn, Transform(target).Coordinates);
RemComp<PlungerUseComponent>(target);
Dirty(target, plunge);
args.Handled = true;
}
}

View File

@@ -0,0 +1,90 @@
using Content.Shared.Storage.EntitySystems;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Item;
using Robust.Shared.Containers;
using Robust.Shared.Prototypes;
using Content.Shared.Tools;
using Robust.Shared.GameStates;
using Content.Shared.DoAfter;
using Robust.Shared.Serialization;
namespace Content.Shared.Storage.Components
{
/// <summary>
/// Logic for a secret slot stash, like plant pot or toilet cistern.
/// Unlike <see cref="ItemSlotsComponent"/> it doesn't have interaction logic or verbs.
/// Other classes like <see cref="ToiletComponent"/> should implement it.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(SecretStashSystem))]
public sealed partial class SecretStashComponent : Component
{
/// <summary>
/// Max item size that can be fitted into secret stash.
/// </summary>
[DataField("maxItemSize")]
public ProtoId<ItemSizePrototype> MaxItemSize = "Small";
/// <summary>
/// If stash has way to open then this will switch between open and closed.
/// </summary>
[DataField, AutoNetworkedField]
public bool ToggleOpen;
/// <summary>
/// Prying the door.
/// </summary>
[DataField]
public float PryDoorTime = 1f;
[DataField]
public ProtoId<ToolQualityPrototype> PryingQuality = "Prying";
/// <summary>
/// Is stash openable?.
/// </summary>
[DataField, AutoNetworkedField]
public bool OpenableStash = false;
/// <summary>
/// IC secret stash name. For example "the toilet cistern".
/// If empty string, will replace it with entity name in init.
/// </summary>
[DataField]
public string SecretPartName { get; set; } = "";
[DataField, AutoNetworkedField]
public string ExamineStash = "comp-secret-stash-on-examine-found-hidden-item";
/// <summary>
/// Container used to keep secret stash item.
/// </summary>
[ViewVariables]
public ContainerSlot ItemContainer = default!;
}
/// <summary>
/// Simple pry event for prying open a stash door.
/// </summary>
[Serializable, NetSerializable]
public sealed partial class StashPryDoAfterEvent : SimpleDoAfterEvent
{
}
/// <summary>
/// Visualizers for handling stash open closed state if stash has door.
/// </summary>
[Serializable, NetSerializable]
public enum StashVisuals : byte
{
DoorVisualState,
}
[Serializable, NetSerializable]
public enum DoorVisualState : byte
{
DoorOpen,
DoorClosed
}
}

View File

@@ -0,0 +1,222 @@
using Content.Shared.Popups;
using Content.Shared.Storage.Components;
using Content.Shared.Destructible;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Item;
using Robust.Shared.Containers;
using Content.Shared.Interaction;
using Content.Shared.Tools.Systems;
using Content.Shared.Examine;
namespace Content.Shared.Storage.EntitySystems
{
/// <summary>
/// Secret Stash allows an item to be hidden within.
/// </summary>
public sealed class SecretStashSystem : EntitySystem
{
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
[Dependency] private readonly SharedItemSystem _item = default!;
[Dependency] private readonly SharedToolSystem _tool = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SecretStashComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<SecretStashComponent, DestructionEventArgs>(OnDestroyed);
SubscribeLocalEvent<SecretStashComponent, StashPryDoAfterEvent>(OnSecretStashPried);
SubscribeLocalEvent<SecretStashComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<SecretStashComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<SecretStashComponent, ExaminedEvent>(OnExamine);
}
private void OnInit(EntityUid uid, SecretStashComponent component, ComponentInit args)
{
component.ItemContainer = _containerSystem.EnsureContainer<ContainerSlot>(uid, "stash", out _);
}
private void OnDestroyed(EntityUid uid, SecretStashComponent component, DestructionEventArgs args)
{
_containerSystem.EmptyContainer(component.ItemContainer);
}
/// <summary>
/// Is there something inside secret stash item container?
/// </summary>
public bool HasItemInside(EntityUid uid, SecretStashComponent? component = null)
{
if (!Resolve(uid, ref component))
return false;
return component.ItemContainer.ContainedEntity != null;
}
private void OnInteractUsing(EntityUid uid, SecretStashComponent component, InteractUsingEvent args)
{
if (args.Handled)
return;
if (!component.OpenableStash)
return;
// is player trying place or lift off cistern lid?
if (_tool.UseTool(args.Used, args.User, uid, component.PryDoorTime, component.PryingQuality, new StashPryDoAfterEvent()))
args.Handled = true;
// maybe player is trying to hide something inside cistern?
else if (component.ToggleOpen)
{
TryHideItem(uid, args.User, args.Used);
args.Handled = true;
}
}
private void OnInteractHand(EntityUid uid, SecretStashComponent component, InteractHandEvent args)
{
if (args.Handled)
return;
if (!component.OpenableStash)
return;
// trying to get something from stash?
if (component.ToggleOpen)
{
var gotItem = TryGetItem(uid, args.User);
if (gotItem)
{
args.Handled = true;
return;
}
}
args.Handled = true;
}
private void OnSecretStashPried(EntityUid uid, SecretStashComponent component, StashPryDoAfterEvent args)
{
if (args.Cancelled)
return;
ToggleOpen(uid, component);
}
public void ToggleOpen(EntityUid uid, SecretStashComponent? component = null, MetaDataComponent? meta = null)
{
if (!Resolve(uid, ref component))
return;
component.ToggleOpen = !component.ToggleOpen;
UpdateAppearance(uid, component);
Dirty(uid, component, meta);
}
private void UpdateAppearance(EntityUid uid, SecretStashComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
_appearance.SetData(uid, StashVisuals.DoorVisualState, component.ToggleOpen ? DoorVisualState.DoorOpen : DoorVisualState.DoorClosed);
}
/// <summary>
/// Tries to hide item inside secret stash from hands of user.
/// </summary>
/// <returns>True if item was hidden inside stash</returns>
public bool TryHideItem(EntityUid uid, EntityUid userUid, EntityUid itemToHideUid,
SecretStashComponent? component = null, ItemComponent? item = null,
HandsComponent? hands = null)
{
if (!Resolve(uid, ref component))
return false;
if (!Resolve(itemToHideUid, ref item))
return false;
if (!Resolve(userUid, ref hands))
return false;
// check if secret stash is already occupied
var container = component.ItemContainer;
if (container.ContainedEntity != null)
{
var msg = Loc.GetString("comp-secret-stash-action-hide-container-not-empty");
_popupSystem.PopupClient(msg, uid, userUid);
return false;
}
// check if item is too big to fit into secret stash
if (_item.GetSizePrototype(item.Size) > _item.GetSizePrototype(component.MaxItemSize))
{
var msg = Loc.GetString("comp-secret-stash-action-hide-item-too-big",
("item", itemToHideUid), ("stash", GetSecretPartName(uid, component)));
_popupSystem.PopupClient(msg, uid, userUid);
return false;
}
// try to move item from hands to stash container
if (!_handsSystem.TryDropIntoContainer(userUid, itemToHideUid, container))
{
return false;
}
// all done, show success message
var successMsg = Loc.GetString("comp-secret-stash-action-hide-success",
("item", itemToHideUid), ("this", GetSecretPartName(uid, component)));
_popupSystem.PopupClient(successMsg, uid, userUid);
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>
/// <returns>True if user received item</returns>
public bool TryGetItem(EntityUid uid, EntityUid userUid, SecretStashComponent? component = null,
HandsComponent? hands = null)
{
if (!Resolve(uid, ref component))
return false;
if (!Resolve(userUid, ref hands))
return false;
// check if secret stash has something inside
var container = component.ItemContainer;
if (container.ContainedEntity == null)
{
return false;
}
_handsSystem.PickupOrDrop(userUid, container.ContainedEntity.Value, handsComp: hands);
// show success message
var successMsg = Loc.GetString("comp-secret-stash-action-get-item-found-something",
("stash", GetSecretPartName(uid, component)));
_popupSystem.PopupClient(successMsg, uid, userUid);
return true;
}
private void OnExamine(EntityUid uid, SecretStashComponent component, ExaminedEvent args)
{
if (args.IsInDetailsRange && component.ToggleOpen)
{
if (HasItemInside(uid))
{
var msg = Loc.GetString(component.ExamineStash);
args.PushMarkup(msg);
}
}
}
private string GetSecretPartName(EntityUid uid, SecretStashComponent stash)
{
if (stash.SecretPartName != "")
return Loc.GetString(stash.SecretPartName);
var entityName = Loc.GetString("comp-secret-stash-secret-part-name", ("this", uid));
return entityName;
}
}
}

View 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
}
}

View 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);
}
}
}

View File

@@ -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
{
}
}

View File

@@ -1,10 +0,0 @@
using Robust.Shared.Serialization;
namespace Content.Shared.Toilet;
[Serializable, NetSerializable]
public enum ToiletVisuals
{
LidOpen,
SeatUp
}