forked from noxious/server
Fixes for teleporting between zones
This commit is contained in:
@ -148,6 +148,33 @@ class ZoneManager {
|
||||
|
||||
return grid
|
||||
}
|
||||
|
||||
public async moveCharacterBetweenZones(oldZoneId: number, newZoneId: number, character: Character): Promise<void> {
|
||||
// Find the old and new zones
|
||||
const oldZone = this.loadedZones.find(zone => zone.zone.id === oldZoneId);
|
||||
const newZone = this.loadedZones.find(zone => zone.zone.id === newZoneId);
|
||||
|
||||
if (!oldZone || !newZone) {
|
||||
logger.error(`Unable to move character ${character.id}: zones not found`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove character from old zone
|
||||
oldZone.characters = oldZone.characters.filter(c => c.id !== character.id);
|
||||
|
||||
// Check if the new position is walkable
|
||||
if (this.isPositionWalkable(newZoneId, character.positionX, character.positionY)) {
|
||||
newZone.characters.push(character);
|
||||
} else {
|
||||
// Set position to 0,0 if not walkable
|
||||
logger.warn(`Position (${character.positionX}, ${character.positionY}) is not walkable in zone ${newZoneId}. Moving character to (0,0).`);
|
||||
character.positionX = 0;
|
||||
character.positionY = 0;
|
||||
newZone.characters.push(character);
|
||||
}
|
||||
|
||||
logger.info(`Character ${character.id} moved from zone ${oldZoneId} to zone ${newZoneId}`);
|
||||
}
|
||||
}
|
||||
|
||||
export default new ZoneManager()
|
||||
|
Reference in New Issue
Block a user