2019-11-21 07:22:20 -06:00
|
|
|
using System;
|
2019-12-08 08:52:41 -06:00
|
|
|
using System.Threading;
|
2019-11-21 07:22:20 -06:00
|
|
|
|
|
|
|
|
namespace ACE.Common
|
2018-12-21 23:51:57 -05:00
|
|
|
{
|
|
|
|
|
// important class, ensure unit tests pass for this
|
2019-11-21 07:22:20 -06:00
|
|
|
// todo: implement exactly the way AC handles it.. which we'll never know unless we get original source code
|
2018-12-21 23:51:57 -05:00
|
|
|
public static class ThreadSafeRandom
|
|
|
|
|
{
|
2019-12-08 08:52:41 -06:00
|
|
|
static readonly ThreadLocal<Random> random = new ThreadLocal<Random>(() => new Random());
|
2019-11-21 07:22:20 -06:00
|
|
|
|
2018-12-21 23:51:57 -05:00
|
|
|
/// <summary>
|
2020-08-26 01:03:17 -04:00
|
|
|
/// Returns a random floating-point number that is greater than or equal to 'min', and less than 'max'.
|
2018-12-21 23:51:57 -05:00
|
|
|
/// </summary>
|
2020-08-26 01:03:17 -04:00
|
|
|
/// <param name="min">The value returned will be greater than or equal to 'min'</param>
|
|
|
|
|
/// <param name="max">The value returned will be less than 'max'</param>
|
|
|
|
|
public static double Next(float min, float max)
|
2018-12-21 23:51:57 -05:00
|
|
|
{
|
2020-08-26 01:03:17 -04:00
|
|
|
// for ranges other than 1, (max - upper bound) will be scaled by the range
|
|
|
|
|
return random.Value.NextDouble() * (max - min) + min;
|
2018-12-21 23:51:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns a random integer between min and max, inclusive
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="min">The minimum possible value to return</param>
|
|
|
|
|
/// <param name="max">The maximum possible value to return</param>
|
|
|
|
|
public static int Next(int min, int max)
|
|
|
|
|
{
|
2019-12-08 08:52:41 -06:00
|
|
|
return random.Value.Next(min, max + 1);
|
2018-12-21 23:51:57 -05:00
|
|
|
}
|
adding AssignMagic_New method, aligned more closely with retail (#3257)
* adding end of retail mutation filters for melee weapon damage, wield difficulty, damage variance, weapondefense, and weaponoffense
* .
* adding 4eyebiped credit
* adding end of retail mutation filters for missile weapon DamageMod, ElementalDamageBonus, WieldRequirements, and WeaponDefense
* adding end of retail mutation filters for caster weapon ManaConversionMod, ElementalDamageMod, WieldRequirements, and WeaponDefense
* update melee scripts
* resolve merge
* .
* add missing lines
* adding weapon speed mutations
* appending LongDesc with ' of <first spell name w/ descriptor>'
* .
* adding some missing spell descs from magloot logs
* adding SpellDIDs to isMagical casters
* wip
* finalizing
* updating qualityMod
* modifying qualityMod again, to align with data + magloot logs for legendary chests
* ConcurrentDictionary.TryAdd
* updating Clothing spells w/ latest data
2020-10-03 01:12:02 -04:00
|
|
|
|
|
|
|
|
public static double NextInterval(float qualityMod)
|
|
|
|
|
{
|
|
|
|
|
return Math.Max(0.0, random.Value.NextDouble() - qualityMod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The maximum possible double < 1.0
|
|
|
|
|
/// </summary>
|
2024-08-24 07:32:35 -07:00
|
|
|
private const double maxExclusive = 0.9999999999999999;
|
adding AssignMagic_New method, aligned more closely with retail (#3257)
* adding end of retail mutation filters for melee weapon damage, wield difficulty, damage variance, weapondefense, and weaponoffense
* .
* adding 4eyebiped credit
* adding end of retail mutation filters for missile weapon DamageMod, ElementalDamageBonus, WieldRequirements, and WeaponDefense
* adding end of retail mutation filters for caster weapon ManaConversionMod, ElementalDamageMod, WieldRequirements, and WeaponDefense
* update melee scripts
* resolve merge
* .
* add missing lines
* adding weapon speed mutations
* appending LongDesc with ' of <first spell name w/ descriptor>'
* .
* adding some missing spell descs from magloot logs
* adding SpellDIDs to isMagical casters
* wip
* finalizing
* updating qualityMod
* modifying qualityMod again, to align with data + magloot logs for legendary chests
* ConcurrentDictionary.TryAdd
* updating Clothing spells w/ latest data
2020-10-03 01:12:02 -04:00
|
|
|
|
|
|
|
|
public static double NextIntervalMax(float qualityMod)
|
|
|
|
|
{
|
|
|
|
|
return Math.Min(maxExclusive, random.Value.NextDouble() + qualityMod);
|
|
|
|
|
}
|
2018-12-21 23:51:57 -05:00
|
|
|
}
|
|
|
|
|
}
|