Generalize ReagentUnit into FixedPoint2 and use it for damage calculations (#5151)

* Damage units

* sum ext method
This commit is contained in:
mirrorcult
2021-11-03 16:48:03 -07:00
committed by GitHub
parent 8165d8f38c
commit 3ab4a30a0f
100 changed files with 730 additions and 601 deletions

View File

@@ -3,6 +3,7 @@ using System.Threading.Tasks;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.DoAfter;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Helpers;
using Content.Shared.Popups;
@@ -26,12 +27,12 @@ namespace Content.Server.Fluids.Components
private List<EntityUid> _currentlyUsing = new();
public ReagentUnit MaxVolume
public FixedPoint2 MaxVolume
{
get =>
EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution)
? solution.MaxVolume
: ReagentUnit.Zero;
: FixedPoint2.Zero;
set
{
if (EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution))
@@ -41,9 +42,9 @@ namespace Content.Server.Fluids.Components
}
}
public ReagentUnit CurrentVolume => EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution)
public FixedPoint2 CurrentVolume => EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution)
? solution.CurrentVolume
: ReagentUnit.Zero;
: FixedPoint2.Zero;
[DataField("sound")]
private SoundSpecifier _sound = new SoundPathSpecifier("/Audio/Effects/Fluids/watersplash.ogg");
@@ -93,7 +94,7 @@ namespace Content.Server.Fluids.Components
// Top up mops solution given it needs it to annihilate puddles I guess
var transferAmount = ReagentUnit.Min(mopComponent.MaxVolume - mopComponent.CurrentVolume, CurrentVolume);
var transferAmount = FixedPoint2.Min(mopComponent.MaxVolume - mopComponent.CurrentVolume, CurrentVolume);
if (transferAmount == 0)
{
return false;

View File

@@ -1,5 +1,6 @@
using Content.Server.Fluids.EntitySystems;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
@@ -13,7 +14,7 @@ namespace Content.Server.Fluids.Components
public override string Name => "Evaporation";
/// <summary>
/// The time that it will take this puddle to lose one reagent unit of solution, in seconds.
/// The time that it will take this puddle to lose one fixed unit of solution, in seconds.
/// </summary>
[DataField("evaporateTime")]
public float EvaporateTime { get; set; } = 5f;
@@ -29,14 +30,14 @@ namespace Content.Server.Fluids.Components
/// Defaults to evaporate completely.
/// </summary>
[DataField("lowerLimit")]
public ReagentUnit LowerLimit = ReagentUnit.Zero;
public FixedPoint2 LowerLimit = FixedPoint2.Zero;
/// <summary>
/// Upper limit below which puddle won't evaporate. Useful when wanting to make sure large puddle will
/// remain forever. Defaults to <see cref="PuddleComponent.DefaultOverflowVolume"/>.
/// </summary>
[DataField("upperLimit")]
public ReagentUnit UpperLimit = PuddleComponent.DefaultOverflowVolume;
public FixedPoint2 UpperLimit = PuddleComponent.DefaultOverflowVolume;
/// <summary>
/// The time accumulated since the start.

View File

@@ -4,6 +4,7 @@ using Content.Server.DoAfter;
using Content.Server.Fluids.EntitySystems;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Helpers;
using Content.Shared.Popups;
@@ -40,9 +41,9 @@ namespace Content.Server.Fluids.Components
}
}
public ReagentUnit MaxVolume
public FixedPoint2 MaxVolume
{
get => MopSolution?.MaxVolume ?? ReagentUnit.Zero;
get => MopSolution?.MaxVolume ?? FixedPoint2.Zero;
set
{
var solution = MopSolution;
@@ -53,14 +54,14 @@ namespace Content.Server.Fluids.Components
}
}
public ReagentUnit CurrentVolume => MopSolution?.CurrentVolume ?? ReagentUnit.Zero;
public FixedPoint2 CurrentVolume => MopSolution?.CurrentVolume ?? FixedPoint2.Zero;
// Currently there's a separate amount for pickup and dropoff so
// Picking up a puddle requires multiple clicks
// Dumping in a bucket requires 1 click
// Long-term you'd probably use a cooldown and start the pickup once we have some form of global cooldown
[DataField("pickup_amount")]
public ReagentUnit PickupAmount { get; } = ReagentUnit.New(5);
public FixedPoint2 PickupAmount { get; } = FixedPoint2.New(5);
[DataField("pickup_sound")]
private SoundSpecifier _pickupSound = new SoundPathSpecifier("/Audio/Effects/Fluids/slosh.ogg");
@@ -136,7 +137,7 @@ namespace Content.Server.Fluids.Components
return false;
// Annihilate the puddle
var transferAmount = ReagentUnit.Min(ReagentUnit.New(5), puddleComponent.CurrentVolume, CurrentVolume);
var transferAmount = FixedPoint2.Min(FixedPoint2.New(5), puddleComponent.CurrentVolume, CurrentVolume);
var puddleCleaned = puddleComponent.CurrentVolume - transferAmount <= 0;
var puddleSystem = EntitySystem.Get<PuddleSystem>();
@@ -146,7 +147,7 @@ namespace Content.Server.Fluids.Components
if (puddleSystem.EmptyHolder(puddleComponent.Owner.Uid, puddleComponent)) //The puddle doesn't actually *have* reagents, for example vomit because there's no "vomit" reagent.
{
puddleComponent.Owner.Delete();
transferAmount = ReagentUnit.Min(ReagentUnit.New(5), CurrentVolume);
transferAmount = FixedPoint2.Min(FixedPoint2.New(5), CurrentVolume);
puddleCleaned = true;
}
else

View File

@@ -1,5 +1,6 @@
using Content.Server.Fluids.EntitySystems;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Content.Shared.Sound;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
@@ -16,8 +17,8 @@ namespace Content.Server.Fluids.Components
public sealed class PuddleComponent : Component
{
public const string DefaultSolutionName = "puddle";
private static readonly ReagentUnit DefaultSlipThreshold = ReagentUnit.New(3);
public static readonly ReagentUnit DefaultOverflowVolume = ReagentUnit.New(20);
private static readonly FixedPoint2 DefaultSlipThreshold = FixedPoint2.New(3);
public static readonly FixedPoint2 DefaultOverflowVolume = FixedPoint2.New(20);
public override string Name => "Puddle";
@@ -35,7 +36,7 @@ namespace Content.Server.Fluids.Components
// to check for low volumes for evaporation or whatever
[DataField("slipThreshold")] public ReagentUnit SlipThreshold = DefaultSlipThreshold;
[DataField("slipThreshold")] public FixedPoint2 SlipThreshold = DefaultSlipThreshold;
[DataField("spillSound")]
public SoundSpecifier SpillSound = new SoundPathSpecifier("/Audio/Effects/Fluids/splat.ogg");
@@ -46,12 +47,12 @@ namespace Content.Server.Fluids.Components
public bool Overflown;
[ViewVariables(VVAccess.ReadOnly)]
public ReagentUnit CurrentVolume => EntitySystem.Get<PuddleSystem>().CurrentVolume(Owner.Uid);
public FixedPoint2 CurrentVolume => EntitySystem.Get<PuddleSystem>().CurrentVolume(Owner.Uid);
[ViewVariables] [DataField("overflowVolume")]
public ReagentUnit OverflowVolume = DefaultOverflowVolume;
public FixedPoint2 OverflowVolume = DefaultOverflowVolume;
public ReagentUnit OverflowLeft => CurrentVolume - OverflowVolume;
public FixedPoint2 OverflowLeft => CurrentVolume - OverflowVolume;
[DataField("solution")] public string SolutionName { get; set; } = DefaultSolutionName;
}

View File

@@ -5,6 +5,7 @@ using Content.Server.Coordinates.Helpers;
using Content.Server.Fluids.EntitySystems;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -132,7 +133,7 @@ namespace Content.Server.Fluids.Components
.TryGetRefillableSolution(spillEntity.Uid, out var solutionContainerComponent))
{
EntitySystem.Get<SolutionContainerSystem>().Refill(spillEntity.Uid, solutionContainerComponent,
solution.SplitSolution(ReagentUnit.Min(
solution.SplitSolution(FixedPoint2.Min(
solutionContainerComponent.AvailableVolume,
solutionContainerComponent.MaxSpillRefill))
);

View File

@@ -6,6 +6,7 @@ using Content.Shared.ActionBlocker;
using Content.Shared.Audio;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Cooldown;
using Content.Shared.FixedPoint;
using Content.Shared.Fluids;
using Content.Shared.Interaction;
using Content.Shared.Popups;
@@ -34,7 +35,7 @@ namespace Content.Server.Fluids.Components
[Dependency] private readonly IGameTiming _gameTiming = default!;
[DataField("transferAmount")]
private ReagentUnit _transferAmount = ReagentUnit.New(10);
private FixedPoint2 _transferAmount = FixedPoint2.New(10);
[DataField("sprayVelocity")]
private float _sprayVelocity = 1.5f;
[DataField("sprayAliveTime")]
@@ -56,7 +57,7 @@ namespace Content.Server.Fluids.Components
/// The amount of solution to be sprayer from this solution when using it
/// </summary>
[ViewVariables]
public ReagentUnit TransferAmount
public FixedPoint2 TransferAmount
{
get => _transferAmount;
set => _transferAmount = value;
@@ -75,11 +76,11 @@ namespace Content.Server.Fluids.Components
[DataField("spraySound", required: true)]
public SoundSpecifier SpraySound { get; } = default!;
public ReagentUnit CurrentVolume {
public FixedPoint2 CurrentVolume {
get
{
EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution);
return solution?.CurrentVolume ?? ReagentUnit.Zero;
return solution?.CurrentVolume ?? FixedPoint2.Zero;
}
}
@@ -131,7 +132,7 @@ namespace Content.Server.Fluids.Components
var solution = EntitySystem.Get<SolutionContainerSystem>().SplitSolution(Owner.Uid, contents, _transferAmount);
if (solution.TotalVolume <= ReagentUnit.Zero)
if (solution.TotalVolume <= FixedPoint2.Zero)
break;
var vapor = entManager.SpawnEntity(_vaporPrototype, playerPos.Offset(distance < 1 ? quarter : threeQuarters));