Files
tbd-station-14/Content.Server/Extinguisher/FireExtinguisherComponent.cs
Galactic Chimp f531c65a0b Merge branch 'master' into replace-sounds-with-sound-specifier
# Conflicts:
#	Content.Server/Actions/Actions/DisarmAction.cs
#	Content.Server/Actions/Actions/ScreamAction.cs
#	Content.Server/Arcade/Components/SpaceVillainArcadeComponent.cs
#	Content.Server/Damage/Components/DamageOnHighSpeedImpactComponent.cs
#	Content.Server/Explosion/Components/FlashExplosiveComponent.cs
#	Content.Server/Physics/Controllers/MoverController.cs
#	Content.Server/Portal/Components/PortalComponent.cs
#	Content.Server/Portal/Components/TeleporterComponent.cs
#	Content.Server/Projectiles/Components/ProjectileComponent.cs
#	Content.Server/Singularity/Components/EmitterComponent.cs
#	Content.Server/Sound/EmitSoundSystem.cs
#	Content.Server/Stunnable/Components/StunbatonComponent.cs
#	Content.Server/Tools/Components/MultitoolComponent.cs
#	Content.Server/Weapon/Ranged/Barrels/Components/ServerBatteryBarrelComponent.cs
#	Content.Shared/Gravity/GravityComponent.cs
#	Content.Shared/Light/Component/SharedExpendableLightComponent.cs
#	Content.Shared/Maps/ContentTileDefinition.cs
#	Content.Shared/Slippery/SlipperyComponent.cs
#	Content.Shared/Standing/StandingStateComponent.cs
#	Resources/Prototypes/Entities/Objects/Fun/bike_horn.yml
2021-07-25 14:12:00 +02:00

58 lines
2.1 KiB
C#

using System.Threading.Tasks;
using Content.Server.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Chemistry.Solution.Components;
using Content.Shared.Interaction;
using Content.Shared.Notification;
using Content.Shared.Notification.Managers;
using Content.Shared.Sound;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Player;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Extinguisher
{
[RegisterComponent]
public class FireExtinguisherComponent : Component, IAfterInteract
{
public override string Name => "FireExtinguisher";
[DataField("refillSound")] SoundSpecifier _refillSound = new SoundPathSpecifier("/Audio/Effects/refill.ogg");
// Higher priority than sprays.
int IAfterInteract.Priority => 1;
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
{
if (eventArgs.Target == null || !eventArgs.CanReach)
{
return false;
}
if (eventArgs.Target.TryGetComponent(out ReagentTankComponent? tank)
&& eventArgs.Target.TryGetComponent(out ISolutionInteractionsComponent? targetSolution)
&& targetSolution.CanDrain
&& Owner.TryGetComponent(out SolutionContainerComponent? container))
{
var trans = ReagentUnit.Min(container.EmptyVolume, targetSolution.DrainAvailable);
if (trans > 0)
{
var drained = targetSolution.Drain(trans);
container.TryAddSolution(drained);
if(_refillSound.TryGetSound(out var sound))
SoundSystem.Play(Filter.Pvs(Owner), sound, Owner);
eventArgs.Target.PopupMessage(eventArgs.User, Loc.GetString("fire-extinguisher-component-after-interact-refilled-message",("owner", Owner)));
}
return true;
}
return false;
}
}
}