forked from noxious/server
Major refractor, cleaning and improvements.
This commit is contained in:
@ -13,7 +13,7 @@ type TLoadedZone = {
|
||||
class ZoneManager {
|
||||
private loadedZones: TLoadedZone[] = []
|
||||
|
||||
// Method to initialize zone manager
|
||||
// Method to initialize zoneEditor manager
|
||||
public async boot() {
|
||||
if (!(await ZoneRepository.getById(1))) {
|
||||
const zoneService = new ZoneService()
|
||||
@ -29,9 +29,9 @@ class ZoneManager {
|
||||
logger.info('Zone manager loaded')
|
||||
}
|
||||
|
||||
// Method to handle individual zone loading
|
||||
// Method to handle individual zoneEditor loading
|
||||
public async loadZone(zone: Zone) {
|
||||
const grid = await this.getGrid(zone.id) // Create the grid for the zone
|
||||
const grid = await this.getGrid(zone.id) // Create the grid for the zoneEditor
|
||||
this.loadedZones.push({
|
||||
zone,
|
||||
characters: [],
|
||||
@ -40,7 +40,7 @@ class ZoneManager {
|
||||
logger.info(`Zone ID ${zone.id} loaded`)
|
||||
}
|
||||
|
||||
// Method to handle individual zone unloading
|
||||
// Method to handle individual zoneEditor unloading
|
||||
public unloadZone(zoneId: number) {
|
||||
this.loadedZones = this.loadedZones.filter((loadedZone) => {
|
||||
return loadedZone.zone.id !== zoneId
|
||||
@ -56,15 +56,43 @@ class ZoneManager {
|
||||
// Check if position is walkable
|
||||
private isPositionWalkable(zoneId: number, x: number, y: number): boolean {
|
||||
const loadedZone = this.loadedZones.find((lz) => lz.zone.id === zoneId)
|
||||
return loadedZone ? loadedZone.grid[y][x] === 0 : false
|
||||
if (!loadedZone) {
|
||||
console.log(`Zone ${zoneId} not found in loadedZones`);
|
||||
return false;
|
||||
}
|
||||
if (!loadedZone.grid) {
|
||||
console.log(`Grid for zone ${zoneId} is undefined`);
|
||||
return false;
|
||||
}
|
||||
if (!loadedZone.grid[y]) {
|
||||
console.log(`Row ${y} in grid for zone ${zoneId} is undefined`);
|
||||
return false;
|
||||
}
|
||||
return loadedZone.grid[y][x] === 0;
|
||||
}
|
||||
|
||||
public addCharacterToZone(zoneId: number, character: Character) {
|
||||
console.log(`Adding character ${character.id} to zone ${zoneId}`);
|
||||
console.log(`Character position: x=${character.positionX}, y=${character.positionY}`);
|
||||
|
||||
const loadedZone = this.loadedZones.find((loadedZone) => {
|
||||
return loadedZone.zone.id === zoneId
|
||||
})
|
||||
if (loadedZone && this.isPositionWalkable(zoneId, character.positionX, character.positionY)) {
|
||||
|
||||
if (!loadedZone) {
|
||||
console.log(`Zone ${zoneId} not found in loadedZones`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isPositionWalkable(zoneId, character.positionX, character.positionY)) {
|
||||
loadedZone.characters.push(character)
|
||||
console.log(`Character ${character.id} added to zone ${zoneId}`);
|
||||
} else {
|
||||
// set position to 0,0 if not walkable
|
||||
console.log(`Position (${character.positionX}, ${character.positionY}) is not walkable in zone ${zoneId}`);
|
||||
character.positionX = 0;
|
||||
character.positionY = 0;
|
||||
loadedZone.characters.push(character);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user