Teleport fix

This commit is contained in:
Dennis Postma 2025-01-14 02:18:53 +01:00
parent 74f5214ca3
commit 0ba79c2299
2 changed files with 21 additions and 8 deletions

View File

@ -55,7 +55,7 @@ export default class CharacterMove extends BaseEvent {
if (mapEventTile?.type === 'BLOCK') break
if (mapEventTile?.type === 'TELEPORT' && mapEventTile.teleport) {
await this.handleMapEventTile(mapEventTile as MapEventTileWithTeleport)
break
return
}
// Update position first

View File

@ -48,13 +48,6 @@ class TeleportService {
const currentMapId = mapCharacter.character.map?.id
const io = SocketManager.getIO()
// Handle current map cleanup
if (currentMapId) {
socket.leave(currentMapId)
MapManager.removeCharacter(characterId)
io.in(currentMapId).emit('map:character:leave', characterId)
}
// Update character position and map
await mapCharacter
.getCharacter()
@ -64,6 +57,26 @@ class TeleportService {
.setMap(targetMap.getMap())
.save()
// If the current map is the target map and we are not joining, send move event
if (currentMapId === options.targetMapId && !options.isInitialJoin) {
// If the current map is the target map, send move event
io.in(currentMapId).emit('map:character:move', {
characterId: mapCharacter.character.id,
positionX: options.targetX,
positionY: options.targetY,
rotation: options.rotation ?? 0,
isMoving: false
})
return true
}
// Handle current map cleanup
if (currentMapId) {
socket.leave(currentMapId)
MapManager.removeCharacter(characterId)
io.in(currentMapId).emit('map:character:leave', characterId)
}
// Join new map
socket.join(options.targetMapId)
targetMap.addCharacter(mapCharacter.getCharacter())