refactoring, generics, a bug fix in mana drain, a few todos done
This commit is contained in:
parent
f95101c201
commit
50b59db594
9 changed files with 89 additions and 125 deletions
|
|
@ -226,7 +226,7 @@ namespace Server.Mobiles
|
|||
GenericBuyInfo buy = m_ArmorBuyInfo[i] as GenericBuyInfo;
|
||||
|
||||
if ( buy != null )
|
||||
buy.DeleteDisplayObject();
|
||||
buy.DeleteDisplayEntity();
|
||||
}
|
||||
|
||||
SBInfos.Clear();
|
||||
|
|
@ -560,7 +560,7 @@ namespace Server.Mobiles
|
|||
|
||||
// NOTE: Only GBI supported; if you use another implementation of IBuyItemInfo, this will crash
|
||||
GenericBuyInfo gbi = (GenericBuyInfo) buyItem;
|
||||
IEntity disp = gbi.GetDisplayObject() as IEntity;
|
||||
IEntity disp = gbi.GetDisplayEntity();
|
||||
|
||||
list.Add( new BuyItemState( buyItem.Name, cont.Serial, disp == null ? (Serial) 0x7FC0FFEE : disp.Serial, buyItem.Price, buyItem.Amount, buyItem.ItemID, buyItem.Hue ) );
|
||||
count++;
|
||||
|
|
@ -765,11 +765,10 @@ namespace Server.Mobiles
|
|||
{
|
||||
IBuyItemInfo[] buyInfo = this.GetBuyInfo();
|
||||
|
||||
for ( int i = 0; i < buyInfo.Length; ++i )
|
||||
{
|
||||
GenericBuyInfo gbi = buyInfo[i] as GenericBuyInfo;
|
||||
for ( int i = 0; i < buyInfo.Length; ++i ) {
|
||||
GenericBuyInfo gbi = (GenericBuyInfo)buyInfo[i];
|
||||
|
||||
if ( gbi.GetDisplayObject() == obj )
|
||||
if ( gbi.GetDisplayEntity() == obj )
|
||||
return gbi;
|
||||
}
|
||||
|
||||
|
|
@ -812,7 +811,7 @@ namespace Server.Mobiles
|
|||
|
||||
bii.Amount -= amount;
|
||||
|
||||
object o = bii.GetObject();
|
||||
IEntity o = bii.GetEntity();
|
||||
|
||||
if ( o is Item )
|
||||
{
|
||||
|
|
@ -834,7 +833,7 @@ namespace Server.Mobiles
|
|||
|
||||
for (int i=1;i<amount;i++)
|
||||
{
|
||||
item = bii.GetObject() as Item;
|
||||
item = bii.GetEntity() as Item;
|
||||
|
||||
if ( item != null )
|
||||
{
|
||||
|
|
@ -859,7 +858,7 @@ namespace Server.Mobiles
|
|||
|
||||
for ( int i = 1; i < amount; ++i )
|
||||
{
|
||||
m = bii.GetObject() as Mobile;
|
||||
m = bii.GetEntity() as Mobile;
|
||||
|
||||
if ( m != null )
|
||||
{
|
||||
|
|
@ -1451,7 +1450,7 @@ namespace Server
|
|||
public interface IBuyItemInfo
|
||||
{
|
||||
//get a new instance of an object (we just bought it)
|
||||
object GetObject();
|
||||
IEntity GetEntity();
|
||||
|
||||
int ControlSlots{ get; }
|
||||
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ namespace Server.Mobiles
|
|||
Name = (1042965 + (int)content).ToString();
|
||||
}
|
||||
|
||||
public override object GetObject()
|
||||
public override IEntity GetEntity()
|
||||
{
|
||||
return Activator.CreateInstance( Type, new object[]{ m_Content } );
|
||||
return (IEntity)Activator.CreateInstance( Type, new object[]{ m_Content } );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Server;
|
||||
using Server.Items;
|
||||
using Server.Network;
|
||||
|
|
@ -12,10 +12,8 @@ namespace Server.Mobiles
|
|||
{
|
||||
private static DisplayCache m_Cache;
|
||||
|
||||
public static DisplayCache Cache
|
||||
{
|
||||
get
|
||||
{
|
||||
public static DisplayCache Cache {
|
||||
get {
|
||||
if ( m_Cache == null || m_Cache.Deleted )
|
||||
m_Cache = new DisplayCache();
|
||||
|
||||
|
|
@ -23,29 +21,31 @@ namespace Server.Mobiles
|
|||
}
|
||||
}
|
||||
|
||||
private Hashtable m_Table;
|
||||
private ArrayList m_Mobiles;
|
||||
private Dictionary<Type, IEntity> m_Table;
|
||||
private List<Mobile> m_Mobiles;
|
||||
|
||||
public DisplayCache() : base( 0 )
|
||||
{
|
||||
m_Table = new Hashtable();
|
||||
m_Mobiles = new ArrayList();
|
||||
m_Table = new Dictionary<Type, IEntity>();
|
||||
m_Mobiles = new List<Mobile>();
|
||||
}
|
||||
|
||||
public object Lookup( Type key )
|
||||
public IEntity Lookup( Type key )
|
||||
{
|
||||
return m_Table[key];
|
||||
IEntity e = null;
|
||||
m_Table.TryGetValue( key, out e );
|
||||
return e;
|
||||
}
|
||||
|
||||
public void Store( Type key, object obj, bool cache )
|
||||
public void Store( Type key, IEntity obj, bool cache )
|
||||
{
|
||||
if ( cache )
|
||||
m_Table[key] = obj;
|
||||
|
||||
if ( obj is Item )
|
||||
AddItem( (Item) obj );
|
||||
AddItem( (Item)obj );
|
||||
else if ( obj is Mobile )
|
||||
m_Mobiles.Add( obj );
|
||||
m_Mobiles.Add( (Mobile)obj );
|
||||
}
|
||||
|
||||
public DisplayCache( Serial serial ) : base( serial )
|
||||
|
|
@ -57,15 +57,13 @@ namespace Server.Mobiles
|
|||
base.OnAfterDelete();
|
||||
|
||||
for ( int i = 0; i < m_Mobiles.Count; ++i )
|
||||
((Mobile)m_Mobiles[i]).Delete();
|
||||
m_Mobiles[i].Delete();
|
||||
|
||||
m_Mobiles.Clear();
|
||||
|
||||
for ( int i = Items.Count - 1; i >= 0; --i )
|
||||
{
|
||||
if ( i < Items.Count )
|
||||
((Item)Items[i]).Delete();
|
||||
}
|
||||
Items[i].Delete();
|
||||
|
||||
if ( m_Cache == this )
|
||||
m_Cache = null;
|
||||
|
|
@ -77,7 +75,7 @@ namespace Server.Mobiles
|
|||
|
||||
writer.Write( (int) 0 ); // version
|
||||
|
||||
writer.WriteMobileList( m_Mobiles, true );
|
||||
writer.Write( m_Mobiles );
|
||||
}
|
||||
|
||||
public override void Deserialize( GenericReader reader )
|
||||
|
|
@ -86,25 +84,23 @@ namespace Server.Mobiles
|
|||
|
||||
int version = reader.ReadInt();
|
||||
|
||||
m_Mobiles = reader.ReadMobileList();
|
||||
m_Mobiles = reader.ReadStrongMobileList();
|
||||
|
||||
for ( int i = 0; i < m_Mobiles.Count; ++i )
|
||||
((Mobile)m_Mobiles[i]).Delete();
|
||||
m_Mobiles[i].Delete();
|
||||
|
||||
m_Mobiles.Clear();
|
||||
|
||||
for ( int i = Items.Count - 1; i >= 0; --i )
|
||||
{
|
||||
if ( i < Items.Count )
|
||||
((Item)Items[i]).Delete();
|
||||
}
|
||||
Items[i].Delete();
|
||||
|
||||
if ( m_Cache == null )
|
||||
m_Cache = this;
|
||||
else
|
||||
Delete();
|
||||
|
||||
m_Table = new Hashtable();
|
||||
m_Table = new Dictionary<Type, IEntity>();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -115,48 +111,44 @@ namespace Server.Mobiles
|
|||
private int m_ItemID;
|
||||
private int m_Hue;
|
||||
private object[] m_Args;
|
||||
private object m_DisplayObject;
|
||||
private IEntity m_DisplayEntity;
|
||||
|
||||
public virtual int ControlSlots{ get{ return 0; } }
|
||||
|
||||
public virtual bool CanCacheDisplay{ get{ return false; } } //return ( m_Args == null || m_Args.Length == 0 ); }
|
||||
|
||||
private bool IsDeleted( object obj )
|
||||
private bool IsDeleted( IEntity obj )
|
||||
{
|
||||
if ( obj is Item )
|
||||
return (obj as Item).Deleted;
|
||||
return ((Item)obj).Deleted;
|
||||
else if ( obj is Mobile )
|
||||
return (obj as Mobile).Deleted;
|
||||
return ((Mobile)obj).Deleted;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void DeleteDisplayObject()
|
||||
public void DeleteDisplayEntity()
|
||||
{
|
||||
if ( m_DisplayObject is Item )
|
||||
(m_DisplayObject as Item).Delete();
|
||||
else if ( m_DisplayObject is Mobile )
|
||||
(m_DisplayObject as Mobile).Delete();
|
||||
|
||||
m_DisplayObject = null;
|
||||
m_DisplayEntity.Delete();
|
||||
m_DisplayEntity = null;
|
||||
}
|
||||
|
||||
public object GetDisplayObject()
|
||||
public IEntity GetDisplayEntity()
|
||||
{
|
||||
if ( m_DisplayObject != null && !IsDeleted( m_DisplayObject ) )
|
||||
return m_DisplayObject;
|
||||
if ( m_DisplayEntity != null && !IsDeleted( m_DisplayEntity ) )
|
||||
return m_DisplayEntity;
|
||||
|
||||
bool canCache = this.CanCacheDisplay;
|
||||
|
||||
if ( canCache )
|
||||
m_DisplayObject = DisplayCache.Cache.Lookup( m_Type );
|
||||
m_DisplayEntity = DisplayCache.Cache.Lookup( m_Type );
|
||||
|
||||
if ( m_DisplayObject == null || IsDeleted( m_DisplayObject ) )
|
||||
m_DisplayObject = GetObject();
|
||||
if ( m_DisplayEntity == null || IsDeleted( m_DisplayEntity ) )
|
||||
m_DisplayEntity = GetEntity();
|
||||
|
||||
DisplayCache.Cache.Store( m_Type, m_DisplayObject, canCache );
|
||||
DisplayCache.Cache.Store( m_Type, m_DisplayEntity, canCache );
|
||||
|
||||
return m_DisplayObject;
|
||||
return m_DisplayEntity;
|
||||
}
|
||||
|
||||
public Type Type
|
||||
|
|
@ -267,12 +259,12 @@ namespace Server.Mobiles
|
|||
}
|
||||
|
||||
//get a new instance of an object (we just bought it)
|
||||
public virtual object GetObject()
|
||||
public virtual IEntity GetEntity()
|
||||
{
|
||||
if ( m_Args == null || m_Args.Length == 0 )
|
||||
return Activator.CreateInstance( m_Type );
|
||||
return (IEntity)Activator.CreateInstance( m_Type );
|
||||
|
||||
return Activator.CreateInstance( m_Type, m_Args );
|
||||
return (IEntity)Activator.CreateInstance( m_Type, m_Args );
|
||||
//return (Item)Activator.CreateInstance( m_Type );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Server.Items;
|
||||
|
||||
namespace Server.Mobiles
|
||||
{
|
||||
public class GenericSellInfo : IShopSellInfo
|
||||
{
|
||||
private Hashtable m_Table = new Hashtable();
|
||||
private Dictionary<Type, int> m_Table = new Dictionary<Type, int>();
|
||||
private Type[] m_Types;
|
||||
|
||||
public GenericSellInfo()
|
||||
|
|
@ -21,10 +21,10 @@ namespace Server.Mobiles
|
|||
|
||||
public int GetSellPriceFor( Item item )
|
||||
{
|
||||
int price = (int)m_Table[item.GetType()];
|
||||
int price = 0;
|
||||
m_Table.TryGetValue( item.GetType(), out price );
|
||||
|
||||
if ( item is BaseArmor )
|
||||
{
|
||||
if ( item is BaseArmor ) {
|
||||
BaseArmor armor = (BaseArmor)item;
|
||||
|
||||
if ( armor.Quality == ArmorQuality.Low )
|
||||
|
|
@ -39,9 +39,7 @@ namespace Server.Mobiles
|
|||
if ( price < 1 )
|
||||
price = 1;
|
||||
}
|
||||
|
||||
else if ( item is BaseWeapon )
|
||||
{
|
||||
else if ( item is BaseWeapon ) {
|
||||
BaseWeapon weapon = (BaseWeapon)item;
|
||||
|
||||
if ( weapon.Quality == WeaponQuality.Low )
|
||||
|
|
@ -56,8 +54,7 @@ namespace Server.Mobiles
|
|||
if ( price < 1 )
|
||||
price = 1;
|
||||
}
|
||||
else if ( item is BaseBeverage )
|
||||
{
|
||||
else if ( item is BaseBeverage ) {
|
||||
int price1 = price, price2 = price;
|
||||
|
||||
if ( item is Pitcher )
|
||||
|
|
@ -123,12 +120,7 @@ namespace Server.Mobiles
|
|||
|
||||
public bool IsInList( Type type )
|
||||
{
|
||||
Object o = m_Table[type];
|
||||
|
||||
if ( o == null )
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
return m_Table.ContainsKey( type );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace Server.Mobiles
|
|||
m_Entry = entry;
|
||||
}
|
||||
|
||||
public override object GetObject()
|
||||
public override IEntity GetEntity()
|
||||
{
|
||||
return new PresetMap( m_Entry );
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue