Files
tbd-station-14/Content.Server/GameObjects/Components/Chemistry/RehydratableComponent.cs
py01 2b195fccb9 Chemical reaction refactor (#2936)
* Moves ContainsReagent from SolutionContainer to Solution

GetMajorReagentId from SOlutionContainer to Solution

Makes capability checks use HasFlag

Moves Solution Color calculation from SolutionContainer to Solution

Replaces SolutionContainerCaps.NoExamine with CanExamine

Misc SolutionContainer.Capabilities yaml cleanup

* Moves IReactionEffect from server to shared

* Moves ReactionPrototype from server to shared

* Moves SolutionValidReaction from SolutionContainer to ChemicalReactionSystem

* Moves PerformReaction from SolutionContainer to ChemicalReactionSystem

* Moves CheckForReaction from SolutionContainer to ChemicalReactionSystem

* Removes unused SolutionContainer methods

* Removes now-unused GetMajorReagentId from SOlutionContainer

* ChemicalReactionSystem comments

* Replaces usage of SolutionContainer.ContainsReagent and replaces it with SolutionContainer.Solution.ContainsReagent

* ChemicalReactionSystem ProcessReactions

* Moves ExplosionReactionEffect to shared, comments out server code, TODO: figure out how to let ReactionEffects in shared do server stuff

* Fixes SolutionContainer.CheckForReaction infinite recursion

* Moves IReactionEffect and ExplosionReactionEffect back to server

* Moves ChemicalReactionSystem and ReactionPrototype back to server

* Uncomments out Explosion code

* namespace fixes

* Moves ReactionPrototype and IReactionEffect from Server to Shared

* Moves ChemicalReactionSystem from Server to Shared

* ChemicalReaction code partial rewrite

* Moves CanReact and PerformReaction to Solution

* Revert "Moves CanReact and PerformReaction to Solution"

This reverts commit bab791c3ebd0ff39d22f2610e27ca04f0d46d6b8.

* Moves ChemistrySystem from Server to Shared

* diff fix

* TODO warning

Co-authored-by: py01 <pyronetics01@gmail.com>
2021-01-07 17:31:43 +11:00

76 lines
2.7 KiB
C#

#nullable enable
using Content.Server.Utility;
using Content.Shared.Chemistry;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Chemistry
{
/// <summary>
/// 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.
/// </summary>
[RegisterComponent]
[ComponentReference(typeof(IReagentReaction))]
[ComponentReference(typeof(ISolutionChange))]
public class RehydratableComponent : Component, IReagentReaction, ISolutionChange
{
public override string Name => "Rehydratable";
[ViewVariables]
private string _catalystPrototype = "";
[ViewVariables]
private string? _targetPrototype;
private bool _expanding;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _catalystPrototype, "catalyst", "chem.Water");
serializer.DataField(ref _targetPrototype, "target", null);
}
ReagentUnit IReagentReaction.ReagentReactTouch(ReagentPrototype reagent, ReagentUnit volume) => Reaction(reagent, volume);
ReagentUnit IReagentReaction.ReagentReactInjection(ReagentPrototype reagent, ReagentUnit volume) => Reaction(reagent, volume);
private ReagentUnit Reaction(ReagentPrototype reagent, ReagentUnit volume)
{
if ((volume > ReagentUnit.Zero) && (reagent.ID == _catalystPrototype))
{
Expand();
}
return ReagentUnit.Zero;
}
void ISolutionChange.SolutionChanged(SolutionChangeEventArgs eventArgs)
{
var solution = eventArgs.Owner.GetComponent<SolutionContainerComponent>();
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("{0:TheName} expands!", Owner));
if (!string.IsNullOrEmpty(_targetPrototype))
{
Owner.EntityManager.SpawnEntity(_targetPrototype, Owner.Transform.Coordinates);
}
Owner.Delete();
}
}
}