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.
}

View file

@ -1648,7 +1648,7 @@ namespace Server
public void InvalidateProperties()
{
if ( !Core.AOS )
if ( !ObjectPropertyList.Enabled )
return;
if ( m_Map != null && m_Map != Map.Internal && !World.Loading )

View file

@ -754,7 +754,7 @@ namespace Server
private int m_MeleeDamageAbsorb;
private int m_MagicDamageAbsorb;
private int m_Followers, m_FollowersMax;
private ArrayList m_Actions;
private List<object> _actions; // prefer List<object> over ArrayList for more specific profiling information
private Queue<MovementRecord> m_MoveRecords;
private int m_WarmodeChanges = 0;
private DateTime m_NextWarmodeChange;
@ -1464,17 +1464,14 @@ namespace Server
public bool BeginAction( object toLock )
{
if( m_Actions == null )
{
m_Actions = new ArrayList( 2 );
if ( _actions == null ) {
_actions = new ArrayList( 2 );
m_Actions.Add( toLock );
_actions.Add( toLock );
return true;
}
else if( !m_Actions.Contains( toLock ) )
{
m_Actions.Add( toLock );
} else if ( !_actions.Contains( toLock ) ) {
_actions.Add( toLock );
return true;
}
@ -1484,17 +1481,17 @@ namespace Server
public bool CanBeginAction( object toLock )
{
return (m_Actions == null || !m_Actions.Contains( toLock ));
return ( _actions == null || !_actions.Contains( toLock ) );
}
public void EndAction( object toLock )
{
if( m_Actions != null )
{
m_Actions.Remove( toLock );
if ( _actions != null ) {
_actions.Remove( toLock );
if( m_Actions.Count == 0 )
m_Actions = null;
if ( _actions.Count == 0 ) {
_actions = null;
}
}
}
@ -8643,7 +8640,7 @@ namespace Server
public void InvalidateProperties()
{
if( !Core.AOS )
if( !ObjectPropertyList.Enabled )
return;
if( m_Map != null && m_Map != Map.Internal && !World.Loading )
@ -9636,7 +9633,7 @@ namespace Server
bool sendUpdate = false, sendRemove = false;
bool sendPublicStats = false, sendPrivateStats = false;
bool sendMoving = false, sendNonlocalMoving = false;
bool sendOPLUpdate = Core.AOS && (delta & MobileDelta.Properties) != 0;
bool sendOPLUpdate = ObjectPropertyList.Enabled && (delta & MobileDelta.Properties) != 0;
bool sendHair = false, sendFacialHair = false, removeHair = false, removeFacialHair = false;