1 | exports.command = {
|
2 | name: "close",
|
3 | autoload: true,
|
4 | unloadable: true,
|
5 | min_rank: 6,
|
6 | display: "closes an existent passage",
|
7 | help: ".close <direction> will close the passage in that direction. More info about directions in .file directions.",
|
8 | usage: ".close <direction>",
|
9 | weigth: 0,
|
10 |
|
11 |
|
12 | execute: function(socket, command, command_access) {
|
13 | var chalk = require('chalk');
|
14 | direction = command.split(' ')[0];
|
15 |
|
16 | if (typeof direction !== 'string' || direction.length === 0) {
|
17 | socket.write(chalk.bold("Syntax:") + " .close <direction>\r\n");
|
18 | return;
|
19 | }
|
20 |
|
21 |
|
22 |
|
23 | valid = false;
|
24 | if (direction.toUpperCase() === direction) {
|
25 | for (var i in command_access.getUniverse()) {
|
26 | if (i === direction &&
|
27 | typeof command_access.getUniverse()[i] === 'number'
|
28 | )
|
29 | valid = true;
|
30 | }
|
31 | }
|
32 | if (!valid) {
|
33 | socket.write(direction + " is not a valid direction.\r\n");
|
34 | return;
|
35 | }
|
36 | var updateMe = command_access.getUniverse().get(socket.db.where);
|
37 |
|
38 | var newPassage = eval("command_access.getUniverse()."+direction);
|
39 | if ((updateMe.passages & newPassage) !== newPassage) {
|
40 | socket.write("You cannot close a passage that doesn't exist!\r\n");
|
41 | return;
|
42 | }
|
43 | updateMe.passages -= newPassage;
|
44 | if (!command_access.getUniverse().update(updateMe)) {
|
45 | socket.write("You should have been able to destroy that passage. However, " +
|
46 | "that didn't work. Please let a " +
|
47 | command_access.ranks.list[
|
48 | command_access.ranks.list.length - 1
|
49 | ] + " know about this!\r\n");
|
50 | } else {
|
51 | socket.write("You closed the passage.\r\n");
|
52 | }
|
53 |
|
54 | command_access.saveUniverse();
|
55 | socket.write(":: You closed the passage towards " + chalk.bold(direction) + ".\r\n");
|
56 | }
|
57 | }
|