]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add prediction for puddle and spillable examines (#25794)
authorTayrtahn <tayrtahn@gmail.com>
Sun, 3 Mar 2024 05:36:36 +0000 (00:36 -0500)
committerGitHub <noreply@github.com>
Sun, 3 Mar 2024 05:36:36 +0000 (16:36 +1100)
Prediction for puddle and spillable examines

Content.Server/Destructible/Thresholds/Behaviors/SpillBehavior.cs
Content.Server/Fluids/EntitySystems/PuddleSystem.Evaporation.cs
Content.Server/Fluids/EntitySystems/PuddleSystem.Spillable.cs
Content.Server/Fluids/EntitySystems/PuddleSystem.cs
Content.Shared/Fluids/Components/EvaporationComponent.cs [moved from Content.Server/Fluids/Components/EvaporationComponent.cs with 73% similarity]
Content.Shared/Fluids/Components/PuddleComponent.cs
Content.Shared/Fluids/Components/SpillableComponent.cs [moved from Content.Server/Fluids/Components/SpillableComponent.cs with 80% similarity]
Content.Shared/Fluids/SharedPuddleSystem.Evaporation.cs [new file with mode: 0644]
Content.Shared/Fluids/SharedPuddleSystem.Spillable.cs [new file with mode: 0644]
Content.Shared/Fluids/SharedPuddleSystem.cs
Resources/Locale/en-US/fluids/components/puddle-component.ftl

index 9e22510307171336958eea05f28794ed6b06d037..38564380c042e70842dc1a7bd00225798334ce7e 100644 (file)
@@ -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
index 2a80c33836075a4a2c2833d8991a57fbe3b1807d..d9605c775c1953c5145dbe30400639baf15c2192 100644 (file)
@@ -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<ReagentPrototype>]
-    private const string Water = "Water";
-
-    public static string[] EvaporationReagents = new[] { Water };
-
     private void OnEvaporationMapInit(Entity<EvaporationComponent> 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;
-    }
 }
index 177391de22d280e8393759850e437775abe8da72..3cd6d06aebd246df83821a9f9c66caf1fada0c02 100644 (file)
@@ -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<SpillableComponent, ExaminedEvent>(OnExamined);
+        base.InitializeSpillable();
+
         SubscribeLocalEvent<SpillableComponent, LandEvent>(SpillOnLand);
-        // openable handles the event if its closed
-        SubscribeLocalEvent<SpillableComponent, MeleeHitEvent>(SplashOnMeleeHit, after: new[] { typeof(OpenableSystem) });
+        // Openable handles the event if it's closed
+        SubscribeLocalEvent<SpillableComponent, MeleeHitEvent>(SplashOnMeleeHit, after: [typeof(OpenableSystem)]);
         SubscribeLocalEvent<SpillableComponent, GetVerbsEvent<Verb>>(AddSpillVerb);
         SubscribeLocalEvent<SpillableComponent, GotEquippedEvent>(OnGotEquipped);
         SubscribeLocalEvent<SpillableComponent, SolutionContainerOverflowEvent>(OnOverflow);
@@ -41,17 +41,6 @@ public sealed partial class PuddleSystem
         SubscribeLocalEvent<SpillableComponent, AttemptPacifiedThrowEvent>(OnAttemptPacifiedThrow);
     }
 
-    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"));
-        }
-    }
-
     private void OnOverflow(Entity<SpillableComponent> entity, ref SolutionContainerOverflowEvent args)
     {
         if (args.Handled)
index 44d28379aba5ad018200978413defeff1b66196e..c0e8847ae98d710e4a5c62abd0c45543ddab8d04 100644 (file)
@@ -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<ReagentPrototype>]
     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<EntityUid> _deletionQueue = new();
+    private HashSet<EntityUid> _deletionQueue = [];
 
     private EntityQuery<PuddleComponent> _puddleQuery;
 
@@ -91,7 +90,6 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
 
         // Shouldn't need re-anchoring.
         SubscribeLocalEvent<PuddleComponent, AnchorStateChangedEvent>(OnAnchorChanged);
-        SubscribeLocalEvent<PuddleComponent, ExaminedEvent>(HandlePuddleExamined);
         SubscribeLocalEvent<PuddleComponent, SolutionContainerChangedEvent>(OnSolutionUpdate);
         SubscribeLocalEvent<PuddleComponent, ComponentInit>(OnPuddleInit);
         SubscribeLocalEvent<PuddleComponent, SpreadNeighborsEvent>(OnPuddleSpread);
@@ -99,7 +97,6 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
 
         SubscribeLocalEvent<EvaporationComponent, MapInitEvent>(OnEvaporationMapInit);
 
-        InitializeSpillable();
         InitializeTransfers();
     }
 
@@ -448,31 +445,6 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
         }
     }
 
-    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-slipper-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"));
-        }
-    }
-
     private void OnAnchorChanged(Entity<PuddleComponent> entity, ref AnchorStateChangedEvent args)
     {
         if (!args.Anchored)
similarity index 73%
rename from Content.Server/Fluids/Components/EvaporationComponent.cs
rename to Content.Shared/Fluids/Components/EvaporationComponent.cs
index 0f530da79ec36655187f7acbc16c7a4ecbfffdc5..f2ed3a6186bf72e0885180e35a287c93d2b6c4d0 100644 (file)
@@ -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;
 
 /// <summary>
 /// Added to puddles that contain water so it may evaporate over time.
 /// </summary>
-[RegisterComponent, Access(typeof(PuddleSystem))]
+[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))]
+    [ViewVariables(VVAccess.ReadWrite), DataField("nextTick", customTypeSerializer: typeof(TimeOffsetSerializer))]
     public TimeSpan NextTick = TimeSpan.Zero;
 
     /// <summary>
index bc40e9960c60cb60166ae0986adab214c64c3d9d..b8a6fe0cb8826de3f326d897b2d1ddeb0dc7f541 100644 (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";
similarity index 80%
rename from Content.Server/Fluids/Components/SpillableComponent.cs
rename to Content.Shared/Fluids/Components/SpillableComponent.cs
index 645b0af6121c897eae992f2051e343820f674520..a1b5fa17eb8c6ff62d6d69f247db365f5dbdf295 100644 (file)
@@ -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.
     /// </summary>
-    [DataField("spillWorn")]
+    [DataField]
     public bool SpillWorn = true;
 
-    [DataField("spillDelay")]
+    [DataField]
     public float? SpillDelay;
 
     /// <summary>
     ///     At most how much reagent can be splashed on someone at once?
     /// </summary>
-    [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 (file)
index 0000000..023d024
--- /dev/null
@@ -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;
+    }
+}
diff --git a/Content.Shared/Fluids/SharedPuddleSystem.Spillable.cs b/Content.Shared/Fluids/SharedPuddleSystem.Spillable.cs
new file mode 100644 (file)
index 0000000..77730e5
--- /dev/null
@@ -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"));
+        }
+    }
+}
index 59a9c6ef26ac81cb968c4db3592415213cbc337c..e4bd61baa8ebb1d0c9869bff1a19fc26035caa13 100644 (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"));
+        }
+    }
 }
index e1ae9bab4bffead8f415762518513ce15fdd9452..6368787ac3d4c1c83507dddc2dbb7cc348a53817 100644 (file)
@@ -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].