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!

"Cannot change return type when overriding the inherited member"

Shadow-Sigma

Wanderer
"Cannot change return type when overriding the inherited member"

My scripts that seem to be related to the problem:

AppleTree.cs -

(This is the script I think the problem's in. This is a mod off of the SmallBedEast scripts, the highlighted part I haven't changed from the original script, don't know what to do with it.)
Code:
using System;
using Server;

namespace Server.Items
{
	public class AppleTree : BaseLeaves
	{
		public override BaseLeavesDeed Deed{ get{ return new AppleTreeDeed(); } }

		[Constructable]
		public AppleTree()
		{
			AddComponent( new AddonComponent( 0xd95 ), 0, 0, 0 );
			AddComponent( new AddonComponent( 0xd96 ), 0, 0, 0 );
		}

		public AppleTree( Serial serial ) : base( serial )
		{
		}

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.Write( (int) 0 ); // version
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );

			int version = reader.ReadInt();
		}
	}

	public class AppleTreeDeed : BaseLeavesDeed
	{
		public override BaseLeaves Addon{ get{ return new AppleTreeDeed(); } }
	[COLOR="Red"]	public override int LabelNumber{ get{ return 1044322; } } [/COLOR]

		[Constructable]
		public AppleTreeDeed()
		{
		}

		public AppleTreeDeed( Serial serial ) : base( serial )
		{
		}

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.Write( (int) 0 ); // version
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );

			int version = reader.ReadInt();
		}
	}
}

BaseLeavesDeed.cs -
Code:
using System;
using System.Collections;
using Server;
using Server.Targeting;

namespace Server.Items
{
	[Flipable( 0x14F0, 0x14EF )]
	public abstract class BaseLeavesDeed : Item
	{
		public abstract BaseLeaves Addon{ get; }

		public BaseLeavesDeed() : base( 0x14F0 )
		{
			Weight = 1.0;

			if ( !Core.AOS )
				LootType = LootType.Newbied;
		}

		public BaseLeavesDeed( Serial serial ) : base( serial )
		{
		}

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.Write( (int) 0 ); // version
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );

			int version = reader.ReadInt();

			if ( Weight == 0.0 )
				Weight = 1.0;
		}

		public override void OnDoubleClick( Mobile from )
		{
			if ( IsChildOf( from.Backpack ) )
				from.Target = new InternalTarget( this );
			else
				from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it.
		}

		private class InternalTarget : Target
		{
			private BaseLeavesDeed m_Deed;

			public InternalTarget( BaseLeavesDeed deed ) : base( -1, true, TargetFlags.None )
			{
				m_Deed = deed;

				CheckLOS = false;
			}

			protected override void OnTarget( Mobile from, object targeted )
			{
				IPoint3D p = targeted as IPoint3D;
				Map map = from.Map;

				if ( p == null || map == null || m_Deed.Deleted )
					return;

				if ( m_Deed.IsChildOf( from.Backpack ) )
				{
					BaseAddon addon = m_Deed.Addon;

					Server.Spells.SpellHelper.GetSurfaceTop( ref p );

					ArrayList houses = null;

					AddonFitResult res = addon.CouldFit( p, map, from, ref houses );

					if ( res == AddonFitResult.Valid )
						addon.MoveToWorld( new Point3D( p ), map );
					else if ( res == AddonFitResult.Blocked )
						from.SendLocalizedMessage( 500269 ); // You cannot build that there.
					else if ( res == AddonFitResult.NotInHouse )
						from.SendLocalizedMessage( 500274 ); // You can only place this in a house that you own!
					else if ( res == AddonFitResult.DoorsNotClosed )
						from.SendMessage( "You must close all house doors before placing this." );
					else if ( res == AddonFitResult.DoorTooClose )
						from.SendLocalizedMessage( 500271 ); // You cannot build near the door.
					else if ( res == AddonFitResult.NoWall )
						from.SendLocalizedMessage( 500268 ); // This object needs to be mounted on something.
					
					if ( res == AddonFitResult.Valid )
					{
						m_Deed.Delete();

						if ( houses != null )
						{
							foreach ( Server.Multis.BaseHouse h in houses )
								h.Addons.Add( addon );
						}
					}
					else
					{
						addon.Delete();
					}
				}
				else
				{
					from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it.
				}
			}
		}
	}
}

Error Report:
Code:
Scripts: Compiling C# scripts...failed (1 errors, 0 warnings)
 - Error: Scripts\Custom\Test Folder\AppleTree\AppleTree.cs: CS0508: (line 38, c
olumn 30) 'Server.Items.AppleTreeDeed.Addon': cannot change return type when overriding inherited member 'Server.Items.BaseLeavesDeed.Addon'
Scripts: One or more scripts failed to compile or no script files were found.
 - Press return to exit, or R to try again.
 

Phantom

Knight
public override BaseLeaves Addon{ get{ return new AppleTreeDeed(); } }

Your trying to return a different type, then you declared BaseLeaves, in another class.

Return the same type, and then it will compile.
 

Shadow-Sigma

Wanderer
Headache Incarnate

I've been working on this stupid thing for hours and I get the feeling that the more I work on this, the worse it's getting. Here are the scripts and error report, if anyone can make any sense of this, please help me out. It's just giving me a worse and worse headache. If I can just get past this part I can pick up and keep going and I'll know how to fix this from now on, I'm just having way too much trouble and I've spent way too much time trying to do something that's probably very simple...

I realize some of this is restricted to the house. As I mentioned before, it's a mod off of the smallbedeast addon. This script still has a long way to go, it's just stuck and I don't want to make it any more complex than it is at the moment...
AppleTree.cs
Code:
using System;
using Server;

namespace Server.Items
{
	public class AppleTree : BaseLeaves
	{
		public override BaseLeavesDeed Deed{ get{ return new AppleTreeDeed(); } }

		[Constructable]
		public AppleTree()
		{
			AddComponent( new AddonComponent( 0xd95 ), 0, 0, 0 );
			AddComponent( new AddonComponent( 0xd96 ), 0, 0, 0 );
		}

		public AppleTree( Serial serial ) : base( serial )
		{
		}

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.Write( (int) 0 ); // version
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );

			int version = reader.ReadInt();
		}
	}

	public class AppleTreeDeed : BaseLeavesDeed
	{
		public override BaseLeaves Addon{ get{ return new BaseLeaves(); } }
		public override int LabelNumber{ get{ return 1044322; } } // AppleTree

		[Constructable]
		public AppleTreeDeed()
		{
		}

		public AppleTreeDeed( Serial serial ) : base( serial )
		{
		}

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.Write( (int) 0 ); // version
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );

			int version = reader.ReadInt();
		}
	}
}

BaseLeaves.cs
Code:
using System;
using System.Collections;
using Server;
using Server.Multis;
using Server.Regions;

namespace Server.Items
{
	public enum AppleTreeFitResult
	{
		Valid,
		Blocked,
		NotInHouse,
		DoorsNotClosed,
		DoorTooClose,
		NoWall
	}

	public interface IAppleTree
	{
		Item Deed{ get; }

		bool CouldFit( IPoint3D p, Map map );
	}

	public abstract class BaseLeaves : Item, IChopable, IAppleTree
	{
		private ArrayList m_Components;

		public void AddComponent( AddonComponent c, int x, int y, int z )
		{
			if ( Deleted )
				return;

			m_Components.Add( c );

			c.Addon = this;
			c.Offset = new Point3D( x, y, z );
			c.MoveToWorld( new Point3D( X + x, Y + y, Z + z ), Map );
		}

		public BaseLeaves() : base( 1 )
		{
			Movable = false;
			Visible = false;

			m_Components = new ArrayList();
		}

		public virtual bool RetainDeedHue{ get{ return false; } }

		public void OnChop( Mobile from )
		{
			BaseHouse house = BaseHouse.FindHouseAt( this );

			if ( house != null && house.IsOwner( from ) && house.Addons.Contains( this ) )
			{
				Effects.PlaySound( GetWorldLocation(), Map, 0x3B3 );
				from.SendLocalizedMessage( 500461 ); // You destroy the item.

				int hue = 0;

				if ( RetainDeedHue )
				{
					for ( int i = 0; hue == 0 && i < m_Components.Count; ++i )
					{
						AddonComponent c = (AddonComponent)m_Components[i];

						if ( c.Hue != 0 )
							hue = c.Hue;
					}
				}

				Delete();

				house.Addons.Remove( this );

				BaseLeavesDeed deed = Deed;

				if ( deed != null )
				{
					if ( RetainDeedHue )
						deed.Hue = hue;

					from.AddToBackpack( deed );
				}
			}
		}

		public virtual BaseLeavesDeed Deed{ get{ return null; } }

		Item IAppleTree.Deed
		{
			get{ return this.Deed; }
		}

		public ArrayList Components
		{
			get
			{
				return m_Components;
			}
		}

		public BaseLeaves( Serial serial ) : base( serial )
		{
		}

		public bool CouldFit( IPoint3D p, Map map )
		{
			ArrayList houses = null;

			return ( CouldFit( p, map, null, ref houses ) == AddonFitResult.Valid );
		}

		public AddonFitResult CouldFit( IPoint3D p, Map map, Mobile from, ref ArrayList houseList )
		{
			if ( Deleted )
				return AddonFitResult.Blocked;

			ArrayList houses = new ArrayList();

			foreach ( AddonComponent c in m_Components )
			{
				Point3D p3D = new Point3D( p.X + c.Offset.X, p.Y + c.Offset.Y, p.Z + c.Offset.Z );

				if ( !map.CanFit( p3D.X, p3D.Y, p3D.Z, c.ItemData.Height, false, true, ( c.Z == 0 ) ) )
					return AddonFitResult.Blocked;
				else if ( !CheckHouse( from, p3D, map, c.ItemData.Height, houses ) )
					return AddonFitResult.NotInHouse;

				if ( c.NeedsWall )
				{
					Point3D wall = c.WallPosition;

					if ( !IsWall( p3D.X + wall.X, p3D.Y + wall.Y, p3D.Z + wall.Z, map ) )
						return AddonFitResult.NoWall;
				}
			}

			foreach ( BaseHouse house in houses )
			{
				ArrayList doors = house.Doors;

				for ( int i = 0; i < doors.Count; ++i )
				{
					BaseDoor door = doors[i] as BaseDoor;

					if ( door != null && door.Open )
						return AddonFitResult.DoorsNotClosed;

					Point3D doorLoc = door.GetWorldLocation();
					int doorHeight = door.ItemData.CalcHeight;

					foreach ( AddonComponent c in m_Components )
					{
						Point3D addonLoc = new Point3D( p.X + c.Offset.X, p.Y + c.Offset.Y, p.Z + c.Offset.Z );
						int addonHeight = c.ItemData.CalcHeight;

						if ( Utility.InRange( doorLoc, addonLoc, 1 ) && (addonLoc.Z == doorLoc.Z || ((addonLoc.Z + addonHeight) > doorLoc.Z && (doorLoc.Z + doorHeight) > addonLoc.Z)) )
							return AddonFitResult.DoorTooClose;
					}
				}
			}

			houseList = houses;
			return AddonFitResult.Valid;
		}

		public bool CheckHouse( Mobile from, Point3D p, Map map, int height, ArrayList list )
		{
			if ( from == null || from.AccessLevel >= AccessLevel.GameMaster )
				return true;

			BaseHouse house = BaseHouse.FindHouseAt( p, map, height );

			if ( house == null || !house.IsOwner( from ) )
				return false;

			if ( !list.Contains( house ) )
				list.Add( house );

			return true;
		}

		public static bool IsWall( int x, int y, int z, Map map )
		{
			if ( map == null )
				return false;

			Tile[] tiles = map.Tiles.GetStaticTiles( x, y, true );

			for ( int i = 0; i < tiles.Length; ++i )
			{
				Tile t = tiles[i];
				ItemData id = TileData.ItemTable[t.ID & 0x3FFF];

				if ( (id.Flags & TileFlag.Wall) != 0 && (z + 16) > t.Z && (t.Z + t.Height) > z )
					return true;
			}

			return false;
		}

		public virtual void OnComponentLoaded( AddonComponent c )
		{
		}

		public override void OnLocationChange( Point3D oldLoc )
		{
			if ( Deleted )
				return;

			foreach ( AddonComponent c in m_Components )
				c.Location = new Point3D( X + c.Offset.X, Y + c.Offset.Y, Z + c.Offset.Z );
		}

		public override void OnMapChange()
		{
			if ( Deleted )
				return;

			foreach ( AddonComponent c in m_Components )
				c.Map = Map;
		}

		public override void OnAfterDelete()
		{
			base.OnAfterDelete();

			foreach ( AddonComponent c in m_Components )
				c.Delete();
		}

		public virtual bool ShareHue{ get{ return true; } }

		[Hue, CommandProperty( AccessLevel.GameMaster )]
		public override int Hue
		{
			get
			{
				return base.Hue;
			}
			set
			{
				if ( base.Hue != value )
				{
					base.Hue = value;

					if ( !Deleted && this.ShareHue && m_Components != null )
					{
						foreach ( AddonComponent c in m_Components )
							c.Hue = value;
					}
				}
			}
		}

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.Write( (int) 0 ); // version

			writer.WriteItemList( m_Components );
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );

			int version = reader.ReadInt();

			switch ( version )
			{
				case 0:
				{
					m_Components = reader.ReadItemList();
					break;
				}
			}
		}
	}
}

BaseLeavesDeed.cs
Code:
using System;
using System.Collections;
using Server;
using Server.Targeting;

namespace Server.Items
{
	[Flipable( 0x14F0, 0x14EF )]
	public abstract class BaseLeavesDeed : Item
	{
		public abstract BaseLeaves Addon{ get; }

		public BaseLeavesDeed() : base( 0x14F0 )
		{
			Weight = 1.0;

			if ( !Core.AOS )
				LootType = LootType.Newbied;
		}

		public BaseLeavesDeed( Serial serial ) : base( serial )
		{
		}

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.Write( (int) 0 ); // version
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );

			int version = reader.ReadInt();

			if ( Weight == 0.0 )
				Weight = 1.0;
		}

		public override void OnDoubleClick( Mobile from )
		{
			if ( IsChildOf( from.Backpack ) )
				from.Target = new InternalTarget( this );
			else
				from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it.
		}

		private class InternalTarget : Target
		{
			private BaseLeavesDeed m_Deed;

			public InternalTarget( AppleTree deed ) : base( -1, true, TargetFlags.None )
			{
				m_Deed = deed;

				CheckLOS = false;
			}

			protected override void OnTarget( Mobile from, object targeted )
			{
				IPoint3D p = targeted as IPoint3D;
				Map map = from.Map;

				if ( p == null || map == null || m_Deed.Deleted )
					return;

				if ( m_Deed.IsChildOf( from.Backpack ) )
				{
					AppleTree addon = m_Deed.Addon;

					Server.Spells.SpellHelper.GetSurfaceTop( ref p );

					ArrayList houses = null;

					AppleTreeFitResult res = addon.CouldFit( p, map, from, ref houses );

					if ( res == AppleTreeFitResult.Valid )
						addon.MoveToWorld( new Point3D( p ), map );
					else if ( res == AppleTreeFitResult.Blocked )
						from.SendLocalizedMessage( 500269 ); // You cannot build that there.
					else if ( res == AppleTreeFitResult.NotInHouse )
						from.SendLocalizedMessage( 500274 ); // You can only place this in a house that you own!
					else if ( res == AppleTreeFitResult.DoorsNotClosed )
						from.SendMessage( "You must close all house doors before placing this." );
					else if ( res == AppleTreeFitResult.DoorTooClose )
						from.SendLocalizedMessage( 500271 ); // You cannot build near the door.
					else if ( res == AppleTreeFitResult.NoWall )
						from.SendLocalizedMessage( 500268 ); // This object needs to be mounted on something.
					
					if ( res == AppleTreeFitResult.Valid )
					{
						m_Deed.Delete();

						if ( houses != null )
						{
							foreach ( Server.Multis.BaseHouse h in houses )
								h.Addons.Add( addon );
						}
					}
					else
					{
						addon.Delete();
					}
				}
				else
				{
					from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it.
				}
			}
		}
	}
}

Error Report
Code:
 - Error: Scripts\Custom\Test Folder\AppleTree\BaseLeavesDeed.cs: CS1502: (line
45, column 19) The best overloaded method match for 'Server.Items.BaseLeavesDeed
.InternalTarget.InternalTarget(Server.Items.AppleTree)' has some invalid argumen
ts
 - Error: Scripts\Custom\Test Folder\AppleTree\BaseLeavesDeed.cs: CS1503: (line
45, column 39) Argument '1': cannot convert from 'Server.Items.BaseLeavesDeed' t
o 'Server.Items.AppleTree'
 - Error: Scripts\Custom\Test Folder\AppleTree\BaseLeavesDeed.cs: CS0029: (line
56, column 14) Cannot implicitly convert type 'Server.Items.AppleTree' to 'Serve
r.Items.BaseLeavesDeed'
 - Error: Scripts\Custom\Test Folder\AppleTree\BaseLeavesDeed.cs: CS0029: (line
71, column 24) Cannot implicitly convert type 'Server.Items.BaseLeaves' to 'Serv
er.Items.AppleTree'
 - Error: Scripts\Custom\Test Folder\AppleTree\BaseLeavesDeed.cs: CS0029: (line
77, column 31) Cannot implicitly convert type 'Server.Items.AddonFitResult' to '
Server.Items.AppleTreeFitResult'
 - Error: Scripts\Custom\Test Folder\AppleTree\BaseLeaves.cs: CS0029: (line 37,
column 14) Cannot implicitly convert type 'Server.Items.BaseLeaves' to 'Server.I
tems.BaseAddon'
 - Error: Scripts\Custom\Test Folder\AppleTree\AppleTree.cs: CS0144: (line 38, c
olumn 49) Cannot create an instance of the abstract class or interface 'Server.I
tems.BaseLeaves'
Scripts: One or more scripts failed to compile or no script files were found.
 - Press return to exit, or R to try again.

:(
 

Phantom

Knight
Code:
 Error: Scripts\Custom\Test Folder\AppleTree\BaseLeaves.cs: CS0029: (line 37,
column 14) Cannot implicitly convert type 'Server.Items.BaseLeaves' to 'Server.I
tems.BaseAddon'

You cannot assign a BaseLeaves reference to a BaseAddon unless you cast to it. You also didn't fix what I pointed out, till you at least fix that error, I cannot help you.
 

Shadow-Sigma

Wanderer
The best I can tell is that these are the codes that have to match:

Code:
	public class AppleTreeDeed : BaseLeavesDeed
	{
		public override BaseLeaves Addon{ get{ return new [color="Red"]BaseLeaves[/color](); } }
		public override int LabelNumber{ get{ return 1044322; } } // AppleTree
-and-
Code:
	[Flipable( 0x14F0, 0x14EF )]
	public abstract class BaseLeavesDeed : Item
	{
		public abstract [color="Red"]BaseLeaves[/color] Addon{ get; }

		public BaseLeavesDeed() : base( 0x14F0 )

I've tried everything I can think of (including, but not limited to, BaseLeavesDeed, BaseLeaves, AppleTree, AppleTreeDeed, BaseDeed, and AppleTreeBase), and I've searched through these scripts to try and figure out exactly what to do. I haven't stopped digging since your first post on this, it's not like I'm being lazy. Every time I find out how to fix something I never make that same mistake again, never have and never will. However, I just can't get this one. I have also toyed around with this part of the script to try and get it to work, with no better results:

Code:
		private class InternalTarget : Target
		{
			private BaseLeavesDeed m_Deed;

			public InternalTarget( [color="Red"]AppleTree[/color] deed ) : base( -1, true, TargetFlags.None )
			{
 
Top