Revert "Updates Packets & Randomizer (#43)" (#61)

This reverts commit 179cb50557.
This commit is contained in:
Kamron Batman 2019-11-11 08:46:11 -08:00 • committed by GitHub
parent 179cb50557
commit c2ecc76457
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
588 changed files with 16260 additions and 10926 deletions

View file

@ -20,10 +20,8 @@
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Server.Items;
using Server.Network;
using Server.Targeting;
@ -47,7 +45,7 @@ namespace Server
void Free();
}
public interface IPooledEnumerable<out T> : IPooledEnumerable, IEnumerable<T>
public interface IPooledEnumerable<T> : IPooledEnumerable, IEnumerable<T>
{
}
@ -90,15 +88,21 @@ namespace Server
return eable.Where(bounds.Contains);
}
public static IEnumerable<T> SelectMobiles<T>(Sector s, Rectangle2D bounds) where T : Mobile =>
s.Mobiles.OfType<T>().Where(o => !o.Deleted && bounds.Contains(o));
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));
}
public static IEnumerable<T> SelectItems<T>(Sector s, Rectangle2D bounds) where T : Item =>
s.Items.OfType<T>()
public static IEnumerable<T> SelectItems<T>(Sector s, Rectangle2D bounds) where T : Item
{
return s.Items.OfType<T>()
.Where(o => o.Deleted == false && o.Parent == null && bounds.Contains(o));
}
public static IEnumerable<BaseMulti> SelectMultis(Sector s, Rectangle2D bounds) =>
s.Multis.Where(o => o?.Deleted == false && bounds.Contains(o.Location));
public static IEnumerable<BaseMulti> SelectMultis(Sector s, Rectangle2D bounds)
{
return s.Multis.Where(o => o?.Deleted == false && bounds.Contains(o.Location));
}
public static IEnumerable<StaticTile[]> SelectMultiTiles(Sector s, Rectangle2D bounds)
{
@ -106,23 +110,26 @@ namespace Server
{
MultiComponentList c = o.Components;
for (int x = bounds.Start.X; x < bounds.End.X; x++)
int x, y, xo, yo;
StaticTile[] t, r;
for (x = bounds.Start.X; x < bounds.End.X; x++)
{
int xo = x - (o.X + c.Min.X);
xo = x - (o.X + c.Min.X);
if (xo < 0 || xo >= c.Width) continue;
for (int y = bounds.Start.Y; y < bounds.End.Y; y++)
for (y = bounds.Start.Y; y < bounds.End.Y; y++)
{
int yo = y - (o.Y + c.Min.Y);
yo = y - (o.Y + c.Min.Y);
if (yo < 0 || yo >= c.Height) continue;
StaticTile[] t = c.Tiles[xo][yo];
t = c.Tiles[xo][yo];
if (t.Length <= 0) continue;
StaticTile[] r = new StaticTile[t.Length];
r = new StaticTile[t.Length];
for (int i = 0; i < t.Length; i++)
{
@ -250,7 +257,7 @@ namespace Server
public const int SectorShift = 4;
public static int SectorActiveRange = 2;
private static readonly ConcurrentQueue<List<Item>> _FixPool = new ConcurrentQueue<List<Item>>();
private static readonly Queue<List<Item>> _FixPool = new Queue<List<Item>>(128);
private static readonly List<Item> _EmptyFixItems = new List<Item>();
private Region m_DefaultRegion;
@ -264,7 +271,9 @@ namespace Server
private TileMatrix m_Tiles;
public Map(int mapID, int mapIndex, int fileIndex, int width, int height, byte season, string name, MapRules rules)
private object tileLock = new object();
public Map(int mapID, int mapIndex, int fileIndex, int width, int height, int season, string name, MapRules rules)
{
MapID = mapID;
MapIndex = mapIndex;
@ -293,14 +302,17 @@ namespace Server
public static List<Map> AllMaps{ get; } = new List<Map>();
public byte Season{ get; set; }
public int Season{ get; set; }
public TileMatrix Tiles
{
get
{
if (m_Tiles == null)
Interlocked.Exchange(ref m_Tiles, new TileMatrix(this, m_FileIndex, MapID, Width, Height));
lock (tileLock)
{
m_Tiles = new TileMatrix(this, m_FileIndex, MapID, Width, Height);
}
return m_Tiles;
}
@ -318,7 +330,8 @@ namespace Server
public Region DefaultRegion
{
get => m_DefaultRegion ??= new Region(null, this, 0, new Rectangle3D[0]);
get => m_DefaultRegion ??
(m_DefaultRegion = new Region(null, this, 0, new Rectangle3D[0]));
set => m_DefaultRegion = value;
}
@ -356,9 +369,15 @@ namespace Server
public int CompareTo(Map other) => other == null ? -1 : MapID.CompareTo(other.MapID);
public static string[] GetMapNames() => Maps.Where(m => m != null).Select(m => m.Name).ToArray();
public static string[] GetMapNames()
{
return Maps.Where(m => m != null).Select(m => m.Name).ToArray();
}
public static Map[] GetMapValues() => Maps.Where(m => m != null).ToArray();
public static Map[] GetMapValues()
{
return Maps.Where(m => m != null).ToArray();
}
public static Map Parse(string value)
{
@ -369,7 +388,7 @@ namespace Server
return Internal;
if (!int.TryParse(value, out int index))
return Maps.FirstOrDefault(m => Insensitive.Equals(m?.Name ?? "", value));
return Maps.FirstOrDefault(m => m != null && Insensitive.Equals(m.Name, value));
return index == 127 ? Internal : Maps.FirstOrDefault(m => m?.MapIndex == index);
}
@ -429,7 +448,15 @@ namespace Server
if (map == null || map == Internal || x < 0 || x > map.Width || y < 0 || y > map.Height)
return _EmptyFixItems;
if (!_FixPool.TryDequeue(out List<Item> pool) || pool == null)
List<Item> pool = null;
lock (_FixPool)
{
if (_FixPool.Count > 0)
pool = _FixPool.Dequeue();
}
if (pool == null)
pool = new List<Item>(128); // Arbitrary limit
IPooledEnumerable<Item> eable = map.GetItemsInRange(new Point3D(x, y, 0), 0);
@ -451,8 +478,11 @@ namespace Server
pool.Clear();
if (_FixPool.Count < 128)
_FixPool.Enqueue(pool);
lock (_FixPool)
{
if (_FixPool.Count < 128)
_FixPool.Enqueue(pool);
}
}
public void FixColumn(int x, int y)
@ -548,13 +578,13 @@ namespace Server
/// Gets the highest surface that is lower than <paramref name="p" />.
/// </summary>
/// <param name="p">The reference point.</param>
/// <returns>A surface <typeparamref><name>ITile</name></typeparamref></returns>
public ITile GetTopSurface(Point3D p)
/// <returns>A surface <typeparamref name="Tile" /> or <typeparamref name="Item" />.</returns>
public object GetTopSurface(Point3D p)
{
if (this == Internal)
return null;
ITile surface = null;
object surface = null;
int surfaceZ = int.MinValue;
@ -906,7 +936,7 @@ namespace Server
public sealed class PooledEnumerable<T> : IPooledEnumerable<T>, IDisposable
{
private static readonly ConcurrentQueue<PooledEnumerable<T>> _Buffer = new ConcurrentQueue<PooledEnumerable<T>>();
private static readonly Queue<PooledEnumerable<T>> _Buffer = new Queue<PooledEnumerable<T>>(0x400);
private bool _IsDisposed;
@ -938,20 +968,29 @@ namespace Server
_Pool.Clear();
_Pool.Capacity = Math.Max(_Pool.Capacity, 0x100);
_Buffer.Enqueue(this);
lock (((ICollection)_Buffer).SyncRoot)
{
_Buffer.Enqueue(this);
}
}
public static PooledEnumerable<T> Instantiate(Map map, Rectangle2D bounds, PooledEnumeration.Selector<T> selector)
{
IEnumerable<T> pool = PooledEnumeration.EnumerateSectors(map, bounds).SelectMany(s => selector(s, bounds));
PooledEnumerable<T> e = null;
if (_Buffer.TryDequeue(out PooledEnumerable<T> e) && e != null)
lock (((ICollection)_Buffer).SyncRoot)
{
e._Pool.AddRange(pool);
return e;
if (_Buffer.Count > 0)
e = _Buffer.Dequeue();
}
return new PooledEnumerable<T>(pool);
IEnumerable<T> pool = PooledEnumeration.EnumerateSectors(map, bounds).SelectMany(s => selector(s, bounds));
if (e == null)
return new PooledEnumerable<T>(pool);
e._Pool.AddRange(pool);
return e;
}
}
@ -992,7 +1031,6 @@ namespace Server
public IPooledEnumerable<T> GetMobilesInBounds<T>(Rectangle2D bounds) where T : Mobile => PooledEnumeration.GetMobiles<T>(this, bounds);
public IPooledEnumerable<T> GetMobilesInBounds<T>(Rectangle2D bounds) where T : Mobile => PooledEnumeration.GetMobiles<T>(this, bounds);
#endregion
#region CanFit
@ -1025,7 +1063,8 @@ namespace Server
if ((landFlags & TileFlag.Impassable) != 0 && avgZ > z && z + height > lowZ)
return false;
hasSurface |= (landFlags & TileFlag.Impassable) == 0 && z == avgZ && !lt.Ignored;
if ((landFlags & TileFlag.Impassable) == 0 && z == avgZ && !lt.Ignored)
hasSurface = true;
StaticTile[] staticTiles = Tiles.GetStaticTiles(x, y, true);
@ -1040,7 +1079,8 @@ namespace Server
if ((surface || impassable) && staticTiles[i].Z + id.CalcHeight > z && z + height > staticTiles[i].Z)
return false;
hasSurface |= surface && !impassable && z == staticTiles[i].Z + id.CalcHeight;
if (surface && !impassable && z == staticTiles[i].Z + id.CalcHeight)
hasSurface = true;
}
Sector sector = GetSector(x, y);
@ -1061,14 +1101,22 @@ namespace Server
z + height > item.Z)
return false;
hasSurface |= surface && !impassable && !item.Movable && z == item.Z + id.CalcHeight;
if (surface && !impassable && !item.Movable && z == item.Z + id.CalcHeight)
hasSurface = true;
}
}
return !(checkMobiles && mobs.Any(m => m.Location.m_X == x && m.Location.m_Y == y &&
(m.AccessLevel == AccessLevel.Player || !m.Hidden) &&
m.Z + 16 > z && z + height > m.Z)) &&
(!requireSurface || hasSurface);
if (checkMobiles)
for (int i = 0; i < mobs.Count; ++i)
{
Mobile m = mobs[i];
if (m.Location.m_X == x && m.Location.m_Y == y && (m.AccessLevel == AccessLevel.Player || !m.Hidden) &&
m.Z + 16 > z && z + height > m.Z)
return false;
}
return !requireSurface || hasSurface;
}
#endregion
@ -1079,8 +1127,13 @@ namespace Server
public bool CanSpawnMobile(Point2D p, int z) => CanSpawnMobile(p.m_X, p.m_Y, z);
public bool CanSpawnMobile(int x, int y, int z) =>
Region.Find(new Point3D(x, y, z), this).AllowSpawn() && CanFit(x, y, z, 16);
public bool CanSpawnMobile(int x, int y, int z)
{
if (!Region.Find(new Point3D(x, y, z), this).AllowSpawn())
return false;
return CanFit(x, y, z, 16);
}
#endregion