Puddles & spreader refactor (#15191)

This commit is contained in:
metalgearsloth
2023-04-10 15:37:03 +10:00
committed by GitHub
parent 3178ab83f6
commit 317a4013eb
141 changed files with 3046 additions and 3201 deletions

View File

@@ -0,0 +1,18 @@
using Robust.Shared.GameStates;
namespace Content.Shared.Chemistry.Components;
/// <summary>
/// Denotes the solution that can be easily removed through any reagent container.
/// Think pouring this or draining from a water tank.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed class DrainableSolutionComponent : Component
{
/// <summary>
/// Solution name that can be drained.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("solution")]
public string Solution { get; set; } = "default";
}

View File

@@ -0,0 +1,27 @@
using Content.Shared.FixedPoint;
using Robust.Shared.GameStates;
namespace Content.Shared.Chemistry.Components;
/// <summary>
/// Reagents that can be added easily. For example like
/// pouring something into another beaker, glass, or into the gas
/// tank of a car.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed class RefillableSolutionComponent : Component
{
/// <summary>
/// Solution name that can added to easily.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("solution")]
public string Solution { get; set; } = "default";
/// <summary>
/// The maximum amount that can be transferred to the solution at once
/// </summary>
[DataField("maxRefill")]
[ViewVariables(VVAccess.ReadWrite)]
public FixedPoint2? MaxRefill { get; set; } = null;
}

View File

@@ -432,6 +432,18 @@ namespace Content.Shared.Chemistry.Components
_heatCapacity = 0;
}
/// <summary>
/// Splits a solution without the specified reagent.
/// </summary>
public Solution SplitSolutionWithout(FixedPoint2 toTake, string without)
{
TryGetReagent(without, out var existing);
RemoveReagent(without, toTake);
var sol = SplitSolution(toTake);
AddReagent(without, existing);
return sol;
}
public Solution SplitSolution(FixedPoint2 toTake)
{
if (toTake <= FixedPoint2.Zero)
@@ -599,7 +611,7 @@ namespace Content.Shared.Chemistry.Components
ValidateSolution();
}
public Color GetColor(IPrototypeManager? protoMan)
public Color GetColorWithout(IPrototypeManager? protoMan, params string[] without)
{
if (Volume == FixedPoint2.Zero)
{
@@ -614,6 +626,9 @@ namespace Content.Shared.Chemistry.Components
foreach (var reagent in Contents)
{
if (without.Contains(reagent.ReagentId))
continue;
runningTotalQuantity += reagent.Quantity;
if (!protoMan.TryIndex(reagent.ReagentId, out ReagentPrototype? proto))
@@ -634,6 +649,11 @@ namespace Content.Shared.Chemistry.Components
return mixColor;
}
public Color GetColor(IPrototypeManager? protoMan)
{
return GetColorWithout(protoMan);
}
[Obsolete("Use ReactiveSystem.DoEntityReaction")]
public void DoEntityReaction(EntityUid uid, ReactionMethod method)
{

View File

@@ -250,7 +250,10 @@ namespace Content.Shared.Chemistry.Reaction
return false;
// Remove any reactions that were not applicable. Avoids re-iterating over them in future.
reactions.Except(toRemove);
foreach (var proto in toRemove)
{
reactions.Remove(proto);
}
if (products.Volume <= 0)
return true;

View File

@@ -5,6 +5,7 @@ using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reaction;
using Content.Shared.Database;
using Content.Shared.FixedPoint;
using Robust.Shared.Audio;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
@@ -73,6 +74,12 @@ namespace Content.Shared.Chemistry.Reagent
[DataField("metamorphicSprite")]
public SpriteSpecifier? MetamorphicSprite { get; } = null;
/// <summary>
/// If this reagent is part of a puddle is it slippery.
/// </summary>
[DataField("slippery")]
public bool Slippery = false;
[DataField("metabolisms", serverOnly: true, customTypeSerializer: typeof(PrototypeIdDictionarySerializer<ReagentEffectsEntry, MetabolismGroupPrototype>))]
public Dictionary<string, ReagentEffectsEntry>? Metabolisms = null;
@@ -85,26 +92,11 @@ namespace Content.Shared.Chemistry.Reagent
[DataField("plantMetabolism", serverOnly: true)]
public readonly List<ReagentEffect> PlantMetabolisms = new(0);
[DataField("pricePerUnit")]
public float PricePerUnit { get; }
[DataField("pricePerUnit")] public float PricePerUnit;
/// <summary>
/// If the substance color is too dark we user a lighter version to make the text color readable when the user examines a solution.
/// </summary>
public Color GetSubstanceTextColor()
{
var highestValue = MathF.Max(SubstanceColor.R, MathF.Max(SubstanceColor.G, SubstanceColor.B));
var difference = 0.5f - highestValue;
if (difference > 0f)
{
return new Color(SubstanceColor.R + difference,
SubstanceColor.G + difference,
SubstanceColor.B + difference);
}
return SubstanceColor;
}
// TODO: Pick the highest reagent for sounds and add sticky to cola, juice, etc.
[DataField("footstepSound")]
public SoundSpecifier FootstepSound = new SoundCollectionSpecifier("FootstepWater");
public FixedPoint2 ReactionTile(TileRef tile, FixedPoint2 reactVolume)
{