fixed a bug where blocks are still consumend even if there is a block already under the cursor

This commit is contained in:
minjaesong
2022-07-14 17:07:59 +09:00
parent 69c5ceb61f
commit 23c2d86c27
3 changed files with 13 additions and 13 deletions

Binary file not shown.

View File

@@ -69,7 +69,7 @@ class ActorInventory() : FixtureInventory() {
fun consumeItem(item: GameItem, amount: Long = 1L) {
val actor = this.actor as Actor
if (item.isDynamic && amount != 1L) throw IllegalArgumentException("Dynamic item must be consumed 'once' (expected 1, got $amount)")
if (amount < 0) throw IllegalArgumentException("Consuming negative amount of an item (expected >=0, got $amount)")
if (item.stackable && !item.isDynamic) {
remove(item, amount)

View File

@@ -29,7 +29,7 @@ object BlockBase {
// FIXME actually it's this code: not recognising hitbox's starting point correctly. Use F9 for visualisation
// FIXME the above issue is resolved by using intTilewise instead of hInt, but the hitbox itself is still
// FIXME badly defined
if (gameItem.inventoryCategory == GameItem.Category.BLOCK) {
var ret1 = true
ingame.actorContainerActive.forEach {
@@ -39,20 +39,17 @@ object BlockBase {
if (!ret1) return@mouseInInteractableRange -1L
}
// return false if the tile underneath is:
// 0. same tile
// 1. actorblock
if (gameItem.inventoryCategory == GameItem.Category.BLOCK &&
gameItem.dynamicID == ingame.world.getTileFromTerrain(mouseTile.x, mouseTile.y) ||
gameItem.inventoryCategory == GameItem.Category.WALL &&
gameItem.dynamicID == "wall@" + ingame.world.getTileFromWall(mouseTile.x, mouseTile.y) ||
BlockCodex[ingame.world.getTileFromTerrain(mouseTile.x, mouseTile.y)].nameKey.contains("ACTORBLOCK_")
)
return@mouseInInteractableRange 1L
val isWall = itemID.startsWith("wall@")
val terrainUnderCursor = ingame.world.getTileFromTerrain(mouseTile.x, mouseTile.y)
val wallUnderCursor = ingame.world.getTileFromWall(mouseTile.x, mouseTile.y)
// return false if there is a tile already
if (isWall && BlockCodex[wallUnderCursor].isSolid || !isWall && BlockCodex[terrainUnderCursor].isSolid)
return@mouseInInteractableRange -1L
// filter passed, do the job
// FIXME this is only useful for Player
if (itemID.startsWith("wall@")) {
if (isWall) {
ingame.world.setTileWall(
mouseTile.x,
mouseTile.y,