context: // Created by Peoharen
  using System;
  using System.Collections.Generic;
  using Server.Engines.PartySystem;
  using Server.Guilds;
  using Server.Items;
  using Server.Spells;
  using Server.Spells.Necromancy;
  using Server.Spells.Ninjitsu;
  using Server.Spells.Sixth;
  using Server.Spells.Third;
  using Server.Targeting;
  
  namespace Server.Mobiles
  {
      public partial class OmniAI : BaseAI
      {
          private DateTime m_NextCastTime;
          private DateTime m_NextHealTime;
          private DateTime m_NextFieldCheck;
          private DateTime m_NextCheckArmed;
          private DateTime m_NextPetCommand;
  
          #region canuse
          public virtual bool m_IsSmart
          {
              get
              {
                  return false;
              }
          }
  
          public virtual bool m_CanUseBard
          {
              get
              {
                  return (this.m_Mobile.Skills[SkillName.Musicianship].Base > 10.0);
              }
          }
  
          public virtual bool m_CanUseBushido
          {
              get
              {
                  return (this.m_Mobile.Skills[SkillName.Bushido].Base > 10.0);
              }
          }
  
          public virtual bool m_CanUseChivalry
          {
              get
              {
                  return (this.m_Mobile.Skills[SkillName.Chivalry].Base > 10.0);
              }
          }
  
          public virtual bool m_CanUseMagery
          {
              get
              {
                  return (this.m_Mobile.Skills[SkillName.Magery].Base > 10.0);
              }
          }
  
          public virtual bool m_CanUseNecromancy
          {
              get
              {
                  return (this.m_Mobile.Skills[SkillName.Necromancy].Base > 10.0);
              }
          }
  
          public virtual bool m_CanUseNinjitsu
          {
              get
              {
                  return (this.m_Mobile.Skills[SkillName.Ninjitsu].Base > 10.0);
              }
          }
  
          public virtual bool m_CanUseSpellweaving
          {
              get
              {
                  return (this.m_Mobile.Skills[SkillName.Spellweaving].Base >= 10.0);
              }
          }
  
          public virtual bool m_CanUseMystic
          {
              get
              {
                  return (this.m_Mobile.Skills[SkillName.Mysticism].Base >= 10.0);
              }
          }
  
          public virtual bool m_SwapWeapons
          {
              get
              {
                  return this.m_CanUseBushido || this.m_CanUseNinjitsu;
              }
          }
  
          public virtual bool m_Melees
          {
              get
              {
                  if (this.m_ForceMelee)
                      return true;
                  else if (this.m_Mobile.Weapon is BaseRanged)
                      return false;
                  if (this.m_CanUseChivalry || this.m_CanUseBushido || this.m_CanUseNinjitsu)
                      return true;
                  else if (this.m_CanUseMagery || this.m_CanUseNecromancy)
                      return false;
                  else
                      return true;
              }
          }
          public virtual bool m_ForceMelee
          {
              get
              {
                  return false;
              }
          }
          #endregion
  
          public OmniAI(BaseCreature m)
              : base(m)
          {
          }
  
          #region getoutofmyway
          public override bool Think()
          {
              if (this.m_Mobile.Deleted)
                  return false;
  
              if (DateTime.UtcNow > this.m_NextFieldCheck)
              {
                  this.CheckForFieldSpells();
                  this.m_NextFieldCheck = DateTime.UtcNow + TimeSpan.FromSeconds(3);
              }
  
              if (DateTime.UtcNow > this.m_NextCheckArmed)
              {
                  this.CheckArmed(this.m_SwapWeapons);
                  this.m_NextCheckArmed = DateTime.UtcNow + TimeSpan.FromSeconds(12);
              }
  
              if (this.ProcessTarget())
                  return true;
              else
                  return base.Think();
          }
  
          public override bool DoActionWander()
          {
              if (this.m_Mobile.Debug)
                  this.m_Mobile.DebugSay("I have no combatant");
  
              if (!this.m_Mobile.Hidden && !this.m_Mobile.Poisoned && this.m_CanUseNinjitsu)
                  this.m_Mobile.UseSkill(SkillName.Hiding);
  
              if (this.AcquireFocusMob(this.m_Mobile.RangePerception, this.m_Mobile.FightMode, false, false, true))
              {
                  if (this.m_Mobile.Debug)
                      this.m_Mobile.DebugSay("I have detected {0}, attacking", this.m_Mobile.FocusMob.Name);
  
                  this.m_Mobile.Combatant = this.m_Mobile.FocusMob;
                  this.Action = ActionType.Combat;
              }
              else if (this.m_Mobile.Mana < this.m_Mobile.ManaMax && this.m_Mobile.Skills[SkillName.Meditation].Value > 60.0)
              {
                  if (this.m_Mobile.Debug)
                      this.m_Mobile.DebugSay("I am going to meditate");
  
                  this.m_Mobile.UseSkill(SkillName.Meditation);
              }
              else
              {
                  base.DoActionWander();
                  this.TryToHeal();
              }
  
              return true;
          }
  
          #endregion
  
          public override bool DoActionCombat()
          {
              Mobile combatant = this.m_Mobile.Combatant as Mobile;
  
              if (DateTime.UtcNow > this.m_NextPetCommand)
              {
                  BaseCreature bc = null;
  
                  foreach (Mobile m in this.m_Mobile.GetMobilesInRange(10))
                  {
                      if (m == null)
                          continue;
                      else if (m is BaseCreature)
                      {
                          bc = m as BaseCreature;
  
                          if (bc.ControlMaster == this.m_Mobile || bc.SummonMaster == this.m_Mobile)
                          {
                              bc.ControlTarget = combatant;
                              bc.ControlOrder = OrderType.Attack;
                          }
                      }
                  }
  
                  this.m_NextPetCommand = DateTime.UtcNow + TimeSpan.FromSeconds(10);
              }
  
              if (combatant == null || combatant.Deleted || combatant.Map != this.m_Mobile.Map || !combatant.Alive || combatant.IsDeadBondedPet)
              {
                  if (this.m_Mobile.Debug)
                      this.m_Mobile.DebugSay("My combatant is gone, so my guard is up");
  
                  this.Action = ActionType.Guard;
                  return true;
              }
  
              if (!this.m_Mobile.InRange(combatant, this.m_Mobile.RangePerception))
              {
                  // They are somewhat far away, can we find something else?
                  if (this.AcquireFocusMob(this.m_Mobile.RangePerception, this.m_Mobile.FightMode, false, false, true))
                  {
                      this.m_Mobile.Combatant = this.m_Mobile.FocusMob;
                      this.m_Mobile.FocusMob = null;
                  }
                  else if (!this.m_Mobile.InRange(combatant, this.m_Mobile.RangePerception * 3))
                  {
                      this.m_Mobile.Combatant = null;
                  }
  
                  combatant = this.m_Mobile.Combatant as Mobile;
  
                  if (combatant == null)
                  {
                      if (this.m_Mobile.Debug)
                          this.m_Mobile.DebugSay("My combatant has fled, so I am on guard");
  
                      this.Action = ActionType.Guard;
                      return true;
                  }
              }
  
  
gt:             if (this.MoveTo(combatant, true, this.m_Mobile.RangeFight))