diff --git a/Projects/Server/Geometry/Rectangle2D.cs b/Projects/Server/Geometry/Rectangle2D.cs index 0b1bd4793..ccd051760 100644 --- a/Projects/Server/Geometry/Rectangle2D.cs +++ b/Projects/Server/Geometry/Rectangle2D.cs @@ -21,12 +21,6 @@ namespace Server private Point2D m_Start; 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) { m_Start = start; @@ -141,7 +135,8 @@ namespace Server 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; - 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})"; } diff --git a/Projects/Server/Geometry/Rectangle3D.cs b/Projects/Server/Geometry/Rectangle3D.cs index 1bed6f4df..a81a24576 100644 --- a/Projects/Server/Geometry/Rectangle3D.cs +++ b/Projects/Server/Geometry/Rectangle3D.cs @@ -118,6 +118,18 @@ namespace Server && p.m_Z >= m_Start.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) => p.X >= m_Start.m_X && p.X < m_End.m_X diff --git a/Projects/Server/Geometry/WorldLocation.cs b/Projects/Server/Geometry/WorldLocation.cs index 23883b781..466f8ef82 100644 --- a/Projects/Server/Geometry/WorldLocation.cs +++ b/Projects/Server/Geometry/WorldLocation.cs @@ -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) { } diff --git a/Projects/Server/IEntity.cs b/Projects/Server/IEntity.cs index 4dbb61470..1d2dbcf62 100644 --- a/Projects/Server/IEntity.cs +++ b/Projects/Server/IEntity.cs @@ -29,8 +29,6 @@ namespace Server bool InRange(Point3D p, int range); - bool InRange(IPoint2D p, int range); - void RemoveItem(Item item); } diff --git a/Projects/Server/Items/Item.cs b/Projects/Server/Items/Item.cs index c54d6ae40..2704039d6 100644 --- a/Projects/Server/Items/Item.cs +++ b/Projects/Server/Items/Item.cs @@ -1606,23 +1606,9 @@ namespace Server set => Location = new Point3D(m_Location.m_X, m_Location.m_Y, value); } - public virtual bool InRange(Point2D p, int 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(Point2D p, int range) => Utility.InRange(p.X, p.Y, X, Y, range); - public virtual bool InRange(Point3D p, int 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 virtual bool InRange(Point3D p, int range) => Utility.InRange(p.X, p.Y, X, Y, range); public ExpandFlag GetExpandFlags() { diff --git a/Projects/Server/Maps/Map.cs b/Projects/Server/Maps/Map.cs index 42d6acc2a..3ddb12526 100644 --- a/Projects/Server/Maps/Map.cs +++ b/Projects/Server/Maps/Map.cs @@ -54,7 +54,7 @@ namespace Server public static IEnumerable 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 SelectEntities(Sector s, Rectangle2D bounds) => @@ -73,18 +73,18 @@ namespace Server 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 SelectMobiles(Sector s, Rectangle2D bounds) where T : Mobile { - return s.Mobiles.OfType().Where(o => !o.Deleted && bounds.Contains(o)); + return s.Mobiles.OfType().Where(o => !o.Deleted && bounds.Contains(o.Location)); } public static IEnumerable SelectItems(Sector s, Rectangle2D bounds) where T : Item { return s.Items.OfType() - .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 SelectMultis(Sector s, Rectangle2D bounds) @@ -806,7 +806,7 @@ namespace Server { if (this != Internal) { - GetSector(m).OnClientChange(oldState, newState); + GetSector(m.Location).OnClientChange(oldState, newState); } } @@ -814,7 +814,7 @@ namespace Server { if (this != Internal) { - GetSector(m).OnEnter(m); + GetSector(m.Location).OnEnter(m); } } @@ -825,7 +825,7 @@ namespace Server return; } - GetSector(item).OnEnter(item); + GetSector(item.Location).OnEnter(item); if (item is BaseMulti m) { @@ -842,7 +842,7 @@ namespace Server { if (this != Internal) { - GetSector(m).OnLeave(m); + GetSector(m.Location).OnLeave(m); } } @@ -853,7 +853,7 @@ namespace Server return; } - GetSector(item).OnLeave(item); + GetSector(item.Location).OnLeave(item); 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(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); diff --git a/Projects/Server/Mobiles/Mobile.cs b/Projects/Server/Mobiles/Mobile.cs index aee6309fa..cfa1de607 100644 --- a/Projects/Server/Mobiles/Mobile.cs +++ b/Projects/Server/Mobiles/Mobile.cs @@ -1119,8 +1119,7 @@ namespace Server [CommandProperty(AccessLevel.GameMaster)] 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 TimeSpan AutoManifestTimeout { get; set; } = TimeSpan.FromSeconds(5.0); @@ -2108,7 +2107,6 @@ namespace Server if (Stam < StamMax) { m_StamTimer ??= new StamTimer(this); - m_StamTimer.Start(); } else if (Stam > StamMax) @@ -2167,7 +2165,6 @@ namespace Server if (Mana < ManaMax) { m_ManaTimer ??= new ManaTimer(this); - m_ManaTimer.Start(); } else if (Mana > ManaMax) @@ -2234,17 +2231,14 @@ namespace Server DamageEntries.Clear(); // reset damage entries on full HP } } + else if (CanRegenHits) + { + m_HitsTimer ??= new HitsTimer(this); + m_HitsTimer.Start(); + } else { - if (CanRegenHits) - { - m_HitsTimer ??= new HitsTimer(this); - m_HitsTimer.Start(); - } - else - { - m_HitsTimer?.Stop(); - } + m_HitsTimer?.Stop(); } if (m_Hits != value) @@ -2279,22 +2273,14 @@ namespace Server 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 { - if (CanRegenStam) - { - m_StamTimer ??= new StamTimer(this); - - m_StamTimer.Start(); - } - else - { - m_StamTimer?.Stop(); - } + m_StamTimer?.Stop(); } if (m_Stam != value) @@ -2342,18 +2328,14 @@ namespace Server SendLocalizedMessage(501846); // You are at peace. } } + else if (CanRegenMana) + { + m_ManaTimer ??= new ManaTimer(this); + m_ManaTimer.Start(); + } else { - if (CanRegenMana) - { - m_ManaTimer ??= new ManaTimer(this); - - m_ManaTimer.Start(); - } - else - { - m_ManaTimer?.Stop(); - } + m_ManaTimer?.Stop(); } 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); /// /// Overridable. Virtual event invoked after the property has changed. @@ -5041,7 +5023,7 @@ namespace Server var root = item.RootParent; var okay = false; - if (!Utility.InUpdateRange(this, item.GetWorldLocation())) + if (!Utility.InUpdateRange(Location, item.GetWorldLocation())) { item.OnDoubleClickOutOfRange(this); } @@ -5111,7 +5093,7 @@ namespace Server return; } - if (!Utility.InUpdateRange(this, m)) + if (!Utility.InUpdateRange(Location, m.Location)) { m.OnDoubleClickOutOfRange(this); } @@ -5525,7 +5507,7 @@ namespace Server using var sb = new ValueStringBuilder(stackalloc char[Math.Min(text.Length, 256)]); for (var i = 0; i < text.Length; ++i) { - sb.Append(text[i] != ' ' ? GhostChars.RandomElement() : ' '); + sb.Append(text[i] != ' ' ? (GhostChars ?? DefaultGhostChars).RandomElement() : ' '); } text = sb.ToString(); @@ -6586,7 +6568,6 @@ namespace Server if (CanRegenStam) { m_StamTimer ??= new StamTimer(this); - m_StamTimer.Start(); } else @@ -6604,7 +6585,6 @@ namespace Server if (CanRegenMana) { m_ManaTimer ??= new ManaTimer(this); - m_ManaTimer.Start(); } else @@ -7986,7 +7966,7 @@ namespace Server /// 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); } @@ -8156,6 +8136,8 @@ namespace Server public static TimeSpan GetManaRegenRate(Mobile m) => ManaRegenRateHandler?.Invoke(m) ?? DefaultManaRate; + public static char[] DefaultGhostChars = { 'o', 'O' }; + public Prompt BeginPrompt(PromptCallback callback, PromptCallback cancelCallback) => Prompt = new SimplePrompt(callback, cancelCallback); @@ -9309,11 +9291,7 @@ namespace Server { private readonly Mobile m_Owner; - public ManaTimer(Mobile m) - : base(GetManaRegenRate(m), GetManaRegenRate(m)) - { - m_Owner = m; - } + public ManaTimer(Mobile m) : base(GetManaRegenRate(m), GetManaRegenRate(m)) => m_Owner = m; protected override void OnTick() { @@ -9330,11 +9308,7 @@ namespace Server { private readonly Mobile m_Owner; - public HitsTimer(Mobile m) - : base(GetHitsRegenRate(m), GetHitsRegenRate(m)) - { - m_Owner = m; - } + public HitsTimer(Mobile m) : base(GetHitsRegenRate(m), GetHitsRegenRate(m)) => m_Owner = m; protected override void OnTick() { @@ -9351,11 +9325,7 @@ namespace Server { private readonly Mobile m_Owner; - public StamTimer(Mobile m) - : base(GetStamRegenRate(m), GetStamRegenRate(m)) - { - m_Owner = m; - } + public StamTimer(Mobile m) : base(GetStamRegenRate(m), GetStamRegenRate(m)) => m_Owner = m; protected override void OnTick() { diff --git a/Projects/Server/Network/Packets/IncomingEntityPackets.cs b/Projects/Server/Network/Packets/IncomingEntityPackets.cs index d94bca39e..1a6c7711a 100644 --- a/Projects/Server/Network/Packets/IncomingEntityPackets.cs +++ b/Projects/Server/Network/Packets/IncomingEntityPackets.cs @@ -110,7 +110,7 @@ namespace Server.Network { 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) { @@ -173,7 +173,7 @@ namespace Server.Network { 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); } diff --git a/Projects/Server/Network/Packets/IncomingExtendedCommandPackets.cs b/Projects/Server/Network/Packets/IncomingExtendedCommandPackets.cs index fe8f01177..3579b40a1 100644 --- a/Projects/Server/Network/Packets/IncomingExtendedCommandPackets.cs +++ b/Projects/Server/Network/Packets/IncomingExtendedCommandPackets.cs @@ -347,7 +347,7 @@ namespace Server.Network { 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); } diff --git a/Projects/Server/Network/Packets/IncomingMobilePackets.cs b/Projects/Server/Network/Packets/IncomingMobilePackets.cs index a14746ce7..5d15625d8 100644 --- a/Projects/Server/Network/Packets/IncomingMobilePackets.cs +++ b/Projects/Server/Network/Packets/IncomingMobilePackets.cs @@ -42,7 +42,7 @@ namespace Server.Network { 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); } diff --git a/Projects/Server/Network/Packets/IncomingVendorPackets.cs b/Projects/Server/Network/Packets/IncomingVendorPackets.cs index 8589126e3..8d08218c1 100644 --- a/Projects/Server/Network/Packets/IncomingVendorPackets.cs +++ b/Projects/Server/Network/Packets/IncomingVendorPackets.cs @@ -36,7 +36,7 @@ namespace Server.Network 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 @@ -75,7 +75,7 @@ namespace Server.Network 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); return; diff --git a/Projects/Server/Sector.cs b/Projects/Server/Sector.cs index 8a8fa9cf1..898461856 100644 --- a/Projects/Server/Sector.cs +++ b/Projects/Server/Sector.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Runtime.CompilerServices; +using Server.Collections; using Server.Items; using Server.Network; @@ -141,11 +141,15 @@ namespace Server { if (m_Mobiles != null) { - var sandbox = new List(m_Mobiles); - - foreach (var mob in sandbox) + using var queue = PooledRefQueue.Create(m_Mobiles.Count); + foreach (var mob in m_Mobiles) { - mob.UpdateRegion(); + queue.Enqueue(mob); + } + + while (queue.Count > 0) + { + queue.Dequeue().UpdateRegion(); } } } @@ -162,7 +166,7 @@ namespace Server public void Activate() { - if (!Active && Owner != Map.Internal) + if (!Active) { if (m_Items != null) { diff --git a/Projects/Server/Timer/Timer.DelayCall.cs b/Projects/Server/Timer/Timer.DelayCall.cs index ab06fb076..11d6b84c6 100644 --- a/Projects/Server/Timer/Timer.DelayCall.cs +++ b/Projects/Server/Timer/Timer.DelayCall.cs @@ -19,7 +19,6 @@ using System.Collections.Generic; #endif using System.Diagnostics; using System.Runtime.CompilerServices; -using System.Threading; namespace Server { diff --git a/Projects/Server/Utilities/Utility.cs b/Projects/Server/Utilities/Utility.cs index f87750995..430dd0907 100644 --- a/Projects/Server/Utilities/Utility.cs +++ b/Projects/Server/Utilities/Utility.cs @@ -571,10 +571,14 @@ namespace Server 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 dy = to.Y - from.Y; + var dx = toX - fromX; + var dy = toY - fromY; var adx = Abs(dx); var ady = Abs(dy); @@ -615,32 +619,20 @@ namespace Server { if (bottom.m_X < top.m_X) { - var swap = top.m_X; - top.m_X = bottom.m_X; - bottom.m_X = swap; + (top.m_X, bottom.m_X) = (bottom.m_X, top.m_X); } if (bottom.m_Y < top.m_Y) { - var swap = top.m_Y; - top.m_Y = bottom.m_Y; - bottom.m_Y = swap; + (top.m_Y, bottom.m_Y) = (bottom.m_Y, top.m_Y); } if (bottom.m_Z < top.m_Z) { - var swap = top.m_Z; - top.m_Z = bottom.m_Z; - bottom.m_Z = swap; + (top.m_Z, bottom.m_Z) = (bottom.m_Z, top.m_Z); } } - 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) { 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) { - var i = bound1; - bound1 = bound2; - bound2 = i; + (bound1, bound2) = (bound2, bound1); } return num < bound2 + allowance && num > bound1 - allowance; @@ -1063,29 +1053,26 @@ namespace Server 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) => - p1.m_X >= p2.m_X - range - && p1.m_X <= p2.m_X + range - && p1.m_Y >= p2.m_Y - range - && p1.m_Y <= p2.m_Y + range; + InRange(p1.m_X, p1.m_Y, p2.m_X, p2.m_Y, range); - public static bool InUpdateRange(Point3D p1, Point3D 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(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; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool InUpdateRange(Point3D p1, Point3D p2) => InRange(p1, p2, 18); // 4d6+8 would be: Utility.Dice( 4, 6, 8 ) public static int Dice(uint amount, uint sides, int bonus) @@ -1106,9 +1093,7 @@ namespace Server for (var i = 0; i < count; i++) { var r = RandomMinMax(i, count - 1); - var swap = list[r]; - list[r] = list[i]; - list[i] = swap; + (list[r], list[i]) = (list[i], list[r]); } } @@ -1118,9 +1103,7 @@ namespace Server for (var i = 0; i < count; i++) { var r = RandomMinMax(i, count - 1); - var swap = list[r]; - list[r] = list[i]; - list[i] = swap; + (list[r], list[i]) = (list[i], list[r]); } } @@ -1208,9 +1191,7 @@ namespace Server { if (min > max) { - var copy = min; - min = max; - max = copy; + (min, max) = (max, min); } else if (min == max) { @@ -1225,9 +1206,7 @@ namespace Server { if (min > max) { - var copy = min; - min = max; - max = copy; + (min, max) = (max, min); } else if (min == max) { diff --git a/Projects/UOContent/Commands/VisibilityList.cs b/Projects/UOContent/Commands/VisibilityList.cs index b3ebae88d..cea19640d 100644 --- a/Projects/UOContent/Commands/VisibilityList.cs +++ b/Projects/UOContent/Commands/VisibilityList.cs @@ -75,7 +75,7 @@ namespace Server.Commands { 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); m.NetState?.Send(removeEntity); @@ -110,7 +110,7 @@ namespace Server.Commands 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; diff --git a/Projects/UOContent/Engines/ConPVP/Gumps/ArenaGump.cs b/Projects/UOContent/Engines/ConPVP/Gumps/ArenaGump.cs index 466549483..8f7a3cf97 100644 --- a/Projects/UOContent/Engines/ConPVP/Gumps/ArenaGump.cs +++ b/Projects/UOContent/Engines/ConPVP/Gumps/ArenaGump.cs @@ -245,7 +245,7 @@ namespace Server.Engines.ConPVP { 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. } diff --git a/Projects/UOContent/Engines/Party/Party.cs b/Projects/UOContent/Engines/Party/Party.cs index 2c3b1c0bd..f9e8c3f57 100644 --- a/Projects/UOContent/Engines/Party/Party.cs +++ b/Projects/UOContent/Engines/Party/Party.cs @@ -58,7 +58,7 @@ namespace Server.Engines.PartySystem var c = Members[i].Mobile; 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); } @@ -75,7 +75,7 @@ namespace Server.Engines.PartySystem var c = Members[i].Mobile; 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); } @@ -85,7 +85,7 @@ namespace Server.Engines.PartySystem public void OnStatsQuery(Mobile beholder, Mobile beheld) { if (beholder != beheld && Contains(beholder) && beholder.Map == beheld.Map && - Utility.InUpdateRange(beholder, beheld)) + Utility.InUpdateRange(beholder.Location, beheld.Location)) { if (!beholder.CanSee(beheld)) { diff --git a/Projects/UOContent/Engines/Quests/Dark Tides/Items/KronusScroll.cs b/Projects/UOContent/Engines/Quests/Dark Tides/Items/KronusScroll.cs index c27a0be0d..e893f2ff7 100644 --- a/Projects/UOContent/Engines/Quests/Dark Tides/Items/KronusScroll.cs +++ b/Projects/UOContent/Engines/Quests/Dark Tides/Items/KronusScroll.cs @@ -58,7 +58,7 @@ namespace Server.Engines.Quests.Necro } 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(); diff --git a/Projects/UOContent/Engines/Quests/Study of the Solen Hive/NestArea.cs b/Projects/UOContent/Engines/Quests/Study of the Solen Hive/NestArea.cs index 7cc0dbf65..bc93f6289 100644 --- a/Projects/UOContent/Engines/Quests/Study of the Solen Hive/NestArea.cs +++ b/Projects/UOContent/Engines/Quests/Study of the Solen Hive/NestArea.cs @@ -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)); } @@ -73,11 +73,13 @@ namespace Server.Engines.Quests.Naturalist 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) { - if (rect.Contains(p)) + if (rect.Contains(x, y)) { return true; } diff --git a/Projects/UOContent/Engines/Quests/Study of the Solen Hive/Objectives.cs b/Projects/UOContent/Engines/Quests/Study of the Solen Hive/Objectives.cs index db9219214..7f63dfa96 100644 --- a/Projects/UOContent/Engines/Quests/Study of the Solen Hive/Objectives.cs +++ b/Projects/UOContent/Engines/Quests/Study of the Solen Hive/Objectives.cs @@ -26,7 +26,7 @@ namespace Server.Engines.Quests.Naturalist { 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) { @@ -75,7 +75,7 @@ namespace Server.Engines.Quests.Naturalist } else if (from.Map == Map.Trammel || from.Map == Map.Felucca) { - var nest = NestArea.Find(from); + var nest = NestArea.Find(from.Location); if (nest != null) { diff --git a/Projects/UOContent/Engines/Treasures of Tokuno/TreasuresOfTokuno.cs b/Projects/UOContent/Engines/Treasures of Tokuno/TreasuresOfTokuno.cs index b21626fbc..676d4dd06 100644 --- a/Projects/UOContent/Engines/Treasures of Tokuno/TreasuresOfTokuno.cs +++ b/Projects/UOContent/Engines/Treasures of Tokuno/TreasuresOfTokuno.cs @@ -119,12 +119,12 @@ namespace Server.Misc { var r = m.Region; - if (r.IsPartOf() || BaseBoat.FindBoatAt(m, m.Map) != null) + if (r.IsPartOf() || BaseBoat.FindBoatAt(m.Location, m.Map) != null) { 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")) { return true; diff --git a/Projects/UOContent/Items/Misc/SerpentPillar.cs b/Projects/UOContent/Items/Misc/SerpentPillar.cs index 5157d4e39..2038aa244 100644 --- a/Projects/UOContent/Items/Misc/SerpentPillar.cs +++ b/Projects/UOContent/Items/Misc/SerpentPillar.cs @@ -39,7 +39,7 @@ namespace Server.Items 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) { diff --git a/Projects/UOContent/Items/Weapons/Maces/FireworksWand.cs b/Projects/UOContent/Items/Weapons/Maces/FireworksWand.cs index 672c97f6a..c107c02a6 100644 --- a/Projects/UOContent/Items/Weapons/Maces/FireworksWand.cs +++ b/Projects/UOContent/Items/Weapons/Maces/FireworksWand.cs @@ -88,32 +88,15 @@ namespace Server.Items private static void FinishLaunch(Point3D endLoc, Map map) { - var hue = Utility.Random(40); - - if (hue < 8) + var hue = Utility.Random(40) switch { - hue = 0x66D; - } - else if (hue < 10) - { - hue = 0x482; - } - else if (hue < 12) - { - hue = 0x47E; - } - else if (hue < 16) - { - hue = 0x480; - } - else if (hue < 20) - { - hue = 0x47F; - } - else - { - hue = 0; - } + < 8 => 0x66D, + < 10 => 0x482, + < 12 => 0x47E, + < 16 => 0x480, + < 20 => 0x47F, + _ => 0 + }; if (Utility.RandomBool()) { diff --git a/Projects/UOContent/Misc/RegenRates.cs b/Projects/UOContent/Misc/RegenRates.cs index 36d695b80..6359d3284 100644 --- a/Projects/UOContent/Misc/RegenRates.cs +++ b/Projects/UOContent/Misc/RegenRates.cs @@ -203,22 +203,13 @@ namespace Server.Misc { var medPoints = (from.Int + from.Skills.Meditation.Value) * 0.5; - if (medPoints <= 0) + rate = medPoints switch { - rate = 7.0; - } - else if (medPoints <= 100) - { - rate = 7.0 - 239 * medPoints / 2400 + 19 * medPoints * medPoints / 48000; - } - else if (medPoints < 120) - { - rate = 1.0; - } - else - { - rate = 0.75; - } + <= 0 => 7.0, + <= 100 => 7.0 - 239 * medPoints / 2400 + 19 * medPoints * medPoints / 48000, + < 120 => 1.0, + _ => 0.75 + }; rate += armorPenalty; diff --git a/Projects/UOContent/Mobiles/AI/BaseAI.cs b/Projects/UOContent/Mobiles/AI/BaseAI.cs index 0cff0afdc..42f74c24f 100644 --- a/Projects/UOContent/Mobiles/AI/BaseAI.cs +++ b/Projects/UOContent/Mobiles/AI/BaseAI.cs @@ -121,7 +121,7 @@ namespace Server.Mobiles { 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; } @@ -3040,7 +3040,7 @@ namespace Server.Mobiles 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) { m_Owner.Deactivate(); diff --git a/Projects/UOContent/Mobiles/BaseCreature.cs b/Projects/UOContent/Mobiles/BaseCreature.cs index 5732fb1a4..f846378ac 100644 --- a/Projects/UOContent/Mobiles/BaseCreature.cs +++ b/Projects/UOContent/Mobiles/BaseCreature.cs @@ -887,15 +887,13 @@ namespace Server.Mobiles public virtual bool CanBreath => HasBreath && !Summoned; public virtual bool IsDispellable => Summoned && !IsAnimatedDead; - public virtual bool - PlayerRangeSensitive // If they are following a waypoint, they'll continue to follow it even if players aren't around - => CurrentWayPoint == null; + // If they are following a waypoint, they'll continue to follow it even if players aren't around + public virtual bool PlayerRangeSensitive => CurrentWayPoint == null; public virtual bool ReturnsToHome => SeeksHome && Home != Point3D.Zero && !m_ReturnQueued && !Controlled && !Summoned; // used for deleting untamed creatures [in houses] - [CommandProperty(AccessLevel.GameMaster)] public bool RemoveIfUntamed { get; set; } @@ -3895,16 +3893,13 @@ namespace Server.Mobiles 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) { - SetLocation(Home, true); - - if (!Map.GetSector(X, Y).Active) - { - AIObject?.Deactivate(); - } + AIObject?.Deactivate(); } } diff --git a/Projects/UOContent/Mobiles/Vendors/PlayerVendor.cs b/Projects/UOContent/Mobiles/Vendors/PlayerVendor.cs index 11cffccc3..8bb6fdcb7 100644 --- a/Projects/UOContent/Mobiles/Vendors/PlayerVendor.cs +++ b/Projects/UOContent/Mobiles/Vendors/PlayerVendor.cs @@ -968,7 +968,7 @@ namespace Server.Mobiles 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; } @@ -1184,7 +1184,7 @@ namespace Server.Mobiles 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; } diff --git a/Projects/UOContent/Multis/Boats/BaseBoat.cs b/Projects/UOContent/Multis/Boats/BaseBoat.cs index eed92df2d..3bc792753 100644 --- a/Projects/UOContent/Multis/Boats/BaseBoat.cs +++ b/Projects/UOContent/Multis/Boats/BaseBoat.cs @@ -239,7 +239,7 @@ namespace Server.Multis 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); @@ -1512,7 +1512,7 @@ namespace Server.Multis var adx = dx.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; // Compute the maximum distance we can travel without going too far away diff --git a/Projects/UOContent/Multis/Boats/BaseBoatDeed.cs b/Projects/UOContent/Multis/Boats/BaseBoatDeed.cs index 49ee0708c..eabf02198 100644 --- a/Projects/UOContent/Multis/Boats/BaseBoatDeed.cs +++ b/Projects/UOContent/Multis/Boats/BaseBoatDeed.cs @@ -116,7 +116,7 @@ namespace Server.Multis return; } - if (from.Region.IsPartOf() || BaseBoat.FindBoatAt(from, from.Map) != null) + if (from.Region.IsPartOf() || BaseBoat.FindBoatAt(from.Location, from.Map) != null) { from.SendLocalizedMessage( 1010568, diff --git a/Projects/UOContent/Multis/Houses/BaseHouse.cs b/Projects/UOContent/Multis/Houses/BaseHouse.cs index bd6a66b22..80303a89a 100644 --- a/Projects/UOContent/Multis/Houses/BaseHouse.cs +++ b/Projects/UOContent/Multis/Houses/BaseHouse.cs @@ -707,16 +707,16 @@ namespace Server.Multis return fromSecures + fromVendors + fromLockdowns + fromMovingCrate; } - public override bool InRange(IPoint2D from, int range) + public bool InRange(Point2D from, int range) { if (Region == null) { return false; } - 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) { return true; diff --git a/Projects/UOContent/Network/MapUO.cs b/Projects/UOContent/Network/MapUO.cs index ac82b4ab3..c5d4649a2 100644 --- a/Projects/UOContent/Network/MapUO.cs +++ b/Projects/UOContent/Network/MapUO.cs @@ -79,7 +79,7 @@ namespace Server.Network continue; } - if (sendLocations && Utility.InUpdateRange(from, m) && from.CanSee(m)) + if (sendLocations && Utility.InUpdateRange(from.Location, m.Location) && from.CanSee(m)) { continue; } @@ -139,7 +139,7 @@ namespace Server.Network continue; } - if (Utility.InUpdateRange(from, mob) && from.CanSee(mob)) + if (Utility.InUpdateRange(from.Location, mob.Location) && from.CanSee(mob)) { continue; } diff --git a/Projects/UOContent/Skills/Meditation.cs b/Projects/UOContent/Skills/Meditation.cs index 123b63d63..b30f63a91 100644 --- a/Projects/UOContent/Skills/Meditation.cs +++ b/Projects/UOContent/Skills/Meditation.cs @@ -11,30 +11,10 @@ namespace Server.SkillHandlers SkillInfo.Table[46].Callback = OnUse; } - public static bool CheckOkayHolding(Item item) - { - if (item == null) - { - 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 bool CheckOkayHolding(Item item) => + item is null or Spellbook or Runebook + || Core.AOS && item is BaseWeapon weapon && weapon.Attributes.SpellChanneling != 0 + || Core.AOS && item is BaseArmor armor && armor.Attributes.SpellChanneling != 0; public static TimeSpan OnUse(Mobile m) { diff --git a/Projects/UOContent/Spells/Spellweaving/GiftOfLife.cs b/Projects/UOContent/Spells/Spellweaving/GiftOfLife.cs index 06ccae164..8d27cd5c6 100644 --- a/Projects/UOContent/Spells/Spellweaving/GiftOfLife.cs +++ b/Projects/UOContent/Spells/Spellweaving/GiftOfLife.cs @@ -112,7 +112,7 @@ namespace Server.Spells.Spellweaving { var master = pet.GetMaster(); - if (master?.NetState != null && Utility.InUpdateRange(pet, master)) + if (master?.NetState != null && Utility.InUpdateRange(pet.Location, master.Location)) { master.CloseGump(); master.SendGump(new PetResurrectGump(master, pet, hitsScalar)); @@ -125,7 +125,7 @@ namespace Server.Spells.Spellweaving { var friend = friends[i]; - if (friend.NetState != null && Utility.InUpdateRange(pet, friend)) + if (friend.NetState != null && Utility.InUpdateRange(pet.Location, friend.Location)) { friend.CloseGump(); friend.SendGump(new PetResurrectGump(friend, pet));