Teleport fix

This commit is contained in:
Zaxiure 2024-09-20 23:30:38 +02:00
parent ed92663313
commit 12283640fe
No known key found for this signature in database
3 changed files with 17 additions and 8 deletions

View File

@ -58,19 +58,17 @@ export default class TeleportCommandEvent {
// Remove character from current zone
this.io.to(character.zoneId.toString()).emit('zone:character:leave', character.id)
this.socket.leave(character.zoneId.toString())
await CharacterManager.removeCharacter(character)
CharacterManager.getCharacter(character.id);
// Add character to new zone
this.io.to(zone.id.toString()).emit('zone:character:join', character)
this.socket.join(zone.id.toString())
character.zoneId = zone.id
character.positionX = 0
character.positionY = 0
// Update character in CharacterManager
CharacterManager.initCharacter(character)
character.resetMovement = true;
this.socket.emit('zone:character:teleport', {
zone,

View File

@ -18,6 +18,7 @@ export default class CharacterMove {
private characterMoveService: CharacterMoveService
private zoneEventTileService: ZoneEventTileService
private nextPath: { [index: number]: { x: number; y: number }[] } = []
private currentZoneId: {[index:number]: number} = []
constructor(
private readonly io: Server,
@ -58,6 +59,7 @@ export default class CharacterMove {
}
if (!character.isMoving && !character.resetMovement) {
character.isMoving = true
this.currentZoneId[character.id] = character.zoneId;
await this.moveAlongPath(character, path)
}
}
@ -71,7 +73,7 @@ export default class CharacterMove {
// break
// }
if (character.resetMovement) {
if (CharacterManager.hasResetMovement(character)) {
break
}
@ -109,9 +111,14 @@ export default class CharacterMove {
await this.characterMoveService.applyMovementDelay()
}
if (character.resetMovement) {
if (CharacterManager.hasResetMovement(character)) {
character.resetMovement = false
await this.moveAlongPath(character, this.nextPath[character.id])
if(this.currentZoneId[character.id] === character.zoneId) {
await this.moveAlongPath(character, this.nextPath[character.id])
} else {
delete this.currentZoneId[character.id];
character.isMoving = false;
}
} else {
this.finalizeMovement(character)
}

View File

@ -9,7 +9,7 @@ class CharacterManager {
this.characters = []
}
public initCharacter(character: ExtendedCharacter) {
public initCharacter(character: ExtendedCharacter) {
this.characters = [...this.characters, character]
}
@ -34,6 +34,10 @@ class CharacterManager {
return this.characters.find((x) => x.id === socket?.characterId)
}
public hasResetMovement(character: ExtendedCharacter) {
return this.characters.find(x => x.id === character.id)?.resetMovement;
}
public getCharactersInZone(zone: Zone) {
return this.characters.filter((x) => x.zoneId === zone.id)
}