Beispiel #1
0
        public void Update(double frameMS)
        {
            if (!IsMoving)
            {
                if (m_entity.IsClientEntity && m_playerMobile_NextMoveInMS <= 0d)
                {
                    PlayerMobile_CheckForMoveEvent();
                }

                MobileMoveEvent moveEvent;
                int             sequence;

                if (m_entity.IsClientEntity)
                {
                    while ((moveEvent = m_MoveEvents.GetNextMoveEvent(out sequence)) != null)
                    {
                        if (moveEvent.CreatedByPlayerInput)
                        {
                            SendMoveRequestPacket(new MoveRequestPacket((byte)moveEvent.Facing, (byte)sequence, moveEvent.Fastwalk));
                        }
                        Facing = (Direction)moveEvent.Facing;
                        Position3D p = new Position3D(moveEvent.X, moveEvent.Y, moveEvent.Z);
                        if (p != CurrentPosition)
                        {
                            GoalPosition = p;
                            break;
                        }
                    }
                }
                else
                {
                    moveEvent = m_MoveEvents.GetAndForwardToFinalMoveEvent(out sequence);
                    if (moveEvent != null)
                    {
                        Facing = (Direction)moveEvent.Facing;
                        Position3D p = new Position3D(moveEvent.X, moveEvent.Y, moveEvent.Z);
                        if (p != CurrentPosition)
                        {
                            GoalPosition = p;
                        }
                    }
                }
            }


            // Are we moving? (if our current location != our destination, then we are moving)
            if (IsMoving)
            {
                double diff = (frameMS / MovementSpeed.TimeToCompleteMove(m_entity, Facing));

                MoveSequence += diff;
                if (m_entity.IsClientEntity)
                {
                    m_playerMobile_NextMoveInMS -= frameMS;
                }

                if (Math.Abs(GoalPosition.X - CurrentPosition.X) > 1 || Math.Abs(GoalPosition.Y - CurrentPosition.Y) > 1)
                {
                    int x, y;
                    if (CurrentPosition.X < GoalPosition.X)
                    {
                        x = GoalPosition.X - 1;
                    }
                    else if (CurrentPosition.X > GoalPosition.X)
                    {
                        x = GoalPosition.X + 1;
                    }
                    else
                    {
                        x = GoalPosition.X;
                    }

                    if (CurrentPosition.Y < GoalPosition.Y)
                    {
                        y = GoalPosition.Y - 1;
                    }
                    else if (CurrentPosition.Y > GoalPosition.Y)
                    {
                        y = GoalPosition.Y + 1;
                    }
                    else
                    {
                        y = GoalPosition.Y;
                    }

                    CurrentPosition.Set(x, y, CurrentPosition.Z);
                }

                if (MoveSequence < 1f)
                {
                    CurrentPosition.Offset = new Vector3(
                        GoalPosition.X - CurrentPosition.X,
                        GoalPosition.Y - CurrentPosition.Y,
                        GoalPosition.Z - CurrentPosition.Z) * (float)MoveSequence;
                }
                else
                {
                    CurrentPosition.Set(GoalPosition.X, GoalPosition.Y, GoalPosition.Z);
                    CurrentPosition.Offset = Vector3.Zero;
                    MoveSequence           = 0f;
                    if (m_entity.IsClientEntity)
                    {
                        m_playerMobile_NextMoveInMS = 0;
                    }
                }
            }
            else
            {
                MoveSequence = 0f;
                if (m_entity.IsClientEntity)
                {
                    m_playerMobile_NextMoveInMS = 0d;
                }
            }
        }