CraftItem.ItemIDOf now uses a dictionary to avoid int boxing

fixed vendor issue causing PropertyList to be accessed on pre-aos shards
fixed a few places which incorrectly used Core.AOS instead of ObjectPropertyList.Enabled
changed actions list from ArrayList to List<object> for diagnostic purposes
This commit is contained in:
krrios 2007-04-24 03:48:58 +00:00
parent 235b1ee73e
commit 537e026912
4 changed files with 76 additions and 70 deletions

View file

@ -1,5 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Server;
using Server.Items;
using Server.Factions;
@ -75,56 +76,48 @@ namespace Server.Engines.Craft
m_Recipe = new Recipe( id, system, this );
}
private static Hashtable m_ItemIDs = new Hashtable();
private static Dictionary<Type, int> _itemIds = new Dictionary<Type, int>();
public static int ItemIDOf( Type type )
{
object obj = m_ItemIDs[type];
public static int ItemIDOf( Type type ) {
int itemId;
if ( obj != null )
return (int)obj;
int itemID = 0;
if ( type == typeof( FactionExplosionTrap ) )
itemID = 14034;
else if ( type == typeof( FactionGasTrap ) )
itemID = 4523;
else if ( type == typeof( FactionSawTrap ) )
itemID = 4359;
else if ( type == typeof( FactionSpikeTrap ) )
itemID = 4517;
if ( itemID == 0 )
{
object[] attrs = type.GetCustomAttributes( typeof( CraftItemIDAttribute ), false );
if ( attrs.Length > 0 )
{
CraftItemIDAttribute craftItemID = (CraftItemIDAttribute) attrs[0];
itemID = craftItemID.ItemID;
if ( !_itemIds.TryGetValue( type, out itemId ) ) {
if ( type == typeof( FactionExplosionTrap ) ) {
itemId = 14034;
} else if ( type == typeof( FactionGasTrap ) ) {
itemId = 4523;
} else if ( type == typeof( FactionSawTrap ) ) {
itemId = 4359;
} else if ( type == typeof( FactionSpikeTrap ) ) {
itemId = 4517;
}
if ( itemId == 0 ) {
object[] attrs = type.GetCustomAttributes( typeof( CraftItemIDAttribute ), false );
if ( attrs.Length > 0 ) {
CraftItemIDAttribute craftItemID = ( CraftItemIDAttribute ) attrs[0];
itemId = craftItemID.ItemID;
}
}
if ( itemId == 0 ) {
Item item = null;
try { item = Activator.CreateInstance( type ) as Item; } catch { }
if ( item != null ) {
itemId = item.ItemID;
item.Delete();
}
}
_itemIds[type] = itemId;
}
if ( itemID == 0 )
{
Item item = null;
try{ item = Activator.CreateInstance( type ) as Item; }
catch{}
if ( item != null )
{
itemID = item.ItemID;
item.Delete();
}
}
m_ItemIDs[type] = itemID;
return itemID;
return itemId;
}
public CraftItem( Type type, TextDefinition groupName, TextDefinition name )

View file

@ -549,7 +549,7 @@ namespace Server.Mobiles
list = new ArrayList( buyInfo.Length );
Container cont = this.BuyPack;
ArrayList opls = new ArrayList();
List<ObjectPropertyList> opls = null;
for (int idx=0;idx<buyInfo.Length;idx++)
{
@ -565,10 +565,17 @@ namespace Server.Mobiles
list.Add( new BuyItemState( buyItem.Name, cont.Serial, disp == null ? (Serial) 0x7FC0FFEE : disp.Serial, buyItem.Price, buyItem.Amount, buyItem.ItemID, buyItem.Hue ) );
count++;
if ( disp is Item )
opls.Add( (disp as Item).PropertyList );
else if ( disp is Mobile )
opls.Add( (disp as Mobile).PropertyList );
if ( ObjectPropertyList.Enabled ) {
if ( opls == null ) {
opls = new List<ObjectPropertyList>();
}
if ( disp is Item ) {
opls.Add( ( ( Item ) disp ).PropertyList );
} else if ( disp is Mobile ) {
opls.Add( ( ( Mobile ) disp ).PropertyList );
}
}
}
List<Item> playerItems = cont.Items;
@ -606,7 +613,13 @@ namespace Server.Mobiles
list.Add( new BuyItemState( name, cont.Serial, item.Serial, price, item.Amount, item.ItemID, item.Hue ) );
count++;
opls.Add( item.PropertyList );
if ( ObjectPropertyList.Enabled ) {
if ( opls == null ) {
opls = new List<ObjectPropertyList>();
}
opls.Add( item.PropertyList );
}
}
}
@ -625,8 +638,11 @@ namespace Server.Mobiles
from.Send( new DisplayBuyList( this ) );
from.Send( new MobileStatusExtended( from ) );//make sure their gold amount is sent
for ( int i = 0; i < opls.Count; ++i )
from.Send( opls[i] as Packet );
if ( ObjectPropertyList.Enabled && opls != null ) {
for ( int i = 0; i < opls.Count; ++i ) {
from.Send( opls[i] );
}
}
SayTo( from, 500186 ); // Greetings. Have a look around.
}