Added logics for a* pathfinding , rotation calculation and anti cheat, npm update.

This commit is contained in:
2024-07-28 00:46:13 +02:00
parent 7f84c4fedf
commit f2fcc67cb6
6 changed files with 242 additions and 31 deletions

View File

@ -1,6 +1,7 @@
import { Character, Zone } from '@prisma/client'
import ZoneRepository from '../repositories/ZoneRepository'
import ZoneService from '../services/ZoneService'
import zoneRepository from '../repositories/ZoneRepository'
type TLoadedZone = {
zone: Zone
@ -88,6 +89,44 @@ class ZoneManager {
})
return loadedZone ? loadedZone.characters : []
}
public async getGrid(zoneId: number): Promise<number[][]> {
const zone = this.loadedZones.find((z) => z.zone.id === zoneId)
let grid: number[][] = []
if (zone) {
const eventTiles = await zoneRepository.getEventTiles(zoneId)
const objects = await zoneRepository.getObjects(zoneId)
// Create a grid based on the event tiles
for (let i = 0; i < zone.zone.width; i++) {
grid.push(Array(zone.zone.height).fill(0))
}
// Set the grid values based on the event tiles, these are strings
eventTiles.forEach((eventTile) => {
if (eventTile.type === 'BLOCK') {
grid[eventTile.position_x][eventTile.position_y] = 0
} else if (eventTile.type === 'WARP') {
grid[eventTile.position_x][eventTile.position_y] = 1
} else if (eventTile.type === 'NPC') {
grid[eventTile.position_x][eventTile.position_y] = 2
} else if (eventTile.type === 'ITEM') {
grid[eventTile.position_x][eventTile.position_y] = 3
}
});
objects.forEach((object) => {
if (object.objectId === 'blank_tile') {
grid[object.position_x][object.position_y] = 0
} else {
grid[object.position_x][object.position_y] = 1
}
});
return grid
}
return []
}
}
export default new ZoneManager()