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