From e621a82e657a8096bdf0b7c579d6ac9604732051 Mon Sep 17 00:00:00 2001 From: StStevens Date: Mon, 25 Oct 2021 00:04:24 -0700 Subject: [PATCH] Fire extinguisher safety (#4912) * Moved safety into FireExtinguisherComponent. * Fix errant find and replace * Address reviews Co-authored-by: metalgearsloth --- .../FireExtinguisherVisualizer.cs} | 12 ++-- .../Extinguisher/FireExtinguisherComponent.cs | 66 ++++++++++++++++++- .../Fluids/Components/SprayComponent.cs | 60 +---------------- .../SharedFireExtinguisherComponent.cs | 17 +++++ Content.Shared/Fluids/SharedSprayComponent.cs | 4 +- .../fire-extinguisher-component.ftl | 3 +- .../fluids/components/spray-component.ftl | 3 +- .../Objects/Misc/fire_extinguisher.yml | 6 +- 8 files changed, 95 insertions(+), 76 deletions(-) rename Content.Client/{Fluids/SprayVisualizer.cs => Extinguisher/FireExtinguisherVisualizer.cs} (64%) create mode 100644 Content.Shared/Extinguisher/SharedFireExtinguisherComponent.cs diff --git a/Content.Client/Fluids/SprayVisualizer.cs b/Content.Client/Extinguisher/FireExtinguisherVisualizer.cs similarity index 64% rename from Content.Client/Fluids/SprayVisualizer.cs rename to Content.Client/Extinguisher/FireExtinguisherVisualizer.cs index db89a5fa5e..ddeeb510ab 100644 --- a/Content.Client/Fluids/SprayVisualizer.cs +++ b/Content.Client/Extinguisher/FireExtinguisherVisualizer.cs @@ -1,12 +1,12 @@ -using Content.Shared.Fluids; +using Content.Shared.Extinguisher; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; -namespace Content.Client.Fluids +namespace Content.Client.Extinguisher { [UsedImplicitly] - public class SprayVisualizer : AppearanceVisualizer + public class FireExtinguisherVisualizer : AppearanceVisualizer { [DataField("safety_on_state")] private string? _safetyOnState; @@ -17,7 +17,7 @@ namespace Content.Client.Fluids { base.OnChangeData(component); - if (component.TryGetData(SprayVisuals.Safety, out var safety)) + if (component.TryGetData(FireExtinguisherVisuals.Safety, out var safety)) { SetSafety(component, safety); } @@ -27,11 +27,11 @@ namespace Content.Client.Fluids { var sprite = component.Owner.GetComponent(); - sprite.LayerSetState(SprayVisualLayers.Base, safety ? _safetyOnState : _safetyOffState); + sprite.LayerSetState(FireExtinguisherVisualLayers.Base, safety ? _safetyOnState : _safetyOffState); } } - public enum SprayVisualLayers : byte + public enum FireExtinguisherVisualLayers : byte { Base } diff --git a/Content.Server/Extinguisher/FireExtinguisherComponent.cs b/Content.Server/Extinguisher/FireExtinguisherComponent.cs index eb40b6cd90..4f4a5cba6e 100644 --- a/Content.Server/Extinguisher/FireExtinguisherComponent.cs +++ b/Content.Server/Extinguisher/FireExtinguisherComponent.cs @@ -1,10 +1,15 @@ +using System; using System.Threading.Tasks; using Content.Server.Chemistry.Components; +using Content.Shared.ActionBlocker; +using Content.Shared.Audio; using Content.Shared.Chemistry.EntitySystems; using Content.Shared.Chemistry.Reagent; using Content.Shared.Interaction; using Content.Shared.Popups; using Content.Shared.Sound; +using Content.Shared.Extinguisher; +using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.Localization; @@ -14,20 +19,42 @@ using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Extinguisher { [RegisterComponent] - public class FireExtinguisherComponent : Component, IAfterInteract + public class FireExtinguisherComponent : SharedFireExtinguisherComponent, IAfterInteract, IUse, IActivate, IDropped { public override string Name => "FireExtinguisher"; - [DataField("refillSound")] SoundSpecifier _refillSound = new SoundPathSpecifier("/Audio/Effects/refill.ogg"); + [DataField("refillSound")] + SoundSpecifier _refillSound = new SoundPathSpecifier("/Audio/Effects/refill.ogg"); + [DataField("hasSafety")] + private bool _hasSafety; + [DataField("safety")] + private bool _safety = true; + [DataField("safetySound")] + public SoundSpecifier SafetySound { get; } = new SoundPathSpecifier("/Audio/Machines/button.ogg"); // Higher priority than sprays. int IAfterInteract.Priority => 1; + protected override void Initialize() + { + base.Initialize(); + + if (_hasSafety) + { + SetSafety(Owner, _safety); + } + } + async Task IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs) { var solutionContainerSystem = EntitySystem.Get(); if (eventArgs.Target == null || !eventArgs.CanReach) { + if (_hasSafety && _safety) + { + Owner.PopupMessage(eventArgs.User, Loc.GetString("fire-extinguisher-component-safety-on-message")); + return true; + } return false; } @@ -44,7 +71,7 @@ namespace Content.Server.Extinguisher SoundSystem.Play(Filter.Pvs(Owner), _refillSound.GetSound(), Owner); eventArgs.Target.PopupMessage(eventArgs.User, - Loc.GetString("fire-extinguisher-component-after-interact-refilled-message", ("owner", Owner))); + Loc.GetString("fire-extingusiher-component-after-interact-refilled-message", ("owner", Owner))); } return true; @@ -52,5 +79,38 @@ namespace Content.Server.Extinguisher return false; } + bool IUse.UseEntity(UseEntityEventArgs eventArgs) + { + ToggleSafety(eventArgs.User); + return true; + } + + void IActivate.Activate(ActivateEventArgs eventArgs) + { + ToggleSafety(eventArgs.User); + } + + private void ToggleSafety(IEntity user) + { + SoundSystem.Play(Filter.Pvs(Owner), SafetySound.GetSound(), Owner, AudioHelpers.WithVariation(0.125f).WithVolume(-4f)); + SetSafety(user, !_safety); + } + + private void SetSafety(IEntity user, bool state) + { + if (!EntitySystem.Get().CanInteract(user) || !_hasSafety) + return; + + _safety = state; + + if (Owner.TryGetComponent(out AppearanceComponent? appearance)) + appearance.SetData(FireExtinguisherVisuals.Safety, _safety); + } + + void IDropped.Dropped(DroppedEventArgs eventArgs) + { + if (_hasSafety && Owner.TryGetComponent(out AppearanceComponent? appearance)) + appearance.SetData(FireExtinguisherVisuals.Safety, _safety); + } } } diff --git a/Content.Server/Fluids/Components/SprayComponent.cs b/Content.Server/Fluids/Components/SprayComponent.cs index 7363d3d9df..4f507aae3e 100644 --- a/Content.Server/Fluids/Components/SprayComponent.cs +++ b/Content.Server/Fluids/Components/SprayComponent.cs @@ -27,7 +27,7 @@ using Robust.Shared.ViewVariables; namespace Content.Server.Fluids.Components { [RegisterComponent] - internal sealed class SprayComponent : SharedSprayComponent, IAfterInteract, IUse, IActivate, IDropped + internal sealed class SprayComponent : SharedSprayComponent, IAfterInteract { public const float SprayDistance = 3f; public const string SolutionName = "spray"; @@ -50,10 +50,6 @@ namespace Content.Server.Fluids.Components private int _vaporAmount = 1; [DataField("vaporSpread")] private float _vaporSpread = 90f; - [DataField("hasSafety")] - private bool _hasSafety; - [DataField("safety")] - private bool _safety = true; [DataField("impulse")] private float _impulse = 0f; @@ -80,10 +76,6 @@ namespace Content.Server.Fluids.Components [DataField("spraySound", required: true)] public SoundSpecifier SpraySound { get; } = default!; - [DataField("safetySound")] - public SoundSpecifier SafetySound { get; } = new SoundPathSpecifier("/Audio/Machines/button.ogg"); - - public ReagentUnit CurrentVolume { get { @@ -92,27 +84,11 @@ namespace Content.Server.Fluids.Components } } - protected override void Initialize() - { - base.Initialize(); - - if (_hasSafety) - { - SetSafety(Owner, _safety); - } - } - async Task IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs) { if (!EntitySystem.Get().CanInteract(eventArgs.User)) return false; - if (_hasSafety && _safety) - { - Owner.PopupMessage(eventArgs.User, Loc.GetString("spray-component-safety-on-message")); - return true; - } - if (CurrentVolume <= 0) { Owner.PopupMessage(eventArgs.User, Loc.GetString("spray-component-is-empty-message")); @@ -196,39 +172,5 @@ namespace Content.Server.Fluids.Components return true; } - - bool IUse.UseEntity(UseEntityEventArgs eventArgs) - { - ToggleSafety(eventArgs.User); - return true; - } - - void IActivate.Activate(ActivateEventArgs eventArgs) - { - ToggleSafety(eventArgs.User); - } - - private void ToggleSafety(IEntity user) - { - SoundSystem.Play(Filter.Pvs(Owner), SafetySound.GetSound(), Owner, AudioHelpers.WithVariation(0.125f).WithVolume(-4f)); - SetSafety(user, !_safety); - } - - private void SetSafety(IEntity user, bool state) - { - if (!EntitySystem.Get().CanInteract(user) || !_hasSafety) - return; - - _safety = state; - - if(Owner.TryGetComponent(out AppearanceComponent? appearance)) - appearance.SetData(SprayVisuals.Safety, _safety); - } - - void IDropped.Dropped(DroppedEventArgs eventArgs) - { - if(_hasSafety && Owner.TryGetComponent(out AppearanceComponent? appearance)) - appearance.SetData(SprayVisuals.Safety, _safety); - } } } diff --git a/Content.Shared/Extinguisher/SharedFireExtinguisherComponent.cs b/Content.Shared/Extinguisher/SharedFireExtinguisherComponent.cs new file mode 100644 index 0000000000..1aebe3f40e --- /dev/null +++ b/Content.Shared/Extinguisher/SharedFireExtinguisherComponent.cs @@ -0,0 +1,17 @@ +using System; +using Robust.Shared.GameObjects; +using Robust.Shared.Serialization; + +namespace Content.Shared.Extinguisher +{ + public abstract class SharedFireExtinguisherComponent : Component + { + public override string Name => "FireExtinguisher"; + } + + [Serializable, NetSerializable] + public enum FireExtinguisherVisuals : byte + { + Safety + } +} diff --git a/Content.Shared/Fluids/SharedSprayComponent.cs b/Content.Shared/Fluids/SharedSprayComponent.cs index ef46ea9644..c9fc212aaf 100644 --- a/Content.Shared/Fluids/SharedSprayComponent.cs +++ b/Content.Shared/Fluids/SharedSprayComponent.cs @@ -10,8 +10,8 @@ namespace Content.Shared.Fluids } [Serializable, NetSerializable] - public enum SprayVisuals + public enum SprayVisuals : byte { - Safety, + Safety } } diff --git a/Resources/Locale/en-US/fire-extinguisher/fire-extinguisher-component.ftl b/Resources/Locale/en-US/fire-extinguisher/fire-extinguisher-component.ftl index 184a136317..a252faa086 100644 --- a/Resources/Locale/en-US/fire-extinguisher/fire-extinguisher-component.ftl +++ b/Resources/Locale/en-US/fire-extinguisher/fire-extinguisher-component.ftl @@ -1 +1,2 @@ -fire-extinguisher-component-after-interact-refilled-message = {$owner} is now refilled \ No newline at end of file +fire-extinguisher-component-after-interact-refilled-message = {$owner} is now refilled +fire-extinguisher-component-safety-on-message = Its safety is on! \ No newline at end of file diff --git a/Resources/Locale/en-US/fluids/components/spray-component.ftl b/Resources/Locale/en-US/fluids/components/spray-component.ftl index 7b4acaee69..e7060f2287 100644 --- a/Resources/Locale/en-US/fluids/components/spray-component.ftl +++ b/Resources/Locale/en-US/fluids/components/spray-component.ftl @@ -1,2 +1 @@ -spray-component-safety-on-message = Its safety is on! -spray-component-is-empty-message = It's empty! \ No newline at end of file +spray-component-is-empty-message = It's empty! diff --git a/Resources/Prototypes/Entities/Objects/Misc/fire_extinguisher.yml b/Resources/Prototypes/Entities/Objects/Misc/fire_extinguisher.yml index 0ddf3cfd09..76149520c6 100644 --- a/Resources/Prototypes/Entities/Objects/Misc/fire_extinguisher.yml +++ b/Resources/Prototypes/Entities/Objects/Misc/fire_extinguisher.yml @@ -9,7 +9,7 @@ sprite: Objects/Misc/fire_extinguisher.rsi layers: - state: fire_extinguisher_closed - map: [ "enum.SprayVisualLayers.Base" ] + map: [ "enum.FireExtinguisherVisualLayers.Base" ] - type: Item sprite: Objects/Misc/fire_extinguisher.rsi size: 10 @@ -29,7 +29,6 @@ spraySound: path: /Audio/Effects/extinguish.ogg sprayedPrototype: ExtinguisherSpray - hasSafety: true vaporAmount: 3 vaporSpread: 90 sprayVelocity: 2.0 @@ -37,6 +36,7 @@ transferAmount: 5 impulse: 50.0 - type: FireExtinguisher + hasSafety: true - type: MeleeWeapon damage: types: @@ -45,7 +45,7 @@ path: /Audio/Weapons/smash.ogg - type: Appearance visuals: - - type: SprayVisualizer + - type: FireExtinguisherVisualizer safety_on_state: fire_extinguisher_closed safety_off_state: fire_extinguisher_open