]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Predict MessyDrinker (#39660)
authorScarKy0 <106310278+ScarKy0@users.noreply.github.com>
Sat, 16 Aug 2025 15:03:50 +0000 (17:03 +0200)
committerGitHub <noreply@github.com>
Sat, 16 Aug 2025 15:03:50 +0000 (17:03 +0200)
init

Content.Shared/Nutrition/Components/MessyDrinkerComponent.cs [moved from Content.Server/Nutrition/Components/MessyDrinkerComponent.cs with 71% similarity]
Content.Shared/Nutrition/EntitySystems/MessyDrinkerSystem.cs [moved from Content.Server/Nutrition/EntitySystems/MessyDrinkerSystem.cs with 58% similarity]

similarity index 71%
rename from Content.Server/Nutrition/Components/MessyDrinkerComponent.cs
rename to Content.Shared/Nutrition/Components/MessyDrinkerComponent.cs
index 5519c5d9838dfdbc0f36ef838cfd72da079d12ef..c077db823199cac3e6d99722bef7a2aee5d6f457 100644 (file)
@@ -1,30 +1,31 @@
 using Content.Shared.FixedPoint;
 using Content.Shared.Nutrition.Prototypes;
+using Robust.Shared.GameStates;
 using Robust.Shared.Prototypes;
 
-namespace Content.Server.Nutrition.Components;
+namespace Content.Shared.Nutrition.Components;
 
 /// <summary>
 /// Entities with this component occasionally spill some of the solution they're ingesting.
 /// </summary>
-[RegisterComponent]
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
 public sealed partial class MessyDrinkerComponent : Component
 {
-    [DataField]
+    [DataField, AutoNetworkedField]
     public float SpillChance = 0.2f;
 
     /// <summary>
     /// The amount of solution that is spilled when <see cref="SpillChance"/> procs.
     /// </summary>
-    [DataField]
+    [DataField, AutoNetworkedField]
     public FixedPoint2 SpillAmount = 1.0;
 
     /// <summary>
     /// The types of food prototypes we can spill
     /// </summary>
-    [DataField]
+    [DataField, AutoNetworkedField]
     public List<ProtoId<EdiblePrototype>> SpillableTypes = new List<ProtoId<EdiblePrototype>> { "Drink" };
 
-    [DataField]
+    [DataField, AutoNetworkedField]
     public LocId? SpillMessagePopup;
 }
similarity index 58%
rename from Content.Server/Nutrition/EntitySystems/MessyDrinkerSystem.cs
rename to Content.Shared/Nutrition/EntitySystems/MessyDrinkerSystem.cs
index dc8c11bb7f81cb320e6db5db92fd42a1adbb9aa6..bf084e6054dc8bc8d16607f02194aaccd97f8079 100644 (file)
@@ -1,18 +1,18 @@
-using Content.Server.Fluids.EntitySystems;
-using Content.Server.Nutrition.Components;
-using Content.Shared.Nutrition;
-using Content.Shared.Nutrition.EntitySystems;
+using Content.Shared.Fluids;
+using Content.Shared.Nutrition.Components;
 using Content.Shared.Popups;
+using Content.Shared.Random.Helpers;
 using Robust.Shared.Random;
+using Robust.Shared.Timing;
 
-namespace Content.Server.Nutrition.EntitySystems;
+namespace Content.Shared.Nutrition.EntitySystems;
 
 public sealed class MessyDrinkerSystem : EntitySystem
 {
-    [Dependency] private readonly IRobustRandom _random = default!;
     [Dependency] private readonly IngestionSystem _ingestion = default!;
-    [Dependency] private readonly PuddleSystem _puddle = default!;
+    [Dependency] private readonly SharedPuddleSystem _puddle = default!;
     [Dependency] private readonly SharedPopupSystem _popup = default!;
+    [Dependency] private readonly IGameTiming _timing = default!;
 
     public override void Initialize()
     {
@@ -35,11 +35,14 @@ public sealed class MessyDrinkerSystem : EntitySystem
         if (ev.ForceFed)
             return;
 
-        if (!_random.Prob(ent.Comp.SpillChance))
+        // TODO: Replace with RandomPredicted once the engine PR is merged
+        var seed = SharedRandomExtensions.HashCodeCombine(new() { (int)_timing.CurTick.Value, GetNetEntity(ent).Id });
+        var rand = new System.Random(seed);
+        if (!rand.Prob(ent.Comp.SpillChance))
             return;
 
         if (ent.Comp.SpillMessagePopup != null)
-            _popup.PopupEntity(Loc.GetString(ent.Comp.SpillMessagePopup), ent, ent, PopupType.MediumCaution);
+            _popup.PopupPredicted(Loc.GetString(ent.Comp.SpillMessagePopup), null, ent, ent, PopupType.MediumCaution);
 
         var split = ev.Split.SplitSolution(ent.Comp.SpillAmount);