Reaction sound re-added (#2990)

* Reaction sound re-added

* Moves reaction sound file to reaction prototype

Co-authored-by: py01 <pyronetics01@gmail.com>
This commit is contained in:
py01
2021-01-14 01:06:23 -06:00
committed by GitHub
parent 6a19dd9f02
commit 4c80082555
5 changed files with 39 additions and 6 deletions

View File

@@ -0,0 +1,9 @@
using Content.Shared.GameObjects.EntitySystems;
namespace Content.Client.GameObjects.EntitySystems.NewFolder
{
public class ChemicalReactionSystem : SharedChemicalReactionSystem
{
}
}

View File

@@ -0,0 +1,17 @@
using Content.Shared.Chemistry;
using Content.Shared.GameObjects.EntitySystems;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.Interfaces.GameObjects;
namespace Content.Server.GameObjects.EntitySystems.NewFolder
{
public class ChemicalReactionSystem : SharedChemicalReactionSystem
{
protected override void OnReaction(ReactionPrototype reaction, IEntity owner, ReagentUnit unitReactions)
{
base.OnReaction(reaction, owner, unitReactions);
Get<AudioSystem>().PlayAtCoords(reaction.Sound, owner.Transform.Coordinates);
}
}
}

View File

@@ -36,6 +36,8 @@ namespace Content.Shared.Chemistry
/// </summary> /// </summary>
public IReadOnlyList<IReactionEffect> Effects => _effects; public IReadOnlyList<IReactionEffect> Effects => _effects;
public string Sound { get; private set; }
[Dependency] private readonly IModuleManager _moduleManager = default!; [Dependency] private readonly IModuleManager _moduleManager = default!;
public void LoadFrom(YamlMappingNode mapping) public void LoadFrom(YamlMappingNode mapping)
@@ -46,6 +48,7 @@ namespace Content.Shared.Chemistry
serializer.DataField(ref _name, "name", string.Empty); serializer.DataField(ref _name, "name", string.Empty);
serializer.DataField(ref _reactants, "reactants", new Dictionary<string, ReactantPrototype>()); serializer.DataField(ref _reactants, "reactants", new Dictionary<string, ReactantPrototype>());
serializer.DataField(ref _products, "products", new Dictionary<string, ReagentUnit>()); serializer.DataField(ref _products, "products", new Dictionary<string, ReagentUnit>());
serializer.DataField(this, x => x.Sound, "sound", "/Audio/Effects/Chemistry/bubbles.ogg");
if (_moduleManager.IsServerModule) if (_moduleManager.IsServerModule)
{ {

View File

@@ -179,7 +179,7 @@ namespace Content.Shared.GameObjects.Components.Chemistry
if (!CanReact) if (!CanReact)
return; return;
EntitySystem.Get<ChemicalReactionSystem>() EntitySystem.Get<SharedChemicalReactionSystem>()
.FullyReactSolution(Solution, Owner, MaxVolume); .FullyReactSolution(Solution, Owner, MaxVolume);
} }

View File

@@ -8,8 +8,7 @@ using System.Collections.Generic;
namespace Content.Shared.GameObjects.EntitySystems namespace Content.Shared.GameObjects.EntitySystems
{ {
//TODO: Reimplement sounds for reactions public abstract class SharedChemicalReactionSystem : EntitySystem
public class ChemicalReactionSystem : EntitySystem
{ {
private IEnumerable<ReactionPrototype> _reactions; private IEnumerable<ReactionPrototype> _reactions;
@@ -56,7 +55,7 @@ namespace Content.Shared.GameObjects.EntitySystems
/// Perform a reaction on a solution. This assumes all reaction criteria are met. /// Perform a reaction on a solution. This assumes all reaction criteria are met.
/// Removes the reactants from the solution, then returns a solution with all products. /// Removes the reactants from the solution, then returns a solution with all products.
/// </summary> /// </summary>
private static Solution PerformReaction(Solution solution, IEntity owner, ReactionPrototype reaction, ReagentUnit unitReactions) private Solution PerformReaction(Solution solution, IEntity owner, ReactionPrototype reaction, ReagentUnit unitReactions)
{ {
//Remove reactants //Remove reactants
foreach (var reactant in reaction.Reactants) foreach (var reactant in reaction.Reactants)
@@ -76,12 +75,17 @@ namespace Content.Shared.GameObjects.EntitySystems
} }
// Trigger reaction effects // Trigger reaction effects
OnReaction(reaction, owner, unitReactions);
return products;
}
protected virtual void OnReaction(ReactionPrototype reaction, IEntity owner, ReagentUnit unitReactions)
{
foreach (var effect in reaction.Effects) foreach (var effect in reaction.Effects)
{ {
effect.React(owner, unitReactions.Double()); effect.React(owner, unitReactions.Double());
} }
return products;
} }
/// <summary> /// <summary>