mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-15 04:54:05 +09:00
@@ -1,7 +1,6 @@
|
||||
package net.torvald.terrarum.itemproperties
|
||||
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import net.torvald.terrarum.gameactors.sqrt
|
||||
import net.torvald.terrarum.gameactors.*
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-04-17.
|
||||
@@ -16,8 +15,8 @@ object Calculate {
|
||||
*
|
||||
* TODO Newtons as unit?
|
||||
*/
|
||||
fun pickaxePower(material: Material): Float {
|
||||
return 4f * material.forceMod.toFloat().sqrt()
|
||||
fun pickaxePower(actor: ActorHumanoid, material: Material): Float {
|
||||
return (4.0 * material.forceMod.toDouble().sqrt() * (actor.avStrength / 1000.0)).toFloat()
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package net.torvald.terrarum.itemproperties
|
||||
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.ItemValue
|
||||
import net.torvald.terrarum.gameactors.ActorInventory
|
||||
import net.torvald.terrarum.gameactors.Pocketed
|
||||
import net.torvald.terrarum.itemproperties.Material
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
@@ -12,7 +14,7 @@ import org.newdawn.slick.GameContainer
|
||||
*/
|
||||
abstract class InventoryItem : Comparable<InventoryItem>, Cloneable {
|
||||
|
||||
abstract val id: Int
|
||||
abstract var id: Int
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -49,12 +51,23 @@ abstract class InventoryItem : Comparable<InventoryItem>, Cloneable {
|
||||
/** Single-use then destroyed (e.g. Tiles), aka negation of "stackable" */
|
||||
abstract var consumable: Boolean
|
||||
|
||||
/**
|
||||
* DYNAMIC means the item ID should be generated on the fly whenever the item is created.
|
||||
* This is to be used with weapons/armours/etc where multiple instances can exist, and
|
||||
* each of them should be treated as different item.
|
||||
*
|
||||
* ID Range: 32768..1048575 (ItemCodex.ITEM_DYNAMIC)
|
||||
*
|
||||
* The opposite of this is called STATIC and their example is a Block.
|
||||
*/
|
||||
open val isDynamic = false
|
||||
|
||||
/**
|
||||
* Where to equip the item
|
||||
*/
|
||||
open var equipPosition: Int = EquipPosition.NULL
|
||||
open val equipPosition: Int = EquipPosition.NULL
|
||||
|
||||
open var material: Material? = null
|
||||
open val material: Material? = null
|
||||
|
||||
/**
|
||||
* Apparent mass of the item. (basemass * scale^3)
|
||||
@@ -77,6 +90,7 @@ abstract class InventoryItem : Comparable<InventoryItem>, Cloneable {
|
||||
else
|
||||
throw NullPointerException("null input; nullify baseToolSize instead :p")
|
||||
}
|
||||
var originalID = id
|
||||
|
||||
/**
|
||||
* Scale of the item.
|
||||
@@ -226,4 +240,14 @@ abstract class InventoryItem : Comparable<InventoryItem>, Cloneable {
|
||||
|
||||
return clonedItem
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun generateNewDynamicID(inventory: ActorInventory): Int {
|
||||
var ret: Int
|
||||
do {
|
||||
ret = HQRNG().nextInt(ItemCodex.ITEM_DYNAMIC.endInclusive + 1 - ItemCodex.ITEM_DYNAMIC.first) + ItemCodex.ITEM_DYNAMIC.first
|
||||
} while (inventory.contains(ret))
|
||||
return ret
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ object ItemCodex {
|
||||
// tile items (blocks and walls are the same thing basically)
|
||||
for (i in ITEM_TILES + ITEM_WALLS) {
|
||||
itemCodex[i] = object : InventoryItem() {
|
||||
override val id: Int = i
|
||||
override var id: Int = i
|
||||
override val isUnique: Boolean = false
|
||||
override var baseMass: Double = TileCodex[i].density / 1000.0
|
||||
override var baseToolSize: Double? = null
|
||||
@@ -54,6 +54,7 @@ object ItemCodex {
|
||||
override val originalName = TileCodex[i % ITEM_WALLS.first].nameKey
|
||||
override var consumable = true
|
||||
override var inventoryCategory = Category.BLOCK
|
||||
override var isDynamic = true
|
||||
|
||||
init {
|
||||
itemProperties[IVKey.ITEMTYPE] = if (i in ITEM_TILES)
|
||||
@@ -103,19 +104,19 @@ object ItemCodex {
|
||||
|
||||
// test copper pickaxe
|
||||
itemCodex[ITEM_STATIC.first] = object : InventoryItem() {
|
||||
override val id = ITEM_STATIC.first
|
||||
override var id = ITEM_STATIC.first
|
||||
override val isUnique = false
|
||||
override val originalName = "Test Pick"
|
||||
override var baseMass = 10.0
|
||||
override var baseToolSize: Double? = 10.0
|
||||
override var consumable = false
|
||||
override var maxDurability = 147//606 // this much tiles before breaking
|
||||
override var maxDurability = 64//606 // this much tiles before breaking
|
||||
override var durability = maxDurability.toFloat()
|
||||
override var equipPosition = EquipPosition.HAND_GRIP
|
||||
override var inventoryCategory = Category.TOOL
|
||||
|
||||
private val testmaterial = Material(
|
||||
0,0,0,0,0,0,0,0,14,0.0 // quick test material Steel
|
||||
0,0,0,0,0,0,0,0,1,0.0 // quick test material Stone
|
||||
)
|
||||
|
||||
init {
|
||||
@@ -131,6 +132,7 @@ object ItemCodex {
|
||||
using = true
|
||||
|
||||
// linear search filter (check for intersection with tilewise mouse point and tilewise hitbox)
|
||||
// return false if hitting actors
|
||||
Terrarum.ingame!!.actorContainer.forEach {
|
||||
if (it is ActorWithPhysics && it.tilewiseHitbox.intersects(mousePoint))
|
||||
return false
|
||||
@@ -144,11 +146,12 @@ object ItemCodex {
|
||||
// filter passed, do the job
|
||||
val swingDmgToFrameDmg = delta.toDouble() / actorvalue.getAsDouble(AVKey.ACTION_INTERVAL)!!
|
||||
|
||||
return Terrarum.ingame!!.world.inflctTerrainDamage(
|
||||
Terrarum.ingame!!.world.inflctTerrainDamage(
|
||||
gc.mouseTileX,
|
||||
gc.mouseTileY,
|
||||
Calculate.pickaxePower(testmaterial) * swingDmgToFrameDmg.toFloat()
|
||||
Calculate.pickaxePower(Terrarum.ingame!!.player!!, testmaterial) * swingDmgToFrameDmg.toFloat()
|
||||
)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun endPrimaryUse(gc: GameContainer, delta: Int): Boolean {
|
||||
@@ -164,6 +167,9 @@ object ItemCodex {
|
||||
// read from save (if applicable) and fill dynamicItemDescription
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns clone of the item in the Codex
|
||||
*/
|
||||
operator fun get(code: Int): InventoryItem {
|
||||
if (code <= ITEM_STATIC.endInclusive) // generic item
|
||||
return itemCodex[code]!!.clone() // from CSV
|
||||
|
||||
Reference in New Issue
Block a user