assassin-bug/src/engine/commands/look.js

41 lines
1.2 KiB
JavaScript
Raw Normal View History

2025-07-18 18:41:49 +00:00
import CommandBuilder from "../builders/command";
function lookHandler(args, context) {
2021-11-04 21:19:50 +00:00
if (args.length == 1) {
2021-11-04 19:58:37 +00:00
context.examineRoom();
} else {
const room = context.getRoom(context.player.currentRoom);
const items = room.getItems();
let item = null;
for (let i of items) {
if (i.name.includes(args[1])) {
item = i;
break;
}
}
2021-11-05 22:22:28 +00:00
if (!item) {
const items = context.player.getInventory();
for (let i of items) {
if (i.name.includes(args[1])) {
item = i;
break;
}
}
}
2021-11-04 19:58:37 +00:00
if (!item) {
2021-11-05 13:28:01 +00:00
context.output.say(`I could not find a ${args[1]}.`);
2021-11-04 19:58:37 +00:00
} else {
2021-11-05 22:22:28 +00:00
context.output.say(`You look at ${item.name}.`);
2021-11-04 19:58:37 +00:00
context.output.say(item.description);
}
}
2025-07-18 14:33:56 +00:00
}
2025-07-18 18:41:49 +00:00
export default new CommandBuilder()
.withName("look")
.withAliases(["l"])
.withCategory("Actions")
.withDescription("Examine room or object")
.withArgument("item", "target", true, "Object to examine")
.withHandler(lookHandler)
.create();