xiaokeer 0 Posted July 3 Share Posted July 3 I'm now trying to write a bit of fuzzy matching code, but it hasn't worked,Following the normal traversal of the target name, the code I used was: string[] objectNames = new string[] { "Alliance Bonfire" }; foreach (string objectName in objectNames) { var gameObject = ObjectManager.GetWoWGameObjectByName(objectName) .Where(o => o.GetDistance <= maxDistance) .OrderBy(o => o.GetDistance) .FirstOrDefault(); if (gameObject != null ) {...... } } What I want to achieve is a fuzzy match, which doesn't require a full traversal of the "Alliance Bonfire", just a matching "Bonfire". Link to comment https://wrobot.eu/forums/topic/15495-code-about-fuzzy-matching/ Share on other sites More sharing options...
Droidz 2738 Posted July 4 Share Posted July 4 Hello, string[] objectNames = new string[] { "Bonfire" }; foreach (string objectName in objectNames) { var gameObjects = ObjectManager.GetObjectWoWGameObject() .Where(o => o.Name.Contains(objectName) && o.GetDistance <= maxDistance) .OrderBy(o => o.GetDistance) .FirstOrDefault(); if (gameObjects != null) { // ... } } Link to comment https://wrobot.eu/forums/topic/15495-code-about-fuzzy-matching/#findComment-69450 Share on other sites More sharing options...
xiaokeer 0 Posted July 4 Author Share Posted July 4 10 hours ago, Droidz said: 你好 string[] objectNames = new string[] { "Bonfire" }; foreach (string objectName in objectNames) { var gameObjects = ObjectManager.GetObjectWoWGameObject() .Where(o => o.Name.Contains(objectName) && o.GetDistance <= maxDistance) .OrderBy(o => o.GetDistance) .FirstOrDefault(); if (gameObjects != null) { // ... } } I tested it and it didn't work with a fuzzy match, and when I tested the full name with PNC "Auctioneer Billdu", I was able to match this PNC, but when I used the fuzzy name "Auctioneer", it didn't match properly, here's my code string[] objectNames = new string[] { "Auctioneer Billdu" }; float maxDistance = 2250.0f; while (true) { foreach (string objectName in objectNames) { var gameObjects = ObjectManager.GetObjectWoWGameObject() .Where(o => objectNames.Contains(o.Name) && o.GetDistance <= maxDistance) .OrderBy(o => o.GetDistance) .FirstOrDefault(); if (gameObjects != null) { string luaPrintCommand = string.Format("print('Targeted object: {0}')", gameObjects.Name); Lua.LuaDoString(luaPrintCommand); Thread.Sleep(50); } } } If you change it to the following code, it will not match the NPC: string[] objectNames = new string[] { "Auctioneer" }; float maxDistance = 2250.0f; while (true) { foreach (string objectName in objectNames) { var gameObjects = ObjectManager.GetObjectWoWGameObject() .Where(o => objectNames.Contains(o.Name) && o.GetDistance <= maxDistance) .OrderBy(o => o.GetDistance) .FirstOrDefault(); if (gameObjects != null) { string luaPrintCommand = string.Format("print('Targeted object: {0}')", gameObjects.Name); Lua.LuaDoString(luaPrintCommand); Thread.Sleep(50); } } } Link to comment https://wrobot.eu/forums/topic/15495-code-about-fuzzy-matching/#findComment-69451 Share on other sites More sharing options...
Zer0 148 Posted July 5 Share Posted July 5 You're not using the elements of your foreach loop. The code Droidz gave you is absolutely correct. Replace var gameObjects = ObjectManager.GetObjectWoWGameObject() .Where(o => objectNames.Contains(o.Name) && o.GetDistance <= maxDistance) .OrderBy(o => o.GetDistance) .FirstOrDefault(); with var gameObjects = ObjectManager.GetObjectWoWGameObject() .Where(o => o.Name.Contains(objectName) && o.GetDistance <= maxDistance) .OrderBy(o => o.GetDistance) .FirstOrDefault(); Link to comment https://wrobot.eu/forums/topic/15495-code-about-fuzzy-matching/#findComment-69452 Share on other sites More sharing options...
xiaokeer 0 Posted July 6 Author Share Posted July 6 On 7/5/2024 at 9:22 AM, Zer0 said: You're not using the elements of your foreach loop. The code Droidz gave you is absolutely correct. Replace var gameObjects = ObjectManager.GetObjectWoWGameObject() .Where(o => objectNames.Contains(o.Name) && o.GetDistance <= maxDistance) .OrderBy(o => o.GetDistance) .FirstOrDefault(); with var gameObjects = ObjectManager.GetObjectWoWGameObject() .Where(o => o.Name.Contains(objectName) && o.GetDistance <= maxDistance) .OrderBy(o => o.GetDistance) .FirstOrDefault(); Thanks for the reminder, I tested it again, it was me who got the code wrong, thanks Link to comment https://wrobot.eu/forums/topic/15495-code-about-fuzzy-matching/#findComment-69458 Share on other sites More sharing options...
xiaokeer 0 Posted July 6 Author Share Posted July 6 On 7/4/2024 at 2:42 PM, Droidz said: Hello, string[] objectNames = new string[] { "Bonfire" }; foreach (string objectName in objectNames) { var gameObjects = ObjectManager.GetObjectWoWGameObject() .Where(o => o.Name.Contains(objectName) && o.GetDistance <= maxDistance) .OrderBy(o => o.GetDistance) .FirstOrDefault(); if (gameObjects != null) { // ... } } 感谢,之前是我自己把代码搞错了,代码能正常使用的,非常感谢 Link to comment https://wrobot.eu/forums/topic/15495-code-about-fuzzy-matching/#findComment-69459 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now