Clean up: Bugs, LINQ, constructors, default values, and null checks (#18)
This commit is contained in:
parent
e748af4430
commit
513e54f70e
1094 changed files with 15913 additions and 21892 deletions
|
|
@ -72,7 +72,7 @@ namespace Server
|
|||
|
||||
public static IEnumerable<NetState> SelectClients(Sector s, Rectangle2D bounds)
|
||||
{
|
||||
return s.Clients.Where(o => o?.Mobile != null && !o.Mobile.Deleted && bounds.Contains(o.Mobile));
|
||||
return s.Clients.Where(o => o?.Mobile?.Deleted == false && bounds.Contains(o.Mobile));
|
||||
}
|
||||
|
||||
public static IEnumerable<IEntity> SelectEntities(Sector s, Rectangle2D bounds)
|
||||
|
|
@ -84,9 +84,9 @@ namespace Server
|
|||
{
|
||||
IEnumerable<IEntity> eable = Enumerable.Empty<IEntity>();
|
||||
if (mobiles)
|
||||
eable = eable.Union(s.Mobiles.Where(o => o != null && !o.Deleted));
|
||||
eable = eable.Union(s.Mobiles.Where(o => o?.Deleted == false));
|
||||
if (items)
|
||||
eable = eable.Union(s.Items.Where(o => o != null && !o.Deleted && o.Parent == null));
|
||||
eable = eable.Union(s.Items.Where(o => o?.Deleted == false && o.Parent == null));
|
||||
|
||||
return eable.Where(bounds.Contains);
|
||||
}
|
||||
|
|
@ -99,17 +99,17 @@ namespace Server
|
|||
public static IEnumerable<T> SelectItems<T>(Sector s, Rectangle2D bounds) where T : Item
|
||||
{
|
||||
return s.Items.OfType<T>()
|
||||
.Where(o => !o.Deleted && o.Parent == null && bounds.Contains(o));
|
||||
.Where(o => o.Deleted == false && o.Parent == null && bounds.Contains(o));
|
||||
}
|
||||
|
||||
public static IEnumerable<BaseMulti> SelectMultis(Sector s, Rectangle2D bounds)
|
||||
{
|
||||
return s.Multis.Where(o => o != null && !o.Deleted && bounds.Contains(o.Location));
|
||||
return s.Multis.Where(o => o?.Deleted == false && bounds.Contains(o.Location));
|
||||
}
|
||||
|
||||
public static IEnumerable<StaticTile[]> SelectMultiTiles(Sector s, Rectangle2D bounds)
|
||||
{
|
||||
foreach (BaseMulti o in s.Multis.Where(o => o != null && !o.Deleted))
|
||||
foreach (BaseMulti o in s.Multis.Where(o => o?.Deleted == false))
|
||||
{
|
||||
MultiComponentList c = o.Components;
|
||||
|
||||
|
|
@ -354,13 +354,8 @@ namespace Server
|
|||
|
||||
public Region DefaultRegion
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_DefaultRegion == null)
|
||||
m_DefaultRegion = new Region(null, this, 0, new Rectangle3D[0]);
|
||||
|
||||
return m_DefaultRegion;
|
||||
}
|
||||
get => m_DefaultRegion ??
|
||||
(m_DefaultRegion = new Region(null, this, 0, new Rectangle3D[0]));
|
||||
set => m_DefaultRegion = value;
|
||||
}
|
||||
|
||||
|
|
@ -424,16 +419,16 @@ namespace Server
|
|||
|
||||
public static Map Parse(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value)) return null;
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return null;
|
||||
|
||||
if (Insensitive.Equals(value, "Internal")) return Internal;
|
||||
if (Insensitive.Equals(value, "Internal"))
|
||||
return Internal;
|
||||
|
||||
if (!int.TryParse(value, out int index))
|
||||
return Maps.FirstOrDefault(m => m != null && Insensitive.Equals(m.Name, value));
|
||||
|
||||
if (index == 127) return Internal;
|
||||
|
||||
return Maps.FirstOrDefault(m => m != null && m.MapIndex == index);
|
||||
return index == 127 ? Internal : Maps.FirstOrDefault(m => m != null && m.MapIndex == index);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
|
@ -473,10 +468,8 @@ namespace Server
|
|||
if (zBottom > top)
|
||||
top = zBottom;
|
||||
|
||||
if (Math.Abs(zTop - zBottom) > Math.Abs(zLeft - zRight))
|
||||
avg = FloorAverage(zLeft, zRight);
|
||||
else
|
||||
avg = FloorAverage(zTop, zBottom);
|
||||
avg = Math.Abs(zTop - zBottom) > Math.Abs(zLeft - zRight) ?
|
||||
FloorAverage(zLeft, zRight) : FloorAverage(zTop, zBottom);
|
||||
}
|
||||
|
||||
private static int FloorAverage(int a, int b)
|
||||
|
|
@ -496,16 +489,19 @@ namespace Server
|
|||
|
||||
private static List<Item> AcquireFixItems(Map map, int x, int y)
|
||||
{
|
||||
if (map == null || map == Internal || x < 0 || x > map.Width || y < 0 || y > map.Height) return _EmptyFixItems;
|
||||
if (map == null || map == Internal || x < 0 || x > map.Width || y < 0 || y > map.Height)
|
||||
return _EmptyFixItems;
|
||||
|
||||
List<Item> pool = null;
|
||||
|
||||
lock (_FixPool)
|
||||
{
|
||||
if (_FixPool.Count > 0) pool = _FixPool.Dequeue();
|
||||
if (_FixPool.Count > 0)
|
||||
pool = _FixPool.Dequeue();
|
||||
}
|
||||
|
||||
if (pool == null) pool = new List<Item>(128); // Arbitrary limit
|
||||
if (pool == null)
|
||||
pool = new List<Item>(128); // Arbitrary limit
|
||||
|
||||
IPooledEnumerable<Item> eable = map.GetItemsInRange(new Point3D(x, y, 0), 0);
|
||||
|
||||
|
|
@ -528,7 +524,8 @@ namespace Server
|
|||
|
||||
lock (_FixPool)
|
||||
{
|
||||
if (_FixPool.Count < 128) _FixPool.Enqueue(pool);
|
||||
if (_FixPool.Count < 128)
|
||||
_FixPool.Enqueue(pool);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1064,13 +1061,12 @@ namespace Server
|
|||
|
||||
IEnumerable<T> pool = PooledEnumeration.EnumerateSectors(map, bounds).SelectMany(s => selector(s, bounds));
|
||||
|
||||
if (e != null)
|
||||
{
|
||||
e._Pool.AddRange(pool);
|
||||
return e;
|
||||
}
|
||||
if (e == null)
|
||||
return new PooledEnumerable<T>(pool);
|
||||
|
||||
e._Pool.AddRange(pool);
|
||||
return e;
|
||||
|
||||
return new PooledEnumerable<T>(pool);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1436,14 +1432,7 @@ namespace Server
|
|||
{
|
||||
IPooledEnumerable<Item> eable = GetItemsInRange(point, 0);
|
||||
|
||||
foreach (Item item in eable)
|
||||
{
|
||||
if (item.Visible)
|
||||
contains = false;
|
||||
|
||||
if (!contains)
|
||||
break;
|
||||
}
|
||||
contains = !eable.Any(item => item.Visible);
|
||||
|
||||
eable.Free();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue