equip item by body parts

Former-commit-id: 34294de21d16c03da98427edae3b3c6ed94088aa
Former-commit-id: b37fe27635b1643e72e8f714bfea6ce214006931
This commit is contained in:
Song Minjae
2016-12-16 18:56:13 +09:00
parent 1d1769a2c3
commit 5dc99f5612
10 changed files with 90 additions and 56 deletions

View File

@@ -12,7 +12,8 @@ import org.newdawn.slick.GameContainer
*
* Created by minjaesong on 16-09-08.
*/
open class DynamicItem(val baseItemID: Int, val newMass: Double? = null, val newScale: Double? = null) : InventoryItem {
open class DynamicItem(val baseItemID: Int?, newMass: Double? = null, newScale: Double? = null)
: InventoryItemAdapter() {
/**
* Internal ID of an Item, Long
@@ -23,6 +24,13 @@ open class DynamicItem(val baseItemID: Int, val newMass: Double? = null, val new
*/
override val itemID: Int = generateUniqueDynamicItemID()
override val equipPosition: Int = // default to HAND_GRIP if no baseItemID given
if (baseItemID != null)
ItemPropCodex.getProp(baseItemID).equipPosition
else
EquipPosition.HAND_GRIP
private fun generateUniqueDynamicItemID(): Int {
var ret: Int
do {
@@ -55,38 +63,18 @@ open class DynamicItem(val baseItemID: Int, val newMass: Double? = null, val new
init {
// set mass to the value from item codex using baseItemID
// if you forget this, the game will throw NullPointerException!
if (newMass != null) mass = newMass
if (newScale != null) scale = newScale
if (baseItemID == null) {
mass = newMass!!
}
else {
mass = newMass ?: ItemPropCodex.getProp(baseItemID).mass
}
if (baseItemID == null) {
scale = newScale!!
}
else {
scale = newScale ?: ItemPropCodex.getProp(baseItemID).scale
}
}
/**
* Effects applied continuously while in pocket
*/
override fun effectWhileInPocket(gc: GameContainer, delta: Int) { }
/**
* Effects applied immediately only once if picked up
*/
override fun effectWhenPickedUp(gc: GameContainer, delta: Int) { }
/**
* Effects applied (continuously or not) while primary button (usually left mouse button) is down
*/
override fun primaryUse(gc: GameContainer, delta: Int) { }
/**
* Effects applied (continuously or not) while secondary button (usually right mouse button) is down
*/
override fun secondaryUse(gc: GameContainer, delta: Int) { }
/**
* Effects applied immediately only once if thrown from pocket
*/
override fun effectWhenThrown(gc: GameContainer, delta: Int) { }
/**
* Effects applied (continuously or not) while thrown to the world
*/
override fun effectWhenTakenOut(gc: GameContainer, delta: Int) { }
}

View File

@@ -15,6 +15,11 @@ interface InventoryItem {
*/
val itemID: Int
/**
* Where to equip the item
*/
val equipPosition: Int
/**
* Base mass of the item. Real mass must be calculated from
* mass * scale^3
@@ -55,7 +60,39 @@ interface InventoryItem {
fun effectWhenThrown(gc: GameContainer, delta: Int)
/**
* Effects applied (continuously or not) while thrown to the world
* Effects applied (continuously or not) when equipped
*/
fun effectWhenTakenOut(gc: GameContainer, delta: Int)
fun effectWhenEquipped(gc: GameContainer, delta: Int)
/**
* Effects applied only once when unequipped
*/
fun effectWhenUnEquipped(gc: GameContainer, delta: Int)
}
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
}

View File

@@ -7,6 +7,7 @@ import org.newdawn.slick.GameContainer
*/
abstract class InventoryItemAdapter : InventoryItem {
override abstract val itemID: Int
override abstract val equipPosition: Int
override abstract var mass: Double
override abstract var scale: Double
@@ -25,6 +26,9 @@ abstract class InventoryItemAdapter : InventoryItem {
override fun effectWhenThrown(gc: GameContainer, delta: Int) {
}
override fun effectWhenTakenOut(gc: GameContainer, delta: Int) {
override fun effectWhenEquipped(gc: GameContainer, delta: Int) {
}
override fun effectWhenUnEquipped(gc: GameContainer, delta: Int) {
}
}