#nullable enable using Content.Server.Notification; using Content.Shared.Chemistry; using Content.Shared.Chemistry.Reagent; using Robust.Shared.GameObjects; using Robust.Shared.Localization; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.Chemistry.Components { /// /// Basically, monkey cubes. /// But specifically, this component deletes the entity and spawns in a new entity when the entity is exposed to a given reagent. /// [RegisterComponent] [ComponentReference(typeof(ISolutionChange))] public class RehydratableComponent : Component, ISolutionChange { public override string Name => "Rehydratable"; [ViewVariables] [DataField("catalyst")] private string _catalystPrototype = "Water"; [ViewVariables] [DataField("target")] private string? _targetPrototype = default!; private bool _expanding; void ISolutionChange.SolutionChanged(SolutionChangeEventArgs eventArgs) { var solution = eventArgs.Owner.GetComponent(); if (solution.Solution.GetReagentQuantity(_catalystPrototype) > ReagentUnit.Zero) { Expand(); } } // Try not to make this public if you can help it. private void Expand() { if (_expanding) { return; } _expanding = true; Owner.PopupMessageEveryone(Loc.GetString("rehydratable-component-expands-message",("owner", Owner))); if (!string.IsNullOrEmpty(_targetPrototype)) { var ent = Owner.EntityManager.SpawnEntity(_targetPrototype, Owner.Transform.Coordinates); ent.Transform.AttachToGridOrMap(); } Owner.Delete(); } } }