generic conversions

This commit is contained in:
Mark Sturgill 2013-11-02 21:40:42 -07:00
parent fa1df8eae5
commit 0eeb0c0c31
6 changed files with 29 additions and 25 deletions

View file

@ -1,5 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace Server.Items
{
@ -480,7 +480,7 @@ namespace Server.Items
return ( resource == CraftResource.None || resource == CraftResource.Iron || resource == CraftResource.RegularLeather || resource == CraftResource.RegularWood );
}
private static Hashtable m_TypeTable;
private static Dictionary<Type, CraftResource> m_TypeTable;
/// <summary>
/// Registers that '<paramref name="resourceType"/>' uses '<paramref name="resource"/>' so that it can later be queried by <see cref="CraftResources.GetFromType"/>
@ -488,7 +488,7 @@ namespace Server.Items
public static void RegisterType( Type resourceType, CraftResource resource )
{
if ( m_TypeTable == null )
m_TypeTable = new Hashtable();
m_TypeTable = new Dictionary<Type, CraftResource>();
m_TypeTable[resourceType] = resource;
}
@ -501,12 +501,12 @@ namespace Server.Items
if ( m_TypeTable == null )
return CraftResource.None;
object obj = m_TypeTable[resourceType];
if ( !(obj is CraftResource) )
CraftResource res;
if (!m_TypeTable.TryGetValue(resourceType, out res))
return CraftResource.None;
return (CraftResource)obj;
return res;
}
/// <summary>

View file

@ -1,5 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Server;
using Server.Mobiles;
using Server.Factions;
@ -48,7 +48,9 @@ namespace Server
if ( m_Table == null )
LoadTable();
SpeedInfo sp = (SpeedInfo)m_Table[obj.GetType()];
SpeedInfo sp = null;
m_Table.TryGetValue(obj.GetType(), out sp);
return ( sp != null );
}
@ -61,7 +63,9 @@ namespace Server
if ( m_Table == null )
LoadTable();
SpeedInfo sp = (SpeedInfo)m_Table[obj.GetType()];
SpeedInfo sp = null;
m_Table.TryGetValue(obj.GetType(), out sp);
if ( sp == null )
return false;
@ -74,7 +78,7 @@ namespace Server
private static void LoadTable()
{
m_Table = new Hashtable();
m_Table = new Dictionary<Type, SpeedInfo>();
for ( int i = 0; i < m_Speeds.Length; ++i )
{
@ -86,7 +90,7 @@ namespace Server
}
}
private static Hashtable m_Table;
private static Dictionary<Type, SpeedInfo> m_Table;
private static SpeedInfo[] m_Speeds = new SpeedInfo[]
{

View file

@ -710,7 +710,7 @@ namespace Server.Mobiles
{
IShopSellInfo[] info = GetSellInfo();
Hashtable table = new Hashtable();
Dictionary<Item, SellItemState> table = new Dictionary<Item, SellItemState>();
foreach ( IShopSellInfo ssi in info )
{
@ -730,7 +730,7 @@ namespace Server.Mobiles
{
SendPacksTo( from );
from.Send( new VendorSellList( this, table ) );
from.Send( new VendorSellList( this, table.Values ) );
}
else
{

View file

@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using Server;
@ -276,7 +275,7 @@ namespace Server.Mobiles
public class PlayerVendor : Mobile
{
private Hashtable m_SellItems;
private Dictionary<Item, VendorItem> m_SellItems;
private Mobile m_Owner;
private BaseHouse m_House;
@ -309,7 +308,7 @@ namespace Server.Mobiles
ShopName = "Shop Not Yet Named";
m_SellItems = new Hashtable();
m_SellItems = new Dictionary<Item, VendorItem>();
CantWalk = true;
@ -384,9 +383,10 @@ namespace Server.Mobiles
m_BankAccount = reader.ReadInt();
m_HoldGold = reader.ReadInt();
m_SellItems = new Hashtable();
int count = reader.ReadInt();
m_SellItems = new Dictionary<Item, VendorItem>(count);
for ( int i = 0; i < count; i++ )
{
Item item = reader.ReadItem();
@ -779,7 +779,9 @@ namespace Server.Mobiles
public VendorItem GetVendorItem( Item item )
{
return (VendorItem) m_SellItems[item];
VendorItem v = null;
m_SellItems.TryGetValue(item, out v);
return v;
}
private VendorItem SetVendorItem( Item item, int price, string description )