context: using System;
  using System.Collections;
  using System.Collections.Generic;
  using Server.Items;
  using Server.Engines.CannedEvil;
  
  namespace Server.Mobiles
  {
      public class Harrower : BaseCreature
      {
          private int m_StatCap = Config.Get("PlayerCaps.TotalStatCap", 225);
          private static readonly SpawnEntry[] m_Entries = new SpawnEntry[]
          {
              new SpawnEntry(new Point3D(5242, 945, -40), new Point3D(1176, 2638, 0)), // Destard
              new SpawnEntry(new Point3D(5225, 798, 0), new Point3D(1176, 2638, 0)), // Destard
              new SpawnEntry(new Point3D(5556, 886, 30), new Point3D(1298, 1080, 0)), // Despise
              new SpawnEntry(new Point3D(5187, 615, 0), new Point3D(4111, 432, 5)), // Deceit
              new SpawnEntry(new Point3D(5319, 583, 0), new Point3D(4111, 432, 5)), // Deceit
              new SpawnEntry(new Point3D(5713, 1334, -1), new Point3D(2923, 3407, 8)), // Fire
              new SpawnEntry(new Point3D(5860, 1460, -2), new Point3D(2923, 3407, 8)), // Fire
              new SpawnEntry(new Point3D(5328, 1620, 0), new Point3D(5451, 3143, -60)), // Terathan Keep
              new SpawnEntry(new Point3D(5690, 538, 0), new Point3D(2042, 224, 14)), // Wrong
              new SpawnEntry(new Point3D(5609, 195, 0), new Point3D(514, 1561, 0)), // Shame
              new SpawnEntry(new Point3D(5475, 187, 0), new Point3D(514, 1561, 0)), // Shame
              new SpawnEntry(new Point3D(6085, 179, 0), new Point3D(4721, 3822, 0)), // Hythloth
              new SpawnEntry(new Point3D(6084, 66, 0), new Point3D(4721, 3822, 0)), // Hythloth
              /*new SpawnEntry(new Point3D(5499, 2003, 0), new Point3D(2499, 919, 0)), // Covetous*/
              new SpawnEntry(new Point3D(5579, 1858, 0), new Point3D(2499, 919, 0))// Covetous
          };
          private static readonly ArrayList m_Instances = new ArrayList();
          private static readonly double[] m_Offsets = new double[]
          {
              Math.Cos(000.0 / 180.0 * Math.PI), Math.Sin(000.0 / 180.0 * Math.PI),
              Math.Cos(040.0 / 180.0 * Math.PI), Math.Sin(040.0 / 180.0 * Math.PI),
              Math.Cos(080.0 / 180.0 * Math.PI), Math.Sin(080.0 / 180.0 * Math.PI),
              Math.Cos(120.0 / 180.0 * Math.PI), Math.Sin(120.0 / 180.0 * Math.PI),
              Math.Cos(160.0 / 180.0 * Math.PI), Math.Sin(160.0 / 180.0 * Math.PI),
              Math.Cos(200.0 / 180.0 * Math.PI), Math.Sin(200.0 / 180.0 * Math.PI),
              Math.Cos(240.0 / 180.0 * Math.PI), Math.Sin(240.0 / 180.0 * Math.PI),
              Math.Cos(280.0 / 180.0 * Math.PI), Math.Sin(280.0 / 180.0 * Math.PI),
              Math.Cos(320.0 / 180.0 * Math.PI), Math.Sin(320.0 / 180.0 * Math.PI),
          };
          private bool m_TrueForm;
          private Item m_GateItem;
          private List<HarrowerTentacles> m_Tentacles;
  
          Dictionary<Mobile, int> m_DamageEntries;
          [Constructable]
          public Harrower()
              : base(AIType.AI_Mage, FightMode.Closest, 18, 1, 0.2, 0.4)
          {
              m_Instances.Add(this);
  
              this.Name = "the harrower";
              this.BodyValue = 146;
  
              this.SetStr(900, 1000);
              this.SetDex(125, 135);
              this.SetInt(1000, 1200);
  
              this.Fame = 22500;
              this.Karma = -22500;
  
              this.VirtualArmor = 60;
  
              this.SetDamageType(ResistanceType.Physical, 50);
              this.SetDamageType(ResistanceType.Energy, 50);
  
              this.SetResistance(ResistanceType.Physical, 55, 65);
              this.SetResistance(ResistanceType.Fire, 60, 80);
              this.SetResistance(ResistanceType.Cold, 60, 80);
              this.SetResistance(ResistanceType.Poison, 60, 80);
              this.SetResistance(ResistanceType.Energy, 60, 80);
  
              this.SetSkill(SkillName.Wrestling, 90.1, 100.0);
              this.SetSkill(SkillName.Tactics, 90.2, 110.0);
              this.SetSkill(SkillName.MagicResist, 120.2, 160.0);
              this.SetSkill(SkillName.Magery, 120.0);
              this.SetSkill(SkillName.EvalInt, 120.0);
              this.SetSkill(SkillName.Meditation, 120.0);
  
              this.m_Tentacles = new List<HarrowerTentacles>();
          }
  
          public Harrower(Serial serial)
              : base(serial)
          {
              m_Instances.Add(this);
          }
  
          public static ArrayList Instances
          {
              get
              {
                  return m_Instances;
              }
          }
          public static bool CanSpawn
          {
              get
              {
                  return (m_Instances.Count == 0);
              }
          }
          public Type[] UniqueList
          {
              get
              {
                  return new Type[] { typeof(AcidProofRobe) };
              }
          }
          public Type[] SharedList
          {
              get
              {
                  return new Type[] { typeof(TheRobeOfBritanniaAri) };
              }
          }
          public Type[] DecorativeList
          {
              get
              {
                  return new Type[] { typeof(EvilIdolSkull), typeof(SkullPole) };
              }
          }
          public override bool AutoDispel
          {
              get
              {
                  return true;
              }
          }
          public override bool Unprovokable
          {
              get
              {
                  return true;
              }
          }
          public override Poison PoisonImmune
          {
              get
              {
                  return Poison.Lethal;
              }
          }
          [CommandProperty(AccessLevel.GameMaster)]
          public override int HitsMax
          {
              get
              {
                  return this.m_TrueForm ? 65000 : 30000;
              }
          }
          [CommandProperty(AccessLevel.GameMaster)]
          public override int ManaMax
          {
              get
              {
                  return 5000;
              }
          }
          public override bool DisallowAllMoves
          {
              get
              {
                  return this.m_TrueForm;
              }
          }
  
          public override bool TeleportsTo { get { return true; } }
  
          public static Harrower Spawn(Point3D platLoc, Map platMap)
          {
              if (m_Instances.Count > 0)
                  return null;
  
              SpawnEntry entry = m_Entries[Utility.Random(m_Entries.Length)];
  
              Harrower harrower = new Harrower();
  
              harrower.MoveToWorld(entry.m_Location, Map.Felucca);
  
              harrower.m_GateItem = new HarrowerGate(harrower, platLoc, platMap, entry.m_Entrance, Map.Felucca);
  
              return harrower;
          }
  
          public override void GenerateLoot()
          {
              this.AddLoot(LootPack.SuperBoss, 2);
              this.AddLoot(LootPack.Meager);
          }
  
          public void Morph()
          {
              if (this.m_TrueForm)
                  return;
  
              this.m_TrueForm = true;
  
              this.Name = "the true harrower";
              this.BodyValue = 780;
              this.Hue = 0x497;
  
              this.Hits = this.HitsMax;
              this.Stam = this.StamMax;
              this.Mana = this.ManaMax;
  
              this.ProcessDelta();
  
              this.Say(1049499); // Behold my true form!
  
              Map map = this.Map;
  
              if (map != null)
              {
                  for (int i = 0; i < m_Offsets.Length; i += 2)
                  {
                      double rx = m_Offsets[i];
                      double ry = m_Offsets[i + 1];
  
                      int dist = 0;
                      bool ok = false;
                      int x = 0, y = 0, z = 0;
  
                      while (!ok && dist < 10)
                      {
                          int rdist = 10 + dist;
  
                          x = this.X + (int)(rx * rdist);
                          y = this.Y + (int)(ry * rdist);
                          z = map.GetAverageZ(x, y);
  
                          if (!(ok = map.CanFit(x, y, this.Z, 16, false, false)))
                              ok = map.CanFit(x, y, z, 16, false, false);
  
                          if (dist >= 0)
                              dist = -(dist + 1);
                          else
                              dist = -(dist - 1);
                      }
  
                      if (!ok)
                          continue;
  
                      HarrowerTentacles spawn = new HarrowerTentacles(this);
  
                      spawn.Team = this.Team;
  
                      spawn.MoveToWorld(new Point3D(x, y, z), map);
  
                      this.m_Tentacles.Add(spawn);
                  }
              }
          }
  
          public override void OnAfterDelete()
          {
              m_Instances.Remove(this);
  
              base.OnAfterDelete();
          }
  
          public override void Serialize(GenericWriter writer)
          {
              base.Serialize(writer);
  
              writer.Write((int)0); // version
  
              writer.Write(this.m_TrueForm);
              writer.Write(this.m_GateItem);
              writer.WriteMobileList<HarrowerTentacles>(this.m_Tentacles);
          }
  
          public override void Deserialize(GenericReader reader)
          {
              base.Deserialize(reader);
  
              int version = reader.ReadInt();
  
              switch ( version )
              {
                  case 0:
                      {
                          this.m_TrueForm = reader.ReadBool();
  
gt:                         this.m_GateItem = reader.ReadItem();