forked from noxious/server
Pathfinding spam fix, persistence character location without saving every step
This commit is contained in:
@ -6,6 +6,9 @@ import prisma from '../../utilities/prisma'
|
||||
import { ZoneEventTile, ZoneEventTileTeleport } from '@prisma/client'
|
||||
import Rotation from '../../utilities/character/rotation'
|
||||
import logger from '../../utilities/logger'
|
||||
import CharacterManager from '../../managers/characterManager'
|
||||
import zoneManager from '../../managers/zoneManager'
|
||||
import ZoneManager from '../../managers/zoneManager'
|
||||
|
||||
type ZoneEventTileWithTeleport = ZoneEventTile & {
|
||||
teleport: ZoneEventTileTeleport
|
||||
@ -29,22 +32,32 @@ export default class CharacterMove {
|
||||
}
|
||||
|
||||
private async handleCharacterMove({ positionX, positionY }: { positionX: number; positionY: number }): Promise<void> {
|
||||
const { character } = this.socket
|
||||
let character = CharacterManager.getCharacterFromSocket(this.socket);
|
||||
if (!character) {
|
||||
logger.error('character:move error', 'Character not found')
|
||||
return
|
||||
}
|
||||
|
||||
if(!character) {
|
||||
logger.error('character:move error', 'character has not been initialized?');
|
||||
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 = false;
|
||||
}
|
||||
if (character.isMoving && !character.resetMovement) {
|
||||
character.resetMovement = true
|
||||
this.nextPath[character.id] = path
|
||||
} else {
|
||||
}
|
||||
if(!character.isMoving && !character.resetMovement) {
|
||||
character.isMoving = true;
|
||||
await this.moveAlongPath(character, path)
|
||||
}
|
||||
}
|
||||
@ -58,16 +71,9 @@ export default class CharacterMove {
|
||||
// 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.resetMovement) {
|
||||
|
||||
if (!character.isMoving) {
|
||||
character.isMoving = true
|
||||
break
|
||||
}
|
||||
|
||||
character.rotation = Rotation.calculate(start.x, start.y, end.x, end.y)
|
||||
@ -98,13 +104,18 @@ export default class CharacterMove {
|
||||
}
|
||||
}
|
||||
|
||||
await this.characterMoveService.updatePosition(character, end)
|
||||
this.characterMoveService.updatePosition(character, end)
|
||||
this.io.in(character.zoneId.toString()).emit('character:move', character)
|
||||
|
||||
await this.characterMoveService.applyMovementDelay()
|
||||
}
|
||||
|
||||
this.finalizeMovement(character)
|
||||
if(character.resetMovement) {
|
||||
character.resetMovement = false;
|
||||
await this.moveAlongPath(character, this.nextPath[character.id]);
|
||||
} else {
|
||||
this.finalizeMovement(character)
|
||||
}
|
||||
}
|
||||
|
||||
private async handleZoneEventTile(zoneEventTile: ZoneEventTileWithTeleport): Promise<void> {
|
||||
@ -122,7 +133,7 @@ export default class CharacterMove {
|
||||
}
|
||||
|
||||
private finalizeMovement(character: ExtendedCharacter): void {
|
||||
character.isMoving = false
|
||||
character.isMoving = false;
|
||||
this.io.in(character.zoneId.toString()).emit('character:move', character)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user