|
|
|
@ -16,7 +16,7 @@ export default class CharacterMoveEvent {
|
|
|
|
|
private characterMoveService: CharacterMoveService
|
|
|
|
|
private zoneEventTileService: ZoneEventTileService
|
|
|
|
|
private movementValidator: MovementValidator
|
|
|
|
|
private nextPath: {[index: number]: {x: number, y: number}[]} = [];
|
|
|
|
|
private nextPath: { [index: number]: { x: number; y: number }[] } = []
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private readonly io: Server,
|
|
|
|
@ -38,16 +38,15 @@ export default class CharacterMoveEvent {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const path = await this.characterMoveService.calculatePath(character, positionX, positionY)
|
|
|
|
|
if (!path) {
|
|
|
|
|
this.io.in(character.zoneId.toString()).emit('character:moveError', 'No valid path found')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(character.isMoving && !character.resetMovement) {
|
|
|
|
|
character.resetMovement = true;
|
|
|
|
|
this.nextPath[character.id] = path;
|
|
|
|
|
if (character.isMoving && !character.resetMovement) {
|
|
|
|
|
character.resetMovement = true
|
|
|
|
|
this.nextPath[character.id] = path
|
|
|
|
|
} else {
|
|
|
|
|
await this.moveAlongPath(character, path)
|
|
|
|
|
}
|
|
|
|
@ -55,26 +54,26 @@ export default class CharacterMoveEvent {
|
|
|
|
|
|
|
|
|
|
private async moveAlongPath(character: ExtendedCharacter, path: Array<{ x: number; y: number }>): Promise<void> {
|
|
|
|
|
for (let i = 0; i < path.length - 1; i++) {
|
|
|
|
|
const start = path[i];
|
|
|
|
|
const end = path[i + 1];
|
|
|
|
|
const start = path[i]
|
|
|
|
|
const end = path[i + 1]
|
|
|
|
|
|
|
|
|
|
if (!(await this.movementValidator.isValidMove(character, end))) {
|
|
|
|
|
break;
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(character.isMoving && character.resetMovement) {
|
|
|
|
|
character.isMoving = false;
|
|
|
|
|
character.resetMovement = false;
|
|
|
|
|
const nextPath = this.nextPath[character.id];
|
|
|
|
|
this.moveAlongPath(character, nextPath);
|
|
|
|
|
break;
|
|
|
|
|
if (character.isMoving && character.resetMovement) {
|
|
|
|
|
character.isMoving = false
|
|
|
|
|
character.resetMovement = false
|
|
|
|
|
const nextPath = this.nextPath[character.id]
|
|
|
|
|
this.moveAlongPath(character, nextPath)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!character.isMoving) {
|
|
|
|
|
character.isMoving = true;
|
|
|
|
|
if (!character.isMoving) {
|
|
|
|
|
character.isMoving = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
character.rotation = Rotation.calculate(start.x, start.y, end.x, end.y);
|
|
|
|
|
character.rotation = Rotation.calculate(start.x, start.y, end.x, end.y)
|
|
|
|
|
|
|
|
|
|
const zoneEventTile = await prisma.zoneEventTile.findFirst({
|
|
|
|
|
where: {
|
|
|
|
@ -82,33 +81,33 @@ export default class CharacterMoveEvent {
|
|
|
|
|
positionX: Math.floor(end.x),
|
|
|
|
|
positionY: Math.floor(end.y)
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (zoneEventTile) {
|
|
|
|
|
if (zoneEventTile.type === 'BLOCK') {
|
|
|
|
|
break;
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (zoneEventTile.type === 'TELEPORT') {
|
|
|
|
|
const teleportTile = await prisma.zoneEventTile.findFirst({
|
|
|
|
|
const teleportTile = (await prisma.zoneEventTile.findFirst({
|
|
|
|
|
where: { id: zoneEventTile.id },
|
|
|
|
|
include: { teleport: true }
|
|
|
|
|
}) as ZoneEventTileWithTeleport;
|
|
|
|
|
})) as ZoneEventTileWithTeleport
|
|
|
|
|
|
|
|
|
|
if (teleportTile) {
|
|
|
|
|
await this.handleZoneEventTile(teleportTile);
|
|
|
|
|
break;
|
|
|
|
|
await this.handleZoneEventTile(teleportTile)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await this.characterMoveService.updatePosition(character, end);
|
|
|
|
|
this.io.in(character.zoneId.toString()).emit('character:move', character);
|
|
|
|
|
await this.characterMoveService.updatePosition(character, end)
|
|
|
|
|
this.io.in(character.zoneId.toString()).emit('character:move', character)
|
|
|
|
|
|
|
|
|
|
await this.characterMoveService.applyMovementDelay();
|
|
|
|
|
await this.characterMoveService.applyMovementDelay()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.finalizeMovement(character);
|
|
|
|
|
this.finalizeMovement(character)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async handleZoneEventTile(zoneEventTile: ZoneEventTileWithTeleport): Promise<void> {
|
|
|
|
|