forked from noxious/server
Walk fixes
This commit is contained in:
@ -270,7 +270,14 @@ export default class InitCommand extends BaseCommand {
|
||||
.save()
|
||||
|
||||
const characterType = new CharacterType()
|
||||
await characterType.setId('75b70c78-17f0-44c0-a4fa-15043cb95be0').setName('New character type').setGender(CharacterGender.MALE).setRace(CharacterRace.HUMAN).setIsSelectable(true).setSprite(characterSprite).save()
|
||||
await characterType
|
||||
.setId('75b70c78-17f0-44c0-a4fa-15043cb95be0')
|
||||
.setName('New character type')
|
||||
.setGender(CharacterGender.MALE)
|
||||
.setRace(CharacterRace.HUMAN)
|
||||
.setIsSelectable(true)
|
||||
.setSprite(characterSprite)
|
||||
.save()
|
||||
}
|
||||
|
||||
private async createCharacterHair(): Promise<void> {
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import MapManager from '@/managers/mapManager'
|
||||
import MapRepository from '@/repositories/mapRepository'
|
||||
import ChatService from '@/services/chatService'
|
||||
|
||||
type TypePayload = {
|
||||
@ -25,13 +24,6 @@ export default class ChatMessageEvent extends BaseEvent {
|
||||
|
||||
const character = mapCharacter.character
|
||||
|
||||
const mapRepository = new MapRepository()
|
||||
const map = await mapRepository.getById(character.map.id)
|
||||
if (!map) {
|
||||
this.logger.error('chat:message error', 'Map not found')
|
||||
return callback(false)
|
||||
}
|
||||
|
||||
if (await ChatService.sendMapMessage(character.getId(), data.message)) {
|
||||
return callback(true)
|
||||
}
|
||||
|
@ -19,7 +19,16 @@ export class Server {
|
||||
await Database.initialize()
|
||||
|
||||
// Initialize managers
|
||||
await Promise.all([HttpManager.boot(HttpManager.getAppInstance()), SocketManager.boot(HttpManager.getAppInstance(), HttpManager.getServerInstance()), QueueManager.boot(), UserManager.boot(), MapManager.boot(), DateManager.boot(), WeatherManager.boot(), ConsoleManager.boot()])
|
||||
await Promise.all([
|
||||
HttpManager.boot(HttpManager.getAppInstance()),
|
||||
SocketManager.boot(HttpManager.getAppInstance(), HttpManager.getServerInstance()),
|
||||
QueueManager.boot(),
|
||||
UserManager.boot(),
|
||||
MapManager.boot(),
|
||||
DateManager.boot(),
|
||||
WeatherManager.boot(),
|
||||
ConsoleManager.boot()
|
||||
])
|
||||
} catch (error: any) {
|
||||
console.error(error)
|
||||
this.logger.error(`Server failed to start: ${error.message}`)
|
||||
|
@ -118,35 +118,42 @@ class CharacterMoveService extends BaseService {
|
||||
|
||||
private findPath(start: Position, end: Position, grid: number[][]): Node[] {
|
||||
const openList = new PriorityQueue<Node>((a, b) => a.f - b.f)
|
||||
openList.enqueue({ ...start, g: 0, h: 0, f: 0 })
|
||||
const closedSet = new Set<string>()
|
||||
|
||||
const getKey = (p: Position) => `${p.positionX},${p.positionY}`
|
||||
|
||||
while (openList.length > 0) {
|
||||
const current = openList.dequeue()
|
||||
if (!current) break
|
||||
openList.enqueue({ ...start, g: 0, h: 0, f: 0 })
|
||||
|
||||
if (current.positionX === end.positionX && current.positionY === end.positionY) {
|
||||
return this.reconstructPath(current)
|
||||
try {
|
||||
while (openList.length > 0) {
|
||||
const current = openList.dequeue()
|
||||
if (!current) break
|
||||
|
||||
if (current.positionX === end.positionX && current.positionY === end.positionY) {
|
||||
return this.reconstructPath(current)
|
||||
}
|
||||
|
||||
closedSet.add(getKey(current))
|
||||
|
||||
const neighbors = this.getValidNeighbors(current, grid, end)
|
||||
|
||||
for (const neighbor of neighbors) {
|
||||
if (closedSet.has(getKey(neighbor))) continue
|
||||
|
||||
const g = current.g + this.getDistance(current, neighbor)
|
||||
const h = this.getDistance(neighbor, end)
|
||||
const f = g + h
|
||||
|
||||
const node: Node = {...neighbor, g, h, f, parent: current}
|
||||
openList.enqueue(node)
|
||||
}
|
||||
}
|
||||
|
||||
closedSet.add(getKey(current))
|
||||
|
||||
const neighbors = this.getValidNeighbors(current, grid, end)
|
||||
|
||||
for (const neighbor of neighbors) {
|
||||
if (closedSet.has(getKey(neighbor))) continue
|
||||
|
||||
const g = current.g + this.getDistance(current, neighbor)
|
||||
const h = this.getDistance(neighbor, end)
|
||||
const f = g + h
|
||||
|
||||
const node: Node = { ...neighbor, g, h, f, parent: current }
|
||||
openList.enqueue(node)
|
||||
}
|
||||
return [] // No path found
|
||||
} finally {
|
||||
while(openList.length > 0) openList.dequeue()
|
||||
closedSet.clear()
|
||||
}
|
||||
|
||||
return [] // No path found
|
||||
}
|
||||
|
||||
private getValidNeighbors(current: Position, grid: number[][], end: Position): Position[] {
|
||||
@ -159,7 +166,13 @@ class CharacterMoveService extends BaseService {
|
||||
}
|
||||
|
||||
private isValidPosition(pos: Position, grid: number[][], end: Position): boolean {
|
||||
return pos.positionX >= 0 && pos.positionY >= 0 && pos.positionX < grid[0]!.length && pos.positionY < grid.length && (grid[pos.positionY]![pos.positionX] === 0 || (pos.positionX === end.positionX && pos.positionY === end.positionY))
|
||||
return (
|
||||
pos.positionX >= 0 &&
|
||||
pos.positionY >= 0 &&
|
||||
pos.positionX < grid[0]!.length &&
|
||||
pos.positionY < grid.length &&
|
||||
(grid[pos.positionY]![pos.positionX] === 0 || (pos.positionX === end.positionX && pos.positionY === end.positionY))
|
||||
)
|
||||
}
|
||||
|
||||
private getDistance(a: Position, b: Position): number {
|
||||
@ -179,7 +192,13 @@ class CharacterMoveService extends BaseService {
|
||||
return path
|
||||
}
|
||||
|
||||
public validateMovementDistance(currentX: number, currentY: number, lastKnownPosition: { x: number; y: number } | null, stepDelay: number, isMoving: boolean): { isValid: boolean; maxAllowedDistance: number; actualDistance: number } {
|
||||
public validateMovementDistance(
|
||||
currentX: number,
|
||||
currentY: number,
|
||||
lastKnownPosition: { x: number; y: number } | null,
|
||||
stepDelay: number,
|
||||
isMoving: boolean
|
||||
): { isValid: boolean; maxAllowedDistance: number; actualDistance: number } {
|
||||
if (!lastKnownPosition || !isMoving) {
|
||||
return { isValid: true, maxAllowedDistance: 0, actualDistance: 0 }
|
||||
}
|
||||
|
Reference in New Issue
Block a user