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) { Facing = (Direction)moveEvent.Facing; Mobile pl = (Mobile)m_entity; if (pl.Stamina.Current == 0) { break; } if ((pl.Stamina.Current < m_MinimumStaminaToRun) && (pl.Stamina.Current > 0) && ((Facing & Direction.Running) == Direction.Running)) { Facing &= Direction.FacingMask; } if (moveEvent.CreatedByPlayerInput) { SendMoveRequestPacket(new MoveRequestPacket((byte)Facing, (byte)sequence, moveEvent.Fastwalk)); } 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; } } }
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) { m_GoalPosition = p; break; } } } else { moveEvent = m_MoveEvents.GetFinalMoveEvent(out sequence); if (moveEvent != null) { Facing = (Direction)moveEvent.Facing; Position3D p = new Position3D(moveEvent.X, moveEvent.Y, moveEvent.Z); if (p != CurrentPosition) { m_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 (MoveSequence < 1f) { CurrentPosition.Offset = new Vector3( m_GoalPosition.X - CurrentPosition.X, m_GoalPosition.Y - CurrentPosition.Y, m_GoalPosition.Z - CurrentPosition.Z) * (float)MoveSequence; } else { CurrentPosition.Set(m_GoalPosition.X, m_GoalPosition.Y, m_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; } } }