ISpawner; ISpawnable, cleanup. All custom spawners should inherit from ISpawner. Also, Ridiculous, not rediculous,

This commit is contained in:
asayre 2010-12-26 05:18:57 +00:00
parent 2971234c1c
commit 18d1396670
17 changed files with 212 additions and 243 deletions

View file

@ -451,7 +451,7 @@ namespace Server.Commands
int indexOf = m_Params[i].IndexOf( '=' ); int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 ) if ( indexOf >= 0 )
sp.CreaturesName.Add( m_Params[i].Substring( ++indexOf ) ); sp.SpawnNames.Add( m_Params[i].Substring( ++indexOf ) );
} }
else if ( m_Params[i].StartsWith( "MinDelay" ) ) else if ( m_Params[i].StartsWith( "MinDelay" ) )
{ {

View file

@ -448,7 +448,7 @@ namespace Server.Commands
int indexOf = m_Params[i].IndexOf( '=' ); int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 ) if ( indexOf >= 0 )
sp.CreaturesName.Add( m_Params[i].Substring( ++indexOf ) ); sp.SpawnNames.Add( m_Params[i].Substring( ++indexOf ) );
} }
else if ( m_Params[i].StartsWith( "MinDelay" ) ) else if ( m_Params[i].StartsWith( "MinDelay" ) )
{ {

View file

@ -356,8 +356,8 @@ namespace Server.Commands
{ {
Spawner spawner = (Spawner)item; Spawner spawner = (Spawner)item;
for ( int i = 0; !hasBankerSpawner && i < spawner.CreaturesName.Count; ++i ) for ( int i = 0; !hasBankerSpawner && i < spawner.SpawnNames.Count; ++i )
hasBankerSpawner = Insensitive.Equals( (string)spawner.CreaturesName[i], "banker" ); hasBankerSpawner = Insensitive.Equals( (string)spawner.SpawnNames[i], "banker" );
if ( hasBankerSpawner ) if ( hasBankerSpawner )
break; break;

View file

@ -673,7 +673,7 @@ namespace Server.Factions
int dexMod = GetStatMod( m_Guard, StatType.Dex ); int dexMod = GetStatMod( m_Guard, StatType.Dex );
int intMod = GetStatMod( m_Guard, StatType.Int ); int intMod = GetStatMod( m_Guard, StatType.Int );
List<Type> types = new List<Type>(); List<Type> types = new List<Type>();
if ( strMod <= 0 ) if ( strMod <= 0 )
types.Add( typeof( StrengthSpell ) ); types.Add( typeof( StrengthSpell ) );
@ -712,7 +712,7 @@ namespace Server.Factions
int dexMod = GetStatMod( combatant, StatType.Dex ); int dexMod = GetStatMod( combatant, StatType.Dex );
int intMod = GetStatMod( combatant, StatType.Int ); int intMod = GetStatMod( combatant, StatType.Int );
List<Type> types = new List<Type>(); List<Type> types = new List<Type>();
if ( strMod >= 0 ) if ( strMod >= 0 )
types.Add( typeof( WeakenSpell ) ); types.Add( typeof( WeakenSpell ) );

View file

@ -12,38 +12,38 @@ using CPA = Server.CommandPropertyAttribute;
namespace Server.Mobiles namespace Server.Mobiles
{ {
public class Spawner : Item public class Spawner : Item, ISpawner
{ {
private int m_Team; private int m_Team;
private int m_HomeRange; private int m_HomeRange;
private int m_WalkingRange = -1; private int m_WalkingRange;
private int m_Count; private int m_Count;
private TimeSpan m_MinDelay; private TimeSpan m_MinDelay;
private TimeSpan m_MaxDelay; private TimeSpan m_MaxDelay;
private List<string> m_CreaturesName; private List<string> m_SpawnNames;
private List<IEntity> m_Creatures; private List<ISpawnable> m_Spawned;
private DateTime m_End; private DateTime m_End;
private InternalTimer m_Timer; private InternalTimer m_Timer;
private bool m_Running; private bool m_Running;
private bool m_Group; private bool m_Group;
private WayPoint m_WayPoint; private WayPoint m_WayPoint;
public bool IsFull{ get{ return ( m_Creatures != null && m_Creatures.Count >= m_Count ); } } public bool IsFull{ get{ return ( m_Spawned != null && m_Spawned.Count >= m_Count ); } }
public List<string> CreaturesName public List<string> SpawnNames
{ {
get { return m_CreaturesName; } get { return m_SpawnNames; }
set set
{ {
m_CreaturesName = value; m_SpawnNames = value;
if ( m_CreaturesName.Count < 1 ) if ( m_SpawnNames.Count < 1 )
Stop(); Stop();
InvalidateProperties(); InvalidateProperties();
} }
} }
public virtual int CreaturesNameCount { get { return m_CreaturesName.Count; } } public virtual int SpawnNamesCount { get { return m_SpawnNames.Count; } }
public override void OnAfterDuped( Item newItem ) public override void OnAfterDuped( Item newItem )
{ {
@ -52,7 +52,8 @@ namespace Server.Mobiles
if ( s == null ) if ( s == null )
return; return;
s.m_CreaturesName = new List<string>( m_CreaturesName ); s.m_SpawnNames = new List<string>( m_SpawnNames );
s.m_Spawned = new List<ISpawnable>();
} }
[CommandProperty( AccessLevel.GameMaster )] [CommandProperty( AccessLevel.GameMaster )]
@ -150,32 +151,33 @@ namespace Server.Mobiles
} }
[Constructable] [Constructable]
public Spawner( int amount, int minDelay, int maxDelay, int team, int homeRange, string creatureName ) : base( 0x1f13 ) public Spawner()
: this(null)
{ {
List<string> creaturesName = new List<string>();
creaturesName.Add( creatureName );
InitSpawn( amount, TimeSpan.FromMinutes( minDelay ), TimeSpan.FromMinutes( maxDelay ), team, homeRange, creaturesName );
} }
[Constructable] [Constructable]
public Spawner( string creatureName ) : base( 0x1f13 ) public Spawner( string spawnName )
: this( 1, 5, 10, 0, 4, spawnName)
{ {
List<string> creaturesName = new List<string>();
creaturesName.Add( creatureName );
InitSpawn( 1, TimeSpan.FromMinutes( 5 ), TimeSpan.FromMinutes( 10 ), 0, 4, creaturesName );
} }
[Constructable] [Constructable]
public Spawner() : base( 0x1f13 ) public Spawner(int amount, int minDelay, int maxDelay, int team, int homeRange, string spawnName)
: base(0x1f13)
{ {
List<string> creaturesName = new List<string>(); List<string> spawnNames = new List<string>();
InitSpawn( 1, TimeSpan.FromMinutes( 5 ), TimeSpan.FromMinutes( 10 ), 0, 4, creaturesName );
if (!String.IsNullOrEmpty(spawnName))
spawnNames.Add(spawnName);
InitSpawner(amount, TimeSpan.FromMinutes(minDelay), TimeSpan.FromMinutes(maxDelay), team, homeRange, spawnNames);
} }
public Spawner( int amount, TimeSpan minDelay, TimeSpan maxDelay, int team, int homeRange, List<string> creaturesName ) public Spawner(int amount, TimeSpan minDelay, TimeSpan maxDelay, int team, int homeRange, List<string> spawnNames)
: base( 0x1f13 ) : base(0x1f13)
{ {
InitSpawn( amount, minDelay, maxDelay, team, homeRange, creaturesName ); InitSpawner(amount, minDelay, maxDelay, team, homeRange, spawnNames);
} }
public override string DefaultName public override string DefaultName
@ -183,7 +185,7 @@ namespace Server.Mobiles
get { return "Spawner"; } get { return "Spawner"; }
} }
public void InitSpawn( int amount, TimeSpan minDelay, TimeSpan maxDelay, int team, int homeRange, List<string> creaturesName ) private void InitSpawner( int amount, TimeSpan minDelay, TimeSpan maxDelay, int team, int homeRange, List<string> spawnNames )
{ {
Visible = false; Visible = false;
Movable = false; Movable = false;
@ -194,8 +196,9 @@ namespace Server.Mobiles
m_Count = amount; m_Count = amount;
m_Team = team; m_Team = team;
m_HomeRange = homeRange; m_HomeRange = homeRange;
m_CreaturesName = creaturesName; m_WalkingRange = -1;
m_Creatures = new List<IEntity>(); m_SpawnNames = spawnNames;
m_Spawned = new List<ISpawnable>();
DoTimer( TimeSpan.FromSeconds( 1 ) ); DoTimer( TimeSpan.FromSeconds( 1 ) );
} }
@ -228,8 +231,8 @@ namespace Server.Mobiles
list.Add( 1060660, "team\t{0}", m_Team ); // ~1_val~: ~2_val~ list.Add( 1060660, "team\t{0}", m_Team ); // ~1_val~: ~2_val~
list.Add( 1060661, "speed\t{0} to {1}", m_MinDelay, m_MaxDelay ); // ~1_val~: ~2_val~ list.Add( 1060661, "speed\t{0} to {1}", m_MinDelay, m_MaxDelay ); // ~1_val~: ~2_val~
for ( int i = 0; i < 2 && i < m_CreaturesName.Count; ++i ) for ( int i = 0; i < 2 && i < m_SpawnNames.Count; ++i )
list.Add( 1060662 + i, "{0}\t{1}", m_CreaturesName[i], CountCreatures( m_CreaturesName[i] ) ); list.Add( 1060662 + i, "{0}\t{1}", m_SpawnNames[i], CountCreatures( m_SpawnNames[i] ) );
} }
else else
{ {
@ -251,7 +254,7 @@ namespace Server.Mobiles
{ {
if ( !m_Running ) if ( !m_Running )
{ {
if ( CreaturesNameCount > 0 ) if ( SpawnNamesCount > 0 )
{ {
m_Running = true; m_Running = true;
DoTimer(); DoTimer();
@ -277,45 +280,41 @@ namespace Server.Mobiles
{ {
bool removed = false; bool removed = false;
for ( int i = 0; i < m_Creatures.Count; ++i ) for ( int i = 0; i < m_Spawned.Count; ++i )
{ {
IEntity e = m_Creatures[i]; ISpawnable e = m_Spawned[i];
if ( e is Item ) bool toRemove = false;
if( e is Item )
{ {
Item item = (Item)e; Item item = (Item)e;
if ( item.Deleted || item.Parent != null ) if (item.Deleted || item.Parent != null)
{ toRemove = true;
m_Creatures.RemoveAt( i );
--i;
removed = true;
}
} }
else if ( e is Mobile ) else if (e is Mobile)
{ {
Mobile m = (Mobile)e; Mobile m = (Mobile)e;
if ( m.Deleted ) if (m.Deleted)
{ {
m_Creatures.RemoveAt( i ); toRemove = true;
--i;
removed = true;
} }
else if ( m is BaseCreature ) else if (m is BaseCreature)
{ {
BaseCreature bc = (BaseCreature)m; BaseCreature bc = (BaseCreature)m;
if ( bc.Controlled || bc.IsStabled )
if (bc.Controlled || bc.IsStabled)
{ {
m_Creatures.RemoveAt( i ); toRemove = true;
--i;
removed = true;
} }
} }
} }
else
if (toRemove)
{ {
m_Creatures.RemoveAt( i ); m_Spawned.RemoveAt(i);
--i; --i;
removed = true; removed = true;
} }
@ -325,6 +324,15 @@ namespace Server.Mobiles
InvalidateProperties(); InvalidateProperties();
} }
bool ISpawner.UnlinkOnTaming { get { return true; } }
void ISpawner.Remove( ISpawnable spawn )
{
m_Spawned.Remove( spawn );
InvalidateProperties();
}
public void OnTick() public void OnTick()
{ {
DoTimer(); DoTimer();
@ -333,7 +341,7 @@ namespace Server.Mobiles
{ {
Defrag(); Defrag();
if ( m_Creatures.Count == 0 ) if ( m_Spawned.Count == 0 )
{ {
Respawn(); Respawn();
} }
@ -350,7 +358,7 @@ namespace Server.Mobiles
public void Respawn() public void Respawn()
{ {
RemoveCreatures(); RemoveSpawned();
for ( int i = 0; i < m_Count; i++ ) for ( int i = 0; i < m_Count; i++ )
Spawn(); Spawn();
@ -358,15 +366,15 @@ namespace Server.Mobiles
public void Spawn() public void Spawn()
{ {
if ( CreaturesNameCount > 0 ) if ( SpawnNamesCount > 0 )
Spawn( Utility.Random( CreaturesNameCount ) ); Spawn( Utility.Random( SpawnNamesCount ) );
} }
public void Spawn( string creatureName ) public void Spawn( string creatureName )
{ {
for ( int i = 0; i < m_CreaturesName.Count; i++ ) for ( int i = 0; i < m_SpawnNames.Count; i++ )
{ {
if ( m_CreaturesName[i] == creatureName ) if ( m_SpawnNames[i] == creatureName )
{ {
Spawn( i ); Spawn( i );
break; break;
@ -374,18 +382,18 @@ namespace Server.Mobiles
} }
} }
protected virtual IEntity CreateSpawnedObject( int index ) protected virtual ISpawnable CreateSpawnedObject( int index )
{ {
if ( index >= m_CreaturesName.Count ) if ( index >= m_SpawnNames.Count )
return null; return null;
Type type = ScriptCompiler.FindTypeByName( ParseType( m_CreaturesName[index] ) ); Type type = ScriptCompiler.FindTypeByName( ParseType( m_SpawnNames[index] ) );
if ( type != null ) if ( type != null )
{ {
try try
{ {
return Build( CommandSystem.Split( m_CreaturesName[index] ) ); return Build( type, CommandSystem.Split( m_SpawnNames[index] ) );
} }
catch catch
{ {
@ -395,9 +403,14 @@ namespace Server.Mobiles
return null; return null;
} }
public static IEntity Build( string[] args ) public static ISpawnable Build( Type type, string[] args)
{ {
string name = args[0]; bool isISpawnable = typeof(ISpawnable).IsAssignableFrom( type );
if (!isISpawnable)
{
return null;
}
Add.FixArgs( ref args ); Add.FixArgs( ref args );
@ -428,12 +441,6 @@ namespace Server.Mobiles
} }
} }
Type type = ScriptCompiler.FindTypeByName( name );
if ( !Add.IsEntity( type ) ) {
return null;
}
PropertyInfo[] realProps = null; PropertyInfo[] realProps = null;
if ( props != null ) if ( props != null )
@ -495,78 +502,59 @@ namespace Server.Mobiles
} }
} }
return (IEntity)built; return (ISpawnable)built;
} }
} }
return null; return null;
} }
public Point3D HomeLocation { get { return this.Location; } }
public void Spawn( int index ) public void Spawn( int index )
{ {
Map map = Map; Map map = Map;
if ( map == null || map == Map.Internal || CreaturesNameCount == 0 || index >= CreaturesNameCount || Parent != null ) if ( map == null || map == Map.Internal || SpawnNamesCount == 0 || index >= SpawnNamesCount || Parent != null )
return; return;
Defrag(); Defrag();
if ( m_Creatures.Count >= m_Count ) if ( m_Spawned.Count >= m_Count )
return; return;
ISpawnable spawned = CreateSpawnedObject( index );
IEntity ent = CreateSpawnedObject( index ); if (spawned == null)
return;
if ( ent is Mobile ) m_Spawned.Add(spawned);
Point3D loc = (spawned is BaseVendor ? this.Location : GetSpawnPosition());
spawned.OnBeforeSpawn(loc, map);
InvalidateProperties();
spawned.MoveToWorld(loc, map);
if (spawned is BaseCreature)
{ {
Mobile m = (Mobile)ent; BaseCreature bc = (BaseCreature)spawned;
m_Creatures.Add( m );
Point3D loc = ( m is BaseVendor ? this.Location : GetSpawnPosition() );
m.OnBeforeSpawn( loc, map );
InvalidateProperties();
m.MoveToWorld( loc, map );
if ( m is BaseCreature )
{
BaseCreature c = (BaseCreature)m;
if( m_WalkingRange >= 0 ) if( m_WalkingRange >= 0 )
c.RangeHome = m_WalkingRange; bc.RangeHome = m_WalkingRange;
else else
c.RangeHome = m_HomeRange; bc.RangeHome = m_HomeRange;
c.CurrentWayPoint = m_WayPoint; bc.CurrentWayPoint = m_WayPoint;
if ( m_Team > 0 ) if ( m_Team > 0 )
c.Team = m_Team; bc.Team = m_Team;
c.Home = this.Location; bc.Home = this.HomeLocation;
}
m.OnAfterSpawn();
} }
else if ( ent is Item ) }
{
Item item = (Item)ent;
m_Creatures.Add( item );
Point3D loc = GetSpawnPosition();
item.OnBeforeSpawn( loc, map );
InvalidateProperties();
item.MoveToWorld( loc, map );
item.OnAfterSpawn();
}
}
public Point3D GetSpawnPosition() public Point3D GetSpawnPosition()
{ {
@ -653,20 +641,20 @@ namespace Server.Mobiles
int count = 0; int count = 0;
for ( int i = 0; i < m_Creatures.Count; ++i ) for ( int i = 0; i < m_Spawned.Count; ++i )
if ( Insensitive.Equals( creatureName, m_Creatures[i].GetType().Name ) ) if ( Insensitive.Equals( creatureName, m_Spawned[i].GetType().Name ) )
++count; ++count;
return count; return count;
} }
public void RemoveCreatures( string creatureName ) public void RemoveSpawned( string creatureName )
{ {
Defrag(); Defrag();
for ( int i = 0; i < m_Creatures.Count; ++i ) for ( int i = 0; i < m_Spawned.Count; ++i )
{ {
IEntity e = m_Creatures[i]; IEntity e = m_Spawned[i];
if ( Insensitive.Equals( creatureName, e.GetType().Name ) ) if ( Insensitive.Equals( creatureName, e.GetType().Name ) )
e.Delete(); e.Delete();
@ -675,12 +663,12 @@ namespace Server.Mobiles
InvalidateProperties(); InvalidateProperties();
} }
public void RemoveCreatures() public void RemoveSpawned()
{ {
Defrag(); Defrag();
for ( int i = 0; i < m_Creatures.Count; ++i ) for ( int i = 0; i < m_Spawned.Count; ++i )
m_Creatures[i].Delete(); m_Spawned[i].Delete();
InvalidateProperties(); InvalidateProperties();
} }
@ -689,22 +677,12 @@ namespace Server.Mobiles
{ {
Defrag(); Defrag();
for ( int i = 0; i < m_Creatures.Count; ++i ) for ( int i = 0; i < m_Spawned.Count; ++i )
{ {
IEntity e = m_Creatures[i]; ISpawnable e = m_Spawned[i];
if ( e is Mobile ) e.MoveToWorld( this.Location, this.Map );
{
Mobile m = (Mobile)e;
m.MoveToWorld( Location, Map );
}
else if ( e is Item )
{
Item item = (Item)e;
item.MoveToWorld( Location, Map );
}
} }
} }
@ -712,7 +690,7 @@ namespace Server.Mobiles
{ {
base.OnDelete(); base.OnDelete();
RemoveCreatures(); RemoveSpawned();
if ( m_Timer != null ) if ( m_Timer != null )
m_Timer.Stop(); m_Timer.Stop();
} }
@ -738,16 +716,16 @@ namespace Server.Mobiles
if ( m_Running ) if ( m_Running )
writer.WriteDeltaTime( m_End ); writer.WriteDeltaTime( m_End );
writer.Write( m_CreaturesName.Count ); writer.Write( m_SpawnNames.Count );
for ( int i = 0; i < m_CreaturesName.Count; ++i ) for ( int i = 0; i < m_SpawnNames.Count; ++i )
writer.Write( m_CreaturesName[i] ); writer.Write( m_SpawnNames[i] );
writer.Write( m_Creatures.Count ); writer.Write( m_Spawned.Count );
for ( int i = 0; i < m_Creatures.Count; ++i ) for ( int i = 0; i < m_Spawned.Count; ++i )
{ {
IEntity e = m_Creatures[i]; IEntity e = m_Spawned[i];
if ( e is Item ) if ( e is Item )
writer.Write( (Item)e ); writer.Write( (Item)e );
@ -805,13 +783,13 @@ namespace Server.Mobiles
int size = reader.ReadInt(); int size = reader.ReadInt();
m_CreaturesName = new List<string>( size ); m_SpawnNames = new List<string>( size );
for ( int i = 0; i < size; ++i ) for ( int i = 0; i < size; ++i )
{ {
string creatureString = reader.ReadString(); string creatureString = reader.ReadString();
m_CreaturesName.Add( creatureString ); m_SpawnNames.Add( creatureString );
string typeName = ParseType( creatureString ); string typeName = ParseType( creatureString );
if ( ScriptCompiler.FindTypeByName( typeName ) == null ) if ( ScriptCompiler.FindTypeByName( typeName ) == null )
@ -825,14 +803,14 @@ namespace Server.Mobiles
int count = reader.ReadInt(); int count = reader.ReadInt();
m_Creatures = new List<IEntity>( count ); m_Spawned = new List<ISpawnable>(count);
for ( int i = 0; i < count; ++i ) for ( int i = 0; i < count; ++i )
{ {
IEntity e = World.FindEntity( reader.ReadInt() ); ISpawnable e = World.FindEntity(reader.ReadInt()) as ISpawnable;
if ( e != null ) if ( e != null )
m_Creatures.Add( e ); m_Spawned.Add( e );
} }
if ( m_Running ) if ( m_Running )

View file

@ -42,9 +42,9 @@ namespace Server.Mobiles
string str = ""; string str = "";
if ( i < spawner.CreaturesName.Count ) if ( i < spawner.SpawnNames.Count )
{ {
str = (string)spawner.CreaturesName[i]; str = (string)spawner.SpawnNames[i];
int count = m_Spawner.CountCreatures( str ); int count = m_Spawner.CountCreatures( str );
AddLabel( 382, ( 22 * i ) + 20, 0, count.ToString() ); AddLabel( 382, ( 22 * i ) + 20, 0, count.ToString() );
@ -98,7 +98,7 @@ namespace Server.Mobiles
} }
case 1: // Okay case 1: // Okay
{ {
m_Spawner.CreaturesName = CreateArray( info, state.Mobile ); m_Spawner.SpawnNames = CreateArray( info, state.Mobile );
break; break;
} }
@ -127,9 +127,9 @@ namespace Server.Mobiles
if ( type == 0 ) // Spawn creature if ( type == 0 ) // Spawn creature
m_Spawner.Spawn( entry.Text ); m_Spawner.Spawn( entry.Text );
else // Remove creatures else // Remove creatures
m_Spawner.RemoveCreatures( entry.Text ); m_Spawner.RemoveSpawned( entry.Text );
m_Spawner.CreaturesName = CreateArray( info, state.Mobile ); m_Spawner.SpawnNames = CreateArray( info, state.Mobile );
} }
break; break;

View file

@ -49,7 +49,7 @@ namespace Server.Items
public void Unlink() public void Unlink()
{ {
SpawnEntry se = this.Spawner as SpawnEntry; ISpawner se = this.Spawner;
if ( se != null ) if ( se != null )
{ {

View file

@ -1548,10 +1548,10 @@ namespace Server.Mobiles
m_Mobile.IsBonded = false; m_Mobile.IsBonded = false;
SpawnEntry se = m_Mobile.Spawner as SpawnEntry; SpawnEntry se = m_Mobile.Spawner as SpawnEntry;
if( se != null && se.Home != Point3D.Zero ) if( se != null && se.HomeLocation != Point3D.Zero )
{ {
m_Mobile.Home = se.Home; m_Mobile.Home = se.HomeLocation;
m_Mobile.RangeHome = se.Range; m_Mobile.RangeHome = se.HomeRange;
} }
if( m_Mobile.DeleteOnRelease || m_Mobile.IsDeadPet ) if( m_Mobile.DeleteOnRelease || m_Mobile.IsDeadPet )
@ -2618,14 +2618,14 @@ namespace Server.Mobiles
if( se != null && se.ReturnOnDeactivate && !m_Mobile.Controlled ) if( se != null && se.ReturnOnDeactivate && !m_Mobile.Controlled )
{ {
if( se.Home == Point3D.Zero ) if( se.HomeLocation == Point3D.Zero )
{ {
if( !m_Mobile.Region.AcceptsSpawnsFrom( se.Region ) ) if( !m_Mobile.Region.AcceptsSpawnsFrom( se.Region ) )
{ {
Timer.DelayCall( TimeSpan.Zero, new TimerCallback( ReturnToHome ) ); Timer.DelayCall( TimeSpan.Zero, new TimerCallback( ReturnToHome ) );
} }
} }
else if( !m_Mobile.InRange( se.Home, se.Range ) ) else if( !m_Mobile.InRange( se.HomeLocation, se.HomeRange ) )
{ {
Timer.DelayCall( TimeSpan.Zero, new TimerCallback( ReturnToHome ) ); Timer.DelayCall( TimeSpan.Zero, new TimerCallback( ReturnToHome ) );
} }

View file

@ -4656,7 +4656,7 @@ namespace Server.Mobiles
} }
else else
{ {
SpawnEntry se = this.Spawner as SpawnEntry; ISpawner se = this.Spawner;
if ( se != null && se.UnlinkOnTaming ) if ( se != null && se.UnlinkOnTaming )
{ {
this.Spawner.Remove( this ); this.Spawner.Remove( this );

View file

@ -15,7 +15,7 @@ namespace Server.Regions
{ {
} }
public abstract object Spawn( SpawnEntry entry ); public abstract ISpawnable Spawn( SpawnEntry entry );
public abstract bool CanSpawn( params Type[] types ); public abstract bool CanSpawn( params Type[] types );
@ -110,19 +110,20 @@ namespace Server.Regions
{ {
} }
public override object Spawn( SpawnEntry entry ) public override ISpawnable Spawn( SpawnEntry entry )
{ {
BaseRegion region = entry.Region; BaseRegion region = entry.Region;
Map map = region.Map; Map map = region.Map;
Point3D loc = entry.RandomSpawnLocation( this.Height, this.Land, this.Water ); Point3D loc = entry.RandomSpawnLocation( this.Height, this.Land, this.Water );
if ( loc == Point3D.Zero ) if ( loc == Point3D.Zero )
return null; return null;
return Construct( entry, loc, map ); return Construct( entry, loc, map );
} }
protected abstract object Construct( SpawnEntry entry, Point3D loc, Map map ); protected abstract ISpawnable Construct( SpawnEntry entry, Point3D loc, Map map );
public override bool CanSpawn( params Type[] types ) public override bool CanSpawn( params Type[] types )
{ {
@ -174,15 +175,16 @@ namespace Server.Regions
mob.Delete(); mob.Delete();
} }
protected override object Construct( SpawnEntry entry, Point3D loc, Map map ) protected override ISpawnable Construct(SpawnEntry entry, Point3D loc, Map map)
{ {
Mobile mobile = CreateMobile(); Mobile mobile = CreateMobile();
BaseCreature creature = mobile as BaseCreature; BaseCreature creature = mobile as BaseCreature;
if ( creature != null ) if ( creature != null )
{ {
creature.Home = entry.Home; creature.Home = entry.HomeLocation;
creature.RangeHome = entry.Range; creature.RangeHome = entry.HomeRange;
} }
if ( entry.Direction != SpawnEntry.InvalidDirection ) if ( entry.Direction != SpawnEntry.InvalidDirection )
@ -237,7 +239,7 @@ namespace Server.Regions
item.Delete(); item.Delete();
} }
protected override object Construct( SpawnEntry entry, Point3D loc, Map map ) protected override ISpawnable Construct( SpawnEntry entry, Point3D loc, Map map )
{ {
Item item = CreateItem(); Item item = CreateItem();
@ -376,7 +378,7 @@ namespace Server.Regions
m_TotalWeight += elements[i].Weight; m_TotalWeight += elements[i].Weight;
} }
public override object Spawn( SpawnEntry entry ) public override ISpawnable Spawn(SpawnEntry entry)
{ {
int index = Utility.Random( m_TotalWeight ); int index = Utility.Random( m_TotalWeight );

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using Server; using Server;
using Server.Mobiles; using Server.Mobiles;
using Server.Commands; using Server.Commands;
@ -34,7 +35,7 @@ namespace Server.Regions
private int m_Range; private int m_Range;
private Direction m_Direction; private Direction m_Direction;
private SpawnDefinition m_Definition; private SpawnDefinition m_Definition;
private ArrayList m_SpawnedObjects; private List<ISpawnable> m_SpawnedObjects;
private int m_Max; private int m_Max;
private TimeSpan m_MinSpawnTime; private TimeSpan m_MinSpawnTime;
private TimeSpan m_MaxSpawnTime; private TimeSpan m_MaxSpawnTime;
@ -45,11 +46,11 @@ namespace Server.Regions
public int ID{ get{ return m_ID; } } public int ID{ get{ return m_ID; } }
public BaseRegion Region{ get{ return m_Region; } } public BaseRegion Region{ get{ return m_Region; } }
public Point3D Home{ get{ return m_Home; } } public Point3D HomeLocation{ get{ return m_Home; } }
public int Range{ get{ return m_Range; } } public int HomeRange{ get{ return m_Range; } }
public Direction Direction{ get{ return m_Direction; } } public Direction Direction{ get{ return m_Direction; } }
public SpawnDefinition Definition{ get{ return m_Definition; } } public SpawnDefinition Definition{ get{ return m_Definition; } }
public ArrayList SpawnedObjects{ get{ return m_SpawnedObjects; } } public List<ISpawnable> SpawnedObjects{ get{ return m_SpawnedObjects; } }
public int Max{ get{ return m_Max; } } public int Max{ get{ return m_Max; } }
public TimeSpan MinSpawnTime{ get{ return m_MinSpawnTime; } } public TimeSpan MinSpawnTime{ get{ return m_MinSpawnTime; } }
public TimeSpan MaxSpawnTime{ get{ return m_MaxSpawnTime; } } public TimeSpan MaxSpawnTime{ get{ return m_MaxSpawnTime; } }
@ -66,7 +67,7 @@ namespace Server.Regions
m_Range = range; m_Range = range;
m_Direction = direction; m_Direction = direction;
m_Definition = definition; m_Definition = definition;
m_SpawnedObjects = new ArrayList(); m_SpawnedObjects = new List<ISpawnable>();
m_Max = max; m_Max = max;
m_MinSpawnTime = minSpawnTime; m_MinSpawnTime = minSpawnTime;
m_MaxSpawnTime = maxSpawnTime; m_MaxSpawnTime = maxSpawnTime;
@ -103,30 +104,23 @@ namespace Server.Regions
private void Spawn() private void Spawn()
{ {
object spawn = m_Definition.Spawn( this ); ISpawnable spawn = m_Definition.Spawn(this);
if ( spawn != null ) if ( spawn != null )
Add( spawn ); Add( spawn );
} }
private void Add( object spawn ) private void Add( ISpawnable spawn )
{ {
m_SpawnedObjects.Add( spawn ); m_SpawnedObjects.Add( spawn );
if ( spawn is Mobile ) spawn.Spawner = this;
{
((Mobile)spawn).Spawner = this;
if ( spawn is BaseCreature ) if ( spawn is BaseCreature )
((BaseCreature)spawn).RemoveIfUntamed = this.RemoveIfUntamed; ((BaseCreature)spawn).RemoveIfUntamed = this.RemoveIfUntamed;
}
else
{
((Item)spawn).Spawner = this;
}
} }
void ISpawner.Remove( object spawn ) void ISpawner.Remove( ISpawnable spawn )
{ {
m_SpawnedObjects.Remove( spawn ); m_SpawnedObjects.Remove( spawn );
@ -181,23 +175,14 @@ namespace Server.Regions
private void InternalDeleteSpawnedObjects() private void InternalDeleteSpawnedObjects()
{ {
foreach ( object obj in m_SpawnedObjects ) foreach ( ISpawnable spawnable in m_SpawnedObjects )
{ {
if ( obj is Mobile ) spawnable.Spawner = null;
{
Mobile mob = (Mobile) obj;
mob.Spawner = null; bool uncontrolled = !(spawnable is BaseCreature) || !((BaseCreature)spawnable).Controlled;
if ( !(mob is BaseCreature) || !((BaseCreature)mob).Controlled )
mob.Delete();
}
else
{
Item item = (Item) obj;
item.Spawner = null; if( uncontrolled )
item.Delete(); spawnable.Delete();
}
} }
m_SpawnedObjects.Clear(); m_SpawnedObjects.Clear();
@ -235,13 +220,9 @@ namespace Server.Regions
for ( int i = 0; i < m_SpawnedObjects.Count; i++ ) for ( int i = 0; i < m_SpawnedObjects.Count; i++ )
{ {
object spawn = m_SpawnedObjects[i]; ISpawnable spawn = m_SpawnedObjects[i];
int serial; int serial = spawn.Serial;
if ( spawn is Mobile )
serial = ((Mobile)spawn).Serial;
else
serial = ((Item)spawn).Serial;
writer.Write( (int) serial ); writer.Write( (int) serial );
} }
@ -266,10 +247,10 @@ namespace Server.Regions
for ( int i = 0; i < count; i++ ) for ( int i = 0; i < count; i++ )
{ {
int serial = reader.ReadInt(); int serial = reader.ReadInt();
IEntity entity = World.FindEntity( serial ); ISpawnable spawnableEntity = World.FindEntity( serial ) as ISpawnable;
if ( entity != null ) if (spawnableEntity != null)
Add( entity ); Add(spawnableEntity);
} }
m_Running = reader.ReadBool(); m_Running = reader.ReadBool();
@ -291,7 +272,7 @@ namespace Server.Regions
CheckTimer(); CheckTimer();
} }
private static ArrayList m_RemoveList; private static List<IEntity> m_RemoveList;
public static void Remove( GenericReader reader, int version ) public static void Remove( GenericReader reader, int version )
{ {
@ -305,7 +286,7 @@ namespace Server.Regions
if ( entity != null ) if ( entity != null )
{ {
if ( m_RemoveList == null ) if ( m_RemoveList == null )
m_RemoveList = new ArrayList(); m_RemoveList = new List<IEntity>();
m_RemoveList.Add( entity ); m_RemoveList.Add( entity );
} }
@ -321,12 +302,9 @@ namespace Server.Regions
{ {
if ( m_RemoveList != null ) if ( m_RemoveList != null )
{ {
foreach ( object obj in m_RemoveList ) foreach ( IEntity ent in m_RemoveList )
{ {
if ( obj is Mobile ) ent.Delete();
((Mobile)obj).Delete();
else
((Item)obj).Delete();
} }
m_RemoveList = null; m_RemoveList = null;

View file

@ -95,4 +95,22 @@ namespace Server
void OnManaChanged( Mobile m ); void OnManaChanged( Mobile m );
void OnStatsQuery( Mobile beholder, Mobile beheld ); void OnStatsQuery( Mobile beholder, Mobile beheld );
} }
public interface ISpawner
{
bool UnlinkOnTaming { get; }
Point3D HomeLocation { get; }
int HomeRange { get; }
void Remove(ISpawnable spawn);
}
public interface ISpawnable : IEntity
{
void OnBeforeSpawn(Point3D location, Map map);
void MoveToWorld(Point3D location, Map map);
void OnAfterSpawn();
ISpawner Spawner { get; set; }
}
} }

View file

@ -559,7 +559,7 @@ namespace Server
Weight = 0x80 Weight = 0x80
} }
public class Item : IEntity, IHued, IComparable<Item>, ISerializable public class Item : IEntity, IHued, IComparable<Item>, ISerializable, ISpawnable
{ {
public static readonly List<Item> EmptyItems = new List<Item>(); public static readonly List<Item> EmptyItems = new List<Item>();
@ -3438,6 +3438,7 @@ namespace Server
return true; return true;
} }
//TODO: Move to CompactInfo.
private ISpawner m_Spawner; private ISpawner m_Spawner;
public ISpawner Spawner{ get{ return m_Spawner; } set{ m_Spawner = value; } } public ISpawner Spawner{ get{ return m_Spawner; } set{ m_Spawner = value; } }

View file

@ -108,8 +108,11 @@ namespace Server
public static Thread Thread { get { return m_Thread; } } public static Thread Thread { get { return m_Thread; } }
public static MultiTextWriter MultiConsoleOut { get { return m_MultiConOut; } } public static MultiTextWriter MultiConsoleOut { get { return m_MultiConOut; } }
public static readonly bool Is64Bit = (IntPtr.Size == 8); #if Framework_4_0
//TODO: Upon public release of .NET 4.0, use Environment.Is64BitOperatingSystem/Process public static readonly bool Is64Bit = Environment.Is64BitProcess;
#else
public static readonly bool Is64Bit = (IntPtr.Size == 8); //Returns the size for the current /process/
#endif
private static bool m_MultiProcessor; private static bool m_MultiProcessor;
private static int m_ProcessorCount; private static int m_ProcessorCount;
@ -482,7 +485,7 @@ namespace Server
ScriptCompiler.Invoke( "Initialize" ); ScriptCompiler.Invoke( "Initialize" );
MessagePump ms = m_MessagePump = new MessagePump(); MessagePump messagePump = new MessagePump();
timerThread.Start(); timerThread.Start();
@ -508,7 +511,7 @@ namespace Server
Item.ProcessDeltaQueue(); Item.ProcessDeltaQueue();
Timer.Slice(); Timer.Slice();
m_MessagePump.Slice(); messagePump.Slice();
NetState.FlushAll(); NetState.FlushAll();
NetState.ProcessDisposedQueue(); NetState.ProcessDisposedQueue();

View file

@ -500,7 +500,7 @@ namespace Server
/// <summary> /// <summary>
/// Base class representing players, npcs, and creatures. /// Base class representing players, npcs, and creatures.
/// </summary> /// </summary>
public class Mobile : IEntity, IHued, IComparable<Mobile>, ISerializable public class Mobile : IEntity, IHued, IComparable<Mobile>, ISerializable, ISpawnable
{ {
#region CompareTo(...) #region CompareTo(...)
public int CompareTo( IEntity other ) public int CompareTo( IEntity other )

View file

@ -99,17 +99,6 @@ namespace Server
ValoriaShips ValoriaShips
} }
public interface ISpawner
{
bool UnlinkOnTaming{ get; }
Point3D Home{ get; }
int Range{ get; }
void Remove( object spawn );
}
public class Region : IComparable public class Region : IComparable
{ {
private static List<Region> m_Regions = new List<Region>(); private static List<Region> m_Regions = new List<Region>();

View file

@ -412,7 +412,7 @@ namespace Server
{ {
string file = e.FileName; string file = e.FileName;
// Rediculous. FileName is null if the warning/error is internally generated in csc. // Ridiculous. FileName is null if the warning/error is internally generated in csc.
if ( string.IsNullOrEmpty( file ) ) { if ( string.IsNullOrEmpty( file ) ) {
Console.WriteLine( "ScriptCompiler: {0}: {1}", e.ErrorNumber, e.ErrorText ); Console.WriteLine( "ScriptCompiler: {0}: {1}", e.ErrorNumber, e.ErrorText );
continue; continue;