RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

ISpawner Interface

LuxoR

Sorceror
ISpawner Interface

Implementation in BaseCreature methods do provide support for ISpawner interfaces, it defaults to SpawnEntry. This logic makes the ISpawner interface useless for custom spawners, even if implemented correctly. The following changes properly call Remove( object ), and implement UnlinkOnTaming checks to all ISpawner interfaces.

Code:
public bool SetControlMaster( Mobile m )
{
		....

		[COLOR="Red"]SpawnEntry se = this.Spawner as SpawnEntry;
		if ( se != null && se.UnlinkOnTaming )[/COLOR]
		{
			this.Spawner.Remove( this );
			this.Spawner = null;
		}

		....

Changed to ..

Code:
public bool SetControlMaster( Mobile m )
{
		....

		[COLOR="SeaGreen"]if ( Spawner != null && Spawner.UnlinkOnTaming )[/COLOR]
		{
			this.Spawner.Remove( this );
			this.Spawner = null;
		}

		....

It's also true for BaseCreature.OnRegionChange(), however support would require changes for ISpawner, and SpawnEntry. The issue is the highlighted portion, where ISpawner does not support Region, but SpawnEntry does.

Code:
public override void OnRegionChange( Region Old, Region New )
{
	base.OnRegionChange( Old, New );

	if ( this.Controlled )
	{
		ISpawner spawner = this.Spawner as ISpawner;

		if ( spawner != null && !spawner.UnlinkOnTaming && ( New == null || [COLOR="DeepSkyBlue"]!New.AcceptsSpawnsFrom( spawner.Region )[/COLOR] ) )
		{
			this.Spawner.Remove( this );
			this.Spawner = null;
		}
	}
}

Code:
public interface ISpawner
{
	bool UnlinkOnTaming{ get; }
	Point3D Home{ get; }
	int Range{ get; }
	[COLOR="DeepSkyBlue"]Region Region{ get; }[/COLOR]

	void Remove( object spawn );
}

The last change propagates other changes, cases where BaseRegion needs to be changed to Region. (SpawnEntry & SpawnDefinition)


4 Files are modified by the following patch diff:
BaseCreature.cs
Region.cs
SpawnEntry.cs
SpawnDefinition.cs

I'm not sure if the second set of changes to ISpawner is the right way to go, but there needs to be some way to use ISpawner instead of SpawnEntry.
 

Attachments

  • ISpawner.rar
    436 bytes · Views: 10
  • ISpawner.zip
    464 bytes · Views: 3

LuxoR

Sorceror
The second set of changes can be ignored by adding a secondary conditional statement. No changes to ISpawner, SpawnEntry, or SpawnDefinition need to be made. Only to BaseCreature.

The following would be the second change in BaseCreature.cs:
Code:
public override void OnRegionChange( Region Old, Region New )
{
	base.OnRegionChange( Old, New );

	if ( this.Controlled )
	{
		[COLOR="SeaGreen"]/*
		SpawnEntry se = this.Spawner as SpawnEntry;

		if ( se != null && !se.UnlinkOnTaming && ( New == null || !New.AcceptsSpawnsFrom( se.Region ) ) )
		{
			this.Spawner.Remove( this );
			this.Spawner = null;
		}
		*/[/COLOR]
		[COLOR="Red"]if ( Spawner != null && !Spawner.UnlinkOnTaming )
		{
			if ( Spawner is SpawnEntry && New != null && New.AcceptsSpawnsFrom( ((SpawnEntry)Spawner).Region ) )
				return;

			this.Spawner.Remove( this );
			this.Spawner = null;
		}[/COLOR]
	}
}


The original attachments have been updated, and the new patch file does not contain the commented code.
 
Top