1
0
forked from noxious/server

Added models to store extra data in RAM

This commit is contained in:
2024-09-09 18:31:12 +02:00
parent 32b390bb20
commit 636aa6cc55
11 changed files with 116 additions and 190 deletions

View File

@ -2,16 +2,5 @@ import { ExtendedCharacter } from '../types'
import ZoneManager from '../../managers/zoneManager'
export class MovementValidator {
public async isValidMove(character: ExtendedCharacter, position: { x: number; y: number }): Promise<boolean> {
const grid = await ZoneManager.getGrid(character.zoneId)
if (!grid?.length) return false
return !this.isObstacle(position, grid)
}
private isObstacle({ x, y }: { x: number; y: number }, grid: number[][]): boolean {
const gridX = Math.floor(x)
const gridY = Math.floor(y)
return grid[gridY]?.[gridX] === 1 || grid[gridY]?.[Math.ceil(x)] === 1 || grid[Math.ceil(y)]?.[gridX] === 1 || grid[Math.ceil(y)]?.[Math.ceil(x)] === 1
}
}

View File

@ -32,4 +32,4 @@ class Rotation {
}
}
export default Rotation
export default Rotation