Add prediction for puddle and spillable examines (#25794)

Prediction for puddle and spillable examines
This commit is contained in:
Tayrtahn
2024-03-03 00:36:36 -05:00
committed by GitHub
parent a0b33def48
commit 4943151111
11 changed files with 96 additions and 74 deletions

View File

@@ -0,0 +1,25 @@
using Content.Shared.FixedPoint;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Shared.Fluids.Components;
/// <summary>
/// Added to puddles that contain water so it may evaporate over time.
/// </summary>
[NetworkedComponent]
[RegisterComponent, Access(typeof(SharedPuddleSystem))]
public sealed partial class EvaporationComponent : Component
{
/// <summary>
/// The next time we remove the EvaporationSystem reagent amount from this entity.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("nextTick", customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan NextTick = TimeSpan.Zero;
/// <summary>
/// How much evaporation occurs every tick.
/// </summary>
[DataField("evaporationAmount")]
public FixedPoint2 EvaporationAmount = FixedPoint2.New(0.3);
}

View File

@@ -11,10 +11,10 @@ namespace Content.Shared.Fluids.Components
[RegisterComponent, NetworkedComponent, Access(typeof(SharedPuddleSystem))]
public sealed partial class PuddleComponent : Component
{
[DataField("spillSound")]
[DataField]
public SoundSpecifier SpillSound = new SoundPathSpecifier("/Audio/Effects/Fluids/splat.ogg");
[DataField("overflowVolume")]
[DataField]
public FixedPoint2 OverflowVolume = FixedPoint2.New(20);
[DataField("solution")] public string SolutionName = "puddle";

View File

@@ -0,0 +1,26 @@
using Content.Shared.FixedPoint;
namespace Content.Shared.Fluids.Components;
[RegisterComponent]
public sealed partial class SpillableComponent : Component
{
[DataField("solution")]
public string SolutionName = "puddle";
/// <summary>
/// Should this item be spilled when worn as clothing?
/// Doesn't count for pockets or hands.
/// </summary>
[DataField]
public bool SpillWorn = true;
[DataField]
public float? SpillDelay;
/// <summary>
/// At most how much reagent can be splashed on someone at once?
/// </summary>
[DataField]
public FixedPoint2 MaxMeleeSpillAmount = FixedPoint2.New(20);
}

View File

@@ -0,0 +1,17 @@
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
namespace Content.Shared.Fluids;
public abstract partial class SharedPuddleSystem
{
[ValidatePrototypeId<ReagentPrototype>]
private const string Water = "Water";
public static readonly string[] EvaporationReagents = [Water];
public bool CanFullyEvaporate(Solution solution)
{
return solution.GetTotalPrototypeQuantity(EvaporationReagents) == solution.Volume;
}
}

View File

@@ -0,0 +1,24 @@
using Content.Shared.Examine;
using Content.Shared.Fluids.Components;
using Content.Shared.Weapons.Melee;
namespace Content.Shared.Fluids;
public abstract partial class SharedPuddleSystem
{
protected virtual void InitializeSpillable()
{
SubscribeLocalEvent<SpillableComponent, ExaminedEvent>(OnExamined);
}
private void OnExamined(Entity<SpillableComponent> entity, ref ExaminedEvent args)
{
using (args.PushGroup(nameof(SpillableComponent)))
{
args.PushMarkup(Loc.GetString("spill-examine-is-spillable"));
if (HasComp<MeleeWeaponComponent>(entity))
args.PushMarkup(Loc.GetString("spill-examine-spillable-weapon"));
}
}
}

View File

@@ -2,13 +2,16 @@ using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.DragDrop;
using Content.Shared.Examine;
using Content.Shared.FixedPoint;
using Content.Shared.Fluids.Components;
using Content.Shared.Movement.Events;
using Content.Shared.StepTrigger.Components;
using Robust.Shared.Prototypes;
namespace Content.Shared.Fluids;
public abstract class SharedPuddleSystem : EntitySystem
public abstract partial class SharedPuddleSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainerSystem = default!;
@@ -28,6 +31,9 @@ public abstract class SharedPuddleSystem : EntitySystem
SubscribeLocalEvent<DrainableSolutionComponent, CanDropTargetEvent>(OnDrainCanDropTarget);
SubscribeLocalEvent<RefillableSolutionComponent, CanDropDraggedEvent>(OnRefillableCanDropDragged);
SubscribeLocalEvent<PuddleComponent, GetFootstepSoundEvent>(OnGetFootstepSound);
SubscribeLocalEvent<PuddleComponent, ExaminedEvent>(HandlePuddleExamined);
InitializeSpillable();
}
private void OnRefillableCanDrag(Entity<RefillableSolutionComponent> entity, ref CanDragEvent args)
@@ -75,4 +81,29 @@ public abstract class SharedPuddleSystem : EntitySystem
args.Sound = proto.FootstepSound;
}
}
private void HandlePuddleExamined(Entity<PuddleComponent> entity, ref ExaminedEvent args)
{
using (args.PushGroup(nameof(PuddleComponent)))
{
if (TryComp<StepTriggerComponent>(entity, out var slippery) && slippery.Active)
{
args.PushMarkup(Loc.GetString("puddle-component-examine-is-slippery-text"));
}
if (HasComp<EvaporationComponent>(entity) &&
_solutionContainerSystem.ResolveSolution(entity.Owner, entity.Comp.SolutionName,
ref entity.Comp.Solution, out var solution))
{
if (CanFullyEvaporate(solution))
args.PushMarkup(Loc.GetString("puddle-component-examine-evaporating"));
else if (solution.GetTotalPrototypeQuantity(EvaporationReagents) > FixedPoint2.Zero)
args.PushMarkup(Loc.GetString("puddle-component-examine-evaporating-partial"));
else
args.PushMarkup(Loc.GetString("puddle-component-examine-evaporating-no"));
}
else
args.PushMarkup(Loc.GetString("puddle-component-examine-evaporating-no"));
}
}
}