context: using System;
  using Server;
  using Server.Items;
  using System.Collections.Generic;
  using Server.Engines.Quests;
  using System.Linq;
  
  namespace Server.Mobiles
  {
      [CorpseName("a tyrannosaurus rex corpse")]
      public class TRex : BaseCreature
      {
          private DateTime _NextFreeze;
  
          [Constructable]
          public TRex()
              : base(AIType.AI_Melee, FightMode.Weakest, 10, 1, .08, .17)
          {
              this.Name = "Tyrannosaurus Rex";
              this.Body = 1400;
              this.BaseSoundID = 362;
  
              this.SetStr(500, 700);
              this.SetDex(500, 700);
              this.SetInt(100, 180);
  
              this.SetHits(15000);
  
              this.SetDamage(33, 55);
  
              this.SetDamageType(ResistanceType.Physical, 100);
  
              this.SetResistance(ResistanceType.Physical, 80, 90);
              this.SetResistance(ResistanceType.Fire, 60, 80);
              this.SetResistance(ResistanceType.Cold, 60, 70);
              this.SetResistance(ResistanceType.Poison, 80, 100);
              this.SetResistance(ResistanceType.Energy, 60, 70);
  
              this.SetSkill(SkillName.Anatomy, 100.0);
              this.SetSkill(SkillName.MagicResist, 140.0, 150.0);
              this.SetSkill(SkillName.Tactics, 110.0, 130.0);
              this.SetSkill(SkillName.Wrestling, 130.0, 150.0);
              this.SetSkill(SkillName.Poisoning, 60.0, 70.0);
              this.SetSkill(SkillName.Parry, 100);
  
              this.Fame = 24000;
              this.Karma = -24000;
  
              _NextFreeze = DateTime.UtcNow;
  
              this.CanSwim = true;
          }
  
          public override bool AutoDispel { get { return true; } }
          public override Poison PoisonImmune { get { return Poison.Lethal; } }
          public override bool UseSmartAI { get { return true; } }
          public override bool ReacquireOnMovement { get { return true; } }
          public override bool AttacksFocus { get { return true; } }
  
          public override WeaponAbility GetWeaponAbility()
          {
              return WeaponAbility.ArmorIgnore;
          }
  
          // Missing Tail Swipe Ability
  
          public override void OnThink()
          {
              base.OnThink();
  
              if (Combatant == null)
                  return;
  
              if (_NextFreeze < DateTime.UtcNow)
                  DoFreeze();
          }
  
          public void DoFreeze()
          {
              DoEffects(Direction.North);
              DoEffects(Direction.West);
              DoEffects(Direction.South);
              DoEffects(Direction.East);
  
              _NextFreeze = DateTime.UtcNow + TimeSpan.FromSeconds(Utility.RandomMinMax(45, 60));
          }
  
          private bool DoEffects(Direction d)
          {
              int x = this.X;
              int y = this.Y;
              int z = this.Z;
              int range = 10;
              int offset = 8;
  
              switch (d)
              {
                  case Direction.North:
                      x = this.X + Utility.RandomMinMax(-offset, offset);
                      y = this.Y - range;
                      break;
                  case Direction.West:
                      x = this.X - range;
                      y = this.Y + Utility.RandomMinMax(-offset, offset);
                      break;
                  case Direction.South:
                      x = this.X + Utility.RandomMinMax(-offset, offset);
                      y = this.Y + range;
                      break;
                  case Direction.East:
                      x = this.X + range;
                      y = this.Y + Utility.RandomMinMax(-offset, offset);
                      break;
              }
  
              for (int i = 0; i < range; i++)
              {
                  switch (d)
                  {
                      case Direction.North: y += i; break;
                      case Direction.West: x += i; break;
                      case Direction.South: y -= i; break;
                      case Direction.East: x -= i; break;
                  }
  
                  z = this.Map.GetAverageZ(x, y);
                  Point3D p = new Point3D(x, y, z);
  
                  if (Server.Spells.SpellHelper.AdjustField(ref p, this.Map, 12, false))/*this.Map.CanFit(x, y, z, 16, false, false, true))/*this.Map.CanSpawnMobile(x, y, z)*/
                  {
                      MovementPath path = new MovementPath(this, p);
  
                      if (path.Success)
                      {
                          DropCrack(path);
                          return true;
                      }
                  }
              }
  
              return false;
          }
  
          private void DropCrack(MovementPath path)
          {
              int time = 10;
              int x = this.X;
              int y = this.Y;
  
              for (int i = 0; i < path.Directions.Length; ++i)
              {
                  Movement.Movement.Offset(path.Directions[i], ref x, ref y);
                  IPoint3D p = new Point3D(x, y, this.Map.GetAverageZ(x, y)) as IPoint3D;
  
                  Timer.DelayCall(TimeSpan.FromMilliseconds(time), new TimerStateCallback(ManaDrainEffects_Callback), new object[] { p, this.Map });
  
                  time += 200;
              }
          }
  
          private void ManaDrainEffects_Callback(object o)
          {
              object[] objs = o as object[];
              IPoint3D p = objs[0] as IPoint3D;
              Map map = objs[1] as Map;
  
              var item = new FreezeItem(Utility.RandomList(6913, 6915, 6917, 6919), this);
              Spells.SpellHelper.GetSurfaceTop(ref p);
  
              item.MoveToWorld(new Point3D(p), this.Map);
          }
  
          private class FreezeItem : Item
          {
              public Item Static { get; private set; }
              public BaseCreature Owner { get; private set; }
  
              public FreezeItem(int id, BaseCreature owner)
                  : base(id)
              {
                  Owner = owner;
  
                  Movable = false;
                  Hue = 1152;
                  Timer.DelayCall(TimeSpan.FromSeconds(5), ChangeHue);
              }
  
              private void ChangeHue()
              {
                  Hue = 1153;
                  Static.Hue = 1153;
  
                  Timer.DelayCall(TimeSpan.FromSeconds(0.5), Delete);
              }
  
              public override void Delete()
              {
                  if (Static != null)
                      Static.Delete();
  
                  Static = null;
                  base.Delete();
              }
  
              public override void OnLocationChange(Point3D oldLocation)
              {
                  Static = new Static(this.ItemID + 1);
                  Static.MoveToWorld(this.Location, this.Map);
  
                  IPooledEnumerable eable = this.Map.GetMobilesInRange(this.Location, 0);
  
                  foreach (Mobile m in eable)
                  {
                      OnMoveOver(m);
                  }
                  eable.Free();
              }
  
              public override bool OnMoveOver(Mobile m)
              {
                  if ((m is PlayerMobile || (m is BaseCreature && ((BaseCreature)m).GetMaster() is PlayerMobile)) && m.CanBeHarmful(Owner, false))
                  {
                      m.Freeze(TimeSpan.FromSeconds(Utility.RandomMinMax(5, 10)));
  
                      if (Owner.CanBeHarmful(m))
                      {
                          m.AggressiveAction(Owner);
                          Owner.InitialFocus = m;
                          Owner.Combatant = m;
                      }
                  }
  
                  return true;
              }
  
              public FreezeItem(Serial serial)
                  : base(serial)
              {
              }
  
              public override void Serialize(GenericWriter writer)
              {
                  base.Serialize(writer);
                  writer.Write(0);
              }
  
              public override void Deserialize(GenericReader reader)
              {
                  base.Deserialize(reader);
                  int version = reader.ReadInt();
  
                  Delete();
              }
          }
  
          public override void GenerateLoot()
          {
              AddLoot(LootPack.SuperBoss, 2);
          }
  
          public TRex(Serial serial)
              : base(serial)
          {
          }
  
          public override void Serialize(GenericWriter writer)
          {
              base.Serialize(writer);
  
              writer.Write((int)0); // version
          }
  
          public override void Deserialize(GenericReader reader)
          {
              base.Deserialize(reader);
  
  
gt:             int version = reader.ReadInt();