context: /*
  
  $Id: 
  
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  
  */
  
  using System;
  using System.Collections;
  using Server;
  using Server.Gumps;
  using Server.Items;
  using Server.Mobiles;
  using Server.Prompts;
  
  namespace Server.Items
  {
      public class PowerScrollBookGump : Gump
      {
          private PlayerMobile m_From;
          private PowerScrollBook m_Book;
          private ArrayList m_List;
  
          private int m_Page;
  
          private const int LabelColor = 0x7FFF;
  
          public Item Reconstruct(object obj)
          {
              Item item = null;
  
              if (obj is PowerScrollBookEntry)
                  item = ((PowerScrollBookEntry)obj).Reconstruct();
  
              return item;
          }
  
          public bool CheckFilter(object obj)
          {
              if (obj is PowerScrollBookEntry)
              {
                  PowerScrollBookEntry e = (PowerScrollBookEntry)obj;
  
                  return CheckFilter(e.Skill, e.SkillValue);
              }
  
              return false;
          }
  
          private static SkillName[] m_Skills_Miscellaneous = new SkillName[]
          {
              SkillName.Alchemy,
              SkillName.Blacksmith,
              SkillName.Fletching,
              SkillName.Bushido,
              SkillName.Carpentry,
              SkillName.Chivalry,
              SkillName.Cooking,
              SkillName.Fishing,
              SkillName.Focus,
              SkillName.Healing,
              SkillName.Herding,
              SkillName.Lockpicking,
              SkillName.Lumberjacking,
              SkillName.Magery,
              SkillName.Meditation,
              SkillName.Mining,
              SkillName.Musicianship,
              SkillName.Necromancy,
              SkillName.Ninjitsu,
              SkillName.RemoveTrap,
              SkillName.MagicResist,
              SkillName.Snooping,
              SkillName.Spellweaving,
              SkillName.Stealing,
              SkillName.Stealth,
              SkillName.Tailoring,
              SkillName.Tinkering,
              SkillName.Veterinary
          };
  
          private static SkillName[] m_Skills_CombatRatings = new SkillName[]
          {
              SkillName.Archery,
              SkillName.ArmsLore,
              SkillName.Fencing,
              SkillName.Lumberjacking,
              SkillName.Macing,
              SkillName.Parry,
              SkillName.Swords,
              SkillName.Tactics,
              SkillName.Wrestling
          };
  
          private static SkillName[] m_Skills_Actions = new SkillName[]
          {
              SkillName.AnimalTaming,
              SkillName.Begging,
              SkillName.Camping,
              SkillName.Cartography,
              SkillName.DetectHidden,
              SkillName.Discordance,
              SkillName.Hiding,
              SkillName.Inscribe,
              SkillName.Peacemaking,
              SkillName.Poisoning,
              SkillName.Provocation,
              SkillName.SpiritSpeak,
              SkillName.Tracking
          };
  
          private static SkillName[] m_Skills_LoreKnowledge = new SkillName[]
          {
              SkillName.Anatomy,
              SkillName.AnimalLore,
              SkillName.ArmsLore,
              SkillName.EvalInt,
              SkillName.Forensics,
              SkillName.ItemID,
              SkillName.TasteID
          };
  
          private static SkillName[] m_Skills_Magical = new SkillName[]
          {
              SkillName.Magery,
              SkillName.Chivalry,
              SkillName.Necromancy,
              SkillName.Spellweaving,
              SkillName.Bushido,
              SkillName.Ninjitsu
          };
  
          private static SkillName[] m_Skills_Crafting = new SkillName[]
          {
              SkillName.Alchemy,
              SkillName.Blacksmith,
              SkillName.Carpentry,
              SkillName.Cooking,
              SkillName.Fishing,
              SkillName.Fletching,
              SkillName.Inscribe,
              SkillName.Lumberjacking,
              SkillName.Mining,
              SkillName.Tailoring,
              SkillName.Tinkering
          };
  
          public bool CheckFilter(SkillName skill, int skillvalue)
          {
              PowerScrollFilter f = (m_Book.Filter);
  
              if (f.IsDefault)
                  return true;
  
              if (f.SkillValue != 0 && f.SkillValue != skillvalue)
                  return false;
  
              if (f.SkillCat != SkillCategory.None)
              {
                  if (f.SkillCat == SkillCategory.Miscellaneous)
                  {
                      for (int i = 0; i < m_Skills_Miscellaneous.Length; i++)
                          if (m_Skills_Miscellaneous[i] == skill)
                              return true;
                  }
                  else if (f.SkillCat == SkillCategory.CombatRatings)
                  {
                      for (int i = 0; i < m_Skills_CombatRatings.Length; i++)
                          if (m_Skills_CombatRatings[i] == skill)
                              return true;
                  }
                  else if (f.SkillCat == SkillCategory.Actions)
                  {
                      for (int i = 0; i < m_Skills_Actions.Length; i++)
                          if (m_Skills_Actions[i] == skill)
                              return true;
                  }
                  else if (f.SkillCat == SkillCategory.LoreKnowledge)
                  {
                      for (int i = 0; i < m_Skills_LoreKnowledge.Length; i++)
                          if (m_Skills_LoreKnowledge[i] == skill)
                              return true;
                  }
                  else if (f.SkillCat == SkillCategory.Magical)
                  {
                      for (int i = 0; i < m_Skills_Magical.Length; i++)
                          if (m_Skills_Magical[i] == skill)
                              return true;
                  }
                  else if (f.SkillCat == SkillCategory.CraftingHarvesting)
                  {
                      for (int i = 0; i < m_Skills_Crafting.Length; i++)
                          if (m_Skills_Crafting[i] == skill)
                              return true;
                  }
  
                  return false;
              }
              return true;
          }
  
          public int GetIndexForPage(int page)
          {
              int index = 0;
  
              while (page-- > 0)
                  index += GetCountForIndex(index);
  
              return index;
          }
  
          public int GetCountForIndex(int index)
          {
              int slots = 0;
              int count = 0;
  
              ArrayList list = m_List;
  
              for (int i = index; i >= 0 && i < list.Count; ++i)
              {
                  object obj = list[i];
  
                  if (CheckFilter(obj))
                  {
                      int add;
  
                      add = 1;
  
  
gt:                     if ((slots + add) > 10)