forked from noxious/server
Started improving character move event
This commit is contained in:
@ -50,7 +50,6 @@ export default class CharacterMove {
|
||||
const { character } = zoneCharacter
|
||||
|
||||
for (let i = 0; i < path.length - 1; i++) {
|
||||
// Exit if movement was cancelled or interrupted
|
||||
if (!zoneCharacter.isMoving || zoneCharacter.currentPath !== path) {
|
||||
return
|
||||
}
|
||||
@ -67,11 +66,17 @@ export default class CharacterMove {
|
||||
}
|
||||
|
||||
this.characterService.updatePosition(character, end)
|
||||
this.io.in(character.zone!.id.toString()).emit('character:move', zoneCharacter)
|
||||
// Send minimal data
|
||||
this.io.in(character.zone!.id.toString()).emit('character:move', {
|
||||
id: character.id,
|
||||
positionX: end.x,
|
||||
positionY: end.y,
|
||||
rotation: character.rotation,
|
||||
isMoving: true
|
||||
})
|
||||
await this.characterService.applyMovementDelay()
|
||||
}
|
||||
|
||||
// Only finalize if this path wasn't interrupted
|
||||
if (zoneCharacter.isMoving && zoneCharacter.currentPath === path) {
|
||||
this.finalizeMovement(zoneCharacter)
|
||||
}
|
||||
@ -91,6 +96,12 @@ export default class CharacterMove {
|
||||
|
||||
private finalizeMovement(zoneCharacter: ZoneCharacter): void {
|
||||
zoneCharacter.isMoving = false
|
||||
this.io.in(zoneCharacter.character.zone!.id.toString()).emit('character:move', zoneCharacter)
|
||||
this.io.in(zoneCharacter.character.zone!.id.toString()).emit('character:move', {
|
||||
id: zoneCharacter.character.id,
|
||||
positionX: zoneCharacter.character.positionX,
|
||||
positionY: zoneCharacter.character.positionY,
|
||||
rotation: zoneCharacter.character.rotation,
|
||||
isMoving: false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user