Entity Reagent Reactions v2 (#3714)

* Refactors reactions to be more POWERFUL and DATA-ORIENTED
This commit is contained in:
Vera Aguilera Puerto
2021-03-26 12:02:41 +01:00
committed by GitHub
parent 6739d6a6a9
commit a6f04e22e4
25 changed files with 333 additions and 140 deletions

View File

@@ -25,7 +25,7 @@ using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Atmos
{
[RegisterComponent]
public class FlammableComponent : SharedFlammableComponent, IStartCollide, IFireAct, IReagentReaction, IInteractUsing
public class FlammableComponent : SharedFlammableComponent, IStartCollide, IFireAct, IInteractUsing
{
private bool _resisting = false;
private readonly List<EntityUid> _collided = new();
@@ -205,27 +205,6 @@ namespace Content.Server.GameObjects.Components.Atmos
});
}
ReagentUnit IReagentReaction.ReagentReactTouch(ReagentPrototype reagent, ReagentUnit volume)
{
switch (reagent.ID)
{
case "chem.Water":
Extinguish();
AdjustFireStacks(-1.5f);
return ReagentUnit.Zero;
case "chem.WeldingFuel":
case "chem.Thermite":
case "chem.Plasma":
case "chem.Ethanol":
AdjustFireStacks(volume.Float() / 10f);
return volume;
default:
return ReagentUnit.Zero;
}
}
public async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
{
foreach (var hotItem in eventArgs.Using.GetAllComponents<IHotItem>())

View File

@@ -36,7 +36,7 @@ using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Botany
{
[RegisterComponent]
public class PlantHolderComponent : Component, IInteractUsing, IInteractHand, IActivate, IReagentReaction, IExamine
public class PlantHolderComponent : Component, IInteractUsing, IInteractHand, IActivate, IExamine
{
public const float HydroponicsSpeedMultiplier = 1f;
public const float HydroponicsConsumptionMultiplier = 4f;
@@ -807,24 +807,6 @@ namespace Content.Server.GameObjects.Components.Botany
return false;
}
ReagentUnit IReagentReaction.ReagentReactTouch(ReagentPrototype reagent, ReagentUnit volume)
{
if(_solutionContainer == null)
return ReagentUnit.Zero;
_solutionContainer.TryAddReagent(reagent.ID, volume, out var accepted);
return accepted;
}
ReagentUnit IReagentReaction.ReagentReactInjection(ReagentPrototype reagent, ReagentUnit volume)
{
if(_solutionContainer == null)
return ReagentUnit.Zero;
_solutionContainer.TryAddReagent(reagent.ID, volume, out var accepted);
return accepted;
}
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
{
// DoHarvest does the sanity checks.

View File

@@ -17,9 +17,8 @@ namespace Content.Server.GameObjects.Components.Chemistry
/// 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 class RehydratableComponent : Component, ISolutionChange
{
public override string Name => "Rehydratable";
@@ -28,22 +27,10 @@ namespace Content.Server.GameObjects.Components.Chemistry
private string _catalystPrototype = "chem.Water";
[ViewVariables]
[DataField("target")]
private string? _targetPrototype;
private string? _targetPrototype = default!;
private bool _expanding;
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>();

View File

@@ -4,6 +4,7 @@ using Content.Server.GameObjects.Components.Body.Circulatory;
using Content.Server.GameObjects.Components.Body.Respiratory;
using Content.Shared.Chemistry;
using Content.Shared.GameObjects.Components.Chemistry;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
@@ -37,6 +38,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
internals.AreInternalsWorking())
return;
var chemistry = EntitySystem.Get<ChemistrySystem>();
var cloneSolution = SolutionContainerComponent.Solution.Clone();
var transferAmount = ReagentUnit.Min(cloneSolution.TotalVolume * solutionFraction, bloodstream.EmptyVolume);
var transferSolution = cloneSolution.SplitSolution(transferAmount);
@@ -44,8 +46,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
foreach (var reagentQuantity in transferSolution.Contents.ToArray())
{
if (reagentQuantity.Quantity == ReagentUnit.Zero) continue;
var reagent = PrototypeManager.Index<ReagentPrototype>(reagentQuantity.ReagentId);
transferSolution.RemoveReagent(reagentQuantity.ReagentId,reagent.ReactionEntity(entity, ReactionMethod.Ingestion, reagentQuantity.Quantity));
chemistry.ReactionEntity(entity, ReactionMethod.Ingestion, reagentQuantity.ReagentId, reagentQuantity.Quantity, transferSolution);
}
bloodstream.TryTransferSolution(transferSolution);

View File

@@ -4,6 +4,7 @@ using System.Linq;
using Content.Server.GameObjects.Components.Atmos;
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.IoC;
@@ -130,6 +131,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
if (SolutionContainerComponent == null)
return;
var chemistry = EntitySystem.Get<ChemistrySystem>();
var mapGrid = MapManager.GetGrid(Owner.Transform.GridID);
var tile = mapGrid.GetTileRef(Owner.Transform.Coordinates.ToVector2i(Owner.EntityManager, MapManager));
@@ -146,7 +148,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
// Touch every entity on the tile
foreach (var entity in tile.GetEntitiesInTileFast().ToArray())
{
reagent.ReactionEntity(entity, ReactionMethod.Touch, reagentQuantity.Quantity * solutionFraction);
chemistry.ReactionEntity(entity, ReactionMethod.Touch, reagent, reagentQuantity.Quantity * solutionFraction, SolutionContainerComponent.Solution);
}
}

View File

@@ -12,7 +12,7 @@ using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Nutrition
{
[RegisterComponent]
public class CreamPiedComponent : SharedCreamPiedComponent, IReagentReaction, IThrowCollide
public class CreamPiedComponent : SharedCreamPiedComponent, IThrowCollide
{
private bool _creamPied;
@@ -38,19 +38,6 @@ namespace Content.Server.GameObjects.Components.Nutrition
CreamPied = false;
}
ReagentUnit IReagentReaction.ReagentReactTouch(ReagentPrototype reagent, ReagentUnit volume)
{
switch (reagent.ID)
{
case "chem.SpaceCleaner":
case "chem.Water":
Wash();
break;
}
return ReagentUnit.Zero;
}
void IThrowCollide.HitBy(ThrowCollideEventArgs eventArgs)
{
if (eventArgs.Thrown.Deleted || !eventArgs.Thrown.TryGetComponent(out CreamPieComponent? creamPie)) return;