mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 04:24:05 +09:00
WIP inventory implementation
Former-commit-id: ce7d2125209c2c4f49b7d755b068ce72387f5e8f Former-commit-id: f413b2699ee7448f3d3b70775ca7b679ade66475
This commit is contained in:
@@ -18,7 +18,7 @@ class CodexEdictis : ConsoleCommand {
|
||||
}
|
||||
else {
|
||||
try {
|
||||
val commandObj = CommandDict.get(args[1].toLowerCase())
|
||||
val commandObj = CommandDict[args[1].toLowerCase()]
|
||||
commandObj.printUsage()
|
||||
}
|
||||
catch (e: NullPointerException) {
|
||||
|
||||
@@ -40,6 +40,7 @@ object CommandDict {
|
||||
Pair("seed", Seed()),
|
||||
Pair("testgetlight", TestGetLight()),
|
||||
Pair("println", EchoConsole()),
|
||||
Pair("inventory", Inventory()),
|
||||
|
||||
// Test codes
|
||||
Pair("bulletintest", SetBulletin()),
|
||||
|
||||
65
src/net/torvald/terrarum/console/Inventory.kt
Normal file
65
src/net/torvald/terrarum/console/Inventory.kt
Normal file
@@ -0,0 +1,65 @@
|
||||
package net.torvald.terrarum.console
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.ActorInventory
|
||||
import net.torvald.terrarum.gameactors.Player
|
||||
import net.torvald.terrarum.gameactors.Pocketed
|
||||
import net.torvald.terrarum.itemproperties.ItemPropCodex
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2016-12-12.
|
||||
*/
|
||||
class Inventory : ConsoleCommand {
|
||||
|
||||
private var target: ActorInventory = Terrarum.ingame.player.inventory
|
||||
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 1) {
|
||||
printUsage()
|
||||
} else {
|
||||
when (args[1]) {
|
||||
"list" -> listInventory()
|
||||
"add" -> addItem(args[2].toInt(), args[3].toInt())
|
||||
"target" -> setTarget(args[2].toInt())
|
||||
"assign" -> assignQuickBar(args[2].toInt(), args[3].toInt())
|
||||
else -> printUsage()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun listInventory() {
|
||||
if (target.getTotalUniqueCount() == 0) {
|
||||
Echo().execute("(inventory empty)")
|
||||
} else {
|
||||
target.forEach { refId, amount ->
|
||||
if (amount == 0) {
|
||||
Error().execute("Unexpected zero-amounted item: ID $refId")
|
||||
}
|
||||
Echo().execute("ID $refId${if (amount > 1) " ($amount)" else ""}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setTarget(actorRefId: Int = Player.PLAYER_REF_ID) {
|
||||
val actor = Terrarum.ingame.getActorByID(actorRefId)
|
||||
if (actor !is Pocketed) {
|
||||
Error().execute("Cannot edit inventory of incompatible actor: $actor")
|
||||
} else {
|
||||
target = actor.inventory
|
||||
}
|
||||
}
|
||||
|
||||
private fun addItem(refId: Int, amount: Int = 1) {
|
||||
target.add(ItemPropCodex.getProp(refId), amount)
|
||||
}
|
||||
|
||||
private fun assignQuickBar(refId: Int, index: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo().execute("Usage: inventory command arguments")
|
||||
Echo().execute("Available commands:")
|
||||
Echo().execute("list | assign slot | add itemid [amount] | target [actorid]")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user