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

@ -51,4 +51,4 @@ export default class ChatMessageEvent {
callback(false)
}
}
}
}

View File

@ -56,4 +56,4 @@ export default class GMSpriteDeleteEvent {
}
})
}
}
}

View File

@ -61,4 +61,4 @@ export default class GMTileDeleteEvent {
logger.warn(`File ${finalFilePath} does not exist.`)
}
}
}
}

View File

@ -16,7 +16,7 @@ export default class CharacterMoveEvent {
private characterMoveService: CharacterMoveService
private zoneEventTileService: ZoneEventTileService
private movementValidator: MovementValidator
private nextPath: {[index: number]: {x: number, y: number}[]} = [];
private nextPath: { [index: number]: { x: number; y: number }[] } = []
constructor(
private readonly io: Server,
@ -38,16 +38,15 @@ export default class CharacterMoveEvent {
return
}
const path = await this.characterMoveService.calculatePath(character, positionX, positionY)
if (!path) {
this.io.in(character.zoneId.toString()).emit('character:moveError', 'No valid path found')
return
}
if(character.isMoving && !character.resetMovement) {
character.resetMovement = true;
this.nextPath[character.id] = path;
if (character.isMoving && !character.resetMovement) {
character.resetMovement = true
this.nextPath[character.id] = path
} else {
await this.moveAlongPath(character, path)
}
@ -55,26 +54,26 @@ export default class CharacterMoveEvent {
private async moveAlongPath(character: ExtendedCharacter, path: Array<{ x: number; y: number }>): Promise<void> {
for (let i = 0; i < path.length - 1; i++) {
const start = path[i];
const end = path[i + 1];
const start = path[i]
const end = path[i + 1]
if (!(await this.movementValidator.isValidMove(character, end))) {
break;
break
}
if(character.isMoving && character.resetMovement) {
character.isMoving = false;
character.resetMovement = false;
const nextPath = this.nextPath[character.id];
this.moveAlongPath(character, nextPath);
break;
if (character.isMoving && character.resetMovement) {
character.isMoving = false
character.resetMovement = false
const nextPath = this.nextPath[character.id]
this.moveAlongPath(character, nextPath)
break
}
if(!character.isMoving) {
character.isMoving = true;
if (!character.isMoving) {
character.isMoving = true
}
character.rotation = Rotation.calculate(start.x, start.y, end.x, end.y);
character.rotation = Rotation.calculate(start.x, start.y, end.x, end.y)
const zoneEventTile = await prisma.zoneEventTile.findFirst({
where: {
@ -82,33 +81,33 @@ export default class CharacterMoveEvent {
positionX: Math.floor(end.x),
positionY: Math.floor(end.y)
}
});
})
if (zoneEventTile) {
if (zoneEventTile.type === 'BLOCK') {
break;
break
}
if (zoneEventTile.type === 'TELEPORT') {
const teleportTile = await prisma.zoneEventTile.findFirst({
const teleportTile = (await prisma.zoneEventTile.findFirst({
where: { id: zoneEventTile.id },
include: { teleport: true }
}) as ZoneEventTileWithTeleport;
})) as ZoneEventTileWithTeleport
if (teleportTile) {
await this.handleZoneEventTile(teleportTile);
break;
await this.handleZoneEventTile(teleportTile)
break
}
}
}
await this.characterMoveService.updatePosition(character, end);
this.io.in(character.zoneId.toString()).emit('character:move', character);
await this.characterMoveService.updatePosition(character, end)
this.io.in(character.zoneId.toString()).emit('character:move', character)
await this.characterMoveService.applyMovementDelay();
await this.characterMoveService.applyMovementDelay()
}
this.finalizeMovement(character);
this.finalizeMovement(character)
}
private async handleZoneEventTile(zoneEventTile: ZoneEventTileWithTeleport): Promise<void> {