fix(game): stop the player from stopping when walking to another map (#98)
* fix(game): stop moving the player when they cross a map connection * fix(game): only send map data the client does not already have
This commit is contained in:
1 parent
14fbc05bab
commit
d4940f85cf
6 files changed
+27
-16
No files matched your search
@@ -294,6 +294,7 @@ constructor(
|
|||||||
"Placing '${info.name}' at ${info.positionRegionId}:${info.positionBankId}:" +
|
"Placing '${info.name}' at ${info.positionRegionId}:${info.positionBankId}:" +
|
||||||
"${info.positionMapId} (${info.positionX}, ${info.positionY})"
|
"${info.positionMapId} (${info.positionX}, ${info.positionY})"
|
||||||
}
|
}
|
||||||
|
mapLoadService.resetClientCache(ctx, map)
|
||||||
ctx.send(mapManager.createLoadMapPacket(map, reloadPlayer = true, deleteCache = true))
|
ctx.send(mapManager.createLoadMapPacket(map, reloadPlayer = true, deleteCache = true))
|
||||||
mapLoadService.preloadConnectedMaps(ctx, map)
|
mapLoadService.preloadConnectedMaps(ctx, map)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+17
-4
@@ -10,6 +10,8 @@ import de.fiereu.openmmo.maps.MapManager
|
|||||||
import de.fiereu.openmmo.net.game.codecs.SkinSet
|
import de.fiereu.openmmo.net.game.codecs.SkinSet
|
||||||
import de.fiereu.openmmo.net.game.packets.LoadEntityPacket
|
import de.fiereu.openmmo.net.game.packets.LoadEntityPacket
|
||||||
import de.fiereu.openmmo.net.game.packets.MapData
|
import de.fiereu.openmmo.net.game.packets.MapData
|
||||||
|
import de.fiereu.openmmo.server.game.session.PLAYER_STATE
|
||||||
|
import de.fiereu.openmmo.server.game.session.mapCacheKey
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@@ -43,21 +45,32 @@ constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forget what the client has cached. Call this alongside a LoadMap that carries deleteCache,
|
||||||
|
* since the client throws its own cache away when it sees that flag.
|
||||||
|
*/
|
||||||
|
fun resetClientCache(ctx: SessionContext, map: MapDef) {
|
||||||
|
val state = ctx.attributes[PLAYER_STATE] ?: return
|
||||||
|
state.loadedMaps.clear()
|
||||||
|
state.loadedMaps.add(mapCacheKey(map.regionId.toInt(), map.bankId.toInt(), map.mapId.toInt()))
|
||||||
|
}
|
||||||
|
|
||||||
fun preloadConnectedMaps(
|
fun preloadConnectedMaps(
|
||||||
ctx: SessionContext,
|
ctx: SessionContext,
|
||||||
map: MapDef,
|
map: MapDef,
|
||||||
depth: Int = 2,
|
depth: Int = 2,
|
||||||
reloadPlayer: Boolean = false,
|
reloadPlayer: Boolean = false,
|
||||||
) {
|
) {
|
||||||
val loaded = mutableSetOf<String>()
|
val loaded = ctx.attributes[PLAYER_STATE]?.loadedMaps ?: mutableSetOf()
|
||||||
loaded.add("${map.bankId}:${map.mapId}")
|
val regionId = map.regionId.toInt()
|
||||||
|
loaded.add(mapCacheKey(regionId, map.bankId.toInt(), map.mapId.toInt()))
|
||||||
fun preload(connections: List<MapData.GbaConnection>, remaining: Int) {
|
fun preload(connections: List<MapData.GbaConnection>, remaining: Int) {
|
||||||
if (remaining <= 0) return
|
if (remaining <= 0) return
|
||||||
for (conn in connections) {
|
for (conn in connections) {
|
||||||
val key = "${conn.targetBank}:${conn.targetMap}"
|
val key = mapCacheKey(regionId, conn.targetBank, conn.targetMap)
|
||||||
if (!loaded.add(key)) continue
|
if (!loaded.add(key)) continue
|
||||||
// Connections stay inside one region.
|
// Connections stay inside one region.
|
||||||
val connected = mapManager.getMap(map.regionId.toInt(), conn.targetBank, conn.targetMap)
|
val connected = mapManager.getMap(regionId, conn.targetBank, conn.targetMap)
|
||||||
if (connected != null) {
|
if (connected != null) {
|
||||||
ctx.send(
|
ctx.send(
|
||||||
mapManager.createLoadMapPacket(
|
mapManager.createLoadMapPacket(
|
||||||
|
|||||||
+1
-12
@@ -149,15 +149,7 @@ constructor(
|
|||||||
Direction.DOWN -> 0
|
Direction.DOWN -> 0
|
||||||
else -> (fromY - connection.unknown).coerceIn(0, targetMap.height - 1)
|
else -> (fromY - connection.unknown).coerceIn(0, targetMap.height - 1)
|
||||||
}
|
}
|
||||||
edgeTransition(
|
edgeTransition(ctx, charId, currentMap.regionId, connection, entryX.toByte(), entryY.toByte())
|
||||||
ctx,
|
|
||||||
charId,
|
|
||||||
currentMap.regionId,
|
|
||||||
connection,
|
|
||||||
entryX.toByte(),
|
|
||||||
entryY.toByte(),
|
|
||||||
msg.direction,
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,7 +270,6 @@ constructor(
|
|||||||
connection: MapData.GbaConnection,
|
connection: MapData.GbaConnection,
|
||||||
targetX: Byte,
|
targetX: Byte,
|
||||||
targetY: Byte,
|
targetY: Byte,
|
||||||
direction: Direction,
|
|
||||||
) {
|
) {
|
||||||
val targetBank = connection.targetBank.toByte()
|
val targetBank = connection.targetBank.toByte()
|
||||||
val targetMap = connection.targetMap.toByte()
|
val targetMap = connection.targetMap.toByte()
|
||||||
@@ -304,8 +295,6 @@ constructor(
|
|||||||
mapLoadService.preloadConnectedMaps(ctx, map, depth = 1)
|
mapLoadService.preloadConnectedMaps(ctx, map, depth = 1)
|
||||||
npcService.spawnNpcsForMap(ctx, targetBank.toInt(), targetMap.toInt(), regionId.toInt())
|
npcService.spawnNpcsForMap(ctx, targetBank.toInt(), targetMap.toInt(), regionId.toInt())
|
||||||
|
|
||||||
ctx.send(gbaMovePacket(charId, map, targetX.toInt(), targetY.toInt(), direction))
|
|
||||||
|
|
||||||
if (state != null) mapScriptService.onMapEnter(ctx, state, map)
|
if (state != null) mapScriptService.onMapEnter(ctx, state, map)
|
||||||
|
|
||||||
log.info { "Player $charId edge-transitioned to bank=$targetBank map=$targetMap" }
|
log.info { "Player $charId edge-transitioned to bank=$targetBank map=$targetMap" }
|
||||||
|
|||||||
+1
@@ -53,6 +53,7 @@ constructor(
|
|||||||
session.send(MapTransitionPacket())
|
session.send(MapTransitionPacket())
|
||||||
session.send(RenderScreenPacket(false))
|
session.send(RenderScreenPacket(false))
|
||||||
session.send(MapTransitionAckPacket(2))
|
session.send(MapTransitionAckPacket(2))
|
||||||
|
mapLoadService.resetClientCache(session, map)
|
||||||
session.send(mapManager.createLoadMapPacket(map, reloadPlayer = true, deleteCache = true))
|
session.send(mapManager.createLoadMapPacket(map, reloadPlayer = true, deleteCache = true))
|
||||||
mapLoadService.preloadConnectedMaps(session, map, depth = 1, reloadPlayer = true)
|
mapLoadService.preloadConnectedMaps(session, map, depth = 1, reloadPlayer = true)
|
||||||
session.send(mapLoadService.createLoadEntity(info, destination.facing))
|
session.send(mapLoadService.createLoadEntity(info, destination.facing))
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ constructor(
|
|||||||
ctx.send(MapTransitionAckPacket(2))
|
ctx.send(MapTransitionAckPacket(2))
|
||||||
|
|
||||||
if (destMap != null) {
|
if (destMap != null) {
|
||||||
|
mapLoadService.resetClientCache(ctx, destMap)
|
||||||
ctx.send(mapManager.createLoadMapPacket(destMap, reloadPlayer = true, deleteCache = true))
|
ctx.send(mapManager.createLoadMapPacket(destMap, reloadPlayer = true, deleteCache = true))
|
||||||
mapLoadService.preloadConnectedMaps(ctx, destMap, depth = 1, reloadPlayer = true)
|
mapLoadService.preloadConnectedMaps(ctx, destMap, depth = 1, reloadPlayer = true)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -17,4 +17,10 @@ data class PlayerState(
|
|||||||
var y: Short = 2,
|
var y: Short = 2,
|
||||||
/** Trusts one source tile after scripted movement. */
|
/** Trusts one source tile after scripted movement. */
|
||||||
var acceptNextMoveSource: Boolean = false,
|
var acceptNextMoveSource: Boolean = false,
|
||||||
|
/** Maps the client already holds. A warp sends deleteCache, which empties this. */
|
||||||
|
val loadedMaps: MutableSet<Int> = mutableSetOf(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/** Packs a map address into one key for [PlayerState.loadedMaps]. */
|
||||||
|
fun mapCacheKey(regionId: Int, bankId: Int, mapId: Int): Int =
|
||||||
|
(regionId shl 16) or (bankId shl 8) or mapId
|
||||||
Reference in new issue
Block a user