minimap work

This commit is contained in:
Boki 2026-02-13 12:14:57 -05:00
parent 802f1030d5
commit ba8626b470
7 changed files with 312 additions and 118 deletions

View file

@ -58,61 +58,70 @@ public class NavigationExecutor : IDisposable
await _game.ToggleMinimap();
await Helpers.Sleep(300);
var lastMoveTime = long.MinValue;
while (!_stopped)
{
var frameStart = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
try
{
// 1. Capture frame
// 1. Capture + track every frame (~30 fps)
SetState(NavigationState.Capturing);
using var frame = _capture.CaptureFrame();
if (frame == null)
{
Log.Warning("Failed to capture minimap frame");
await Helpers.Sleep(200);
await Helpers.Sleep(_config.CaptureIntervalMs);
continue;
}
// 2. Track position via phase correlation
SetState(NavigationState.Processing);
var pos = _tracker.UpdatePosition(frame.GrayMat);
// 3. Stitch into world map
_worldMap.StitchFrame(frame.ClassifiedMat, pos);
// 4. Check if stuck
if (_tracker.IsStuck)
// 2. Movement decisions at slower rate
var now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
if (now - lastMoveTime >= _config.MovementWaitMs)
{
SetState(NavigationState.Stuck);
Log.Information("Stuck detected, clicking random direction");
await ClickRandomDirection();
await Helpers.Sleep(_config.MovementWaitMs);
continue;
lastMoveTime = now;
if (_tracker.IsStuck)
{
SetState(NavigationState.Stuck);
Log.Information("Stuck detected, clicking random direction");
await ClickRandomDirection();
}
else
{
SetState(NavigationState.Planning);
var direction = _worldMap.FindNearestUnexplored(pos);
if (direction == null)
{
Log.Information("Map fully explored");
SetState(NavigationState.Completed);
break;
}
SetState(NavigationState.Moving);
await ClickToMove(direction.Value.dirX, direction.Value.dirY);
}
}
// 5. Find best exploration direction
SetState(NavigationState.Planning);
var direction = _worldMap.FindNearestUnexplored(pos);
if (direction == null)
{
Log.Information("Map fully explored");
SetState(NavigationState.Completed);
break;
}
// 6. Click to move in that direction
SetState(NavigationState.Moving);
await ClickToMove(direction.Value.dirX, direction.Value.dirY);
// 7. Wait for character to walk
await Helpers.Sleep(_config.MovementWaitMs);
}
catch (Exception ex)
{
Log.Error(ex, "Error in explore loop");
SetState(NavigationState.Failed);
await Helpers.Sleep(1000);
continue;
}
// Sleep remainder of frame interval
var elapsed = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - frameStart;
var sleepMs = _config.CaptureIntervalMs - (int)elapsed;
if (sleepMs > 0)
await Helpers.Sleep(sleepMs);
}
if (_state != NavigationState.Completed)
@ -149,16 +158,20 @@ public class NavigationExecutor : IDisposable
/// <summary>
/// Capture one frame, track position, stitch into world map.
/// Returns viewport PNG bytes, or null on failure.
/// Returns PNG bytes for the requested debug stage (or world map viewport by default).
/// </summary>
public byte[]? ProcessFrame()
public byte[]? ProcessFrame(MinimapDebugStage stage = MinimapDebugStage.WorldMap)
{
using var frame = _capture.CaptureFrame();
if (frame == null) return null;
var pos = _tracker.UpdatePosition(frame.GrayMat);
_worldMap.StitchFrame(frame.ClassifiedMat, pos);
return _worldMap.GetViewportSnapshot(pos);
if (stage == MinimapDebugStage.WorldMap)
return _worldMap.GetViewportSnapshot(pos);
return _capture.CaptureStage(stage);
}
public void SaveDebugCapture() => _capture.SaveDebugCapture();