Combined ItemProp to InventoryItem and introduced Material

Former-commit-id: d73882505cb26a99a5cc70ef5dc2b7e2d087823c
Former-commit-id: cf061fd2edb6fbe765ac812507cb5b0d7b77ee7b
This commit is contained in:
Song Minjae
2017-02-04 22:55:06 +09:00
parent bb33d9e381
commit 8e7b61ea0c
6 changed files with 89 additions and 39 deletions

View File

@@ -12,7 +12,7 @@ import org.newdawn.slick.GameContainer
*
* Created by minjaesong on 16-09-08.
*/
open class DynamicItem(val baseItemID: Int?, newMass: Double? = null, newScale: Double? = null)
open abstract class DynamicItem(val baseItemID: Int?, newMass: Double? = null, newScale: Double? = null)
: InventoryItem() {
/**
@@ -24,13 +24,6 @@ open class DynamicItem(val baseItemID: Int?, newMass: Double? = null, newScale:
*/
override val id: Int = generateUniqueDynamicItemID()
override val equipPosition: Int = // default to HAND_GRIP if no baseItemID given
if (baseItemID != null)
ItemCodex[baseItemID].equipPosition
else
EquipPosition.HAND_GRIP
private fun generateUniqueDynamicItemID(): Int {
var ret: Int
do {

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.gameitem
import net.torvald.terrarum.itemproperties.Material
import org.newdawn.slick.GameContainer
/**
@@ -15,16 +16,38 @@ abstract class InventoryItem {
*/
abstract val id: Int
abstract var baseMass: Double
abstract var baseToolSize: Double?
/**
* Where to equip the item
*/
abstract val equipPosition: Int
var equipPosition: Int = EquipPosition.NULL
var material: Material? = null
/**
* Base mass of the item. Real mass must be calculated from
* mass * scale^3
* Apparent mass of the item. (basemass * scale^3)
*/
abstract var mass: Double
open var mass: Double
get() = baseMass * scale * scale * scale
set(value) { baseMass = value / (scale * scale * scale) }
/**
* Apparent tool size (or weight in kg). (baseToolSize * scale^3)
*/
open var toolSize: Double?
get() = if (baseToolSize != null) baseToolSize!! * scale * scale * scale else null
set(value) {
if (value != null)
if (baseToolSize != null)
baseToolSize = value / (scale * scale * scale)
else
throw NullPointerException("baseToolSize is null; this item is not a tool or you're doing it wrong")
else
throw NullPointerException("null input; nullify baseToolSize instead :p")
}
/**
* Scale of the item.