using System;
using Server;
using Server.Items;
using Server.Mobiles;
using Server.Multis;
using Server.Multis.Deeds;

namespace Server.Items
{
    public class LootObject : Item
    {
        [Constructable]
        public LootObject() : base( 0xE76 )
        {
            Weight = 1.0;
            Name = "Loot";
            Movable = false;
        }

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

        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );
            writer.Write( (int) 0 );
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize( reader );
            int version = reader.ReadInt();
        }

        public override void OnDoubleClick( Mobile from )
        {
            if ( from.InRange( this, 2 ) && from.CanSee( this ) )
            {
                int i_item = 0;
                int i_get_flag = Utility.Random( 10 ); //Used to determine if any items spawn.
               
                int i_howmany_items = Utility.Random( 3 ) + 1; //Used to determine how many items will spawn from chest.
               
                if(i_get_flag > 0 )
                {
                    for (int i = 1; i <= i_howmany_items; i++)
                    {
                        i_item = Utility.Random ( 9900 );
                       
                       
			if(i_item > 5000 && i_item <= 9900)
                        {
                            //roll for tool
                            int type = Utility.Random( 16 ) + 1;
                            switch ( type )
                            {
                                case 1: from.AddToBackpack( new Skillet(  ) ); from.SendMessage( "You received a skillet." ); break;
                                case 2: from.AddToBackpack( new FletcherTools(  ) );  from.SendMessage( "You received fletching tools." ); break;
                                case 3: from.AddToBackpack( new Hatchet(  ) );  from.SendMessage( "You received a hatchet." ); break;
                                case 4: from.AddToBackpack( new Dagger(  ) ); from.SendMessage( "You received a dagger." ); break;
				case 5: from.AddToBackpack( new Scissors(  ) );  from.SendMessage( "You received a scissors." ); break;
				case 6: from.AddToBackpack( new Dyes(  ) );  from.SendMessage( "You received dyes." ); break;
				case 7: from.AddToBackpack( new DyeTub(  ) );  from.SendMessage( "You received a Dyetub." ); break;
				case 8: from.AddToBackpack( new BeverageBottle( BeverageType.Water ) );  from.SendMessage( "You received a bottle of water." ); break;
				case 9: from.AddToBackpack( new Pitcher(  ) );  from.SendMessage( "You received a Pitcher." ); break;
				case 10: from.AddToBackpack( new Bow(  ) );  from.SendMessage( "You received a bow." ); break;
				case 11: from.AddToBackpack( new Arrow( Utility.Random (20) ) );  from.SendMessage( "You received arrows." ); break;
				case 12: from.AddToBackpack( new Bolt( Utility.Random (20) ) );  from.SendMessage( "You received bolts." ); break;
				case 13: from.AddToBackpack( new Crossbow(  ) );  from.SendMessage( "You received a crossbow." ); break;
				case 14: from.AddToBackpack( new Tagebuch1(  ) );  from.SendMessage( "You received a book." ); break;
				case 15: from.AddToBackpack( new Pickaxe(  ) );  from.SendMessage( "You received a pickaxe." ); break;
				case 16: from.AddToBackpack( new VikingSword(  ) );  from.SendMessage( "You received a viking sword." ); break;
                            }
                           
                        }
                        else if(i_item > 2000 && i_item <= 5000)
                        {
                            //roll for food
                            int amount = Utility.Random( 2 ) + 1;
                            int type = Utility.Random( 6 ) + 1;
                            switch ( type )
                            {
                                case 1:
                                    from.AddToBackpack( new Apple ( amount ) );
                                    from.SendMessage( "You received " + amount.ToString() + " Apple(s)." );
                                    break;
                                case 2:
                                    from.AddToBackpack( new ApplePie ( ) );
                                    from.SendMessage( "You received a Apple Pie." );
                                    break;
                                case 3:
                                    from.AddToBackpack( new Ribs ( amount ) );
                                    from.SendMessage( "You received " + amount.ToString() + " Rib(s)." );
                                    break;
                                case 4:
                                    from.AddToBackpack( new FishSteak ( amount ) );
                                    from.SendMessage( "You received " + amount.ToString() + " Fish Steak(S)." );
                                    break;
                                case 5:
                                    from.AddToBackpack( new CheeseWheel ( ) );
                                    from.SendMessage( "You received a Cheese Wheel." );
                                    break;
                                case 6:
                                    from.AddToBackpack( new SlabOfBacon ( ) );
                                    from.SendMessage( "You received a slab of Bacon." );
                                    break;
                                case 7:
                                    from.AddToBackpack( new RoastPig ( ) );
                                    from.SendMessage( "You received a roasted Pig." );
                                    break;
                           
                            }
                        }

                        else if(i_item <= 2000)
                        {
                            //roll for gold
                            int amount = Utility.Random( 80 ) + 1;
                            from.AddToBackpack( new Gold ( amount ) );
                            from.SendMessage( "You received " + amount.ToString() + " gold." );
                        }                      
                    }
                }
                else
                {
                    from.SendMessage( "Sorry, nothing was in the bag." );
                }

                this.Delete(); //Delete the chest
            }
            else
            {
                from.SendLocalizedMessage( 500446 ); // That is too far away.
            }

        }
    }
}