Fire extinguisher safety (#4912)
* Moved safety into FireExtinguisherComponent. * Fix errant find and replace * Address reviews Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -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<bool>(SprayVisuals.Safety, out var safety))
|
||||
if (component.TryGetData<bool>(FireExtinguisherVisuals.Safety, out var safety))
|
||||
{
|
||||
SetSafety(component, safety);
|
||||
}
|
||||
@@ -27,11 +27,11 @@ namespace Content.Client.Fluids
|
||||
{
|
||||
var sprite = component.Owner.GetComponent<ISpriteComponent>();
|
||||
|
||||
sprite.LayerSetState(SprayVisualLayers.Base, safety ? _safetyOnState : _safetyOffState);
|
||||
sprite.LayerSetState(FireExtinguisherVisualLayers.Base, safety ? _safetyOnState : _safetyOffState);
|
||||
}
|
||||
}
|
||||
|
||||
public enum SprayVisualLayers : byte
|
||||
public enum FireExtinguisherVisualLayers : byte
|
||||
{
|
||||
Base
|
||||
}
|
||||
@@ -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<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
|
||||
{
|
||||
var solutionContainerSystem = EntitySystem.Get<SolutionContainerSystem>();
|
||||
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<ActionBlockerSystem>().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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
|
||||
{
|
||||
if (!EntitySystem.Get<ActionBlockerSystem>().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<ActionBlockerSystem>().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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -10,8 +10,8 @@ namespace Content.Shared.Fluids
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum SprayVisuals
|
||||
public enum SprayVisuals : byte
|
||||
{
|
||||
Safety,
|
||||
Safety
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
fire-extinguisher-component-after-interact-refilled-message = {$owner} is now refilled
|
||||
fire-extinguisher-component-after-interact-refilled-message = {$owner} is now refilled
|
||||
fire-extinguisher-component-safety-on-message = Its safety is on!
|
||||
@@ -1,2 +1 @@
|
||||
spray-component-safety-on-message = Its safety is on!
|
||||
spray-component-is-empty-message = It's empty!
|
||||
spray-component-is-empty-message = It's empty!
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user