2021-09-26 15:19:00 +02:00
|
|
|
using Content.Shared.Chemistry.Components;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Chemistry.Reaction;
|
|
|
|
|
using Content.Shared.Chemistry.Reagent;
|
2020-04-08 15:53:15 +05:00
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-03-26 12:02:41 +01:00
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Prototypes;
|
2020-04-08 15:53:15 +05:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Shared.Chemistry
|
2020-04-08 15:53:15 +05:00
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
2021-09-06 15:49:44 +02:00
|
|
|
public partial class ChemistrySystem : EntitySystem
|
2020-04-08 15:53:15 +05:00
|
|
|
{
|
2021-03-26 12:02:41 +01:00
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
|
|
|
|
2021-09-26 15:19:00 +02:00
|
|
|
public void ReactionEntity(IEntity entity, ReactionMethod method, Solution solution)
|
|
|
|
|
{
|
|
|
|
|
foreach (var (id, quantity) in solution)
|
|
|
|
|
{
|
|
|
|
|
ReactionEntity(entity, method, id, quantity, solution);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ReactionEntity(IEntity entity, ReactionMethod method, string reagentId, ReagentUnit reactVolume, Solution? source)
|
2021-03-26 12:02:41 +01:00
|
|
|
{
|
|
|
|
|
// We throw if the reagent specified doesn't exist.
|
|
|
|
|
ReactionEntity(entity, method, _prototypeManager.Index<ReagentPrototype>(reagentId), reactVolume, source);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-26 15:19:00 +02:00
|
|
|
public void ReactionEntity(IEntity entity, ReactionMethod method, ReagentPrototype reagent,
|
|
|
|
|
ReagentUnit reactVolume, Solution? source)
|
2021-03-26 12:02:41 +01:00
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-08 15:53:15 +05:00
|
|
|
}
|
|
|
|
|
}
|