furred npc test might delete later

This commit is contained in:
minjaesong
2019-05-20 12:07:01 +09:00
parent 3106657f44
commit b52dd12807
60 changed files with 306 additions and 91 deletions

View File

@@ -0,0 +1,97 @@
package net.torvald.terrarum.modulebasegame.gameitems
import net.torvald.terrarum.Point2d
import net.torvald.terrarum.Point2i
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.IngameRenderer
import net.torvald.terrarum.realestate.LandUtil
/**
* Created by minjaesong on 2019-05-02.
*/
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 {
val ingame = Terrarum.ingame!! as Ingame
val mousePoint = Point2d(Terrarum.mouseTileX.toDouble(), Terrarum.mouseTileY.toDouble())
val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY)
// check for collision with actors (BLOCK only)
if (gameItem.inventoryCategory == GameItem.Category.BLOCK) {
var ret1 = true
ingame.actorContainerActive.forEach {
if (it is ActorWBMovable && it.hIntTilewiseHitbox.intersects(mousePoint))
ret1 = false // return is not allowed here
}
if (!ret1) return ret1
}
// return false if the tile is already there
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)
)
return false
// filter passed, do the job
// FIXME this is only useful for Player
if (itemID in ItemCodex.ITEM_TILES) {
ingame.world.setTileTerrain(
mouseTile.x,
mouseTile.y,
itemID
)
}
else {
ingame.world.setTileWall(
mouseTile.x,
mouseTile.y,
itemID
)
}
return true
}
fun blockEffectWhenEquipped(delta: Float) {
IngameRenderer.selectedWireBitToDraw = 0
}
fun wireStartPrimaryUse(gameItem: GameItem, wireTypeBit: Int, delta: Float): Boolean {
val ingame = Terrarum.ingame!! as Ingame
val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY)
// return false if the tile is already there
if (ingame.world.getWiringBlocks(mouseTile.x, mouseTile.y) and wireTypeBit != 0)
return false
// filter passed, do the job
// FIXME this is only useful for Player
ingame.world.addNewConduitTo(
mouseTile.x,
mouseTile.y,
GameWorld.WiringNode(
LandUtil.getBlockAddr(ingame.world, mouseTile.x, mouseTile.y),
wireTypeBit,
0f
)
)
return true
}
fun wireEffectWhenEquipped(typebit: Int, delta: Float) {
IngameRenderer.selectedWireBitToDraw = typebit
}
}

View File

@@ -0,0 +1,153 @@
package net.torvald.terrarum.modulebasegame.gameitems
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.Point2d
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.itemproperties.Calculate
import net.torvald.terrarum.itemproperties.MaterialCodex
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore.BASE_MASS_AND_SIZE
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore.TOOL_DURABILITY_BASE
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import kotlin.math.roundToInt
/**
* Created by minjaesong on 2019-03-10.
*/
object PickaxeCore {
fun startPrimaryUse(delta: Float, item: GameItem): Boolean {
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return false
val mouseTileX = Terrarum.mouseTileX
val mouseTileY = Terrarum.mouseTileY
val mousePoint = Point2d(mouseTileX.toDouble(), mouseTileY.toDouble())
val actorvalue = player.actorValue
item.using = true
// linear search filter (check for intersection with tilewise mouse point and tilewise hitbox)
// return false if hitting actors
var ret1 = true
Terrarum.ingame!!.actorContainerActive.forEach {
if (it is ActorWBMovable && it.hIntTilewiseHitbox.intersects(mousePoint))
ret1 = false // return is not allowed here
}
if (!ret1) return ret1
// return false if here's no tile
if (Block.AIR == (Terrarum.ingame!!.world).getTileFromTerrain(mouseTileX, mouseTileY))
return false
// filter passed, do the job
val swingDmgToFrameDmg = delta.toDouble() / actorvalue.getAsDouble(AVKey.ACTION_INTERVAL)!!
(Terrarum.ingame!!.world).inflictTerrainDamage(
mouseTileX, mouseTileY,
Calculate.pickaxePower(player, item.material) * swingDmgToFrameDmg
)
return true
}
fun endPrimaryUse(delta: Float, item: GameItem): Boolean {
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return false
item.using = false
// reset action timer to zero
player.actorValue.set(AVKey.__ACTION_TIMER, 0.0)
return true
}
const val BASE_MASS_AND_SIZE = 10.0 // of iron pick
const val TOOL_DURABILITY_BASE = 350 // of iron pick
}
/**
* Created by minjaesong on 2017-07-17.
*/
class PickaxeCopper(originalID: ItemID) : GameItem(originalID) {
override val originalName = "PACKAGED_PICK"
override var baseToolSize: Double? = BASE_MASS_AND_SIZE
override var stackable = true
override var inventoryCategory = Category.TOOL
override val isUnique = false
override val isDynamic = true
override val material = MaterialCodex["CUPR"]
override var baseMass = material.density.toDouble() / MaterialCodex["IRON"].density * BASE_MASS_AND_SIZE
override val itemImage: TextureRegion?
get() = (AppLoader.resourcePool["basegame.items24"] as TextureRegionPack).get(0,0)
init {
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
super.maxDurability = (TOOL_DURABILITY_BASE * material.enduranceMod).roundToInt()
super.durability = maxDurability.toFloat()
super.name = "Copper Pickaxe"
}
override fun startPrimaryUse(delta: Float) = PickaxeCore.startPrimaryUse(delta, this)
override fun endPrimaryUse(delta: Float) = PickaxeCore.endPrimaryUse(delta, this)
}
/**
* Created by minjaesong on 2019-03-10.
*/
class PickaxeIron(originalID: ItemID) : GameItem(originalID) {
override val originalName = "PACKAGED_PICK"
override var baseToolSize: Double? = BASE_MASS_AND_SIZE
override var stackable = true
override var inventoryCategory = Category.TOOL
override val isUnique = false
override val isDynamic = true
override val material = MaterialCodex["IRON"]
override var baseMass = material.density.toDouble() / MaterialCodex["IRON"].density * BASE_MASS_AND_SIZE
override val itemImage: TextureRegion?
get() = (AppLoader.resourcePool["basegame.items24"] as TextureRegionPack).get(1,0)
init {
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
super.maxDurability = (TOOL_DURABILITY_BASE * material.enduranceMod).roundToInt()
super.durability = maxDurability.toFloat()
super.name = "Iron Pickaxe"
}
override fun startPrimaryUse(delta: Float) = PickaxeCore.startPrimaryUse(delta, this)
override fun endPrimaryUse(delta: Float) = PickaxeCore.endPrimaryUse(delta, this)
}
/**
* Created by minjaesong on 2019-03-10.
*/
class PickaxeSteel(originalID: ItemID) : GameItem(originalID) {
override val originalName = "PACKAGED_PICK"
override var baseToolSize: Double? = BASE_MASS_AND_SIZE
override var stackable = true
override var inventoryCategory = Category.TOOL
override val isUnique = false
override val isDynamic = true
override val material = MaterialCodex["STAL"]
override var baseMass = material.density.toDouble() / MaterialCodex["IRON"].density * BASE_MASS_AND_SIZE
override val itemImage: TextureRegion?
get() = (AppLoader.resourcePool["basegame.items24"] as TextureRegionPack).get(2,0)
init {
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
super.maxDurability = (TOOL_DURABILITY_BASE * material.enduranceMod).roundToInt()
super.durability = maxDurability.toFloat()
super.name = "Steel Pickaxe"
}
override fun startPrimaryUse(delta: Float) = PickaxeCore.startPrimaryUse(delta, this)
override fun endPrimaryUse(delta: Float) = PickaxeCore.endPrimaryUse(delta, this)
}

View File

@@ -0,0 +1,34 @@
package net.torvald.terrarum.modulebasegame.gameitems
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.modulebasegame.gameactors.FixtureTikiTorch
/**
* Created by minjaesong on 2019-05-16.
*/
class TikiTorchTester(originalID: ItemID) : GameItem(originalID) {
override var dynamicID: ItemID = originalID
override val originalName = "Tiki Torch"
override var baseMass = 1.0
override var stackable = true
override var inventoryCategory = Category.FIXTURE
override val isUnique = false
override val isDynamic = false
override val material = Material()
override val itemImage: TextureRegion?
get() = AppLoader.resourcePool.getAsTextureRegion("itemplaceholder_48")
override var baseToolSize: Double? = baseMass
override fun startPrimaryUse(delta: Float): Boolean {
val torch = FixtureTikiTorch()
return torch.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - torch.blockBox.height + 1)
// return true when placed, false when cannot be placed
}
}

View File

@@ -0,0 +1,30 @@
package net.torvald.terrarum.modulebasegame.gameitems
import net.torvald.random.Fudge3
import net.torvald.random.HQRNG
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
import kotlin.math.pow
/**
* Created by minjaesong on 2019-03-17.
*/
object WeaponMeleeCore {
val SQRT2 = Math.sqrt(2.0)
private val dF3 = Fudge3(HQRNG())
private val randomiser = doubleArrayOf(0.94, 0.96, 0.98, 1.0, 1.02, 1.04, 1.06)
private fun randomise() = dF3.rollForArray(randomiser)
private fun getAttackMomentum(weapon: WeaponMeleeBase, actor: ActorHumanoid) =
weapon.mass * weapon.material.density * weapon.velocityMod * actor.scale.pow(SQRT2) // TODO multiply racial strength from RaceCodex
fun getAttackPower(weapon: WeaponMeleeBase, actor: ActorHumanoid, actee: ActorHumanoid) =
getAttackMomentum(weapon, actor) * randomise() * maxOf(1.0, (actee.hitbox.endY - actor.hitbox.startY) / actee.hitbox.height)
}
abstract class WeaponMeleeBase(originalID: ItemID) : GameItem(originalID) {
abstract val velocityMod: Double
}

View File

@@ -0,0 +1,39 @@
package net.torvald.terrarum.modulebasegame.gameitems
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.blockproperties.Wire
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.itemproperties.Material
/**
* Created by minjaesong on 2019-03-10.
*/
class WirePieceSignalWire(originalID: ItemID) : GameItem(originalID) {
override var dynamicID: ItemID = originalID
override val originalName = "ITEM_WIRE"
override var baseMass = 0.001
override var baseToolSize: Double? = null
override var stackable = true
override var inventoryCategory = Category.WIRE
override val isUnique = false
override val isDynamic = false
override val material = Material()
override val itemImage: TextureRegion?
get() = AppLoader.resourcePool.getAsTextureRegionPack("basegame.items16").get(1,9)
init {
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
}
override fun startPrimaryUse(delta: Float): Boolean {
return BlockBase.wireStartPrimaryUse(this, Wire.BIT_SIGNAL_RED, delta)
}
override fun effectWhenEquipped(delta: Float) {
BlockBase.wireEffectWhenEquipped(Wire.BIT_SIGNAL_RED, delta)
}
}