pickaxe working as intended

This commit is contained in:
Song Minjae
2017-04-18 01:14:25 +09:00
parent f840dbe7de
commit 5fe604cf45
41 changed files with 271 additions and 231 deletions

View File

@@ -1,67 +0,0 @@
package net.torvald.terrarum.gameitem
import net.torvald.random.HQRNG
import net.torvald.terrarum.KVHashMap
import net.torvald.terrarum.itemproperties.ItemCodex
import org.newdawn.slick.GameContainer
/**
* Items that has some more information (like floppy disk that contains UUID)
*
* @param baseItemID ID of the item that this item is based on
*
* Created by minjaesong on 16-09-08.
*/
@Deprecated("Use InventoryItem's ItemProp")
open abstract class DynamicItem(val baseItemID: Int?, newMass: Double? = null, newScale: Double? = null)
: InventoryItem() {
/*
override val id: Int = generateUniqueDynamicItemID()
private fun generateUniqueDynamicItemID(): Int {
var ret: Int
do {
ret = HQRNG().nextInt().and(0x7FFFFFFF) // set new ID
} while (ItemCodex.contains(ret) || ret < ItemCodex.ITEM_DYNAMIC_MIN || ret > ItemCodex.ITEM_DYNAMIC_MAX) // check for collision
return ret
}
/**
* Weight of the item
*/
override var mass: Double
get() = itemInfo.getAsDouble(ItemInfoKey.MASS)!!
set(value) {
itemInfo[ItemInfoKey.MASS] = value
}
/**
* Scale of the item. Real mass: mass * (scale^3)
*
* For static item, it must be 1.0. If you tinkered the item to be bigger,
* it must be re-assigned as Dynamic Item
*/
override var scale: Double
get() = itemInfo.getAsDouble(ItemInfoKey.SCALE) ?: 1.0
set(value) {
itemInfo[ItemInfoKey.SCALE] = value
}
val itemInfo = KVHashMap()
init {
// set mass to the value from item codex using baseItemID
if (baseItemID == null) {
mass = newMass!!
}
else {
mass = newMass ?: ItemCodex[baseItemID].mass
}
if (baseItemID == null) {
scale = newScale!!
}
else {
scale = newScale ?: ItemCodex[baseItemID].scale
}
}*/
}

View File

@@ -1,26 +0,0 @@
package net.torvald.terrarum.gameitem
/**
* Created by minjaesong on 16-09-09.
*/
object IVKey {
const val ITEMTYPE = "itemtype" // "sword1h", "sword2h", "pick", "hammer", "tile", "wall", etc
const val UUID = "uuid" // some items need UUID to be stored
const val BASE_WEAPON_POWER = "baseweaponpower"
const val BASE_PICK_POWER = "basepickpower"
object ItemType {
const val BLOCK = "tile"
const val WALL = "wall"
// tools
const val PICK = "pick"
const val HAMMER= "hammer"
// weapons
const val SWORDJAB = "sword1h"
const val SWORDSWING = "sword2h"
// generic
const val ARTEFACT = "artefact" // or Key Items
}
}

View File

@@ -1,224 +0,0 @@
package net.torvald.terrarum.gameitem
import net.torvald.terrarum.ItemValue
import net.torvald.terrarum.gameactors.Pocketed
import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.langpack.Lang
import org.newdawn.slick.Color
import org.newdawn.slick.GameContainer
/**
* Created by minjaesong on 16-01-16.
*/
abstract class InventoryItem : Comparable<InventoryItem>, Cloneable {
abstract val id: Int
/**
*
* e.g. Key Items (in a Pokémon sense), floppies
*/
abstract val isUnique: Boolean
/**
* OriginalName is always read from Language files.
*/
abstract protected val originalName: String
private var newName: String = "I AM VITTUN PLACEHOLDER"
var name: String
set(value) {
newName = value
isCustomName = true
}
get() = if (isCustomName) newName else Lang[originalName]
open var isCustomName = false // true: reads from lang
var nameColour = Color.white
abstract var baseMass: Double
abstract var baseToolSize: Double?
abstract var inventoryCategory: String // "weapon", "tool", "armor", etc. (all smallcaps)
var itemProperties = ItemValue()
/** Single-use then destroyed (e.g. Tiles), aka negation of "stackable" */
abstract var consumable: Boolean
/**
* Where to equip the item
*/
open var equipPosition: Int = EquipPosition.NULL
open var material: Material? = null
/**
* Apparent mass of the item. (basemass * scale^3)
*/
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.
*
* For static item, it must be 1.0. If you tinkered the item to be bigger,
* it must be re-assigned as Dynamic Item
*/
open var scale: Double = 1.0
/**
* Set to zero if durability not applicable
*/
open var maxDurability: Int = 0
/**
* Float. NOT A MISTAKE
*/
open var durability: Float = 0f
/**
* Effects applied continuously while in pocket
*/
open fun effectWhileInPocket(gc: GameContainer, delta: Int) { }
/**
* Effects applied immediately only once if picked up
*/
open fun effectWhenPickedUp(gc: GameContainer, delta: Int) { }
/**
* Apply effects (continuously or not) while primary button (usually left mouse button) is down.
* The item will NOT be consumed, so you will want to consume it yourself by inventory.consumeItem(item)
*
* @return true when used successfully, false otherwise
*
* note: DO NOT super(gc, g) this!
*
* Consumption function is executed in net.torvald.terrarum.gamecontroller.GameController,
* in which the function itself is defined in net.torvald.terrarum.gameactors.ActorInventory
*/
open fun primaryUse(gc: GameContainer, delta: Int): Boolean = false
/**
* Apply effects (continuously or not) while secondary button (usually right mouse button) is down
* The item will NOT be consumed, so you will want to consume it yourself by inventory.consumeItem(item)
*
* @return true when used successfully, false otherwise
*
* note: DO NOT super(gc, g) this!
*/
open fun secondaryUse(gc: GameContainer, delta: Int): Boolean = false
/**
* Effects applied immediately only once if thrown from pocket
*/
open fun effectWhenThrown(gc: GameContainer, delta: Int) { }
/**
* Effects applied (continuously or not) when equipped (drawn)
*/
open fun effectWhenEquipped(gc: GameContainer, delta: Int) { }
/**
* Effects applied only once when unequipped
*/
open fun effectOnUnequip(gc: GameContainer, delta: Int) { }
override fun toString(): String {
return id.toString()
}
override fun hashCode(): Int {
return id
}
override fun equals(other: Any?): Boolean {
if (other == null) return false
return id == (other as InventoryItem).id
}
fun unsetCustomName() {
name = originalName
isCustomName = false
nameColour = Color.white
}
override fun compareTo(other: InventoryItem): Int = (this.id - other.id).sign()
fun Int.sign(): Int = if (this > 0) 1 else if (this < 0) -1 else 0
infix fun equipTo(actor: Pocketed) {
if (equipPosition == EquipPosition.NULL)
throw IllegalArgumentException("Item is not supposed to be equipped (equipPosition is NULL")
actor.equipItem(this)
}
object EquipPosition {
const val NULL = -1
const val ARMOUR = 0
// you can add alias to address something like LEGGINGS, BREASTPLATE, RINGS, NECKLACES, etc.
const val BODY_BACK = 1 // wings, jetpacks, etc.
const val BODY_BUFF2 = 2
const val BODY_BUFF3 = 3
const val BODY_BUFF4 = 4
const val BODY_BUFF5 = 5
const val BODY_BUFF6 = 6
const val BODY_BUFF7 = 7
const val BODY_BUFF8 = 8
const val HAND_GRIP = 9
const val HAND_GAUNTLET = 10
const val HAND_BUFF2 = 11
const val HAND_BUFF3 = 12
const val HAND_BUFF4 = 13
const val FOOTWEAR = 14
const val HEADGEAR = 15
const val INDEX_MAX = 15
}
object Category {
const val WEAPON = "weapon"
const val TOOL = "tool"
const val ARMOUR = "armour"
const val GENERIC = "generic"
const val POTION = "potion"
const val MAGIC = "magic"
const val BLOCK = "block"
const val WALL = "wall"
const val MISC = "misc"
}
override public fun clone(): InventoryItem {
val clonedItem = super.clone()
// properly clone ItemValue
(clonedItem as InventoryItem).itemProperties = this.itemProperties.clone()
return clonedItem
}
}