public static void Write(this BinaryWriter writer, MovementInvalid movement) { writer.Write(movement.State); if ((movement.MovementData.MotionFlags & MotionFlags.StickToObject) != 0) { writer.WriteGuid(movement.StickyObject); } }
public MovementData(WorldObject wo, Motion motion) { WorldObject = wo; //var sequence = wo.Sequences; // do this here, or in network writer? IsAutonomous = motion.IsAutonomous; //MovementSequence = BitConverter.ToUInt16(sequence.GetNextSequence(SequenceType.ObjectMovement)); //if (IsAutonomous) //ServerControlSequence = BitConverter.ToUInt16(sequence.GetCurrentSequence(SequenceType.ObjectServerControl)); //else //ServerControlSequence = BitConverter.ToUInt16(sequence.GetNextSequence(SequenceType.ObjectServerControl)); MovementType = motion.MovementType; MotionFlags = motion.MotionFlags; //if (motion.HasTarget) //MotionFlags |= MotionFlags.StickToObject; //if (motion.StandingLongJump) //MotionFlags |= MotionFlags.StandingLongJump; // indicates if player started charging jump bar while standing still CurrentStyle = motion.Stance; switch (MovementType) { case MovementType.Invalid: Invalid = new MovementInvalid(this, motion); break; case MovementType.MoveToObject: MoveToObject = new MoveToObject(motion); break; case MovementType.MoveToPosition: MoveToPosition = new MoveToPosition(motion); break; case MovementType.TurnToObject: TurnToObject = new TurnToObject(motion); break; case MovementType.TurnToHeading: TurnToHeading = new TurnToHeading(motion); break; } }
/// <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); }