Exemplo n.º 1
0
            protected override void OnTick()
            {
                if (m_Owner.Deleted)
                {
                    Stop();
                    return;
                }

                m_Owner.Criminal = false;
                m_Owner.Kills    = 0;
                m_Owner.Stam     = m_Owner.StamMax;

                Mobile target = m_Owner.Focus;

                if ((target != null && (target.Deleted || !target.Alive || !m_Owner.CanBeHarmful(target) || target.Map == Map.Internal)))
                {
                    foreach (Mobile m in m_Owner.GetMobilesInRange(15))
                    {
                        if (Misc.NotorietyHandlers.IsGuardCandidate(m))
                        {
                            Region        region        = (Region.Find(m.Location, m.Map));
                            GuardedRegion guardedRegion = (GuardedRegion)region.GetRegion(typeof(GuardedRegion));

                            //Player is in guarded
                            if (guardedRegion != null && !guardedRegion.Disabled)
                            {
                                target        = m;
                                m_Owner.Focus = m;
                                break;
                            }
                        }
                    }
                }

                if (target != null && (target.Deleted || !target.Alive || !m_Owner.CanBeHarmful(target) || target.Map == Map.Internal))
                {
                    m_Owner.Focus = null;
                    Stop();
                    return;
                }
                else if (m_Owner.Weapon is Fists)
                {
                    m_Owner.Kill();
                    Stop();
                    return;
                }

                if (target != null && m_Owner.Combatant != target)
                {
                    m_Owner.Combatant = target;
                }

                if (target == null)
                {
                    m_Owner.Focus = null;
                    Stop();
                    return;
                }

                if (target.Hidden)
                {
                    target.RevealingAction();
                    target.SendLocalizedMessage(500814); // You have been revealed!
                }

                Region        from = (Region.Find(target.Location, target.Map));
                GuardedRegion reg  = (GuardedRegion)from.GetRegion(typeof(GuardedRegion));

                //Player is in unguarded
                if (reg == null || reg.Disabled)
                {
                    //Player is still within range, follow on foot
                    if (m_Owner.InRange(target, 30))
                    {
                        m_Owner.Move(m_Owner.GetDirectionTo(target));
                    }

                    //Player has gone away, remove guard
                    else
                    {
                        m_Owner.Focus = null;
                        Stop();
                        return;
                    }
                }
                //Player is in guarded, teleport
                else if (!m_Owner.InRange(target, 1))
                {
                    TeleportTo(target);
                }
            }