ChemicalPuddleArtifactSystem.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using Content.Server.Fluids.EntitySystems;
  2. using Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components;
  3. using Content.Server.Xenoarchaeology.XenoArtifacts.Events;
  4. using Robust.Shared.Random;
  5. namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems;
  6. /// <summary>
  7. /// This handles <see cref="ChemicalPuddleArtifactComponent"/>
  8. /// </summary>
  9. public sealed class ChemicalPuddleArtifactSystem : EntitySystem
  10. {
  11. [Dependency] private readonly IRobustRandom _random = default!;
  12. [Dependency] private readonly ArtifactSystem _artifact = default!;
  13. [Dependency] private readonly PuddleSystem _puddle = default!;
  14. /// <summary>
  15. /// The key for the node data entry containing
  16. /// the chemicals that the puddle is made of.
  17. /// </summary>
  18. public const string NodeDataChemicalList = "nodeDataChemicalList";
  19. /// <inheritdoc/>
  20. public override void Initialize()
  21. {
  22. SubscribeLocalEvent<ChemicalPuddleArtifactComponent, ArtifactActivatedEvent>(OnActivated);
  23. }
  24. private void OnActivated(EntityUid uid, ChemicalPuddleArtifactComponent component, ArtifactActivatedEvent args)
  25. {
  26. if (!TryComp<ArtifactComponent>(uid, out var artifact))
  27. return;
  28. if (!_artifact.TryGetNodeData(uid, NodeDataChemicalList, out List<string>? chemicalList, artifact))
  29. {
  30. chemicalList = new();
  31. for (var i = 0; i < component.ChemAmount; i++)
  32. {
  33. var chemProto = _random.Pick(component.PossibleChemicals);
  34. chemicalList.Add(chemProto);
  35. }
  36. _artifact.SetNodeData(uid, NodeDataChemicalList, chemicalList, artifact);
  37. }
  38. var amountPerChem = component.ChemicalSolution.MaxVolume / component.ChemAmount;
  39. foreach (var reagent in chemicalList)
  40. {
  41. component.ChemicalSolution.AddReagent(reagent, amountPerChem);
  42. }
  43. _puddle.TrySpillAt(uid, component.ChemicalSolution, out _);
  44. }
  45. }