fixes, bits and pieces, changes in ID referencing, terrain and wall takes damage, working test pickaxe, and a new issue

This commit is contained in:
Song Minjae
2017-04-17 02:18:52 +09:00
parent 6087072d3d
commit f2ae2d9449
40 changed files with 502 additions and 249 deletions

View File

@@ -11,6 +11,8 @@ import net.torvald.terrarum.gamecontroller.mouseTileY
import net.torvald.terrarum.gameitem.IVKey
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.mapdrawer.TilesDrawer
import net.torvald.terrarum.mapdrawer.TilesDrawer.wallOverlayColour
import net.torvald.terrarum.tileproperties.Tile
import net.torvald.terrarum.tileproperties.TileCodex
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Image
@@ -28,31 +30,35 @@ object ItemCodex {
private val itemCodex = HashMap<Int, InventoryItem>()
private val dynamicItemDescription = HashMap<Int, KVHashMap>()
val ITEM_TILE_MAX = GameWorld.TILES_SUPPORTED - 1 // 4095
val ITEM_COUNT_MAX = 1048576
val ITEM_DYNAMIC_MAX = ITEM_COUNT_MAX - 1
val ITEM_STATIC_MAX = 32767
val ITEM_DYNAMIC_MIN = ITEM_STATIC_MAX + 1
val ITEM_STATIC_MIN = ITEM_TILE_MAX + 1 // 4096
val ITEM_TILES = 0..GameWorld.TILES_SUPPORTED - 1
val ITEM_WALLS = GameWorld.TILES_SUPPORTED..GameWorld.TILES_SUPPORTED * 2 - 1
val ITEM_WIRES = GameWorld.TILES_SUPPORTED * 2..GameWorld.TILES_SUPPORTED * 2 + 255
val ITEM_STATIC = ITEM_WIRES.endInclusive + 1..32767
val ITEM_DYNAMIC = 32768..1048575
val ACTOR_ID_MIN = ITEM_DYNAMIC.endInclusive + 1
private val itemImagePlaceholder = Image("./assets/item_kari_24.tga")
init {
// tile items (blocks and walls are the same thing basically)
for (i in 0..ITEM_TILE_MAX) {
for (i in ITEM_TILES + ITEM_WALLS) {
itemCodex[i] = object : InventoryItem() {
override val id: Int = i
override val isUnique: Boolean = false
override var baseMass: Double = TileCodex[i].density / 1000.0
override var baseToolSize: Double? = null
override var equipPosition = EquipPosition.HAND_GRIP
override var category = "block"
override val originalName = TileCodex[i].nameKey
override val originalName = TileCodex[i % ITEM_WALLS.first].nameKey
override var consumable = true
override var inventoryCategory = Category.BLOCK
init {
itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.BLOCK
itemProperties[IVKey.ITEMTYPE] = if (i in ITEM_TILES)
IVKey.ItemType.BLOCK
else
IVKey.ItemType.WALL
}
override fun primaryUse(gc: GameContainer, delta: Int): Boolean {
@@ -74,26 +80,81 @@ object ItemCodex {
// filter passed, do the job
// FIXME this is only useful for Player
Terrarum.ingame!!.world.setTileTerrain(
gc.mouseTileX,
gc.mouseTileY,
i
)
if (i in ITEM_TILES) {
Terrarum.ingame!!.world.setTileTerrain(
gc.mouseTileX,
gc.mouseTileY,
i
)
}
else {
Terrarum.ingame!!.world.setTileWall(
gc.mouseTileX,
gc.mouseTileY,
i
)
}
return true
}
}
}
// read prop in csv and fill itemCodex
// test copper pickaxe
itemCodex[ITEM_STATIC.first] = object : InventoryItem() {
override val id = ITEM_STATIC.first
override val isUnique = false
override val originalName = "Test Pick"
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 durability = maxDurability.toFloat()
override var equipPosition = EquipPosition.HAND_GRIP
override var inventoryCategory = Category.TOOL
init {
itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.PICK
}
override fun primaryUse(gc: GameContainer, delta: Int): Boolean {
val mousePoint = Point2d(gc.mouseTileX.toDouble(), gc.mouseTileY.toDouble())
// 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))
return false
}
// return false if the tile is already there
if (this.id == Terrarum.ingame!!.world.getTileFromTerrain(gc.mouseTileX, gc.mouseTileY))
return false
// filter passed, do the job
Terrarum.ingame!!.world.setTileTerrain(
gc.mouseTileX,
gc.mouseTileY,
Tile.AIR
)
/*Terrarum.ingame!!.world.inflctTerrainDamage(
gc.mouseTileX,
gc.mouseTileY,
<power calculation using ForceMod (ref. Pickaxe Power.xlsx) and other shits>
)*/
return true
}
}
// TODO read prop in Lua and fill itemCodex
// read from save (if applicable) and fill dynamicItemDescription
}
operator fun get(code: Int): InventoryItem {
if (code < ITEM_STATIC_MAX) // generic item
return itemCodex[code]!! // from CSV
else if (code < ITEM_DYNAMIC_MAX) {
if (code <= ITEM_STATIC.endInclusive) // generic item
return itemCodex[code]!!.clone() // from CSV
else if (code <= ITEM_DYNAMIC.endInclusive) {
TODO("read from dynamicitem description (JSON)")
}
else {
@@ -105,8 +166,15 @@ object ItemCodex {
}
fun getItemImage(code: Int): Image {
if (code <= ITEM_TILE_MAX)
if (code <= ITEM_TILES.endInclusive)
return TilesDrawer.tilesTerrain.getSubImage((code % 16) * 16, code / 16)
else if (code <= ITEM_WALLS.endInclusive) {
val img = TilesDrawer.tilesTerrain.getSubImage((code % 16) * 16, code / 16)
img.setImageColor(wallOverlayColour.r, wallOverlayColour.g, wallOverlayColour.b)
return img
}
else if (code <= ITEM_WIRES.endInclusive)
return TilesDrawer.tilesWire.getSubImage((code % 16) * 16, code / 16)
else
return itemImagePlaceholder
}

View File

@@ -0,0 +1,61 @@
package net.torvald.terrarum.itemproperties
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ai.toLua
import net.torvald.terrarum.gamecontroller.mouseTileX
import net.torvald.terrarum.gamecontroller.mouseTileY
import net.torvald.terrarum.gamecontroller.mouseX
import net.torvald.terrarum.gamecontroller.mouseY
import org.luaj.vm2.Globals
import org.luaj.vm2.LuaTable
import org.luaj.vm2.LuaValue
import org.luaj.vm2.lib.ThreeArgFunction
import org.luaj.vm2.lib.ZeroArgFunction
/**
* Created by SKYHi14 on 2017-04-16.
*/
class ItemEffectsLuaAPI(g: Globals) {
init {
g["getMouseTile"] = GetMouseTile()
g["getMousePos"] = GetMousePos()
g["world"] = LuaTable()
g["world"]["strikeEarth"] = StrikeEarth()
g["world"]["strikeWall"] = StrikeWall()
g["actor"] = LuaTable()
}
class GetMouseTile : ZeroArgFunction() {
override fun call(): LuaValue {
return LuaValue.tableOf(arrayOf(Terrarum.appgc.mouseTileX.toLua(), Terrarum.appgc.mouseTileY.toLua()))
}
}
class GetMousePos : ZeroArgFunction() {
override fun call(): LuaValue {
return LuaValue.tableOf(arrayOf(Terrarum.appgc.mouseX.toLua(), Terrarum.appgc.mouseY.toLua()))
}
}
class StrikeEarth : ThreeArgFunction() {
override fun call(x: LuaValue, y: LuaValue, power: LuaValue): LuaValue {
Terrarum.ingame!!.world.inflctTerrainDamage(x.checkint(), y.checkint(), power.checkint())
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())
return LuaValue.NONE
}
}
}