Catchable items, playable basketball (#37702)
* catching * fix * improve * fix linter * cleanup * fix prediction * do the same here * fix comment
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user