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
|
|
@ -1,5 +1,5 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Server.Items;
|
||||
|
||||
namespace Server.Engines.Craft
|
||||
|
|
@ -42,7 +42,7 @@ namespace Server.Engines.Craft
|
|||
|
||||
public virtual CraftECA ECA{ get{ return CraftECA.ChanceMinusSixty; } }
|
||||
|
||||
private Hashtable m_ContextTable = new Hashtable();
|
||||
private Dictionary<Mobile, CraftContext> m_ContextTable = new Dictionary<Mobile, CraftContext>();
|
||||
|
||||
public abstract double GetChanceAtMin( CraftItem item );
|
||||
|
||||
|
|
@ -62,7 +62,8 @@ namespace Server.Engines.Craft
|
|||
return null;
|
||||
}
|
||||
|
||||
CraftContext c = (CraftContext)m_ContextTable[m];
|
||||
CraftContext c = null;
|
||||
m_ContextTable.TryGetValue( m, out c );
|
||||
|
||||
if ( c == null )
|
||||
m_ContextTable[m] = c = new CraftContext();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
using Server.Network;
|
||||
|
|
@ -50,8 +50,7 @@ namespace Server.Items
|
|||
|
||||
public PuzzleChestSolution()
|
||||
{
|
||||
for ( int i = 0; i < m_Cylinders.Length; i++ )
|
||||
{
|
||||
for ( int i = 0; i < m_Cylinders.Length; i++ ) {
|
||||
m_Cylinders[i] = RandomCylinder();
|
||||
}
|
||||
}
|
||||
|
|
@ -67,8 +66,7 @@ namespace Server.Items
|
|||
|
||||
public PuzzleChestSolution( PuzzleChestSolution solution )
|
||||
{
|
||||
for ( int i = 0; i < m_Cylinders.Length; i++ )
|
||||
{
|
||||
for ( int i = 0; i < m_Cylinders.Length; i++ ) {
|
||||
m_Cylinders[i] = solution.m_Cylinders[i];
|
||||
}
|
||||
}
|
||||
|
|
@ -183,7 +181,7 @@ namespace Server.Items
|
|||
|
||||
private PuzzleChestSolution m_Solution;
|
||||
private PuzzleChestCylinder[] m_Hints = new PuzzleChestCylinder[HintsCount];
|
||||
private Hashtable m_Guesses = new Hashtable();
|
||||
private Dictionary<Mobile, PuzzleChestSolutionAndTime> m_Guesses = new Dictionary<Mobile, PuzzleChestSolutionAndTime>();
|
||||
|
||||
public PuzzleChestSolution Solution
|
||||
{
|
||||
|
|
@ -212,17 +210,15 @@ namespace Server.Items
|
|||
|
||||
private void InitHints()
|
||||
{
|
||||
ArrayList list = new ArrayList( Solution.Cylinders.Length - 1 );
|
||||
List<PuzzleChestCylinder> list = new List<PuzzleChestCylinder>( Solution.Cylinders.Length - 1 );
|
||||
for ( int i = 1; i < Solution.Cylinders.Length; i++ )
|
||||
{
|
||||
list.Add( Solution.Cylinders[i] );
|
||||
}
|
||||
|
||||
m_Hints = new PuzzleChestCylinder[HintsCount];
|
||||
for ( int i = 0; i < m_Hints.Length; i++ )
|
||||
{
|
||||
|
||||
for ( int i = 0; i < m_Hints.Length; i++ ) {
|
||||
int pos = Utility.Random( list.Count );
|
||||
m_Hints[i] = (PuzzleChestCylinder)list[pos];
|
||||
m_Hints[i] = list[pos];
|
||||
list.RemoveAt( pos );
|
||||
}
|
||||
}
|
||||
|
|
@ -256,7 +252,9 @@ namespace Server.Items
|
|||
|
||||
public PuzzleChestSolutionAndTime GetLastGuess( Mobile m )
|
||||
{
|
||||
return (PuzzleChestSolutionAndTime)m_Guesses[m];
|
||||
PuzzleChestSolutionAndTime pcst = null;
|
||||
m_Guesses.TryGetValue( m, out pcst );
|
||||
return pcst;
|
||||
}
|
||||
|
||||
public void SubmitSolution( Mobile m, PuzzleChestSolution solution )
|
||||
|
|
@ -561,16 +559,14 @@ namespace Server.Items
|
|||
{
|
||||
DropItem( new Gold( 600, 900 ) );
|
||||
|
||||
ArrayList gems = new ArrayList();
|
||||
List<Item> gems = new List<Item>();
|
||||
for ( int i = 0; i < 9; i++ )
|
||||
{
|
||||
Item gem = Loot.RandomGem();
|
||||
Type gemType = gem.GetType();
|
||||
|
||||
foreach ( Item listGem in gems )
|
||||
{
|
||||
if ( listGem.GetType() == gemType )
|
||||
{
|
||||
foreach ( Item listGem in gems ) {
|
||||
if ( listGem.GetType() == gemType ) {
|
||||
listGem.Amount++;
|
||||
gem.Delete();
|
||||
break;
|
||||
|
|
@ -582,10 +578,7 @@ namespace Server.Items
|
|||
}
|
||||
|
||||
foreach ( Item gem in gems )
|
||||
{
|
||||
DropItem( gem );
|
||||
}
|
||||
|
||||
|
||||
if ( 0.2 > Utility.RandomDouble() )
|
||||
DropItem( new BagOfReagents( 50 ) );
|
||||
|
|
@ -676,18 +669,15 @@ namespace Server.Items
|
|||
|
||||
public void CleanupGuesses()
|
||||
{
|
||||
ArrayList toDelete = new ArrayList();
|
||||
List<Mobile> toDelete = new List<Mobile>();
|
||||
|
||||
foreach ( DictionaryEntry entry in m_Guesses )
|
||||
{
|
||||
if ( DateTime.Now - ((PuzzleChestSolutionAndTime)entry.Value).When > CleanupTime )
|
||||
toDelete.Add( entry.Key );
|
||||
foreach ( KeyValuePair<Mobile, PuzzleChestSolutionAndTime> kvp in m_Guesses ) {
|
||||
if ( DateTime.Now - kvp.Value.When > CleanupTime )
|
||||
toDelete.Add( kvp.Key );
|
||||
}
|
||||
|
||||
foreach ( Mobile m in toDelete )
|
||||
{
|
||||
m_Guesses.Remove( m );
|
||||
}
|
||||
}
|
||||
|
||||
public PuzzleChest( Serial serial ) : base( serial )
|
||||
|
|
@ -711,10 +701,9 @@ namespace Server.Items
|
|||
}
|
||||
|
||||
writer.WriteEncodedInt( (int) m_Guesses.Count );
|
||||
foreach ( DictionaryEntry entry in m_Guesses )
|
||||
{
|
||||
writer.Write( (Mobile) entry.Key );
|
||||
((PuzzleChestSolutionAndTime)entry.Value).Serialize( writer );
|
||||
foreach ( KeyValuePair<Mobile, PuzzleChestSolutionAndTime> kvp in m_Guesses ) {
|
||||
writer.Write( kvp.Key );
|
||||
kvp.Value.Serialize( writer );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -242,16 +242,7 @@ namespace Server.Multis
|
|||
{
|
||||
int type = (itemID - 0x314) / 16;
|
||||
DoorFacing facing = (DoorFacing)(((itemID - 0x314) / 2) % 8);
|
||||
|
||||
//TODO: Change this to just do a 0x314 + type*16
|
||||
switch( type )
|
||||
{
|
||||
case 0: door = new GenericHouseDoor( facing, 0x314, 0xED, 0xF4 ); break;
|
||||
case 1: door = new GenericHouseDoor( facing, 0x324, 0xED, 0xF4 ); break;
|
||||
case 2: door = new GenericHouseDoor( facing, 0x334, 0xED, 0xF4 ); break;
|
||||
case 3: door = new GenericHouseDoor( facing, 0x344, 0xED, 0xF4 ); break;
|
||||
case 4: door = new GenericHouseDoor( facing, 0x354, 0xED, 0xF4 ); break;
|
||||
}
|
||||
door = new GenericHouseDoor( facing, 0x314 + ( type * 16 ), 0xED, 0xF4 );
|
||||
}
|
||||
else if( itemID >= 0x824 && itemID < 0x834 )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using Server.Targeting;
|
||||
using System.Collections.Generic;
|
||||
using Server.Network;
|
||||
using Server.Targeting;
|
||||
|
||||
namespace Server.Spells.Fourth
|
||||
{
|
||||
|
|
@ -26,7 +26,7 @@ namespace Server.Spells.Fourth
|
|||
Caster.Target = new InternalTarget( this );
|
||||
}
|
||||
|
||||
private Hashtable m_Table = new Hashtable();
|
||||
private static Dictionary<Mobile, Timer> m_Table = new Dictionary<Mobile, Timer>();
|
||||
|
||||
private void AosDelay_Callback( object state )
|
||||
{
|
||||
|
|
@ -72,7 +72,7 @@ namespace Server.Spells.Fourth
|
|||
else if ( toDrain > m.Mana )
|
||||
toDrain = m.Mana;
|
||||
|
||||
if ( m_Table.Contains( m ) )
|
||||
if ( m_Table.ContainsKey( m ) )
|
||||
toDrain = 0;
|
||||
|
||||
m.FixedParticles( 0x3789, 10, 25, 5032, EffectLayer.Head );
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue