using System;
using Server;

namespace Server.Items
{
	[Furniture]
	public class SunkenShip : LootChest
	{
		[Constructable]
		public SunkenShip()
		{
			Weight = -2.0;
			Name = "shipwreck";
			ItemID = Utility.RandomList( 0x48F, 0x490 );
			Level = Utility.RandomMinMax(1,3);
			Category = Utility.RandomMinMax(1,3);
		}

		public override void Open( Mobile from )
		{
			Timer.DelayCall( TimeSpan.FromSeconds( 60.0 ), new TimerCallback( Delete ) );
			Weight = 5;
			base.Open( from );
		}

		public override void OnDelete()
		{
			Effects.PlaySound( Location, Map, 0x026 );

			int x = Location.X;
			int y = Location.Y;
			int z = Location.Z;

			Point3D p0 = new Point3D( x, y-1, z );
			Point3D p1 = new Point3D( x, y, z );
			Point3D p2 = new Point3D( x, y+1, z );
			Point3D p3 = new Point3D( x-1, y-1, z );
			Point3D p4 = new Point3D( x-1, y, z );
			Point3D p5 = new Point3D( x-1, y+1, z );
			Point3D p6 = new Point3D( x+1, y-1, z );
			Point3D p7 = new Point3D( x+1, y, z );
			Point3D p8 = new Point3D( x+1, y+1, z );

			Effects.SendLocationEffect( p0, Map, 0x352D, 16 );
			Effects.SendLocationEffect( p1, Map, 0x352D, 16 );
			Effects.SendLocationEffect( p2, Map, 0x352D, 16 );
			Effects.SendLocationEffect( p3, Map, 0x352D, 16 );
			Effects.SendLocationEffect( p4, Map, 0x352D, 16 );
			Effects.SendLocationEffect( p5, Map, 0x352D, 16 );
			Effects.SendLocationEffect( p6, Map, 0x352D, 16 );
			Effects.SendLocationEffect( p7, Map, 0x352D, 16 );
			Effects.SendLocationEffect( p8, Map, 0x352D, 16 );
		}

		public SunkenShip( 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 < 10 )
				Timer.DelayCall( TimeSpan.FromSeconds( 5.0 ), new TimerCallback( Delete ) );
		}
	}
}