Files
tbd-station-14/Content.Server/Extinguisher/FireExtinguisherComponent.cs
Ygg01 c209e3f29b Solution refactor (#4407)
* Rename SolutionContainerCaps -> Capability

* Move IExamine event to Chemistry System.

* ECS the ISolutionChange into SolutionChangeEvent

* Unify SolutionContainer into a single shared component

* Replace ISolutionInteraction with SolutionContainerComponent

* Move all methods from SolutionContainer to ChemistrySystem

* Refactor EntitySystem calls to Dependencies

* Refactor SolutionContainer to SolutionManager

* Fix yamls

* Fix test fails

* Fix post merge issues

* Fix various issues with SolutionManager

* More fixes

* Fix more components

* Fix events not being directed

* Fixes for Hypospray

* Separate removal and iteration on Metabolism

* Fix creampie problems

* Address some of sloth's issues

* Refactors for Systems

* Refactored solution location

* Fix tests

* Address more sloth issues

* Fix dependency

* Fix merge conflicts

* Add xmldocs for Capabilities components

* Remove HasSolution/TryGetDefaultSolution and Add/Remove Drainable/Refillable

* Replace Grindable/Juiceable with Extractable

* Refactor field names

* Fix Drainable

* Fix some issues with spillable and injector

* Fix issues with Grinder

* Fix Beaker having duplicate solutions

* Fix foaming

* Address some MGS issues

* Fix Uid issues

* Fix errors in solution Tranfer

* Fixed some extra values constant values

* Cola is drinkable now
2021-09-06 23:49:44 +10:00

58 lines
2.2 KiB
C#

using System.Threading.Tasks;
using Content.Server.Chemistry.Components;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Interaction;
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";
private const string SolutionName = "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)
{
var solutionContainerSystem = EntitySystem.Get<SolutionContainerSystem>();
if (eventArgs.Target == null || !eventArgs.CanReach)
{
return false;
}
var targetEntity = eventArgs.Target;
if (eventArgs.Target.HasComponent<ReagentTankComponent>()
&& solutionContainerSystem.TryGetDrainableSolution(targetEntity.Uid, out var targetSolution)
&& solutionContainerSystem.TryGetSolution(Owner, SolutionName, out var container))
{
var transfer = ReagentUnit.Min(container.AvailableVolume, targetSolution.DrainAvailable);
if (transfer > 0)
{
var drained = solutionContainerSystem.Drain(targetEntity.Uid, targetSolution, transfer);
solutionContainerSystem.TryAddSolution(Owner.Uid, container, drained);
SoundSystem.Play(Filter.Pvs(Owner), _refillSound.GetSound(), Owner);
eventArgs.Target.PopupMessage(eventArgs.User,
Loc.GetString("fire-extinguisher-component-after-interact-refilled-message", ("owner", Owner)));
}
return true;
}
return false;
}
}
}