fix: Cleanup IPoint3D calls (#704)

This commit is contained in:
Kamron Batman 2021-08-19 09:11:48 -07:00 • committed by GitHub
parent 788b04b958
commit 3293ffcf06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 158 additions and 264 deletions

View file

@ -21,12 +21,6 @@ namespace Server
private Point2D m_Start; private Point2D m_Start;
private Point2D m_End; private Point2D m_End;
public Rectangle2D(IPoint2D start, IPoint2D end)
{
m_Start = new Point2D(start);
m_End = new Point2D(end);
}
public Rectangle2D(Point2D start, Point2D end) public Rectangle2D(Point2D start, Point2D end)
{ {
m_Start = start; m_Start = start;
@ -141,7 +135,8 @@ namespace Server
public readonly bool Contains(Point2D p) => public readonly bool Contains(Point2D p) =>
m_Start.m_X <= p.m_X && m_Start.m_Y <= p.m_Y && m_End.m_X > p.m_X && m_End.m_Y > p.m_Y; m_Start.m_X <= p.m_X && m_Start.m_Y <= p.m_Y && m_End.m_X > p.m_X && m_End.m_Y > p.m_Y;
public readonly bool Contains(IPoint2D p) => m_Start <= p && m_End > p; public readonly bool Contains(int x, int y) =>
m_Start.m_X <= x && m_Start.m_Y <= y && m_End.m_X > x && m_End.m_Y > y;
public override string ToString() => $"({X}, {Y})+({Width}, {Height})"; public override string ToString() => $"({X}, {Y})+({Width}, {Height})";
} }

View file

@ -118,6 +118,18 @@ namespace Server
&& p.m_Z >= m_Start.m_Z && p.m_Z >= m_Start.m_Z
&& p.m_Z < m_End.m_Z; && p.m_Z < m_End.m_Z;
public bool Contains(Point2D p) =>
p.m_X >= m_Start.m_X
&& p.m_X < m_End.m_X
&& p.m_Y >= m_Start.m_Y
&& p.m_Y < m_End.m_Y;
public bool Contains(IPoint2D p) =>
p.X >= m_Start.m_X
&& p.X < m_End.m_X
&& p.Y >= m_Start.m_Y
&& p.Y < m_End.m_Y;
public bool Contains(IPoint3D p) => public bool Contains(IPoint3D p) =>
p.X >= m_Start.m_X p.X >= m_Start.m_X
&& p.X < m_End.m_X && p.X < m_End.m_X

View file

@ -66,7 +66,7 @@ namespace Server
{ {
} }
public WorldLocation(IPoint2D p, Map map) : this(p.X, p.Y, 0, map) public WorldLocation(Point2D p, Map map) : this(p.X, p.Y, 0, map)
{ {
} }
@ -74,7 +74,7 @@ namespace Server
{ {
} }
public WorldLocation(IPoint3D p, Map map) : this(p.X, p.Y, p.Z, map) public WorldLocation(Point3D p, Map map) : this(p.X, p.Y, p.Z, map)
{ {
} }

View file

@ -29,8 +29,6 @@ namespace Server
bool InRange(Point3D p, int range); bool InRange(Point3D p, int range);
bool InRange(IPoint2D p, int range);
void RemoveItem(Item item); void RemoveItem(Item item);
} }

View file

@ -1606,23 +1606,9 @@ namespace Server
set => Location = new Point3D(m_Location.m_X, m_Location.m_Y, value); set => Location = new Point3D(m_Location.m_X, m_Location.m_Y, value);
} }
public virtual bool InRange(Point2D p, int range) => public virtual bool InRange(Point2D p, int range) => Utility.InRange(p.X, p.Y, X, Y, range);
p.m_X >= Location.m_X - range
&& p.m_X <= Location.m_X + range
&& p.m_Y >= Location.m_Y - range
&& p.m_Y <= Location.m_Y + range;
public virtual bool InRange(Point3D p, int range) => public virtual bool InRange(Point3D p, int range) => Utility.InRange(p.X, p.Y, X, Y, range);
p.m_X >= Location.m_X - range
&& p.m_X <= Location.m_X + range
&& p.m_Y >= Location.m_Y - range
&& p.m_Y <= Location.m_Y + range;
public virtual bool InRange(IPoint2D p, int range) =>
p.X >= Location.m_X - range
&& p.X <= Location.m_X + range
&& p.Y >= Location.m_Y - range
&& p.Y <= Location.m_Y + range;
public ExpandFlag GetExpandFlags() public ExpandFlag GetExpandFlags()
{ {

View file

@ -54,7 +54,7 @@ namespace Server
public static IEnumerable<NetState> SelectClients(Sector s, Rectangle2D bounds) public static IEnumerable<NetState> SelectClients(Sector s, Rectangle2D bounds)
{ {
return s.Clients.Where(o => o?.Mobile?.Deleted == false && bounds.Contains(o.Mobile)); return s.Clients.Where(o => o?.Mobile?.Deleted == false && bounds.Contains(o.Mobile.Location));
} }
public static IEnumerable<IEntity> SelectEntities(Sector s, Rectangle2D bounds) => public static IEnumerable<IEntity> SelectEntities(Sector s, Rectangle2D bounds) =>
@ -73,18 +73,18 @@ namespace Server
eable = eable.Union(s.Items.Where(o => o?.Deleted == false && o.Parent == null)); eable = eable.Union(s.Items.Where(o => o?.Deleted == false && o.Parent == null));
} }
return eable.Where(bounds.Contains); return eable.Where(o => bounds.Contains(o.Location));
} }
public static IEnumerable<T> SelectMobiles<T>(Sector s, Rectangle2D bounds) where T : Mobile public static IEnumerable<T> SelectMobiles<T>(Sector s, Rectangle2D bounds) where T : Mobile
{ {
return s.Mobiles.OfType<T>().Where(o => !o.Deleted && bounds.Contains(o)); return s.Mobiles.OfType<T>().Where(o => !o.Deleted && bounds.Contains(o.Location));
} }
public static IEnumerable<T> SelectItems<T>(Sector s, Rectangle2D bounds) where T : Item public static IEnumerable<T> SelectItems<T>(Sector s, Rectangle2D bounds) where T : Item
{ {
return s.Items.OfType<T>() return s.Items.OfType<T>()
.Where(o => o.Deleted == false && o.Parent == null && bounds.Contains(o)); .Where(o => o.Deleted == false && o.Parent == null && bounds.Contains(o.Location));
} }
public static IEnumerable<BaseMulti> SelectMultis(Sector s, Rectangle2D bounds) public static IEnumerable<BaseMulti> SelectMultis(Sector s, Rectangle2D bounds)
@ -806,7 +806,7 @@ namespace Server
{ {
if (this != Internal) if (this != Internal)
{ {
GetSector(m).OnClientChange(oldState, newState); GetSector(m.Location).OnClientChange(oldState, newState);
} }
} }
@ -814,7 +814,7 @@ namespace Server
{ {
if (this != Internal) if (this != Internal)
{ {
GetSector(m).OnEnter(m); GetSector(m.Location).OnEnter(m);
} }
} }
@ -825,7 +825,7 @@ namespace Server
return; return;
} }
GetSector(item).OnEnter(item); GetSector(item.Location).OnEnter(item);
if (item is BaseMulti m) if (item is BaseMulti m)
{ {
@ -842,7 +842,7 @@ namespace Server
{ {
if (this != Internal) if (this != Internal)
{ {
GetSector(m).OnLeave(m); GetSector(m.Location).OnLeave(m);
} }
} }
@ -853,7 +853,7 @@ namespace Server
return; return;
} }
GetSector(item).OnLeave(item); GetSector(item.Location).OnLeave(item);
if (item is BaseMulti m) if (item is BaseMulti m)
{ {
@ -1192,7 +1192,7 @@ namespace Server
public Sector GetSector(Point2D p) => InternalGetSector(p.m_X >> SectorShift, p.m_Y >> SectorShift); public Sector GetSector(Point2D p) => InternalGetSector(p.m_X >> SectorShift, p.m_Y >> SectorShift);
public Sector GetSector(IPoint2D p) => InternalGetSector(p.X >> SectorShift, p.Y >> SectorShift); // public Sector GetSector(IPoint2D p) => InternalGetSector(p.X >> SectorShift, p.Y >> SectorShift);
public Sector GetSector(int x, int y) => InternalGetSector(x >> SectorShift, y >> SectorShift); public Sector GetSector(int x, int y) => InternalGetSector(x >> SectorShift, y >> SectorShift);

View file

@ -1119,8 +1119,7 @@ namespace Server
[CommandProperty(AccessLevel.GameMaster)] [CommandProperty(AccessLevel.GameMaster)]
public Container Corpse { get; set; } public Container Corpse { get; set; }
public static char[] GhostChars { get; set; } = { 'o', 'O' }; public static char[] GhostChars { get; set; }
public static bool NoSpeechLOS { get; set; } public static bool NoSpeechLOS { get; set; }
public static TimeSpan AutoManifestTimeout { get; set; } = TimeSpan.FromSeconds(5.0); public static TimeSpan AutoManifestTimeout { get; set; } = TimeSpan.FromSeconds(5.0);
@ -2108,7 +2107,6 @@ namespace Server
if (Stam < StamMax) if (Stam < StamMax)
{ {
m_StamTimer ??= new StamTimer(this); m_StamTimer ??= new StamTimer(this);
m_StamTimer.Start(); m_StamTimer.Start();
} }
else if (Stam > StamMax) else if (Stam > StamMax)
@ -2167,7 +2165,6 @@ namespace Server
if (Mana < ManaMax) if (Mana < ManaMax)
{ {
m_ManaTimer ??= new ManaTimer(this); m_ManaTimer ??= new ManaTimer(this);
m_ManaTimer.Start(); m_ManaTimer.Start();
} }
else if (Mana > ManaMax) else if (Mana > ManaMax)
@ -2234,17 +2231,14 @@ namespace Server
DamageEntries.Clear(); // reset damage entries on full HP DamageEntries.Clear(); // reset damage entries on full HP
} }
} }
else if (CanRegenHits)
{
m_HitsTimer ??= new HitsTimer(this);
m_HitsTimer.Start();
}
else else
{ {
if (CanRegenHits) m_HitsTimer?.Stop();
{
m_HitsTimer ??= new HitsTimer(this);
m_HitsTimer.Start();
}
else
{
m_HitsTimer?.Stop();
}
} }
if (m_Hits != value) if (m_Hits != value)
@ -2279,22 +2273,14 @@ namespace Server
value = Math.Clamp(value, 0, StamMax); value = Math.Clamp(value, 0, StamMax);
if (value == StamMax) if (CanRegenStam && value < StamMax)
{ {
m_StamTimer?.Stop(); m_StamTimer ??= new StamTimer(this);
m_StamTimer.Start();
} }
else else
{ {
if (CanRegenStam) m_StamTimer?.Stop();
{
m_StamTimer ??= new StamTimer(this);
m_StamTimer.Start();
}
else
{
m_StamTimer?.Stop();
}
} }
if (m_Stam != value) if (m_Stam != value)
@ -2342,18 +2328,14 @@ namespace Server
SendLocalizedMessage(501846); // You are at peace. SendLocalizedMessage(501846); // You are at peace.
} }
} }
else if (CanRegenMana)
{
m_ManaTimer ??= new ManaTimer(this);
m_ManaTimer.Start();
}
else else
{ {
if (CanRegenMana) m_ManaTimer?.Stop();
{
m_ManaTimer ??= new ManaTimer(this);
m_ManaTimer.Start();
}
else
{
m_ManaTimer?.Stop();
}
} }
if (m_Mana != value) if (m_Mana != value)
@ -3874,7 +3856,7 @@ namespace Server
} }
} }
public virtual bool CheckAttack(Mobile m) => Utility.InUpdateRange(this, m) && CanSee(m) && InLOS(m); public virtual bool CheckAttack(Mobile m) => Utility.InUpdateRange(Location, m.Location) && CanSee(m) && InLOS(m);
/// <summary> /// <summary>
/// Overridable. Virtual event invoked after the <see cref="Combatant" /> property has changed. /// Overridable. Virtual event invoked after the <see cref="Combatant" /> property has changed.
@ -5041,7 +5023,7 @@ namespace Server
var root = item.RootParent; var root = item.RootParent;
var okay = false; var okay = false;
if (!Utility.InUpdateRange(this, item.GetWorldLocation())) if (!Utility.InUpdateRange(Location, item.GetWorldLocation()))
{ {
item.OnDoubleClickOutOfRange(this); item.OnDoubleClickOutOfRange(this);
} }
@ -5111,7 +5093,7 @@ namespace Server
return; return;
} }
if (!Utility.InUpdateRange(this, m)) if (!Utility.InUpdateRange(Location, m.Location))
{ {
m.OnDoubleClickOutOfRange(this); m.OnDoubleClickOutOfRange(this);
} }
@ -5525,7 +5507,7 @@ namespace Server
using var sb = new ValueStringBuilder(stackalloc char[Math.Min(text.Length, 256)]); using var sb = new ValueStringBuilder(stackalloc char[Math.Min(text.Length, 256)]);
for (var i = 0; i < text.Length; ++i) for (var i = 0; i < text.Length; ++i)
{ {
sb.Append(text[i] != ' ' ? GhostChars.RandomElement() : ' '); sb.Append(text[i] != ' ' ? (GhostChars ?? DefaultGhostChars).RandomElement() : ' ');
} }
text = sb.ToString(); text = sb.ToString();
@ -6586,7 +6568,6 @@ namespace Server
if (CanRegenStam) if (CanRegenStam)
{ {
m_StamTimer ??= new StamTimer(this); m_StamTimer ??= new StamTimer(this);
m_StamTimer.Start(); m_StamTimer.Start();
} }
else else
@ -6604,7 +6585,6 @@ namespace Server
if (CanRegenMana) if (CanRegenMana)
{ {
m_ManaTimer ??= new ManaTimer(this); m_ManaTimer ??= new ManaTimer(this);
m_ManaTimer.Start(); m_ManaTimer.Start();
} }
else else
@ -7986,7 +7966,7 @@ namespace Server
/// <param name="from"></param> /// <param name="from"></param>
public virtual void OnStatsQuery(Mobile from) public virtual void OnStatsQuery(Mobile from)
{ {
if (from.Map == Map && Utility.InUpdateRange(this, from) && from.CanSee(this)) if (from.Map == Map && Utility.InUpdateRange(Location, from.Location) && from.CanSee(this))
{ {
from.m_NetState.SendMobileStatus(from, this); from.m_NetState.SendMobileStatus(from, this);
} }
@ -8156,6 +8136,8 @@ namespace Server
public static TimeSpan GetManaRegenRate(Mobile m) => ManaRegenRateHandler?.Invoke(m) ?? DefaultManaRate; public static TimeSpan GetManaRegenRate(Mobile m) => ManaRegenRateHandler?.Invoke(m) ?? DefaultManaRate;
public static char[] DefaultGhostChars = { 'o', 'O' };
public Prompt BeginPrompt(PromptCallback callback, PromptCallback cancelCallback) => public Prompt BeginPrompt(PromptCallback callback, PromptCallback cancelCallback) =>
Prompt = new SimplePrompt(callback, cancelCallback); Prompt = new SimplePrompt(callback, cancelCallback);
@ -9309,11 +9291,7 @@ namespace Server
{ {
private readonly Mobile m_Owner; private readonly Mobile m_Owner;
public ManaTimer(Mobile m) public ManaTimer(Mobile m) : base(GetManaRegenRate(m), GetManaRegenRate(m)) => m_Owner = m;
: base(GetManaRegenRate(m), GetManaRegenRate(m))
{
m_Owner = m;
}
protected override void OnTick() protected override void OnTick()
{ {
@ -9330,11 +9308,7 @@ namespace Server
{ {
private readonly Mobile m_Owner; private readonly Mobile m_Owner;
public HitsTimer(Mobile m) public HitsTimer(Mobile m) : base(GetHitsRegenRate(m), GetHitsRegenRate(m)) => m_Owner = m;
: base(GetHitsRegenRate(m), GetHitsRegenRate(m))
{
m_Owner = m;
}
protected override void OnTick() protected override void OnTick()
{ {
@ -9351,11 +9325,7 @@ namespace Server
{ {
private readonly Mobile m_Owner; private readonly Mobile m_Owner;
public StamTimer(Mobile m) public StamTimer(Mobile m) : base(GetStamRegenRate(m), GetStamRegenRate(m)) => m_Owner = m;
: base(GetStamRegenRate(m), GetStamRegenRate(m))
{
m_Owner = m;
}
protected override void OnTick() protected override void OnTick()
{ {

View file

@ -110,7 +110,7 @@ namespace Server.Network
{ {
var m = World.FindMobile(s); var m = World.FindMobile(s);
if (m != null && from.CanSee(m) && Utility.InUpdateRange(from, m)) if (m != null && from.CanSee(m) && Utility.InUpdateRange(from.Location, m.Location))
{ {
if (SingleClickProps) if (SingleClickProps)
{ {
@ -173,7 +173,7 @@ namespace Server.Network
{ {
var m = World.FindMobile(s); var m = World.FindMobile(s);
if (m != null && from.CanSee(m) && Utility.InUpdateRange(from, m)) if (m != null && from.CanSee(m) && Utility.InUpdateRange(from.Location, m.Location))
{ {
m.SendPropertiesTo(from); m.SendPropertiesTo(from);
} }

View file

@ -347,7 +347,7 @@ namespace Server.Network
{ {
var m = World.FindMobile(s); var m = World.FindMobile(s);
if (m != null && from.CanSee(m) && Utility.InUpdateRange(from, m)) if (m != null && from.CanSee(m) && Utility.InUpdateRange(from.Location, m.Location))
{ {
m.SendPropertiesTo(from); m.SendPropertiesTo(from);
} }

View file

@ -42,7 +42,7 @@ namespace Server.Network
{ {
var m = World.FindMobile(reader.ReadUInt32()); var m = World.FindMobile(reader.ReadUInt32());
if (m != null && Utility.InUpdateRange(state.Mobile, m) && state.Mobile.CanSee(m)) if (m != null && Utility.InUpdateRange(state.Mobile.Location, m.Location) && state.Mobile.CanSee(m))
{ {
state.SendMobileName(m); state.SendMobileName(m);
} }

View file

@ -36,7 +36,7 @@ namespace Server.Network
var flag = reader.ReadByte(); var flag = reader.ReadByte();
if (!vendor.Deleted && Utility.RangeCheck(vendor.Location, state.Mobile.Location, 10) && flag == 0x02) if (!vendor.Deleted && Utility.InRange(vendor.Location, state.Mobile.Location, 10) && flag == 0x02)
{ {
var msgSize = packetLength - 8; // Remaining bytes var msgSize = packetLength - 8; // Remaining bytes
@ -75,7 +75,7 @@ namespace Server.Network
return; return;
} }
if (vendor.Deleted || !Utility.RangeCheck(vendor.Location, state.Mobile.Location, 10)) if (vendor.Deleted || !Utility.InRange(vendor.Location, state.Mobile.Location, 10))
{ {
state.SendEndVendorSell(vendor.Serial); state.SendEndVendorSell(vendor.Serial);
return; return;

View file

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices; using Server.Collections;
using Server.Items; using Server.Items;
using Server.Network; using Server.Network;
@ -141,11 +141,15 @@ namespace Server
{ {
if (m_Mobiles != null) if (m_Mobiles != null)
{ {
var sandbox = new List<Mobile>(m_Mobiles); using var queue = PooledRefQueue<Mobile>.Create(m_Mobiles.Count);
foreach (var mob in m_Mobiles)
foreach (var mob in sandbox)
{ {
mob.UpdateRegion(); queue.Enqueue(mob);
}
while (queue.Count > 0)
{
queue.Dequeue().UpdateRegion();
} }
} }
} }
@ -162,7 +166,7 @@ namespace Server
public void Activate() public void Activate()
{ {
if (!Active && Owner != Map.Internal) if (!Active)
{ {
if (m_Items != null) if (m_Items != null)
{ {

View file

@ -19,7 +19,6 @@ using System.Collections.Generic;
#endif #endif
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Threading;
namespace Server namespace Server
{ {

View file

@ -571,10 +571,14 @@ namespace Server
public static bool InsensitiveStartsWith(string first, string second) => first.InsensitiveStartsWith(second); public static bool InsensitiveStartsWith(string first, string second) => first.InsensitiveStartsWith(second);
public static Direction GetDirection(IPoint2D from, IPoint2D to) public static Direction GetDirection(Point3D from, Point3D to) => GetDirection(from.X, from.Y, to.X, to.Y);
public static Direction GetDirection(Point2D from, Point2D to) => GetDirection(from.X, from.Y, to.X, to.Y);
public static Direction GetDirection(int fromX, int fromY, int toX, int toY)
{ {
var dx = to.X - from.X; var dx = toX - fromX;
var dy = to.Y - from.Y; var dy = toY - fromY;
var adx = Abs(dx); var adx = Abs(dx);
var ady = Abs(dy); var ady = Abs(dy);
@ -615,32 +619,20 @@ namespace Server
{ {
if (bottom.m_X < top.m_X) if (bottom.m_X < top.m_X)
{ {
var swap = top.m_X; (top.m_X, bottom.m_X) = (bottom.m_X, top.m_X);
top.m_X = bottom.m_X;
bottom.m_X = swap;
} }
if (bottom.m_Y < top.m_Y) if (bottom.m_Y < top.m_Y)
{ {
var swap = top.m_Y; (top.m_Y, bottom.m_Y) = (bottom.m_Y, top.m_Y);
top.m_Y = bottom.m_Y;
bottom.m_Y = swap;
} }
if (bottom.m_Z < top.m_Z) if (bottom.m_Z < top.m_Z)
{ {
var swap = top.m_Z; (top.m_Z, bottom.m_Z) = (bottom.m_Z, top.m_Z);
top.m_Z = bottom.m_Z;
bottom.m_Z = swap;
} }
} }
public static bool RangeCheck(IPoint2D p1, IPoint2D p2, int range) =>
p1.X >= p2.X - range
&& p1.X <= p2.X + range
&& p1.Y >= p2.Y - range
&& p2.Y <= p2.Y + range;
public static void FormatBuffer(TextWriter output, Stream input, int length) public static void FormatBuffer(TextWriter output, Stream input, int length)
{ {
output.WriteLine(" 0 1 2 3 4 5 6 7 8 9 A B C D E F"); output.WriteLine(" 0 1 2 3 4 5 6 7 8 9 A B C D E F");
@ -874,9 +866,7 @@ namespace Server
{ {
if (bound1 > bound2) if (bound1 > bound2)
{ {
var i = bound1; (bound1, bound2) = (bound2, bound1);
bound1 = bound2;
bound2 = i;
} }
return num < bound2 + allowance && num > bound1 - allowance; return num < bound2 + allowance && num > bound1 - allowance;
@ -1063,29 +1053,26 @@ namespace Server
public static string GetText(XmlElement node, string defaultValue) => node?.InnerText ?? defaultValue; public static string GetText(XmlElement node, string defaultValue) => node?.InnerText ?? defaultValue;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool InRange(int p1X, int p1Y, int p2X, int p2Y, int range) =>
p1X >= p2X - range
&& p1X <= p2X + range
&& p1Y >= p2Y - range
&& p1Y <= p2Y + range;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool InRange(Point2D p1, Point2D p2, int range) =>
InRange(p1.m_X, p1.m_Y, p2.m_X, p2.m_Y, range);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool InUpdateRange(Point2D p1, Point2D p2) => InRange(p1, p2, 18);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool InRange(Point3D p1, Point3D p2, int range) => public static bool InRange(Point3D p1, Point3D p2, int range) =>
p1.m_X >= p2.m_X - range InRange(p1.m_X, p1.m_Y, p2.m_X, p2.m_Y, range);
&& p1.m_X <= p2.m_X + range
&& p1.m_Y >= p2.m_Y - range
&& p1.m_Y <= p2.m_Y + range;
public static bool InUpdateRange(Point3D p1, Point3D p2) => [MethodImpl(MethodImplOptions.AggressiveInlining)]
p1.m_X >= p2.m_X - 18 public static bool InUpdateRange(Point3D p1, Point3D p2) => InRange(p1, p2, 18);
&& p1.m_X <= p2.m_X + 18
&& p1.m_Y >= p2.m_Y - 18
&& p1.m_Y <= p2.m_Y + 18;
public static bool InUpdateRange(Point2D p1, Point2D p2) =>
p1.m_X >= p2.m_X - 18
&& p1.m_X <= p2.m_X + 18
&& p1.m_Y >= p2.m_Y - 18
&& p1.m_Y <= p2.m_Y + 18;
public static bool InUpdateRange(IPoint2D p1, IPoint2D p2) =>
p1.X >= p2.X - 18
&& p1.X <= p2.X + 18
&& p1.Y >= p2.Y - 18
&& p1.Y <= p2.Y + 18;
// 4d6+8 would be: Utility.Dice( 4, 6, 8 ) // 4d6+8 would be: Utility.Dice( 4, 6, 8 )
public static int Dice(uint amount, uint sides, int bonus) public static int Dice(uint amount, uint sides, int bonus)
@ -1106,9 +1093,7 @@ namespace Server
for (var i = 0; i < count; i++) for (var i = 0; i < count; i++)
{ {
var r = RandomMinMax(i, count - 1); var r = RandomMinMax(i, count - 1);
var swap = list[r]; (list[r], list[i]) = (list[i], list[r]);
list[r] = list[i];
list[i] = swap;
} }
} }
@ -1118,9 +1103,7 @@ namespace Server
for (var i = 0; i < count; i++) for (var i = 0; i < count; i++)
{ {
var r = RandomMinMax(i, count - 1); var r = RandomMinMax(i, count - 1);
var swap = list[r]; (list[r], list[i]) = (list[i], list[r]);
list[r] = list[i];
list[i] = swap;
} }
} }
@ -1208,9 +1191,7 @@ namespace Server
{ {
if (min > max) if (min > max)
{ {
var copy = min; (min, max) = (max, min);
min = max;
max = copy;
} }
else if (min == max) else if (min == max)
{ {
@ -1225,9 +1206,7 @@ namespace Server
{ {
if (min > max) if (min > max)
{ {
var copy = min; (min, max) = (max, min);
min = max;
max = copy;
} }
else if (min == max) else if (min == max)
{ {

View file

@ -75,7 +75,7 @@ namespace Server.Commands
{ {
var m = list[i]; var m = list[i];
if (!m.CanSee(pm) && Utility.InUpdateRange(m, pm)) if (!m.CanSee(pm) && Utility.InUpdateRange(m.Location, pm.Location))
{ {
OutgoingEntityPackets.CreateRemoveEntity(removeEntity, pm.Serial); OutgoingEntityPackets.CreateRemoveEntity(removeEntity, pm.Serial);
m.NetState?.Send(removeEntity); m.NetState?.Send(removeEntity);
@ -110,7 +110,7 @@ namespace Server.Commands
pm.SendMessage("{0} has been added to your visibility list.", targ.Name); pm.SendMessage("{0} has been added to your visibility list.", targ.Name);
} }
if (Utility.InUpdateRange(targ, from)) if (Utility.InUpdateRange(targ.Location, from.Location))
{ {
var ns = targ.NetState; var ns = targ.NetState;

View file

@ -245,7 +245,7 @@ namespace Server.Engines.ConPVP
{ {
m_From.SendLocalizedMessage(1049616); // You are too busy to do that at the moment. m_From.SendLocalizedMessage(1049616); // You are too busy to do that at the moment.
} }
else if (m_From.Map == arena.Facet && arena.Zone.Contains(m_From)) else if (m_From.Map == arena.Facet && arena.Zone.Contains(m_From.Location))
{ {
m_From.SendLocalizedMessage(1019003); // You are already there. m_From.SendLocalizedMessage(1019003); // You are already there.
} }

View file

@ -58,7 +58,7 @@ namespace Server.Engines.PartySystem
var c = Members[i].Mobile; var c = Members[i].Mobile;
var ns = c.NetState; var ns = c.NetState;
if (c != m && ns != null && m.Map == c.Map && Utility.InUpdateRange(c, m) && c.CanSee(m)) if (c != m && ns != null && m.Map == c.Map && Utility.InUpdateRange(c.Location, m.Location) && c.CanSee(m))
{ {
ns.Send(p); ns.Send(p);
} }
@ -75,7 +75,7 @@ namespace Server.Engines.PartySystem
var c = Members[i].Mobile; var c = Members[i].Mobile;
var ns = c.NetState; var ns = c.NetState;
if (c != m && ns != null && m.Map == c.Map && Utility.InUpdateRange(c, m) && c.CanSee(m)) if (c != m && ns != null && m.Map == c.Map && Utility.InUpdateRange(c.Location, m.Location) && c.CanSee(m))
{ {
ns.Send(p); ns.Send(p);
} }
@ -85,7 +85,7 @@ namespace Server.Engines.PartySystem
public void OnStatsQuery(Mobile beholder, Mobile beheld) public void OnStatsQuery(Mobile beholder, Mobile beheld)
{ {
if (beholder != beheld && Contains(beholder) && beholder.Map == beheld.Map && if (beholder != beheld && Contains(beholder) && beholder.Map == beheld.Map &&
Utility.InUpdateRange(beholder, beheld)) Utility.InUpdateRange(beholder.Location, beheld.Location))
{ {
if (!beholder.CanSee(beheld)) if (!beholder.CanSee(beheld))
{ {

View file

@ -58,7 +58,7 @@ namespace Server.Engines.Quests.Necro
} }
else if (qs.IsObjectiveInProgress(typeof(UseCallingScrollObjective))) else if (qs.IsObjectiveInProgress(typeof(UseCallingScrollObjective)))
{ {
if (pm.Map == m_WellOfTearsMap && m_WellOfTearsArea.Contains(pm)) if (pm.Map == m_WellOfTearsMap && m_WellOfTearsArea.Contains(pm.Location))
{ {
QuestObjective obj = qs.FindObjective<UseCallingScrollObjective>(); QuestObjective obj = qs.FindObjective<UseCallingScrollObjective>();

View file

@ -58,7 +58,7 @@ namespace Server.Engines.Quests.Naturalist
} }
} }
public static NestArea Find(IPoint2D p) public static NestArea Find(Point3D p)
{ {
return m_Areas.FirstOrDefault(area => area.Contains(p)); return m_Areas.FirstOrDefault(area => area.Contains(p));
} }
@ -73,11 +73,13 @@ namespace Server.Engines.Quests.Naturalist
return null; return null;
} }
public bool Contains(IPoint2D p) public bool Contains(Point3D p)
{ {
var x = p.X;
var y = p.Y;
foreach (var rect in m_Rects) foreach (var rect in m_Rects)
{ {
if (rect.Contains(p)) if (rect.Contains(x, y))
{ {
return true; return true;
} }

View file

@ -26,7 +26,7 @@ namespace Server.Engines.Quests.Naturalist
{ {
var nest = m_CurrentNest; var nest = m_CurrentNest;
if ((from.Map == Map.Trammel || from.Map == Map.Felucca) && nest.Contains(from)) if ((from.Map == Map.Trammel || from.Map == Map.Felucca) && nest.Contains(from.Location))
{ {
if (m_StudyState != StudyState.Inactive) if (m_StudyState != StudyState.Inactive)
{ {
@ -75,7 +75,7 @@ namespace Server.Engines.Quests.Naturalist
} }
else if (from.Map == Map.Trammel || from.Map == Map.Felucca) else if (from.Map == Map.Trammel || from.Map == Map.Felucca)
{ {
var nest = NestArea.Find(from); var nest = NestArea.Find(from.Location);
if (nest != null) if (nest != null)
{ {

View file

@ -119,12 +119,12 @@ namespace Server.Misc
{ {
var r = m.Region; var r = m.Region;
if (r.IsPartOf<HouseRegion>() || BaseBoat.FindBoatAt(m, m.Map) != null) if (r.IsPartOf<HouseRegion>() || BaseBoat.FindBoatAt(m.Location, m.Map) != null)
{ {
return false; return false;
} }
// TODO: a CanReach of something check as opposed to above?
// TODO: a CanReach of something check as opposed to above?
if (r.IsPartOf("Yomotsu Mines") || r.IsPartOf("Fan Dancer's Dojo")) if (r.IsPartOf("Yomotsu Mines") || r.IsPartOf("Fan Dancer's Dojo"))
{ {
return true; return true;

View file

@ -39,7 +39,7 @@ namespace Server.Items
if (!e.Handled && from.InRange(this, 10) && e.Speech.ToLower() == Word) if (!e.Handled && from.InRange(this, 10) && e.Speech.ToLower() == Word)
{ {
var boat = BaseBoat.FindBoatAt(from, from.Map); var boat = BaseBoat.FindBoatAt(from.Location, from.Map);
if (boat == null) if (boat == null)
{ {

View file

@ -88,32 +88,15 @@ namespace Server.Items
private static void FinishLaunch(Point3D endLoc, Map map) private static void FinishLaunch(Point3D endLoc, Map map)
{ {
var hue = Utility.Random(40); var hue = Utility.Random(40) switch
if (hue < 8)
{ {
hue = 0x66D; < 8 => 0x66D,
} < 10 => 0x482,
else if (hue < 10) < 12 => 0x47E,
{ < 16 => 0x480,
hue = 0x482; < 20 => 0x47F,
} _ => 0
else if (hue < 12) };
{
hue = 0x47E;
}
else if (hue < 16)
{
hue = 0x480;
}
else if (hue < 20)
{
hue = 0x47F;
}
else
{
hue = 0;
}
if (Utility.RandomBool()) if (Utility.RandomBool())
{ {

View file

@ -203,22 +203,13 @@ namespace Server.Misc
{ {
var medPoints = (from.Int + from.Skills.Meditation.Value) * 0.5; var medPoints = (from.Int + from.Skills.Meditation.Value) * 0.5;
if (medPoints <= 0) rate = medPoints switch
{ {
rate = 7.0; <= 0 => 7.0,
} <= 100 => 7.0 - 239 * medPoints / 2400 + 19 * medPoints * medPoints / 48000,
else if (medPoints <= 100) < 120 => 1.0,
{ _ => 0.75
rate = 7.0 - 239 * medPoints / 2400 + 19 * medPoints * medPoints / 48000; };
}
else if (medPoints < 120)
{
rate = 1.0;
}
else
{
rate = 0.75;
}
rate += armorPenalty; rate += armorPenalty;

View file

@ -121,7 +121,7 @@ namespace Server.Mobiles
{ {
activate = false; activate = false;
} }
else if (m.Map == null || m.Map == Map.Internal || !m.Map.GetSector(m).Active) else if (m.Map == null || m.Map == Map.Internal || !m.Map.GetSector(m.Location).Active)
{ {
activate = false; activate = false;
} }
@ -3040,7 +3040,7 @@ namespace Server.Mobiles
if (m_Owner.m_Mobile.PlayerRangeSensitive) // have to check this in the timer.... if (m_Owner.m_Mobile.PlayerRangeSensitive) // have to check this in the timer....
{ {
var sect = m_Owner.m_Mobile.Map.GetSector(m_Owner.m_Mobile); var sect = m_Owner.m_Mobile.Map.GetSector(m_Owner.m_Mobile.Location);
if (!sect.Active) if (!sect.Active)
{ {
m_Owner.Deactivate(); m_Owner.Deactivate();

View file

@ -887,15 +887,13 @@ namespace Server.Mobiles
public virtual bool CanBreath => HasBreath && !Summoned; public virtual bool CanBreath => HasBreath && !Summoned;
public virtual bool IsDispellable => Summoned && !IsAnimatedDead; public virtual bool IsDispellable => Summoned && !IsAnimatedDead;
public virtual bool // If they are following a waypoint, they'll continue to follow it even if players aren't around
PlayerRangeSensitive // If they are following a waypoint, they'll continue to follow it even if players aren't around public virtual bool PlayerRangeSensitive => CurrentWayPoint == null;
=> CurrentWayPoint == null;
public virtual bool ReturnsToHome => public virtual bool ReturnsToHome =>
SeeksHome && Home != Point3D.Zero && !m_ReturnQueued && !Controlled && !Summoned; SeeksHome && Home != Point3D.Zero && !m_ReturnQueued && !Controlled && !Summoned;
// used for deleting untamed creatures [in houses] // used for deleting untamed creatures [in houses]
[CommandProperty(AccessLevel.GameMaster)] [CommandProperty(AccessLevel.GameMaster)]
public bool RemoveIfUntamed { get; set; } public bool RemoveIfUntamed { get; set; }
@ -3895,16 +3893,13 @@ namespace Server.Mobiles
public void GoHome_Callback() public void GoHome_Callback()
{ {
if (m_ReturnQueued && IsSpawnerBound()) if (m_ReturnQueued && IsSpawnerBound() && !Map.GetSector(X, Y).Active)
{ {
SetLocation(Home, true);
if (!Map.GetSector(X, Y).Active) if (!Map.GetSector(X, Y).Active)
{ {
SetLocation(Home, true); AIObject?.Deactivate();
if (!Map.GetSector(X, Y).Active)
{
AIObject?.Deactivate();
}
} }
} }

View file

@ -968,7 +968,7 @@ namespace Server.Mobiles
public bool CanInteractWith(Mobile from, bool ownerOnly) public bool CanInteractWith(Mobile from, bool ownerOnly)
{ {
if (!from.CanSee(this) || !Utility.InUpdateRange(from, this) || !from.CheckAlive()) if (!from.CanSee(this) || !Utility.InUpdateRange(from.Location, Location) || !from.CheckAlive())
{ {
return false; return false;
} }
@ -1184,7 +1184,7 @@ namespace Server.Mobiles
return false; return false;
} }
if (House.IsInside(to) || to.Map != House.Map || !House.InRange(to, 5)) if (House.IsInside(to) || to.Map != House.Map || !House.InRange(to.Location, 5))
{ {
return false; return false;
} }

View file

@ -239,7 +239,7 @@ namespace Server.Multis
public override bool AllowsRelativeDrop => true; public override bool AllowsRelativeDrop => true;
public static BaseBoat FindBoatAt(IPoint2D loc, Map map) public static BaseBoat FindBoatAt(Point3D loc, Map map)
{ {
var sector = map.GetSector(loc); var sector = map.GetSector(loc);
@ -1512,7 +1512,7 @@ namespace Server.Multis
var adx = dx.Abs(); var adx = dx.Abs();
var ady = dy.Abs(); var ady = dy.Abs();
var dir = Utility.GetDirection(this, new Point2D(x, y)); var dir = Utility.GetDirection(Location.X, Location.Y, x, y);
var iDir = (int)dir; var iDir = (int)dir;
// Compute the maximum distance we can travel without going too far away // Compute the maximum distance we can travel without going too far away

View file

@ -116,7 +116,7 @@ namespace Server.Multis
return; return;
} }
if (from.Region.IsPartOf<HouseRegion>() || BaseBoat.FindBoatAt(from, from.Map) != null) if (from.Region.IsPartOf<HouseRegion>() || BaseBoat.FindBoatAt(from.Location, from.Map) != null)
{ {
from.SendLocalizedMessage( from.SendLocalizedMessage(
1010568, 1010568,

View file

@ -707,16 +707,16 @@ namespace Server.Multis
return fromSecures + fromVendors + fromLockdowns + fromMovingCrate; return fromSecures + fromVendors + fromLockdowns + fromMovingCrate;
} }
public override bool InRange(IPoint2D from, int range) public bool InRange(Point2D from, int range)
{ {
if (Region == null) if (Region == null)
{ {
return false; return false;
} }
foreach (var rect in Region.Area) foreach (var rect in Region.Area)
{ {
// TODO: Convert this to 3D - https://github.com/modernuo/ModernUO/issues/29
if (from.X >= rect.Start.X - range && from.Y >= rect.Start.Y - range && from.X < rect.End.X + range && from.Y < rect.End.Y + range) if (from.X >= rect.Start.X - range && from.Y >= rect.Start.Y - range && from.X < rect.End.X + range && from.Y < rect.End.Y + range)
{ {
return true; return true;

View file

@ -79,7 +79,7 @@ namespace Server.Network
continue; continue;
} }
if (sendLocations && Utility.InUpdateRange(from, m) && from.CanSee(m)) if (sendLocations && Utility.InUpdateRange(from.Location, m.Location) && from.CanSee(m))
{ {
continue; continue;
} }
@ -139,7 +139,7 @@ namespace Server.Network
continue; continue;
} }
if (Utility.InUpdateRange(from, mob) && from.CanSee(mob)) if (Utility.InUpdateRange(from.Location, mob.Location) && from.CanSee(mob))
{ {
continue; continue;
} }

View file

@ -11,30 +11,10 @@ namespace Server.SkillHandlers
SkillInfo.Table[46].Callback = OnUse; SkillInfo.Table[46].Callback = OnUse;
} }
public static bool CheckOkayHolding(Item item) public static bool CheckOkayHolding(Item item) =>
{ item is null or Spellbook or Runebook
if (item == null) || Core.AOS && item is BaseWeapon weapon && weapon.Attributes.SpellChanneling != 0
{ || Core.AOS && item is BaseArmor armor && armor.Attributes.SpellChanneling != 0;
return true;
}
if (item is Spellbook || item is Runebook)
{
return true;
}
if (Core.AOS && item is BaseWeapon weapon && weapon.Attributes.SpellChanneling != 0)
{
return true;
}
if (Core.AOS && item is BaseArmor armor && armor.Attributes.SpellChanneling != 0)
{
return true;
}
return false;
}
public static TimeSpan OnUse(Mobile m) public static TimeSpan OnUse(Mobile m)
{ {

View file

@ -112,7 +112,7 @@ namespace Server.Spells.Spellweaving
{ {
var master = pet.GetMaster(); var master = pet.GetMaster();
if (master?.NetState != null && Utility.InUpdateRange(pet, master)) if (master?.NetState != null && Utility.InUpdateRange(pet.Location, master.Location))
{ {
master.CloseGump<PetResurrectGump>(); master.CloseGump<PetResurrectGump>();
master.SendGump(new PetResurrectGump(master, pet, hitsScalar)); master.SendGump(new PetResurrectGump(master, pet, hitsScalar));
@ -125,7 +125,7 @@ namespace Server.Spells.Spellweaving
{ {
var friend = friends[i]; var friend = friends[i];
if (friend.NetState != null && Utility.InUpdateRange(pet, friend)) if (friend.NetState != null && Utility.InUpdateRange(pet.Location, friend.Location))
{ {
friend.CloseGump<PetResurrectGump>(); friend.CloseGump<PetResurrectGump>();
friend.SendGump(new PetResurrectGump(friend, pet)); friend.SendGump(new PetResurrectGump(friend, pet));