Catchable items, playable basketball (#37702)

* catching

* fix

* improve

* fix linter

* cleanup

* fix prediction

* do the same here

* fix comment
This commit is contained in:
slarticodefast
2025-07-06 18:54:20 +02:00
committed by GitHub
parent cb21b72600
commit 22e3d533d3
16 changed files with 304 additions and 24 deletions

View File

@@ -184,5 +184,25 @@ namespace Content.Shared.Random.Helpers
// Shouldn't happen
throw new InvalidOperationException($"Invalid weighted pick for {prototype.ID}!");
}
/// <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.
/// </summary>
/// <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 });
/// </code>
/// </example>
public static int HashCodeCombine(List<int> values)
{
int hash = 5381;
foreach (var value in values)
{
hash = (hash << 5) + hash + value;
}
return hash;
}
}
}