I have an algorithm that can calculate line of sight between spot a and spot b by checking the collision flags. I have another algorithm that determines if an npc can reach you by simulating the path it will take to walk to you by also checking collision flags. The second algorithm is probably the one you would need. You can determine how it works pretty easily by just watching how npcs walk towards you in the game. npcs will only move toward you in both the x and y directions first, x direction second, then y direction last based on which one it is able to do. They never move away unless you are out of its range, then it will only move backwards (extremely annoying when I made this script.) If an npc covers multiple positions, its main position is always the south-west post position. Feel free to message me if you need more info.