Files
tbd-station-14/Content.Server/GameObjects/Components/Chemistry/RehydratableComponent.cs
DrSmugleaf dd385a0511 Change all of body system to use entities and components (#2074)
* Early commit

* Early commit 2

* merging master broke my git

* does anyone even read these

* life is fleeting

* it just works

* this time passing integration tests

* Remove hashset yaml serialization for now

* You got a license for those nullables?

* No examine, no context menu, part and mechanism parenting and visibility

* Fix wrong brain sprite state

* Removing layers was a mistake

* just tear body system a new one and see if it still breathes

* Remove redundant code

* Add that comment back

* Separate damage and body, component states, stomach rework

* Add containers for body parts

* Bring layers back pls

* Fix parts magically changing color

* Reimplement sprite layer visibility

* Fix tests

* Add leg test

* Active legs is gone

Crab rave

* Merge fixes, rename DamageState to CurrentState

* Remove IShowContextMenu and ICanExamine
2020-10-10 15:25:13 +02:00

76 lines
2.7 KiB
C#

#nullable enable
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Utility;
using Content.Shared.Chemistry;
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.H2O");
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();
}
}
}