Ejemplo n.º 1
0
        private static void Path(Mobile from, IPoint3D p, PathAlgorithm alg, string name, int zOffset)
        {
            m_OverrideAlgorithm = alg;

            long         start = DateTime.UtcNow.Ticks;
            MovementPath path  = new MovementPath(from, new Point3D(p));
            long         end   = DateTime.UtcNow.Ticks;
            double       len   = Math.Round((end - start) / 10000.0, 2);

            if (!path.Success)
            {
                from.SendMessage("{0} path failed: {1}ms", name, len);
            }
            else
            {
                from.SendMessage("{0} path success: {1}ms", name, len);

                int x = from.X;
                int y = from.Y;
                int z = from.Z;

                for (int i = 0; i < path.Directions.Length; ++i)
                {
                    Movement.Movement.Offset(path.Directions[i], ref x, ref y);

                    new Items.RecallRune().MoveToWorld(new Point3D(x, y, z + zOffset), from.Map);
                }
            }
        }
Ejemplo n.º 2
0
        public bool CheckPath()
        {
            if (!Enabled)
            {
                return(false);
            }

            bool repath = false;

            Point3D goal = GetGoalLocation();

            if (m_Path == null)
            {
                repath = true;
            }
            else if ((!m_Path.Success || goal != m_LastGoalLoc) && (m_LastPathTime + RepathDelay) <= DateTime.UtcNow)
            {
                repath = true;
            }
            else if (m_Path.Success && Check(m_From.Location, m_LastGoalLoc, 0))
            {
                repath = true;
            }

            if (!repath)
            {
                return(false);
            }

            m_LastPathTime = DateTime.UtcNow;
            m_LastGoalLoc  = goal;

            m_Path = new MovementPath(m_From, goal);

            m_Index = 0;
            m_Next  = m_From.Location;

            Advance(ref m_Next, m_Index);

            return(true);
        }
Ejemplo n.º 3
0
 public void ForceRepath()
 {
     m_Path = null;
 }
Ejemplo n.º 4
0
        public bool Follow(bool run, int range)
        {
            Point3D   goal = GetGoalLocation();
            Direction d;

            if (Check(m_From.Location, goal, range))
            {
                return(true);
            }

            bool repathed = CheckPath();

            if (!Enabled || !m_Path.Success)
            {
                d = m_From.GetDirectionTo(goal);

                if (run)
                {
                    d |= Direction.Running;
                }

                m_From.SetDirection(d);
                Move(d);

                return(Check(m_From.Location, goal, range));
            }

            d = m_From.GetDirectionTo(m_Next);

            if (run)
            {
                d |= Direction.Running;
            }

            m_From.SetDirection(d);

            MoveResult res = Move(d);

            if (res == MoveResult.Blocked)
            {
                if (repathed)
                {
                    return(false);
                }

                m_Path = null;
                CheckPath();

                if (!m_Path.Success)
                {
                    d = m_From.GetDirectionTo(goal);

                    if (run)
                    {
                        d |= Direction.Running;
                    }

                    m_From.SetDirection(d);
                    Move(d);

                    return(Check(m_From.Location, goal, range));
                }

                d = m_From.GetDirectionTo(m_Next);

                if (run)
                {
                    d |= Direction.Running;
                }

                m_From.SetDirection(d);

                res = Move(d);

                if (res == MoveResult.Blocked)
                {
                    return(false);
                }
            }

            if (m_From.X == m_Next.X && m_From.Y == m_Next.Y)
            {
                if (m_From.Z == m_Next.Z)
                {
                    ++m_Index;
                    Advance(ref m_Next, m_Index);
                }
                else
                {
                    m_Path = null;
                }
            }

            return(Check(m_From.Location, goal, range));
        }