From 28744d486ee5466a0d8d370399211944a83b78b4 Mon Sep 17 00:00:00 2001 From: Mark Sturgill Date: Wed, 23 Oct 2013 09:54:06 -0700 Subject: [PATCH] misc generic conversions --- Scripts/Engines/Virtues/VirtueGump.cs | 8 ++-- Scripts/Gumps/Properties/PropsGump.cs | 41 ++++++++++--------- Scripts/Gumps/Properties/SetBodyGump.cs | 8 ++-- Scripts/Gumps/Properties/SetCustomEnumGump.cs | 5 ++- Scripts/Gumps/Properties/SetGump.cs | 11 ++--- Scripts/Gumps/Properties/SetListOptionGump.cs | 7 ++-- Scripts/Gumps/Properties/SetObjectGump.cs | 11 ++--- Scripts/Gumps/Properties/SetObjectTarget.cs | 7 ++-- Scripts/Gumps/Properties/SetPoint2DGump.cs | 11 ++--- Scripts/Gumps/Properties/SetPoint3DGump.cs | 11 ++--- Scripts/Gumps/Properties/SetTimeSpanGump.cs | 7 ++-- Scripts/Mobiles/AI/BaseAI.cs | 4 +- Scripts/Skills/Stealing.cs | 5 ++- Server/Serialization.cs | 26 ++++++++---- 14 files changed, 91 insertions(+), 71 deletions(-) diff --git a/Scripts/Engines/Virtues/VirtueGump.cs b/Scripts/Engines/Virtues/VirtueGump.cs index 51507dfc2..be34dabdf 100644 --- a/Scripts/Engines/Virtues/VirtueGump.cs +++ b/Scripts/Engines/Virtues/VirtueGump.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using Server; using Server.Gumps; using Server.Mobiles; @@ -11,7 +11,7 @@ namespace Server public class VirtueGump : Gump { - private static Hashtable m_Callbacks = new Hashtable(); + private static Dictionary m_Callbacks = new Dictionary(); public static void Initialize() { @@ -38,7 +38,9 @@ namespace Server return; } - OnVirtueUsed callback = (OnVirtueUsed)m_Callbacks[e.GumpID]; + OnVirtueUsed callback = null; + + m_Callbacks.TryGetValue(e.GumpID, out callback); if ( callback != null ) callback( e.Beholder ); diff --git a/Scripts/Gumps/Properties/PropsGump.cs b/Scripts/Gumps/Properties/PropsGump.cs index fe084586c..982537a8a 100644 --- a/Scripts/Gumps/Properties/PropsGump.cs +++ b/Scripts/Gumps/Properties/PropsGump.cs @@ -1,6 +1,7 @@ using System; -using System.Reflection; using System.Collections; +using System.Collections.Generic; +using System.Reflection; using Server; using Server.Commands.Generic; using Server.Network; @@ -11,6 +12,18 @@ using CPA = Server.CommandPropertyAttribute; namespace Server.Gumps { + public class StackEntry + { + public object m_Object; + public PropertyInfo m_Property; + + public StackEntry(object obj, PropertyInfo prop) + { + m_Object = obj; + m_Property = prop; + } + } + public class PropertiesGump : Gump { private ArrayList m_List; @@ -18,7 +31,7 @@ namespace Server.Gumps private Mobile m_Mobile; private object m_Object; private Type m_Type; - private Stack m_Stack; + private Stack m_Stack; public static readonly bool OldStyle = PropsConfig.OldStyle; @@ -86,7 +99,7 @@ namespace Server.Gumps Initialize( 0 ); } - public PropertiesGump( Mobile mobile, object o, Stack stack, StackEntry parent ) : base( GumpOffsetX, GumpOffsetY ) + public PropertiesGump( Mobile mobile, object o, Stack stack, StackEntry parent ) : base( GumpOffsetX, GumpOffsetY ) { m_Mobile = mobile; m_Object = o; @@ -97,7 +110,7 @@ namespace Server.Gumps if ( parent != null ) { if ( m_Stack == null ) - m_Stack = new Stack(); + m_Stack = new Stack(); m_Stack.Push( parent ); } @@ -105,7 +118,7 @@ namespace Server.Gumps Initialize( 0 ); } - public PropertiesGump( Mobile mobile, object o, Stack stack, ArrayList list, int page ) : base( GumpOffsetX, GumpOffsetY ) + public PropertiesGump( Mobile mobile, object o, Stack stack, ArrayList list, int page ) : base( GumpOffsetX, GumpOffsetY ) { m_Mobile = mobile; m_Object = o; @@ -231,18 +244,6 @@ namespace Server.Gumps public static string[] m_PoisonNames = new string[]{ "None", "Lesser", "Regular", "Greater", "Deadly", "Lethal" }; public static object[] m_PoisonValues = new object[]{ null, Poison.Lesser, Poison.Regular, Poison.Greater, Poison.Deadly, Poison.Lethal }; - public class StackEntry - { - public object m_Object; - public PropertyInfo m_Property; - - public StackEntry( object obj, PropertyInfo prop ) - { - m_Object = obj; - m_Property = prop; - } - } - public override void OnResponse( NetState state, RelayInfo info ) { Mobile from = state.Mobile; @@ -259,7 +260,7 @@ namespace Server.Gumps { if ( m_Stack != null && m_Stack.Count > 0 ) { - StackEntry entry = (StackEntry)m_Stack.Pop(); + StackEntry entry = m_Stack.Pop(); from.SendGump( new PropertiesGump( from, entry.m_Object, m_Stack, null ) ); } @@ -356,7 +357,7 @@ namespace Server.Gumps return type.IsDefined( typeofCustomEnum, false ); } - public static void OnValueChanged( object obj, PropertyInfo prop, Stack stack ) + public static void OnValueChanged( object obj, PropertyInfo prop, Stack stack ) { if ( stack == null || stack.Count == 0 ) return; @@ -364,7 +365,7 @@ namespace Server.Gumps if ( !prop.PropertyType.IsValueType ) return; - StackEntry peek = (StackEntry)stack.Peek(); + StackEntry peek = stack.Peek(); if ( peek.m_Property.CanWrite ) peek.m_Property.SetValue( peek.m_Object, obj, null ); diff --git a/Scripts/Gumps/Properties/SetBodyGump.cs b/Scripts/Gumps/Properties/SetBodyGump.cs index a172b38db..661211716 100644 --- a/Scripts/Gumps/Properties/SetBodyGump.cs +++ b/Scripts/Gumps/Properties/SetBodyGump.cs @@ -1,7 +1,7 @@ using System; -using System.Reflection; using System.Collections; using System.Collections.Generic; +using System.Reflection; using Server; using Server.Network; using Server.HuePickers; @@ -14,7 +14,7 @@ namespace Server.Gumps private PropertyInfo m_Property; private Mobile m_Mobile; private object m_Object; - private Stack m_Stack; + private Stack m_Stack; private int m_Page; private ArrayList m_List; private int m_OurPage; @@ -25,7 +25,7 @@ namespace Server.Gumps private const int SelectedColor32 = 0x8080FF; private const int TextColor32 = 0xFFFFFF; - public SetBodyGump( PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list ) + public SetBodyGump( PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list ) : this( prop, mobile, o, stack, page, list, 0, null, ModelBodyType.Invalid ) { } @@ -48,7 +48,7 @@ namespace Server.Gumps AddHtml( x + 35, y, 200, 20, Color( text, isSelection ? SelectedColor32 : LabelColor32 ), false, false ); } - public SetBodyGump( PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list, int ourPage, ArrayList ourList, ModelBodyType ourType ) + public SetBodyGump(PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list, int ourPage, ArrayList ourList, ModelBodyType ourType) : base( 20, 30 ) { m_Property = prop; diff --git a/Scripts/Gumps/Properties/SetCustomEnumGump.cs b/Scripts/Gumps/Properties/SetCustomEnumGump.cs index 34b923f31..39f5e2621 100644 --- a/Scripts/Gumps/Properties/SetCustomEnumGump.cs +++ b/Scripts/Gumps/Properties/SetCustomEnumGump.cs @@ -1,6 +1,7 @@ using System; -using System.Reflection; using System.Collections; +using System.Collections.Generic; +using System.Reflection; using Server; using Server.Network; using Server.Commands; @@ -11,7 +12,7 @@ namespace Server.Gumps { private string[] m_Names; - public SetCustomEnumGump( PropertyInfo prop, Mobile mobile, object o, Stack stack, int propspage, ArrayList list, string[] names ) : base( prop, mobile, o, stack, propspage, list, names, null ) + public SetCustomEnumGump( PropertyInfo prop, Mobile mobile, object o, Stack stack, int propspage, ArrayList list, string[] names ) : base( prop, mobile, o, stack, propspage, list, names, null ) { m_Names = names; } diff --git a/Scripts/Gumps/Properties/SetGump.cs b/Scripts/Gumps/Properties/SetGump.cs index 456c42a86..f57a34084 100644 --- a/Scripts/Gumps/Properties/SetGump.cs +++ b/Scripts/Gumps/Properties/SetGump.cs @@ -1,6 +1,7 @@ using System; -using System.Reflection; using System.Collections; +using System.Collections.Generic; +using System.Reflection; using Server; using Server.Network; using Server.HuePickers; @@ -13,7 +14,7 @@ namespace Server.Gumps private PropertyInfo m_Property; private Mobile m_Mobile; private object m_Object; - private Stack m_Stack; + private Stack m_Stack; private int m_Page; private ArrayList m_List; @@ -59,7 +60,7 @@ namespace Server.Gumps private static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; private static readonly int BackHeight = BorderSize + TotalHeight + BorderSize; - public SetGump( PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list ) : base( GumpOffsetX, GumpOffsetY ) + public SetGump( PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list ) : base( GumpOffsetX, GumpOffsetY ) { m_Property = prop; m_Mobile = mobile; @@ -160,11 +161,11 @@ namespace Server.Gumps private PropertyInfo m_Property; private Mobile m_Mobile; private object m_Object; - private Stack m_Stack; + private Stack m_Stack; private int m_Page; private ArrayList m_List; - public InternalPicker( PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list ) : base( ((IHued)o).HuedItemID ) + public InternalPicker( PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list ) : base( ((IHued)o).HuedItemID ) { m_Property = prop; m_Mobile = mobile; diff --git a/Scripts/Gumps/Properties/SetListOptionGump.cs b/Scripts/Gumps/Properties/SetListOptionGump.cs index a976906a0..0e106bcfb 100644 --- a/Scripts/Gumps/Properties/SetListOptionGump.cs +++ b/Scripts/Gumps/Properties/SetListOptionGump.cs @@ -1,6 +1,7 @@ using System; -using System.Reflection; using System.Collections; +using System.Collections.Generic; +using System.Reflection; using Server; using Server.Network; using Server.Commands; @@ -12,7 +13,7 @@ namespace Server.Gumps protected PropertyInfo m_Property; protected Mobile m_Mobile; protected object m_Object; - protected Stack m_Stack; + protected Stack m_Stack; protected int m_Page; protected ArrayList m_List; @@ -67,7 +68,7 @@ namespace Server.Gumps protected object[] m_Values; - public SetListOptionGump( PropertyInfo prop, Mobile mobile, object o, Stack stack, int propspage, ArrayList list, string[] names, object[] values ) : base( GumpOffsetX, GumpOffsetY ) + public SetListOptionGump( PropertyInfo prop, Mobile mobile, object o, Stack stack, int propspage, ArrayList list, string[] names, object[] values ) : base( GumpOffsetX, GumpOffsetY ) { m_Property = prop; m_Mobile = mobile; diff --git a/Scripts/Gumps/Properties/SetObjectGump.cs b/Scripts/Gumps/Properties/SetObjectGump.cs index 0b33ebd72..8bdd80edd 100644 --- a/Scripts/Gumps/Properties/SetObjectGump.cs +++ b/Scripts/Gumps/Properties/SetObjectGump.cs @@ -1,6 +1,7 @@ using System; -using System.Reflection; using System.Collections; +using System.Collections.Generic; +using System.Reflection; using Server; using Server.Commands.Generic; using Server.Network; @@ -14,7 +15,7 @@ namespace Server.Gumps private PropertyInfo m_Property; private Mobile m_Mobile; private object m_Object; - private Stack m_Stack; + private Stack m_Stack; private Type m_Type; private int m_Page; private ArrayList m_List; @@ -61,7 +62,7 @@ namespace Server.Gumps private static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; private static readonly int BackHeight = BorderSize + TotalHeight + BorderSize; - public SetObjectGump( PropertyInfo prop, Mobile mobile, object o, Stack stack, Type type, int page, ArrayList list ) : base( GumpOffsetX, GumpOffsetY ) + public SetObjectGump( PropertyInfo prop, Mobile mobile, object o, Stack stack, Type type, int page, ArrayList list ) : base( GumpOffsetX, GumpOffsetY ) { m_Property = prop; m_Mobile = mobile; @@ -142,12 +143,12 @@ namespace Server.Gumps private PropertyInfo m_Property; private Mobile m_Mobile; private object m_Object; - private Stack m_Stack; + private Stack m_Stack; private Type m_Type; private int m_Page; private ArrayList m_List; - public InternalPrompt( PropertyInfo prop, Mobile mobile, object o, Stack stack, Type type, int page, ArrayList list ) + public InternalPrompt( PropertyInfo prop, Mobile mobile, object o, Stack stack, Type type, int page, ArrayList list ) { m_Property = prop; m_Mobile = mobile; diff --git a/Scripts/Gumps/Properties/SetObjectTarget.cs b/Scripts/Gumps/Properties/SetObjectTarget.cs index 5dc8193bc..99ee4f62a 100644 --- a/Scripts/Gumps/Properties/SetObjectTarget.cs +++ b/Scripts/Gumps/Properties/SetObjectTarget.cs @@ -1,6 +1,7 @@ using System; -using System.Reflection; using System.Collections; +using System.Collections.Generic; +using System.Reflection; using Server; using Server.Items; using Server.Targeting; @@ -13,12 +14,12 @@ namespace Server.Gumps private PropertyInfo m_Property; private Mobile m_Mobile; private object m_Object; - private Stack m_Stack; + private Stack m_Stack; private Type m_Type; private int m_Page; private ArrayList m_List; - public SetObjectTarget( PropertyInfo prop, Mobile mobile, object o, Stack stack, Type type, int page, ArrayList list ) : base( -1, false, TargetFlags.None ) + public SetObjectTarget( PropertyInfo prop, Mobile mobile, object o, Stack stack, Type type, int page, ArrayList list ) : base( -1, false, TargetFlags.None ) { m_Property = prop; m_Mobile = mobile; diff --git a/Scripts/Gumps/Properties/SetPoint2DGump.cs b/Scripts/Gumps/Properties/SetPoint2DGump.cs index 4c20703cc..00a4de250 100644 --- a/Scripts/Gumps/Properties/SetPoint2DGump.cs +++ b/Scripts/Gumps/Properties/SetPoint2DGump.cs @@ -1,6 +1,7 @@ using System; -using System.Reflection; using System.Collections; +using System.Collections.Generic; +using System.Reflection; using Server; using Server.Targeting; using Server.Network; @@ -13,7 +14,7 @@ namespace Server.Gumps private PropertyInfo m_Property; private Mobile m_Mobile; private object m_Object; - private Stack m_Stack; + private Stack m_Stack; private int m_Page; private ArrayList m_List; @@ -60,7 +61,7 @@ namespace Server.Gumps private static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; private static readonly int BackHeight = BorderSize + TotalHeight + BorderSize; - public SetPoint2DGump( PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list ) : base( GumpOffsetX, GumpOffsetY ) + public SetPoint2DGump( PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list ) : base( GumpOffsetX, GumpOffsetY ) { m_Property = prop; m_Mobile = mobile; @@ -131,11 +132,11 @@ namespace Server.Gumps private PropertyInfo m_Property; private Mobile m_Mobile; private object m_Object; - private Stack m_Stack; + private Stack m_Stack; private int m_Page; private ArrayList m_List; - public InternalTarget( PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list ) : base( -1, true, TargetFlags.None ) + public InternalTarget( PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list ) : base( -1, true, TargetFlags.None ) { m_Property = prop; m_Mobile = mobile; diff --git a/Scripts/Gumps/Properties/SetPoint3DGump.cs b/Scripts/Gumps/Properties/SetPoint3DGump.cs index c38b01035..7890eed7c 100644 --- a/Scripts/Gumps/Properties/SetPoint3DGump.cs +++ b/Scripts/Gumps/Properties/SetPoint3DGump.cs @@ -1,6 +1,7 @@ using System; -using System.Reflection; using System.Collections; +using System.Collections.Generic; +using System.Reflection; using Server; using Server.Targeting; using Server.Network; @@ -13,7 +14,7 @@ namespace Server.Gumps private PropertyInfo m_Property; private Mobile m_Mobile; private object m_Object; - private Stack m_Stack; + private Stack m_Stack; private int m_Page; private ArrayList m_List; @@ -60,7 +61,7 @@ namespace Server.Gumps private static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; private static readonly int BackHeight = BorderSize + TotalHeight + BorderSize; - public SetPoint3DGump( PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list ) : base( GumpOffsetX, GumpOffsetY ) + public SetPoint3DGump( PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list ) : base( GumpOffsetX, GumpOffsetY ) { m_Property = prop; m_Mobile = mobile; @@ -136,11 +137,11 @@ namespace Server.Gumps private PropertyInfo m_Property; private Mobile m_Mobile; private object m_Object; - private Stack m_Stack; + private Stack m_Stack; private int m_Page; private ArrayList m_List; - public InternalTarget( PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list ) : base( -1, true, TargetFlags.None ) + public InternalTarget( PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list ) : base( -1, true, TargetFlags.None ) { m_Property = prop; m_Mobile = mobile; diff --git a/Scripts/Gumps/Properties/SetTimeSpanGump.cs b/Scripts/Gumps/Properties/SetTimeSpanGump.cs index fb6cdc0dd..bc74de02f 100644 --- a/Scripts/Gumps/Properties/SetTimeSpanGump.cs +++ b/Scripts/Gumps/Properties/SetTimeSpanGump.cs @@ -1,6 +1,7 @@ using System; -using System.Reflection; using System.Collections; +using System.Collections.Generic; +using System.Reflection; using Server; using Server.Network; using Server.Commands; @@ -12,7 +13,7 @@ namespace Server.Gumps private PropertyInfo m_Property; private Mobile m_Mobile; private object m_Object; - private Stack m_Stack; + private Stack m_Stack; private int m_Page; private ArrayList m_List; @@ -58,7 +59,7 @@ namespace Server.Gumps private static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; private static readonly int BackHeight = BorderSize + TotalHeight + BorderSize; - public SetTimeSpanGump( PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list ) : base( GumpOffsetX, GumpOffsetY ) + public SetTimeSpanGump( PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list ) : base( GumpOffsetX, GumpOffsetY ) { m_Property = prop; m_Mobile = mobile; diff --git a/Scripts/Mobiles/AI/BaseAI.cs b/Scripts/Mobiles/AI/BaseAI.cs index a917b1a82..fd67f7945 100644 --- a/Scripts/Mobiles/AI/BaseAI.cs +++ b/Scripts/Mobiles/AI/BaseAI.cs @@ -2028,7 +2028,7 @@ namespace Server.Mobiles return (res == MoveResult.Success || res == MoveResult.SuccessAutoTurn || (badStateOk && res == MoveResult.BadState)); } - private static Queue m_Obstacles = new Queue(); + private static Queue m_Obstacles = new Queue(); public virtual MoveResult DoMoveImpl(Direction d) { @@ -2117,7 +2117,7 @@ namespace Server.Mobiles while (m_Obstacles.Count > 0) { - Item item = (Item)m_Obstacles.Dequeue(); + Item item = m_Obstacles.Dequeue(); if (item is BaseDoor) { diff --git a/Scripts/Skills/Stealing.cs b/Scripts/Skills/Stealing.cs index 3cf4e2825..832a65fbe 100644 --- a/Scripts/Skills/Stealing.cs +++ b/Scripts/Skills/Stealing.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server; using Server.Mobiles; using Server.Targeting; @@ -424,7 +425,7 @@ namespace Server.SkillHandlers m_Expires = DateTime.UtcNow + StealTime; } - private static Queue m_Queue = new Queue(); + private static Queue m_Queue = new Queue(); public static void Add( Item item, Mobile thief, Mobile victim ) { @@ -478,7 +479,7 @@ namespace Server.SkillHandlers { while ( m_Queue.Count > 0 ) { - StolenItem si = (StolenItem) m_Queue.Peek(); + StolenItem si = m_Queue.Peek(); if ( si.IsExpired ) m_Queue.Dequeue(); diff --git a/Server/Serialization.cs b/Server/Serialization.cs index ddba58568..b71805103 100644 --- a/Server/Serialization.cs +++ b/Server/Serialization.cs @@ -1410,7 +1410,7 @@ namespace Server private BinaryWriter m_Bin; private FileStream m_File; - private Queue m_WriteQueue; + private Queue m_WriteQueue; private Thread m_WorkerThread; public AsyncWriter( string filename, bool prefix ) @@ -1422,7 +1422,7 @@ namespace Server { PrefixStrings = prefix; m_Closed = false; - m_WriteQueue = Queue.Synchronized( new Queue() ); + m_WriteQueue = new Queue(); BufferSize = buffSize; m_File = new FileStream( filename, FileMode.Create, FileAccess.Write, FileShare.None ); @@ -1432,7 +1432,8 @@ namespace Server private void Enqueue( MemoryStream mem ) { - m_WriteQueue.Enqueue( mem ); + lock (m_WriteQueue) + m_WriteQueue.Enqueue( mem ); if( m_WorkerThread == null || !m_WorkerThread.IsAlive ) { @@ -1454,13 +1455,20 @@ namespace Server public void Worker() { AsyncWriter.m_ThreadCount++; - while( m_Owner.m_WriteQueue.Count > 0 ) - { - MemoryStream mem = (MemoryStream)m_Owner.m_WriteQueue.Dequeue(); - if( mem != null && mem.Length > 0 ) - mem.WriteTo( m_Owner.m_File ); - } + int lastCount = 0; + + do { + MemoryStream mem = null; + + lock (m_Owner.m_WriteQueue) { + if ((lastCount = m_Owner.m_WriteQueue.Count) > 0) + mem = m_Owner.m_WriteQueue.Dequeue(); + } + + if (mem != null && mem.Length > 0) + mem.WriteTo(m_Owner.m_File); + } while (lastCount > 1); if( m_Owner.m_Closed ) m_Owner.m_File.Close();