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