Esempio n. 1
0
        public MovementInvalid(MovementData movementData, Motion motion)
        {
            MovementData = movementData;

            State = new InterpretedMotionState(movementData, motion);

            if ((motion.MotionFlags & MotionFlags.StickToObject) != 0)
            {
                StickyObject = motion.TargetGuid;
            }
        }
Esempio n. 2
0
        public static void Write(this BinaryWriter writer, InterpretedMotionState state)
        {
            var numCommands = state.Commands != null ? state.Commands.Count : 0;

            writer.Write((uint)state.Flags | (uint)numCommands << 7);

            // for MotionStance / MotionCommand, write as ushort
            if ((state.Flags & MovementStateFlag.CurrentStyle) != 0)
            {
                writer.Write((ushort)state.CurrentStyle);
            }

            if ((state.Flags & MovementStateFlag.ForwardCommand) != 0)
            {
                writer.Write((ushort)state.ForwardCommand);
            }

            if ((state.Flags & MovementStateFlag.SideStepCommand) != 0)
            {
                writer.Write((ushort)state.SidestepCommand);
            }

            if ((state.Flags & MovementStateFlag.TurnCommand) != 0)
            {
                writer.Write((ushort)state.TurnCommand);
            }

            if ((state.Flags & MovementStateFlag.ForwardSpeed) != 0)
            {
                writer.Write(state.ForwardSpeed);
            }

            if ((state.Flags & MovementStateFlag.SideStepSpeed) != 0)
            {
                writer.Write(state.SidestepSpeed);
            }

            if ((state.Flags & MovementStateFlag.TurnSpeed) != 0)
            {
                writer.Write(state.TurnSpeed);
            }

            if (numCommands > 0)
            {
                foreach (var motion in state.Commands)
                {
                    writer.Write(motion);
                }
            }

            // align to DWORD boundary
            writer.Align();
        }
Esempio n. 3
0
        public InterpretedMotionState(InterpretedMotionState state)
        {
            // copy constructor
            Flags           = state.Flags;
            MovementData    = state.MovementData;
            CurrentStyle    = state.CurrentStyle;
            ForwardCommand  = state.ForwardCommand;
            SidestepCommand = state.SidestepCommand;
            TurnCommand     = state.TurnCommand;
            ForwardSpeed    = state.ForwardSpeed;
            SidestepSpeed   = state.SidestepSpeed;
            TurnSpeed       = state.TurnSpeed;

            if (state.Commands != null)
            {
                Commands = new List <MotionItem>();
                foreach (var command in state.Commands)
                {
                    Commands.Add(new MotionItem(command));
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Converts a MoveToState packet from the client -> MovementData packet to send to other clients
        /// This is effectively a shortcut for converting RawMotionState -> InterpretedMotionState
        /// </summary>
        public MovementData(Creature creature, MoveToState state)
        {
            WorldObject = creature;

            var rawState = state.RawMotionState;

            // keeping most of this existing logic, ported from ConvertToClientAccepted
            if ((rawState.Flags & RawMotionFlags.CurrentStyle) != 0)
            {
                CurrentStyle = rawState.CurrentStyle;
            }

            // only using primary hold key?
            var holdKey = rawState.CurrentHoldKey;
            var speed   = holdKey == HoldKey.Run ? creature.GetRunRate() : 1.0f;

            var interpState = new InterpretedMotionState(this);

            // move forwards / backwards / animation
            if ((rawState.Flags & RawMotionFlags.ForwardCommand) != 0 && !state.StandingLongJump)
            {
                if (rawState.ForwardCommand == MotionCommand.WalkForward || rawState.ForwardCommand == MotionCommand.WalkBackwards)
                {
                    interpState.ForwardCommand = MotionCommand.WalkForward;

                    if (rawState.ForwardCommand == MotionCommand.WalkForward && holdKey == HoldKey.Run)
                    {
                        interpState.ForwardCommand = MotionCommand.RunForward;
                    }

                    interpState.ForwardSpeed = speed;

                    if (rawState.ForwardCommand == MotionCommand.WalkBackwards)
                    {
                        interpState.ForwardSpeed *= -0.65f;
                    }
                }
                else
                {
                    interpState.ForwardCommand = rawState.ForwardCommand;
                }
            }

            // sidestep
            if ((rawState.Flags & RawMotionFlags.SideStepCommand) != 0 && !state.StandingLongJump)
            {
                interpState.SidestepCommand = MotionCommand.SideStepRight;
                interpState.SidestepSpeed   = speed * 3.12f / 1.25f * 0.5f;

                if (rawState.SidestepCommand == MotionCommand.SideStepLeft)
                {
                    interpState.SidestepSpeed *= -1;
                }

                Math.Clamp(interpState.SidestepSpeed, -3, 3);
            }

            // rotate
            if ((rawState.Flags & RawMotionFlags.TurnCommand) != 0)
            {
                interpState.TurnCommand = MotionCommand.TurnRight;
                interpState.TurnSpeed   = holdKey == HoldKey.Run ? 1.5f : 1.0f;

                if (rawState.TurnCommand == MotionCommand.TurnLeft)
                {
                    interpState.TurnSpeed *= -1;
                }
            }

            // contact/sticky?
            // this alone isn't enough for standing long jump,
            // and observing clients seems to show a buggy shallow arc jump
            // without the above exclusions of ForwardCommand / SidestepCommand
            if (state.StandingLongJump)
            {
                MotionFlags |= MotionFlags.StandingLongJump;
            }

            interpState.Commands = rawState.Commands;
            interpState.Flags    = interpState.BuildMovementFlags();

            // this is a hack to make walking work correctly - investigate this
            // wouldn't all of these be autonomous?
            // walk backwards?
            //if (holdKey != HoldKey.Invalid || rawState.ForwardCommand == MotionCommand.WalkForward)
            IsAutonomous = true;

            Invalid = new MovementInvalid(this, interpState);
        }
Esempio n. 5
0
 public MovementInvalid(MovementData movementData, InterpretedMotionState state)
 {
     MovementData = movementData;
     State        = state;
     state.BuildMovementFlags();
 }
Esempio n. 6
0
        public ObjectGuid StickyObject;         // choose valid sections by masking against MotionFlags: 0x1 - object to stick to

        public MovementInvalid(MovementData movementData)
        {
            MovementData = movementData;
            State        = new InterpretedMotionState(movementData);
        }