feat(game): start a wild battle when a player steps in grass (#68)
* feat(game): start a wild battle when a player steps in grass * fix(codegen): key species by national dex so the client shows the right mon
This commit is contained in:
1 parent
300bc52531
commit
109cf5f814
18 files changed
+488
-9
No files matched your search
@@ -1,9 +1,11 @@
|
||||
package de.fiereu.openmmo.maps
|
||||
|
||||
import de.fiereu.openmmo.common.Tile2D
|
||||
import de.fiereu.openmmo.common.enums.EncounterMethod
|
||||
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.TileBehavior
|
||||
import de.fiereu.openmmo.common.enums.Weather
|
||||
import de.fiereu.openmmo.net.game.packets.MapData
|
||||
import java.util.Base64
|
||||
@@ -31,19 +33,34 @@ class MapDef(
|
||||
val npcs: List<NpcDef> = emptyList(),
|
||||
val bgEvents: List<BgEventDef> = emptyList(),
|
||||
private val blockData: String = "",
|
||||
private val behaviorData: String = "",
|
||||
) {
|
||||
|
||||
val tiles: List<Tile2D> by lazy { decodeBlockData(blockData) }
|
||||
val tiles: List<Tile2D> by lazy { decodeBlockData(blockData, behaviorData) }
|
||||
|
||||
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
|
||||
|
||||
/** The wild table for [method] on this map, or null when the map has no such encounters. */
|
||||
fun encounterTable(method: EncounterMethod): WildEncounterTable? =
|
||||
wildEncounters.firstOrNull { it.method == method }
|
||||
}
|
||||
|
||||
private fun decodeBlockData(blockData: String): List<Tile2D> {
|
||||
private fun decodeBlockData(blockData: String, behaviorData: String): List<Tile2D> {
|
||||
if (blockData.isEmpty()) return emptyList()
|
||||
val bytes = Base64.getDecoder().decode(blockData)
|
||||
// One behavior byte per tile, generated alongside the block data. Empty on maps we could not
|
||||
// resolve behaviors for, in which case every tile stays NORMAL.
|
||||
val behaviors =
|
||||
if (behaviorData.isEmpty()) ByteArray(0) else Base64.getDecoder().decode(behaviorData)
|
||||
val behaviorValues = TileBehavior.entries
|
||||
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())
|
||||
val behavior = behaviors.getOrNull(i)?.toInt()?.let { behaviorValues.getOrNull(it) }
|
||||
Tile2D(
|
||||
material = (raw and 0x3FF).toShort(),
|
||||
collision = ((raw shr 10) and 0x3F).toByte(),
|
||||
behavior = behavior ?: TileBehavior.NORMAL,
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user