/// <summary>
        /// Retrieves the last move event received. If more than one move event is in the queue, forwards the mobile to the
        /// second-to-last move event destination.
        /// </summary>
        /// <param name="sequence">The sequence index of the final move event. The player mobile needs to track this so
        /// it can send it with each move event and keep in sync with the server.</param>
        /// <returns>The final move event! Null if no move events in the queue</returns>
        public MobileMoveEvent GetAndForwardToFinalMoveEvent(out int sequence)
        {
            MobileMoveEvent moveEvent = null;
            MobileMoveEvent moveEventNext, moveEventLast;

            while ((moveEventNext = GetNextMoveEvent(out sequence)) != null)
            {
                // save the last moveEvent.
                moveEventLast = moveEvent;
                // get the next move event, erasing it from the queued move events.
                moveEvent = moveEventNext;
                // get the next move event, peeking to see if it is null (this does not erase it from the queue).
                moveEventNext = PeekNextMoveEvent();
                // we want to save move events that are the last move event in the queue, and are only facing changes.
                if (moveEventNext == null && moveEventLast != null &&
                    moveEvent.X == moveEventLast.X && moveEvent.Y == moveEventLast.Y && moveEventLast.Z == moveEvent.Z &&
                    moveEvent.Facing != moveEventLast.Facing)
                {
                    // re-queue the final facing change, and return the second-to-last move event.
                    AddMoveEvent(moveEvent.X, moveEvent.Y, moveEvent.Z, moveEvent.Facing, false);
                    return(moveEventLast);
                }
            }
            return(moveEvent);
        }
        public void AddMoveEvent(int x, int y, int z, int facing, bool createdByPlayerInput)
        {
            var moveEvent = new MobileMoveEvent(x, y, z, facing, _fastWalkKey);

            moveEvent.CreatedByPlayerInput = createdByPlayerInput;
            _history[_sequenceQueued]      = moveEvent;
            _sequenceQueued += 1;
            if (_sequenceQueued > byte.MaxValue)
            {
                _sequenceQueued = 1;
            }
        }