namespace Poe2Trade.Navigation; /// /// Detects when the player hasn't moved significantly over a window of frames. /// internal class StuckDetector { private readonly double _threshold; private readonly int _frameCount; private int _counter; private MapPosition? _lastPosition; public bool IsStuck => _counter >= _frameCount; public StuckDetector(double threshold, int frameCount) { _threshold = threshold; _frameCount = frameCount; } public void Update(MapPosition position) { if (_lastPosition != null) { var dx = position.X - _lastPosition.X; var dy = position.Y - _lastPosition.Y; if (Math.Sqrt(dx * dx + dy * dy) < _threshold) _counter++; else _counter = 0; } _lastPosition = position; } public void Reset() { _counter = 0; _lastPosition = null; } }