From f2abcd8dfc59bfa500f9fc1f7bad821b32de9863 Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 22 Oct 2009 12:37:29 +0000 Subject: [PATCH] Simple Generics --- Scripts/Items/Containers/FurnitureContainer.cs | 10 ++++++---- Scripts/Items/Skill Items/Magical/Spellbook.cs | 18 ++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Scripts/Items/Containers/FurnitureContainer.cs b/Scripts/Items/Containers/FurnitureContainer.cs index 75cc2eaef..9e3d01169 100644 --- a/Scripts/Items/Containers/FurnitureContainer.cs +++ b/Scripts/Items/Containers/FurnitureContainer.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using Server; using Server.Multis; using Server.Network; @@ -352,11 +352,11 @@ namespace Server.Items public class DynamicFurniture { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public static bool Open( Container c, Mobile m ) { - if ( m_Table.Contains( c ) ) + if ( m_Table.ContainsKey( c ) ) { c.SendRemovePacket(); Close( c ); @@ -385,7 +385,9 @@ namespace Server.Items public static void Close( Container c ) { - Timer t = (Timer)m_Table[c]; + Timer t = null; + + m_Table.TryGetValue( c, out t ); if ( t != null ) { diff --git a/Scripts/Items/Skill Items/Magical/Spellbook.cs b/Scripts/Items/Skill Items/Magical/Spellbook.cs index f6db8fa00..89aff89ef 100644 --- a/Scripts/Items/Skill Items/Magical/Spellbook.cs +++ b/Scripts/Items/Skill Items/Magical/Spellbook.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using Server; using Server.Commands; using Server.Engines.Craft; @@ -123,7 +123,7 @@ namespace Server.Items } } - private static Hashtable m_Table = new Hashtable(); + private static Dictionary> m_Table = new Dictionary>(); public static SpellbookType GetTypeForSpell( int spellID ) { @@ -183,14 +183,16 @@ namespace Server.Items if ( from == null ) return null; - ArrayList list = (ArrayList)m_Table[from]; - if ( from.Deleted ) { m_Table.Remove( from ); return null; } + List list = null; + + m_Table.TryGetValue( from, out list ); + bool searchAgain = false; if ( list == null ) @@ -210,7 +212,7 @@ namespace Server.Items return book; } - public static Spellbook FindSpellbookInList( ArrayList list, Mobile from, int spellID, SpellbookType type ) + public static Spellbook FindSpellbookInList( List list, Mobile from, int spellID, SpellbookType type ) { Container pack = from.Backpack; @@ -219,7 +221,7 @@ namespace Server.Items if ( i >= list.Count ) continue; - Spellbook book = (Spellbook)list[i]; + Spellbook book = list[i]; if ( !book.Deleted && (book.Parent == from || (pack != null && book.Parent == pack)) && ValidateSpellbook( book, spellID, type ) ) return book; @@ -230,9 +232,9 @@ namespace Server.Items return null; } - public static ArrayList FindAllSpellbooks( Mobile from ) + public static List FindAllSpellbooks( Mobile from ) { - ArrayList list = new ArrayList(); + List list = new List(); Item item = from.FindItemOnLayer( Layer.OneHanded );