fix(game): trigger warps by their tile behaviour (#93)

* fix(game): use the npc's own region for map and sprite lookups

* fix(game): trigger warps by their tile behaviour

* fix(game): classify every warp metatile behaviour the decomp accepts
This commit is contained in:
Fiereu authored and GitHub committed 2026-08-07 10:57:17 +02:00
1 parent 9866c1b0fb
commit 14fbc05bab
6 files changed
+177 -24

No files matched your search

@@ -115,14 +115,14 @@ constructor(
toY = landing.second
}
// Some warps trigger from their current tile.
val onTileWarp =
currentMap.warps.find { w ->
w.x == fromX && w.y == fromY && w.facingDirection == msg.direction
}
if (onTileWarp != null) {
warpService.executeWarp(ctx, charId, onTileWarp)
return
// Stairs and arrow warps fire from the tile the player stands on.
val standingBehavior = currentMap.tileAt(fromX, fromY)?.behavior
if (standingBehavior?.warpsWhenWalking == msg.direction) {
val onTileWarp = currentMap.warps.find { it.x == fromX && it.y == fromY }
if (onTileWarp != null) {
warpService.executeWarp(ctx, charId, onTileWarp)
return
}
}
// Walking off the edge of a map hands the player to the neighbouring map, if there is one.
@@ -161,13 +161,14 @@ constructor(
return
}
// Warps fire on the destination tile.
val warp =
currentMap.warps.find { w ->
w.x == toX &&
w.y == toY &&
(w.facingDirection == null || w.facingDirection == msg.direction)
// A door only warps when walked into from below, a ladder warps on the step itself.
val targetBehavior = currentMap.tileAt(toX, toY)?.behavior
val stepsIntoWarp =
when (targetBehavior) {
TileBehavior.DOOR -> msg.direction == Direction.UP
else -> targetBehavior?.warpsOnStep == true
}
val warp = if (!stepsIntoWarp) null else currentMap.warps.find { w -> w.x == toX && w.y == toY }
if (warp != null) {
log.info { "WARP at ($toX, $toY) facing ${msg.direction}" }
// A MAP_DYNAMIC warp (the truck exit) resolves to the destination a script set on the player.
@@ -39,12 +39,13 @@ constructor(
val knownOverride =
WarpExitRules.getKnownOverride(sourceMap, destMap, warp.targetX, warp.targetY)
val destBehavior = destMap?.tileAt(warp.targetX, warp.targetY)?.behavior
val warpFacing =
warp.exitFacing
?: knownOverride?.facing
?: WarpExitRules.inferExitFacing(
destTileBehavior = null,
destTileBehavior = destBehavior,
destMap = destMap,
destX = warp.targetX,
destY = warp.targetY,
@@ -58,7 +59,11 @@ constructor(
val shouldAutoStepOffWarp =
knownOverride?.autoStep
?: WarpExitRules.shouldAutoStep(sourceMap = sourceMap, destMap = destMap)
?: WarpExitRules.shouldAutoStep(
sourceMap = sourceMap,
destMap = destMap,
destTileBehavior = destBehavior,
)
if (shouldAutoStepOffWarp && destMap != null) {
val destWarp = destMap.warps.find { it.x == offsetX && it.y == offsetY }
if (destWarp != null) {
@@ -2,6 +2,7 @@ package de.fiereu.openmmo.server.game.world
import de.fiereu.openmmo.common.enums.Direction
import de.fiereu.openmmo.common.enums.MapType
import de.fiereu.openmmo.common.enums.TileBehavior
import de.fiereu.openmmo.maps.MapDef
data class WarpExitOverride(
@@ -12,7 +13,7 @@ data class WarpExitOverride(
object WarpExitRules {
fun inferExitFacing(
destTileBehavior: String?,
destTileBehavior: TileBehavior?,
destMap: MapDef?,
destX: Int,
destY: Int,
@@ -20,13 +21,15 @@ object WarpExitRules {
): Direction {
if (destMap == null) return Direction.DOWN
// The tile itself is exact, so it wins over the guesses below.
when (destTileBehavior) {
"MB_NON_ANIMATED_DOOR",
"MB_ANIMATED_DOOR" -> return Direction.DOWN
"MB_NORTH_ARROW_WARP" -> return Direction.DOWN
"MB_SOUTH_ARROW_WARP" -> return Direction.UP
"MB_WEST_ARROW_WARP" -> return Direction.RIGHT
"MB_EAST_ARROW_WARP" -> return Direction.LEFT
TileBehavior.DOOR,
TileBehavior.NON_ANIMATED_DOOR -> return Direction.DOWN
TileBehavior.NORTH_ARROW_WARP -> return Direction.DOWN
TileBehavior.SOUTH_ARROW_WARP -> return Direction.UP
TileBehavior.WEST_ARROW_WARP -> return Direction.RIGHT
TileBehavior.EAST_ARROW_WARP -> return Direction.LEFT
else -> Unit
}
val sourceMapType = sourceMap?.mapType
@@ -103,9 +106,20 @@ object WarpExitRules {
fun shouldAutoStep(
sourceMap: MapDef?,
destMap: MapDef?,
destTileBehavior: TileBehavior? = null,
): Boolean {
if (sourceMap == null || destMap == null) return false
// An animated door drops the player below it, every other warp tile keeps them on it.
when (destTileBehavior) {
TileBehavior.DOOR -> return true
TileBehavior.NON_ANIMATED_DOOR,
TileBehavior.LADDER,
TileBehavior.STAIR_WARP_EAST,
TileBehavior.STAIR_WARP_WEST -> return false
else -> Unit
}
val sourceBuilding =
sourceMap.mapType == MapType.INSIDE || sourceMap.mapType == MapType.SECRET_BASE
@@ -0,0 +1,74 @@
package de.fiereu.openmmo.server.game.world
import de.fiereu.openmmo.common.enums.Direction
import de.fiereu.openmmo.common.enums.TileBehavior
import de.fiereu.openmmo.maps.MapManager
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
private const val KANTO = 0
private const val TOWNS_AND_ROUTES_BANK = 3
private const val PALLET_TOWN_MAP = 0
private const val ROUTE_4_MAP = 22
private const val INDOOR_PALLET_BANK = 4
private const val PLAYERS_HOUSE_1F = 0
private const val PLAYERS_HOUSE_2F = 1
class WarpTileBehaviorTest :
FunSpec({
val maps = MapManager()
test("Kanto doors and stairs are classified from the decomp") {
val town = maps.getMap(KANTO, TOWNS_AND_ROUTES_BANK, PALLET_TOWN_MAP)!!
town.tileAt(6, 7)!!.behavior shouldBe TileBehavior.DOOR
// Right goes up, left comes back down.
val house1f = maps.getMap(KANTO, INDOOR_PALLET_BANK, PLAYERS_HOUSE_1F)!!
val house2f = maps.getMap(KANTO, INDOOR_PALLET_BANK, PLAYERS_HOUSE_2F)!!
house1f.tileAt(10, 2)!!.behavior shouldBe TileBehavior.STAIR_WARP_EAST
house2f.tileAt(10, 2)!!.behavior shouldBe TileBehavior.STAIR_WARP_WEST
house1f.tileAt(10, 2)!!.behavior.warpsWhenWalking shouldBe Direction.RIGHT
house2f.tileAt(10, 2)!!.behavior.warpsWhenWalking shouldBe Direction.LEFT
}
test("standing on stairs only warps when walking the way they point") {
val stairs = maps.getMap(KANTO, INDOOR_PALLET_BANK, PLAYERS_HOUSE_1F)!!.tileAt(10, 2)!!
stairs.behavior.warpsWhenWalking shouldBe Direction.RIGHT
(stairs.behavior.warpsWhenWalking == Direction.LEFT) shouldBe false
(stairs.behavior.warpsWhenWalking == Direction.UP) shouldBe false
(stairs.behavior.warpsWhenWalking == Direction.DOWN) shouldBe false
stairs.behavior.warpsOnStep shouldBe false
}
test("a door drops the player out facing down and off the tile") {
val town = maps.getMap(KANTO, TOWNS_AND_ROUTES_BANK, PALLET_TOWN_MAP)!!
val house = maps.getMap(KANTO, INDOOR_PALLET_BANK, PLAYERS_HOUSE_1F)!!
WarpExitRules.inferExitFacing(
destTileBehavior = TileBehavior.DOOR,
destMap = town,
destX = 6,
destY = 7,
sourceMap = house,
) shouldBe Direction.DOWN
WarpExitRules.shouldAutoStep(house, town, TileBehavior.DOOR) shouldBe true
TileBehavior.DOOR.warpsWhenWalking shouldBe null
}
test("a cave entrance warps on the step, in any direction") {
val route4 = maps.getMap(KANTO, TOWNS_AND_ROUTES_BANK, ROUTE_4_MAP)!!
val entrance = route4.tileAt(19, 5)!!.behavior
entrance shouldBe TileBehavior.NON_ANIMATED_DOOR
entrance.warpsOnStep shouldBe true
entrance.warpsWhenWalking shouldBe null
}
test("stairs leave the player standing on the tile") {
val house1f = maps.getMap(KANTO, INDOOR_PALLET_BANK, PLAYERS_HOUSE_1F)!!
val house2f = maps.getMap(KANTO, INDOOR_PALLET_BANK, PLAYERS_HOUSE_2F)!!
WarpExitRules.shouldAutoStep(house1f, house2f, TileBehavior.STAIR_WARP_EAST) shouldBe false
}
})