mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-15 16:16:10 +09:00
inventory: saving ID only, most things still work
This commit is contained in:
@@ -7,6 +7,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
|||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import net.torvald.colourutil.CIELabUtil.darkerLab
|
import net.torvald.colourutil.CIELabUtil.darkerLab
|
||||||
import net.torvald.terrarum.itemproperties.GameItem
|
import net.torvald.terrarum.itemproperties.GameItem
|
||||||
|
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||||
import net.torvald.terrarum.modulebasegame.Ingame
|
import net.torvald.terrarum.modulebasegame.Ingame
|
||||||
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull
|
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull
|
||||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellBase
|
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellBase
|
||||||
@@ -147,12 +148,12 @@ class UIItemInventoryElem(
|
|||||||
|
|
||||||
val inventory = player.inventory
|
val inventory = player.inventory
|
||||||
val slot = if (keycode == Input.Keys.NUM_0) 9 else keycode - Input.Keys.NUM_1
|
val slot = if (keycode == Input.Keys.NUM_0) 9 else keycode - Input.Keys.NUM_1
|
||||||
val currentSlotItem = inventory?.getQuickslot(slot)
|
val currentSlotItem = inventory.getQuickslot(slot)
|
||||||
|
|
||||||
|
|
||||||
inventory.setQuickBar(
|
inventory.setQuickBar(
|
||||||
slot,
|
slot,
|
||||||
if (currentSlotItem?.item != item)
|
if (currentSlotItem?.item != item?.dynamicID)
|
||||||
item?.dynamicID // register
|
item?.dynamicID // register
|
||||||
else
|
else
|
||||||
null // drop registration
|
null // drop registration
|
||||||
@@ -161,7 +162,7 @@ class UIItemInventoryElem(
|
|||||||
// search for duplicates in the quickbar, except mine
|
// search for duplicates in the quickbar, except mine
|
||||||
// if there is, unregister the other
|
// if there is, unregister the other
|
||||||
(0..9).minus(slot).forEach {
|
(0..9).minus(slot).forEach {
|
||||||
if (inventory.getQuickslot(it)?.item == item) {
|
if (inventory.getQuickslot(it)?.item == item?.dynamicID) {
|
||||||
inventory.setQuickBar(it, null)
|
inventory.setQuickBar(it, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,7 +184,7 @@ class UIItemInventoryElem(
|
|||||||
|
|
||||||
if (player == null) return false
|
if (player == null) return false
|
||||||
|
|
||||||
if (item != player.inventory.itemEquipped.get(itemEquipSlot)) { // if this item is unequipped, equip it
|
if (item != ItemCodex[player.inventory.itemEquipped.get(itemEquipSlot)]) { // if this item is unequipped, equip it
|
||||||
player.equipItem(item!!)
|
player.equipItem(item!!)
|
||||||
}
|
}
|
||||||
else { // if not, unequip it
|
else { // if not, unequip it
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.Color
|
|||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import net.torvald.terrarum.itemproperties.GameItem
|
import net.torvald.terrarum.itemproperties.GameItem
|
||||||
|
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||||
import net.torvald.terrarum.modulebasegame.Ingame
|
import net.torvald.terrarum.modulebasegame.Ingame
|
||||||
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull
|
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull
|
||||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellBase
|
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellBase
|
||||||
@@ -137,7 +138,7 @@ class UIItemInventoryElemSimple(
|
|||||||
|
|
||||||
inventory.setQuickBar(
|
inventory.setQuickBar(
|
||||||
slot,
|
slot,
|
||||||
if (currentSlotItem?.item != item)
|
if (currentSlotItem?.item != item?.dynamicID)
|
||||||
item?.dynamicID // register
|
item?.dynamicID // register
|
||||||
else
|
else
|
||||||
null // drop registration
|
null // drop registration
|
||||||
@@ -146,7 +147,7 @@ class UIItemInventoryElemSimple(
|
|||||||
// search for duplicates in the quickbar, except mine
|
// search for duplicates in the quickbar, except mine
|
||||||
// if there is, unregister the other
|
// if there is, unregister the other
|
||||||
(0..9).minus(slot).forEach {
|
(0..9).minus(slot).forEach {
|
||||||
if (inventory.getQuickslot(it)?.item == item) {
|
if (inventory.getQuickslot(it)?.item == item?.dynamicID) {
|
||||||
inventory.setQuickBar(it, null)
|
inventory.setQuickBar(it, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,7 +166,7 @@ class UIItemInventoryElemSimple(
|
|||||||
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
|
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
|
||||||
if (player == null) return false
|
if (player == null) return false
|
||||||
|
|
||||||
if (item != player.inventory.itemEquipped.get(itemEquipSlot)) { // if this item is unequipped, equip it
|
if (item != ItemCodex[player.inventory.itemEquipped.get(itemEquipSlot)]) { // if this item is unequipped, equip it
|
||||||
player.equipItem(item!!)
|
player.equipItem(item!!)
|
||||||
}
|
}
|
||||||
else { // if not, unequip it
|
else { // if not, unequip it
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import net.torvald.terrarum.floorInt
|
|||||||
import net.torvald.terrarum.gameactors.AVKey
|
import net.torvald.terrarum.gameactors.AVKey
|
||||||
import net.torvald.terrarum.gameworld.fmod
|
import net.torvald.terrarum.gameworld.fmod
|
||||||
import net.torvald.terrarum.itemproperties.GameItem
|
import net.torvald.terrarum.itemproperties.GameItem
|
||||||
|
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||||
import net.torvald.terrarum.modulebasegame.Ingame
|
import net.torvald.terrarum.modulebasegame.Ingame
|
||||||
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
|
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
|
||||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||||
@@ -66,10 +67,10 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
|
|||||||
|
|
||||||
itemOnGrip?.let {
|
itemOnGrip?.let {
|
||||||
if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary"))) {
|
if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary"))) {
|
||||||
player.consumePrimary(it)
|
player.consumePrimary(ItemCodex[it]!!)
|
||||||
}
|
}
|
||||||
if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary"))) {
|
if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary"))) {
|
||||||
player.consumeSecondary(it)
|
player.consumeSecondary(ItemCodex[it]!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -248,17 +248,20 @@ object ItemCodex {
|
|||||||
* Returns the item in the Codex. If the item is static, its clone will be returned (you are free to modify the returned item).
|
* Returns the item in the Codex. If the item is static, its clone will be returned (you are free to modify the returned item).
|
||||||
* However, if the item is dynamic, the item itself will be returned. Modifying the item will affect the game.
|
* However, if the item is dynamic, the item itself will be returned. Modifying the item will affect the game.
|
||||||
*/
|
*/
|
||||||
operator fun get(code: ItemID): GameItem {
|
operator fun get(code: ItemID?): GameItem? {
|
||||||
|
if (code == null) return null
|
||||||
|
|
||||||
if (code <= ITEM_STATIC.endInclusive) // generic item
|
if (code <= ITEM_STATIC.endInclusive) // generic item
|
||||||
return itemCodex[code]!!.clone() // from CSV
|
return itemCodex[code]!!.clone() // from CSV
|
||||||
else if (code <= ITEM_DYNAMIC.endInclusive) {
|
else if (code <= ITEM_DYNAMIC.endInclusive) {
|
||||||
return itemCodex[code]!!
|
return dynamicItemDescription[code]!!
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val a = (Terrarum.ingame!! as Ingame).getActorByID(code) // actor item
|
val a = (Terrarum.ingame!! as Ingame).getActorByID(code) // actor item
|
||||||
if (a is CanBeAnItem) return a.itemData
|
if (a is CanBeAnItem) return a.itemData
|
||||||
|
|
||||||
throw IllegalArgumentException("Attempted to get item data of actor that cannot be an item. ($a)")
|
return null
|
||||||
|
//throw IllegalArgumentException("Attempted to get item data of actor that cannot be an item. ($a)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import net.torvald.terrarum.gamecontroller.IngameController
|
|||||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
import net.torvald.terrarum.itemproperties.GameItem
|
import net.torvald.terrarum.itemproperties.GameItem
|
||||||
|
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||||
import net.torvald.terrarum.modulebasegame.console.AVTracker
|
import net.torvald.terrarum.modulebasegame.console.AVTracker
|
||||||
import net.torvald.terrarum.modulebasegame.console.ActorsList
|
import net.torvald.terrarum.modulebasegame.console.ActorsList
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.*
|
import net.torvald.terrarum.modulebasegame.gameactors.*
|
||||||
@@ -392,22 +393,22 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
override fun worldPrimaryClickStart(delta: Float) {
|
override fun worldPrimaryClickStart(delta: Float) {
|
||||||
val itemOnGrip = actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)
|
val itemOnGrip = actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)
|
||||||
itemOnGrip?.startPrimaryUse(delta)
|
ItemCodex[itemOnGrip]?.startPrimaryUse(delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun worldPrimaryClickEnd(delta: Float) {
|
override fun worldPrimaryClickEnd(delta: Float) {
|
||||||
val itemOnGrip = actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)
|
val itemOnGrip = actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)
|
||||||
itemOnGrip?.endPrimaryUse(delta)
|
ItemCodex[itemOnGrip]?.endPrimaryUse(delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun worldSecondaryClickStart(delta: Float) {
|
override fun worldSecondaryClickStart(delta: Float) {
|
||||||
val itemOnGrip = actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)
|
val itemOnGrip = actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)
|
||||||
itemOnGrip?.startSecondaryUse(delta)
|
ItemCodex[itemOnGrip]?.startSecondaryUse(delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun worldSecondaryClickEnd(delta: Float) {
|
override fun worldSecondaryClickEnd(delta: Float) {
|
||||||
val itemOnGrip = actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)
|
val itemOnGrip = actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)
|
||||||
itemOnGrip?.endSecondaryUse(delta)
|
ItemCodex[itemOnGrip]?.endSecondaryUse(delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -671,9 +672,9 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
if (it is Pocketed) {
|
if (it is Pocketed) {
|
||||||
it.inventory.forEach { inventoryEntry ->
|
it.inventory.forEach { inventoryEntry ->
|
||||||
inventoryEntry.item.effectWhileInPocket(delta)
|
ItemCodex[inventoryEntry.item]!!.effectWhileInPocket(delta)
|
||||||
if (it.equipped(inventoryEntry.item)) {
|
if (it.equipped(inventoryEntry.item)) {
|
||||||
inventoryEntry.item.effectWhenEquipped(delta)
|
ItemCodex[inventoryEntry.item]!!.effectWhenEquipped(delta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import net.torvald.terrarum.Terrarum
|
|||||||
import net.torvald.terrarum.console.ConsoleCommand
|
import net.torvald.terrarum.console.ConsoleCommand
|
||||||
import net.torvald.terrarum.console.Echo
|
import net.torvald.terrarum.console.Echo
|
||||||
import net.torvald.terrarum.console.EchoError
|
import net.torvald.terrarum.console.EchoError
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
|
|
||||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||||
import net.torvald.terrarum.modulebasegame.Ingame
|
import net.torvald.terrarum.modulebasegame.Ingame
|
||||||
|
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2016-12-12.
|
* Created by minjaesong on 2016-12-12.
|
||||||
@@ -39,7 +39,7 @@ internal object Inventory : ConsoleCommand {
|
|||||||
else {
|
else {
|
||||||
target!!.inventory.forEach { val (item, amount) = it
|
target!!.inventory.forEach { val (item, amount) = it
|
||||||
if (amount == 0) {
|
if (amount == 0) {
|
||||||
EchoError("Unexpected zero-amounted item: ID ${item.dynamicID}")
|
EchoError("Unexpected zero-amounted item: ID $item")
|
||||||
}
|
}
|
||||||
Echo("ID $item${if (amount > 1) " ($amount)" else ""}")
|
Echo("ID $item${if (amount > 1) " ($amount)" else ""}")
|
||||||
}
|
}
|
||||||
@@ -59,13 +59,13 @@ internal object Inventory : ConsoleCommand {
|
|||||||
|
|
||||||
private fun addItem(refId: Int, amount: Int = 1) {
|
private fun addItem(refId: Int, amount: Int = 1) {
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
target!!.addItem(ItemCodex[refId], amount)
|
target!!.addItem(ItemCodex[refId]!!, amount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun equipItem(refId: Int) {
|
private fun equipItem(refId: Int) {
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
val item = ItemCodex[refId]
|
val item = ItemCodex[refId]!!
|
||||||
target!!.equipItem(item)
|
target!!.equipItem(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import net.torvald.terrarum.gameactors.*
|
|||||||
import net.torvald.terrarum.gameactors.faction.Faction
|
import net.torvald.terrarum.gameactors.faction.Faction
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
import net.torvald.terrarum.itemproperties.GameItem
|
import net.torvald.terrarum.itemproperties.GameItem
|
||||||
|
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||||
import net.torvald.terrarum.itemproperties.Material
|
import net.torvald.terrarum.itemproperties.Material
|
||||||
import net.torvald.terrarum.modulebasegame.Ingame
|
import net.torvald.terrarum.modulebasegame.Ingame
|
||||||
import net.torvald.terrarum.modulebasegame.gameworld.time_t
|
import net.torvald.terrarum.modulebasegame.gameworld.time_t
|
||||||
@@ -208,10 +209,10 @@ open class ActorHumanoid(
|
|||||||
// update inventory items
|
// update inventory items
|
||||||
inventory.forEach {
|
inventory.forEach {
|
||||||
if (!inventory.itemEquipped.contains(it.item)) { // unequipped
|
if (!inventory.itemEquipped.contains(it.item)) { // unequipped
|
||||||
it.item.effectWhileInPocket(delta)
|
ItemCodex[it.item]!!.effectWhileInPocket(delta)
|
||||||
}
|
}
|
||||||
else { // equipped
|
else { // equipped
|
||||||
it.item.effectWhenEquipped(delta)
|
ItemCodex[it.item]!!.effectWhenEquipped(delta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -590,7 +591,7 @@ open class ActorHumanoid(
|
|||||||
// quickslot implementation
|
// quickslot implementation
|
||||||
if (key == AVKey.__PLAYER_QUICKSLOTSEL && value != null) {
|
if (key == AVKey.__PLAYER_QUICKSLOTSEL && value != null) {
|
||||||
// ONLY FOR HAND_GRIPs!!
|
// 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) {
|
if (quickBarItem != null && quickBarItem.equipPosition == GameItem.EquipPosition.HAND_GRIP) {
|
||||||
equipItem(quickBarItem)
|
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.)
|
* 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.
|
* Sorted by referenceID.
|
||||||
@@ -46,7 +46,7 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
|
|||||||
init {
|
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) {
|
fun add(item: GameItem, count: Int = 1) {
|
||||||
|
|
||||||
println("[ActorInventory] add $item, $count")
|
println("[ActorInventory] add $item, $count")
|
||||||
@@ -86,12 +86,12 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
|
|||||||
}
|
}
|
||||||
// new item
|
// new item
|
||||||
else {
|
else {
|
||||||
itemList.add(InventoryPair(item, count))
|
itemList.add(InventoryPair(item.dynamicID, count))
|
||||||
}
|
}
|
||||||
insertionSortLastElem(itemList)
|
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!
|
/** Will check existence of the item using its Dynamic ID; careful with command order!
|
||||||
* e.g. re-assign after this operation */
|
* e.g. re-assign after this operation */
|
||||||
fun remove(item: GameItem, count: Int = 1) {
|
fun remove(item: GameItem, count: Int = 1) {
|
||||||
@@ -152,7 +152,7 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
|
|||||||
else
|
else
|
||||||
getTotalCount().toDouble()
|
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
|
* Real amount
|
||||||
@@ -277,7 +277,10 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
|
|||||||
while (low <= high) {
|
while (low <= high) {
|
||||||
val mid = (low + high).ushr(1) // safe from overflows
|
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)
|
if (ID > midVal)
|
||||||
low = mid + 1
|
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
|
package net.torvald.terrarum.modulebasegame.gameactors
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
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.blockproperties.BlockCodex
|
||||||
import net.torvald.terrarum.gameactors.ActorWBMovable
|
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.
|
* 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)
|
avBaseMass = if (item.dynamicID < BlockCodex.MAX_TERRAIN_TILES)
|
||||||
BlockCodex[item.dynamicID].density / 1000.0
|
BlockCodex[item.dynamicID].density / 1000.0
|
||||||
else
|
else
|
||||||
ItemCodex[item.dynamicID].mass
|
ItemCodex[item.dynamicID]!!.mass
|
||||||
|
|
||||||
scale = ItemCodex[item.dynamicID].scale
|
scale = ItemCodex[item.dynamicID]!!.scale
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun update(delta: Float) {
|
override fun update(delta: Float) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import net.torvald.terrarum.AppLoader
|
|||||||
import net.torvald.terrarum.gameactors.Actor
|
import net.torvald.terrarum.gameactors.Actor
|
||||||
import net.torvald.terrarum.itemproperties.GameItem
|
import net.torvald.terrarum.itemproperties.GameItem
|
||||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||||
|
import net.torvald.terrarum.itemproperties.ItemID
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2016-01-15.
|
* Created by minjaesong on 2016-01-15.
|
||||||
@@ -31,6 +32,12 @@ interface Pocketed {
|
|||||||
item.effectOnUnequip(AppLoader.UPDATE_RATE.toFloat())
|
item.effectOnUnequip(AppLoader.UPDATE_RATE.toFloat())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun unequipItem(itemID: ItemID?) {
|
||||||
|
itemID?.let {
|
||||||
|
unequipItem(ItemCodex[itemID])
|
||||||
|
} ?: return
|
||||||
|
}
|
||||||
|
|
||||||
// no need for equipSlot(Int)
|
// no need for equipSlot(Int)
|
||||||
fun unequipSlot(slot: Int) {
|
fun unequipSlot(slot: Int) {
|
||||||
if (slot < 0 || slot > GameItem.EquipPosition.INDEX_MAX)
|
if (slot < 0 || slot > GameItem.EquipPosition.INDEX_MAX)
|
||||||
@@ -49,19 +56,24 @@ interface Pocketed {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (item.equipPosition >= 0) {
|
if (item.equipPosition >= 0) {
|
||||||
inventory.itemEquipped[item.equipPosition] = item
|
inventory.itemEquipped[item.equipPosition] = item.dynamicID
|
||||||
item.effectWhenEquipped(AppLoader.UPDATE_RATE.toFloat())
|
item.effectWhenEquipped(AppLoader.UPDATE_RATE.toFloat())
|
||||||
}
|
}
|
||||||
// else do nothing
|
// else do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
fun equipped(item: GameItem): Boolean {
|
fun equipItem(itemID: ItemID) {
|
||||||
return inventory.itemEquipped[item.equipPosition] == item
|
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 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 removeItem(item: GameItem, count: Int = 1) = inventory.remove(item, count)
|
||||||
|
|
||||||
fun hasItem(item: GameItem) = inventory.contains(item.dynamicID)
|
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.AppLoader
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
|
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2016-05-25.
|
* Created by minjaesong on 2016-05-25.
|
||||||
@@ -14,9 +15,9 @@ class ThreadActorUpdate(val startIndex: Int, val endIndex: Int) : Runnable {
|
|||||||
|
|
||||||
if (it is Pocketed) {
|
if (it is Pocketed) {
|
||||||
it.inventory.forEach { inventoryEntry ->
|
it.inventory.forEach { inventoryEntry ->
|
||||||
inventoryEntry.item.effectWhileInPocket(AppLoader.UPDATE_RATE.toFloat())
|
ItemCodex[inventoryEntry.item]?.effectWhileInPocket(AppLoader.UPDATE_RATE.toFloat())
|
||||||
if (it.equipped(inventoryEntry.item)) {
|
if (it.equipped(inventoryEntry.item)) {
|
||||||
inventoryEntry.item.effectWhenEquipped(AppLoader.UPDATE_RATE.toFloat())
|
ItemCodex[inventoryEntry.item]?.effectWhenEquipped(AppLoader.UPDATE_RATE.toFloat())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.ui
|
package net.torvald.terrarum.modulebasegame.ui
|
||||||
|
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
|
||||||
import net.torvald.terrarum.itemproperties.GameItem
|
import net.torvald.terrarum.itemproperties.GameItem
|
||||||
|
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||||
|
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2017-04-21.
|
* Created by minjaesong on 2017-04-21.
|
||||||
@@ -9,7 +10,7 @@ import net.torvald.terrarum.itemproperties.GameItem
|
|||||||
object AmmoMeterProxy {
|
object AmmoMeterProxy {
|
||||||
|
|
||||||
operator fun invoke(actor: ActorHumanoid, meter: UIVitalMetre) {
|
operator fun invoke(actor: ActorHumanoid, meter: UIVitalMetre) {
|
||||||
val currentItem = actor.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP]
|
val currentItem = ItemCodex[actor.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP]]
|
||||||
|
|
||||||
if (currentItem == null) {
|
if (currentItem == null) {
|
||||||
meter.vitalGetterMax = { null }
|
meter.vitalGetterMax = { null }
|
||||||
|
|||||||
@@ -316,20 +316,20 @@ class UIItemInventoryDynamicList(
|
|||||||
|
|
||||||
// filter items
|
// filter items
|
||||||
inventory.forEach {
|
inventory.forEach {
|
||||||
if (it.item.inventoryCategory == filter || filter == "__all__")
|
if (ItemCodex[it.item]!!.inventoryCategory == filter || filter == "__all__")
|
||||||
inventorySortList.add(it)
|
inventorySortList.add(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort if needed
|
// sort if needed
|
||||||
// test sort by name
|
// test sort by name
|
||||||
inventorySortList.sortBy { it.item.name }
|
inventorySortList.sortBy { ItemCodex[it.item]!!.name }
|
||||||
|
|
||||||
// map sortList to item list
|
// map sortList to item list
|
||||||
for (k in 0 until items.size) {
|
for (k in 0 until items.size) {
|
||||||
// we have an item
|
// we have an item
|
||||||
try {
|
try {
|
||||||
val sortListItem = inventorySortList[k + itemPage * items.size]
|
val sortListItem = inventorySortList[k + itemPage * items.size]
|
||||||
items[k].item = sortListItem.item
|
items[k].item = ItemCodex[sortListItem.item]
|
||||||
items[k].amount = sortListItem.amount
|
items[k].amount = sortListItem.amount
|
||||||
items[k].itemImage = ItemCodex.getItemImage(sortListItem.item)
|
items[k].itemImage = ItemCodex.getItemImage(sortListItem.item)
|
||||||
|
|
||||||
@@ -346,7 +346,7 @@ class UIItemInventoryDynamicList(
|
|||||||
// set equippedslot number
|
// set equippedslot number
|
||||||
for (eq in 0 until inventory.itemEquipped.size) {
|
for (eq in 0 until inventory.itemEquipped.size) {
|
||||||
if (eq < inventory.itemEquipped.size) {
|
if (eq < inventory.itemEquipped.size) {
|
||||||
if (inventory.itemEquipped[eq] == items[k].item) {
|
if (inventory.itemEquipped[eq] == items[k].item?.dynamicID) {
|
||||||
items[k].equippedSlot = eq
|
items[k].equippedSlot = eq
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,9 +132,9 @@ class UIItemInventoryEquippedView(
|
|||||||
itemGrid[k].equippedSlot = null
|
itemGrid[k].equippedSlot = null
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val itemRecord = inventory.getByDynamicID(item.dynamicID)!!
|
val itemRecord = inventory.getByDynamicID(item)!!
|
||||||
|
|
||||||
itemGrid[k].item = item
|
itemGrid[k].item = ItemCodex[item]
|
||||||
itemGrid[k].amount = itemRecord.amount
|
itemGrid[k].amount = itemRecord.amount
|
||||||
itemGrid[k].itemImage = ItemCodex.getItemImage(item)
|
itemGrid[k].itemImage = ItemCodex.getItemImage(item)
|
||||||
itemGrid[k].quickslot = null // don't need to be displayed
|
itemGrid[k].quickslot = null // don't need to be displayed
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import net.torvald.terrarum.Second
|
|||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.gameactors.AVKey
|
import net.torvald.terrarum.gameactors.AVKey
|
||||||
import net.torvald.terrarum.gameworld.fmod
|
import net.torvald.terrarum.gameworld.fmod
|
||||||
|
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||||
import net.torvald.terrarum.modulebasegame.Ingame
|
import net.torvald.terrarum.modulebasegame.Ingame
|
||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
|
|
||||||
@@ -46,7 +47,7 @@ class UIQuickslotBar : UICanvas() {
|
|||||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||||
|
|
||||||
for (i in 0..SLOT_COUNT - 1) {
|
for (i in 0..SLOT_COUNT - 1) {
|
||||||
val item = (Terrarum.ingame!! as Ingame).actorNowPlaying?.inventory?.getQuickslot(i)?.item
|
val item = ItemCodex[(Terrarum.ingame!! as Ingame).actorNowPlaying?.inventory?.getQuickslot(i)?.item]
|
||||||
|
|
||||||
val image = if (i == selection)
|
val image = if (i == selection)
|
||||||
ItemSlotImageFactory.produceLarge(false, (i + 1) % SLOT_COUNT, item)
|
ItemSlotImageFactory.produceLarge(false, (i + 1) % SLOT_COUNT, item)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.jme3.math.FastMath
|
|||||||
import net.torvald.terrarum.Second
|
import net.torvald.terrarum.Second
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.gameactors.AVKey
|
import net.torvald.terrarum.gameactors.AVKey
|
||||||
|
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||||
import net.torvald.terrarum.modulebasegame.Ingame
|
import net.torvald.terrarum.modulebasegame.Ingame
|
||||||
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar.Companion.COMMON_OPEN_CLOSE
|
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar.Companion.COMMON_OPEN_CLOSE
|
||||||
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar.Companion.SLOT_COUNT
|
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar.Companion.SLOT_COUNT
|
||||||
@@ -62,7 +63,7 @@ class uiQuickslotPie : UICanvas() {
|
|||||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||||
// draw radial thingies
|
// draw radial thingies
|
||||||
for (i in 0..slotCount - 1) {
|
for (i in 0..slotCount - 1) {
|
||||||
val item = (Terrarum.ingame!! as Ingame).actorNowPlaying?.inventory?.getQuickslot(i)?.item
|
val item = ItemCodex[(Terrarum.ingame!! as Ingame).actorNowPlaying?.inventory?.getQuickslot(i)?.item]
|
||||||
|
|
||||||
// set position
|
// set position
|
||||||
val angle = Math.PI * 2.0 * (i.toDouble() / slotCount) + Math.PI // 180 deg monitor-wise
|
val angle = Math.PI * 2.0 * (i.toDouble() / slotCount) + Math.PI // 180 deg monitor-wise
|
||||||
|
|||||||
Reference in New Issue
Block a user