fix: Adds GetDistanceToSqrt for Point3D and centralizes all the calls (#2233)
This commit is contained in:
parent
2086e9b292
commit
416e1be735
8 changed files with 56 additions and 39 deletions
|
|
@ -3723,38 +3723,6 @@ public partial class Mobile : IHued, IComparable<Mobile>, ISpawnable, IObjectPro
|
|||
{
|
||||
}
|
||||
|
||||
public double GetDistanceToSqrt(Point3D p)
|
||||
{
|
||||
var xDelta = m_Location.m_X - p.m_X;
|
||||
var yDelta = m_Location.m_Y - p.m_Y;
|
||||
|
||||
return Math.Sqrt(xDelta * xDelta + yDelta * yDelta);
|
||||
}
|
||||
|
||||
public double GetDistanceToSqrt(Mobile m)
|
||||
{
|
||||
var xDelta = m_Location.m_X - m.m_Location.m_X;
|
||||
var yDelta = m_Location.m_Y - m.m_Location.m_Y;
|
||||
|
||||
return Math.Sqrt(xDelta * xDelta + yDelta * yDelta);
|
||||
}
|
||||
|
||||
public double GetDistanceToSqrt(Point2D p)
|
||||
{
|
||||
var xDelta = m_Location.m_X - p.X;
|
||||
var yDelta = m_Location.m_Y - p.Y;
|
||||
|
||||
return Math.Sqrt(xDelta * xDelta + yDelta * yDelta);
|
||||
}
|
||||
|
||||
public double GetDistanceToSqrt(IPoint2D p)
|
||||
{
|
||||
var xDelta = m_Location.m_X - p.X;
|
||||
var yDelta = m_Location.m_Y - p.Y;
|
||||
|
||||
return Math.Sqrt(xDelta * xDelta + yDelta * yDelta);
|
||||
}
|
||||
|
||||
public virtual void AggressiveAction(Mobile aggressor) => AggressiveAction(aggressor, false);
|
||||
|
||||
public virtual void AggressiveAction(Mobile aggressor, bool criminal)
|
||||
|
|
|
|||
|
|
@ -1524,4 +1524,53 @@ public static partial class Utility
|
|||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double GetDistanceToSqrt(this IEntity entity, Point2D p) => GetDistanceToSqrt(entity.Location, p);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double GetDistanceToSqrt(this IEntity entity, Point3D p) => GetDistanceToSqrt(entity.Location, p);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double GetDistanceToSqrt(this IEntity from, IEntity to) => GetDistanceToSqrt(from.Location, to.Location);
|
||||
|
||||
public static double GetDistanceToSqrt(this IEntity entity, IPoint2D p)
|
||||
{
|
||||
var xDelta = entity.X - p.X;
|
||||
var yDelta = entity.Y - p.Y;
|
||||
|
||||
return Math.Sqrt(xDelta * xDelta + yDelta * yDelta);
|
||||
}
|
||||
|
||||
public static double GetDistanceToSqrt(this Point2D from, Point2D to)
|
||||
{
|
||||
var xDelta = from.m_X - to.m_X;
|
||||
var yDelta = from.m_Y - to.m_Y;
|
||||
|
||||
return Math.Sqrt(xDelta * xDelta + yDelta * yDelta);
|
||||
}
|
||||
|
||||
public static double GetDistanceToSqrt(this Point2D from, Point3D to)
|
||||
{
|
||||
var xDelta = from.m_X - to.m_X;
|
||||
var yDelta = from.m_Y - to.m_Y;
|
||||
|
||||
return Math.Sqrt(xDelta * xDelta + yDelta * yDelta);
|
||||
}
|
||||
|
||||
public static double GetDistanceToSqrt(this Point3D from, Point2D to)
|
||||
{
|
||||
var xDelta = from.m_X - to.m_X;
|
||||
var yDelta = from.m_Y - to.m_Y;
|
||||
|
||||
return Math.Sqrt(xDelta * xDelta + yDelta * yDelta);
|
||||
}
|
||||
|
||||
public static double GetDistanceToSqrt(this Point3D from, Point3D to)
|
||||
{
|
||||
var xDelta = from.m_X - to.m_X;
|
||||
var yDelta = from.m_Y - to.m_Y;
|
||||
|
||||
return Math.Sqrt(xDelta * xDelta + yDelta * yDelta);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ public partial class SummonedPaladin : BaseCreature
|
|||
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(5.0), Delete);
|
||||
}
|
||||
else if (_necromancer.Map != Map || GetDistanceToSqrt(_necromancer) > RangePerception + 1)
|
||||
else if (_necromancer.Map != Map || this.GetDistanceToSqrt(_necromancer) > RangePerception + 1)
|
||||
{
|
||||
Effects.SendLocationParticles(
|
||||
EffectItem.Create(Location, Map, EffectItem.DefaultDuration),
|
||||
|
|
|
|||
|
|
@ -2439,7 +2439,7 @@ namespace Server.Mobiles
|
|||
{
|
||||
FightMode.Strongest => m.Skills.Tactics.Value + m.Str, // returns strongest mobile
|
||||
FightMode.Weakest => -m.Hits, // returns weakest mobile
|
||||
_ => -GetDistanceToSqrt(m)
|
||||
_ => -this.GetDistanceToSqrt(m)
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -2461,7 +2461,7 @@ namespace Server.Mobiles
|
|||
|
||||
public bool IsHurt() => Hits != HitsMax;
|
||||
|
||||
public double GetHomeDistance() => GetDistanceToSqrt(m_Home);
|
||||
public double GetHomeDistance() => this.GetDistanceToSqrt(m_Home);
|
||||
|
||||
public virtual int GetTeamSize(int iRange)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -228,7 +228,7 @@ namespace Server.Mobiles
|
|||
|
||||
var total = Skills.Magery.Value + Skills.Poisoning.Value;
|
||||
|
||||
var dist = GetDistanceToSqrt(m);
|
||||
var dist = this.GetDistanceToSqrt(m);
|
||||
|
||||
if (dist >= 3.0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ namespace Server.Mobiles
|
|||
public override Poison PoisonImmune => Poison.Lethal;
|
||||
|
||||
public override double GetFightModeRanking(Mobile m, FightMode acqType, bool bPlayerOnly) =>
|
||||
m.Str / Math.Max(GetDistanceToSqrt(m), 1.0);
|
||||
m.Str / Math.Max(this.GetDistanceToSqrt(m), 1.0);
|
||||
|
||||
public override int GetAngerSound() => 0x23A;
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ namespace Server.Mobiles
|
|||
public override bool FollowsAcquireRules => Core.AOS || !Summoned || SummonMaster?.Player != true || Map != Map.Felucca;
|
||||
|
||||
public override double GetFightModeRanking(Mobile m, FightMode acqType, bool bPlayerOnly) =>
|
||||
(m.Str + m.Skills.Tactics.Value) / Math.Max(GetDistanceToSqrt(m), 1.0);
|
||||
(m.Str + m.Skills.Tactics.Value) / Math.Max(this.GetDistanceToSqrt(m), 1.0);
|
||||
|
||||
public override int GetAngerSound() => 0x23A;
|
||||
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ namespace Server.Mobiles
|
|||
public override bool FollowsAcquireRules => Core.AOS || !Summoned || SummonMaster?.Player != true || Map != Map.Felucca;
|
||||
|
||||
public override double GetFightModeRanking(Mobile m, FightMode acqType, bool bPlayerOnly) =>
|
||||
(m.Int + m.Skills.Magery.Value) / Math.Max(GetDistanceToSqrt(m), 1.0);
|
||||
(m.Int + m.Skills.Magery.Value) / Math.Max(this.GetDistanceToSqrt(m), 1.0);
|
||||
|
||||
public override int GetAngerSound() => 0x15;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue