refactor
This commit is contained in:
parent
2d6a6bd3a1
commit
d80e723b94
28 changed files with 1801 additions and 352 deletions
40
src/Poe2Trade.Navigation/StuckDetector.cs
Normal file
40
src/Poe2Trade.Navigation/StuckDetector.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
namespace Poe2Trade.Navigation;
|
||||
|
||||
/// <summary>
|
||||
/// Detects when the player hasn't moved significantly over a window of frames.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue