Entity Reagent Reactions v2 (#3714)
* Refactors reactions to be more POWERFUL and DATA-ORIENTED
This commit is contained in:
committed by
GitHub
parent
6739d6a6a9
commit
a6f04e22e4
@@ -0,0 +1,27 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Content.Server.GameObjects.Components.Chemistry;
|
||||||
|
using Content.Shared.Chemistry;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||||
|
|
||||||
|
namespace Content.Server.Chemistry.ReagentEntityReactions
|
||||||
|
{
|
||||||
|
[UsedImplicitly]
|
||||||
|
[DataDefinition]
|
||||||
|
public class AddToSolutionReaction : ReagentEntityReaction
|
||||||
|
{
|
||||||
|
[DataField("reagents", true, customTypeSerializer:typeof(PrototypeIdHashSetSerializer<ReagentPrototype>))]
|
||||||
|
// ReSharper disable once CollectionNeverUpdated.Local
|
||||||
|
private readonly HashSet<string> _reagents = new ();
|
||||||
|
|
||||||
|
protected override void React(IEntity entity, ReagentPrototype reagent, ReagentUnit volume, Solution? source)
|
||||||
|
{
|
||||||
|
if (!entity.TryGetComponent(out SolutionContainerComponent? solutionContainer) || (_reagents.Count > 0 && !_reagents.Contains(reagent.ID))) return;
|
||||||
|
|
||||||
|
if(solutionContainer.TryAddReagent(reagent.ID, volume, out var accepted))
|
||||||
|
source?.RemoveReagent(reagent.ID, accepted);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Content.Server.GameObjects.Components.Atmos;
|
||||||
|
using Content.Shared.Chemistry;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||||
|
|
||||||
|
namespace Content.Server.Chemistry.ReagentEntityReactions
|
||||||
|
{
|
||||||
|
[UsedImplicitly]
|
||||||
|
[DataDefinition]
|
||||||
|
public class ExtinguishReaction : ReagentEntityReaction
|
||||||
|
{
|
||||||
|
[DataField("reagents", true, customTypeSerializer:typeof(PrototypeIdHashSetSerializer<ReagentPrototype>))]
|
||||||
|
// ReSharper disable once CollectionNeverUpdated.Local
|
||||||
|
private readonly HashSet<string> _reagents = new ();
|
||||||
|
|
||||||
|
protected override void React(IEntity entity, ReagentPrototype reagent, ReagentUnit volume, Solution? source)
|
||||||
|
{
|
||||||
|
if (!entity.TryGetComponent(out FlammableComponent? flammable) || !_reagents.Contains(reagent.ID)) return;
|
||||||
|
|
||||||
|
flammable.Extinguish();
|
||||||
|
flammable.AdjustFireStacks(-1.5f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Content.Server.GameObjects.Components.Atmos;
|
||||||
|
using Content.Shared.Chemistry;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||||
|
|
||||||
|
namespace Content.Server.Chemistry.ReagentEntityReactions
|
||||||
|
{
|
||||||
|
[UsedImplicitly]
|
||||||
|
[DataDefinition]
|
||||||
|
public class FlammableReaction : ReagentEntityReaction
|
||||||
|
{
|
||||||
|
[DataField("reagents", true, customTypeSerializer:typeof(PrototypeIdHashSetSerializer<ReagentPrototype>))]
|
||||||
|
// ReSharper disable once CollectionNeverUpdated.Local
|
||||||
|
private readonly HashSet<string> _reagents = new ();
|
||||||
|
|
||||||
|
protected override void React(IEntity entity, ReagentPrototype reagent, ReagentUnit volume, Solution? source)
|
||||||
|
{
|
||||||
|
if (!entity.TryGetComponent(out FlammableComponent? flammable) || !_reagents.Contains(reagent.ID)) return;
|
||||||
|
|
||||||
|
flammable.AdjustFireStacks(volume.Float() / 10f);
|
||||||
|
source?.RemoveReagent(reagent.ID, volume);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Content.Server.GameObjects.Components.Nutrition;
|
||||||
|
using Content.Shared.Chemistry;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||||
|
|
||||||
|
namespace Content.Server.Chemistry.ReagentEntityReactions
|
||||||
|
{
|
||||||
|
[UsedImplicitly]
|
||||||
|
[DataDefinition]
|
||||||
|
public class WashCreamPieReaction : ReagentEntityReaction
|
||||||
|
{
|
||||||
|
[DataField("reagents", true, customTypeSerializer:typeof(PrototypeIdHashSetSerializer<ReagentPrototype>))]
|
||||||
|
// ReSharper disable once CollectionNeverUpdated.Local
|
||||||
|
private readonly HashSet<string> _reagents = new ();
|
||||||
|
|
||||||
|
protected override void React(IEntity entity, ReagentPrototype reagent, ReagentUnit volume, Solution? source)
|
||||||
|
{
|
||||||
|
if (!entity.TryGetComponent(out CreamPiedComponent? creamPied) || !_reagents.Contains(reagent.ID)) return;
|
||||||
|
|
||||||
|
creamPied.Wash();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,7 +25,7 @@ using Robust.Shared.ViewVariables;
|
|||||||
namespace Content.Server.GameObjects.Components.Atmos
|
namespace Content.Server.GameObjects.Components.Atmos
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public class FlammableComponent : SharedFlammableComponent, IStartCollide, IFireAct, IReagentReaction, IInteractUsing
|
public class FlammableComponent : SharedFlammableComponent, IStartCollide, IFireAct, IInteractUsing
|
||||||
{
|
{
|
||||||
private bool _resisting = false;
|
private bool _resisting = false;
|
||||||
private readonly List<EntityUid> _collided = new();
|
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)
|
public async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
|
||||||
{
|
{
|
||||||
foreach (var hotItem in eventArgs.Using.GetAllComponents<IHotItem>())
|
foreach (var hotItem in eventArgs.Using.GetAllComponents<IHotItem>())
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ using Robust.Shared.ViewVariables;
|
|||||||
namespace Content.Server.GameObjects.Components.Botany
|
namespace Content.Server.GameObjects.Components.Botany
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
[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 HydroponicsSpeedMultiplier = 1f;
|
||||||
public const float HydroponicsConsumptionMultiplier = 4f;
|
public const float HydroponicsConsumptionMultiplier = 4f;
|
||||||
@@ -807,24 +807,6 @@ namespace Content.Server.GameObjects.Components.Botany
|
|||||||
return false;
|
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)
|
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
|
||||||
{
|
{
|
||||||
// DoHarvest does the sanity checks.
|
// DoHarvest does the sanity checks.
|
||||||
|
|||||||
@@ -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.
|
/// But specifically, this component deletes the entity and spawns in a new entity when the entity is exposed to a given reagent.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
[ComponentReference(typeof(IReagentReaction))]
|
|
||||||
[ComponentReference(typeof(ISolutionChange))]
|
[ComponentReference(typeof(ISolutionChange))]
|
||||||
public class RehydratableComponent : Component, IReagentReaction, ISolutionChange
|
public class RehydratableComponent : Component, ISolutionChange
|
||||||
{
|
{
|
||||||
public override string Name => "Rehydratable";
|
public override string Name => "Rehydratable";
|
||||||
|
|
||||||
@@ -28,22 +27,10 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
|||||||
private string _catalystPrototype = "chem.Water";
|
private string _catalystPrototype = "chem.Water";
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
[DataField("target")]
|
[DataField("target")]
|
||||||
private string? _targetPrototype;
|
private string? _targetPrototype = default!;
|
||||||
|
|
||||||
private bool _expanding;
|
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)
|
void ISolutionChange.SolutionChanged(SolutionChangeEventArgs eventArgs)
|
||||||
{
|
{
|
||||||
var solution = eventArgs.Owner.GetComponent<SolutionContainerComponent>();
|
var solution = eventArgs.Owner.GetComponent<SolutionContainerComponent>();
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using Content.Server.GameObjects.Components.Body.Circulatory;
|
|||||||
using Content.Server.GameObjects.Components.Body.Respiratory;
|
using Content.Server.GameObjects.Components.Body.Respiratory;
|
||||||
using Content.Shared.Chemistry;
|
using Content.Shared.Chemistry;
|
||||||
using Content.Shared.GameObjects.Components.Chemistry;
|
using Content.Shared.GameObjects.Components.Chemistry;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Content.Shared.Interfaces.GameObjects.Components;
|
using Content.Shared.Interfaces.GameObjects.Components;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
@@ -37,6 +38,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
|||||||
internals.AreInternalsWorking())
|
internals.AreInternalsWorking())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var chemistry = EntitySystem.Get<ChemistrySystem>();
|
||||||
var cloneSolution = SolutionContainerComponent.Solution.Clone();
|
var cloneSolution = SolutionContainerComponent.Solution.Clone();
|
||||||
var transferAmount = ReagentUnit.Min(cloneSolution.TotalVolume * solutionFraction, bloodstream.EmptyVolume);
|
var transferAmount = ReagentUnit.Min(cloneSolution.TotalVolume * solutionFraction, bloodstream.EmptyVolume);
|
||||||
var transferSolution = cloneSolution.SplitSolution(transferAmount);
|
var transferSolution = cloneSolution.SplitSolution(transferAmount);
|
||||||
@@ -44,8 +46,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
|||||||
foreach (var reagentQuantity in transferSolution.Contents.ToArray())
|
foreach (var reagentQuantity in transferSolution.Contents.ToArray())
|
||||||
{
|
{
|
||||||
if (reagentQuantity.Quantity == ReagentUnit.Zero) continue;
|
if (reagentQuantity.Quantity == ReagentUnit.Zero) continue;
|
||||||
var reagent = PrototypeManager.Index<ReagentPrototype>(reagentQuantity.ReagentId);
|
chemistry.ReactionEntity(entity, ReactionMethod.Ingestion, reagentQuantity.ReagentId, reagentQuantity.Quantity, transferSolution);
|
||||||
transferSolution.RemoveReagent(reagentQuantity.ReagentId,reagent.ReactionEntity(entity, ReactionMethod.Ingestion, reagentQuantity.Quantity));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bloodstream.TryTransferSolution(transferSolution);
|
bloodstream.TryTransferSolution(transferSolution);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using Content.Server.GameObjects.Components.Atmos;
|
using Content.Server.GameObjects.Components.Atmos;
|
||||||
using Content.Server.Utility;
|
using Content.Server.Utility;
|
||||||
using Content.Shared.Chemistry;
|
using Content.Shared.Chemistry;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Content.Shared.Interfaces.GameObjects.Components;
|
using Content.Shared.Interfaces.GameObjects.Components;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
@@ -130,6 +131,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
|||||||
if (SolutionContainerComponent == null)
|
if (SolutionContainerComponent == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var chemistry = EntitySystem.Get<ChemistrySystem>();
|
||||||
var mapGrid = MapManager.GetGrid(Owner.Transform.GridID);
|
var mapGrid = MapManager.GetGrid(Owner.Transform.GridID);
|
||||||
var tile = mapGrid.GetTileRef(Owner.Transform.Coordinates.ToVector2i(Owner.EntityManager, MapManager));
|
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
|
// Touch every entity on the tile
|
||||||
foreach (var entity in tile.GetEntitiesInTileFast().ToArray())
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ using Robust.Shared.ViewVariables;
|
|||||||
namespace Content.Server.GameObjects.Components.Nutrition
|
namespace Content.Server.GameObjects.Components.Nutrition
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public class CreamPiedComponent : SharedCreamPiedComponent, IReagentReaction, IThrowCollide
|
public class CreamPiedComponent : SharedCreamPiedComponent, IThrowCollide
|
||||||
{
|
{
|
||||||
private bool _creamPied;
|
private bool _creamPied;
|
||||||
|
|
||||||
@@ -38,19 +38,6 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
|||||||
CreamPied = false;
|
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)
|
void IThrowCollide.HitBy(ThrowCollideEventArgs eventArgs)
|
||||||
{
|
{
|
||||||
if (eventArgs.Thrown.Deleted || !eventArgs.Thrown.TryGetComponent(out CreamPieComponent? creamPie)) return;
|
if (eventArgs.Thrown.Deleted || !eventArgs.Thrown.TryGetComponent(out CreamPieComponent? creamPie)) return;
|
||||||
|
|||||||
56
Content.Shared/Chemistry/ReagentEntityReaction.cs
Normal file
56
Content.Shared/Chemistry/ReagentEntityReaction.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using Content.Shared.Interfaces.GameObjects.Components;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
|
using Robust.Shared.ViewVariables;
|
||||||
|
|
||||||
|
namespace Content.Shared.Chemistry
|
||||||
|
{
|
||||||
|
public enum ReactionMethod
|
||||||
|
{
|
||||||
|
Touch,
|
||||||
|
Injection,
|
||||||
|
Ingestion,
|
||||||
|
}
|
||||||
|
|
||||||
|
[DataDefinition]
|
||||||
|
public abstract class ReagentEntityReaction
|
||||||
|
{
|
||||||
|
[ViewVariables]
|
||||||
|
[field: DataField("touch")]
|
||||||
|
public bool Touch { get; } = false;
|
||||||
|
|
||||||
|
[ViewVariables]
|
||||||
|
[field: DataField("injection")]
|
||||||
|
public bool Injection { get; } = false;
|
||||||
|
|
||||||
|
[ViewVariables]
|
||||||
|
[field: DataField("ingestion")]
|
||||||
|
public bool Ingestion { get; } = false;
|
||||||
|
|
||||||
|
public void React(ReactionMethod method, IEntity entity, ReagentPrototype reagent, ReagentUnit volume, Solution? source)
|
||||||
|
{
|
||||||
|
switch (method)
|
||||||
|
{
|
||||||
|
case ReactionMethod.Touch:
|
||||||
|
if (!Touch)
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
case ReactionMethod.Injection:
|
||||||
|
if(!Injection)
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
case ReactionMethod.Ingestion:
|
||||||
|
if(!Ingestion)
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(method), method, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
React(entity, reagent, volume, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void React(IEntity entity, ReagentPrototype reagent, ReagentUnit volume, Solution? source);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -82,38 +82,6 @@ namespace Content.Shared.Chemistry
|
|||||||
return SubstanceColor;
|
return SubstanceColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReagentUnit ReactionEntity(IEntity? entity, ReactionMethod method, ReagentUnit reactVolume)
|
|
||||||
{
|
|
||||||
var removed = ReagentUnit.Zero;
|
|
||||||
|
|
||||||
if (entity == null || entity.Deleted)
|
|
||||||
return removed;
|
|
||||||
|
|
||||||
foreach (var react in entity.GetAllComponents<IReagentReaction>())
|
|
||||||
{
|
|
||||||
switch (method)
|
|
||||||
{
|
|
||||||
case ReactionMethod.Touch:
|
|
||||||
removed += react.ReagentReactTouch(this, reactVolume);
|
|
||||||
break;
|
|
||||||
case ReactionMethod.Ingestion:
|
|
||||||
removed += react.ReagentReactIngestion(this, reactVolume);
|
|
||||||
break;
|
|
||||||
case ReactionMethod.Injection:
|
|
||||||
removed += react.ReagentReactInjection(this, reactVolume);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (removed > reactVolume)
|
|
||||||
throw new Exception("Removed more than we have!");
|
|
||||||
|
|
||||||
if (removed == reactVolume)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return removed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ReagentUnit ReactionTile(TileRef tile, ReagentUnit reactVolume)
|
public ReagentUnit ReactionTile(TileRef tile, ReagentUnit reactVolume)
|
||||||
{
|
{
|
||||||
var removed = ReagentUnit.Zero;
|
var removed = ReagentUnit.Zero;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Collections;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Content.Shared.Interfaces.GameObjects.Components;
|
using Content.Shared.Interfaces.GameObjects.Components;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
@@ -314,15 +315,11 @@ namespace Content.Shared.Chemistry
|
|||||||
|
|
||||||
public void DoEntityReaction(IEntity entity, ReactionMethod method)
|
public void DoEntityReaction(IEntity entity, ReactionMethod method)
|
||||||
{
|
{
|
||||||
var proto = IoCManager.Resolve<IPrototypeManager>();
|
var chemistry = EntitySystem.Get<ChemistrySystem>();
|
||||||
|
|
||||||
foreach (var (reagentId, quantity) in _contents.ToArray())
|
foreach (var (reagentId, quantity) in _contents.ToArray())
|
||||||
{
|
{
|
||||||
if (!proto.TryIndex(reagentId, out ReagentPrototype? reagent))
|
chemistry.ReactionEntity(entity, method, reagentId, quantity, this);
|
||||||
continue;
|
|
||||||
|
|
||||||
var removedAmount = reagent.ReactionEntity(entity, method, quantity);
|
|
||||||
RemoveReagent(reagentId, removedAmount);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using Content.Shared.Chemistry;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
|
|
||||||
|
namespace Content.Shared.GameObjects.Components.Chemistry
|
||||||
|
{
|
||||||
|
[RegisterComponent]
|
||||||
|
public class ReactiveComponent : Component
|
||||||
|
{
|
||||||
|
public override string Name => "Reactive";
|
||||||
|
|
||||||
|
[field: DataField("reactions", true, serverOnly:true)]
|
||||||
|
public ReagentEntityReaction[] Reactions { get; } = Array.Empty<ReagentEntityReaction>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Content.Shared.Chemistry;
|
||||||
|
using Content.Shared.GameObjects.Components.Chemistry;
|
||||||
|
using Content.Shared.Interfaces.GameObjects.Components;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
|
|
||||||
namespace Content.Shared.GameObjects.EntitySystems
|
namespace Content.Shared.GameObjects.EntitySystems
|
||||||
{
|
{
|
||||||
@@ -25,6 +30,8 @@ namespace Content.Shared.GameObjects.EntitySystems
|
|||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public class ChemistrySystem : EntitySystem
|
public class ChemistrySystem : EntitySystem
|
||||||
{
|
{
|
||||||
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
|
|
||||||
public void HandleSolutionChange(IEntity owner)
|
public void HandleSolutionChange(IEntity owner)
|
||||||
{
|
{
|
||||||
var eventArgs = new SolutionChangeEventArgs
|
var eventArgs = new SolutionChangeEventArgs
|
||||||
@@ -41,5 +48,27 @@ namespace Content.Shared.GameObjects.EntitySystems
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ReactionEntity(IEntity? entity, ReactionMethod method, string reagentId, ReagentUnit reactVolume, Solution? source)
|
||||||
|
{
|
||||||
|
// We throw if the reagent specified doesn't exist.
|
||||||
|
ReactionEntity(entity, method, _prototypeManager.Index<ReagentPrototype>(reagentId), reactVolume, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ReactionEntity(IEntity? entity, ReactionMethod method, ReagentPrototype reagent, ReagentUnit reactVolume, Solution? source)
|
||||||
|
{
|
||||||
|
if (entity == null || entity.Deleted || !entity.TryGetComponent(out ReactiveComponent? reactive))
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (var reaction in reactive.Reactions)
|
||||||
|
{
|
||||||
|
// If we have a source solution, use the reagent quantity we have left. Otherwise, use the reaction volume specified.
|
||||||
|
reaction.React(method, entity, reagent, source?.GetReagentQuantity(reagent.ID) ?? reactVolume, source);
|
||||||
|
|
||||||
|
// Make sure we still have enough reagent to go...
|
||||||
|
if (source != null && !source.ContainsReagent(reagent.ID))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
|
using System.Linq;
|
||||||
using Content.Shared.GameObjects.Components.Movement;
|
using Content.Shared.GameObjects.Components.Movement;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
@@ -11,7 +12,7 @@ namespace Content.Shared.GameObjects.EntitySystems
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Update(float frameTime)
|
public override void Update(float frameTime)
|
||||||
{
|
{
|
||||||
foreach (var slipperyComp in ComponentManager.EntityQuery<SlipperyComponent>(false))
|
foreach (var slipperyComp in ComponentManager.EntityQuery<SlipperyComponent>().ToArray())
|
||||||
{
|
{
|
||||||
slipperyComp.Update();
|
slipperyComp.Update();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
#nullable enable
|
|
||||||
using Content.Shared.Chemistry;
|
|
||||||
using Robust.Shared.Analyzers;
|
|
||||||
|
|
||||||
namespace Content.Shared.Interfaces.GameObjects.Components
|
|
||||||
{
|
|
||||||
public enum ReactionMethod
|
|
||||||
{
|
|
||||||
Touch,
|
|
||||||
Injection,
|
|
||||||
Ingestion,
|
|
||||||
}
|
|
||||||
|
|
||||||
[RequiresExplicitImplementation]
|
|
||||||
public interface IReagentReaction
|
|
||||||
{
|
|
||||||
ReagentUnit ReagentReactTouch(ReagentPrototype reagent, ReagentUnit volume) => ReagentUnit.Zero;
|
|
||||||
ReagentUnit ReagentReactInjection(ReagentPrototype reagent, ReagentUnit volume) => ReagentUnit.Zero;
|
|
||||||
ReagentUnit ReagentReactIngestion(ReagentPrototype reagent, ReagentUnit volume) => ReagentUnit.Zero;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -41,6 +41,19 @@
|
|||||||
- type: AtmosExposed
|
- type: AtmosExposed
|
||||||
- type: Flammable
|
- type: Flammable
|
||||||
fireSpread: true
|
fireSpread: true
|
||||||
|
- type: Reactive
|
||||||
|
reactions:
|
||||||
|
- !type:ExtinguishReaction
|
||||||
|
touch: true
|
||||||
|
reagents:
|
||||||
|
- chem.Water
|
||||||
|
- !type:FlammableReaction
|
||||||
|
touch: true
|
||||||
|
reagents:
|
||||||
|
- chem.WeldingFuel
|
||||||
|
- chem.Thermite
|
||||||
|
- chem.Plasma
|
||||||
|
- chem.Ethanol
|
||||||
- type: Appearance
|
- type: Appearance
|
||||||
visuals:
|
visuals:
|
||||||
- type: FireVisualizer
|
- type: FireVisualizer
|
||||||
|
|||||||
@@ -44,6 +44,9 @@
|
|||||||
caps: Refillable
|
caps: Refillable
|
||||||
- type: SnapGrid
|
- type: SnapGrid
|
||||||
offset: Center
|
offset: Center
|
||||||
|
- type: Reactive
|
||||||
|
reactions:
|
||||||
|
- !type:AddToSolutionReaction
|
||||||
- type: Appearance
|
- type: Appearance
|
||||||
visuals:
|
visuals:
|
||||||
- type: PlantHolderVisualizer
|
- type: PlantHolderVisualizer
|
||||||
|
|||||||
@@ -7,6 +7,19 @@
|
|||||||
- type: Tag
|
- type: Tag
|
||||||
tags:
|
tags:
|
||||||
- Teleportable
|
- Teleportable
|
||||||
|
- type: Reactive
|
||||||
|
reactions:
|
||||||
|
- !type:ExtinguishReaction
|
||||||
|
touch: true
|
||||||
|
reagents:
|
||||||
|
- chem.Water
|
||||||
|
- !type:FlammableReaction
|
||||||
|
touch: true
|
||||||
|
reagents:
|
||||||
|
- chem.WeldingFuel
|
||||||
|
- chem.Thermite
|
||||||
|
- chem.Plasma
|
||||||
|
- chem.Ethanol
|
||||||
- type: UtilityAI
|
- type: UtilityAI
|
||||||
behaviorSets:
|
behaviorSets:
|
||||||
- Clothing
|
- Clothing
|
||||||
|
|||||||
@@ -10,6 +10,24 @@
|
|||||||
tags:
|
tags:
|
||||||
- Teleportable
|
- Teleportable
|
||||||
- FootstepSound
|
- FootstepSound
|
||||||
|
- type: Reactive
|
||||||
|
reactions:
|
||||||
|
- !type:ExtinguishReaction
|
||||||
|
touch: true
|
||||||
|
reagents:
|
||||||
|
- chem.Water
|
||||||
|
- !type:FlammableReaction
|
||||||
|
touch: true
|
||||||
|
reagents:
|
||||||
|
- chem.WeldingFuel
|
||||||
|
- chem.Thermite
|
||||||
|
- chem.Plasma
|
||||||
|
- chem.Ethanol
|
||||||
|
- !type:WashCreamPieReaction
|
||||||
|
touch: true
|
||||||
|
reagents:
|
||||||
|
- chem.Water
|
||||||
|
- chem.SpaceCleaner
|
||||||
- type: Flashable
|
- type: Flashable
|
||||||
- type: Hands
|
- type: Hands
|
||||||
- type: MovementSpeedModifier
|
- type: MovementSpeedModifier
|
||||||
|
|||||||
@@ -85,12 +85,20 @@
|
|||||||
state: pda-clown
|
state: pda-clown
|
||||||
- type: Slippery
|
- type: Slippery
|
||||||
paralyzeTime: 4
|
paralyzeTime: 4
|
||||||
|
- type: CollisionWake
|
||||||
|
enabled: false
|
||||||
- type: Physics
|
- type: Physics
|
||||||
fixtures:
|
bodyType: KinematicController
|
||||||
|
mass: 2.5
|
||||||
|
fixtures: # TODO: Make a second fixture.
|
||||||
- shape:
|
- shape:
|
||||||
!type:PhysShapeAabb
|
!type:PhysShapeAabb
|
||||||
bounds: "-0.25,-0.25,0.25,0.25"
|
bounds: "-0.3,-0.4,0.3,0.4"
|
||||||
|
hard: false
|
||||||
layer:
|
layer:
|
||||||
|
- SmallImpassable
|
||||||
|
mask:
|
||||||
|
- Impassable
|
||||||
- MobImpassable
|
- MobImpassable
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
|
|||||||
@@ -48,6 +48,7 @@
|
|||||||
- state: extinguish
|
- state: extinguish
|
||||||
map: [ "enum.VaporVisualLayers.Base" ]
|
map: [ "enum.VaporVisualLayers.Base" ]
|
||||||
- type: Physics
|
- type: Physics
|
||||||
|
bodyType: KinematicController
|
||||||
fixtures:
|
fixtures:
|
||||||
- shape:
|
- shape:
|
||||||
!type:PhysShapeAabb
|
!type:PhysShapeAabb
|
||||||
|
|||||||
@@ -189,7 +189,7 @@
|
|||||||
- state: chempuff
|
- state: chempuff
|
||||||
map: [ "enum.VaporVisualLayers.Base" ]
|
map: [ "enum.VaporVisualLayers.Base" ]
|
||||||
- type: Physics
|
- type: Physics
|
||||||
bodyType: Dynamic
|
bodyType: KinematicController
|
||||||
fixtures:
|
fixtures:
|
||||||
- shape:
|
- shape:
|
||||||
!type:PhysShapeAabb
|
!type:PhysShapeAabb
|
||||||
|
|||||||
@@ -13,8 +13,31 @@
|
|||||||
caps: Refillable
|
caps: Refillable
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
sprite: Objects/Consumable/Food/monkeycube.rsi
|
sprite: Objects/Consumable/Food/monkeycube.rsi
|
||||||
|
- type: Reactive
|
||||||
|
reactions:
|
||||||
|
- !type:AddToSolutionReaction
|
||||||
|
touch: true
|
||||||
|
ingestion: true
|
||||||
|
injection: true
|
||||||
|
reagents:
|
||||||
|
- chem.Water
|
||||||
- type: Rehydratable
|
- type: Rehydratable
|
||||||
target: MonkeyMob_Content
|
target: MonkeyMob_Content
|
||||||
|
- type: CollisionWake
|
||||||
|
enabled: false
|
||||||
|
- type: Physics
|
||||||
|
bodyType: KinematicController
|
||||||
|
mass: 2.5
|
||||||
|
fixtures: # TODO: Make a second fixture.
|
||||||
|
- shape:
|
||||||
|
!type:PhysShapeAabb
|
||||||
|
bounds: "-0.3,-0.4,0.3,0.4"
|
||||||
|
hard: false
|
||||||
|
layer:
|
||||||
|
- SmallImpassable
|
||||||
|
mask:
|
||||||
|
- Impassable
|
||||||
|
- MobImpassable
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: PlushieCarp
|
parent: PlushieCarp
|
||||||
@@ -29,5 +52,28 @@
|
|||||||
Quantity: 10
|
Quantity: 10
|
||||||
maxVol: 11 # needs room for water
|
maxVol: 11 # needs room for water
|
||||||
caps: Refillable
|
caps: Refillable
|
||||||
|
- type: Reactive
|
||||||
|
reactions:
|
||||||
|
- !type:AddToSolutionReaction
|
||||||
|
touch: true
|
||||||
|
ingestion: true
|
||||||
|
injection: true
|
||||||
|
reagents:
|
||||||
|
- chem.Water
|
||||||
- type: Rehydratable
|
- type: Rehydratable
|
||||||
target: CarpMob_Content
|
target: CarpMob_Content
|
||||||
|
- type: CollisionWake
|
||||||
|
enabled: false
|
||||||
|
- type: Physics
|
||||||
|
bodyType: KinematicController
|
||||||
|
mass: 2.5
|
||||||
|
fixtures: # TODO: Make a second fixture.
|
||||||
|
- shape:
|
||||||
|
!type:PhysShapeAabb
|
||||||
|
bounds: "-0.4,-0.4,0.4,0.4"
|
||||||
|
hard: false
|
||||||
|
layer:
|
||||||
|
- SmallImpassable
|
||||||
|
mask:
|
||||||
|
- Impassable
|
||||||
|
- MobImpassable
|
||||||
|
|||||||
Reference in New Issue
Block a user