Entity Reagent Reactions v2 (#3714)
* Refactors reactions to be more POWERFUL and DATA-ORIENTED
This commit is contained in:
committed by
GitHub
parent
6739d6a6a9
commit
a6f04e22e4
@@ -1,8 +1,13 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.GameObjects.Components.Chemistry;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.GameObjects.EntitySystems
|
||||
{
|
||||
@@ -25,6 +30,8 @@ namespace Content.Shared.GameObjects.EntitySystems
|
||||
[UsedImplicitly]
|
||||
public class ChemistrySystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
public void HandleSolutionChange(IEntity owner)
|
||||
{
|
||||
var eventArgs = new SolutionChangeEventArgs
|
||||
@@ -41,5 +48,27 @@ namespace Content.Shared.GameObjects.EntitySystems
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void ReactionEntity(IEntity? entity, ReactionMethod method, string reagentId, ReagentUnit reactVolume, Solution? source)
|
||||
{
|
||||
// We throw if the reagent specified doesn't exist.
|
||||
ReactionEntity(entity, method, _prototypeManager.Index<ReagentPrototype>(reagentId), reactVolume, source);
|
||||
}
|
||||
|
||||
public void ReactionEntity(IEntity? entity, ReactionMethod method, ReagentPrototype reagent, ReagentUnit reactVolume, Solution? source)
|
||||
{
|
||||
if (entity == null || entity.Deleted || !entity.TryGetComponent(out ReactiveComponent? reactive))
|
||||
return;
|
||||
|
||||
foreach (var reaction in reactive.Reactions)
|
||||
{
|
||||
// If we have a source solution, use the reagent quantity we have left. Otherwise, use the reaction volume specified.
|
||||
reaction.React(method, entity, reagent, source?.GetReagentQuantity(reagent.ID) ?? reactVolume, source);
|
||||
|
||||
// Make sure we still have enough reagent to go...
|
||||
if (source != null && !source.ContainsReagent(reagent.ID))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user