Fixes for anims

This commit is contained in:
Dennis Postma 2024-08-27 00:34:02 +02:00
parent e069d9293a
commit e219bb19ee
2 changed files with 15 additions and 7 deletions

View File

@ -6,6 +6,7 @@ import { MovementValidator } from '../../utilities/movementValidator'
import { SocketEmitter } from '../../utilities/socketEmitter'
import prisma from '../../utilities/prisma'
import { ZoneEventTile, ZoneEventTileTeleport } from '@prisma/client'
import Rotation from '../../utilities/character/rotation'
type ZoneEventTileWithTeleport = ZoneEventTile & {
teleport: ZoneEventTileTeleport | null
@ -38,6 +39,7 @@ export default class CharacterMoveEvent {
return
}
const path = await this.characterMoveService.calculatePath(character, positionX, positionY)
if (!path) {
this.socketEmitter.emitMoveError('No valid path found')
@ -48,17 +50,23 @@ export default class CharacterMoveEvent {
}
private async moveAlongPath(character: ExtendedCharacter, path: Array<{ x: number; y: number }>): Promise<void> {
for (const position of path) {
if (!(await this.movementValidator.isValidMove(character, position))) {
break
for (let i = 0; i < path.length - 1; i++) {
const start = path[i];
const end = path[i + 1];
if (!(await this.movementValidator.isValidMove(character, end))) {
break;
}
character.isMoving = true;
character.rotation = Rotation.calculate(start.x, start.y, end.x, end.y);
const zoneEventTile = await prisma.zoneEventTile.findFirst({
where: {
zoneId: character.zoneId,
type: 'TELEPORT',
positionX: Math.floor(position.x),
positionY: Math.floor(position.y)
positionX: Math.floor(end.x),
positionY: Math.floor(end.y)
},
include: { teleport: true }
}) as ZoneEventTileWithTeleport | null
@ -68,7 +76,7 @@ export default class CharacterMoveEvent {
break
}
await this.characterMoveService.updatePosition(character, position)
await this.characterMoveService.updatePosition(character, end)
this.socketEmitter.emitCharacterMove(character)
await this.characterMoveService.applyMovementDelay()

View File

@ -52,6 +52,6 @@ export class CharacterMoveService {
}
public async applyMovementDelay(): Promise<void> {
await new Promise((resolve) => setTimeout(resolve, 250)) // 50ms delay between steps
await new Promise((resolve) => setTimeout(resolve, 240)) // 50ms delay between steps
}
}