the-flattening wip

This commit is contained in:
minjaesong
2021-02-10 17:48:01 +09:00
parent 73acaea025
commit 8fdc11288c
21 changed files with 513 additions and 503 deletions

View File

@@ -6,6 +6,7 @@ import net.torvald.terrarum.CommonResourcePool
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.ModuleEntryPoint
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.blockproperties.BlockProp
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.itemproperties.MaterialCodex
@@ -52,36 +53,9 @@ class EntryPoint : ModuleEntryPoint() {
// blocks.csvs are loaded by ModMgr beforehand
// block items (blocks and walls are the same thing basically)
for (i in ItemCodex.ITEM_TILES + ItemCodex.ITEM_WALLS) {
val blockProp = BlockCodex.getOrNull(i % ItemCodex.ITEM_WALLS.first)
if (blockProp != null) {
ItemCodex.itemCodex[i] = object : GameItem(i) {
override val isUnique: Boolean = false
override var baseMass: Double = blockProp.density / 1000.0
override var baseToolSize: Double? = null
override val originalName = blockProp.nameKey
override var stackable = true
override var inventoryCategory = if (i in ItemCodex.ITEM_TILES) Category.BLOCK else Category.WALL
override var isDynamic = false
override val material = MaterialCodex.getOrDefault(blockProp.material)
init {
equipPosition = EquipPosition.HAND_GRIP
if (IS_DEVELOPMENT_BUILD)
print("$originalID ")
}
override fun startPrimaryUse(delta: Float): Boolean {
return BlockBase.blockStartPrimaryUse(this, i, delta)
}
override fun effectWhenEquipped(delta: Float) {
BlockBase.blockEffectWhenEquipped(delta)
}
}
}
for (tile in BlockCodex.getAll()) {
ItemCodex[tile.id] = makeNewItemObj(tile, false)
ItemCodex["wall@"+tile.id] = makeNewItemObj(tile, true)
}
@@ -89,6 +63,33 @@ class EntryPoint : ModuleEntryPoint() {
println("[Basegame.EntryPoint] Welcome back!")
}
private fun makeNewItemObj(tile: BlockProp, isWall: Boolean) = object : GameItem(tile.id) {
override val isUnique: Boolean = false
override var baseMass: Double = tile.density / 1000.0
override var baseToolSize: Double? = null
override val originalName = tile.nameKey
override var stackable = true
override var inventoryCategory = if (isWall) Category.WALL else Category.BLOCK
override var isDynamic = false
override val material = MaterialCodex.getOrDefault(tile.material)
init {
equipPosition = EquipPosition.HAND_GRIP
if (IS_DEVELOPMENT_BUILD)
print("$originalID ")
}
override fun startPrimaryUse(delta: Float): Boolean {
return BlockBase.blockStartPrimaryUse(this, tile.id, delta)
}
override fun effectWhenEquipped(delta: Float) {
BlockBase.blockEffectWhenEquipped(delta)
}
}
override fun dispose() {
WatchFont.dispose()
}

View File

@@ -7,8 +7,6 @@ import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_DYNAMIC
import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_WALLS
import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.lock
import net.torvald.terrarum.modulebasegame.TerrarumIngame
@@ -54,8 +52,8 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
// not wall-able walls
if (item.inventoryCategory == GameItem.Category.WALL &&
!BlockCodex[item.dynamicID - ITEM_WALLS.start].isWallable) {
throw IllegalArgumentException("Wall ID ${item.dynamicID - ITEM_WALLS.start} is not wall-able.")
(!item.dynamicID.startsWith("wall@") || !BlockCodex[item.dynamicID.substring(5)].isWallable)) {
throw IllegalArgumentException("Wall ID ${item.dynamicID} is not wall-able.")
}
@@ -65,12 +63,12 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
if (count < 0)
throw IllegalArgumentException("Item count is negative number. If you intended removing items, use remove()\n" +
"These commands are NOT INTERCHANGEABLE; they handle things differently according to the context.")
if (item.originalID == Terrarum.PLAYER_REF_ID || item.originalID == 0x51621D) // do not delete this magic
if (item.originalID == "actor:${Terrarum.PLAYER_REF_ID}" || item.originalID == ("actor:${0x51621D}")) // do not delete this magic
throw IllegalArgumentException("Attempted to put human player into the inventory.")
if (((Terrarum.ingame as? TerrarumIngame)?.gameFullyLoaded ?: false) &&
(item.originalID == (Terrarum.ingame as? TerrarumIngame)?.actorNowPlaying?.referenceID))
(item.originalID == "actor:${(Terrarum.ingame as? TerrarumIngame)?.actorNowPlaying?.referenceID}"))
throw IllegalArgumentException("Attempted to put active player into the inventory.")
if ((!item.stackable || item.dynamicID in ITEM_DYNAMIC) && count > 1)
if ((!item.stackable || item.dynamicID.startsWith("dyn:")) && count > 1)
throw IllegalArgumentException("Attempting to adding stack of item but the item is not stackable; item: $item, count: $count")

View File

@@ -2,7 +2,6 @@ package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.blockproperties.BlockCodex.MAX_TERRAIN_TILES
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.faction.FactionFactory
import net.torvald.terrarum.worlddrawer.CreateTileAtlas
@@ -79,18 +78,18 @@ object PlayerBuilderSigrid {
CreateTileAtlas.tags.forEach { t, _ ->
inventory.add(t, 9995)
if (BlockCodex[t].isWallable) {
inventory.add(t + MAX_TERRAIN_TILES, 9995)
inventory.add("wall@"+t, 9995)
}
}
// item ids are defined in <module>/items/itemid.csv
inventory.add(135168, 16) // copper pick
inventory.add(135169) // iron pick
inventory.add(135170) // steel pick
inventory.add(135171, 9995) // wire piece
inventory.add(135172, 385930603) // test tiki torch
inventory.add(135173, 95) // crafting table
inventory.add("item@basegame:0", 16) // copper pick
inventory.add("item@basegame:1") // iron pick
inventory.add("item@basegame:2") // steel pick
inventory.add("item@basegame:3", 9995) // wire piece
inventory.add("item@basegame:4", 385930603) // test tiki torch
inventory.add("item@basegame:5", 95) // crafting table
//inventory.add(9000) // TEST water bucket
//inventory.add(9001) // TEST lava bucket
}

View File

@@ -5,6 +5,7 @@ import net.torvald.terrarum.Point2i
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.TerrarumIngame
@@ -20,7 +21,7 @@ object BlockBase {
* @param dontEncaseActors when set to true, blocks won't be placed where Actors are. You will want to set it false
* for wire items, otherwise you want it to be true.
*/
fun blockStartPrimaryUse(gameItem: GameItem, itemID: Int, delta: Float): Boolean {
fun blockStartPrimaryUse(gameItem: GameItem, itemID: ItemID, delta: Float): Boolean {
val ingame = Terrarum.ingame!! as TerrarumIngame
val mousePoint = Point2d(Terrarum.mouseTileX.toDouble(), Terrarum.mouseTileY.toDouble())
val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY)
@@ -45,21 +46,21 @@ object BlockBase {
if (gameItem.inventoryCategory == GameItem.Category.BLOCK &&
gameItem.dynamicID == ingame.world.getTileFromTerrain(mouseTile.x, mouseTile.y) ||
gameItem.inventoryCategory == GameItem.Category.WALL &&
gameItem.dynamicID - ItemCodex.ITEM_WALLS.start == ingame.world.getTileFromWall(mouseTile.x, mouseTile.y)
)
gameItem.dynamicID == ingame.world.getTileFromWall(mouseTile.x, mouseTile.y)
)
return false
// filter passed, do the job
// FIXME this is only useful for Player
if (itemID in ItemCodex.ITEM_TILES) {
ingame.world.setTileTerrain(
if (itemID.startsWith("wall@")) {
ingame.world.setTileWall(
mouseTile.x,
mouseTile.y,
itemID
itemID.substring(5)
)
}
else {
ingame.world.setTileWall(
ingame.world.setTileTerrain(
mouseTile.x,
mouseTile.y,
itemID
@@ -74,7 +75,8 @@ object BlockBase {
}
fun wireStartPrimaryUse(gameItem: GameItem, wireTypeBit: Int, delta: Float): Boolean {
val ingame = Terrarum.ingame!! as TerrarumIngame
return false // TODO need new wire storing format
/*val ingame = Terrarum.ingame!! as TerrarumIngame
val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY)
// return false if the tile is already there
@@ -93,7 +95,7 @@ object BlockBase {
)
)
return true
return true*/
}
fun wireEffectWhenEquipped(typebit: Int, delta: Float) {