From 4943151111c8db9ac94701128b08f857b3abd3e6 Mon Sep 17 00:00:00 2001 From: Tayrtahn Date: Sun, 3 Mar 2024 00:36:36 -0500 Subject: [PATCH] Add prediction for puddle and spillable examines (#25794) Prediction for puddle and spillable examines --- .../Thresholds/Behaviors/SpillBehavior.cs | 2 +- .../EntitySystems/PuddleSystem.Evaporation.cs | 12 ------- .../EntitySystems/PuddleSystem.Spillable.cs | 23 ++++--------- .../Fluids/EntitySystems/PuddleSystem.cs | 34 ++----------------- .../Fluids/Components/EvaporationComponent.cs | 11 +++--- .../Fluids/Components/PuddleComponent.cs | 4 +-- .../Fluids/Components/SpillableComponent.cs | 8 ++--- .../Fluids/SharedPuddleSystem.Evaporation.cs | 17 ++++++++++ .../Fluids/SharedPuddleSystem.Spillable.cs | 24 +++++++++++++ Content.Shared/Fluids/SharedPuddleSystem.cs | 33 +++++++++++++++++- .../fluids/components/puddle-component.ftl | 2 +- 11 files changed, 96 insertions(+), 74 deletions(-) rename {Content.Server => Content.Shared}/Fluids/Components/EvaporationComponent.cs (73%) rename {Content.Server => Content.Shared}/Fluids/Components/SpillableComponent.cs (80%) create mode 100644 Content.Shared/Fluids/SharedPuddleSystem.Evaporation.cs create mode 100644 Content.Shared/Fluids/SharedPuddleSystem.Spillable.cs diff --git a/Content.Server/Destructible/Thresholds/Behaviors/SpillBehavior.cs b/Content.Server/Destructible/Thresholds/Behaviors/SpillBehavior.cs index 9e22510307..38564380c0 100644 --- a/Content.Server/Destructible/Thresholds/Behaviors/SpillBehavior.cs +++ b/Content.Server/Destructible/Thresholds/Behaviors/SpillBehavior.cs @@ -1,6 +1,6 @@ using Content.Server.Chemistry.Containers.EntitySystems; -using Content.Server.Fluids.Components; using Content.Server.Fluids.EntitySystems; +using Content.Shared.Fluids.Components; using JetBrains.Annotations; namespace Content.Server.Destructible.Thresholds.Behaviors diff --git a/Content.Server/Fluids/EntitySystems/PuddleSystem.Evaporation.cs b/Content.Server/Fluids/EntitySystems/PuddleSystem.Evaporation.cs index 2a80c33836..d9605c775c 100644 --- a/Content.Server/Fluids/EntitySystems/PuddleSystem.Evaporation.cs +++ b/Content.Server/Fluids/EntitySystems/PuddleSystem.Evaporation.cs @@ -1,6 +1,4 @@ -using Content.Server.Fluids.Components; using Content.Shared.Chemistry.Components; -using Content.Shared.Chemistry.Reagent; using Content.Shared.FixedPoint; using Content.Shared.Fluids.Components; @@ -10,11 +8,6 @@ public sealed partial class PuddleSystem { private static readonly TimeSpan EvaporationCooldown = TimeSpan.FromSeconds(1); - [ValidatePrototypeId] - private const string Water = "Water"; - - public static string[] EvaporationReagents = new[] { Water }; - private void OnEvaporationMapInit(Entity entity, ref MapInitEvent args) { entity.Comp.NextTick = _timing.CurTime + EvaporationCooldown; @@ -64,9 +57,4 @@ public sealed partial class PuddleSystem } } } - - public bool CanFullyEvaporate(Solution solution) - { - return solution.GetTotalPrototypeQuantity(EvaporationReagents) == solution.Volume; - } } diff --git a/Content.Server/Fluids/EntitySystems/PuddleSystem.Spillable.cs b/Content.Server/Fluids/EntitySystems/PuddleSystem.Spillable.cs index 177391de22..3cd6d06aeb 100644 --- a/Content.Server/Fluids/EntitySystems/PuddleSystem.Spillable.cs +++ b/Content.Server/Fluids/EntitySystems/PuddleSystem.Spillable.cs @@ -9,15 +9,14 @@ using Content.Shared.Clothing.Components; using Content.Shared.CombatMode.Pacification; using Content.Shared.Database; using Content.Shared.DoAfter; -using Content.Shared.Examine; using Content.Shared.FixedPoint; +using Content.Shared.Fluids.Components; using Content.Shared.IdentityManagement; using Content.Shared.Inventory.Events; using Content.Shared.Popups; using Content.Shared.Spillable; using Content.Shared.Throwing; using Content.Shared.Verbs; -using Content.Shared.Weapons.Melee; using Content.Shared.Weapons.Melee.Events; using Robust.Shared.Player; @@ -28,12 +27,13 @@ public sealed partial class PuddleSystem [Dependency] private readonly OpenableSystem _openable = default!; [Dependency] private readonly IEntityManager _entityManager = default!; - private void InitializeSpillable() + protected override void InitializeSpillable() { - SubscribeLocalEvent(OnExamined); + base.InitializeSpillable(); + SubscribeLocalEvent(SpillOnLand); - // openable handles the event if its closed - SubscribeLocalEvent(SplashOnMeleeHit, after: new[] { typeof(OpenableSystem) }); + // Openable handles the event if it's closed + SubscribeLocalEvent(SplashOnMeleeHit, after: [typeof(OpenableSystem)]); SubscribeLocalEvent>(AddSpillVerb); SubscribeLocalEvent(OnGotEquipped); SubscribeLocalEvent(OnOverflow); @@ -41,17 +41,6 @@ public sealed partial class PuddleSystem SubscribeLocalEvent(OnAttemptPacifiedThrow); } - private void OnExamined(Entity entity, ref ExaminedEvent args) - { - using (args.PushGroup(nameof(SpillableComponent))) - { - args.PushMarkup(Loc.GetString("spill-examine-is-spillable")); - - if (HasComp(entity)) - args.PushMarkup(Loc.GetString("spill-examine-spillable-weapon")); - } - } - private void OnOverflow(Entity entity, ref SolutionContainerOverflowEvent args) { if (args.Handled) diff --git a/Content.Server/Fluids/EntitySystems/PuddleSystem.cs b/Content.Server/Fluids/EntitySystems/PuddleSystem.cs index 44d28379ab..c0e8847ae9 100644 --- a/Content.Server/Fluids/EntitySystems/PuddleSystem.cs +++ b/Content.Server/Fluids/EntitySystems/PuddleSystem.cs @@ -11,7 +11,6 @@ using Content.Shared.Chemistry.Reaction; using Content.Shared.Chemistry.Reagent; using Content.Shared.Database; using Content.Shared.Effects; -using Content.Shared.Examine; using Content.Shared.FixedPoint; using Content.Shared.Fluids; using Content.Shared.Fluids.Components; @@ -67,13 +66,13 @@ public sealed partial class PuddleSystem : SharedPuddleSystem [ValidatePrototypeId] private const string CopperBlood = "CopperBlood"; - private static string[] _standoutReagents = new[] { Blood, Slime, CopperBlood }; + private static string[] _standoutReagents = [Blood, Slime, CopperBlood]; - public static float PuddleVolume = 1000; + public static readonly float PuddleVolume = 1000; // Using local deletion queue instead of the standard queue so that we can easily "undelete" if a puddle // loses & then gains reagents in a single tick. - private HashSet _deletionQueue = new(); + private HashSet _deletionQueue = []; private EntityQuery _puddleQuery; @@ -91,7 +90,6 @@ public sealed partial class PuddleSystem : SharedPuddleSystem // Shouldn't need re-anchoring. SubscribeLocalEvent(OnAnchorChanged); - SubscribeLocalEvent(HandlePuddleExamined); SubscribeLocalEvent(OnSolutionUpdate); SubscribeLocalEvent(OnPuddleInit); SubscribeLocalEvent(OnPuddleSpread); @@ -99,7 +97,6 @@ public sealed partial class PuddleSystem : SharedPuddleSystem SubscribeLocalEvent(OnEvaporationMapInit); - InitializeSpillable(); InitializeTransfers(); } @@ -448,31 +445,6 @@ public sealed partial class PuddleSystem : SharedPuddleSystem } } - private void HandlePuddleExamined(Entity entity, ref ExaminedEvent args) - { - using (args.PushGroup(nameof(PuddleComponent))) - { - if (TryComp(entity, out var slippery) && slippery.Active) - { - args.PushMarkup(Loc.GetString("puddle-component-examine-is-slipper-text")); - } - - if (HasComp(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")); - } - } - private void OnAnchorChanged(Entity entity, ref AnchorStateChangedEvent args) { if (!args.Anchored) diff --git a/Content.Server/Fluids/Components/EvaporationComponent.cs b/Content.Shared/Fluids/Components/EvaporationComponent.cs similarity index 73% rename from Content.Server/Fluids/Components/EvaporationComponent.cs rename to Content.Shared/Fluids/Components/EvaporationComponent.cs index 0f530da79e..f2ed3a6186 100644 --- a/Content.Server/Fluids/Components/EvaporationComponent.cs +++ b/Content.Shared/Fluids/Components/EvaporationComponent.cs @@ -1,19 +1,20 @@ -using Content.Server.Fluids.EntitySystems; -using Content.Shared.FixedPoint; +using Content.Shared.FixedPoint; +using Robust.Shared.GameStates; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom; -namespace Content.Server.Fluids.Components; +namespace Content.Shared.Fluids.Components; /// /// Added to puddles that contain water so it may evaporate over time. /// -[RegisterComponent, Access(typeof(PuddleSystem))] +[NetworkedComponent] +[RegisterComponent, Access(typeof(SharedPuddleSystem))] public sealed partial class EvaporationComponent : Component { /// /// The next time we remove the EvaporationSystem reagent amount from this entity. /// - [ViewVariables(VVAccess.ReadWrite), DataField("nextTick", customTypeSerializer:typeof(TimeOffsetSerializer))] + [ViewVariables(VVAccess.ReadWrite), DataField("nextTick", customTypeSerializer: typeof(TimeOffsetSerializer))] public TimeSpan NextTick = TimeSpan.Zero; /// diff --git a/Content.Shared/Fluids/Components/PuddleComponent.cs b/Content.Shared/Fluids/Components/PuddleComponent.cs index bc40e9960c..b8a6fe0cb8 100644 --- a/Content.Shared/Fluids/Components/PuddleComponent.cs +++ b/Content.Shared/Fluids/Components/PuddleComponent.cs @@ -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"; diff --git a/Content.Server/Fluids/Components/SpillableComponent.cs b/Content.Shared/Fluids/Components/SpillableComponent.cs similarity index 80% rename from Content.Server/Fluids/Components/SpillableComponent.cs rename to Content.Shared/Fluids/Components/SpillableComponent.cs index 645b0af612..a1b5fa17eb 100644 --- a/Content.Server/Fluids/Components/SpillableComponent.cs +++ b/Content.Shared/Fluids/Components/SpillableComponent.cs @@ -1,6 +1,6 @@ using Content.Shared.FixedPoint; -namespace Content.Server.Fluids.Components; +namespace Content.Shared.Fluids.Components; [RegisterComponent] public sealed partial class SpillableComponent : Component @@ -12,15 +12,15 @@ public sealed partial class SpillableComponent : Component /// Should this item be spilled when worn as clothing? /// Doesn't count for pockets or hands. /// - [DataField("spillWorn")] + [DataField] public bool SpillWorn = true; - [DataField("spillDelay")] + [DataField] public float? SpillDelay; /// /// At most how much reagent can be splashed on someone at once? /// - [DataField("maxMeleeSpillAmount")] + [DataField] public FixedPoint2 MaxMeleeSpillAmount = FixedPoint2.New(20); } diff --git a/Content.Shared/Fluids/SharedPuddleSystem.Evaporation.cs b/Content.Shared/Fluids/SharedPuddleSystem.Evaporation.cs new file mode 100644 index 0000000000..023d024a05 --- /dev/null +++ b/Content.Shared/Fluids/SharedPuddleSystem.Evaporation.cs @@ -0,0 +1,17 @@ +using Content.Shared.Chemistry.Components; +using Content.Shared.Chemistry.Reagent; + +namespace Content.Shared.Fluids; + +public abstract partial class SharedPuddleSystem +{ + [ValidatePrototypeId] + private const string Water = "Water"; + + public static readonly string[] EvaporationReagents = [Water]; + + public bool CanFullyEvaporate(Solution solution) + { + return solution.GetTotalPrototypeQuantity(EvaporationReagents) == solution.Volume; + } +} diff --git a/Content.Shared/Fluids/SharedPuddleSystem.Spillable.cs b/Content.Shared/Fluids/SharedPuddleSystem.Spillable.cs new file mode 100644 index 0000000000..77730e5afc --- /dev/null +++ b/Content.Shared/Fluids/SharedPuddleSystem.Spillable.cs @@ -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(OnExamined); + } + + private void OnExamined(Entity entity, ref ExaminedEvent args) + { + using (args.PushGroup(nameof(SpillableComponent))) + { + args.PushMarkup(Loc.GetString("spill-examine-is-spillable")); + + if (HasComp(entity)) + args.PushMarkup(Loc.GetString("spill-examine-spillable-weapon")); + } + } +} diff --git a/Content.Shared/Fluids/SharedPuddleSystem.cs b/Content.Shared/Fluids/SharedPuddleSystem.cs index 59a9c6ef26..e4bd61baa8 100644 --- a/Content.Shared/Fluids/SharedPuddleSystem.cs +++ b/Content.Shared/Fluids/SharedPuddleSystem.cs @@ -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(OnDrainCanDropTarget); SubscribeLocalEvent(OnRefillableCanDropDragged); SubscribeLocalEvent(OnGetFootstepSound); + SubscribeLocalEvent(HandlePuddleExamined); + + InitializeSpillable(); } private void OnRefillableCanDrag(Entity entity, ref CanDragEvent args) @@ -75,4 +81,29 @@ public abstract class SharedPuddleSystem : EntitySystem args.Sound = proto.FootstepSound; } } + + private void HandlePuddleExamined(Entity entity, ref ExaminedEvent args) + { + using (args.PushGroup(nameof(PuddleComponent))) + { + if (TryComp(entity, out var slippery) && slippery.Active) + { + args.PushMarkup(Loc.GetString("puddle-component-examine-is-slippery-text")); + } + + if (HasComp(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")); + } + } } diff --git a/Resources/Locale/en-US/fluids/components/puddle-component.ftl b/Resources/Locale/en-US/fluids/components/puddle-component.ftl index e1ae9bab4b..6368787ac3 100644 --- a/Resources/Locale/en-US/fluids/components/puddle-component.ftl +++ b/Resources/Locale/en-US/fluids/components/puddle-component.ftl @@ -1,4 +1,4 @@ -puddle-component-examine-is-slipper-text = It looks [color=#169C9C]slippery[/color]. +puddle-component-examine-is-slippery-text = It looks [color=#169C9C]slippery[/color]. puddle-component-examine-evaporating = It is [color=#5E7C16]evaporating[/color]. puddle-component-examine-evaporating-partial = It is [color=#FED83D]partially evaporating[/color]. puddle-component-examine-evaporating-no = It is [color=#B02E26]not evaporating[/color]. -- 2.51.2