1 | exports.command = {
|
2 | name: "destroy",
|
3 | autoload: true,
|
4 | unloadable: true,
|
5 | min_rank: 6,
|
6 | display: "destroys a nearby place",
|
7 | help: ".destroy <direction> will destroy a nearby place, in <direction>'s direction. More info about directions in .file directions.",
|
8 | usage: ".destroy <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: ") + ".destroy <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(chalk.bold(direction) + " " + chalk.red("is not a valid direction.\r\n"));
|
34 | return;
|
35 | }
|
36 |
|
37 | var neighbours = command_access.getUniverse().get_neighbours(
|
38 | command_access.getUniverse().get(socket.db.where));
|
39 | var target = socket.db.where.slice(0);
|
40 | if (direction.search("W") !== -1) target[0]--;
|
41 | if (direction.search("E") !== -1) target[0]++;
|
42 | if (direction.search("N") !== -1) target[1]++;
|
43 | if (direction.search("S") !== -1) target[1]--;
|
44 | if (direction.search("U") !== -1) target[2]++;
|
45 | if (direction.search("D") !== -1) target[2]--;
|
46 | if (target.toString() === command_access.getUniverse().entrypoint.toString()) {
|
47 | socket.write(chalk.red("You cannot destroy the portal to this Universe!\r\n"));
|
48 | return;
|
49 | }
|
50 | targObj = command_access.getUniverse().get(target);
|
51 | if (targObj === null) {
|
52 | socket.write(chalk.red("There's nothing there to be destroyed!\r\n"));
|
53 | return;
|
54 | }
|
55 | if (!command_access.getUniverse().nuke(target)) {
|
56 |
|
57 | socket.write(chalk.red("You should have been able to destroy " + direction +
|
58 | " from here. However, that didn't work. " + chalk.bold("Please let an " +
|
59 | command_access.ranks.list[command_access.ranks.list.length - 1] +
|
60 | " know about this!\r\n")));
|
61 | return;
|
62 | }
|
63 |
|
64 | command_access.saveUniverse();
|
65 | socket.write(chalk.yellow(":: ") + "You destroyed " + chalk.bold(direction) +
|
66 | ", hopefully knowing what you're doing.\r\n");
|
67 | }
|
68 | }
|