diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcSpawnPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcSpawnPacket.kt index 2938132..824ba41 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcSpawnPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcSpawnPacket.kt @@ -4,8 +4,9 @@ import de.fiereu.bytecodec.* data class NpcSpawnPacket( val entityId: Long, - val unk1: Int, - val unk2: Int, + /** Which region's sprite table [graphicsId] is looked up in. */ + val spriteRegionId: Int, + val graphicsId: Int, val unk3: Int, val unk4: Int, val regionId: Int, @@ -21,8 +22,8 @@ data class NpcSpawnPacket( object NpcSpawnPacketCodec : PacketCodec() { override fun CodecScope.body(): NpcSpawnPacket { val entityId = field(S64LE) { it.entityId } - val unk1 = field(U8) { it.unk1 } - val unk2 = field(U16LE) { it.unk2 } + val spriteRegionId = field(U8) { it.spriteRegionId } + val graphicsId = field(U16LE) { it.graphicsId } val unk3 = field(U16LE) { it.unk3 } val unk4 = field(U16LE) { it.unk4 } val regionId = field(U8) { it.regionId } @@ -34,6 +35,18 @@ object NpcSpawnPacketCodec : PacketCodec() { val facing = field(U8) { it.facing } val unk6 = field(U16LE) { it.unk6 } return NpcSpawnPacket( - entityId, unk1, unk2, unk3, unk4, regionId, bankId, mapId, x, y, facing, unk5, unk6) + entityId, + spriteRegionId, + graphicsId, + unk3, + unk4, + regionId, + bankId, + mapId, + x, + y, + facing, + unk5, + unk6) } } diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/InteractionService.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/InteractionService.kt index 87c800c..5f3a42c 100644 --- a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/InteractionService.kt +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/InteractionService.kt @@ -44,11 +44,12 @@ constructor( stored.info.positionBankId, stored.info.positionMapId, ) ?: return + val regionId = stored.info.positionRegionId.toInt() val bankId = stored.info.positionBankId.toInt() val mapId = stored.info.positionMapId.toInt() for (npc in currentMap.npcs) { - if (npcService.getNpcEntityId(bankId, mapId, npc.entityIdx) == npcEntityId) { + if (npcService.getNpcEntityId(regionId, bankId, mapId, npc.entityIdx) == npcEntityId) { val script = scriptRegistry.forLabel(npc.script) if (script != null) { runScript(session, state, script, npcEntityId) diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/LoginService.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/LoginService.kt index 79a6d55..80f0429 100644 --- a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/LoginService.kt +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/LoginService.kt @@ -290,6 +290,10 @@ constructor( ) { val map = mapManager.getMap(info.positionRegionId, info.positionBankId, info.positionMapId) if (map != null) { + log.info { + "Placing '${info.name}' at ${info.positionRegionId}:${info.positionBankId}:" + + "${info.positionMapId} (${info.positionX}, ${info.positionY})" + } ctx.send(mapManager.createLoadMapPacket(map, reloadPlayer = true, deleteCache = true)) mapLoadService.preloadConnectedMaps(ctx, map) } else { diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/MapLoadService.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/MapLoadService.kt index e63f71f..4078fb9 100644 --- a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/MapLoadService.kt +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/MapLoadService.kt @@ -56,7 +56,8 @@ constructor( for (conn in connections) { val key = "${conn.targetBank}:${conn.targetMap}" if (!loaded.add(key)) continue - val connected = mapManager.getMap(1, conn.targetBank, conn.targetMap) + // Connections stay inside one region. + val connected = mapManager.getMap(map.regionId.toInt(), conn.targetBank, conn.targetMap) if (connected != null) { ctx.send( mapManager.createLoadMapPacket( diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/MovementService.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/MovementService.kt index a206990..da4d980 100644 --- a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/MovementService.kt +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/MovementService.kt @@ -128,8 +128,11 @@ constructor( // Walking off the edge of a map hands the player to the neighbouring map, if there is one. if (toX !in 0 until currentMap.width || toY !in 0 until currentMap.height) { val connection = currentMap.connections.find { it.direction == msg.direction } + // Connections stay inside one region. val targetMap = - connection?.let { mapManager.getMap(1, it.targetBank.toByte(), it.targetMap.toByte()) } + connection?.let { + mapManager.getMap(currentMap.regionId, it.targetBank.toByte(), it.targetMap.toByte()) + } if (connection == null || targetMap == null) { sendPositionReset(ctx, charId, currentMap, fromX, fromY, msg.direction) return @@ -146,7 +149,15 @@ constructor( Direction.DOWN -> 0 else -> (fromY - connection.unknown).coerceIn(0, targetMap.height - 1) } - edgeTransition(ctx, charId, connection, entryX.toByte(), entryY.toByte(), msg.direction) + edgeTransition( + ctx, + charId, + currentMap.regionId, + connection, + entryX.toByte(), + entryY.toByte(), + msg.direction, + ) return } @@ -262,6 +273,7 @@ constructor( private fun edgeTransition( ctx: SessionContext, charId: Long, + regionId: Byte, connection: MapData.GbaConnection, targetX: Byte, targetY: Byte, @@ -269,7 +281,7 @@ constructor( ) { val targetBank = connection.targetBank.toByte() val targetMap = connection.targetMap.toByte() - val map = mapManager.getMap(1, targetBank, targetMap) ?: return + val map = mapManager.getMap(regionId, targetBank, targetMap) ?: return val state = ctx.attributes[PLAYER_STATE] if (state != null) { @@ -289,7 +301,7 @@ constructor( presenceService.refresh(ctx) mapLoadService.preloadConnectedMaps(ctx, map, depth = 1) - npcService.spawnNpcsForMap(ctx, targetBank.toInt(), targetMap.toInt(), state?.regionId ?: 1) + npcService.spawnNpcsForMap(ctx, targetBank.toInt(), targetMap.toInt(), regionId.toInt()) ctx.send(gbaMovePacket(charId, map, targetX.toInt(), targetY.toInt(), direction)) diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/NpcService.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/NpcService.kt index 44c0366..84f0150 100644 --- a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/NpcService.kt +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/NpcService.kt @@ -29,75 +29,16 @@ constructor( private val npcEntityIdCounter = AtomicLong(0x1A69000000000000L) private val npcEntityIds = mutableMapOf() - fun getNpcEntityId(bankId: Int, mapId: Int, entityIdx: Int): Long? { - return npcEntityIds["$bankId:$mapId:$entityIdx"] + fun getNpcEntityId(regionId: Int, bankId: Int, mapId: Int, entityIdx: Int): Long? { + return npcEntityIds[key(regionId, bankId, mapId, entityIdx)] } - fun spawnNpcsForMap(ctx: SessionContext, bankId: Int, mapId: Int, regionId: Int = 1) { + fun spawnNpcsForMap(ctx: SessionContext, bankId: Int, mapId: Int, regionId: Int) { val map = mapManager.getMap(regionId, bankId, mapId) ?: return val stored = ctx.attributes[PLAYER_STATE]?.characterId?.let(characterStore::getCharacter) val storyFlags = stored?.storyFlags.orEmpty() val storyVars = stored?.storyVars.orEmpty() - // Generated Petalburg data now supplies these NPCs. - if (regionId == 1 && USE_LEGACY_PETALBURG_SPAWNS && bankId == 74 && mapId == 11) { - data class NpcEntry( - val entityIdx: Int, - val x: Int, - val y: Int, - val gfx: Int, - val unk1: Int, - val unk3: Int, - val unk4: Int, - val facing: Int, - val unk6: Int, - ) - val all16 = - listOf( - NpcEntry(7, 15, 19, 9, 1, 768, 513, 0, 8), - NpcEntry(6, 4, 8, 59, 1, 256, 0, 0, 8), - NpcEntry(5, 35, 20, 59, 1, 2048, 0, 0, 8), - NpcEntry(4, 45, 7, 59, 1, 2048, 0, 0, 8), - NpcEntry(3, 26, 20, 23, 1, 256, 0, 0, 0), - NpcEntry(2, 26, 17, 117, 1, 2563, 0, 3, 0), - NpcEntry(1, 19, 11, 82, 1, 256, 0, 0, 8), - NpcEntry(0, 19, 10, 82, 1, 256, 0, 0, 8), - NpcEntry(15, 16, 24, 0, 10, 25600, 0, 0, 8), - NpcEntry(14, 15, 24, 600, 10, 0, 0, 0, 0), - NpcEntry(13, 36, 23, 246, 10, 0, 0, 0, 8), - NpcEntry(12, 33, 5, 10, 1, 256, 257, 0, 8), - NpcEntry(11, 4, 26, 59, 1, 256, 257, 0, 8), - NpcEntry(10, 30, 34, 13, 1, 512, 258, 0, 8), - NpcEntry(9, 4, 14, 36, 1, 5121, 0, 1, 9), - NpcEntry(8, 7, 32, 36, 1, 5632, 0, 0, 8), - ) - val baseEntityId = 0x000000000001E000L - for (npc in all16) { - val entityId = baseEntityId or npc.entityIdx.toLong() - log.info { - ">> Petalburg NpcSpawn[${npc.entityIdx}] entId=0x${entityId.toString(16)} pos=(${npc.x},${npc.y}) gfx=${npc.gfx}" - } - val spawnPacket = - NpcSpawnPacket( - entityId = entityId, - unk1 = npc.unk1, - unk2 = npc.gfx, - unk3 = npc.unk3, - unk4 = npc.unk4, - regionId = 1, - bankId = bankId, - mapId = mapId, - x = npc.x, - y = npc.y, - facing = npc.facing, - unk5 = 2, - unk6 = npc.unk6, - ) - ctx.send(spawnPacket) - } - return - } - for (npc in map.npcs) { // Decoration slots are not normal NPCs. if (npc.hideFlag.substringAfter('/').startsWith(DECORATION_FLAG_PREFIX)) continue @@ -107,25 +48,31 @@ constructor( val resolved = resolveDynamicGraphics( ctx, applyStoryPlacement(bankId, mapId, npc, storyFlags, storyVars)) - ctx.send(buildSpawnPacket(resolved, entityIdFor(bankId, mapId, npc.entityIdx), bankId, mapId)) + ctx.send( + buildSpawnPacket( + resolved, + entityIdFor(regionId, bankId, mapId, npc.entityIdx), + regionId, + bankId, + mapId, + )) } } /** Allocate (or return) the stable entity id for a map npc by its decomp local id. */ - fun entityIdFor(bankId: Int, mapId: Int, entityIdx: Int): Long = - npcEntityIds.getOrPut("$bankId:$mapId:$entityIdx") { npcEntityIdCounter.incrementAndGet() } + fun entityIdFor(regionId: Int, bankId: Int, mapId: Int, entityIdx: Int): Long = + npcEntityIds.getOrPut(key(regionId, bankId, mapId, entityIdx)) { + npcEntityIdCounter.incrementAndGet() + } /** Spawn a single npc (including a normally hidden one) for one player, for cutscenes. */ - fun spawnNpc(ctx: SessionContext, bankId: Int, mapId: Int, localId: Int) { - val npc = mapManager.getMap(1, bankId, mapId)?.npcs?.firstOrNull { it.entityIdx == localId } - if (npc == null) { - log.warn { "spawnNpc: npc $localId not found on $bankId:$mapId" } - return - } + fun spawnNpc(ctx: SessionContext, regionId: Int, bankId: Int, mapId: Int, localId: Int) { + val npc = findNpc(regionId, bankId, mapId, localId) ?: return ctx.send( buildSpawnPacket( resolveDynamicGraphics(ctx, npc), - entityIdFor(bankId, mapId, localId), + entityIdFor(regionId, bankId, mapId, localId), + regionId, bankId, mapId, )) @@ -134,21 +81,19 @@ constructor( /** Spawns an NPC at a cutscene position. */ fun spawnNpcAt( ctx: SessionContext, + regionId: Int, bankId: Int, mapId: Int, localId: Int, x: Int, y: Int, ) { - val npc = mapManager.getMap(1, bankId, mapId)?.npcs?.firstOrNull { it.entityIdx == localId } - if (npc == null) { - log.warn { "spawnNpcAt: npc $localId not found on $bankId:$mapId" } - return - } + val npc = findNpc(regionId, bankId, mapId, localId) ?: return ctx.send( buildSpawnPacket( resolveDynamicGraphics(ctx, npc.copy(x = x, y = y)), - entityIdFor(bankId, mapId, localId), + entityIdFor(regionId, bankId, mapId, localId), + regionId, bankId, mapId, )) @@ -157,21 +102,18 @@ constructor( /** Repositions an existing NPC. */ fun repositionNpc( ctx: SessionContext, + regionId: Int, bankId: Int, mapId: Int, localId: Int, x: Int, y: Int, ) { - val npc = mapManager.getMap(1, bankId, mapId)?.npcs?.firstOrNull { it.entityIdx == localId } - if (npc == null) { - log.warn { "repositionNpc: npc $localId not found on $bankId:$mapId" } - return - } + val npc = findNpc(regionId, bankId, mapId, localId) ?: return ctx.send( NpcUpdatePacket( - entityId = entityIdFor(bankId, mapId, localId), - regionId = 1, + entityId = entityIdFor(regionId, bankId, mapId, localId), + regionId = regionId, bankId = bankId, mapId = mapId, x = x, @@ -183,18 +125,30 @@ constructor( } /** Removes a cutscene NPC. */ - fun despawnNpc(ctx: SessionContext, bankId: Int, mapId: Int, localId: Int) { - val entityId = getNpcEntityId(bankId, mapId, localId) ?: return + fun despawnNpc(ctx: SessionContext, regionId: Int, bankId: Int, mapId: Int, localId: Int) { + val entityId = getNpcEntityId(regionId, bankId, mapId, localId) ?: return ctx.send(EntityLeavePacket(entityId)) } + private fun findNpc(regionId: Int, bankId: Int, mapId: Int, localId: Int): NpcDef? { + val npc = + mapManager.getMap(regionId, bankId, mapId)?.npcs?.firstOrNull { it.entityIdx == localId } + if (npc == null) log.warn { "npc $localId not found on $regionId:$bankId:$mapId" } + return npc + } + + private fun key(regionId: Int, bankId: Int, mapId: Int, entityIdx: Int) = + "$regionId:$bankId:$mapId:$entityIdx" + private fun buildSpawnPacket( npc: NpcDef, entityId: Long, + regionId: Int, bankId: Int, mapId: Int, ): NpcSpawnPacket { - val movementId = npc.movementType.forRegion(Region.HOENN).id + val region = requireNotNull(Region.byId(regionId)) { "Unknown region id $regionId" } + val movementId = npc.movementType.forRegion(region).id val unk3 = ((movementId and 0xFF) shl 8) or 0x02 val unk4 = if (movementId in 1..6 || (movementId in 25..52)) { @@ -204,11 +158,11 @@ constructor( } return NpcSpawnPacket( entityId = entityId, - unk1 = 1, - unk2 = npc.graphicsId, + spriteRegionId = regionId, + graphicsId = npc.graphicsId, unk3 = unk3, unk4 = unk4, - regionId = 1, + regionId = regionId, bankId = bankId, mapId = mapId, x = npc.x, @@ -268,7 +222,6 @@ constructor( private companion object { const val DECORATION_FLAG_PREFIX = "FLAG_DECORATION_" - const val USE_LEGACY_PETALBURG_SPAWNS = false const val DYNAMIC_GFX_VAR_0 = 240 const val RIVAL_BRENDAN_NORMAL = 100 const val RIVAL_MAY_NORMAL = 105 diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/ScriptMovementService.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/ScriptMovementService.kt index f0deb05..d949185 100644 --- a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/ScriptMovementService.kt +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/ScriptMovementService.kt @@ -45,7 +45,12 @@ constructor( mapManager.getMap(info.positionRegionId, info.positionBankId, info.positionMapId) ?: return val npc = map.npcs.firstOrNull { it.entityIdx == localId } ?: return val entityId = - npcService.entityIdFor(info.positionBankId.toInt(), info.positionMapId.toInt(), localId) + npcService.entityIdFor( + info.positionRegionId.toInt(), + info.positionBankId.toInt(), + info.positionMapId.toInt(), + localId, + ) drive(session, entityId, Pose(npc.x, npc.y, npc.facing), steps) } @@ -63,7 +68,11 @@ constructor( paths.mapNotNull { (localId, steps) -> if (map.npcs.none { it.entityIdx == localId }) return@mapNotNull null npcService.entityIdFor( - info.positionBankId.toInt(), info.positionMapId.toInt(), localId) to steps + info.positionRegionId.toInt(), + info.positionBankId.toInt(), + info.positionMapId.toInt(), + localId, + ) to steps } resolved.forEach { (entityId, steps) -> sendActions(session, entityId, steps) } delay(resolved.maxOfOrNull { (_, steps) -> durationMs(steps) } ?: 0) @@ -84,7 +93,11 @@ constructor( paths.mapNotNull { (localId, steps) -> if (map.npcs.none { it.entityIdx == localId }) return@mapNotNull null npcService.entityIdFor( - info.positionBankId.toInt(), info.positionMapId.toInt(), localId) to steps + info.positionRegionId.toInt(), + info.positionBankId.toInt(), + info.positionMapId.toInt(), + localId, + ) to steps } sendActions(session, info.id, selfSteps) resolved.forEach { (entityId, steps) -> sendActions(session, entityId, steps) } @@ -106,7 +119,13 @@ constructor( fun showNpc(session: SessionContext, state: PlayerState, localId: Int) { val charId = state.characterId ?: return val info = characterStore.getCharacter(charId)?.info ?: return - npcService.spawnNpc(session, info.positionBankId.toInt(), info.positionMapId.toInt(), localId) + npcService.spawnNpc( + session, + info.positionRegionId.toInt(), + info.positionBankId.toInt(), + info.positionMapId.toInt(), + localId, + ) } /** Show a normally hidden map npc at an overridden cutscene position. */ @@ -114,7 +133,14 @@ constructor( val charId = state.characterId ?: return val info = characterStore.getCharacter(charId)?.info ?: return npcService.spawnNpcAt( - session, info.positionBankId.toInt(), info.positionMapId.toInt(), localId, x, y) + session, + info.positionRegionId.toInt(), + info.positionBankId.toInt(), + info.positionMapId.toInt(), + localId, + x, + y, + ) } /** Relocate an npc that the normal map spawn already created. */ @@ -122,7 +148,14 @@ constructor( val charId = state.characterId ?: return val info = characterStore.getCharacter(charId)?.info ?: return npcService.repositionNpc( - session, info.positionBankId.toInt(), info.positionMapId.toInt(), localId, x, y) + session, + info.positionRegionId.toInt(), + info.positionBankId.toInt(), + info.positionMapId.toInt(), + localId, + x, + y, + ) } /** Repositions the player and synchronizes server state. */ @@ -156,14 +189,25 @@ constructor( fun removeNpc(session: SessionContext, state: PlayerState, localId: Int) { val charId = state.characterId ?: return val info = characterStore.getCharacter(charId)?.info ?: return - npcService.despawnNpc(session, info.positionBankId.toInt(), info.positionMapId.toInt(), localId) + npcService.despawnNpc( + session, + info.positionRegionId.toInt(), + info.positionBankId.toInt(), + info.positionMapId.toInt(), + localId, + ) } /** Resolves local NPC ids to entity ids. */ fun npcEntityId(state: PlayerState, localId: Int): Long? { val charId = state.characterId ?: return null val info = characterStore.getCharacter(charId)?.info ?: return null - return npcService.entityIdFor(info.positionBankId.toInt(), info.positionMapId.toInt(), localId) + return npcService.entityIdFor( + info.positionRegionId.toInt(), + info.positionBankId.toInt(), + info.positionMapId.toInt(), + localId, + ) } /** Returns the created player's gender. */ diff --git a/server.game/src/test/kotlin/de/fiereu/openmmo/server/game/script/MapTransitionScriptTest.kt b/server.game/src/test/kotlin/de/fiereu/openmmo/server/game/script/MapTransitionScriptTest.kt index a13a15a..835d662 100644 --- a/server.game/src/test/kotlin/de/fiereu/openmmo/server/game/script/MapTransitionScriptTest.kt +++ b/server.game/src/test/kotlin/de/fiereu/openmmo/server/game/script/MapTransitionScriptTest.kt @@ -94,7 +94,7 @@ class MapTransitionScriptTest : val npcs = NpcService(mapManager, store) val movement = ScriptMovementService(mapManager, npcs, store) val ctx = ScriptContext(session, state, entityId = -1, DialogService(), story, movement) - val momEntityId = npcs.entityIdFor(51, 3, 13) + val momEntityId = npcs.entityIdFor(1, 51, 3, 13) val cutscene = launch { setWallClock(ctx, female = true) } advanceUntilIdle() @@ -277,8 +277,8 @@ class MapTransitionScriptTest : val npcs = NpcService(mapManager, store) val movement = ScriptMovementService(mapManager, npcs, store) val ctx = ScriptContext(session, state, entityId = -1, DialogService(), story, movement) - val birchId = npcs.entityIdFor(50, 16, 1) - val zigzagoonId = npcs.entityIdFor(50, 16, 3) + val birchId = npcs.entityIdFor(1, 50, 16, 1) + val zigzagoonId = npcs.entityIdFor(1, 50, 16, 3) val cutscene = launch { Route101_EventScript_StartBirchRescue.run(ctx) } advanceUntilIdle() @@ -321,7 +321,7 @@ class MapTransitionScriptTest : ScriptContext( session, state, - entityId = npcs.entityIdFor(51, 1, 14), + entityId = npcs.entityIdFor(1, 51, 1, 14), dialog, story, movement, diff --git a/server.game/src/test/kotlin/de/fiereu/openmmo/server/game/services/NpcStoryFlagSyncTest.kt b/server.game/src/test/kotlin/de/fiereu/openmmo/server/game/services/NpcStoryFlagSyncTest.kt index 3374a91..c839cef 100644 --- a/server.game/src/test/kotlin/de/fiereu/openmmo/server/game/services/NpcStoryFlagSyncTest.kt +++ b/server.game/src/test/kotlin/de/fiereu/openmmo/server/game/services/NpcStoryFlagSyncTest.kt @@ -25,18 +25,18 @@ class NpcStoryFlagSyncTest : val session = FakeSession(characterId = character.info.id, bankId = 50, mapId = 9) val npcs = NpcService(MapManager(), store) - npcs.spawnNpcsForMap(session, bankId = 50, mapId = 9) + npcs.spawnNpcsForMap(session, bankId = 50, mapId = 9, regionId = 1) // Only Brendan's truck starts visible. - (npcs.getNpcEntityId(50, 9, 4) != null) shouldBe true - npcs.getNpcEntityId(50, 9, 5) shouldBe null - npcs.getNpcEntityId(50, 9, 3) shouldBe null + (npcs.getNpcEntityId(1, 50, 9, 4) != null) shouldBe true + npcs.getNpcEntityId(1, 50, 9, 5) shouldBe null + npcs.getNpcEntityId(1, 50, 9, 3) shouldBe null StoryService(store) .clearFlag(character.info.id, HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_MOM_OUTSIDE) - npcs.spawnNpcsForMap(session, bankId = 50, mapId = 9) + npcs.spawnNpcsForMap(session, bankId = 50, mapId = 9, regionId = 1) - (npcs.getNpcEntityId(50, 9, 3) != null) shouldBe true + (npcs.getNpcEntityId(1, 50, 9, 3) != null) shouldBe true } } @@ -47,10 +47,10 @@ class NpcStoryFlagSyncTest : val session = FakeSession(characterId = character.info.id, bankId = 51, mapId = 3) val npcs = NpcService(MapManager(), store) - npcs.spawnNpcsForMap(session, bankId = 51, mapId = 3) + npcs.spawnNpcsForMap(session, bankId = 51, mapId = 3, regionId = 1) // Decoration slots are not normal NPCs. - (1..12).forEach { localId -> npcs.getNpcEntityId(51, 3, localId) shouldBe null } + (1..12).forEach { localId -> npcs.getNpcEntityId(1, 51, 3, localId) shouldBe null } } } @@ -63,9 +63,9 @@ class NpcStoryFlagSyncTest : story.setVar(character.info.id, HoennVars.VAR_LITTLEROOT_TOWN_STATE, 1) val npcs = NpcService(MapManager(), store) - npcs.spawnNpcsForMap(session, bankId = 50, mapId = 9) + npcs.spawnNpcsForMap(session, bankId = 50, mapId = 9, regionId = 1) - val twinId = npcs.getNpcEntityId(50, 9, 0) + val twinId = npcs.getNpcEntityId(1, 50, 9, 0) val twin = session.sent.filterIsInstance().single { it.entityId == twinId } twin.x shouldBe 10 @@ -83,12 +83,12 @@ class NpcStoryFlagSyncTest : StoryService(femaleStore).clearFlag(female.info.id, HoennFlags.FLAG_HIDE_ROUTE_103_RIVAL) val femaleSession = FakeSession(characterId = female.info.id, bankId = 50, mapId = 18) val femaleNpcs = NpcService(mapManager, femaleStore) - femaleNpcs.spawnNpcsForMap(femaleSession, bankId = 50, mapId = 18) - val brendanId = femaleNpcs.getNpcEntityId(50, 18, 1) + femaleNpcs.spawnNpcsForMap(femaleSession, bankId = 50, mapId = 18, regionId = 1) + val brendanId = femaleNpcs.getNpcEntityId(1, 50, 18, 1) femaleSession.sent .filterIsInstance() .single { it.entityId == brendanId } - .unk2 shouldBe 100 + .graphicsId shouldBe 100 val maleStore = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope) @@ -96,12 +96,12 @@ class NpcStoryFlagSyncTest : StoryService(maleStore).clearFlag(male.info.id, HoennFlags.FLAG_HIDE_ROUTE_103_RIVAL) val maleSession = FakeSession(characterId = male.info.id, bankId = 50, mapId = 18) val maleNpcs = NpcService(mapManager, maleStore) - maleNpcs.spawnNpcsForMap(maleSession, bankId = 50, mapId = 18) - val mayId = maleNpcs.getNpcEntityId(50, 18, 1) + maleNpcs.spawnNpcsForMap(maleSession, bankId = 50, mapId = 18, regionId = 1) + val mayId = maleNpcs.getNpcEntityId(1, 50, 18, 1) maleSession.sent .filterIsInstance() .single { it.entityId == mayId } - .unk2 shouldBe 105 + .graphicsId shouldBe 105 } } @@ -113,9 +113,9 @@ class NpcStoryFlagSyncTest : val session = FakeSession(characterId = character.info.id, bankId = 50, mapId = 16) val npcs = NpcService(MapManager(), store) - npcs.spawnNpcsForMap(session, bankId = 50, mapId = 16) + npcs.spawnNpcsForMap(session, bankId = 50, mapId = 16, regionId = 1) - npcs.getNpcEntityId(50, 16, 3) shouldBe null + npcs.getNpcEntityId(1, 50, 16, 3) shouldBe null } } })