2021-03-26 12:02:41 +01:00
|
|
|
using System.Collections.Generic;
|
2021-09-06 15:49:44 +02:00
|
|
|
using Content.Shared.Chemistry.Components;
|
|
|
|
|
using Content.Shared.Chemistry.EntitySystems;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Chemistry.Reagent;
|
2021-03-26 12:02:41 +01:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2021-03-26 20:55:14 +01:00
|
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
2021-03-26 12:02:41 +01:00
|
|
|
|
|
|
|
|
namespace Content.Server.Chemistry.ReagentEntityReactions
|
|
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
public class AddToSolutionReaction : ReagentEntityReaction
|
|
|
|
|
{
|
2021-10-19 08:13:43 +01:00
|
|
|
[DataField("solution")]
|
|
|
|
|
private string _solution = "reagents";
|
|
|
|
|
|
2021-09-06 15:49:44 +02:00
|
|
|
[DataField("reagents", true, customTypeSerializer: typeof(PrototypeIdHashSetSerializer<ReagentPrototype>))]
|
2021-03-26 12:02:41 +01:00
|
|
|
// ReSharper disable once CollectionNeverUpdated.Local
|
2021-09-06 15:49:44 +02:00
|
|
|
private readonly HashSet<string> _reagents = new();
|
2021-03-26 12:02:41 +01:00
|
|
|
|
|
|
|
|
protected override void React(IEntity entity, ReagentPrototype reagent, ReagentUnit volume, Solution? source)
|
|
|
|
|
{
|
2021-09-06 15:49:44 +02:00
|
|
|
// TODO see if this is correct
|
|
|
|
|
if (!EntitySystem.Get<SolutionContainerSystem>()
|
2021-10-19 08:13:43 +01:00
|
|
|
.TryGetSolution(entity, _solution, out var solutionContainer)
|
2021-09-06 15:49:44 +02:00
|
|
|
|| (_reagents.Count > 0 && !_reagents.Contains(reagent.ID))) return;
|
2021-03-26 12:02:41 +01:00
|
|
|
|
2021-09-06 15:49:44 +02:00
|
|
|
if (EntitySystem.Get<SolutionContainerSystem>()
|
|
|
|
|
.TryAddReagent(entity.Uid, solutionContainer, reagent.ID, volume, out var accepted))
|
2021-03-26 12:02:41 +01:00
|
|
|
source?.RemoveReagent(reagent.ID, accepted);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|