I think maybe you're solving the wrong problem. The goal isn't to determine if the player is in a locked room, it's to figure out if enemies have a way of getting to them. All it would take is a way to query the pathfinding code to figure out if there's a route from the player to any enemy (and potentially to any exit) that doesn't pass through a player-locked door. This approach would nicely handle being in an unlocked room in a locked wing of a dungeon, or resting in a hidey hole a hundred feet off the ground or something else that's unreachable despite not having a door at all.l3lessed wrote: ↑Wed Aug 04, 2021 7:56 pmFinding the door wouldn't be hard; It could be done using the built in block data that contains all the doors properties within it or you could do a ray/spherecast from player center out a certain range and have it return upon successfully hitting the door object.another thing, is it possible to make the magical door lock (fenrik's door jam / wizard lock) override enemies being nearby, if you lock a door in a dungeon? so you can rest nicely, if you have a good door lock ability
However, the hard part is, how will you know if the player is in the room or in the hallway outside the room? You would have to do more calculations to figure out the area around the player and then assume the bigger area would be the room. However, that assumption isn't even safe.
Or, because all doors start closed, you could create a list/array to store the location the player opens the door at, set that as the location of the hall, and then use that to figure out if the player is on the other side of the door/hall by just calculating the players position from the position of where they opened the door. However, what happens if a monster/npc opens a door? Now it won't work.
Maybe if all doors have a properly places front and back, that could be used. The front would face towards the hall area and the back would face the room. If that is the case, then you could use this as the easiest possible solution. Detect if the player is facing the back of the door (aka is in the room) using the object's and player's rotation/yaw/position properties, and if so, and the door is closed, we get safe sleep.
It can be done, but as said, you would need to be creative and really consider all the issues of code trying to figure out the subjectivity of an area being considered a room or not.
If we want it to simulate magic-using enemies figuring out what's up it can just do a skill check on all player-locked doors and treat the door as unlocked if the check succeeds.