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( '=' );
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" ) )
{

View file

@ -448,7 +448,7 @@ namespace Server.Commands
int indexOf = m_Params[i].IndexOf( '=' );
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" ) )
{

View file

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

View file

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

View file

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

View file

@ -42,9 +42,9 @@ namespace Server.Mobiles
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 );
AddLabel( 382, ( 22 * i ) + 20, 0, count.ToString() );
@ -98,7 +98,7 @@ namespace Server.Mobiles
}
case 1: // Okay
{
m_Spawner.CreaturesName = CreateArray( info, state.Mobile );
m_Spawner.SpawnNames = CreateArray( info, state.Mobile );
break;
}
@ -127,9 +127,9 @@ namespace Server.Mobiles
if ( type == 0 ) // Spawn creature
m_Spawner.Spawn( entry.Text );
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;

View file

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

View file

@ -1548,10 +1548,10 @@ namespace Server.Mobiles
m_Mobile.IsBonded = false;
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.RangeHome = se.Range;
m_Mobile.Home = se.HomeLocation;
m_Mobile.RangeHome = se.HomeRange;
}
if( m_Mobile.DeleteOnRelease || m_Mobile.IsDeadPet )
@ -2618,14 +2618,14 @@ namespace Server.Mobiles
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 ) )
{
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 ) );
}

View file

@ -4656,7 +4656,7 @@ namespace Server.Mobiles
}
else
{
SpawnEntry se = this.Spawner as SpawnEntry;
ISpawner se = this.Spawner;
if ( se != null && se.UnlinkOnTaming )
{
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 );
@ -110,19 +110,20 @@ namespace Server.Regions
{
}
public override object Spawn( SpawnEntry entry )
public override ISpawnable Spawn( SpawnEntry entry )
{
BaseRegion region = entry.Region;
Map map = region.Map;
Point3D loc = entry.RandomSpawnLocation( this.Height, this.Land, this.Water );
if ( loc == Point3D.Zero )
return null;
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 )
{
@ -174,15 +175,16 @@ namespace Server.Regions
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();
BaseCreature creature = mobile as BaseCreature;
if ( creature != null )
{
creature.Home = entry.Home;
creature.RangeHome = entry.Range;
creature.Home = entry.HomeLocation;
creature.RangeHome = entry.HomeRange;
}
if ( entry.Direction != SpawnEntry.InvalidDirection )
@ -237,7 +239,7 @@ namespace Server.Regions
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();
@ -376,7 +378,7 @@ namespace Server.Regions
m_TotalWeight += elements[i].Weight;
}
public override object Spawn( SpawnEntry entry )
public override ISpawnable Spawn(SpawnEntry entry)
{
int index = Utility.Random( m_TotalWeight );

View file

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

View file

@ -95,4 +95,22 @@ namespace Server
void OnManaChanged( Mobile m );
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
}
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>();
@ -3438,6 +3438,7 @@ namespace Server
return true;
}
//TODO: Move to CompactInfo.
private ISpawner m_Spawner;
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 MultiTextWriter MultiConsoleOut { get { return m_MultiConOut; } }
public static readonly bool Is64Bit = (IntPtr.Size == 8);
//TODO: Upon public release of .NET 4.0, use Environment.Is64BitOperatingSystem/Process
#if Framework_4_0
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 int m_ProcessorCount;
@ -482,7 +485,7 @@ namespace Server
ScriptCompiler.Invoke( "Initialize" );
MessagePump ms = m_MessagePump = new MessagePump();
MessagePump messagePump = new MessagePump();
timerThread.Start();
@ -508,7 +511,7 @@ namespace Server
Item.ProcessDeltaQueue();
Timer.Slice();
m_MessagePump.Slice();
messagePump.Slice();
NetState.FlushAll();
NetState.ProcessDisposedQueue();

View file

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

View file

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

View file

@ -412,7 +412,7 @@ namespace Server
{
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 ) ) {
Console.WriteLine( "ScriptCompiler: {0}: {1}", e.ErrorNumber, e.ErrorText );
continue;