artifact soups (#14067)

This commit is contained in:
Nemanja
2023-02-15 14:06:45 -05:00
committed by GitHub
parent ac45d89776
commit 4adfec9548
4 changed files with 155 additions and 3 deletions

View File

@@ -0,0 +1,54 @@
using Content.Server.Fluids.EntitySystems;
using Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components;
using Content.Server.Xenoarchaeology.XenoArtifacts.Events;
using Robust.Shared.Random;
namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems;
/// <summary>
/// This handles <see cref="ChemicalPuddleArtifactComponent"/>
/// </summary>
public sealed class ChemicalPuddleArtifactSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ArtifactSystem _artifact = default!;
[Dependency] private readonly SpillableSystem _spillable = default!;
/// <summary>
/// The key for the node data entry containing
/// the chemicals that the puddle is made of.
/// </summary>
public const string NodeDataChemicalList = "nodeDataSpawnAmount";
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<ChemicalPuddleArtifactComponent, ArtifactActivatedEvent>(OnActivated);
}
private void OnActivated(EntityUid uid, ChemicalPuddleArtifactComponent component, ArtifactActivatedEvent args)
{
if (!TryComp<ArtifactComponent>(uid, out var artifact))
return;
if (!_artifact.TryGetNodeData(uid, NodeDataChemicalList, out List<string>? chemicalList, artifact))
{
chemicalList = new();
for (var i = 0; i < component.ChemAmount; i++)
{
var chemProto = _random.Pick(component.PossibleChemicals);
chemicalList.Add(chemProto);
}
_artifact.SetNodeData(uid, NodeDataChemicalList, chemicalList, artifact);
}
var amountPerChem = component.ChemicalSolution.MaxVolume / component.ChemAmount;
foreach (var reagent in chemicalList)
{
component.ChemicalSolution.AddReagent(reagent, amountPerChem);
}
_spillable.SpillAt(uid, component.ChemicalSolution, component.PuddlePrototype);
}
}