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 // Remove character from current zone
this.io.to(character.zoneId.toString()).emit('zone:character:leave', character.id) this.io.to(character.zoneId.toString()).emit('zone:character:leave', character.id)
this.socket.leave(character.zoneId.toString()) this.socket.leave(character.zoneId.toString())
await CharacterManager.removeCharacter(character)
CharacterManager.getCharacter(character.id);
// Add character to new zone // Add character to new zone
this.io.to(zone.id.toString()).emit('zone:character:join', character) this.io.to(zone.id.toString()).emit('zone:character:join', character)
this.socket.join(zone.id.toString()) this.socket.join(zone.id.toString())
character.zoneId = zone.id character.zoneId = zone.id
character.positionX = 0 character.positionX = 0
character.positionY = 0 character.positionY = 0
// Update character in CharacterManager character.resetMovement = true;
CharacterManager.initCharacter(character)
this.socket.emit('zone:character:teleport', { this.socket.emit('zone:character:teleport', {
zone, zone,

View File

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

View File

@ -34,6 +34,10 @@ class CharacterManager {
return this.characters.find((x) => x.id === socket?.characterId) 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) { public getCharactersInZone(zone: Zone) {
return this.characters.filter((x) => x.zoneId === zone.id) return this.characters.filter((x) => x.zoneId === zone.id)
} }