Take, drop and command echo

This commit is contained in:
2021-11-04 22:47:09 +01:00
parent abb3c475db
commit 37759d7b9f
8 changed files with 75 additions and 3 deletions

View File

@@ -0,0 +1,19 @@
export default function DropCommand(args, context) {
const room = context.getRoom(context.player.currentRoom);
const items = context.player.getInventory();
let item = null;
for (let i of items) {
if (i.name.includes(args[1])) {
item = i;
break;
}
}
if (!item) {
context.print(`You're not carrying a ${args[1]}`);
} else {
context.player.removeItem(item.id);
room.addItem(item.id);
context.print(`You set ${item.name} down on the floor.`);
item.onDrop();
}
}

View File

@@ -0,0 +1,23 @@
export default function TakeCommand(args, context) {
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;
}
}
if (!item) {
context.print(`You can't find any ${args[1]}`);
} else {
if (!item.takeable) {
context.print(`You can't take ${item.name}`);
} else {
room.removeItem(item.id);
context.player.addItem(item.id);
context.print(`You take ${item.name}`);
item.onTake();
}
}
}