thomas-crane / nrelay

A console based modular client for Realm of the Mad God built with Node.js and TypeScript.
https://nrelay.net/
MIT License
40 stars 21 forks source link

Pathfinding seemingly not working #52

Closed ashley-dv closed 4 years ago

ashley-dv commented 4 years ago

Version info

Plugins

Steps to reproduce

  1. Create a plugin which uses client.findPath 1.1. Code in question: client.findPath({ x: 151, y: 138 }); in onText hooking to TextPacket
  2. Start nrelay
  3. Wait for client.findPath to be invoked

Result

Pathfinding fails with the error:

[13:44:09 | Main Client]      Error finding path: Cannot set property 'heapIndex' of undefined
[13:44:09 | Main Client]      TypeError: Cannot set property 'heapIndex' of undefined
    at Heap.add (C:\Users\User\test-project\node_modules\nrelay\lib\services\pathfinding\heap.js:23:24)
    at C:\Users\User\test-project\node_modules\nrelay\lib\services\pathfinding\pathfinder.js:32:21
    at new Promise (<anonymous>)
    at Pathfinder.findPath (C:\Users\User\test-project\node_modules\nrelay\lib\services\pathfinding\pathfinder.js:27:16)
    at Client.findPath (C:\Users\User\test-project\node_modules\nrelay\lib\core\client.js:297:25)
    at GuildChatPlugins.onText (C:\Users\User\test-project\lib\guild-chat-plugin.js:23:16)
    at LibraryManager.callHooks (C:\Users\User\test-project\node_modules\nrelay\lib\core\library-manager.js:190:54)
    at PacketIO.<anonymous> (C:\Users\User\test-project\node_modules\nrelay\lib\core\client.js:94:45)
    at PacketIO.emit (events.js:310:20)
    at PacketIO.emitPacket (C:\Users\User\test-project\node_modules\@realmlib\net\lib\packetio.js:144:18)

Very well may be using pathfinding incorrectly, but can't seem to find much documentation on it.

ashley-dv commented 4 years ago

Issue is in src/services/pathfinding/pathfinder.ts, line 34, as there is no node for the exact position of the client. Using Math.floor on the position fixes the error completely, so to fix, just replace line 34 of pathfinder.ts with:

const startNode = this.nodes[this.getIndex(Math.floor(start.x), Math.floor(start.y))];

The end point already gets floored in client.findPath.