Modernization Fixes & Updates to Default Values (#3)

This commit is contained in:
Kamron Batman 2018-10-28 00:33:16 -07:00 • committed by GitHub
parent 445eddff68
commit dcf64091b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
768 changed files with 10507 additions and 14196 deletions

View file

@ -36,7 +36,7 @@ namespace Server.Regions
if (!Region.ReadString(xml, "name", ref group))
return null;
SpawnDefinition def = (SpawnDefinition)SpawnGroup.Table[group];
SpawnDefinition def = SpawnGroup.Table[@group];
if (def == null)
{
@ -121,12 +121,12 @@ namespace Server.Regions
public class SpawnMobile : SpawnType
{
private static Hashtable m_Table = new Hashtable();
private static Dictionary<Type, SpawnMobile> m_Table = new Dictionary<Type, SpawnMobile>();
protected bool m_Land;
protected bool m_Water;
private bool m_Land;
private bool m_Water;
protected SpawnMobile(Type type) : base(type)
public SpawnMobile(Type type) : base(type)
{
}
@ -152,13 +152,10 @@ namespace Server.Regions
public static SpawnMobile Get(Type type)
{
SpawnMobile sm = (SpawnMobile)m_Table[type];
SpawnMobile sm = m_Table[type];
if (sm == null)
{
sm = new SpawnMobile(type);
m_Table[type] = sm;
}
m_Table[type] = sm = new SpawnMobile(type);
return sm;
}
@ -177,9 +174,7 @@ namespace Server.Regions
{
Mobile mobile = CreateMobile();
BaseCreature creature = mobile as BaseCreature;
if (creature != null)
if (mobile is BaseCreature creature)
{
creature.Home = entry.HomeLocation;
creature.HomeMap = map;
@ -204,7 +199,7 @@ namespace Server.Regions
public class SpawnItem : SpawnType
{
private static Hashtable m_Table = new Hashtable();
private static Dictionary<Type, SpawnItem> m_Table = new Dictionary<Type, SpawnItem>();
protected int m_Height;
@ -226,13 +221,10 @@ namespace Server.Regions
public static SpawnItem Get(Type type)
{
SpawnItem si = (SpawnItem)m_Table[type];
SpawnItem si = m_Table[type];
if (si == null)
{
si = new SpawnItem(type);
m_Table[type] = si;
}
m_Table[type] = si = new SpawnItem(type);
return si;
}
@ -327,9 +319,7 @@ namespace Server.Regions
List<SpawnGroupElement> list = new List<SpawnGroupElement>();
foreach (XmlNode node in xmlDef.ChildNodes)
{
XmlElement el = node as XmlElement;
if (el != null)
if (node is XmlElement el)
{
SpawnDefinition def = GetSpawnDefinition(el);
if (def == null)
@ -364,7 +354,7 @@ namespace Server.Regions
m_TotalWeight += elements[i].Weight;
}
public static Hashtable Table{ get; } = new Hashtable();
public static Dictionary<string, SpawnGroup> Table{ get; } = new Dictionary<string, SpawnGroup>();
public string Name{ get; }
@ -372,7 +362,7 @@ namespace Server.Regions
public static void Register(SpawnGroup group)
{
if (Table.Contains(group.Name))
if (Table.ContainsKey(group.Name))
Console.WriteLine("Warning: Double SpawnGroup name '{0}'", group.Name);
else
Table[group.Name] = group;
@ -404,4 +394,4 @@ namespace Server.Regions
return false;
}
}
}
}

View file

@ -34,13 +34,13 @@ namespace Server.Regions
MaxSpawnTime = maxSpawnTime;
Running = false;
if (Table.Contains(id))
if (Table.ContainsKey(id))
Console.WriteLine("Warning: double SpawnEntry ID '{0}'", id);
else
Table[id] = this;
}
public static Hashtable Table{ get; } = new Hashtable();
public static Dictionary<int, SpawnEntry> Table{ get; } = new Dictionary<int, SpawnEntry>();
// When a creature's AI is deactivated (PlayerRangeSensitive optimization) does it return home?
@ -122,8 +122,8 @@ namespace Server.Regions
spawn.Spawner = this;
if (spawn is BaseCreature)
((BaseCreature)spawn).RemoveIfUntamed = RemoveIfUntamed;
if (spawn is BaseCreature creature)
creature.RemoveIfUntamed = RemoveIfUntamed;
}
private TimeSpan RandomTime()
@ -218,13 +218,7 @@ namespace Server.Regions
writer.Write(SpawnedObjects.Count);
for (int i = 0; i < SpawnedObjects.Count; i++)
{
ISpawnable spawn = SpawnedObjects[i];
int serial = spawn.Serial;
writer.Write(serial);
}
writer.Write(SpawnedObjects[i].Serial);
writer.Write(Running);
@ -245,10 +239,7 @@ namespace Server.Regions
for (int i = 0; i < count; i++)
{
int serial = reader.ReadInt();
ISpawnable spawnableEntity = World.FindEntity(serial) as ISpawnable;
if (spawnableEntity != null)
if (World.FindEntity(reader.ReadUInt()) is ISpawnable spawnableEntity)
Add(spawnableEntity);
}
@ -276,8 +267,7 @@ namespace Server.Regions
for (int i = 0; i < count; i++)
{
int serial = reader.ReadInt();
IEntity entity = World.FindEntity(serial);
IEntity entity = World.FindEntity(reader.ReadUInt());
if (entity != null)
{
@ -442,4 +432,4 @@ namespace Server.Regions
args.Mobile.SendMessage("Spawners of region '{0}' have stopped.", region);
}
}
}
}