Changes properties to use automatic property initializers
This commit is contained in:
parent
f0a48ad431
commit
06fa31a7bf
623 changed files with 13072 additions and 19304 deletions
154
Server/World.cs
154
Server/World.cs
|
|
@ -29,21 +29,15 @@ using Server.Guilds;
|
|||
|
||||
namespace Server {
|
||||
public static class World {
|
||||
|
||||
private static Dictionary<Serial, Mobile> m_Mobiles;
|
||||
private static Dictionary<Serial, Item> m_Items;
|
||||
|
||||
private static bool m_Loading;
|
||||
private static bool m_Loaded;
|
||||
|
||||
private static bool m_Saving;
|
||||
private static ManualResetEvent m_DiskWriteHandle = new ManualResetEvent(true);
|
||||
|
||||
private static Queue<IEntity> _addQueue, _deleteQueue;
|
||||
|
||||
public static bool Saving => m_Saving;
|
||||
public static bool Loaded => m_Loaded;
|
||||
public static bool Loading => m_Loading;
|
||||
public static bool Saving { get; private set; }
|
||||
|
||||
public static bool Loaded { get; private set; }
|
||||
|
||||
public static bool Loading { get; private set; }
|
||||
|
||||
public readonly static string MobileIndexPath = Path.Combine( "Saves/Mobiles/", "Mobiles.idx" );
|
||||
public readonly static string MobileTypesPath = Path.Combine( "Saves/Mobiles/", "Mobiles.tdb" );
|
||||
|
|
@ -69,13 +63,13 @@ namespace Server {
|
|||
m_DiskWriteHandle.WaitOne();
|
||||
}
|
||||
|
||||
public static Dictionary<Serial, Mobile> Mobiles => m_Mobiles;
|
||||
public static Dictionary<Serial, Mobile> Mobiles { get; private set; }
|
||||
|
||||
public static Dictionary<Serial, Item> Items => m_Items;
|
||||
public static Dictionary<Serial, Item> Items { get; private set; }
|
||||
|
||||
public static bool OnDelete( IEntity entity ) {
|
||||
if ( m_Saving || m_Loading ) {
|
||||
if ( m_Saving ) {
|
||||
if ( Saving || Loading ) {
|
||||
if ( Saving ) {
|
||||
AppendSafetyLog( "delete", entity );
|
||||
}
|
||||
|
||||
|
|
@ -121,86 +115,68 @@ namespace Server {
|
|||
}
|
||||
|
||||
private sealed class GuildEntry : IEntityEntry {
|
||||
private BaseGuild m_Guild;
|
||||
private long m_Position;
|
||||
private int m_Length;
|
||||
public BaseGuild Guild { get; }
|
||||
|
||||
public BaseGuild Guild => m_Guild;
|
||||
|
||||
public Serial Serial => m_Guild?.Id ?? 0;
|
||||
public Serial Serial => Guild?.Id ?? 0;
|
||||
|
||||
public int TypeID => 0;
|
||||
|
||||
public long Position => m_Position;
|
||||
public long Position { get; }
|
||||
|
||||
public int Length => m_Length;
|
||||
public int Length { get; }
|
||||
|
||||
public GuildEntry( BaseGuild g, long pos, int length ) {
|
||||
m_Guild = g;
|
||||
m_Position = pos;
|
||||
m_Length = length;
|
||||
Guild = g;
|
||||
Position = pos;
|
||||
Length = length;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class ItemEntry : IEntityEntry {
|
||||
private Item m_Item;
|
||||
private int m_TypeID;
|
||||
private string m_TypeName;
|
||||
private long m_Position;
|
||||
private int m_Length;
|
||||
public Item Item { get; }
|
||||
|
||||
public Item Item => m_Item;
|
||||
public Serial Serial => Item?.Serial ?? Serial.MinusOne;
|
||||
|
||||
public Serial Serial => m_Item?.Serial ?? Serial.MinusOne;
|
||||
public int TypeID { get; }
|
||||
|
||||
public int TypeID => m_TypeID;
|
||||
public string TypeName { get; }
|
||||
|
||||
public string TypeName => m_TypeName;
|
||||
public long Position { get; }
|
||||
|
||||
public long Position => m_Position;
|
||||
|
||||
public int Length => m_Length;
|
||||
public int Length { get; }
|
||||
|
||||
public ItemEntry( Item item, int typeID, string typeName, long pos, int length ) {
|
||||
m_Item = item;
|
||||
m_TypeID = typeID;
|
||||
m_TypeName = typeName;
|
||||
m_Position = pos;
|
||||
m_Length = length;
|
||||
Item = item;
|
||||
TypeID = typeID;
|
||||
TypeName = typeName;
|
||||
Position = pos;
|
||||
Length = length;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class MobileEntry : IEntityEntry {
|
||||
private Mobile m_Mobile;
|
||||
private int m_TypeID;
|
||||
private string m_TypeName;
|
||||
private long m_Position;
|
||||
private int m_Length;
|
||||
public Mobile Mobile { get; }
|
||||
|
||||
public Mobile Mobile => m_Mobile;
|
||||
public Serial Serial => Mobile?.Serial ?? Serial.MinusOne;
|
||||
|
||||
public Serial Serial => m_Mobile?.Serial ?? Serial.MinusOne;
|
||||
public int TypeID { get; }
|
||||
|
||||
public int TypeID => m_TypeID;
|
||||
public string TypeName { get; }
|
||||
|
||||
public string TypeName => m_TypeName;
|
||||
public long Position { get; }
|
||||
|
||||
public long Position => m_Position;
|
||||
|
||||
public int Length => m_Length;
|
||||
public int Length { get; }
|
||||
|
||||
public MobileEntry( Mobile mobile, int typeID, string typeName, long pos, int length ) {
|
||||
m_Mobile = mobile;
|
||||
m_TypeID = typeID;
|
||||
m_TypeName = typeName;
|
||||
m_Position = pos;
|
||||
m_Length = length;
|
||||
Mobile = mobile;
|
||||
TypeID = typeID;
|
||||
TypeName = typeName;
|
||||
Position = pos;
|
||||
Length = length;
|
||||
}
|
||||
}
|
||||
|
||||
private static string m_LoadingType;
|
||||
|
||||
public static string LoadingType => m_LoadingType;
|
||||
public static string LoadingType { get; private set; }
|
||||
|
||||
private static readonly Type[] m_SerialTypeArray = new Type[1] { typeof(Serial) };
|
||||
|
||||
|
|
@ -257,17 +233,17 @@ namespace Server {
|
|||
}
|
||||
|
||||
public static void Load() {
|
||||
if ( m_Loaded )
|
||||
if ( Loaded )
|
||||
return;
|
||||
|
||||
m_Loaded = true;
|
||||
m_LoadingType = null;
|
||||
Loaded = true;
|
||||
LoadingType = null;
|
||||
|
||||
Console.Write( "World: Loading..." );
|
||||
|
||||
Stopwatch watch = Stopwatch.StartNew();
|
||||
|
||||
m_Loading = true;
|
||||
Loading = true;
|
||||
|
||||
_addQueue = new Queue<IEntity>();
|
||||
_deleteQueue = new Queue<IEntity>();
|
||||
|
|
@ -291,7 +267,7 @@ namespace Server {
|
|||
|
||||
mobileCount = idxReader.ReadInt32();
|
||||
|
||||
m_Mobiles = new Dictionary<Serial, Mobile>( mobileCount );
|
||||
Mobiles = new Dictionary<Serial, Mobile>( mobileCount );
|
||||
|
||||
for ( int i = 0; i < mobileCount; ++i ) {
|
||||
int typeID = idxReader.ReadInt32();
|
||||
|
|
@ -326,7 +302,7 @@ namespace Server {
|
|||
idxReader.Close();
|
||||
}
|
||||
} else {
|
||||
m_Mobiles = new Dictionary<Serial, Mobile>();
|
||||
Mobiles = new Dictionary<Serial, Mobile>();
|
||||
}
|
||||
|
||||
if ( File.Exists( ItemIndexPath ) && File.Exists( ItemTypesPath ) ) {
|
||||
|
|
@ -340,7 +316,7 @@ namespace Server {
|
|||
|
||||
itemCount = idxReader.ReadInt32();
|
||||
|
||||
m_Items = new Dictionary<Serial, Item>( itemCount );
|
||||
Items = new Dictionary<Serial, Item>( itemCount );
|
||||
|
||||
for ( int i = 0; i < itemCount; ++i ) {
|
||||
int typeID = idxReader.ReadInt32();
|
||||
|
|
@ -375,7 +351,7 @@ namespace Server {
|
|||
idxReader.Close();
|
||||
}
|
||||
} else {
|
||||
m_Items = new Dictionary<Serial, Item>();
|
||||
Items = new Dictionary<Serial, Item>();
|
||||
}
|
||||
|
||||
if ( File.Exists( GuildIndexPath ) ) {
|
||||
|
|
@ -420,7 +396,7 @@ namespace Server {
|
|||
reader.Seek( entry.Position, SeekOrigin.Begin );
|
||||
|
||||
try {
|
||||
m_LoadingType = entry.TypeName;
|
||||
LoadingType = entry.TypeName;
|
||||
m.Deserialize( reader );
|
||||
|
||||
if ( reader.Position != ( entry.Position + entry.Length ) )
|
||||
|
|
@ -455,7 +431,7 @@ namespace Server {
|
|||
reader.Seek( entry.Position, SeekOrigin.Begin );
|
||||
|
||||
try {
|
||||
m_LoadingType = entry.TypeName;
|
||||
LoadingType = entry.TypeName;
|
||||
item.Deserialize( reader );
|
||||
|
||||
if ( reader.Position != ( entry.Position + entry.Length ) )
|
||||
|
|
@ -478,7 +454,7 @@ namespace Server {
|
|||
}
|
||||
}
|
||||
|
||||
m_LoadingType = null;
|
||||
LoadingType = null;
|
||||
|
||||
if ( !failedMobiles && !failedItems && File.Exists( GuildDataPath ) ) {
|
||||
using ( FileStream bin = new FileStream( GuildDataPath, FileMode.Open, FileAccess.Read, FileShare.Read ) ) {
|
||||
|
|
@ -563,18 +539,18 @@ namespace Server {
|
|||
|
||||
EventSink.InvokeWorldLoad();
|
||||
|
||||
m_Loading = false;
|
||||
Loading = false;
|
||||
|
||||
ProcessSafetyQueues();
|
||||
|
||||
foreach ( Item item in m_Items.Values ) {
|
||||
foreach ( Item item in Items.Values ) {
|
||||
if ( item.Parent == null )
|
||||
item.UpdateTotals();
|
||||
|
||||
item.ClearProperties();
|
||||
}
|
||||
|
||||
foreach ( Mobile m in m_Mobiles.Values ) {
|
||||
foreach ( Mobile m in Mobiles.Values ) {
|
||||
m.UpdateRegion(); // Is this really needed?
|
||||
m.UpdateTotals();
|
||||
|
||||
|
|
@ -583,7 +559,7 @@ namespace Server {
|
|||
|
||||
watch.Stop();
|
||||
|
||||
Console.WriteLine( "done ({1} items, {2} mobiles) ({0:F2} seconds)", watch.Elapsed.TotalSeconds, m_Items.Count, m_Mobiles.Count );
|
||||
Console.WriteLine( "done ({1} items, {2} mobiles) ({0:F2} seconds)", watch.Elapsed.TotalSeconds, Items.Count, Mobiles.Count );
|
||||
}
|
||||
|
||||
private static void ProcessSafetyQueues() {
|
||||
|
|
@ -661,7 +637,7 @@ namespace Server {
|
|||
}
|
||||
|
||||
public static void Save( bool message, bool permitBackgroundWrite ) {
|
||||
if ( m_Saving )
|
||||
if ( Saving )
|
||||
return;
|
||||
|
||||
++m_Saves;
|
||||
|
|
@ -671,7 +647,7 @@ namespace Server {
|
|||
|
||||
WaitForWriteCompletion();//Blocks Save until current disk flush is done.
|
||||
|
||||
m_Saving = true;
|
||||
Saving = true;
|
||||
|
||||
m_DiskWriteHandle.Reset();
|
||||
|
||||
|
|
@ -705,7 +681,7 @@ namespace Server {
|
|||
|
||||
watch.Stop();
|
||||
|
||||
m_Saving = false;
|
||||
Saving = false;
|
||||
|
||||
if (!permitBackgroundWrite)
|
||||
NotifyDiskWriteComplete(); //Sets the DiskWriteHandle. If we allow background writes, we leave this upto the individual save strategies.
|
||||
|
|
@ -737,43 +713,43 @@ namespace Server {
|
|||
public static Mobile FindMobile( Serial serial ) {
|
||||
Mobile mob;
|
||||
|
||||
m_Mobiles.TryGetValue( serial, out mob );
|
||||
Mobiles.TryGetValue( serial, out mob );
|
||||
|
||||
return mob;
|
||||
}
|
||||
|
||||
public static void AddMobile( Mobile m ) {
|
||||
if ( m_Saving ) {
|
||||
if ( Saving ) {
|
||||
AppendSafetyLog( "add", m );
|
||||
_addQueue.Enqueue( m );
|
||||
} else {
|
||||
m_Mobiles[m.Serial] = m;
|
||||
Mobiles[m.Serial] = m;
|
||||
}
|
||||
}
|
||||
|
||||
public static Item FindItem( Serial serial ) {
|
||||
Item item;
|
||||
|
||||
m_Items.TryGetValue( serial, out item );
|
||||
Items.TryGetValue( serial, out item );
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
public static void AddItem( Item item ) {
|
||||
if ( m_Saving ) {
|
||||
if ( Saving ) {
|
||||
AppendSafetyLog( "add", item );
|
||||
_addQueue.Enqueue( item );
|
||||
} else {
|
||||
m_Items[item.Serial] = item;
|
||||
Items[item.Serial] = item;
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveMobile( Mobile m ) {
|
||||
m_Mobiles.Remove( m.Serial );
|
||||
Mobiles.Remove( m.Serial );
|
||||
}
|
||||
|
||||
public static void RemoveItem( Item item ) {
|
||||
m_Items.Remove( item.Serial );
|
||||
Items.Remove( item.Serial );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue