generics, cleanups
This commit is contained in:
parent
6fcfced3fa
commit
071898373e
5 changed files with 58 additions and 76 deletions
|
|
@ -1,5 +1,5 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Server;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
|
|
@ -165,17 +165,15 @@ namespace Server.Spells
|
|||
m.CheckSkill( MoveSkill, RequiredSkill, RequiredSkill + 37.5 );
|
||||
}
|
||||
|
||||
private static Hashtable m_Table = new Hashtable();
|
||||
private static Dictionary<Mobile, SpecialMove> m_Table = new Dictionary<Mobile, SpecialMove>();
|
||||
|
||||
public static Hashtable Table{ get{ return m_Table; } }
|
||||
public static Dictionary<Mobile, SpecialMove> Table{ get{ return m_Table; } }
|
||||
|
||||
public static void ClearAllMoves( Mobile m )
|
||||
{
|
||||
foreach ( DictionaryEntry de in SpellRegistry.SpecialMoves )
|
||||
foreach ( KeyValuePair<Int32, SpecialMove> kvp in SpellRegistry.SpecialMoves )
|
||||
{
|
||||
SpecialMove move = (SpecialMove)de.Value;
|
||||
|
||||
int moveID = SpellRegistry.GetRegistryNumber( move );
|
||||
int moveID = kvp.Key;
|
||||
|
||||
if ( moveID != -1 )
|
||||
m.Send( new ToggleSpecialAbility( moveID + 1, false ) );
|
||||
|
|
@ -195,7 +193,8 @@ namespace Server.Spells
|
|||
return null;
|
||||
}
|
||||
|
||||
SpecialMove move = (SpecialMove)m_Table[m];
|
||||
SpecialMove move = null;
|
||||
m_Table.TryGetValue( m, out move );
|
||||
|
||||
if ( move != null && move.ValidatesDuringHit && !move.Validate( m ) )
|
||||
{
|
||||
|
|
@ -248,7 +247,8 @@ namespace Server.Spells
|
|||
|
||||
public static void ClearCurrentMove( Mobile m )
|
||||
{
|
||||
SpecialMove move = (SpecialMove)m_Table[m];
|
||||
SpecialMove move = null;
|
||||
m_Table.TryGetValue( m, out move );
|
||||
|
||||
if ( move != null )
|
||||
{
|
||||
|
|
@ -268,7 +268,7 @@ namespace Server.Spells
|
|||
}
|
||||
|
||||
|
||||
private static Hashtable m_PlayersTable = new Hashtable();
|
||||
private static Dictionary<Mobile, SpecialMoveContext> m_PlayersTable = new Dictionary<Mobile, SpecialMoveContext>();
|
||||
|
||||
private static void AddContext( Mobile m, SpecialMoveContext context )
|
||||
{
|
||||
|
|
@ -289,12 +289,13 @@ namespace Server.Spells
|
|||
|
||||
private static SpecialMoveContext GetContext( Mobile m )
|
||||
{
|
||||
return ( m_PlayersTable[m] as SpecialMoveContext );
|
||||
return ( m_PlayersTable.ContainsKey( m ) ? m_PlayersTable[m] : null );
|
||||
}
|
||||
|
||||
public static bool GetContext( Mobile m, Type type )
|
||||
{
|
||||
SpecialMoveContext context = m_PlayersTable[m] as SpecialMoveContext;
|
||||
SpecialMoveContext context = null;
|
||||
m_PlayersTable.TryGetValue( m, out context );
|
||||
|
||||
if ( context == null )
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Server.Items;
|
||||
using System.Collections;
|
||||
using Server.Spells.Necromancy;
|
||||
using Server.Spells.Chivalry;
|
||||
using Server.Spells.Bushido;
|
||||
using Server.Spells.Chivalry;
|
||||
using Server.Items;
|
||||
using Server.Spells.Necromancy;
|
||||
using Server.Spells.Ninjitsu;
|
||||
|
||||
namespace Server.Spells
|
||||
|
|
@ -33,16 +33,19 @@ namespace Server.Spells
|
|||
m_Count = 0;
|
||||
|
||||
for ( int i = 0; i < m_Types.Length; ++i )
|
||||
{
|
||||
if ( m_Types[i] != null )
|
||||
++m_Count;
|
||||
}
|
||||
}
|
||||
|
||||
return m_Count;
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<Type, Int32> m_IDsFromTypes = new Dictionary<Type, Int32>( m_Types.Length );
|
||||
|
||||
private static Dictionary<Int32, SpecialMove> m_SpecialMoves = new Dictionary<Int32, SpecialMove>();
|
||||
public static Dictionary<Int32, SpecialMove> SpecialMoves { get { return m_SpecialMoves; } }
|
||||
|
||||
public static int GetRegistryNumber( ISpell s )
|
||||
{
|
||||
return GetRegistryNumber( s.GetType() );
|
||||
|
|
@ -53,20 +56,14 @@ namespace Server.Spells
|
|||
return GetRegistryNumber( s.GetType() );
|
||||
}
|
||||
|
||||
private static Hashtable m_IDsFromTypes = new Hashtable( m_Types.Length );
|
||||
|
||||
public static int GetRegistryNumber( Type type )
|
||||
{
|
||||
if( m_IDsFromTypes.Contains( type ) )
|
||||
return (int)m_IDsFromTypes[type];
|
||||
if( m_IDsFromTypes.ContainsKey( type ) )
|
||||
return m_IDsFromTypes[type];
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static Hashtable m_SpecialMoves = new Hashtable();
|
||||
|
||||
public static Hashtable SpecialMoves { get { return m_SpecialMoves; } }
|
||||
|
||||
public static void Register( int spellID, Type type )
|
||||
{
|
||||
if ( spellID < 0 || spellID >= m_Types.Length )
|
||||
|
|
@ -77,7 +74,7 @@ namespace Server.Spells
|
|||
|
||||
m_Types[spellID] = type;
|
||||
|
||||
if( m_IDsFromTypes[type] == null )
|
||||
if( !m_IDsFromTypes.ContainsKey( type ) )
|
||||
m_IDsFromTypes.Add( type, spellID );
|
||||
|
||||
if( type.IsSubclassOf( typeof( SpecialMove ) ) )
|
||||
|
|
@ -104,13 +101,10 @@ namespace Server.Spells
|
|||
|
||||
Type t = m_Types[spellID];
|
||||
|
||||
if ( t == null || !t.IsSubclassOf( typeof( SpecialMove ) ) ) //Ensure correct registration
|
||||
if ( t == null || !t.IsSubclassOf( typeof( SpecialMove ) ) || !m_SpecialMoves.ContainsKey( spellID ) )
|
||||
return null;
|
||||
|
||||
if( m_SpecialMoves.ContainsKey( spellID ) )
|
||||
return m_SpecialMoves[spellID] as SpecialMove;
|
||||
|
||||
return null;
|
||||
return m_SpecialMoves[spellID];
|
||||
}
|
||||
|
||||
private static object[] m_Params = new object[2];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue