context: using Server.Accounting;
  using Server.Commands;
  using Server.Gumps;
  using Server.Items;
  using Server.Network;
  using Server.Targeting;
  using System;
  using System.Collections;
  using System.Data;
  using System.IO;
  
  namespace Server.Mobiles
  {
      public class XmlSpawnerDefaults
      {
          public class DefaultEntry
          {
              public string AccountName;
              public string PlayerName;
              public TimeSpan MinDelay = TimeSpan.FromMinutes(5);
              public TimeSpan MaxDelay = TimeSpan.FromMinutes(10);
              public TimeSpan RefractMin = TimeSpan.FromMinutes(0);
              public TimeSpan RefractMax = TimeSpan.FromMinutes(0);
              public TimeSpan TODStart = TimeSpan.FromMinutes(0);
              public TimeSpan TODEnd = TimeSpan.FromMinutes(0);
              public TimeSpan Duration = TimeSpan.FromMinutes(0);
              public TimeSpan DespawnTime = TimeSpan.FromHours(0);
              public bool Group;
              public int Team;
              public int ProximitySound = 0x1F4;
              public string SpeechTrigger;
              public string SkillTrigger;
              public int SequentialSpawn = -1;
              public bool HomeRangeIsRelative = true;
              public int SpawnRange = 5;
              public int HomeRange = 5;
              public int ProximityRange = -1;
              public XmlSpawner.TODModeType TODMode = XmlSpawner.TODModeType.Realtime;
              public int KillReset = 1;
              public string SpawnerName = "Spawner";
              public bool AllowGhostTrig;
              public bool AllowNPCTrig;
              public bool SpawnOnTrigger;
              public bool SmartSpawning;
              public bool ExternalTriggering;
              public string TriggerOnCarried;
              public string NoTriggerOnCarried;
              public string ProximityMsg;
              public double TriggerProbability = 1;
              public string PlayerTriggerProp;
              public string TriggerObjectProp;
              public string DefsExt;
              public string[] NameList;
              public bool[] SelectionList;
              public int AddGumpX = 440;
              public int AddGumpY;
              public int SpawnerGumpX;
              public int SpawnerGumpY;
              public int FindGumpX;
              public int FindGumpY;
  
              // these are additional defaults that are not set by XmlAdd but can be used by other routines such as the custom properties gump to determine 
              // whether properties have been changed from spawner default values
              public bool Running = true;
  
              public bool AutoNumber;
              public int AutoNumberValue;
  
              public XmlAddCAGCategory CurrentCategory;
              public int CurrentCategoryPage;
              public int CategorySelectionIndex = -1;
  
              public XmlSpawner LastSpawner;
              public Map StartingMap;
              public Point3D StartingLoc;
              public bool ShowExtension;
  
              public bool IgnoreUpdate;
          }
          public static ArrayList DefaultEntryList;
  
          public static DefaultEntry GetDefaults(string account, string name)
          {
              // find the default entry corresponding to the account and username
              if (DefaultEntryList != null)
              {
                  for (int i = 0; i < DefaultEntryList.Count; i++)
                  {
                      DefaultEntry entry = (DefaultEntry)DefaultEntryList[i];
                      if (entry != null && string.Compare(entry.PlayerName, name, true) == 0 && string.Compare(entry.AccountName, account, true) == 0)
                      {
                          return entry;
                      }
                  }
              }
              // if not found then add one
              DefaultEntry newentry = new DefaultEntry
              {
                  PlayerName = name,
                  AccountName = account
              };
              if (DefaultEntryList == null)
                  DefaultEntryList = new ArrayList();
              DefaultEntryList.Add(newentry);
              return newentry;
          }
  
          public static void RestoreDefs(DefaultEntry defs)
          {
              if (defs == null) return;
              defs.MinDelay = TimeSpan.FromMinutes(5);
              defs.MaxDelay = TimeSpan.FromMinutes(10);
              defs.RefractMin = TimeSpan.FromMinutes(0);
              defs.RefractMax = TimeSpan.FromMinutes(0);
              defs.TODStart = TimeSpan.FromMinutes(0);
              defs.TODEnd = TimeSpan.FromMinutes(0);
              defs.Duration = TimeSpan.FromMinutes(0);
              defs.DespawnTime = TimeSpan.FromHours(0);
              defs.Group = false;
              defs.Team = 0;
              defs.ProximitySound = 0x1F4;
              defs.SpeechTrigger = null;
              defs.SkillTrigger = null;
              defs.SequentialSpawn = -1;
              defs.HomeRangeIsRelative = true;
              defs.SpawnRange = 5;
              defs.HomeRange = 5;
              defs.ProximityRange = -1;
              defs.TODMode = XmlSpawner.TODModeType.Realtime;
              defs.KillReset = 1;
              defs.SpawnerName = "Spawner";
              defs.AllowGhostTrig = false;
              defs.AllowNPCTrig = false;
              defs.SpawnOnTrigger = false;
              defs.SmartSpawning = false;
              defs.ExternalTriggering = false;
              defs.TriggerOnCarried = null;
              defs.NoTriggerOnCarried = null;
              defs.ProximityMsg = null;
              defs.TriggerProbability = 1;
              defs.PlayerTriggerProp = null;
              defs.TriggerObjectProp = null;
              defs.DefsExt = null;
              defs.AddGumpX = 440;
              defs.AddGumpY = 0;
              defs.SpawnerGumpX = 0;
              defs.SpawnerGumpY = 0;
              defs.FindGumpX = 0;
              defs.FindGumpY = 0;
              defs.AutoNumber = false;
              defs.AutoNumberValue = 0;
  
              if (defs.SelectionList != null) Array.Clear(defs.SelectionList, 0, defs.SelectionList.Length);
              if (defs.NameList != null) Array.Clear(defs.NameList, 0, defs.NameList.Length);
          }
      }
  
      public class XmlAddGump : Gump
      {
          private const int MaxEntries = 40;
          private const int MaxEntriesPerColumn = 20;
          private const string DefsDataSetName = "Defs";
          private const string DefsTablePointName = "Values";
          private const string DefsDir = "SpawnerDefs";
  
          private readonly Mobile m_From;
  
          public XmlSpawnerDefaults.DefaultEntry defs;
  
          private string NameListToString()
          {
              if (defs.NameList == null || defs.NameList.Length == 0)
                  return "0";
              System.Text.StringBuilder sb = new System.Text.StringBuilder();
              sb.AppendFormat("{0}", defs.NameList.Length);
              for (int i = 0; i < defs.NameList.Length; i++)
              {
                  sb.AppendFormat(":{0}", defs.NameList[i]);
              }
              return sb.ToString();
          }
  
          private string SelectionListToString()
          {
              if (defs.SelectionList == null || defs.SelectionList.Length == 0)
                  return "0";
              System.Text.StringBuilder sb = new System.Text.StringBuilder();
              sb.AppendFormat("{0}", defs.SelectionList.Length);
              for (int i = 0; i < defs.SelectionList.Length; i++)
              {
                  sb.AppendFormat(":{0}", (defs.SelectionList[i] ? 1 : 0));
              }
              return sb.ToString();
          }
  
          private static string[] StringToNameList(string namelist)
          {
              string[] newlist = new string[MaxEntries];
              string[] tmplist = namelist.Split(':');
              for (int i = 1; i < tmplist.Length; i++)
              {
                  if (i - 1 >= newlist.Length) break;
                  newlist[i - 1] = tmplist[i];
              }
              return newlist;
          }
  
          private static bool[] StringToSelectionList(string selectionlist)
          {
              bool[] newlist = new bool[MaxEntries];
              string[] tmplist = selectionlist.Split(':');
              for (int i = 1; i < tmplist.Length; i++)
              {
                  if (i - 1 >= newlist.Length) break;
                  if (tmplist[i] == "1")
                      newlist[i - 1] = true;
                  else
                      newlist[i - 1] = false;
              }
              return newlist;
          }
  
          private void DoSaveDefs(Mobile from, string filename)
          {
  
gt:             if (filename == null || filename.Length <= 0) return;