context: using System;
  using Server.Items;
  using Server.Targeting;
  using System.Collections;
  using System.Collections.Generic;
  
  namespace Server.Mobiles
  {
      [CorpseName("the corpse of niporailem")]
      public class Niporailem : BaseSABosses
      {
          public override Type[] UniqueSAList { get { return new Type[] { }; } }
          public override Type[] SharedSAList { get { return new Type[] { typeof(BladeOfBattle), typeof(DemonBridleRing), typeof(GiantSteps), typeof(SwordOfShatteredHopes) }; } }
  
          [Constructable]
          public Niporailem()
              : base(AIType.AI_NecroMage, FightMode.Closest, 10, 1, 0.2, 0.4)
          {
              Name = "Niporailem";
              Title = "the Thief";
  
              Body = 722;
  
              SetStr(1000, 1200);
              SetDex(1200);
              SetInt(1200);
  
              SetHits(2654, 3988);
  
              SetDamage(15, 27);
  
              SetDamageType(ResistanceType.Physical, 40);
              SetDamageType(ResistanceType.Cold, 60);
  
              SetResistance(ResistanceType.Physical, 34, 46);
              SetResistance(ResistanceType.Fire, 0);
              SetResistance(ResistanceType.Cold, 31, 49);
              SetResistance(ResistanceType.Poison, 100);
              SetResistance(ResistanceType.Energy, 31, 49);
  
              SetSkill(SkillName.MagicResist, 87.7, 93.5);
              SetSkill(SkillName.Tactics, 56.1, 65.0);
              SetSkill(SkillName.Wrestling, 68.8, 76.2);
              SetSkill(SkillName.EvalInt, 120.0);
              SetSkill(SkillName.Magery, 120.0);
              SetSkill(SkillName.Meditation, 120.0);
              SetSkill(SkillName.Necromancy, 120.0);
              SetSkill(SkillName.SpiritSpeak, 120.0);
  
              PackNecroReg(12, 24); /// Stratics didn't specify
  
              Fame = 15000;
              Karma = -15000;
          }
  
          public override void GenerateLoot()
          {
              AddLoot(LootPack.FilthyRich, 6);
              AddLoot(LootPack.Gems, 6);
          }
  
          public override int Meat { get { return 1; } }
          public override bool AlwaysMurderer { get { return true; } }
  
          public override int GetIdleSound() { return 1609; }
          public override int GetAngerSound() { return 1606; }
          public override int GetHurtSound() { return 1608; }
          public override int GetDeathSound() { return 1607; }
          public override bool GivesSAArtifact { get { return true; } }
  
          public Niporailem(Serial serial)
              : base(serial)
          {
          }
  
          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();
          }
  
          public override void OnGotMeleeAttack(Mobile attacker)
          {
              base.OnGotMeleeAttack(attacker);
  
              if (this.Hits > (this.HitsMax / 4))
              {
                  if (0.25 >= Utility.RandomDouble())
                      SpawnSpectralArmour(attacker);
              }
              else if (0.10 >= Utility.RandomDouble())
              {
                  SpawnSpectralArmour(attacker);
              }
          }
  
          public void SpawnSpectralArmour(Mobile m)
          {
              Map map = this.Map;
  
              if (map == null)
                  return;
  
              SpectralArmour spawned = new SpectralArmour();
  
              spawned.Team = this.Team;
  
              bool validLocation = false;
              Point3D loc = this.Location;
  
              for (int j = 0; !validLocation && j < 10; ++j)
              {
                  int x = X + Utility.Random(3) - 1;
                  int y = Y + Utility.Random(3) - 1;
                  int z = map.GetAverageZ(x, y);
  
                  if (validLocation = map.CanFit(x, y, this.Z, 16, false, false))
                      loc = new Point3D(x, y, Z);
                  else if (validLocation = map.CanFit(x, y, z, 16, false, false))
                      loc = new Point3D(x, y, z);
              }
  
              spawned.MoveToWorld(loc, map);
              spawned.Combatant = m;
  
              foreach (Mobile anim in this.GetMobilesInRange(20))
              {
                  if (anim is SpectralArmour && (anim is BaseCreature))
                  {
                      ((BaseCreature)anim).SummonMaster = this;
                  }
              }
          }
  
          public void DeleteSpectralArmour(Mobile target)
          {
              ArrayList list = new ArrayList();
  
  
              foreach (Mobile m in this.GetMobilesInRange(30))
              {
  
                  if (m is SpectralArmour)
                      list.Add(m);
  
              }
  
              foreach (Mobile m in list)
              {
                  m.Delete();
              }
          }
  
  
          public void DeleteNipoTreasure()
          {
  
              ArrayList items = new ArrayList(World.Items.Values);
              ArrayList list = new ArrayList();
  
              foreach (Item item in items)
              {
                  if (item is NiporailemsTreasure || item is TreasureSand)
                      list.Add(item);
  
              }
  
              foreach (Item item in list)
                  item.Delete();
  
          }
  
          public override void OnAfterDelete()
          {
              DeleteSpectralArmour(this);
  
              DeleteNipoTreasure();
  
              base.OnAfterDelete();
          }
  
          public override bool OnBeforeDeath()
          {
              DeleteSpectralArmour(this);
  
              DeleteNipoTreasure();
  
              return base.OnBeforeDeath();
  
          }
  
          public override void OnDelete()
          {
              DeleteSpectralArmour(this);
  
              DeleteNipoTreasure();
  
              base.OnDelete();
          }
  
          private DateTime m_NextTreasure;
          private int m_Thrown;
  
          public override void OnActionCombat()
          {
              Mobile combatant = Combatant as Mobile;
  
              if (combatant == null || combatant.Deleted || combatant.Map != Map || !InRange(combatant, 20) || !CanBeHarmful(combatant) || !InLOS(combatant))
                  return;
  
  
gt:             if (DateTime.UtcNow >= m_NextTreasure)