boss getting close

This commit is contained in:
Boki 2026-02-21 20:57:22 -05:00
parent f914443d86
commit aee3a7f22c
19 changed files with 422 additions and 119 deletions

View file

@ -10,6 +10,7 @@ public class InventoryManager : IInventoryManager
{
private static readonly string SalvageTemplate = Path.Combine("assets", "salvage.png");
public event Action? Updated;
public InventoryTracker Tracker { get; } = new();
@ -155,6 +156,36 @@ public class InventoryManager : IInventoryManager
return true;
}
public async Task<bool> IdentifyItems()
{
var nameplate = await FindAndClickNameplate("Doryani");
if (nameplate == null)
{
Log.Error("Could not find Doryani nameplate");
return false;
}
await Helpers.Sleep(Delays.PostStashOpen);
// Dialog appears below and to the right of the nameplate
var dialogRegion = new Region(
nameplate.Value.X, nameplate.Value.Y,
460, 600);
var identifyPos = await _screen.FindTextInRegion(dialogRegion, "Identify");
if (identifyPos.HasValue)
{
await _game.LeftClickAt(identifyPos.Value.X, identifyPos.Value.Y);
await Helpers.Sleep(Delays.PostEscape);
}
else
{
Log.Warning("'Identify Items' not found in dialog region");
}
await _game.PressEscape();
await Helpers.Sleep(Delays.PostEscape);
return true;
}
private async Task CtrlClickItems(List<PlacedItem> items, GridLayout layout, int clickDelayMs = Delays.ClickInterval)
{
await _game.KeyDown(Game.InputSender.VK.SHIFT);
@ -207,7 +238,7 @@ public class InventoryManager : IInventoryManager
}
}
public async Task<(int X, int Y)?> FindAndClickNameplate(string name, int maxRetries = 3, int retryDelayMs = 1000)
public async Task<(int X, int Y)?> FindAndClickNameplate(string name, int maxRetries = 3, int retryDelayMs = 1000, System.Drawing.Rectangle? scanRegion = null, string? savePath = null)
{
for (var attempt = 1; attempt <= maxRetries; attempt++)
{
@ -227,7 +258,10 @@ public class InventoryManager : IInventoryManager
await _game.KeyUp(Game.InputSender.VK.MENU);
// Diff OCR — only processes the bright nameplate regions
var result = await _screen.NameplateDiffOcr(reference, current);
var attemptSavePath = savePath != null
? Path.Combine(Path.GetDirectoryName(savePath)!, $"{Path.GetFileNameWithoutExtension(savePath)}_attempt{attempt}{Path.GetExtension(savePath)}")
: null;
var result = await _screen.NameplateDiffOcr(reference, current, scanRegion, attemptSavePath);
var pos = FindWordInOcrResult(result, name, fuzzy: true);
if (pos.HasValue)
{
@ -236,7 +270,7 @@ public class InventoryManager : IInventoryManager
return pos;
}
Log.Debug("Nameplate '{Name}' not found in diff OCR (attempt {Attempt}), text: {Text}", name, attempt, result.Text);
Log.Information("Nameplate '{Name}' not found in diff OCR (attempt {Attempt}), text: {Text}", name, attempt, result.Text);
if (attempt < maxRetries)
await Helpers.Sleep(retryDelayMs);
}