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

@@ -1,39 +0,0 @@
using Content.Shared.Construction;
using Content.Shared.Examine;
using Content.Shared.Toilet;
using JetBrains.Annotations;
namespace Content.Server.Construction.Conditions
{
[UsedImplicitly]
[DataDefinition]
public sealed partial class ToiletLidClosed : IGraphCondition
{
public bool Condition(EntityUid uid, IEntityManager entityManager)
{
if (!entityManager.TryGetComponent(uid, out ToiletComponent? toilet))
return false;
return !toilet.LidOpen;
}
public bool DoExamine(ExaminedEvent args)
{
var entity = args.Examined;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ToiletComponent? toilet)) return false;
if (!toilet.LidOpen) return false;
args.PushMarkup(Loc.GetString("construction-examine-condition-toilet-lid-closed") + "\n");
return true;
}
public IEnumerable<ConstructionGuideEntry> GenerateGuideEntry()
{
yield return new ConstructionGuideEntry()
{
Localization = "construction-step-condition-toilet-lid-closed"
};
}
}
}

View File

@@ -135,8 +135,7 @@ public sealed class DisposalUnitSystem : SharedDisposalUnitSystem
{
// This is not an interaction, activation, or alternative verb type because unfortunately most users are
// unwilling to accept that this is where they belong and don't want to accidentally climb inside.
if (!component.MobsCanEnter ||
!args.CanAccess ||
if (!args.CanAccess ||
!args.CanInteract ||
component.Container.ContainedEntities.Contains(args.User) ||
!_actionBlockerSystem.CanMove(args.User))
@@ -630,10 +629,10 @@ public sealed class DisposalUnitSystem : SharedDisposalUnitSystem
switch (state)
{
case DisposalsPressureState.Flushed:
_appearance.SetData(uid, SharedDisposalUnitComponent.Visuals.VisualState, SharedDisposalUnitComponent.VisualState.Flushing, appearance);
_appearance.SetData(uid, SharedDisposalUnitComponent.Visuals.VisualState, SharedDisposalUnitComponent.VisualState.OverlayFlushing, appearance);
break;
case DisposalsPressureState.Pressurizing:
_appearance.SetData(uid, SharedDisposalUnitComponent.Visuals.VisualState, SharedDisposalUnitComponent.VisualState.Charging, appearance);
_appearance.SetData(uid, SharedDisposalUnitComponent.Visuals.VisualState, SharedDisposalUnitComponent.VisualState.OverlayCharging, appearance);
break;
case DisposalsPressureState.Ready:
_appearance.SetData(uid, SharedDisposalUnitComponent.Visuals.VisualState, SharedDisposalUnitComponent.VisualState.Anchored, appearance);

View File

@@ -1,18 +0,0 @@
using Content.Server.Plants.Systems;
using Content.Server.Storage.Components;
using Robust.Shared.Audio;
namespace Content.Server.Plants.Components
{
/// <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

@@ -1,66 +0,0 @@
using Content.Server.Plants.Components;
using Content.Server.Popups;
using Content.Server.Storage.Components;
using Content.Server.Storage.EntitySystems;
using Content.Shared.Audio;
using Content.Shared.Interaction;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Player;
namespace Content.Server.Plants.Systems
{
public sealed class PottedPlantHideSystem : EntitySystem
{
[Dependency] private readonly PopupSystem _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

@@ -1,5 +1,5 @@
using Content.Server.Popups;
using Content.Server.Storage.Components;
using Content.Shared.Storage.Components;
using Content.Shared.ActionBlocker;
using Content.Shared.DoAfter;
using Content.Shared.Hands.EntitySystems;

View File

@@ -1,39 +0,0 @@
using Content.Server.Storage.EntitySystems;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Item;
using Content.Shared.Toilet;
using Robust.Shared.Containers;
using Robust.Shared.Prototypes;
namespace Content.Server.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]
[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>
/// IC secret stash name. For example "the toilet cistern".
/// If empty string, will replace it with entity name in init.
/// </summary>
[DataField("secretPartName", readOnly: true)]
public string SecretPartName { get; set; } = "";
/// <summary>
/// Container used to keep secret stash item.
/// </summary>
[ViewVariables]
public ContainerSlot ItemContainer = default!;
}
}

View File

@@ -1,131 +0,0 @@
using Content.Server.Popups;
using Content.Server.Storage.Components;
using Content.Shared.Destructible;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Item;
using Robust.Shared.Containers;
namespace Content.Server.Storage.EntitySystems
{
public sealed class SecretStashSystem : EntitySystem
{
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
[Dependency] private readonly SharedItemSystem _item = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SecretStashComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<SecretStashComponent, DestructionEventArgs>(OnDestroyed);
}
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;
}
/// <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.PopupEntity(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.PopupEntity(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.PopupEntity(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.PopupEntity(successMsg, uid, userUid);
return true;
}
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

@@ -1,197 +1,8 @@
using Content.Server.Body.Systems;
using Content.Shared.Buckle;
using Content.Server.Popups;
using Content.Server.Storage.Components;
using Content.Server.Storage.EntitySystems;
using Content.Shared.Audio;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Content.Shared.Buckle.Components;
using Content.Shared.Examine;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Popups;
using Content.Shared.Toilet;
using Content.Shared.Tools;
using Content.Shared.Tools.Components;
using Content.Shared.Verbs;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Player;
using Robust.Shared.Random;
using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
using Content.Shared.Toilet.Systems;
namespace Content.Server.Toilet
namespace Content.Server.Toilet;
public sealed class ToiletSystem : SharedToiletSystem
{
public sealed class ToiletSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly BodySystem _body = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SecretStashSystem _secretStash = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly SharedToolSystem _tool = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ToiletComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<ToiletComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<ToiletComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<ToiletComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<ToiletComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<ToiletComponent, SuicideEvent>(OnSuicide);
SubscribeLocalEvent<ToiletComponent, ToiletPryDoAfterEvent>(OnToiletPried);
SubscribeLocalEvent<ToiletComponent, GetVerbsEvent<AlternativeVerb>>(OnToggleSeatVerb);
}
private void OnSuicide(EntityUid uid, ToiletComponent component, SuicideEvent args)
{
if (args.Handled)
return;
// Check that victim has a head
// FIXME: since suiciding turns you into a ghost immediately, both messages are seen, not sure how this can be fixed
if (TryComp<BodyComponent>(args.Victim, out var body) &&
_body.BodyHasPartType(args.Victim, BodyPartType.Head, body))
{
var othersMessage = Loc.GetString("toilet-component-suicide-head-message-others",
("victim", Identity.Entity(args.Victim, EntityManager)), ("owner", uid));
_popup.PopupEntity(othersMessage, uid, Filter.PvsExcept(args.Victim), true, PopupType.MediumCaution);
var selfMessage = Loc.GetString("toilet-component-suicide-head-message",
("owner", uid));
_popup.PopupEntity(selfMessage, uid, args.Victim, PopupType.LargeCaution);
args.SetHandled(SuicideKind.Asphyxiation);
}
else
{
var othersMessage = Loc.GetString("toilet-component-suicide-message-others",
("victim", Identity.Entity(args.Victim, EntityManager)), ("owner", uid));
_popup.PopupEntity(othersMessage, uid, Filter.PvsExcept(uid), true, PopupType.MediumCaution);
var selfMessage = Loc.GetString("toilet-component-suicide-message",
("owner", uid));
_popup.PopupEntity(selfMessage, uid, args.Victim, PopupType.LargeCaution);
args.SetHandled(SuicideKind.Blunt);
}
}
private void OnInit(EntityUid uid, ToiletComponent component, ComponentInit args)
{
EnsureComp<SecretStashComponent>(uid);
}
private void OnMapInit(EntityUid uid, ToiletComponent component, MapInitEvent args)
{
// roll is toilet seat will be up or down
component.IsSeatUp = _random.Prob(0.5f);
UpdateSprite(uid, component);
}
private void OnInteractUsing(EntityUid uid, ToiletComponent component, InteractUsingEvent args)
{
if (args.Handled)
return;
// are player trying place or lift of cistern lid?
if (_tool.UseTool(args.Used, args.User, uid, component.PryLidTime, component.PryingQuality, new ToiletPryDoAfterEvent()))
{
args.Handled = true;
}
// maybe player trying to hide something inside cistern?
else if (component.LidOpen)
{
args.Handled = true;
_secretStash.TryHideItem(uid, args.User, args.Used);
}
}
private void OnInteractHand(EntityUid uid, ToiletComponent component, InteractHandEvent args)
{
if (args.Handled)
return;
// trying get something from stash?
if (component.LidOpen)
{
var gotItem = _secretStash.TryGetItem(uid, args.User);
if (gotItem)
{
args.Handled = true;
return;
}
}
args.Handled = true;
}
private void OnToggleSeatVerb(EntityUid uid, ToiletComponent component, GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanInteract || !args.CanAccess || !CanToggle(uid))
return;
var alterToiletSeatText = component.IsSeatUp ? Loc.GetString("toilet-seat-close") : Loc.GetString("toilet-seat-open");
var verb = new AlternativeVerb()
{
Act = () => {
if (CanToggle(uid))
ToggleToiletSeat(uid, component);
},
Text = alterToiletSeatText
};
args.Verbs.Add(verb);
}
private void OnExamine(EntityUid uid, ToiletComponent component, ExaminedEvent args)
{
if (args.IsInDetailsRange && component.LidOpen)
{
if (_secretStash.HasItemInside(uid))
{
var msg = Loc.GetString("toilet-component-on-examine-found-hidden-item");
args.PushMarkup(msg);
}
}
}
private void OnToiletPried(EntityUid uid, ToiletComponent toilet, ToiletPryDoAfterEvent args)
{
if (args.Cancelled)
return;
toilet.LidOpen = !toilet.LidOpen;
UpdateSprite(uid, toilet);
}
public bool CanToggle(EntityUid uid)
{
return TryComp<StrapComponent>(uid, out var strap) && strap.BuckledEntities.Count == 0;
}
public void ToggleToiletSeat(EntityUid uid, ToiletComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
component.IsSeatUp = !component.IsSeatUp;
_audio.PlayPvs(component.ToggleSound, uid, AudioParams.Default.WithVariation(SharedContentAudioSystem.DefaultVariation));
UpdateSprite(uid, component);
}
private void UpdateSprite(EntityUid uid, ToiletComponent component)
{
if (!TryComp<AppearanceComponent>(uid, out var appearance))
return;
_appearance.SetData(uid, ToiletVisuals.LidOpen, component.LidOpen, appearance);
_appearance.SetData(uid, ToiletVisuals.SeatUp, component.IsSeatUp, appearance);
}
}
}