diff --git a/assets/modules/basegame/tileprop.csv b/assets/modules/basegame/tiles/tileprop.csv similarity index 99% rename from assets/modules/basegame/tileprop.csv rename to assets/modules/basegame/tiles/tileprop.csv index 7850332f4..02297c4cd 100644 --- a/assets/modules/basegame/tileprop.csv +++ b/assets/modules/basegame/tiles/tileprop.csv @@ -1,4 +1,4 @@ - "id";"dmg";"name" ; "opacity";"strength";"dsty";"mate";"fluid";"solid";"wall"; "lumcolor";"drop";"ddmg";"fall";"dlfn";"vscs";"fv";"friction" + "id";"sid";"name" ; "opacity";"strength";"dsty";"mate";"fluid";"solid";"wall"; "lumcolor";"drop";"ddmg";"fall";"dlfn";"vscs";"fv";"friction" "0"; "0";"TILE_AIR" ; "8396808"; "1"; "1";"null"; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "N/A"; "0";"4" "1"; "0";"TILE_STONE" ; "33587232"; "48";"2400";"rock"; "0"; "1"; "1"; "0"; "1"; "0"; "0"; "0"; "N/A"; "0";"16" "1"; "1";"TILE_STONE_QUARRIED" ; "33587232"; "48";"2400";"rock"; "0"; "1"; "1"; "0"; "1"; "1"; "0"; "0"; "N/A"; "0";"16" diff --git a/src/net/torvald/CSVFetcher.kt b/src/net/torvald/CSVFetcher.kt index 61f8d34d3..4cb839e12 100644 --- a/src/net/torvald/CSVFetcher.kt +++ b/src/net/torvald/CSVFetcher.kt @@ -1,5 +1,6 @@ package net.torvald +import net.torvald.terrarum.ModMgr import org.apache.commons.csv.CSVFormat import org.apache.commons.csv.CSVParser import org.apache.commons.csv.CSVRecord @@ -16,8 +17,7 @@ object CSVFetcher { private var csvString: StringBuffer? = null - @Throws(IOException::class) - operator fun invoke(csvFilePath: String): List { + fun readFromFile(csvFilePath: String): List { csvString = StringBuffer() // reset buffer every time it called readCSVasString(csvFilePath) @@ -40,6 +40,8 @@ object CSVFetcher { return csvRecordList } + fun readFromModule(module: String, path: String) = readFromFile(ModMgr.getPath(module, path)) + fun readFromString(csv: String): List { val csvParser = CSVParser.parse( csv, diff --git a/src/net/torvald/colourutil/ColourTemp.kt b/src/net/torvald/colourutil/ColourTemp.kt index 299aa7fac..e97bc9a55 100644 --- a/src/net/torvald/colourutil/ColourTemp.kt +++ b/src/net/torvald/colourutil/ColourTemp.kt @@ -5,14 +5,14 @@ import net.torvald.terrarum.weather.toColor import org.newdawn.slick.Color import org.newdawn.slick.Image import net.torvald.colourutil.CIEXYZUtil.toColor -import net.torvald.terrarum.ModuleManager +import net.torvald.terrarum.ModMgr /** * RGB-modeled CCT calculator * Created by minjaesong on 16-07-26. */ object ColourTemp { - private var envOverlayColourmap = Image(ModuleManager.getPath("basegame", "colourmap/black_body_col_1000_40000_K.tga")) + private var envOverlayColourmap = Image(ModMgr.getPath("basegame", "colourmap/black_body_col_1000_40000_K.tga")) private fun colTempToImagePos(K: Int): Int { if (K < 1000 || K >= 40000) throw IllegalArgumentException("K: out of range. ($K)") diff --git a/src/net/torvald/serialise/WriteMeta.kt b/src/net/torvald/serialise/WriteMeta.kt index 4824e6bf5..928bdadb1 100644 --- a/src/net/torvald/serialise/WriteMeta.kt +++ b/src/net/torvald/serialise/WriteMeta.kt @@ -5,7 +5,6 @@ import net.torvald.terrarum.mapgenerator.RoguelikeRandomiser import net.torvald.terrarum.Terrarum import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.MaterialCodex -import net.torvald.terrarum.tileproperties.TilePropCSV import net.torvald.terrarum.tileproperties.TileCodex import org.apache.commons.codec.digest.DigestUtils import java.io.FileInputStream @@ -36,7 +35,7 @@ object WriteMeta { * @param savegameName -- Nullable. If the value is not specified, saveDirectoryName will be used instead. */ fun write(saveDirectoryName: String, savegameName: String?): Boolean { - val hashArray: ArrayList = ArrayList() + /*val hashArray: ArrayList = ArrayList() val savenameAsByteArray: ByteArray = (savegameName ?: saveDirectoryName).toByteArray(Charsets.UTF_8) @@ -75,20 +74,7 @@ object WriteMeta { } catch (e: IOException) { e.printStackTrace() - } + }*/ return false } - - fun toByteArray(long: Long): ByteArray { - return byteArrayOf( - (long.ushr(0x38) and 0xFF).toByte(), - (long.ushr(0x30) and 0xFF).toByte(), - (long.ushr(0x28) and 0xFF).toByte(), - (long.ushr(0x20) and 0xFF).toByte(), - (long.ushr(0x18) and 0xFF).toByte(), - (long.ushr(0x10) and 0xFF).toByte(), - (long.ushr(0x08) and 0xFF).toByte(), - (long and 0xFF).toByte() - ) - } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/KVHashMap.kt b/src/net/torvald/terrarum/KVHashMap.kt index 6a8dc6c1f..f6ea73178 100644 --- a/src/net/torvald/terrarum/KVHashMap.kt +++ b/src/net/torvald/terrarum/KVHashMap.kt @@ -51,60 +51,47 @@ class KVHashMap { fun getAsInt(key: String): Int? { val value = get(key) + if (value == null) return null + if (value is JsonPrimitive) return value.asInt - try { - return value as Int - } - catch (e: ClassCastException) { - return null - } + return value as Int } fun getAsDouble(key: String): Double? { val value = get(key) + if (value == null) return null + if (value is Int) return value.toDouble() else if (value is JsonPrimitive) return value.asDouble - try { - return value as Double - } - catch (e: ClassCastException) { - return null - - } + return value as Double } fun getAsString(key: String): String? { val value = get(key) + if (value == null) return null + if (value is JsonPrimitive) return value.asString - try { - return value as String - } - catch (e: ClassCastException) { - return null - } + return value as String } fun getAsBoolean(key: String): Boolean? { val value = get(key) + if (value == null) return null + if (value is JsonPrimitive) return value.asBoolean - try { - return value as Boolean - } - catch (e: ClassCastException) { - return null - } + return value as Boolean } fun hasKey(key: String) = hashMap.containsKey(key) diff --git a/src/net/torvald/terrarum/ModuleManager.kt b/src/net/torvald/terrarum/ModMgr.kt similarity index 96% rename from src/net/torvald/terrarum/ModuleManager.kt rename to src/net/torvald/terrarum/ModMgr.kt index e69986f64..8e648eb49 100644 --- a/src/net/torvald/terrarum/ModuleManager.kt +++ b/src/net/torvald/terrarum/ModMgr.kt @@ -11,7 +11,7 @@ import java.nio.file.FileSystems * * Created by SKYHi14 on 2017-04-17. */ -object ModuleManager { +object ModMgr { data class ModuleMetadata(val order: Int, val isDir: Boolean, val desc: String, val libraries: Array) { override fun toString() = @@ -35,7 +35,7 @@ object ModuleManager { loadOrder.forEachIndexed { index, it -> val moduleName = it[0] - println("[ModuleManager] Loading module $moduleName") + println("[ModMgr] Loading module $moduleName") val description = it[1] val libs = it[2].split(';').toTypedArray() diff --git a/src/net/torvald/terrarum/StateInGame.kt b/src/net/torvald/terrarum/StateInGame.kt index 16c9e97fc..02d0f566c 100644 --- a/src/net/torvald/terrarum/StateInGame.kt +++ b/src/net/torvald/terrarum/StateInGame.kt @@ -12,7 +12,7 @@ import net.torvald.terrarum.gameactors.physicssolver.CollisionSolver import net.torvald.terrarum.gamecontroller.GameController import net.torvald.terrarum.gamecontroller.Key import net.torvald.terrarum.gamecontroller.KeyToggler -import net.torvald.terrarum.gameitem.InventoryItem +import net.torvald.terrarum.itemproperties.InventoryItem import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.WorldSimulator import net.torvald.terrarum.gameworld.WorldTime diff --git a/src/net/torvald/terrarum/StateUITest.kt b/src/net/torvald/terrarum/StateUITest.kt index c1566d4dc..51f51383f 100644 --- a/src/net/torvald/terrarum/StateUITest.kt +++ b/src/net/torvald/terrarum/StateUITest.kt @@ -1,8 +1,8 @@ package net.torvald.terrarum import net.torvald.terrarum.gameactors.* -import net.torvald.terrarum.gameitem.IVKey -import net.torvald.terrarum.gameitem.InventoryItem +import net.torvald.terrarum.itemproperties.IVKey +import net.torvald.terrarum.itemproperties.InventoryItem import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.tileproperties.Tile import net.torvald.terrarum.ui.* diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index a12fe515a..2b7f86061 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -313,7 +313,7 @@ object Terrarum : StateBasedGame(GAME_NAME) { // load modules - ModuleManager + ModMgr gc.graphics.clear() // clean up any 'dust' in the buffer diff --git a/src/net/torvald/terrarum/UIItemInventoryElem.kt b/src/net/torvald/terrarum/UIItemInventoryElem.kt index 8a14773bd..9e0b40438 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElem.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElem.kt @@ -1,7 +1,7 @@ package net.torvald.terrarum import net.torvald.colourutil.CIELabUtil.darkerLab -import net.torvald.terrarum.gameitem.InventoryItem +import net.torvald.terrarum.itemproperties.InventoryItem import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UIInventory import net.torvald.terrarum.ui.UIItem diff --git a/src/net/torvald/terrarum/gameactors/AVKey.kt b/src/net/torvald/terrarum/gameactors/AVKey.kt index 1798d0000..24eb6af11 100644 --- a/src/net/torvald/terrarum/gameactors/AVKey.kt +++ b/src/net/torvald/terrarum/gameactors/AVKey.kt @@ -79,6 +79,11 @@ object AVKey { const val MAGICREGENRATE = "magicregenrate" const val MAGICREGENRATEBUFF = "$MAGICREGENRATE$BUFF" + /** Double + * + */ + const val ACTION_INTERVAL = "actioninterval" + /** String * UUID for certain fixtures @@ -91,4 +96,9 @@ object AVKey { /** SYNOPSIS: __qsitem1 .. __qsitem10 * contains tem ID; they are supposed to be unique. Indices must be ONE-BASED! */ const val __PLAYER_QSPREFIX = "__qsitem" // __qsitem1 .. __qsitem10 (NOT ZERO BASED!) + /** Double + * When using tool/arm/etc. how long action button is held, in milliseconds (Int) + * Or for NPCs, how long it has been waiting for next move + */ + const val __ACTION_TIMER = "__actiontimer" } \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameactors/ActorHumanoid.kt b/src/net/torvald/terrarum/gameactors/ActorHumanoid.kt index d065fcd22..8259aa4d8 100644 --- a/src/net/torvald/terrarum/gameactors/ActorHumanoid.kt +++ b/src/net/torvald/terrarum/gameactors/ActorHumanoid.kt @@ -1,10 +1,11 @@ package net.torvald.terrarum.gameactors import com.jme3.math.FastMath +import net.torvald.terrarum.Millisec import net.torvald.terrarum.Terrarum import net.torvald.terrarum.gameactors.faction.Faction import net.torvald.terrarum.gamecontroller.EnumKeyFunc -import net.torvald.terrarum.gameitem.InventoryItem +import net.torvald.terrarum.itemproperties.InventoryItem import net.torvald.terrarum.realestate.RealEstateUtility import org.newdawn.slick.GameContainer import org.newdawn.slick.Input @@ -22,6 +23,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null) var vehicleRiding: Controllable? = null // usually player only + /** Must be set by PlayerFactory */ override var inventory: ActorInventory = ActorInventory(this, 2000, ActorInventory.CAPACITY_MODE_WEIGHT) // default constructor @@ -77,6 +79,8 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null) @Transient internal const val WALK_ACCEL_BASE: Double = 0.67 @Transient const val BASE_HEIGHT = 40 + // 333.33 miliseconds + @Transient const val BASE_ACTION_INTERVAL = 1000.0 / 3.0 @Transient const val SPRITE_ROW_IDLE = 0 @Transient const val SPRITE_ROW_WALK = 1 diff --git a/src/net/torvald/terrarum/gameactors/ActorInventory.kt b/src/net/torvald/terrarum/gameactors/ActorInventory.kt index 468a88203..d8d23dc57 100644 --- a/src/net/torvald/terrarum/gameactors/ActorInventory.kt +++ b/src/net/torvald/terrarum/gameactors/ActorInventory.kt @@ -1,7 +1,7 @@ package net.torvald.terrarum.gameactors import net.torvald.terrarum.Terrarum -import net.torvald.terrarum.gameitem.InventoryItem +import net.torvald.terrarum.itemproperties.InventoryItem import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.ui.UIInventory import java.util.* diff --git a/src/net/torvald/terrarum/gameactors/ActorWithSprite.kt b/src/net/torvald/terrarum/gameactors/ActorWithSprite.kt index c13de5c39..d3de320dc 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithSprite.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithSprite.kt @@ -1329,6 +1329,7 @@ fun Float.roundInt(): Int = Math.round(this) fun Double.abs() = Math.abs(this) fun Double.sqr() = this * this fun Double.sqrt() = Math.sqrt(this) +fun Float.sqrt() = FastMath.sqrt(this) fun Int.abs() = if (this < 0) -this else this fun Double.bipolarClamp(limit: Double) = if (this > 0 && this > limit) limit diff --git a/src/net/torvald/terrarum/gameactors/CanBeAnItem.kt b/src/net/torvald/terrarum/gameactors/CanBeAnItem.kt index de394ac44..c9f4aff30 100644 --- a/src/net/torvald/terrarum/gameactors/CanBeAnItem.kt +++ b/src/net/torvald/terrarum/gameactors/CanBeAnItem.kt @@ -1,6 +1,6 @@ package net.torvald.terrarum.gameactors -import net.torvald.terrarum.gameitem.InventoryItem +import net.torvald.terrarum.itemproperties.InventoryItem /** * Created by minjaesong on 16-01-31. diff --git a/src/net/torvald/terrarum/gameactors/CreatureBuilder.kt b/src/net/torvald/terrarum/gameactors/CreatureBuilder.kt index 8811a7eab..9e8aa5ded 100644 --- a/src/net/torvald/terrarum/gameactors/CreatureBuilder.kt +++ b/src/net/torvald/terrarum/gameactors/CreatureBuilder.kt @@ -22,6 +22,9 @@ object CreatureBuilder { val actor = ActorWithSprite(Actor.RenderOrder.MIDDLE) InjectCreatureRaw(actor.actorValue, module, jsonFileName) + + actor.actorValue[AVKey.__ACTION_TIMER] = 0.0 + return actor } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameactors/DroppedItem.kt b/src/net/torvald/terrarum/gameactors/DroppedItem.kt index 0c1a045fc..9e243c595 100644 --- a/src/net/torvald/terrarum/gameactors/DroppedItem.kt +++ b/src/net/torvald/terrarum/gameactors/DroppedItem.kt @@ -1,6 +1,6 @@ package net.torvald.terrarum.gameactors -import net.torvald.terrarum.gameitem.InventoryItem +import net.torvald.terrarum.itemproperties.InventoryItem import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.tileproperties.TileCodex import org.newdawn.slick.GameContainer diff --git a/src/net/torvald/terrarum/gameactors/HumanoidNPC.kt b/src/net/torvald/terrarum/gameactors/HumanoidNPC.kt index 371c4c266..48df62bb9 100644 --- a/src/net/torvald/terrarum/gameactors/HumanoidNPC.kt +++ b/src/net/torvald/terrarum/gameactors/HumanoidNPC.kt @@ -7,7 +7,7 @@ import net.torvald.terrarum.gameactors.ai.ActorAI import net.torvald.terrarum.gameactors.ai.LuaAIWrapper import net.torvald.terrarum.gamecontroller.mouseX import net.torvald.terrarum.gamecontroller.mouseY -import net.torvald.terrarum.gameitem.InventoryItem +import net.torvald.terrarum.itemproperties.InventoryItem import org.luaj.vm2.* import org.luaj.vm2.compiler.LuaC import org.luaj.vm2.lib.* diff --git a/src/net/torvald/terrarum/gameactors/InjectCreatureRaw.kt b/src/net/torvald/terrarum/gameactors/InjectCreatureRaw.kt index 9c45674ea..288a9edb8 100644 --- a/src/net/torvald/terrarum/gameactors/InjectCreatureRaw.kt +++ b/src/net/torvald/terrarum/gameactors/InjectCreatureRaw.kt @@ -5,7 +5,7 @@ import net.torvald.random.Fudge3 import net.torvald.terrarum.langpack.Lang import com.google.gson.JsonObject import net.torvald.terrarum.ActorValue -import net.torvald.terrarum.ModuleManager +import net.torvald.terrarum.ModMgr import net.torvald.terrarum.gameactors.ActorHumanoid import org.newdawn.slick.SlickException import java.io.IOException @@ -25,7 +25,7 @@ object InjectCreatureRaw { * @param jsonFileName with extension */ operator fun invoke(actorValueRef: ActorValue, module: String, jsonFileName: String) { - val jsonObj = JsonFetcher(ModuleManager.getPath(module, "creatures/$jsonFileName")) + val jsonObj = JsonFetcher(ModMgr.getPath(module, "creatures/$jsonFileName")) val elementsInt = arrayOf(AVKey.BASEHEIGHT, AVKey.TOOLSIZE, AVKey.ENCUMBRANCE) val elementsString = arrayOf(AVKey.RACENAME, AVKey.RACENAMEPLURAL) diff --git a/src/net/torvald/terrarum/gameactors/PlayerBuilder.kt b/src/net/torvald/terrarum/gameactors/PlayerBuilder.kt index 348d9e5cb..da8568759 100644 --- a/src/net/torvald/terrarum/gameactors/PlayerBuilder.kt +++ b/src/net/torvald/terrarum/gameactors/PlayerBuilder.kt @@ -19,6 +19,8 @@ object PlayerBuilder { // do etc. p.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = 0 + p.actorValue[AVKey.__ACTION_TIMER] = 0.0 + p.actorValue[AVKey.ACTION_INTERVAL] = ActorHumanoid.BASE_ACTION_INTERVAL return p } diff --git a/src/net/torvald/terrarum/gameactors/PlayerBuilderCynthia.kt b/src/net/torvald/terrarum/gameactors/PlayerBuilderCynthia.kt index da664ce63..00fd81f15 100644 --- a/src/net/torvald/terrarum/gameactors/PlayerBuilderCynthia.kt +++ b/src/net/torvald/terrarum/gameactors/PlayerBuilderCynthia.kt @@ -1,7 +1,7 @@ package net.torvald.terrarum.gameactors import net.torvald.spriteanimation.SpriteAnimation -import net.torvald.terrarum.ModuleManager +import net.torvald.terrarum.ModMgr import net.torvald.terrarum.gameactors.ActorHumanoid import net.torvald.terrarum.gameactors.ai.LuaAIWrapper import net.torvald.terrarum.mapdrawer.FeaturesDrawer @@ -20,10 +20,12 @@ object PlayerBuilderCynthia { p.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = 0 + p.actorValue[AVKey.__ACTION_TIMER] = 0.0 + p.actorValue[AVKey.ACTION_INTERVAL] = ActorHumanoid.BASE_ACTION_INTERVAL p.actorValue[AVKey.NAME] = "Cynthia" - p.makeNewSprite(26, 42, ModuleManager.getPath("basegame", "sprites/test_player_2.tga")) + p.makeNewSprite(26, 42, ModMgr.getPath("basegame", "sprites/test_player_2.tga")) p.sprite!!.delay = 200 p.sprite!!.setRowsAndFrames(1, 1) diff --git a/src/net/torvald/terrarum/gameactors/PlayerBuilderSigrid.kt b/src/net/torvald/terrarum/gameactors/PlayerBuilderSigrid.kt index 0201eddfd..0030221a6 100644 --- a/src/net/torvald/terrarum/gameactors/PlayerBuilderSigrid.kt +++ b/src/net/torvald/terrarum/gameactors/PlayerBuilderSigrid.kt @@ -5,7 +5,7 @@ import net.torvald.terrarum.gameactors.faction.Faction import net.torvald.spriteanimation.SpriteAnimation import com.google.gson.JsonObject import net.torvald.terrarum.ActorValue -import net.torvald.terrarum.ModuleManager +import net.torvald.terrarum.ModMgr import net.torvald.terrarum.gameactors.ActorHumanoid import net.torvald.terrarum.gameactors.faction.FactionFactory import net.torvald.terrarum.itemproperties.ItemCodex @@ -28,11 +28,11 @@ object PlayerBuilderSigrid { p.referenceID = 0x51621D // the only constant of this procedural universe - p.makeNewSprite(28, 51, ModuleManager.getPath("basegame", "sprites/test_player.tga")) + p.makeNewSprite(28, 51, ModMgr.getPath("basegame", "sprites/test_player.tga")) p.sprite!!.delay = 200 p.sprite!!.setRowsAndFrames(1, 1) - p.makeNewSpriteGlow(28, 51, ModuleManager.getPath("basegame", "sprites/test_player_glow.tga")) + p.makeNewSpriteGlow(28, 51, ModMgr.getPath("basegame", "sprites/test_player_glow.tga")) p.spriteGlow!!.delay = 200 p.spriteGlow!!.setRowsAndFrames(1, 1) @@ -64,7 +64,8 @@ object PlayerBuilderSigrid { p.actorValue[AVKey.BASEDEFENCE] = 141 p.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = 0 - //p.actorValue["__selectedtile"] = 147 // test code; replace with .primaryUse(gc, delta) + p.actorValue[AVKey.__ACTION_TIMER] = 0.0 + p.actorValue[AVKey.ACTION_INTERVAL] = ActorHumanoid.BASE_ACTION_INTERVAL p.actorValue["__aimhelper"] = true // TODO when you'll gonna implement it? p.setHitboxDimension(15, p.actorValue.getAsInt(AVKey.BASEHEIGHT)!!, 11, 0) diff --git a/src/net/torvald/terrarum/gameactors/PlayerBuilderTestSubject1.kt b/src/net/torvald/terrarum/gameactors/PlayerBuilderTestSubject1.kt index 09678eeaf..1ab9998fb 100644 --- a/src/net/torvald/terrarum/gameactors/PlayerBuilderTestSubject1.kt +++ b/src/net/torvald/terrarum/gameactors/PlayerBuilderTestSubject1.kt @@ -1,6 +1,6 @@ package net.torvald.terrarum.gameactors -import net.torvald.terrarum.ModuleManager +import net.torvald.terrarum.ModMgr import net.torvald.terrarum.gameactors.ai.LuaAIWrapper import net.torvald.terrarum.mapdrawer.FeaturesDrawer @@ -14,10 +14,12 @@ object PlayerBuilderTestSubject1 { p.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = 0 + p.actorValue[AVKey.__ACTION_TIMER] = 0.0 + p.actorValue[AVKey.ACTION_INTERVAL] = ActorHumanoid.BASE_ACTION_INTERVAL p.actorValue[AVKey.NAME] = "Test Subject 1" - p.makeNewSprite(48, 52, ModuleManager.getPath("basegame", "sprites/npc_template_anim_prototype.tga")) + p.makeNewSprite(48, 52, ModMgr.getPath("basegame", "sprites/npc_template_anim_prototype.tga")) p.sprite!!.delay = 200 p.sprite!!.setRowsAndFrames(2, 4) diff --git a/src/net/torvald/terrarum/gameactors/Pocketed.kt b/src/net/torvald/terrarum/gameactors/Pocketed.kt index bdd7cdc77..f2c1121c0 100644 --- a/src/net/torvald/terrarum/gameactors/Pocketed.kt +++ b/src/net/torvald/terrarum/gameactors/Pocketed.kt @@ -1,7 +1,7 @@ package net.torvald.terrarum.gameactors import net.torvald.terrarum.Terrarum -import net.torvald.terrarum.gameitem.InventoryItem +import net.torvald.terrarum.itemproperties.InventoryItem import net.torvald.terrarum.itemproperties.ItemCodex /** diff --git a/src/net/torvald/terrarum/gameactors/faction/FactionFactory.kt b/src/net/torvald/terrarum/gameactors/faction/FactionFactory.kt index 556bc24fc..ddf4805a2 100644 --- a/src/net/torvald/terrarum/gameactors/faction/FactionFactory.kt +++ b/src/net/torvald/terrarum/gameactors/faction/FactionFactory.kt @@ -2,7 +2,7 @@ package net.torvald.terrarum.gameactors.faction import net.torvald.JsonFetcher import com.google.gson.JsonObject -import net.torvald.terrarum.ModuleManager +import net.torvald.terrarum.ModMgr import java.io.IOException @@ -16,7 +16,7 @@ object FactionFactory { */ @Throws(IOException::class) fun create(module: String, path: String): Faction { - val jsonObj = JsonFetcher(ModuleManager.getPath(module, path)) + val jsonObj = JsonFetcher(ModMgr.getPath(module, path)) val factionObj = Faction(jsonObj.get("factionname").asString) jsonObj.get("factionamicable").asJsonArray.forEach { factionObj.addFactionAmicable(it.asString) } diff --git a/src/net/torvald/terrarum/gamecontroller/GameController.kt b/src/net/torvald/terrarum/gamecontroller/GameController.kt index 6eea005cd..1c42c91bd 100644 --- a/src/net/torvald/terrarum/gamecontroller/GameController.kt +++ b/src/net/torvald/terrarum/gamecontroller/GameController.kt @@ -4,7 +4,7 @@ import net.torvald.terrarum.mapdrawer.TilesDrawer import net.torvald.terrarum.mapdrawer.FeaturesDrawer import net.torvald.terrarum.Terrarum import net.torvald.terrarum.gameactors.* -import net.torvald.terrarum.gameitem.InventoryItem +import net.torvald.terrarum.itemproperties.InventoryItem import net.torvald.terrarum.mapdrawer.MapCamera import net.torvald.terrarum.tileproperties.Tile import net.torvald.terrarum.tileproperties.TileCodex @@ -78,7 +78,7 @@ object GameController { if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary"))) { ingame.player!!.consumePrimary(itemOnGrip) } - else if (input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) { + if (input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) { ingame.player!!.consumeSecondary(itemOnGrip) } } @@ -113,7 +113,21 @@ object GameController { } fun mouseReleased(button: Int, x: Int, y: Int) { + if (Terrarum.ingame != null) { + val ingame = Terrarum.ingame!! + if (ingame.player != null && ingame.canPlayerControl) { + val itemOnGrip = ingame.player!!.inventory.itemEquipped[InventoryItem.EquipPosition.HAND_GRIP] + if (itemOnGrip != null) { + if (button == Terrarum.getConfigInt("mousePrimary")) { + itemOnGrip.endPrimaryUse(Terrarum.appgc, Terrarum.UPDATE_DELTA) + } + if (button == Terrarum.getConfigInt("mouseSecondary")) { + itemOnGrip.endSecondaryUse(Terrarum.appgc, Terrarum.UPDATE_DELTA) + } + } + } + } } fun mouseWheelMoved(change: Int) { diff --git a/src/net/torvald/terrarum/gameitem/DynamicItem.kt b/src/net/torvald/terrarum/gameitem/DynamicItem.kt deleted file mode 100644 index a5583d60e..000000000 --- a/src/net/torvald/terrarum/gameitem/DynamicItem.kt +++ /dev/null @@ -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 - } - }*/ -} \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameworld/GameWorld.kt b/src/net/torvald/terrarum/gameworld/GameWorld.kt index dcc09c852..a052396b3 100644 --- a/src/net/torvald/terrarum/gameworld/GameWorld.kt +++ b/src/net/torvald/terrarum/gameworld/GameWorld.kt @@ -2,11 +2,12 @@ package net.torvald.terrarum.gameworld import net.torvald.terrarum.realestate.RealEstateUtility +import net.torvald.terrarum.tileproperties.TileCodex import org.dyn4j.geometry.Vector2 import org.newdawn.slick.SlickException typealias TileAddress = Long -typealias TileDamage = Int +typealias TileDamage = Float class GameWorld(val width: Int, val height: Int) { @@ -211,31 +212,61 @@ class GameWorld(val width: Int, val height: Int) { } } - fun inflctTerrainDamage(x: Int, y: Int, damage: Int) { + /** + * @return true if block is broken + */ + fun inflctTerrainDamage(x: Int, y: Int, damage: Float): Boolean { val addr = RealEstateUtility.getAbsoluteTileNumber(x, y) - if (terrainDamages[addr] == null) { + if (terrainDamages[addr] == null) { // add new terrainDamages[addr] = damage } - else { + else if (terrainDamages[addr]!! + damage <= 0) { // tile is (somehow) fully healed + terrainDamages.remove(addr) + } + else { // normal situation terrainDamages[addr] = terrainDamages[addr]!! + damage } - } - fun getTerrainDamage(x: Int, y: Int) = - terrainDamages[RealEstateUtility.getAbsoluteTileNumber(x, y)] ?: 0 - fun inflctWallDamage(x: Int, y: Int, damage: Int) { + //println("[GameWorld] accumulated damage: ${terrainDamages[addr]}") + + // remove tile from the world + if (terrainDamages[addr]!! >= TileCodex[getTileFromTerrain(x, y)].strength) { + setTileTerrain(x, y, 0) + return true + } + + return false + } + fun getTerrainDamage(x: Int, y: Int): Float = + terrainDamages[RealEstateUtility.getAbsoluteTileNumber(x, y)] ?: 0f + + /** + * @return true if block is broken + */ + fun inflctWallDamage(x: Int, y: Int, damage: Float): Boolean { val addr = RealEstateUtility.getAbsoluteTileNumber(x, y) - if (wallDamages[addr] == null) { + if (wallDamages[addr] == null) { // add new wallDamages[addr] = damage } - else { + else if (wallDamages[addr]!! + damage <= 0) { // tile is (somehow) fully healed + wallDamages.remove(addr) + } + else { // normal situation wallDamages[addr] = wallDamages[addr]!! + damage } + + // remove tile from the world + if (wallDamages[addr]!! >= TileCodex[getTileFromWall(x, y)].strength) { + setTileWall(x, y, 0) + return true + } + + return false } - fun getWallDamage(x: Int, y: Int) = - wallDamages[RealEstateUtility.getAbsoluteTileNumber(x, y)] ?: 0 + fun getWallDamage(x: Int, y: Int): Float = + wallDamages[RealEstateUtility.getAbsoluteTileNumber(x, y)] ?: 0f companion object { diff --git a/src/net/torvald/terrarum/itemproperties/Calculate.kt b/src/net/torvald/terrarum/itemproperties/Calculate.kt new file mode 100644 index 000000000..cca57367b --- /dev/null +++ b/src/net/torvald/terrarum/itemproperties/Calculate.kt @@ -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() } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameitem/IVKey.kt b/src/net/torvald/terrarum/itemproperties/IVKey.kt similarity index 93% rename from src/net/torvald/terrarum/gameitem/IVKey.kt rename to src/net/torvald/terrarum/itemproperties/IVKey.kt index 98129d76e..e0e7a8deb 100644 --- a/src/net/torvald/terrarum/gameitem/IVKey.kt +++ b/src/net/torvald/terrarum/itemproperties/IVKey.kt @@ -1,4 +1,4 @@ -package net.torvald.terrarum.gameitem +package net.torvald.terrarum.itemproperties /** * Created by minjaesong on 16-09-09. diff --git a/src/net/torvald/terrarum/gameitem/InventoryItem.kt b/src/net/torvald/terrarum/itemproperties/InventoryItem.kt similarity index 96% rename from src/net/torvald/terrarum/gameitem/InventoryItem.kt rename to src/net/torvald/terrarum/itemproperties/InventoryItem.kt index 031a9f4c7..6c2e5acf7 100644 --- a/src/net/torvald/terrarum/gameitem/InventoryItem.kt +++ b/src/net/torvald/terrarum/itemproperties/InventoryItem.kt @@ -1,4 +1,4 @@ -package net.torvald.terrarum.gameitem +package net.torvald.terrarum.itemproperties import net.torvald.terrarum.ItemValue import net.torvald.terrarum.gameactors.Pocketed @@ -96,6 +96,8 @@ abstract class InventoryItem : Comparable, Cloneable { */ open var durability: Float = 0f + var using = false + /** * Effects applied continuously while in pocket */ @@ -129,6 +131,9 @@ abstract class InventoryItem : Comparable, Cloneable { */ 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 */ diff --git a/src/net/torvald/terrarum/itemproperties/ItemCodex.kt b/src/net/torvald/terrarum/itemproperties/ItemCodex.kt index 9b307d333..5cb7bd413 100644 --- a/src/net/torvald/terrarum/itemproperties/ItemCodex.kt +++ b/src/net/torvald/terrarum/itemproperties/ItemCodex.kt @@ -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, - - )*/ - + } + 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 } } diff --git a/src/net/torvald/terrarum/itemproperties/ItemEffectsLuaAPI.kt b/src/net/torvald/terrarum/itemproperties/ItemEffectsLuaAPI.kt index 33572eafc..455ff5a35 100644 --- a/src/net/torvald/terrarum/itemproperties/ItemEffectsLuaAPI.kt +++ b/src/net/torvald/terrarum/itemproperties/ItemEffectsLuaAPI.kt @@ -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 } } diff --git a/src/net/torvald/terrarum/itemproperties/Material.kt b/src/net/torvald/terrarum/itemproperties/Material.kt index bfff25ac2..e9ee890ca 100644 --- a/src/net/torvald/terrarum/itemproperties/Material.kt +++ b/src/net/torvald/terrarum/itemproperties/Material.kt @@ -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 ) \ No newline at end of file diff --git a/src/net/torvald/terrarum/mapdrawer/TilesDrawer.kt b/src/net/torvald/terrarum/mapdrawer/TilesDrawer.kt index 4a6355d7a..3b7e3e1d5 100644 --- a/src/net/torvald/terrarum/mapdrawer/TilesDrawer.kt +++ b/src/net/torvald/terrarum/mapdrawer/TilesDrawer.kt @@ -7,12 +7,14 @@ import net.torvald.terrarum.tileproperties.TileCodex import com.jme3.math.FastMath import net.torvald.terrarum.* import net.torvald.terrarum.concurrent.ThreadParallel +import net.torvald.terrarum.gameactors.roundInt import net.torvald.terrarum.mapdrawer.FeaturesDrawer.TILE_SIZE import net.torvald.terrarum.mapdrawer.LightmapRenderer.normaliseToColour import net.torvald.terrarum.mapdrawer.MapCamera.x import net.torvald.terrarum.mapdrawer.MapCamera.y import net.torvald.terrarum.mapdrawer.MapCamera.height import net.torvald.terrarum.mapdrawer.MapCamera.width +import net.torvald.terrarum.realestate.RealEstateUtility import org.lwjgl.opengl.GL11 import org.newdawn.slick.* import java.util.* @@ -25,10 +27,11 @@ object TilesDrawer { private val TILE_SIZE = FeaturesDrawer.TILE_SIZE private val TILE_SIZEF = FeaturesDrawer.TILE_SIZE.toFloat() - var tilesTerrain: SpriteSheet = SpriteSheet(ModuleManager.getPath("basegame", "tiles/terrain.tga"), TILE_SIZE, TILE_SIZE) - private set // Slick has some weird quirks with PNG's transparency. I'm using 32-bit targa here. - var tilesWire: SpriteSheet = SpriteSheet(ModuleManager.getPath("basegame", "tiles/wire.tga"), TILE_SIZE, TILE_SIZE) - private set + val tilesTerrain = SpriteSheet(ModMgr.getPath("basegame", "tiles/terrain.tga"), TILE_SIZE, TILE_SIZE) + // Slick has some weird quirks with PNG's transparency. I'm using 32-bit targa here. + val tilesWire = SpriteSheet(ModMgr.getPath("basegame", "tiles/wire.tga"), TILE_SIZE, TILE_SIZE) + + val breakAnimSteps = 10 val WALL = GameWorld.WALL val TERRAIN = GameWorld.TERRAIN @@ -49,7 +52,7 @@ object TilesDrawer { * It holds different shading rule to discriminate with group 02, index 0 is single tile. * These are the tiles that only connects to itself, will not connect to colour variants */ - var TILES_CONNECT_SELF = arrayOf( + val TILES_CONNECT_SELF = arrayListOf( Tile.ICE_MAGICAL, Tile.GLASS_CRUDE, Tile.GLASS_CLEAN, @@ -98,7 +101,7 @@ object TilesDrawer { * Connectivity group 02 : natural tiles * It holds different shading rule to discriminate with group 01, index 0 is middle tile. */ - var TILES_CONNECT_MUTUAL = arrayOf( + val TILES_CONNECT_MUTUAL = arrayListOf( Tile.STONE, Tile.STONE_QUARRIED, Tile.STONE_TILE_WHITE, @@ -163,7 +166,7 @@ object TilesDrawer { /** * Torches, levers, switches, ... */ - var TILES_WALL_STICKER = arrayOf( + val TILES_WALL_STICKER = arrayListOf( Tile.TORCH, Tile.TORCH_FROST, Tile.TORCH_OFF, @@ -173,7 +176,7 @@ object TilesDrawer { /** * platforms, ... */ - var TILES_WALL_STICKER_CONNECT_SELF = arrayOf( + val TILES_WALL_STICKER_CONNECT_SELF = arrayListOf( Tile.PLATFORM_BIRCH, Tile.PLATFORM_BLOODROSE, Tile.PLATFORM_EBONY, @@ -186,7 +189,7 @@ object TilesDrawer { * will blend colour using colour multiplication * i.e. red hues get lost if you dive into the water */ - var TILES_BLEND_MUL = arrayOf( + val TILES_BLEND_MUL = arrayListOf( Tile.WATER, Tile.WATER_1, Tile.WATER_2, @@ -304,7 +307,7 @@ object TilesDrawer { val noDamageLayer = mode % 3 == WIRE - // draw + // draw a tile, but only when illuminated try { if ((mode == WALL || mode == TERRAIN) && // not an air tile (thisTile ?: 0) != Tile.AIR) { @@ -318,54 +321,70 @@ object TilesDrawer { LightmapRenderer.getHighestRGB(x + 1, y + 1) ?: 0 >= tileDrawLightThreshold || LightmapRenderer.getHighestRGB(x + 1, y - 1) ?: 0 >= tileDrawLightThreshold || LightmapRenderer.getHighestRGB(x - 1, y + 1) ?: 0 >= tileDrawLightThreshold) { - // blackness - if (zeroTileCounter > 0) { - /* unable to do anything */ + // blackness + if (zeroTileCounter > 0) { + /* unable to do anything */ - zeroTileCounter = 0 - } + zeroTileCounter = 0 + } - val nearbyTilesInfo: Int - if (isPlatform(thisTile)) { - nearbyTilesInfo = getNearbyTilesInfoPlatform(x, y) - } - else if (isWallSticker(thisTile)) { - nearbyTilesInfo = getNearbyTilesInfoWallSticker(x, y) - } - else if (isConnectMutual(thisTile)) { - nearbyTilesInfo = getNearbyTilesInfoNonSolid(x, y, mode) - } - else if (isConnectSelf(thisTile)) { - nearbyTilesInfo = getNearbyTilesInfo(x, y, mode, thisTile) - } - else { - nearbyTilesInfo = 0 - } + val nearbyTilesInfo: Int + if (isPlatform(thisTile)) { + nearbyTilesInfo = getNearbyTilesInfoPlatform(x, y) + } + else if (isWallSticker(thisTile)) { + nearbyTilesInfo = getNearbyTilesInfoWallSticker(x, y) + } + else if (isConnectMutual(thisTile)) { + nearbyTilesInfo = getNearbyTilesInfoNonSolid(x, y, mode) + } + else if (isConnectSelf(thisTile)) { + nearbyTilesInfo = getNearbyTilesInfo(x, y, mode, thisTile) + } + else { + nearbyTilesInfo = 0 + } - val thisTileX: Int - if (!noDamageLayer) - thisTileX = PairedMapLayer.RANGE * ((thisTile ?: 0) % PairedMapLayer.RANGE) + nearbyTilesInfo - else - thisTileX = nearbyTilesInfo + val thisTileX = if (!noDamageLayer) + PairedMapLayer.RANGE * ((thisTile ?: 0) % PairedMapLayer.RANGE) + nearbyTilesInfo + else + nearbyTilesInfo - val thisTileY = (thisTile ?: 0) / PairedMapLayer.RANGE + val thisTileY = (thisTile ?: 0) / PairedMapLayer.RANGE - if (drawModeTilesBlendMul) { - if (TilesDrawer.isBlendMul(thisTile)) { - drawTile(mode, x, y, thisTileX, thisTileY) - } - } - else { - // do NOT add "if (!isBlendMul(thisTile))"! - // or else they will not look like they should be when backed with wall + + // draw a tile + if (drawModeTilesBlendMul) { + if (TilesDrawer.isBlendMul(thisTile)) { drawTile(mode, x, y, thisTileX, thisTileY) } + } + else { + // do NOT add "if (!isBlendMul(thisTile))"! + // or else they will not look like they should be when backed with wall + drawTile(mode, x, y, thisTileX, thisTileY) + } + + // draw a breakage + if (mode == TERRAIN || mode == WALL) { + val breakage = if (mode == TERRAIN) world.getTerrainDamage(x, y) else world.getWallDamage(x, y) + val maxHealth = TileCodex[world.getTileFromTerrain(x, y)].strength + val stage = (breakage / maxHealth).times(breakAnimSteps).roundInt() + // actual drawing + if (stage > 0) { + // alpha blending works, but no GL blend func... + drawTile(mode, x, y, 5 + stage, 0) + } + } + + } // end if (is illuminated) + // draw black patch else { - zeroTileCounter++ - //drawTile(mode, x, y, 1, 0) // black patch + zeroTileCounter++ // unused for now + GL11.glColor4f(0f, 0f, 0f, 1f) GL11.glTexCoord2f(0f, 0f) diff --git a/src/net/torvald/terrarum/tileproperties/Tile.kt b/src/net/torvald/terrarum/tileproperties/Tile.kt index 10c891072..06868e25f 100644 --- a/src/net/torvald/terrarum/tileproperties/Tile.kt +++ b/src/net/torvald/terrarum/tileproperties/Tile.kt @@ -7,7 +7,7 @@ import net.torvald.terrarum.Terrarum */ object Tile { - val AIR = 0 + val AIR = 0 // hard coded; this is the standard val STONE = TileCodex.idDamageToIndex(1, 0) val STONE_QUARRIED = TileCodex.idDamageToIndex(1, 1) diff --git a/src/net/torvald/terrarum/tileproperties/TileCodex.kt b/src/net/torvald/terrarum/tileproperties/TileCodex.kt index 1fd53aa76..811b4ebf4 100644 --- a/src/net/torvald/terrarum/tileproperties/TileCodex.kt +++ b/src/net/torvald/terrarum/tileproperties/TileCodex.kt @@ -1,6 +1,7 @@ package net.torvald.terrarum.tileproperties import net.torvald.CSVFetcher +import net.torvald.terrarum.ModMgr import net.torvald.terrarum.gameworld.MapLayer import net.torvald.terrarum.gameworld.PairedMapLayer import org.apache.commons.csv.CSVRecord @@ -14,14 +15,12 @@ object TileCodex { private var tileProps: Array - val CSV_PATH = "/net/torvald/terrarum/tileproperties/tileprop.csv" - const val TILE_UNIQUE_MAX = MapLayer.RANGE * PairedMapLayer.RANGE private val nullProp = TileProp() init { - tileProps = Array(TILE_UNIQUE_MAX * 2, { i -> TileProp() }) + tileProps = Array(TILE_UNIQUE_MAX * 2, { TileProp() }) for (i in tileProps.indices) { tileProps[i] = TileProp() @@ -29,7 +28,7 @@ object TileCodex { try { // todo verify CSV using pre-calculated SHA256 hash - val records = CSVFetcher.readFromString(TilePropCSV()) + val records = CSVFetcher.readFromModule("basegame", "tiles/tileprop.csv") println("[TileCodex] Building tile properties table") @@ -50,15 +49,15 @@ object TileCodex { } - fun get(index: Int, damage: Int): TileProp { + fun get(index: Int, subID: Int): TileProp { try { - tileProps[idDamageToIndex(index, damage)].id + tileProps[idDamageToIndex(index, subID)].id } catch (e: NullPointerException) { - throw NullPointerException("Tile prop with id $index and damage $damage does not exist.") + throw NullPointerException("Tile prop with id $index and subID $subID does not exist.") } - return tileProps[idDamageToIndex(index, damage)] + return tileProps[idDamageToIndex(index, subID)] } operator fun get(rawIndex: Int?): TileProp { diff --git a/src/net/torvald/terrarum/tileproperties/TilePropCSV.kt b/src/net/torvald/terrarum/tileproperties/TilePropCSV.kt index 4e7c65af2..64213ab01 100644 --- a/src/net/torvald/terrarum/tileproperties/TilePropCSV.kt +++ b/src/net/torvald/terrarum/tileproperties/TilePropCSV.kt @@ -3,7 +3,7 @@ package net.torvald.terrarum.tileproperties /** * Created by minjaesong on 16-09-11. */ -object TilePropCSV { +object TilePropCSVFUfufufufufufffnufuuufufu { operator fun invoke() = """ "id";"sid";"name" ; "opacity";"strength";"dsty";"mate";"fluid";"solid";"wall"; "lumcolor";"drop";"ddmg";"fall";"dlfn";"vscs";"fv";"friction" "0"; "0";"TILE_AIR" ; "8396808"; "1"; "1";"null"; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "N/A"; "0";"4" diff --git a/src/net/torvald/terrarum/ui/UIInventory.kt b/src/net/torvald/terrarum/ui/UIInventory.kt index 701aaf859..6465a3f37 100644 --- a/src/net/torvald/terrarum/ui/UIInventory.kt +++ b/src/net/torvald/terrarum/ui/UIInventory.kt @@ -6,7 +6,7 @@ import net.torvald.terrarum.Terrarum.joypadLabelNinA import net.torvald.terrarum.Terrarum.joypadLabelNinY import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.gameactors.ActorInventory.Companion.CAPACITY_MODE_NO_ENCUMBER -import net.torvald.terrarum.gameitem.InventoryItem +import net.torvald.terrarum.itemproperties.InventoryItem import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.langpack.Lang import org.newdawn.slick.* diff --git a/src/net/torvald/terrarum/weather/WeatherMixer.kt b/src/net/torvald/terrarum/weather/WeatherMixer.kt index be685c2a5..306b66289 100644 --- a/src/net/torvald/terrarum/weather/WeatherMixer.kt +++ b/src/net/torvald/terrarum/weather/WeatherMixer.kt @@ -49,7 +49,7 @@ object WeatherMixer { // read weather descriptions from assets/weather (modular weather) val weatherRawValidList = ArrayList() - val weatherRaws = ModuleManager.getFiles("basegame", "weathers") + val weatherRaws = ModMgr.getFiles("basegame", "weathers") weatherRaws.forEach { if (!it.isDirectory && it.name.endsWith(".json")) weatherRawValidList.add(it) @@ -207,7 +207,7 @@ object WeatherMixer { // parse globalLight if (globalLightInJson.isString) - globalLight = Image(ModuleManager.getPath("basegame", "$pathToImage/${globalLightInJson.asString}")) + globalLight = Image(ModMgr.getPath("basegame", "$pathToImage/${globalLightInJson.asString}")) else if (globalLightInJson.isNumber) { // make 1x1 image with specified colour globalLight = Image(1, 1) @@ -219,7 +219,7 @@ object WeatherMixer { // parse skyboxGradColourMap if (skyboxInJson.isString) - skybox = Image(ModuleManager.getPath("basegame", "$pathToImage/${skyboxInJson.asString}")) + skybox = Image(ModMgr.getPath("basegame", "$pathToImage/${skyboxInJson.asString}")) else if (globalLightInJson.isNumber) { // make 1x2 image with specified colour skybox = Image(1, 2) @@ -231,7 +231,7 @@ object WeatherMixer { // get extra images for (i in extraImagesPath) - extraImages.add(Image(ModuleManager.getPath("basegame", "$pathToImage/${i.asString}"))) + extraImages.add(Image(ModMgr.getPath("basegame", "$pathToImage/${i.asString}"))) // get mix from diff --git a/work_files/Pickaxe Power.xlsx b/work_files/Pickaxe Power.xlsx index 066d521b6..bc246eca2 100644 Binary files a/work_files/Pickaxe Power.xlsx and b/work_files/Pickaxe Power.xlsx differ