refactor: maps git submodules (#9)
This commit is contained in:
1 parent
902b537532
commit
abbfe97c6d
34 files changed
+1028
-564
No files matched your search
+32
-10
@@ -3,6 +3,7 @@ package de.fiereu.openmmo.server.game.services
|
||||
import de.fiereu.network.PacketEvent
|
||||
import de.fiereu.network.SessionContext
|
||||
import de.fiereu.openmmo.common.enums.Direction
|
||||
import de.fiereu.openmmo.maps.MapDef
|
||||
import de.fiereu.openmmo.maps.MapManager
|
||||
import de.fiereu.openmmo.net.game.packets.EntityMovePacket
|
||||
import de.fiereu.openmmo.net.game.packets.FaceDirectionPacket
|
||||
@@ -14,6 +15,7 @@ import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
import kotlin.math.abs
|
||||
|
||||
private val log = KotlinLogging.logger {}
|
||||
|
||||
@@ -97,15 +99,15 @@ constructor(
|
||||
}
|
||||
|
||||
if (prevX != null && prevY != null && !isWallBump) {
|
||||
val dx = kotlin.math.abs(msg.x - prevX)
|
||||
val dy = kotlin.math.abs(msg.y - prevY)
|
||||
val dx = abs(msg.x - prevX)
|
||||
val dy = abs(msg.y - prevY)
|
||||
if (dx > 1 || dy > 1) {
|
||||
val gbaDirection =
|
||||
when {
|
||||
prevY == 0 -> 2
|
||||
prevY == currentMap.height - 1 -> 1
|
||||
prevX == 0 -> 3
|
||||
prevX == currentMap.width - 1 -> 4
|
||||
prevY == 0 -> Direction.UP
|
||||
prevY == currentMap.height - 1 -> Direction.DOWN
|
||||
prevX == 0 -> Direction.LEFT
|
||||
prevX == currentMap.width - 1 -> Direction.RIGHT
|
||||
else -> null
|
||||
}
|
||||
if (gbaDirection != null) {
|
||||
@@ -120,14 +122,14 @@ constructor(
|
||||
if (targetMap != null) {
|
||||
val targetX =
|
||||
when (gbaDirection) {
|
||||
3 -> targetMap.width - 1
|
||||
4 -> 0
|
||||
Direction.LEFT -> targetMap.width - 1
|
||||
Direction.RIGHT -> 0
|
||||
else -> (prevX - connection.unknown).coerceIn(0, targetMap.width - 1)
|
||||
}
|
||||
val targetY =
|
||||
when (gbaDirection) {
|
||||
1 -> 0
|
||||
2 -> targetMap.height - 1
|
||||
Direction.DOWN -> 0
|
||||
Direction.UP -> targetMap.height - 1
|
||||
else -> (prevY - connection.unknown).coerceIn(0, targetMap.height - 1)
|
||||
}
|
||||
edgeTransition(
|
||||
@@ -144,6 +146,20 @@ constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isWallBump && !isWalkable(currentMap, msg.x, msg.y)) {
|
||||
log.debug { "WALL: char=$charId blocked at (${msg.x}, ${msg.y})" }
|
||||
val seq = sequenceCounter.incrementAndGet().toByte()
|
||||
ctx.send(
|
||||
EntityMovePacket(
|
||||
entityId = charId,
|
||||
x = stored.info.positionX.toByte(),
|
||||
y = stored.info.positionY.toByte(),
|
||||
direction = msg.direction,
|
||||
seq = seq,
|
||||
))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,6 +202,12 @@ constructor(
|
||||
multiplayerService.broadcastExcept(ctx, movePkt)
|
||||
}
|
||||
|
||||
private fun isWalkable(map: MapDef, x: Int, y: Int): Boolean {
|
||||
if (x !in 0 until map.width || y !in 0 until map.height) return false
|
||||
val tile = map.tileAt(x, y) ?: return true
|
||||
return !tile.blocksMovement()
|
||||
}
|
||||
|
||||
private fun edgeTransition(
|
||||
ctx: SessionContext,
|
||||
charId: Long,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.fiereu.openmmo.server.game.services
|
||||
|
||||
import de.fiereu.network.SessionContext
|
||||
import de.fiereu.openmmo.common.enums.Region
|
||||
import de.fiereu.openmmo.maps.MapManager
|
||||
import de.fiereu.openmmo.net.game.packets.NpcSpawnPacket
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
@@ -88,9 +89,10 @@ constructor(
|
||||
for (npc in map.npcs) {
|
||||
val key = "$bankId:$mapId:${npc.entityIdx}"
|
||||
val entityId = npcEntityIds.getOrPut(key) { npcEntityIdCounter.incrementAndGet() }
|
||||
val unk3 = ((npc.movementType and 0xFF) shl 8) or 0x02
|
||||
val movementId = npc.movementType.forRegion(Region.HOENN).id
|
||||
val unk3 = ((movementId and 0xFF) shl 8) or 0x02
|
||||
val unk4 =
|
||||
if (npc.movementType in 1..6 || (npc.movementType in 25..52)) {
|
||||
if (movementId in 1..6 || (movementId in 25..52)) {
|
||||
((npc.movementRangeX and 0xFF) shl 8) or (npc.movementRangeY and 0xFF)
|
||||
} else {
|
||||
0
|
||||
@@ -107,7 +109,7 @@ constructor(
|
||||
mapId = mapId,
|
||||
x = npc.x,
|
||||
y = npc.y,
|
||||
facing = npc.facing,
|
||||
facing = npc.facing.ordinal,
|
||||
unk5 = 2,
|
||||
unk6 = 8,
|
||||
)
|
||||
|
||||
@@ -62,12 +62,18 @@ constructor(
|
||||
if (shouldAutoStepOffWarp && destMap != null) {
|
||||
val destWarp = destMap.warps.find { it.x == offsetX && it.y == offsetY }
|
||||
if (destWarp != null) {
|
||||
when (warpFacing) {
|
||||
Direction.UP -> offsetY--
|
||||
Direction.DOWN -> offsetY++
|
||||
Direction.LEFT -> offsetX--
|
||||
Direction.RIGHT -> offsetX++
|
||||
}
|
||||
offsetX +=
|
||||
when (warpFacing) {
|
||||
Direction.LEFT -> -1
|
||||
Direction.RIGHT -> 1
|
||||
else -> 0
|
||||
}
|
||||
offsetY +=
|
||||
when (warpFacing) {
|
||||
Direction.UP -> -1
|
||||
Direction.DOWN -> 1
|
||||
else -> 0
|
||||
}
|
||||
offsetX = offsetX.coerceIn(0, destMap.width - 1)
|
||||
offsetY = offsetY.coerceIn(0, destMap.height - 1)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user