UNPKG

2.04 kBJavaScriptView Raw
1exports.command = {
2 name: "look", // Name of command to be executed (Max 10 chars)
3 autoload: true, // Should the command be autoloaded at startup
4 unloadable: true, // Can the command be unloaded dynamically
5 min_rank: 0, // Minimum rank to use to execute the command
6 display: "You look.",
7 help: "You figure out where you are and where to can you go.",
8 usage: ".look",
9
10 // Function to execute the command
11 execute: function(socket, command, command_access) {
12 var chalk = require('chalk');
13 socket.write(chalk.green(":: ") + "You look around...\r\n");
14 socket.write(chalk.green(":: ") + "You notice you are at " +
15 chalk.cyan(command_access.getUniverse().get(socket.db.where).name) + ".\r\n");
16 // look for other people
17 var others = [];
18 for (var i = 0; i < command_access.sockets.length; i++) {
19 if (
20 command_access.sockets[i].loggedin &&
21 command_access.sockets[i].db.where.toString() ==
22 socket.db.where.toString() &&
23 command_access.sockets[i].username !== socket.username
24 ) {
25 others.push(command_access.sockets[i].username);
26 }
27 }
28 if (others.length > 0) {
29 var peeps = chalk.green(":: ") + "You see " + chalk.yellow(others[0]);
30 if (others.length === 1) {
31 peeps += ".";
32 } else {
33 for (var p = 1; p < others.length-1; p++) {
34 peeps += ", " + chalk.yellow(others[p]);
35 }
36 peeps += " and " + chalk.yellow(others[others.length-1]) + ".";
37 }
38 socket.write(peeps + "\r\n");
39 } else {
40 socket.write(chalk.green(":: ") + "You are alone here.\r\n");
41 }
42
43 // look for exits
44 var neighbours = command_access.getUniverse().get_neighbours(
45 command_access.getUniverse().get(socket.db.where));
46 if (neighbours.length == 0) {
47 socket.write(chalk.green(":: ") + "You don't see anywhere to go to.\r\n");
48 } else {
49 socket.write(chalk.green(":: ") + "You see " + chalk.bold(neighbours.length) + " passages:\r\n ");
50 for (var i=0; i < neighbours.length; i++) {
51 socket.write(chalk.green(neighbours[i].name) + " ");
52 }
53 socket.write("\r\n");
54 }
55 }
56}