]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
refactor: new overload for SharedRandomExtensions.HashCodeCombine (#40990)
authorFildrance <fildrance@gmail.com>
Sun, 19 Oct 2025 21:29:31 +0000 (00:29 +0300)
committerGitHub <noreply@github.com>
Sun, 19 Oct 2025 21:29:31 +0000 (21:29 +0000)
* refactor: new overload for SharedRandomExtensions.HashCodeCombine

* Update Content.Shared/Random/Helpers/SharedRandomExtensions.cs

---------

Co-authored-by: pa.pecherskij <pa.pecherskij@interfax.ru>
Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Content.Shared/Body/Systems/SharedBloodstreamSystem.cs
Content.Shared/Clumsy/ClumsySystem.cs
Content.Shared/EntityEffects/SharedEntityEffectsSystem.cs
Content.Shared/Flash/SharedFlashSystem.cs
Content.Shared/Kitchen/SharedKitchenSpikeSystem.cs
Content.Shared/Nutrition/EntitySystems/IngestionSystem.Utensils.cs
Content.Shared/Nutrition/EntitySystems/MessyDrinkerSystem.cs
Content.Shared/Random/Helpers/SharedRandomExtensions.cs
Content.Shared/Throwing/CatchableSystem.cs
Content.Shared/Traits/Assorted/NarcolepsySystem.cs

index ee85fe65b715893f7c9c9cf00104e1a6cae23a09..693eede7d8388a76840e2c2b1f13342f809a1cb5 100644 (file)
@@ -217,7 +217,7 @@ public abstract class SharedBloodstreamSystem : EntitySystem
 
         // TODO: Replace with RandomPredicted once the engine PR is merged
         // Use both the receiver and the damage causing entity for the seed so that we have different results for multiple attacks in the same tick
-        var seed = SharedRandomExtensions.HashCodeCombine(new() { (int)_timing.CurTick.Value, GetNetEntity(ent).Id, GetNetEntity(args.Origin)?.Id ?? 0 });
+        var seed = SharedRandomExtensions.HashCodeCombine((int)_timing.CurTick.Value, GetNetEntity(ent).Id, GetNetEntity(args.Origin)?.Id ?? 0 );
         var rand = new System.Random(seed);
         var prob = Math.Clamp(totalFloat / 25, 0, 1);
         if (totalFloat > 0 && rand.Prob(prob))
index 2506359c25672b18cfeaa8d4d81552a95d0d0d3c..d7b4019eb8bbc45417c9a956a4e9c0c5d74e75a6 100644 (file)
@@ -49,7 +49,7 @@ public sealed class ClumsySystem : EntitySystem
             return;
 
         // TODO: Replace with RandomPredicted once the engine PR is merged
-        var seed = SharedRandomExtensions.HashCodeCombine(new() { (int)_timing.CurTick.Value, GetNetEntity(ent).Id });
+        var seed = SharedRandomExtensions.HashCodeCombine((int)_timing.CurTick.Value, GetNetEntity(ent).Id);
         var rand = new System.Random(seed);
         if (!rand.Prob(ent.Comp.ClumsyDefaultCheck))
             return;
@@ -68,7 +68,7 @@ public sealed class ClumsySystem : EntitySystem
             return;
 
         // TODO: Replace with RandomPredicted once the engine PR is merged
-        var seed = SharedRandomExtensions.HashCodeCombine(new() { (int)_timing.CurTick.Value, GetNetEntity(ent).Id });
+        var seed = SharedRandomExtensions.HashCodeCombine((int)_timing.CurTick.Value, GetNetEntity(ent).Id);
         var rand = new System.Random(seed);
         if (!rand.Prob(ent.Comp.ClumsyDefaultCheck))
             return;
@@ -87,7 +87,7 @@ public sealed class ClumsySystem : EntitySystem
             return;
 
         // TODO: Replace with RandomPredicted once the engine PR is merged
-        var seed = SharedRandomExtensions.HashCodeCombine(new() { (int)_timing.CurTick.Value, GetNetEntity(args.Item).Id });
+        var seed = SharedRandomExtensions.HashCodeCombine((int)_timing.CurTick.Value, GetNetEntity(args.Item).Id);
         var rand = new System.Random(seed);
         if (!rand.Prob(ent.Comp.ClumsyDefaultCheck))
             return;
@@ -121,7 +121,7 @@ public sealed class ClumsySystem : EntitySystem
             return;
 
         // TODO: Replace with RandomPredicted once the engine PR is merged
-        var seed = SharedRandomExtensions.HashCodeCombine(new() { (int)_timing.CurTick.Value, GetNetEntity(args.Gun).Id });
+        var seed = SharedRandomExtensions.HashCodeCombine((int)_timing.CurTick.Value, GetNetEntity(args.Gun).Id);
         var rand = new System.Random(seed);
         if (!rand.Prob(ent.Comp.ClumsyDefaultCheck))
             return;
@@ -146,7 +146,7 @@ public sealed class ClumsySystem : EntitySystem
             return;
 
         // TODO: Replace with RandomPredicted once the engine PR is merged
-        var seed = SharedRandomExtensions.HashCodeCombine(new() { (int)_timing.CurTick.Value, GetNetEntity(ent).Id });
+        var seed = SharedRandomExtensions.HashCodeCombine((int)_timing.CurTick.Value, GetNetEntity(ent).Id);
         var rand = new System.Random(seed);
         if (!_cfg.GetCVar(CCVars.GameTableBonk) && !rand.Prob(ent.Comp.ClumsyDefaultCheck))
             return;
index 1122f75f937f584ac2b6a3e3f581352cdf00413f..91360b3a84f3090c8a71bbe7548e1be687363244 100644 (file)
@@ -1,4 +1,4 @@
-using System.Diagnostics.CodeAnalysis;
+using System.Diagnostics.CodeAnalysis;
 using Content.Shared.Administration.Logs;
 using Content.Shared.Chemistry;
 using Content.Shared.Chemistry.Reaction;
@@ -91,7 +91,7 @@ public sealed partial class SharedEntityEffectsSystem : EntitySystem, IEntityEff
         // TODO: Replace with proper random prediciton when it exists.
         if (effect.Probability <= 1f)
         {
-            var seed = SharedRandomExtensions.HashCodeCombine(new() { (int)_timing.CurTick.Value, GetNetEntity(target).Id, 0 });
+            var seed = SharedRandomExtensions.HashCodeCombine((int)_timing.CurTick.Value, GetNetEntity(target).Id, 0);
             var rand = new System.Random(seed);
             if (!rand.Prob(effect.Probability))
                 return false;
index a762a94e58dbebaeb98099098705f5321fbc5cb9..dad8e6d1562d325fc141cc6e5ef2e346d0203746 100644 (file)
@@ -206,7 +206,7 @@ public abstract class SharedFlashSystem : EntitySystem
         foreach (var entity in _entSet)
         {
             // TODO: Use RandomPredicted https://github.com/space-wizards/RobustToolbox/pull/5849
-            var seed = SharedRandomExtensions.HashCodeCombine(new() { (int)_timing.CurTick.Value, GetNetEntity(entity).Id });
+            var seed = SharedRandomExtensions.HashCodeCombine((int)_timing.CurTick.Value, GetNetEntity(entity).Id);
             var rand = new System.Random(seed);
             if (!rand.Prob(probability))
                 continue;
index bae411f356bb2d76fe0b489f4113a66c16d9367b..530dcb437bd1cdae234f778f0895b07bd3005fbb 100644 (file)
@@ -292,7 +292,7 @@ public sealed class SharedKitchenSpikeSystem : EntitySystem
 
         // Get a random entry to spawn.
         // TODO: Replace with RandomPredicted once the engine PR is merged
-        var seed = SharedRandomExtensions.HashCodeCombine(new() { (int)_gameTiming.CurTick.Value, GetNetEntity(ent).Id });
+        var seed = SharedRandomExtensions.HashCodeCombine((int)_gameTiming.CurTick.Value, GetNetEntity(ent).Id);
         var rand = new System.Random(seed);
 
         var index = rand.Next(butcherable.SpawnedEntities.Count);
index a4ef8422bb08a9fbe145da00be11b94c564dc2c8..f9cb03cb3576a0a51205a470985c690221a8a7ca 100644 (file)
@@ -1,4 +1,4 @@
-using Content.Shared.Containers.ItemSlots;
+using Content.Shared.Containers.ItemSlots;
 using Content.Shared.Hands.Components;
 using Content.Shared.Interaction;
 using Content.Shared.Nutrition.Components;
@@ -66,7 +66,7 @@ public sealed partial class IngestionSystem
             return;
 
         // TODO: Once we have predicted randomness delete this for something sane...
-        var seed = SharedRandomExtensions.HashCodeCombine(new() { (int)_timing.CurTick.Value, GetNetEntity(entity).Id, GetNetEntity(userUid).Id });
+        var seed = SharedRandomExtensions.HashCodeCombine((int)_timing.CurTick.Value, GetNetEntity(entity).Id, GetNetEntity(userUid).Id);
         var rand = new System.Random(seed);
 
         if (!rand.Prob(entity.Comp.BreakChance))
index 7bfb7a5633de581a68874e773a5fbf1e3ae0c4a0..f672edaab4e8eb7bae3ebf3bb57c8528a014b6a9 100644 (file)
@@ -38,7 +38,7 @@ public sealed class MessyDrinkerSystem : EntitySystem
             return;
 
         // TODO: Replace with RandomPredicted once the engine PR is merged
-        var seed = SharedRandomExtensions.HashCodeCombine(new() { (int)_timing.CurTick.Value, GetNetEntity(ent).Id });
+        var seed = SharedRandomExtensions.HashCodeCombine((int)_timing.CurTick.Value, GetNetEntity(ent).Id);
         var rand = new System.Random(seed);
         if (!rand.Prob(ent.Comp.SpillChance))
             return;
index 87e839b56f400d7826e9e88c3d4ad46365213f46..ceb4786ebef4112d74131f64ee5879cb2de548bb 100644 (file)
@@ -185,6 +185,12 @@ namespace Content.Shared.Random.Helpers
             throw new InvalidOperationException($"Invalid weighted pick for {prototype.ID}!");
         }
 
+        /// <inheritdoc cref="HashCodeCombine(IReadOnlyCollection{int})"/>
+        public static int HashCodeCombine(params int[] values)
+        {
+            return HashCodeCombine((IReadOnlyCollection<int>)values);
+        }
+
         /// <summary>
         /// A very simple, deterministic djb2 hash function for generating a combined seed for the random number generator.
         /// We can't use HashCode.Combine because that is initialized with a random value, creating different results on the server and client.
@@ -192,10 +198,10 @@ namespace Content.Shared.Random.Helpers
         /// <example>
         /// Combine the current game tick with a NetEntity Id in order to not get the same random result if this is called multiple times in the same tick.
         /// <code>
-        /// var seed = SharedRandomExtensions.HashCodeCombine(new() { (int)_timing.CurTick.Value, GetNetEntity(ent).Id });
+        /// var seed = SharedRandomExtensions.HashCodeCombine((int)_timing.CurTick.Value, GetNetEntity(ent).Id);
         /// </code>
         /// </example>
-        public static int HashCodeCombine(List<int> values)
+        public static int HashCodeCombine(IReadOnlyCollection<int> values)
         {
             int hash = 5381;
             foreach (var value in values)
index 586397f58b1659fd50d460701641e3571e370046..92ca7062b12497d1560661c6431b452076ad121b 100644 (file)
@@ -56,7 +56,7 @@ public sealed partial class CatchableSystem : EntitySystem
             return;
 
         // TODO: Replace with RandomPredicted once the engine PR is merged
-        var seed = SharedRandomExtensions.HashCodeCombine(new() { (int)_timing.CurTick.Value, GetNetEntity(ent).Id });
+        var seed = SharedRandomExtensions.HashCodeCombine((int)_timing.CurTick.Value, GetNetEntity(ent).Id);
         var rand = new System.Random(seed);
         if (!rand.Prob(ent.Comp.CatchChance))
             return;
index 7bce80c703de9448a1df525b1e47ff11df70157a..f59a1cf2813fd99c4f23d441585dc1485a6e349d 100644 (file)
@@ -53,7 +53,7 @@ public sealed class NarcolepsySystem : EntitySystem
                 continue;
 
             // TODO: Replace with RandomPredicted once the engine PR is merged
-            var seed = SharedRandomExtensions.HashCodeCombine(new() { (int)_timing.CurTick.Value, GetNetEntity(uid).Id });
+            var seed = SharedRandomExtensions.HashCodeCombine((int)_timing.CurTick.Value, GetNetEntity(uid).Id);
             var rand = new System.Random(seed);
 
             var duration = narcolepsy.MinDurationOfIncident + (narcolepsy.MaxDurationOfIncident - narcolepsy.MinDurationOfIncident) * rand.NextDouble();