Inventory now stores objects instead of item IDs

Former-commit-id: 6d7397fe82c986a3ac48ce86fe9fa75a354cf5d3
Former-commit-id: 46b759e0707fe2f7cb207e215708118034aff4f4
This commit is contained in:
Song Minjae
2016-12-16 23:02:21 +09:00
parent fe994621c0
commit 4552d7b7db
3 changed files with 54 additions and 34 deletions

View File

@@ -21,7 +21,8 @@ internal object Inventory : ConsoleCommand {
else {
when (args[1]) {
"list" -> listInventory()
"add" -> addItem(args[2].toInt(), args[3].toInt())
"add" -> if (args.size > 3) addItem(args[2].toInt(), args[3].toInt())
else addItem(args[2].toInt())
"target" -> setTarget(args[2].toInt())
"equip" -> equipItem(args[2].toInt())
else -> printUsage()
@@ -54,11 +55,11 @@ internal object Inventory : ConsoleCommand {
}
private fun addItem(refId: Int, amount: Int = 1) {
target.inventory.add(ItemPropCodex.getProp(refId), amount)
target.inventory.add(ItemPropCodex[refId], amount)
}
private fun equipItem(refId: Int) {
val item = ItemPropCodex.getProp(refId)
val item = ItemPropCodex[refId]
// if the item does not exist, add it first
if (!target.inventory.contains(item)) {