Add loading functionality

This commit is contained in:
2021-11-05 23:22:28 +01:00
parent 6d0548455e
commit 9e95b4c202
6 changed files with 80 additions and 15 deletions

View File

@@ -0,0 +1,15 @@
export default function InventoryCommand(args, context) {
const items = context.player.getInventory();
if (items.length < 1) return context.print(`You're not carrying anything.`);
let itemDescription = `You are carrying `;
items.forEach((item, index) => {
if (index < items.length - 2) {
itemDescription += `${item.name}, `;
} else if (index < items.length - 1) {
itemDescription += `${item.name} and `;
} else {
itemDescription += item.name
}
});
context.print(itemDescription + ".");
}

View File

@@ -11,10 +11,19 @@ export default function LookCommand(args, context) {
break;
}
}
if (!item) {
const items = context.player.getInventory();
for (let i of items) {
if (i.name.includes(args[1])) {
item = i;
break;
}
}
}
if (!item) {
context.output.say(`I could not find a ${args[1]}.`);
} else {
context.output.say(item.name);
context.output.say(`You look at ${item.name}.`);
context.output.say(item.description);
}
}