Core/Random: Changed random functions returning doubles to return floats

Port From (https://github.com/TrinityCore/TrinityCore/commit/9894f6b802c974bb36acd7fbb0d083455a1f0f1b)
This commit is contained in:
hondacrx
2024-02-02 14:39:02 -05:00
parent c5538d6d40
commit a5bc0d0d9b
10 changed files with 24 additions and 24 deletions
@@ -158,7 +158,7 @@ namespace System.Collections.Generic
{
float totalWeight = sequence.Sum(weightSelector);
// The weight we are after...
float itemWeightIndex = (float)RandomHelper.NextDouble() * totalWeight;
float itemWeightIndex = RandomHelper.NextSingle() * totalWeight;
float currentWeightIndex = 0;
foreach (var item in from weightedItem in sequence select new { Value = weightedItem, Weight = weightSelector(weightedItem) })
+2 -2
View File
@@ -16,9 +16,9 @@ public class RandomHelper
/// Returns a random number between 0.0 and 1.0.
/// </summary>
/// <returns></returns>
public static double NextDouble()
public static float NextSingle()
{
return rand.NextDouble();
return rand.NextSingle();
}
/// <summary>
+5 -5
View File
@@ -3389,12 +3389,12 @@ namespace Game.Entities
}
// angle to face `obj` to `this`
float angle = (float)RandomHelper.NextDouble() * (2 * MathFunctions.PI);
float new_dist = (float)RandomHelper.NextDouble() + (float)RandomHelper.NextDouble();
float angle = RandomHelper.NextSingle() * (2 * MathFunctions.PI);
float new_dist = RandomHelper.NextSingle() + RandomHelper.NextSingle();
new_dist = distance * (new_dist > 1 ? new_dist - 2 : new_dist);
rand_x = (float)(pos.posX + new_dist * Math.Cos(angle));
rand_y = (float)(pos.posY + new_dist * Math.Sin(angle));
rand_x = (pos.posX + new_dist * MathF.Cos(angle));
rand_y = (pos.posY + new_dist * MathF.Sin(angle));
rand_z = pos.posZ;
GridDefines.NormalizeMapCoord(ref rand_x);
@@ -3570,7 +3570,7 @@ namespace Game.Entities
public Position GetRandomNearPosition(float radius)
{
var pos = GetPosition();
MovePosition(pos, radius * (float)RandomHelper.NextDouble(), (float)RandomHelper.NextDouble() * MathFunctions.PI * 2);
MovePosition(pos, radius * RandomHelper.NextSingle(), RandomHelper.NextSingle() * MathFunctions.PI * 2);
return pos;
}
+1 -1
View File
@@ -3410,7 +3410,7 @@ namespace Game.Entities
discreteResistProbability[i] = Math.Max(0.5f - 2.5f * Math.Abs(0.1f * i - averageResist), 0.0f);
}
float roll = (float)RandomHelper.NextDouble();
float roll = RandomHelper.NextSingle();
float probabilitySum = 0.0f;
uint resistance = 0;
+5 -5
View File
@@ -995,9 +995,9 @@ namespace Game.Spells
{
float minDist = m_spellInfo.GetMinRange(true);
float maxDist = m_spellInfo.GetMaxRange(true);
float dis = (float)RandomHelper.NextDouble() * (maxDist - minDist) + minDist;
float dis = RandomHelper.NextSingle() * (maxDist - minDist) + minDist;
float x, y, z;
float angle = (float)RandomHelper.NextDouble() * (MathFunctions.PI * 35.0f / 180.0f) - (float)(Math.PI * 17.5f / 180.0f);
float angle = RandomHelper.NextSingle() * (MathF.PI * 35.0f / 180.0f) - (MathF.PI * 17.5f / 180.0f);
m_caster.GetClosePoint(out x, out y, out z, SharedConst.DefaultPlayerBoundingRadius, dis, angle);
float ground = m_caster.GetMapHeight(x, y, z);
@@ -1114,7 +1114,7 @@ namespace Game.Spells
break;
case Targets.DestCasterRandom:
if (dist > objSize)
dist = objSize + (dist - objSize) * (float)RandomHelper.NextDouble();
dist = objSize + (dist - objSize) * RandomHelper.NextSingle();
break;
case Targets.DestCasterFrontLeft:
case Targets.DestCasterBackLeft:
@@ -1165,7 +1165,7 @@ namespace Game.Spells
float angle = targetType.CalcDirectionAngle();
float dist = spellEffectInfo.CalcRadius(null, targetIndex);
if (targetType.GetTarget() == Targets.DestRandom)
dist *= (float)RandomHelper.NextDouble();
dist *= RandomHelper.NextSingle();
Position pos = new(dest.Position);
target.MovePositionToFirstCollision(pos, dist, angle);
@@ -1219,7 +1219,7 @@ namespace Game.Spells
float angle = targetType.CalcDirectionAngle();
float dist = spellEffectInfo.CalcRadius(m_caster, targetIndex);
if (targetType.GetTarget() == Targets.DestRandom)
dist *= (float)RandomHelper.NextDouble();
dist *= RandomHelper.NextSingle();
Position pos = new(m_targets.GetDstPos());
m_caster.MovePositionToFirstCollision(pos, dist, angle);
+1 -1
View File
@@ -4129,7 +4129,7 @@ namespace Game.Spells
//GO is always friendly to it's creator, get range for friends
float min_dis = m_spellInfo.GetMinRange(true);
float max_dis = m_spellInfo.GetMaxRange(true);
float dis = (float)RandomHelper.NextDouble() * (max_dis - min_dis) + min_dis;
float dis = RandomHelper.NextSingle() * (max_dis - min_dis) + min_dis;
unitCaster.GetClosePoint(out fx, out fy, out fz, SharedConst.DefaultPlayerBoundingRadius, dis);
fo = unitCaster.GetOrientation();
+3 -3
View File
@@ -28,7 +28,7 @@ namespace Game.Spells
continue;
_effects.EnsureWritableListIndex((uint)spellEffect.EffectIndex, new SpellEffectInfo(this));
_effects[(int)spellEffect.EffectIndex] = new SpellEffectInfo(this, spellEffect);
_effects[spellEffect.EffectIndex] = new SpellEffectInfo(this, spellEffect);
}
// Correct EffectIndex for blank effects
@@ -1007,7 +1007,7 @@ namespace Game.Spells
if (HasAttribute(SpellAttr8.OnlyTargetIfSameCreator))
{
ObjectGuid getCreatorOrSelf(WorldObject obj)
var getCreatorOrSelf = (WorldObject obj) =>
{
ObjectGuid creator = obj.GetCreatorGUID();
if (creator.IsEmpty())
@@ -5005,7 +5005,7 @@ namespace Game.Spells
case SpellTargetDirectionTypes.FrontLeft:
return pi / 4;
case SpellTargetDirectionTypes.Random:
return (float)RandomHelper.NextDouble() * (2 * pi);
return RandomHelper.NextSingle() * (2 * pi);
default:
return 0.0f;
}
+3 -3
View File
@@ -217,16 +217,16 @@ namespace Game
}
else if (u < 90)
{
m_intensity = (float)RandomHelper.NextDouble() * 0.3333f;
m_intensity = RandomHelper.NextSingle() * 0.3333f;
}
else
{
// Severe change, but how severe?
rn = RandomHelper.URand(0, 99);
if (rn < 50)
m_intensity = (float)RandomHelper.NextDouble() * 0.3333f + 0.3334f;
m_intensity = RandomHelper.NextSingle() * 0.3333f + 0.3334f;
else
m_intensity = (float)RandomHelper.NextDouble() * 0.3333f + 0.6667f;
m_intensity = RandomHelper.NextSingle() * 0.3333f + 0.6667f;
}
// return true only in case weather changes
+2 -2
View File
@@ -276,7 +276,7 @@ namespace Scripts.Events
void HandleDummy(uint effIndex)
{
Position dest = GetCaster().GetFirstCollisionPosition(30.0f, (float)RandomHelper.NextDouble() * (float)(2 * MathF.PI));
Position dest = GetCaster().GetFirstCollisionPosition(30.0f, RandomHelper.NextSingle() * (float)(2 * MathF.PI));
GetCaster().CastSpell(dest, FlingTorch.SpellFlingTorchTriggered, true);
GetCaster().CastSpell(dest, FlingTorch.SpellFlingTorchShadow);
}
@@ -355,7 +355,7 @@ namespace Scripts.Events
}
else
{
Position dest = player.GetFirstCollisionPosition(15.0f, (float)RandomHelper.NextDouble() * (float)(2 * MathF.PI));
Position dest = player.GetFirstCollisionPosition(15.0f, RandomHelper.NextSingle() * (2 * MathF.PI));
player.CastSpell(player, FlingTorch.SpellTorchesCaught);
player.CastSpell(dest, FlingTorch.SpellFlingTorchTriggered, true);
player.CastSpell(dest, FlingTorch.SpellFlingTorchShadow);
+1 -1
View File
@@ -261,7 +261,7 @@ namespace Scripts.Events.ZalazaneFall
me.SetDisplayId(trollmodel[RandomHelper.URand(0, 39)]);
Player player = me.GetOwner().ToPlayer();
if (player != null)
me.GetMotionMaster().MoveFollow(player, 5.0f, (float)(RandomHelper.NextDouble() + 1.0f) * (float)(MathF.PI) / 3.0f * 4.0f);
me.GetMotionMaster().MoveFollow(player, 5.0f, (RandomHelper.NextSingle() + 1.0f) * (MathF.PI) / 3.0f * 4.0f);
}
public override void Reset()