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

            int version = reader.ReadEncodedInt();

            m_Solution = new PuzzleChestSolution(reader);

            int length = reader.ReadEncodedInt();

            for (int i = 0; i < length; i++)
            {
                PuzzleChestCylinder cylinder = (PuzzleChestCylinder)reader.ReadInt();

                if (length == m_Hints.Length)
                {
                    m_Hints[i] = cylinder;
                }
            }
            if (length != m_Hints.Length)
            {
                InitHints();
            }

            int guesses = reader.ReadEncodedInt();

            for (int i = 0; i < guesses; i++)
            {
                Mobile m = reader.ReadMobile();
                PuzzleChestSolutionAndTime sol = new PuzzleChestSolutionAndTime(reader);

                m_Guesses[m] = sol;
            }
        }
 public PuzzleChestSolution(PuzzleChestSolution solution)
 {
     for (int i = 0; i < m_Cylinders.Length; i++)
     {
         m_Cylinders[i] = solution.m_Cylinders[i];
     }
 }
        public override bool CheckLocked(Mobile from)
        {
            if (Locked)
            {
                PuzzleChestSolution solution = GetLastGuess(from);
                if (solution != null)
                {
                    solution = new PuzzleChestSolution(solution);
                }
                else
                {
                    solution = new PuzzleChestSolution(PuzzleChestCylinder.None, PuzzleChestCylinder.None, PuzzleChestCylinder.None, PuzzleChestCylinder.None, PuzzleChestCylinder.None);
                }

                from.CloseGump(typeof(PuzzleGump));
                from.CloseGump(typeof(StatusGump));
                from.SendGump(new PuzzleGump(from, this, solution, 0));

                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void SubmitSolution(Mobile m, PuzzleChestSolution solution)
        {
            int correctCylinders, correctColors;

            if (solution.Matches(this.Solution, out correctCylinders, out correctColors))
            {
                LockPick(m);

                DisplayTo(m);
            }
            else
            {
                m_Guesses[m] = new PuzzleChestSolutionAndTime(DateTime.UtcNow, solution);

                m.SendGump(new StatusGump(correctCylinders, correctColors));

                DoDamage(m);
            }
        }
        public bool Matches(PuzzleChestSolution solution, out int cylinders, out int colors)
        {
            cylinders = 0;
            colors    = 0;

            bool[] matchesSrc = new bool[solution.m_Cylinders.Length];
            bool[] matchesDst = new bool[solution.m_Cylinders.Length];

            for (int i = 0; i < m_Cylinders.Length; i++)
            {
                if (m_Cylinders[i] == solution.m_Cylinders[i])
                {
                    cylinders++;

                    matchesSrc[i] = true;
                    matchesDst[i] = true;
                }
            }

            for (int i = 0; i < m_Cylinders.Length; i++)
            {
                if (!matchesSrc[i])
                {
                    for (int j = 0; j < solution.m_Cylinders.Length; j++)
                    {
                        if (m_Cylinders[i] == solution.m_Cylinders[j] && !matchesDst[j])
                        {
                            colors++;

                            matchesDst[j] = true;
                        }
                    }
                }
            }

            return(cylinders == m_Cylinders.Length);
        }
        protected override void GenerateTreasure()
        {
            DropItem(new Gold(600, 900));

            List <Item> gems = new List <Item>();

            for (int i = 0; i < 9; i++)
            {
                Item gem     = Loot.RandomGem();
                Type gemType = gem.GetType();

                foreach (Item listGem in gems)
                {
                    if (listGem.GetType() == gemType)
                    {
                        listGem.Amount++;
                        gem.Delete();
                        break;
                    }
                }

                if (!gem.Deleted)
                {
                    gems.Add(gem);
                }
            }

            foreach (Item gem in gems)
            {
                DropItem(gem);
            }

            if (0.2 > Utility.RandomDouble())
            {
                DropItem(new BagOfReagents(50));
            }

            for (int i = 0; i < 2; i++)
            {
                Item item;

                if (Core.AOS)
                {
                    item = Loot.RandomArmorOrShieldOrWeaponOrJewelry();
                }
                else
                {
                    item = Loot.RandomArmorOrShieldOrWeapon();
                }

                if (item is BaseWeapon)
                {
                    BaseWeapon weapon = (BaseWeapon)item;

                    if (Core.AOS)
                    {
                        int attributeCount;
                        int min, max;

                        GetRandomAOSStats(out attributeCount, out min, out max);

                        BaseRunicTool.ApplyAttributesTo(weapon, attributeCount, min, max);
                    }
                    else
                    {
                        weapon.DamageLevel     = (WeaponDamageLevel)Utility.Random(6);
                        weapon.AccuracyLevel   = (WeaponAccuracyLevel)Utility.Random(6);
                        weapon.DurabilityLevel = (WeaponDurabilityLevel)Utility.Random(6);
                    }

                    DropItem(item);
                }
                else if (item is BaseArmor)
                {
                    BaseArmor armor = (BaseArmor)item;

                    if (Core.AOS)
                    {
                        int attributeCount;
                        int min, max;

                        GetRandomAOSStats(out attributeCount, out min, out max);

                        BaseRunicTool.ApplyAttributesTo(armor, attributeCount, min, max);
                    }
                    else
                    {
                        armor.ProtectionLevel = (ArmorProtectionLevel)Utility.Random(6);
                        armor.Durability      = (ArmorDurabilityLevel)Utility.Random(6);
                    }

                    DropItem(item);
                }
                else if (item is BaseHat)
                {
                    BaseHat hat = (BaseHat)item;

                    if (Core.AOS)
                    {
                        int attributeCount;
                        int min, max;

                        GetRandomAOSStats(out attributeCount, out min, out max);

                        BaseRunicTool.ApplyAttributesTo(hat, attributeCount, min, max);
                    }

                    DropItem(item);
                }
                else if (item is BaseJewel)
                {
                    int attributeCount;
                    int min, max;

                    GetRandomAOSStats(out attributeCount, out min, out max);

                    BaseRunicTool.ApplyAttributesTo((BaseJewel)item, attributeCount, min, max);

                    DropItem(item);
                }
            }

            Solution = new PuzzleChestSolution();
        }
            public PuzzleGump(Mobile from, PuzzleChest chest, PuzzleChestSolution solution, int check) : base(50, 50)
            {
                m_From     = from;
                m_Chest    = chest;
                m_Solution = solution;

                Dragable = false;

                AddBackground(25, 0, 500, 410, 0x53);

                AddImage(62, 20, 0x67);

                AddHtmlLocalized(80, 36, 110, 70, 1018309, true, false); // A Puzzle Lock

                /* Correctly choose the sequence of cylinders needed to open the latch.  Each cylinder
                 * may potentially be used more than once.  Beware!  A false attempt could be deadly!
                 */
                AddHtmlLocalized(214, 26, 270, 90, 1018310, true, true);

                AddLeftCylinderButton(62, 130, PuzzleChestCylinder.LightBlue, 10);
                AddLeftCylinderButton(62, 180, PuzzleChestCylinder.Blue, 11);
                AddLeftCylinderButton(62, 230, PuzzleChestCylinder.Green, 12);
                AddLeftCylinderButton(62, 280, PuzzleChestCylinder.Orange, 13);

                AddRightCylinderButton(451, 130, PuzzleChestCylinder.Purple, 14);
                AddRightCylinderButton(451, 180, PuzzleChestCylinder.Red, 15);
                AddRightCylinderButton(451, 230, PuzzleChestCylinder.DarkBlue, 16);
                AddRightCylinderButton(451, 280, PuzzleChestCylinder.Yellow, 17);

                double lockpicking = from.Skills.Lockpicking.Base;

                if (lockpicking >= 60.0)
                {
                    AddHtmlLocalized(160, 125, 230, 24, 1018308, false, false); // Lockpicking hint:

                    AddBackground(159, 150, 230, 95, 0x13EC);

                    if (lockpicking >= 80.0)
                    {
                        AddHtmlLocalized(165, 157, 200, 40, 1018312, false, false); // In the first slot:
                        AddCylinder(350, 165, chest.Solution.First);

                        AddHtmlLocalized(165, 197, 200, 40, 1018313, false, false); // Used in unknown slot:
                        AddCylinder(350, 200, chest.FirstHint);

                        if (lockpicking >= 90.0)
                        {
                            AddCylinder(350, 212, chest.SecondHint);
                        }

                        if (lockpicking >= 100.0)
                        {
                            AddCylinder(350, 224, chest.ThirdHint);
                        }
                    }
                    else
                    {
                        AddHtmlLocalized(165, 157, 200, 40, 1018313, false, false); // Used in unknown slot:
                        AddCylinder(350, 160, chest.FirstHint);

                        if (lockpicking >= 70.0)
                        {
                            AddCylinder(350, 172, chest.SecondHint);
                        }
                    }
                }

                PuzzleChestSolution lastGuess = chest.GetLastGuess(from);

                if (lastGuess != null)
                {
                    AddHtmlLocalized(127, 249, 170, 20, 1018311, false, false); // Thy previous guess:

                    AddBackground(290, 247, 115, 25, 0x13EC);

                    AddCylinder(281, 254, lastGuess.First);
                    AddCylinder(303, 254, lastGuess.Second);
                    AddCylinder(325, 254, lastGuess.Third);
                    AddCylinder(347, 254, lastGuess.Fourth);
                    AddCylinder(369, 254, lastGuess.Fifth);
                }

                AddPedestal(140, 270, solution.First, 0, check == 0);
                AddPedestal(195, 270, solution.Second, 1, check == 1);
                AddPedestal(250, 270, solution.Third, 2, check == 2);
                AddPedestal(305, 270, solution.Fourth, 3, check == 3);
                AddPedestal(360, 270, solution.Fifth, 4, check == 4);

                AddButton(258, 370, 0xFA5, 0xFA7, 1, GumpButtonType.Reply, 0);
            }
 public PuzzleChestSolutionAndTime(DateTime when, PuzzleChestSolution solution) : base(solution)
 {
     m_When = when;
 }