using System;
using System.Collections;
using Server;
using Server.Gumps;
using Server.Mobiles;
using Server.Targeting;
using Server.ContextMenus;
using Server.Regions;
using Server.Network;
using System.Collections.Generic;
using Server.Items;
using Server.Targets;

namespace Server.Items
{


	public class NecroTrainer : Item
	{


		public override string DefaultName
		{
            get { return "Necromancy Trainer [100GP]"; }
		}

		[Constructable]
		public NecroTrainer() : base( 0x1F1C )
		{
			Weight = 1.0;
            Movable = false;
		}

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

        public override void OnDoubleClick(Mobile m)
        {
            if (m.Skills.Necromancy.Base <= 19.9)
            {
                if (m.Mana >= 4)
                {
                    if (m.SkillsTotal >= m.SkillsCap)
                    {
                        int toGain = 1;

                        Skills skills = m.Skills;

                        for (int i = 0; i < skills.Length; ++i)
                        {
                            Skill toLower = skills[i];

                            if (toLower != m.Skills.Necromancy && toLower.Lock == SkillLock.Down && toLower.BaseFixedPoint >= toGain)
                            {
                                toLower.BaseFixedPoint -= toGain;
                                break;
                            }
                        }
                    }
                    if (m.SkillsTotal < m.SkillsCap)
                    {
                        if (m.Backpack.ConsumeTotal(typeof(Gold), 100))
                        {
                            if (m.Skills.Necromancy.Base < m.Skills.Necromancy.Cap)
                            {
                                m.Skills.Necromancy.BaseFixedPoint += 1;
                                m.Mana -= 4;
                            }
                            else
                            {
                                m.SendMessage("You have reached the skill cap for that skill");
                            }
                        }
                        else
                        m.SendMessage("You need 100gp in your pack to use this stone.");
                    }
                    else
                    {
                        m.SendMessage("you have reached your total skills cap. Set a skill to lower to continue using me");
                    }

                }
            }
            if (m.Skills.Necromancy.Base <= 39.9 && m.Skills.Necromancy.Base >= 20)
            {
                if (m.Mana >= 5)
                {
                    if (m.SkillsTotal >= m.SkillsCap)
                    {
                        int toGain = 1;

                        Skills skills = m.Skills;

                        for (int i = 0; i < skills.Length; ++i)
                        {
                            Skill toLower = skills[i];

                            if (toLower != m.Skills.Necromancy && toLower.Lock == SkillLock.Down && toLower.BaseFixedPoint >= toGain)
                            {
                                toLower.BaseFixedPoint -= toGain;
                                break;
                            }
                        }
                    }
                    if (m.SkillsTotal < m.SkillsCap)
                    {
                        if (m.Backpack.ConsumeTotal(typeof(Gold), 100))
                        {
                            if (m.Skills.Necromancy.Base < m.Skills.Necromancy.Cap)
                            {
                                m.Skills.Necromancy.BaseFixedPoint += 1;
                                m.Mana -= 5;
                            }
                            else
                            {
                                m.SendMessage("You have reached the skill cap for that skill");
                            }
                        }
                        else
                        m.SendMessage("You need 100gp in your pack to use this stone.");
                    }
                    else
                    {
                        m.SendMessage("you have reached your total skills cap. Set a skill to lower to continue using me");
                    }

                }
                else
                {
                    m.SendMessage("You need 5 mana to use this item at your skill level.");
                }
            }
            if (m.Skills.Necromancy.Base <= 59.9 && m.Skills.Necromancy.Base >= 40)
            {
                if (m.Mana >= 10)
                {
                    if (m.SkillsTotal >= m.SkillsCap)
                    {
                        int toGain = 1;

                        Skills skills = m.Skills;

                        for (int i = 0; i < skills.Length; ++i)
                        {
                            Skill toLower = skills[i];

                            if (toLower != m.Skills.Necromancy && toLower.Lock == SkillLock.Down && toLower.BaseFixedPoint >= toGain)
                            {
                                toLower.BaseFixedPoint -= toGain;
                                break;
                            }
                        }
                    }
                    if (m.SkillsTotal < m.SkillsCap)
                    {
                        if (m.Backpack.ConsumeTotal(typeof(Gold), 100))
                        {
                            if (m.Skills.Necromancy.Base < m.Skills.Necromancy.Cap)
                            {
                                m.Skills.Necromancy.BaseFixedPoint += 1;
                                m.Mana -= 10;
                            }
                            else
                            {
                                m.SendMessage("You have reached the skill cap for that skill");
                            }
                        }
                        else
                        m.SendMessage("You need 100gp in your pack to use this stone.");
                    }
                    else
                    {
                        m.SendMessage("you have reached your total skills cap. Set a skill to lower to continue using me");
                    }

                }
                else
                {
                    m.SendMessage("You need 10 mana to use this item at your skill level.");
                }
            }
            if (m.Skills.Necromancy.Base <= 79.9 && m.Skills.Necromancy.Base >= 60)
            {
                if (m.Mana >= 20)
                {
                    if (m.SkillsTotal >= m.SkillsCap)
                    {
                        int toGain = 1;

                        Skills skills = m.Skills;

                        for (int i = 0; i < skills.Length; ++i)
                        {
                            Skill toLower = skills[i];

                            if (toLower != m.Skills.Necromancy && toLower.Lock == SkillLock.Down && toLower.BaseFixedPoint >= toGain)
                            {
                                toLower.BaseFixedPoint -= toGain;
                                break;
                            }
                        }
                    }
                    if (m.SkillsTotal < m.SkillsCap)
                    {
                        if (m.Backpack.ConsumeTotal(typeof(Gold), 100))
                        {
                            if (m.Skills.Necromancy.Base < m.Skills.Necromancy.Cap)
                            {
                                m.Skills.Necromancy.BaseFixedPoint += 1;
                                m.Mana -= 20;
                            }
                            else
                            {
                                m.SendMessage("You have reached the skill cap for that skill");
                            }
                        }
                        else
                        m.SendMessage("You need 100gp in your pack to use this stone.");
                    }
                    else
                    {
                        m.SendMessage("you have reached your total skills cap. Set a skill to lower to continue using me");
                    }

                }
                else
                {
                    m.SendMessage("You need 20 mana to use this item at your skill level.");
                }
            }
            if (m.Skills.Necromancy.Base <= 99.9 && m.Skills.Necromancy.Base >= 80)
            {
                if (m.Mana >= 30)
                {
                    if (m.SkillsTotal >= m.SkillsCap)
                    {
                        int toGain = 1;

                        Skills skills = m.Skills;

                        for (int i = 0; i < skills.Length; ++i)
                        {
                            Skill toLower = skills[i];

                            if (toLower != m.Skills.Necromancy && toLower.Lock == SkillLock.Down && toLower.BaseFixedPoint >= toGain)
                            {
                                toLower.BaseFixedPoint -= toGain;
                                break;
                            }
                        }
                    }
                    if (m.SkillsTotal < m.SkillsCap)
                    {
                        if (m.Backpack.ConsumeTotal(typeof(Gold), 100))
                        {
                            if (m.Skills.Necromancy.Base < m.Skills.Necromancy.Cap)
                            {
                                m.Skills.Necromancy.BaseFixedPoint += 1;
                                m.Mana -= 30;
                            }
                            else
                            {
                                m.SendMessage("You have reached the skill cap for that skill");
                            }
                        }
                        else
                        m.SendMessage("You need 100gp in your pack to use this stone.");
                    }
                    else
                    {
                        m.SendMessage("You need 30 mana to use this item at your skill level.");
                    }

                }
                else
                {
                    m.SendMessage("You do not have enough mana to use this item");
                }
            }
            if (m.Skills.Necromancy.Base <= 119.9 && m.Skills.Necromancy.Base >= 100)
            {
                if (m.Mana >= 40)
                {
                    if (m.SkillsTotal >= m.SkillsCap)
                    {
                        int toGain = 1;

                        Skills skills = m.Skills;

                        for (int i = 0; i < skills.Length; ++i)
                        {
                            Skill toLower = skills[i];

                            if (toLower != m.Skills.Necromancy && toLower.Lock == SkillLock.Down && toLower.BaseFixedPoint >= toGain)
                            {
                                toLower.BaseFixedPoint -= toGain;
                                break;
                            }
                        }
                    }
                    if (m.SkillsTotal < m.SkillsCap)
                    {
                        if (m.Backpack.ConsumeTotal(typeof(Gold), 100))
                        {
                            if (m.Skills.Necromancy.Base < m.Skills.Necromancy.Cap)
                            {
                                m.Skills.Necromancy.BaseFixedPoint += 1;
                                m.Mana -= 40;
                            }
                            else
                            {
                                m.SendMessage("You have reached the skill cap for that skill");
                            }
                        }
                        else
                        m.SendMessage("You need 100gp in your pack to use this stone.");
                    }
                    else
                    {
                        m.SendMessage("you have reached your total skills cap. Set a skill to lower to continue using me");
                    }


                }
                else
                {
                    m.SendMessage("You need 40 mana to use this item at your skill level.");
                }
            }
        }

		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();
        }
    }
}