mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
inventory item count is now Long; should not interfere with the existing savegame
This commit is contained in:
@@ -48,8 +48,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
* e.g. 0x02010034 will be translated as 2.1.52
|
||||
*
|
||||
*/
|
||||
const val VERSION_RAW = 0x00030001
|
||||
// Commit counts up to the Release 0.3.0: 2259 (plz update!)
|
||||
const val VERSION_RAW = 0x00030002
|
||||
// Commit counts up to the Release 0.3.0: 2259
|
||||
// Commit counts up to the Release 0.3.1: 2278
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
// CONFIGURATION FOR TILE MAKER //
|
||||
|
||||
@@ -20,13 +20,13 @@ class UIItemInventoryElemSimple(
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
override var item: GameItem?,
|
||||
override var amount: Int,
|
||||
override var amount: Long,
|
||||
override var itemImage: TextureRegion?,
|
||||
override var quickslot: Int? = null,
|
||||
override var equippedSlot: Int? = null,
|
||||
val drawBackOnNull: Boolean = true,
|
||||
keyDownFun: (GameItem?, Int, Int) -> Unit,
|
||||
touchDownFun: (GameItem?, Int, Int) -> Unit
|
||||
keyDownFun: (GameItem?, Long, Int) -> Unit, // Item, Amount, Keycode
|
||||
touchDownFun: (GameItem?, Long, Int) -> Unit // Item, Amount, Button
|
||||
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot, keyDownFun, touchDownFun) {
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -24,18 +24,18 @@ class UIItemInventoryElemWide(
|
||||
initialY: Int,
|
||||
override val width: Int,
|
||||
override var item: GameItem?,
|
||||
override var amount: Int,
|
||||
override var amount: Long,
|
||||
override var itemImage: TextureRegion?,
|
||||
override var quickslot: Int? = null,
|
||||
override var equippedSlot: Int? = null,
|
||||
val drawBackOnNull: Boolean = true,
|
||||
keyDownFun: (GameItem?, Int, Int) -> Unit,
|
||||
touchDownFun: (GameItem?, Int, Int) -> Unit
|
||||
keyDownFun: (GameItem?, Long, Int) -> Unit, // Item, Amount, Keycode
|
||||
touchDownFun: (GameItem?, Long, Int) -> Unit // Item, Amount, Button
|
||||
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot, keyDownFun, touchDownFun) {
|
||||
|
||||
companion object {
|
||||
val height = 48
|
||||
val UNIQUE_ITEM_HAS_NO_AMOUNT = -1
|
||||
val UNIQUE_ITEM_HAS_NO_AMOUNT = -1L
|
||||
|
||||
internal val durabilityBarThickness = 3
|
||||
}
|
||||
@@ -100,7 +100,7 @@ class UIItemInventoryElemWide(
|
||||
if (INVEN_DEBUG_MODE) {
|
||||
App.fontGame.draw(batch,
|
||||
// print static id, dynamic id, and count
|
||||
"${item!!.originalID}/${item!!.dynamicID}" + (if (amount > 0 && item!!.stackable) "$fwsp($amountString)" else if (amount != 1) "$fwsp!!$amountString!!" else ""),
|
||||
"${item!!.originalID}/${item!!.dynamicID}" + (if (amount > 0 && item!!.stackable) "$fwsp($amountString)" else if (amount != 1L) "$fwsp!!$amountString!!" else ""),
|
||||
posX + textOffsetX,
|
||||
posY + textOffsetY
|
||||
)
|
||||
@@ -108,7 +108,7 @@ class UIItemInventoryElemWide(
|
||||
else {
|
||||
App.fontGame.draw(batch,
|
||||
// print name and amount in parens
|
||||
item!!.name + (if (amount > 0 && item!!.stackable) "$fwsp($amountString)" else if (amount != 1) "$fwsp!!$amountString!!" else ""),
|
||||
item!!.name + (if (amount > 0 && item!!.stackable) "$fwsp($amountString)" else if (amount != 1L) "$fwsp!!$amountString!!" else ""),
|
||||
|
||||
posX + textOffsetX,
|
||||
posY + textOffsetY
|
||||
|
||||
@@ -28,8 +28,8 @@ internal object Inventory : ConsoleCommand {
|
||||
if (actor != null) {
|
||||
when (args[1]) {
|
||||
"list" -> listInventory(actor)
|
||||
"add" -> if (args.size > 3) addItem(actor, args[2], args[3].toInt()) else addItem(actor, args[2])
|
||||
"remove" -> if (args.size > 3) removeItem(actor, args[2], args[3].toInt()) else removeItem(actor, args[2])
|
||||
"add" -> if (args.size > 3) addItem(actor, args[2], args[3].toLong()) else addItem(actor, args[2])
|
||||
"remove" -> if (args.size > 3) removeItem(actor, args[2], args[3].toLong()) else removeItem(actor, args[2])
|
||||
"equip" -> equipItem(actor, args[2])
|
||||
"unequip"-> unequipItem(actor, args[2])
|
||||
else -> printUsage()
|
||||
@@ -44,12 +44,12 @@ internal object Inventory : ConsoleCommand {
|
||||
private fun getActor() = Terrarum.ingame?.getActorByID(targetID) as? Pocketed
|
||||
|
||||
private fun listInventory(actor: Pocketed) {
|
||||
if (actor.inventory.getTotalUniqueCount() == 0) {
|
||||
if (actor.inventory.getTotalUniqueCount() == 0L) {
|
||||
Echo("(inventory empty)")
|
||||
}
|
||||
else {
|
||||
actor.inventory.forEach { val (item, amount) = it
|
||||
if (amount == 0) {
|
||||
if (amount == 0L) {
|
||||
EchoError("Unexpected zero-amounted item: ID $item")
|
||||
}
|
||||
Echo("${ccW}ID $ccY$item${if (amount > 1) "$ccW ($ccG$amount$ccW)" else ""}")
|
||||
@@ -57,7 +57,7 @@ internal object Inventory : ConsoleCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private fun addItem(actor: Pocketed, refId: ItemID, amount: Int = 1) {
|
||||
private fun addItem(actor: Pocketed, refId: ItemID, amount: Long = 1L) {
|
||||
val item = ItemCodex[refId]
|
||||
if (item != null) {
|
||||
actor.addItem(item, amount)
|
||||
@@ -66,7 +66,7 @@ internal object Inventory : ConsoleCommand {
|
||||
else EchoError("No such item: $refId")
|
||||
}
|
||||
|
||||
private fun removeItem(actor: Pocketed, refId: ItemID, amount: Int = 1) {
|
||||
private fun removeItem(actor: Pocketed, refId: ItemID, amount: Long = 1L) {
|
||||
val item = ItemCodex[refId]
|
||||
if (item != null) {
|
||||
actor.removeItem(item, amount)
|
||||
|
||||
@@ -19,7 +19,7 @@ class ActorInventory() : FixtureInventory() {
|
||||
@Transient lateinit var actor: Pocketed
|
||||
internal set
|
||||
|
||||
constructor(actor: Pocketed, maxCapacity: Int, capacityMode: Int) : this() {
|
||||
constructor(actor: Pocketed, maxCapacity: Long, capacityMode: Int) : this() {
|
||||
this.actor = actor
|
||||
this.maxCapacity = maxCapacity
|
||||
this.capacityMode = capacityMode
|
||||
@@ -38,10 +38,10 @@ class ActorInventory() : FixtureInventory() {
|
||||
val quickSlot = Array<ItemID?>(UIQuickslotBar.SLOT_COUNT) { null } // 0: Slot 1, 9: Slot 10
|
||||
|
||||
|
||||
override fun remove(itemID: ItemID, count: Int) = remove(ItemCodex[itemID]!!, count)
|
||||
override fun remove(itemID: ItemID, count: Long) = 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 */
|
||||
override fun remove(item: GameItem, count: Int) {
|
||||
override fun remove(item: GameItem, count: Long) {
|
||||
super.remove(item, count) { existingItem ->
|
||||
// unequip, if applicable
|
||||
actor.unequipItem(existingItem.itm)
|
||||
|
||||
@@ -28,7 +28,7 @@ open class DroppedItem : ActorWithBody {
|
||||
|
||||
@Transient private var textureRegion: TextureRegion? = null // deserialiser won't call setter of the fields
|
||||
|
||||
var itemCount = 1
|
||||
var itemCount = 1L
|
||||
|
||||
protected constructor()
|
||||
|
||||
|
||||
@@ -15,10 +15,10 @@ import java.util.concurrent.locks.ReentrantLock
|
||||
|
||||
open class FixtureInventory() {
|
||||
|
||||
var maxCapacity = 100
|
||||
var maxCapacity = 100L
|
||||
var capacityMode = CAPACITY_MODE_COUNT
|
||||
|
||||
constructor(maxCapacity: Int, capacityMode: Int) : this() {
|
||||
constructor(maxCapacity: Long, capacityMode: Int) : this() {
|
||||
this.maxCapacity = maxCapacity
|
||||
this.capacityMode = capacityMode
|
||||
}
|
||||
@@ -35,23 +35,23 @@ open class FixtureInventory() {
|
||||
val itemList = ArrayList<InventoryPair>()
|
||||
var wallet = BigInteger("0") // unified currency for whole civs; Dwarf Fortress approach seems too complicated
|
||||
|
||||
fun isEmpty() = getTotalCount() == 0
|
||||
fun isEmpty() = getTotalCount() == 0L
|
||||
fun isNotEmpty() = getTotalCount() > 0
|
||||
|
||||
open fun add(itemID: ItemID, count: Int = 1) {
|
||||
open fun add(itemID: ItemID, count: Long = 1) {
|
||||
if (ItemCodex[itemID] == null)
|
||||
throw NullPointerException("Item not found: $itemID")
|
||||
else
|
||||
add(ItemCodex[itemID]!!, count)
|
||||
}
|
||||
open fun add(item: GameItem, count: Int = 1) {
|
||||
open fun add(item: GameItem, count: Long = 1L) {
|
||||
|
||||
// println("[ActorInventory] add-by-elem $item, $count")
|
||||
|
||||
// other invalid values
|
||||
if (count == 0)
|
||||
if (count == 0L)
|
||||
throw IllegalArgumentException("[${this.javaClass.canonicalName}] Item count is zero.")
|
||||
if (count < 0)
|
||||
if (count < 0L)
|
||||
throw IllegalArgumentException("Item count is negative number. If you intended removing items, use remove()\n" +
|
||||
"These commands are NOT INTERCHANGEABLE; they handle things differently according to the context.")
|
||||
if (item.originalID == "actor:${Terrarum.PLAYER_REF_ID}" || item.originalID == ("actor:${0x51621D}")) // do not delete this magic
|
||||
@@ -71,7 +71,10 @@ open class FixtureInventory() {
|
||||
// if the item already exists
|
||||
if (existingItem != null) {
|
||||
// increment count
|
||||
existingItem.qty += count
|
||||
if (existingItem.qty + count < 0L) // check numeric overflow
|
||||
existingItem.qty = Long.MAX_VALUE
|
||||
else
|
||||
existingItem.qty += count
|
||||
}
|
||||
// new item
|
||||
else {
|
||||
@@ -80,20 +83,20 @@ open class FixtureInventory() {
|
||||
insertionSortLastElem(itemList)
|
||||
}
|
||||
|
||||
open fun remove(itemID: ItemID, count: Int) = remove(ItemCodex[itemID]!!, count) {}
|
||||
open fun remove(item: GameItem, count: Int = 1) = remove(item, count) {}
|
||||
open fun remove(itemID: ItemID, count: Long) = remove(ItemCodex[itemID]!!, count) {}
|
||||
open fun remove(item: GameItem, count: Long = 1L) = remove(item, count) {}
|
||||
|
||||
open fun remove(itemID: ItemID, count: Int, unequipFun: (InventoryPair) -> Unit) =
|
||||
open fun remove(itemID: ItemID, count: Long, unequipFun: (InventoryPair) -> Unit) =
|
||||
remove(ItemCodex[itemID]!!, count, unequipFun)
|
||||
/** Will check existence of the item using its Dynamic ID; careful with command order!
|
||||
* e.g. re-assign after this operation */
|
||||
open fun remove(item: GameItem, count: Int = 1, unequipFun: (InventoryPair) -> Unit) {
|
||||
open fun remove(item: GameItem, count: Long = 1, unequipFun: (InventoryPair) -> Unit) {
|
||||
|
||||
println("[ActorInventory] remove $item, $count")
|
||||
|
||||
if (count == 0)
|
||||
if (count == 0L)
|
||||
throw IllegalArgumentException("[${this.javaClass.canonicalName}] Item count is zero.")
|
||||
if (count < 0)
|
||||
if (count < 0L)
|
||||
throw IllegalArgumentException("[${this.javaClass.canonicalName}] Item count is negative number. If you intended adding items, use add()" +
|
||||
"These commands are NOT INTERCHANGEABLE; they handle things differently according to the context.")
|
||||
|
||||
@@ -144,12 +147,12 @@ open class FixtureInventory() {
|
||||
/**
|
||||
* Real amount
|
||||
*/
|
||||
fun getTotalCount(): Int = itemList.sumOf { it.qty }
|
||||
fun getTotalCount(): Long = itemList.sumOf { it.qty }
|
||||
|
||||
/**
|
||||
* Unique amount, multiple items are calculated as one
|
||||
*/
|
||||
fun getTotalUniqueCount(): Int = itemList.size
|
||||
fun getTotalUniqueCount(): Long = itemList.size.toLong()
|
||||
|
||||
/**
|
||||
* Check whether the itemList contains too many items
|
||||
@@ -229,11 +232,11 @@ open class FixtureInventory() {
|
||||
class InventoryPair {
|
||||
|
||||
var itm: ItemID = ""; private set
|
||||
var qty: Int = 0
|
||||
var qty: Long = 0
|
||||
|
||||
private constructor()
|
||||
|
||||
constructor(item: ItemID, quantity: Int) : this() {
|
||||
constructor(item: ItemID, quantity: Long) : this() {
|
||||
itm = item
|
||||
qty = quantity
|
||||
}
|
||||
|
||||
@@ -77,12 +77,12 @@ internal class UIStorageChest : UICanvas(
|
||||
override var openCloseTime: Second = 0.0f
|
||||
|
||||
private val negotiator = object : InventoryNegotiator() {
|
||||
override fun accept(player: FixtureInventory, fixture: FixtureInventory, item: GameItem, amount: Int) {
|
||||
override fun accept(player: FixtureInventory, fixture: FixtureInventory, item: GameItem, amount: Long) {
|
||||
player.remove(item, amount)
|
||||
fixture.add(item, amount)
|
||||
}
|
||||
|
||||
override fun reject(fixture: FixtureInventory, player: FixtureInventory, item: GameItem, amount: Int) {
|
||||
override fun reject(fixture: FixtureInventory, player: FixtureInventory, item: GameItem, amount: Long) {
|
||||
fixture.remove(item, amount)
|
||||
player.add(item, amount)
|
||||
}
|
||||
|
||||
@@ -85,10 +85,10 @@ interface Pocketed {
|
||||
}
|
||||
fun equipped(itemID: ItemID) = equipped(ItemCodex[itemID]!!)
|
||||
|
||||
fun addItem(itemID: ItemID, count: Int = 1) = inventory.add(ItemCodex[itemID]!!, count)
|
||||
fun addItem(item: GameItem, count: Int = 1) = inventory.add(item, count)
|
||||
fun removeItem(itemID: ItemID, count: Int = 1) = inventory.remove(ItemCodex[itemID]!!, count)
|
||||
fun removeItem(item: GameItem, count: Int = 1) = inventory.remove(item, count)
|
||||
fun addItem(itemID: ItemID, count: Long = 1L) = inventory.add(ItemCodex[itemID]!!, count)
|
||||
fun addItem(item: GameItem, count: Long = 1L) = inventory.add(item, count)
|
||||
fun removeItem(itemID: ItemID, count: Long = 1L) = inventory.remove(ItemCodex[itemID]!!, count)
|
||||
fun removeItem(item: GameItem, count: Long = 1L) = inventory.remove(item, count)
|
||||
|
||||
fun hasItem(item: GameItem) = inventory.contains(item.dynamicID)
|
||||
fun hasItem(id: ItemID) = inventory.contains(id)
|
||||
|
||||
@@ -44,7 +44,7 @@ object PickaxeCore {
|
||||
// if mw or mh is even number, make it closer toward the actor
|
||||
if (mw % 2 == 0 && apos.x > mx * TILE_SIZE) xoff += 1
|
||||
if (mh % 2 == 0 && apos.y > my * TILE_SIZE) yoff += 1
|
||||
|
||||
|
||||
var usageStatus = false
|
||||
|
||||
for (oy in 0 until mh) for (ox in 0 until mw) {
|
||||
|
||||
@@ -11,7 +11,7 @@ abstract class InventoryNegotiator {
|
||||
/** Retrieve item filter to be used to show only the acceptable items when player's own inventory is being displayed */
|
||||
open fun getItemFilter(): List<String> = listOf(CAT_ALL) // GameItem.Category
|
||||
/** Accepts item from the player and pass it to right inventory (object), slot (UI), etc... */
|
||||
abstract fun accept(player: FixtureInventory, fixture: FixtureInventory, item: GameItem, amount: Int = 1)
|
||||
abstract fun accept(player: FixtureInventory, fixture: FixtureInventory, item: GameItem, amount: Long = 1L)
|
||||
/** Rejects item and perhaps returns it back to the player, or make explosion, etc... */
|
||||
abstract fun reject(fixture: FixtureInventory, player: FixtureInventory, item: GameItem, amount: Int = 1)
|
||||
abstract fun reject(fixture: FixtureInventory, player: FixtureInventory, item: GameItem, amount: Long = 1L)
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import net.torvald.terrarum.abs
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UIItem
|
||||
import kotlin.math.absoluteValue
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
@@ -22,12 +23,12 @@ abstract class UIItemInventoryCellBase(
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
open var item: GameItem?,
|
||||
open var amount: Int,
|
||||
open var amount: Long,
|
||||
open var itemImage: TextureRegion?,
|
||||
open var quickslot: Int? = null,
|
||||
open var equippedSlot: Int? = null,
|
||||
val keyDownFun: (GameItem?, Int, Int) -> Unit,
|
||||
val touchDownFun: (GameItem?, Int, Int) -> Unit
|
||||
val keyDownFun: (GameItem?, Long, Int) -> Unit, // Item, Amount, Keycode
|
||||
val touchDownFun: (GameItem?, Long, Int) -> Unit // Item, Amount, Button
|
||||
) : UIItem(parentUI, initialX, initialY) {
|
||||
abstract override fun update(delta: Float)
|
||||
abstract override fun render(batch: SpriteBatch, camera: Camera)
|
||||
@@ -64,7 +65,7 @@ object UIItemInventoryCellCommonRes {
|
||||
|
||||
fun getHealthMeterColour(value: Int, start: Int, end: Int) = getHealthMeterColour(value.toFloat(), start.toFloat(), end.toFloat())
|
||||
|
||||
fun Int.toItemCountText() = (if (this < 0) "-" else "") + when (this.abs()) {
|
||||
fun Long.toItemCountText() = (if (this < 0) "-" else "") + when (this.absoluteValue) {
|
||||
in 0..999999 -> "$this"
|
||||
in 1_000_000..999_999_999 -> "${this / 1_000_000}.${this.rem(1_000_000) / 10_000}M"
|
||||
else -> "${this / 1_000_000_000}.${this.rem(1_000_000_000) / 10_000_000}B"
|
||||
|
||||
@@ -8,6 +8,8 @@ import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.itemListHeight
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.createInvCellGenericKeyDownFun
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.createInvCellGenericTouchDownFun
|
||||
import net.torvald.terrarum.spriteassembler.ADProperties.Companion.EXTRA_HEADROOM_X
|
||||
import net.torvald.terrarum.spriteassembler.ADProperties.Companion.EXTRA_HEADROOM_Y
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UIItem
|
||||
@@ -85,8 +87,8 @@ class UIItemInventoryEquippedView(
|
||||
batch.color = SPRITE_DRAW_COL
|
||||
batch.draw(
|
||||
it.textureRegion.get(0, 0),
|
||||
posX + (width - it.cellWidth).div(2).toFloat(),
|
||||
posY + (width - it.cellHeight).div(2).toFloat()
|
||||
posX + (width - it.cellWidth + EXTRA_HEADROOM_X).div(2).toFloat(),
|
||||
posY + (width - it.cellHeight - EXTRA_HEADROOM_Y).div(2).toFloat()
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@ class UIItemInventoryItemGrid(
|
||||
val verticalCells: Int,
|
||||
val drawScrollOnRightside: Boolean = false,
|
||||
val drawWallet: Boolean = true,
|
||||
keyDownFun: (GameItem?, Int, Int) -> Unit,
|
||||
touchDownFun: (GameItem?, Int, Int) -> Unit
|
||||
keyDownFun: (GameItem?, Long, Int) -> Unit, // Item, Amount, Keycode
|
||||
touchDownFun: (GameItem?, Long, Int) -> Unit // Item, Amount, Button
|
||||
) : UIItem(parentUI, initialX, initialY) {
|
||||
|
||||
// deal with the moving position
|
||||
@@ -99,8 +99,8 @@ class UIItemInventoryItemGrid(
|
||||
fun getEstimatedW(horizontalCells: Int) = horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 1) * listGap
|
||||
fun getEstimatedH(verticalCells: Int) = verticalCells * UIItemInventoryElemSimple.height + (verticalCells - 1) * listGap
|
||||
|
||||
fun createInvCellGenericKeyDownFun(): (GameItem?, Int, Int) -> Unit {
|
||||
return { item: GameItem?, amount: Int, keycode: Int ->
|
||||
fun createInvCellGenericKeyDownFun(): (GameItem?, Long, Int) -> Unit {
|
||||
return { item: GameItem?, amount: Long, keycode: Int ->
|
||||
if (item != null && Terrarum.ingame != null && keycode in Input.Keys.NUM_0..Input.Keys.NUM_9) {
|
||||
val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
|
||||
if (player != null) {
|
||||
@@ -129,8 +129,8 @@ class UIItemInventoryItemGrid(
|
||||
}
|
||||
}
|
||||
|
||||
fun createInvCellGenericTouchDownFun(listRebuildFun: () -> Unit): (GameItem?, Int, Int) -> Unit {
|
||||
return { item: GameItem?, amount: Int, button: Int ->
|
||||
fun createInvCellGenericTouchDownFun(listRebuildFun: () -> Unit): (GameItem?, Long, Int) -> Unit {
|
||||
return { item: GameItem?, amount: Long, button: Int ->
|
||||
if (item != null && Terrarum.ingame != null) {
|
||||
// equip da shit
|
||||
val itemEquipSlot = item.equipPosition
|
||||
|
||||
Reference in New Issue
Block a user