context: using Server.ContextMenus;
  using Server.Gumps;
  using Server.Items;
  using Server.Misc;
  using Server.Multis;
  using Server.Network;
  using Server.Prompts;
  using Server.Spells;
  using Server.Targeting;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  
  namespace Server.Mobiles
  {
      public class Steward : BaseCreature
      {
          private Dictionary<Mobile, DateTime> _Table;
  
          public override bool NoHouseRestrictions => true;
          public override bool ClickTitle => false;
          public override bool IsInvulnerable => true;
  
          private BaseHouse m_House;
          public Mobile Owner { get; set; }
          public string Keyword { get; set; }
  
          public BaseHouse House
          {
              get { return m_House; }
              set
              {
                  if (m_House != null)
                      m_House.PlayerVendors.Remove(this);
  
                  if (value != null)
                      value.PlayerVendors.Add(this);
  
                  m_House = value;
              }
          }
  
          [Constructable]
          public Steward(Mobile owner, BaseHouse house)
              : base(AIType.AI_Use_Default, FightMode.None, 1, 1, 0.2, 0.2)
          {
              InitStats(100, 100, 25);
  
              Hits = HitsMax;
              Blessed = true;
              Frozen = true;
  
              Owner = owner;
              House = house;
              Body = 0x190;
              Race = Race.Human;
              Name = "a Steward";
              Hue = 1828;
              Direction = Direction.South;
  
              Keyword = "";
              _Table = new Dictionary<Mobile, DateTime>();
  
              Container pack = new StewardBackpack(Owner, this);
              pack.Movable = false;
              AddItem(pack);
          }
  
          public bool IsOwner(Mobile m)
          {
              if (m.AccessLevel >= AccessLevel.GameMaster)
                  return true;
  
              return m == Owner;
          }
  
          public override bool CanBeDamaged()
          {
              return false;
          }
  
          public override bool CanBeRenamedBy(Mobile from)
          {
              return false;
          }
  
          public override bool AllowEquipFrom(Mobile from)
          {
              if (IsOwner(from))
                  return true;
  
              return base.AllowEquipFrom(from);
          }
  
          public override bool CheckNonlocalLift(Mobile from, Item item)
          {
              if (IsOwner(from))
                  return true;
  
              return base.CheckNonlocalLift(from, item);
          }
  
          public override bool CheckNonlocalDrop(Mobile from, Item item, Item target)
          {
              if (IsOwner(from))
                  return true;
  
              return false;
          }
  
          public override void OnAosSingleClick(Mobile from)
          {
          }
  
          public override void OnDoubleClick(Mobile from)
          {
              DisplayPaperdollTo(from);
          }
  
          public override bool OnDragDrop(Mobile from, Item dropped)
          {
              if (IsOwner(from) && Backpack != null)
              {
                  return AddToBackpack(dropped);
              }
  
              return false;
          }
  
          public override bool HandlesOnSpeech(Mobile from)
          {
              return from is PlayerMobile;
          }
  
          public override void OnSpeech(SpeechEventArgs e)
          {
              PlayerMobile m = e.Mobile as PlayerMobile;
  
              if (m == null || Keyword == "")
                  return;
  
              if (e.Speech.Contains(Keyword))
              {
                  if (Backpack == null || Backpack.Items.Count <= 0 || IsInCooldown(m))
                  {
                      return;
                  }
  
                  if (Backpack.Items.Count > 0 && m.AddToBackpack(Backpack.Items[Utility.Random(Backpack.Items.Count)]))
                  {
                      m.SendLocalizedMessage(1072223); // An item has been placed in your backpack.
                      _Table[m] = DateTime.UtcNow + TimeSpan.FromHours(24);
                  }
              }
          }
  
          public bool IsInCooldown(Mobile from)
          {
              if (_Table.ContainsKey(from))
              {
                  if (_Table[from] < DateTime.UtcNow)
                      _Table.Remove(from);
              }
  
              return _Table.ContainsKey(from);
          }
  
          public override void OnStatsQuery(Mobile from)
          {
              if (from.Map == Map && Utility.InUpdateRange(this, from) && from.CanSee(this))
              {
                  from.Send(new MobileStatusCompact(false, this));
  
                  if (Map != null)
                  {
                      ProcessDelta();
  
                      Packet p = null;
  
                      IPooledEnumerable eable = Map.GetClientsInRange(Location);
  
                      foreach (NetState state in eable)
                      {
                          state.Mobile.ProcessDelta();
  
                          if (p == null)
                              p = Packet.Acquire(new UpdateStatueAnimation(this, 1, 4, 0));
  
                          state.Send(p);
                      }
  
                      Packet.Release(p);
  
                      eable.Free();
                  }
              }
          }
  
          public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list)
          {
              base.GetContextMenuEntries(from, list);
  
              if (IsOwner(Owner))
              {
                  if (from.Alive && from.InRange(this, 4))
                      list.Add(new CustomizeBodyEntry(from, this));
  
                  if (from.Alive && from.InRange(this, 2))
                  {
                      list.Add(new RenameEntry(from, this));
                      list.Add(new SetKeywordEntry(from, this));
                      list.Add(new OpenBackpackEntry(from, this));
  
                      if (from.Race == Race || (from.Race == Race.Elf && Race == Race.Human || from.Race == Race.Human && Race == Race.Elf))
                      {
  
gt:                         list.Add(new SwitchClothesEntry(from, this));