-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmovement.js
45 lines (41 loc) · 1.51 KB
/
movement.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/** Create template for all directionection commands */
module.exports.createCommands = (world) => {
const directionCommand = (direction) => {
return new world.Command({
name: direction,
positions: [world.constants().positions.STANDING],
execute: async (world, user, buffer) => {
/** Find exit in the direction specified, if one exists */
const exit = user.room().exits().find(x => x.direction() == world.constants().directionsLookup[direction]);
/** If the exit exists... */
if ( exit ) {
/** Move character to exit target room */
await world.characterToRoom(user, exit.target());
/** Find the look command and execute it for this user */
world.commands().find(x => x.name() == `look`).execute()(world, user, ``, []);
}
/** Otherwise, send error */
else {
user.send(`You cannot go that way.\r\n`);
}
},
priority: [`se`, `sw`, `ne`, `nw`, `northeast`, `southeast`, `southwest`, `northwest`].includes(direction) ? 0 : 999
});
};
return [
directionCommand(`north`),
directionCommand(`northeast`),
directionCommand(`ne`),
directionCommand(`east`),
directionCommand(`southeast`),
directionCommand(`se`),
directionCommand(`south`),
directionCommand(`southwest`),
directionCommand(`sw`),
directionCommand(`west`),
directionCommand(`northwest`),
directionCommand(`nw`),
directionCommand(`up`),
directionCommand(`down`)
];
};