Ejemplo n.º 1
0
        public Motion GetMoveToPosition(Position position, float runRate = 1.0f, float?walkRunThreshold = null, float?speed = null)
        {
            // TODO: change parameters to accept an optional MoveToParameters

            var motion = new Motion(this, position);

            motion.MovementType = MovementType.MoveToPosition;
            //motion.Flag |= MovementParams.CanCharge | MovementParams.FailWalk | MovementParams.UseFinalHeading | MovementParams.MoveAway;
            if (walkRunThreshold != null)
            {
                motion.MoveToParameters.WalkRunThreshold = walkRunThreshold.Value;
            }
            if (speed != null)
            {
                motion.MoveToParameters.Speed = speed.Value;
            }

            // always use final heading?
            var frame = new AFrame(position.Pos, position.Rotation);

            motion.MoveToParameters.DesiredHeading      = frame.get_heading();
            motion.MoveToParameters.MovementParameters |= MovementParams.UseFinalHeading;
            motion.MoveToParameters.DistanceToObject    = 0.6f;

            if (runRate > 0)
            {
                motion.RunRate = runRate;
            }
            else
            {
                motion.MoveToParameters.MovementParameters &= ~MovementParams.CanRun;
            }

            return(motion);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Starts rotating a creature from its current direction
        /// so that it eventually is facing the rotation from the input position
        /// Used by the emote system, which has the target rotation stored in positions
        /// </summary>
        /// <returns>The amount of time in seconds for the rotation to complete</returns>
        public float TurnTo(Position position)
        {
            var frame   = new AFrame(position.Pos, position.Rotation);
            var heading = frame.get_heading();

            // send network message to start turning creature
            var turnToMotion = new Motion(this, position, heading);

            EnqueueBroadcastMotion(turnToMotion);

            var angle = GetAngle(position);
            //Console.WriteLine("Angle: " + angle);

            // estimate time to rotate to target
            var rotateDelay = GetRotateDelay(angle);
            //Console.WriteLine("RotateTime: " + rotateTime);

            // update server object rotation on completion
            // TODO: proper incremental rotation
            var actionChain = new ActionChain();

            actionChain.AddDelaySeconds(rotateDelay);
            actionChain.AddAction(this, () =>
            {
                var targetDir = position.GetCurrentDir();
                Location.Rotate(targetDir);
                PhysicsObj.Position.Frame.Orientation = Location.Rotation;
            });
            actionChain.EnqueueChain();

            return(rotateDelay);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sends a network message for moving a creature to a new position
        /// </summary>
        public void MoveTo(Position position, float runRate = 1.0f)
        {
            var motion = new Motion(this, position);

            motion.MovementType = MovementType.MoveToPosition;
            //motion.Flag |= MovementParams.CanCharge | MovementParams.FailWalk | MovementParams.UseFinalHeading | MovementParams.MoveAway;
            motion.MoveToParameters.WalkRunThreshold = 1.0f;

            // always use final heading?
            var frame = new AFrame(position.Pos, position.Rotation);

            motion.MoveToParameters.DesiredHeading      = frame.get_heading();
            motion.MoveToParameters.MovementParameters |= MovementParams.UseFinalHeading;
            motion.MoveToParameters.DistanceToObject    = 0.6f;

            if (runRate > 0)
            {
                motion.RunRate = runRate;
            }
            else
            {
                motion.MoveToParameters.MovementParameters &= ~MovementParams.CanRun;
            }

            // todo: use better movement system
            Location = new Position(position);

            EnqueueBroadcastMotion(motion);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sends a network message for moving a creature to a new position
        /// </summary>
        public void MoveTo(Position position, float runRate = 1.0f, bool setLoc = true, float? walkRunThreshold = null, float? speed = null)
        {
            // TODO: change parameters to accept an optional MoveToParameters

            var motion = new Motion(this, position);
            motion.MovementType = MovementType.MoveToPosition;
            //motion.Flag |= MovementParams.CanCharge | MovementParams.FailWalk | MovementParams.UseFinalHeading | MovementParams.MoveAway;
            if (walkRunThreshold != null)
                motion.MoveToParameters.WalkRunThreshold = walkRunThreshold.Value;
            if (speed != null)
                motion.MoveToParameters.Speed = speed.Value;

            // always use final heading?
            var frame = new AFrame(position.Pos, position.Rotation);
            motion.MoveToParameters.DesiredHeading = frame.get_heading();
            motion.MoveToParameters.MovementParameters |= MovementParams.UseFinalHeading;
            motion.MoveToParameters.DistanceToObject = 0.6f;

            if (runRate > 0)
                motion.RunRate = runRate;
            else
                motion.MoveToParameters.MovementParameters &= ~MovementParams.CanRun;

            // todo: use better movement system
            // todo: set physics position
            if (setLoc)
                Location = new Position(position);

            EnqueueBroadcastMotion(motion);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Sends a network message for moving a creature to a new position
        /// </summary>
        public void MoveTo(Position position, float runRate = 1.0f, bool setLoc = true, float?walkRunThreshold = null, float?speed = null)
        {
            // TODO: change parameters to accept an optional MoveToParameters

            var motion = new Motion(this, position);

            motion.MovementType = MovementType.MoveToPosition;
            //motion.Flag |= MovementParams.CanCharge | MovementParams.FailWalk | MovementParams.UseFinalHeading | MovementParams.MoveAway;
            if (walkRunThreshold != null)
            {
                motion.MoveToParameters.WalkRunThreshold = walkRunThreshold.Value;
            }
            if (speed != null)
            {
                motion.MoveToParameters.Speed = speed.Value;
            }

            // always use final heading?
            var frame = new AFrame(position.Pos, position.Rotation);

            motion.MoveToParameters.DesiredHeading      = frame.get_heading();
            motion.MoveToParameters.MovementParameters |= MovementParams.UseFinalHeading;
            motion.MoveToParameters.DistanceToObject    = 0.6f;

            if (runRate > 0)
            {
                motion.RunRate = runRate;
            }
            else
            {
                motion.MoveToParameters.MovementParameters &= ~MovementParams.CanRun;
            }

            // todo: use physics MoveToManager
            // todo: handle landblock updates
            if (setLoc)
            {
                Location = new Position(position);
                PhysicsObj.SetPositionSimple(new Physics.Common.Position(position), true);
            }

            EnqueueBroadcastMotion(motion);
        }
Ejemplo n.º 6
0
 public float heading_diff(Position position)
 {
     return(heading(position) - Frame.get_heading());
 }