much better bot and ocr
This commit is contained in:
parent
bb8f50116a
commit
6257bcf122
25 changed files with 583 additions and 101 deletions
|
|
@ -309,16 +309,37 @@ public class InventoryManager : IInventoryManager
|
|||
return null;
|
||||
}
|
||||
|
||||
// Single word
|
||||
// Single word — prefer exact line match ("STASH") over substring ("Guild Stash")
|
||||
(int X, int Y)? containsMatch = null;
|
||||
(int X, int Y)? fuzzyMatch = null;
|
||||
|
||||
foreach (var line in result.Lines)
|
||||
foreach (var word in line.Words)
|
||||
{
|
||||
if (word.Text.Contains(needle, StringComparison.OrdinalIgnoreCase))
|
||||
return (word.X + word.Width / 2, word.Y + word.Height / 2);
|
||||
if (fuzzy && BigramSimilarity(Normalize(needle), Normalize(word.Text)) >= 0.55)
|
||||
return (word.X + word.Width / 2, word.Y + word.Height / 2);
|
||||
// Exact line match — the entire line is just this word
|
||||
if (line.Text.Equals(needle, StringComparison.OrdinalIgnoreCase) && line.Words.Count > 0)
|
||||
{
|
||||
var first = line.Words[0];
|
||||
var last = line.Words[^1];
|
||||
return ((first.X + last.X + last.Width) / 2, (first.Y + last.Y + last.Height) / 2);
|
||||
}
|
||||
|
||||
foreach (var word in line.Words)
|
||||
{
|
||||
if (word.Text.Equals(needle, StringComparison.OrdinalIgnoreCase))
|
||||
return (word.X + word.Width / 2, word.Y + word.Height / 2);
|
||||
|
||||
containsMatch ??= word.Text.Contains(needle, StringComparison.OrdinalIgnoreCase)
|
||||
? (word.X + word.Width / 2, word.Y + word.Height / 2)
|
||||
: null;
|
||||
|
||||
if (fuzzy)
|
||||
fuzzyMatch ??= BigramSimilarity(Normalize(needle), Normalize(word.Text)) >= 0.55
|
||||
? (word.X + word.Width / 2, word.Y + word.Height / 2)
|
||||
: null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
return containsMatch ?? fuzzyMatch;
|
||||
}
|
||||
|
||||
private static string Normalize(string s) =>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue