Minor movement improvements

This commit is contained in:
Dennis Postma 2025-02-16 18:16:17 +01:00
parent d68d307895
commit f2dd1a2ffe
3 changed files with 10 additions and 11 deletions

View File

@ -121,6 +121,11 @@ export default class CharacterMove extends BaseEvent {
if (mapEventTile) { if (mapEventTile) {
if (mapEventTile.type === 'BLOCK') break if (mapEventTile.type === 'BLOCK') break
if (mapEventTile.type === 'TELEPORT' && mapEventTile.teleport) { if (mapEventTile.type === 'TELEPORT' && mapEventTile.teleport) {
// Force clear movement state before teleport
mapCharacter.isMoving = false
mapCharacter.currentPath = null
this.lastKnownPosition = null // Reset last known position
await CharacterMoveService.handleTeleportMapEventTile(character.id, mapEventTile as MapEventTileWithTeleport) await CharacterMoveService.handleTeleportMapEventTile(character.id, mapEventTile as MapEventTileWithTeleport)
return return
} }

View File

@ -13,8 +13,6 @@ type Position = { positionX: number; positionY: number }
export type Node = Position & { parent?: Node; g: number; h: number; f: number } export type Node = Position & { parent?: Node; g: number; h: number; f: number }
class CharacterMoveService extends BaseService { class CharacterMoveService extends BaseService {
private io: Server = SocketManager.getIO()
// Rotation lookup table for better performance // Rotation lookup table for better performance
private readonly ROTATION_MAP = { private readonly ROTATION_MAP = {
diagonal: { diagonal: {
@ -223,8 +221,9 @@ class CharacterMoveService extends BaseService {
return path return path
} }
public broadcastMovement(character: Character, isMoving: boolean): void { public broadcastMovement(character: Character, isMoving: boolean = false): void {
this.io.in(character.map.id).emit(SocketEvent.MAP_CHARACTER_MOVE, [character.id, character.getPositionX(), character.getPositionY(), character.getRotation(), isMoving]) const io: Server = SocketManager.getIO()
io.in(character.map.id).emit(SocketEvent.MAP_CHARACTER_MOVE, [character.id, character.getPositionX(), character.getPositionY(), character.getRotation(), isMoving])
} }
public validateMovementDistance( public validateMovementDistance(

View File

@ -6,6 +6,7 @@ import MapManager from '@/managers/mapManager'
import SocketManager from '@/managers/socketManager' import SocketManager from '@/managers/socketManager'
import MapCharacter from '@/models/mapCharacter' import MapCharacter from '@/models/mapCharacter'
import MapRepository from '@/repositories/mapRepository' import MapRepository from '@/repositories/mapRepository'
import CharacterMoveService from '@/services/characterMoveService'
interface TeleportOptions { interface TeleportOptions {
targetMapId: UUID targetMapId: UUID
@ -61,13 +62,7 @@ class CharacterTeleportService {
// If the current map is the target map and we are not joining, send move event // If the current map is the target map and we are not joining, send move event
if (currentMapId === options.targetMapId && !options.isInitialJoin) { if (currentMapId === options.targetMapId && !options.isInitialJoin) {
// If the current map is the target map, send move event // If the current map is the target map, send move event
io.in(currentMapId).emit(SocketEvent.MAP_CHARACTER_MOVE, { CharacterMoveService.broadcastMovement(mapCharacter.character, false)
characterId: mapCharacter.character.id,
positionX: options.targetX,
positionY: options.targetY,
rotation: options.rotation ?? 0,
isMoving: false
})
return true return true
} }