mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 03:24:06 +09:00
inventory: saving ID only, most things still work
This commit is contained in:
@@ -9,6 +9,7 @@ import net.torvald.terrarum.gameactors.*
|
||||
import net.torvald.terrarum.gameactors.faction.Faction
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.itemproperties.Material
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.time_t
|
||||
@@ -208,10 +209,10 @@ open class ActorHumanoid(
|
||||
// update inventory items
|
||||
inventory.forEach {
|
||||
if (!inventory.itemEquipped.contains(it.item)) { // unequipped
|
||||
it.item.effectWhileInPocket(delta)
|
||||
ItemCodex[it.item]!!.effectWhileInPocket(delta)
|
||||
}
|
||||
else { // equipped
|
||||
it.item.effectWhenEquipped(delta)
|
||||
ItemCodex[it.item]!!.effectWhenEquipped(delta)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -590,7 +591,7 @@ open class ActorHumanoid(
|
||||
// quickslot implementation
|
||||
if (key == AVKey.__PLAYER_QUICKSLOTSEL && value != null) {
|
||||
// ONLY FOR HAND_GRIPs!!
|
||||
val quickBarItem = inventory.getQuickslot(actorValue.getAsInt(key)!!)?.item
|
||||
val quickBarItem = ItemCodex[inventory.getQuickslot(actorValue.getAsInt(key)!!)?.item]
|
||||
|
||||
if (quickBarItem != null && quickBarItem.equipPosition == GameItem.EquipPosition.HAND_GRIP) {
|
||||
equipItem(quickBarItem)
|
||||
|
||||
@@ -33,7 +33,7 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
|
||||
/**
|
||||
* List of all equipped items (tools, armours, rings, necklaces, etc.)
|
||||
*/
|
||||
val itemEquipped = Array<GameItem?>(GameItem.EquipPosition.INDEX_MAX) { null }
|
||||
val itemEquipped = Array<ItemID?>(GameItem.EquipPosition.INDEX_MAX) { null }
|
||||
|
||||
/**
|
||||
* Sorted by referenceID.
|
||||
@@ -46,7 +46,7 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
|
||||
init {
|
||||
}
|
||||
|
||||
fun add(itemID: ItemID, count: Int = 1) = add(ItemCodex[itemID], count)
|
||||
fun add(itemID: ItemID, count: Int = 1) = add(ItemCodex[itemID]!!, count)
|
||||
fun add(item: GameItem, count: Int = 1) {
|
||||
|
||||
println("[ActorInventory] add $item, $count")
|
||||
@@ -86,12 +86,12 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
|
||||
}
|
||||
// new item
|
||||
else {
|
||||
itemList.add(InventoryPair(item, count))
|
||||
itemList.add(InventoryPair(item.dynamicID, count))
|
||||
}
|
||||
insertionSortLastElem(itemList)
|
||||
}
|
||||
|
||||
fun remove(itemID: ItemID, count: Int) = remove(ItemCodex[itemID], count)
|
||||
fun remove(itemID: ItemID, count: Int) = remove(ItemCodex[itemID]!!, count)
|
||||
/** Will check existence of the item using its Dynamic ID; careful with command order!
|
||||
* e.g. re-assign after this operation */
|
||||
fun remove(item: GameItem, count: Int = 1) {
|
||||
@@ -152,7 +152,7 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
|
||||
else
|
||||
getTotalCount().toDouble()
|
||||
|
||||
fun getTotalWeight(): Double = itemList.map { it.item.mass * it.amount }.sum()
|
||||
fun getTotalWeight(): Double = itemList.map { ItemCodex[it.item]!!.mass * it.amount }.sum()
|
||||
|
||||
/**
|
||||
* Real amount
|
||||
@@ -277,7 +277,10 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
|
||||
while (low <= high) {
|
||||
val mid = (low + high).ushr(1) // safe from overflows
|
||||
|
||||
val midVal = if (searchBy == STATIC_ID) this.get(mid).item.originalID else this.get(mid).item.dynamicID
|
||||
val midVal = if (searchBy == STATIC_ID)
|
||||
ItemCodex[this[mid].item]!!.originalID
|
||||
else
|
||||
ItemCodex[this[mid].item]!!.dynamicID
|
||||
|
||||
if (ID > midVal)
|
||||
low = mid + 1
|
||||
@@ -290,4 +293,4 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
|
||||
}
|
||||
}
|
||||
|
||||
data class InventoryPair(val item: GameItem, var amount: Int)
|
||||
data class InventoryPair(val item: ItemID, var amount: Int)
|
||||
@@ -1,10 +1,10 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
import net.torvald.terrarum.gameactors.ActorWBMovable
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-03-15.
|
||||
@@ -20,9 +20,9 @@ open class DroppedItem(private val item: GameItem) : ActorWBMovable(RenderOrder.
|
||||
avBaseMass = if (item.dynamicID < BlockCodex.MAX_TERRAIN_TILES)
|
||||
BlockCodex[item.dynamicID].density / 1000.0
|
||||
else
|
||||
ItemCodex[item.dynamicID].mass
|
||||
ItemCodex[item.dynamicID]!!.mass
|
||||
|
||||
scale = ItemCodex[item.dynamicID].scale
|
||||
scale = ItemCodex[item.dynamicID]!!.scale
|
||||
}
|
||||
|
||||
override fun update(delta: Float) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.gameactors.Actor
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.itemproperties.ItemID
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-01-15.
|
||||
@@ -31,6 +32,12 @@ interface Pocketed {
|
||||
item.effectOnUnequip(AppLoader.UPDATE_RATE.toFloat())
|
||||
}
|
||||
|
||||
fun unequipItem(itemID: ItemID?) {
|
||||
itemID?.let {
|
||||
unequipItem(ItemCodex[itemID])
|
||||
} ?: return
|
||||
}
|
||||
|
||||
// no need for equipSlot(Int)
|
||||
fun unequipSlot(slot: Int) {
|
||||
if (slot < 0 || slot > GameItem.EquipPosition.INDEX_MAX)
|
||||
@@ -49,19 +56,24 @@ interface Pocketed {
|
||||
}
|
||||
|
||||
if (item.equipPosition >= 0) {
|
||||
inventory.itemEquipped[item.equipPosition] = item
|
||||
inventory.itemEquipped[item.equipPosition] = item.dynamicID
|
||||
item.effectWhenEquipped(AppLoader.UPDATE_RATE.toFloat())
|
||||
}
|
||||
// else do nothing
|
||||
}
|
||||
|
||||
fun equipped(item: GameItem): Boolean {
|
||||
return inventory.itemEquipped[item.equipPosition] == item
|
||||
fun equipItem(itemID: ItemID) {
|
||||
equipItem(ItemCodex[itemID]!!)
|
||||
}
|
||||
|
||||
fun addItem(itemID: Int, count: Int = 1) = inventory.add(ItemCodex[itemID], count)
|
||||
fun equipped(item: GameItem): Boolean {
|
||||
return inventory.itemEquipped[item.equipPosition] == item.dynamicID
|
||||
}
|
||||
fun equipped(itemID: ItemID) = equipped(ItemCodex[itemID]!!)
|
||||
|
||||
fun addItem(itemID: Int, count: Int = 1) = inventory.add(ItemCodex[itemID]!!, count)
|
||||
fun addItem(item: GameItem, count: Int = 1) = inventory.add(item, count)
|
||||
fun removeItem(itemID: Int, count: Int = 1) = inventory.remove(ItemCodex[itemID], count)
|
||||
fun removeItem(itemID: Int, count: Int = 1) = inventory.remove(ItemCodex[itemID]!!, count)
|
||||
fun removeItem(item: GameItem, count: Int = 1) = inventory.remove(item, count)
|
||||
|
||||
fun hasItem(item: GameItem) = inventory.contains(item.dynamicID)
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-05-25.
|
||||
@@ -14,9 +15,9 @@ class ThreadActorUpdate(val startIndex: Int, val endIndex: Int) : Runnable {
|
||||
|
||||
if (it is Pocketed) {
|
||||
it.inventory.forEach { inventoryEntry ->
|
||||
inventoryEntry.item.effectWhileInPocket(AppLoader.UPDATE_RATE.toFloat())
|
||||
ItemCodex[inventoryEntry.item]?.effectWhileInPocket(AppLoader.UPDATE_RATE.toFloat())
|
||||
if (it.equipped(inventoryEntry.item)) {
|
||||
inventoryEntry.item.effectWhenEquipped(AppLoader.UPDATE_RATE.toFloat())
|
||||
ItemCodex[inventoryEntry.item]?.effectWhenEquipped(AppLoader.UPDATE_RATE.toFloat())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user