28 lines
880 B
TypeScript
28 lines
880 B
TypeScript
import { BaseEvent } from'@/application/base/baseEvent'
|
|
import { SocketEvent } from'@/application/enums'
|
|
import { MapObject } from'@/entities/mapObject'
|
|
import MapObjectRepository from'@/repositories/mapObjectRepository'
|
|
|
|
interface IPayload {}
|
|
|
|
export default class MapObjectListEvent extends BaseEvent {
|
|
public listen(): void {
|
|
this.socket.on(SocketEvent.GM_MAPOBJECT_LIST, this.handleEvent.bind(this))
|
|
}
|
|
|
|
private async handleEvent(data: IPayload, callback: (response: MapObject[]) => void): Promise<void> {
|
|
try {
|
|
if (!(await this.isCharacterGM())) return
|
|
|
|
// Get all map objects
|
|
const mapObjectRepository = new MapObjectRepository()
|
|
const mapObjects = await mapObjectRepository.getAll()
|
|
|
|
return callback(mapObjects)
|
|
} catch (error) {
|
|
this.logger.error('gm:mapObject:list error', error)
|
|
return callback([])
|
|
}
|
|
}
|
|
}
|