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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user