feat(codegen): generate Pokemon moves and unify map/move codegen into one module (#16)

This commit is contained in:
Fiereu authored and GitHub committed 2026-07-20 14:25:57 +02:00
1 parent 75fe4ae0d2
commit b44bd1cc26
36 files changed
+635 -71

No files matched your search

@@ -0,0 +1,8 @@
package de.fiereu.openmmo.maps
data class BgEventDef(
val x: Int,
val y: Int,
val facingDir: String,
val script: String,
)
@@ -0,0 +1,49 @@
package de.fiereu.openmmo.maps
import de.fiereu.openmmo.common.Tile2D
import de.fiereu.openmmo.common.enums.EncounterType
import de.fiereu.openmmo.common.enums.Lighting
import de.fiereu.openmmo.common.enums.MapType
import de.fiereu.openmmo.common.enums.Weather
import de.fiereu.openmmo.net.game.packets.MapData
import java.util.Base64
class MapDef(
val regionId: Byte,
val bankId: Byte,
val mapId: Byte,
val width: Int = 20,
val height: Int = 15,
val paletteIdx1: Int = 12,
val paletteIdx2: Int = 14,
val borderWidth: Int = 2,
val borderHeight: Int = 2,
val unknownShort: Int = 0,
val unknownByte: Int = 0,
val borderTiles: List<Tile2D> = listOf(Tile2D(8, 0), Tile2D(8, 0), Tile2D(8, 0), Tile2D(8, 0)),
val lighting: Lighting = Lighting.REGULAR,
val weather: Weather = Weather.REGULAR_WEATHER,
val mapType: MapType = MapType.CITY,
val encounterType: EncounterType = EncounterType.RANDOM,
val wildEncounters: List<WildEncounterTable> = emptyList(),
val connections: List<MapData.GbaConnection> = emptyList(),
val warps: List<WarpTile> = emptyList(),
val npcs: List<NpcDef> = emptyList(),
val bgEvents: List<BgEventDef> = emptyList(),
private val blockData: String = "",
) {
val tiles: List<Tile2D> by lazy { decodeBlockData(blockData) }
fun tileAt(x: Int, y: Int): Tile2D? =
if (x in 0 until width && y in 0 until height) tiles.getOrNull(y * width + x) else null
}
private fun decodeBlockData(blockData: String): List<Tile2D> {
if (blockData.isEmpty()) return emptyList()
val bytes = Base64.getDecoder().decode(blockData)
return List(bytes.size / 2) { i ->
val raw = (bytes[i * 2].toInt() and 0xFF) or ((bytes[i * 2 + 1].toInt() and 0xFF) shl 8)
Tile2D(material = (raw and 0x3FF).toShort(), collision = ((raw shr 10) and 0x3F).toByte())
}
}
@@ -0,0 +1,65 @@
package de.fiereu.openmmo.maps
import de.fiereu.openmmo.maps.generated.GeneratedMaps
import de.fiereu.openmmo.net.game.packets.LoadMapPacket
import de.fiereu.openmmo.net.game.packets.MapData
import java.util.concurrent.ConcurrentHashMap
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class MapManager @Inject constructor() {
private val maps = ConcurrentHashMap<Long, MapDef>()
init {
GeneratedMaps.loadInto(this)
}
fun register(map: MapDef) {
maps[key(map.regionId, map.bankId, map.mapId)] = map
}
fun getMap(regionId: Byte, bankId: Byte, mapId: Byte): MapDef? =
maps[key(regionId, bankId, mapId)]
fun getMap(regionId: Int, bankId: Int, mapId: Int): MapDef? =
getMap(regionId.toByte(), bankId.toByte(), mapId.toByte())
fun size(): Int = maps.size
fun createLoadMapPacket(
map: MapDef,
reloadPlayer: Boolean = false,
deleteCache: Boolean = false,
): LoadMapPacket =
LoadMapPacket(
reloadPlayer = reloadPlayer,
deleteCache = deleteCache,
regionId = map.regionId.toInt() and 0xFF,
bankId = map.bankId.toInt() and 0xFF,
mapId = map.mapId.toInt() and 0xFF,
mapData =
MapData.GbaMapData(
width = map.width,
height = map.height,
paletteIdx1 = map.paletteIdx1,
paletteIdx2 = map.paletteIdx2,
borderWidth = map.borderWidth,
borderHeight = map.borderHeight,
unknownShort = map.unknownShort,
unknownByte = map.unknownByte,
borderTiles = map.borderTiles,
lighting = map.lighting,
weather = map.weather,
mapType = map.mapType,
encounterType = map.encounterType,
connections = map.connections,
),
)
private fun key(regionId: Byte, bankId: Byte, mapId: Byte): Long =
((regionId.toLong() and 0xFF) shl 16) or
((bankId.toLong() and 0xFF) shl 8) or
(mapId.toLong() and 0xFF)
}
@@ -0,0 +1,18 @@
package de.fiereu.openmmo.maps
import de.fiereu.openmmo.common.enums.Direction
import de.fiereu.openmmo.common.enums.MovementType
data class NpcDef(
val entityIdx: Int,
val graphicsId: Int,
val x: Int,
val y: Int,
val elevation: Int,
val movementType: MovementType,
val movementRangeX: Int,
val movementRangeY: Int,
val trainerType: Int,
val facing: Direction,
val script: String = "0x0",
)
@@ -0,0 +1,16 @@
package de.fiereu.openmmo.maps
import de.fiereu.openmmo.common.enums.Direction
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: Direction? = null,
)
@@ -0,0 +1,5 @@
package de.fiereu.openmmo.maps
data class WildEncounterTable(val encounterRate: Int, val pokemon: List<WildPokemon>)
data class WildPokemon(val dexId: Int, val minLevel: Int, val maxLevel: Int, val weight: Int)
@@ -0,0 +1,22 @@
package de.fiereu.openmmo.moves
import de.fiereu.openmmo.common.enums.MoveEffect
import de.fiereu.openmmo.common.enums.MoveFlag
import de.fiereu.openmmo.common.enums.MoveTarget
import de.fiereu.openmmo.common.enums.PokemonType
data class MoveDef(
val id: Int,
val name: String,
val effect: MoveEffect,
val power: Int,
val type: PokemonType,
val accuracy: Int,
val pp: Int,
val secondaryEffectChance: Int,
val target: MoveTarget,
val priority: Int,
val flags: Set<MoveFlag> = emptySet(),
) {
fun hasFlag(flag: MoveFlag): Boolean = flag in flags
}
@@ -0,0 +1,26 @@
package de.fiereu.openmmo.moves
import de.fiereu.openmmo.moves.generated.GeneratedMoves
import java.util.concurrent.ConcurrentHashMap
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class MoveRegistry @Inject constructor() {
private val moves = ConcurrentHashMap<Int, MoveDef>()
init {
GeneratedMoves.loadInto(this)
}
fun register(move: MoveDef) {
moves[move.id] = move
}
fun get(id: Int): MoveDef? = moves[id]
fun all(): Collection<MoveDef> = moves.values
fun size(): Int = moves.size
}