feat(game): add Z coordinate to warps

This commit is contained in:
LananaHWP authored and Fiereu committed 2026-05-26 16:15:48 +02:00
1 parent 4e367fb5bb
commit 374aae68f6
7 files changed
+3842 -1284

No files matched your search

+12 -4
View File
@@ -4,6 +4,9 @@ const path = require('path');
const POKEEMERALD = 'D:/openmmo/pokeemerald'; const POKEEMERALD = 'D:/openmmo/pokeemerald';
const OUTPUT = 'D:/openmmo/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/world/MapManager.kt'; const OUTPUT = 'D:/openmmo/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/world/MapManager.kt';
// Bank group index offset: maps in group 0 are bank (50+0)=50, group 1 = 51, etc.
const BANK_GROUP_OFFSET = 50;
// ---- Load data ---- // ---- Load data ----
const mapGroups = JSON.parse(fs.readFileSync(`${POKEEMERALD}/data/maps/map_groups.json`, 'utf-8')); const mapGroups = JSON.parse(fs.readFileSync(`${POKEEMERALD}/data/maps/map_groups.json`, 'utf-8'));
const layoutsJson = JSON.parse(fs.readFileSync(`${POKEEMERALD}/data/layouts/layouts.json`, 'utf-8')); const layoutsJson = JSON.parse(fs.readFileSync(`${POKEEMERALD}/data/layouts/layouts.json`, 'utf-8'));
@@ -317,7 +320,7 @@ for (let gi = 0; gi < groupOrder.length; gi++) {
} }
const addr = resolveMap(c.map); const addr = resolveMap(c.map);
if (!addr) return null; if (!addr) return null;
const bank = addr.groupIndex + 50; const bank = addr.groupIndex + BANK_GROUP_OFFSET;
const mapNum = addr.mapIndex; const mapNum = addr.mapIndex;
const offset = Number.isInteger(c.offset) ? c.offset : parseInt(c.offset || 0, 10) || 0; const offset = Number.isInteger(c.offset) ? c.offset : parseInt(c.offset || 0, 10) || 0;
return `GbaConnection(direction = ${dir}, unknown = ${offset}, targetBank = ${bank}, targetMap = ${mapNum})`; return `GbaConnection(direction = ${dir}, unknown = ${offset}, targetBank = ${bank}, targetMap = ${mapNum})`;
@@ -328,11 +331,12 @@ for (let gi = 0; gi < groupOrder.length; gi++) {
const warpStrs = warps.map(w => { const warpStrs = warps.map(w => {
const destAddr = resolveMap(w.dest_map); const destAddr = resolveMap(w.dest_map);
if (!destAddr) return null; if (!destAddr) return null;
const destBank = destAddr.groupIndex + 50; const destBank = destAddr.groupIndex + BANK_GROUP_OFFSET;
const destMapNum = destAddr.mapIndex; const destMapNum = destAddr.mapIndex;
// Find dest warp position in destination map // Find dest warp position in destination map
const destMapDir = `${POKEEMERALD}/data/maps/${destAddr.mapName}`; const destMapDir = `${POKEEMERALD}/data/maps/${destAddr.mapName}`;
let destX = w.x, destY = w.y; // fallback let destX = w.x, destY = w.y; // fallback
let targetElevation = 0;
try { try {
const destMapJson = JSON.parse(fs.readFileSync(`${destMapDir}/map.json`, 'utf-8')); const destMapJson = JSON.parse(fs.readFileSync(`${destMapDir}/map.json`, 'utf-8'));
const destWarps = destMapJson.warp_events || []; const destWarps = destMapJson.warp_events || [];
@@ -341,11 +345,13 @@ for (let gi = 0; gi < groupOrder.length; gi++) {
const targetWarp = destWarps[targetWarpIdx]; const targetWarp = destWarps[targetWarpIdx];
destX = targetWarp.x; destX = targetWarp.x;
destY = targetWarp.y; destY = targetWarp.y;
targetElevation = targetWarp.elevation !== undefined ? Math.max(0, targetWarp.elevation - 1) : 0;
} }
} catch (e) { } catch (e) {
// use fallback // use fallback
} }
return `WarpTile(x = ${w.x}, y = ${w.y}, targetRegionId = 1, targetBankId = ${destBank}, targetMapId = ${destMapNum}, targetX = ${destX}, targetY = ${destY})`; const elevation = w.elevation !== undefined ? Math.max(0, w.elevation - 1) : 0;
return `WarpTile(x = ${w.x}, y = ${w.y}, elevation = ${elevation}, targetRegionId = 1, targetBankId = ${destBank}, targetMapId = ${destMapNum}, targetX = ${destX}, targetY = ${destY}, targetElevation = ${targetElevation})`;
}).filter(Boolean); }).filter(Boolean);
// NPCs / object events // NPCs / object events
@@ -399,7 +405,7 @@ for (let gi = 0; gi < groupOrder.length; gi++) {
// Region: always 1 for now // Region: always 1 for now
const region = 1; const region = 1;
const bank = gi + 50; const bank = gi + BANK_GROUP_OFFSET;
// Generate MapDef // Generate MapDef
const comment = `// ${mapName} (${mapJson.id})`; const comment = `// ${mapName} (${mapJson.id})`;
@@ -475,11 +481,13 @@ data class WildPokemon(
data class WarpTile( data class WarpTile(
val x: Int, val x: Int,
val y: Int, val y: Int,
val elevation: Int = 0,
val targetRegionId: Byte, val targetRegionId: Byte,
val targetBankId: Byte, val targetBankId: Byte,
val targetMapId: Byte, val targetMapId: Byte,
val targetX: Int, val targetX: Int,
val targetY: Int, val targetY: Int,
val targetElevation: Int = 0,
val facingDirection: de.fiereu.openmmo.common.enums.Direction? = null, val facingDirection: de.fiereu.openmmo.common.enums.Direction? = null,
) )
@@ -22,7 +22,10 @@ data class LoadEntityPacket(
val mapId: Int, val mapId: Int,
val x: Int, val x: Int,
val y: Int, val y: Int,
val z: Int,
val facing: Direction, val facing: Direction,
val transportation: Int = 0,
val entityNameplateType: Int = 0,
val status: EntityStatus, val status: EntityStatus,
val hasFollower: Boolean, val hasFollower: Boolean,
val followerDexId: Short, val followerDexId: Short,
@@ -40,11 +43,10 @@ class LoadEntitySerializer : PacketSerializer<LoadEntityPacket> {
writeByte(packet.mapId) writeByte(packet.mapId)
writeShortLE(packet.x) writeShortLE(packet.x)
writeShortLE(packet.y) writeShortLE(packet.y)
writeByte(packet.z)
writeByte(packet.facing.ordinal) writeByte(packet.facing.ordinal)
writeByte(0) writeByte(packet.transportation)
writeByte(packet.entityNameplateType)
writeByte(0)
writeByte(packet.status.ordinal)
var flags = 0 var flags = 0
if (packet.hasFollower) flags = flags or 0x04 if (packet.hasFollower) flags = flags or 0x04
@@ -85,11 +87,10 @@ class LoadEntityDeserializer : PacketDeserializer<LoadEntityPacket> {
val mapId = readByte().toInt() val mapId = readByte().toInt()
val x = readShortLE() val x = readShortLE()
val y = readShortLE() val y = readShortLE()
val z = readByte().toInt()
val facing = Direction.entries[readByte().toInt()] val facing = Direction.entries[readByte().toInt()]
readByte() // Skip padding byte val transportation = readByte().toInt()
val entityNameplateType = readByte().toInt()
readByte() // Skip padding byte
val status = EntityStatus.entries[readByte().toInt()]
val flags = readUnsignedShortLE() val flags = readUnsignedShortLE()
if (flags and 0x01 != 0) { if (flags and 0x01 != 0) {
@@ -127,8 +128,11 @@ class LoadEntityDeserializer : PacketDeserializer<LoadEntityPacket> {
mapId = mapId, mapId = mapId,
x = x.toInt(), x = x.toInt(),
y = y.toInt(), y = y.toInt(),
z = z,
facing = facing, facing = facing,
status = status, transportation = transportation,
entityNameplateType = entityNameplateType,
status = EntityStatus.NONE,
hasFollower = hasFollower, hasFollower = hasFollower,
followerDexId = followerDexId, followerDexId = followerDexId,
) )
@@ -340,6 +340,7 @@ class LoginService(
mapId = other.mapId, mapId = other.mapId,
x = other.x.toInt(), x = other.x.toInt(),
y = other.y.toInt(), y = other.y.toInt(),
z = 0,
facing = other.facingDirection, facing = other.facingDirection,
status = de.fiereu.openmmo.common.enums.EntityStatus.NONE, status = de.fiereu.openmmo.common.enums.EntityStatus.NONE,
hasFollower = otherParty.isNotEmpty(), hasFollower = otherParty.isNotEmpty(),
@@ -358,6 +359,7 @@ class LoginService(
mapId = mapId, mapId = mapId,
x = info.positionX.toInt(), x = info.positionX.toInt(),
y = info.positionY.toInt(), y = info.positionY.toInt(),
z = 0,
facing = facing, facing = facing,
status = de.fiereu.openmmo.common.enums.EntityStatus.NONE, status = de.fiereu.openmmo.common.enums.EntityStatus.NONE,
hasFollower = hasFollower, hasFollower = hasFollower,
@@ -18,6 +18,7 @@ class MapLoadService(private val packetSender: PacketSender) {
fun createLoadEntity( fun createLoadEntity(
info: CharacterInfo, info: CharacterInfo,
facing: Direction = Direction.DOWN, facing: Direction = Direction.DOWN,
z: Int = 0,
): LoadEntityPacket { ): LoadEntityPacket {
return LoadEntityPacket( return LoadEntityPacket(
entityId = info.id, entityId = info.id,
@@ -28,6 +29,7 @@ class MapLoadService(private val packetSender: PacketSender) {
mapId = info.positionMapId.toInt(), mapId = info.positionMapId.toInt(),
x = info.positionX.toInt(), x = info.positionX.toInt(),
y = info.positionY.toInt(), y = info.positionY.toInt(),
z = z,
facing = facing, facing = facing,
status = de.fiereu.openmmo.common.enums.EntityStatus.NONE, status = de.fiereu.openmmo.common.enums.EntityStatus.NONE,
hasFollower = false, hasFollower = false,
@@ -69,11 +69,15 @@ class WarpService(
} }
} }
val playerZ =
destMap?.warps?.find { it.x == warp.targetX && it.y == warp.targetY }?.elevation
?: warp.targetElevation
log.info { log.info {
"WARP EXIT: source=${sourceMap?.bankId}:${sourceMap?.mapId} ${sourceMap?.mapType} " + "WARP EXIT: source=${sourceMap?.bankId}:${sourceMap?.mapId} ${sourceMap?.mapType} " +
"dest=${destMap?.bankId}:${destMap?.mapId} ${destMap?.mapType} " + "dest=${destMap?.bankId}:${destMap?.mapId} ${destMap?.mapType} " +
"target=(${warp.targetX},${warp.targetY}) final=($offsetX,$offsetY) " + "target=(${warp.targetX},${warp.targetY}) final=($offsetX,$offsetY) " +
"facing=$warpFacing autoStep=$shouldAutoStepOffWarp" "z=$playerZ facing=$warpFacing autoStep=$shouldAutoStepOffWarp"
} }
val newInfo = val newInfo =
@@ -110,7 +114,7 @@ class WarpService(
// Real server warp sequence (from packets.db): // Real server warp sequence (from packets.db):
ctx.channel().writeAndFlush(MapTransitionPacket()) ctx.channel().writeAndFlush(MapTransitionPacket())
ctx.channel().writeAndFlush(RenderScreenPacket(false)) ctx.channel().writeAndFlush(RenderScreenPacket(false))
ctx.channel().writeAndFlush(mapLoadService.createLoadEntity(newInfo, warpFacing)) ctx.channel().writeAndFlush(mapLoadService.createLoadEntity(newInfo, warpFacing, playerZ))
ctx.channel().writeAndFlush(MapTransitionAckPacket(0)) ctx.channel().writeAndFlush(MapTransitionAckPacket(0))
if (destMap != null) { if (destMap != null) {
@@ -60,7 +60,7 @@ object CharacterStore {
positionBankId = 51, positionBankId = 51,
positionMapId = 3, positionMapId = 3,
positionX = 4, positionX = 4,
positionY = 2, positionY = 4,
repelLeft = 0, repelLeft = 0,
repelItemId = 0, repelItemId = 0,
lureLeft = 0, lureLeft = 0,
File diff suppressed because it is too large. Load diff