mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 12:34:05 +09:00
pickaxe working as intended
This commit is contained in:
26
src/net/torvald/terrarum/itemproperties/Calculate.kt
Normal file
26
src/net/torvald/terrarum/itemproperties/Calculate.kt
Normal file
@@ -0,0 +1,26 @@
|
||||
package net.torvald.terrarum.itemproperties
|
||||
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import net.torvald.terrarum.gameactors.sqrt
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-04-17.
|
||||
*/
|
||||
object Calculate {
|
||||
/**
|
||||
* Pickaxe power per action (swing)
|
||||
*
|
||||
* @return arbrtrary unit
|
||||
*
|
||||
* See: work_files/Pickaxe Power.xlsx
|
||||
*
|
||||
* TODO Newtons as unit?
|
||||
*/
|
||||
fun pickaxePower(material: Material): Float {
|
||||
return 4f * material.forceMod.toFloat().sqrt()
|
||||
}
|
||||
|
||||
|
||||
fun armorwhatever() { TODO() }
|
||||
fun yogafire() { TODO() }
|
||||
}
|
||||
26
src/net/torvald/terrarum/itemproperties/IVKey.kt
Normal file
26
src/net/torvald/terrarum/itemproperties/IVKey.kt
Normal file
@@ -0,0 +1,26 @@
|
||||
package net.torvald.terrarum.itemproperties
|
||||
|
||||
/**
|
||||
* 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
|
||||
}
|
||||
}
|
||||
229
src/net/torvald/terrarum/itemproperties/InventoryItem.kt
Normal file
229
src/net/torvald/terrarum/itemproperties/InventoryItem.kt
Normal file
@@ -0,0 +1,229 @@
|
||||
package net.torvald.terrarum.itemproperties
|
||||
|
||||
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
|
||||
|
||||
var using = false
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
open fun endPrimaryUse(gc: GameContainer, delta: Int): Boolean = false
|
||||
open fun endSecondaryUse(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
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,13 @@ package net.torvald.terrarum.itemproperties
|
||||
import net.torvald.point.Point2d
|
||||
import net.torvald.terrarum.KVHashMap
|
||||
import net.torvald.terrarum.gameactors.CanBeAnItem
|
||||
import net.torvald.terrarum.gameitem.InventoryItem
|
||||
import net.torvald.terrarum.itemproperties.InventoryItem
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameactors.ActorWithSprite
|
||||
import net.torvald.terrarum.gamecontroller.mouseTileX
|
||||
import net.torvald.terrarum.gamecontroller.mouseTileY
|
||||
import net.torvald.terrarum.gameitem.IVKey
|
||||
import net.torvald.terrarum.itemproperties.IVKey
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.mapdrawer.TilesDrawer
|
||||
import net.torvald.terrarum.mapdrawer.TilesDrawer.wallOverlayColour
|
||||
@@ -108,17 +109,27 @@ object ItemCodex {
|
||||
override var baseMass = 10.0
|
||||
override var baseToolSize: Double? = 10.0
|
||||
override var consumable = false
|
||||
override var maxDurability = 200 // this much tiles before breaking
|
||||
override var maxDurability = 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
|
||||
)
|
||||
|
||||
init {
|
||||
itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.PICK
|
||||
name = "Steel pickaxe"
|
||||
}
|
||||
|
||||
override fun primaryUse(gc: GameContainer, delta: Int): Boolean {
|
||||
val mousePoint = Point2d(gc.mouseTileX.toDouble(), gc.mouseTileY.toDouble())
|
||||
val actorvalue = Terrarum.ingame!!.player!!.actorValue
|
||||
|
||||
|
||||
using = true
|
||||
|
||||
// linear search filter (check for intersection with tilewise mouse point and tilewise hitbox)
|
||||
Terrarum.ingame!!.actorContainer.forEach {
|
||||
if (it is ActorWithSprite && it.tilewiseHitbox.intersects(mousePoint))
|
||||
@@ -129,19 +140,21 @@ object ItemCodex {
|
||||
if (Tile.AIR == Terrarum.ingame!!.world.getTileFromTerrain(gc.mouseTileX, gc.mouseTileY))
|
||||
return false
|
||||
|
||||
|
||||
// filter passed, do the job
|
||||
Terrarum.ingame!!.world.setTileTerrain(
|
||||
val swingDmgToFrameDmg = delta.toDouble() / actorvalue.getAsDouble(AVKey.ACTION_INTERVAL)!!
|
||||
|
||||
return Terrarum.ingame!!.world.inflctTerrainDamage(
|
||||
gc.mouseTileX,
|
||||
gc.mouseTileY,
|
||||
Tile.AIR
|
||||
Calculate.pickaxePower(testmaterial) * swingDmgToFrameDmg.toFloat()
|
||||
)
|
||||
/*Terrarum.ingame!!.world.inflctTerrainDamage(
|
||||
gc.mouseTileX,
|
||||
gc.mouseTileY,
|
||||
<power calculation using ForceMod (ref. Pickaxe Power.xlsx) and other shits>
|
||||
)*/
|
||||
|
||||
}
|
||||
|
||||
override fun endPrimaryUse(gc: GameContainer, delta: Int): Boolean {
|
||||
using = false
|
||||
// reset action timer to zero
|
||||
Terrarum.ingame!!.player!!.actorValue[AVKey.__ACTION_TIMER] = 0.0
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,13 +47,13 @@ class ItemEffectsLuaAPI(g: Globals) {
|
||||
|
||||
class StrikeEarth : ThreeArgFunction() {
|
||||
override fun call(x: LuaValue, y: LuaValue, power: LuaValue): LuaValue {
|
||||
Terrarum.ingame!!.world.inflctTerrainDamage(x.checkint(), y.checkint(), power.checkint())
|
||||
Terrarum.ingame!!.world.inflctTerrainDamage(x.checkint(), y.checkint(), power.checkdouble().toFloat())
|
||||
return LuaValue.NONE
|
||||
}
|
||||
}
|
||||
class StrikeWall : ThreeArgFunction() {
|
||||
override fun call(x: LuaValue, y: LuaValue, power: LuaValue): LuaValue {
|
||||
Terrarum.ingame!!.world.inflctWallDamage(x.checkint(), y.checkint(), power.checkint())
|
||||
Terrarum.ingame!!.world.inflctWallDamage(x.checkint(), y.checkint(), power.checkdouble().toFloat())
|
||||
return LuaValue.NONE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ data class Material (
|
||||
var thermalConductivity: Int, // pascal (N/m^2); if the item (e.g. sword) receives a force that exceeds this value, the item will be destroyed
|
||||
|
||||
|
||||
// must be a item properties
|
||||
var weapSharpnessMod: Double, // multiplier
|
||||
|
||||
var forceMod: Int, // arbitrary unit. See Pickaxe_Power.xlsx
|
||||
var armourMod: Double // multiplier
|
||||
)
|
||||
Reference in New Issue
Block a user