mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-18 14:34:04 +09:00
WIP inventory implementation
Former-commit-id: ce7d2125209c2c4f49b7d755b068ce72387f5e8f Former-commit-id: f413b2699ee7448f3d3b70775ca7b679ade66475
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameitem.InventoryItem
|
||||
import net.torvald.terrarum.itemproperties.ItemPropCodex
|
||||
import java.util.*
|
||||
@@ -21,7 +22,7 @@ class ActorInventory() {
|
||||
private var capacityMode: Int
|
||||
|
||||
/**
|
||||
* HashMap<ReferenceID, Amounts>
|
||||
* HashMap<ReferenceID, Amounts>
|
||||
*/
|
||||
private val itemList: HashMap<Int, Int> = HashMap()
|
||||
|
||||
@@ -78,6 +79,8 @@ class ActorInventory() {
|
||||
return itemList
|
||||
}
|
||||
|
||||
fun forEach(consumer: (Int, Int) -> Unit) = itemList.forEach(consumer)
|
||||
|
||||
/**
|
||||
* Get clone of the itemList
|
||||
* @return
|
||||
@@ -97,6 +100,9 @@ class ActorInventory() {
|
||||
return weight
|
||||
}
|
||||
|
||||
/**
|
||||
* Real amount
|
||||
*/
|
||||
fun getTotalCount(): Int {
|
||||
var count = 0
|
||||
|
||||
@@ -107,26 +113,26 @@ class ActorInventory() {
|
||||
return count
|
||||
}
|
||||
|
||||
/**
|
||||
* Unique amount, multiple items are calculated as one
|
||||
*/
|
||||
fun getTotalUniqueCount(): Int {
|
||||
return itemList.entries.size
|
||||
}
|
||||
|
||||
fun appendToPocket(item: InventoryItem) {
|
||||
appendToPocket(item, 1)
|
||||
fun add(item: InventoryItem) {
|
||||
add(item, 1)
|
||||
}
|
||||
|
||||
fun appendToPocket(item: InventoryItem, count: Int) {
|
||||
fun add(item: InventoryItem, count: Int) {
|
||||
val key = item.itemID
|
||||
|
||||
// if (key == Player.PLAYER_REF_ID)
|
||||
// throw new IllegalArgumentException("Attempted to put player into the inventory.");
|
||||
if (key == Player.PLAYER_REF_ID || key == Terrarum.ingame.player.referenceID)
|
||||
throw IllegalArgumentException("Attempted to put active player or human player into the inventory.")
|
||||
|
||||
if (itemList.containsKey(key))
|
||||
// increment amount if it already has specified item
|
||||
itemList.put(key, itemList[key]!! + count)
|
||||
else
|
||||
// add new entry if it does not have specified item
|
||||
itemList.put(key, count)
|
||||
// If we already have the item, increment the amount
|
||||
// If not, add item with specified amount
|
||||
itemList.put(key, itemList[key] ?: 0 + count)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.torvald.terrarum.gameactors
|
||||
|
||||
import net.torvald.terrarum.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.gameitem.InventoryItem
|
||||
import net.torvald.terrarum.gameitem.InventoryItemAdapter
|
||||
import org.luaj.vm2.Globals
|
||||
import org.luaj.vm2.LoadState
|
||||
import org.luaj.vm2.LuaError
|
||||
@@ -39,7 +40,7 @@ open class HumanoidNPC(aiFile: String, born: GameDate) : ActorHumanoid(born), AI
|
||||
}
|
||||
|
||||
// we're having InventoryItem data so that this class could be somewhat universal
|
||||
override var itemData: InventoryItem = object : InventoryItem {
|
||||
override var itemData: InventoryItem = object : InventoryItemAdapter() {
|
||||
override var itemID = referenceID
|
||||
|
||||
override var mass: Double
|
||||
@@ -54,30 +55,9 @@ open class HumanoidNPC(aiFile: String, born: GameDate) : ActorHumanoid(born), AI
|
||||
actorValue[AVKey.SCALE] = value
|
||||
}
|
||||
|
||||
override fun effectWhileInPocket(gc: GameContainer, delta: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun effectWhenPickedUp(gc: GameContainer, delta: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun primaryUse(gc: GameContainer, delta: Int) {
|
||||
// TODO do not allow primary_use
|
||||
}
|
||||
|
||||
override fun secondaryUse(gc: GameContainer, delta: Int) {
|
||||
// TODO place this Actor to the world
|
||||
}
|
||||
|
||||
override fun effectWhenThrown(gc: GameContainer, delta: Int) {
|
||||
}
|
||||
|
||||
override fun effectWhenTakenOut(gc: GameContainer, delta: Int) {
|
||||
}
|
||||
|
||||
override fun worldActorEffect(gc: GameContainer, delta: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemWeight(): Double {
|
||||
|
||||
@@ -55,7 +55,7 @@ object PlayerBuilderSigrid {
|
||||
|
||||
p.actorValue[AVKey.INTELLIGENT] = true
|
||||
|
||||
p.actorValue[AVKey.LUMINOSITY] = 0//95487100
|
||||
p.actorValue[AVKey.LUMINOSITY] = 95487100
|
||||
|
||||
p.actorValue[AVKey.BASEDEFENCE] = 141
|
||||
|
||||
@@ -71,6 +71,14 @@ object PlayerBuilderSigrid {
|
||||
|
||||
p.faction.add(FactionFactory.create("FactionSigrid.json"))
|
||||
|
||||
|
||||
|
||||
// Test fill up inventory
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return p
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user