From f7072acdd248950c268280550372b658e76ab9ff Mon Sep 17 00:00:00 2001 From: Dennis Postma Date: Fri, 15 Nov 2024 01:58:05 +0100 Subject: [PATCH] Added code comment for #246 --- .../gameMaster/zoneEditor/update.ts | 7 ++-- src/utilities/character/rotation.ts | 32 +++++++++---------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/socketEvents/gameMaster/zoneEditor/update.ts b/src/socketEvents/gameMaster/zoneEditor/update.ts index af5aef8..a8f11c4 100644 --- a/src/socketEvents/gameMaster/zoneEditor/update.ts +++ b/src/socketEvents/gameMaster/zoneEditor/update.ts @@ -39,10 +39,10 @@ export default class ZoneUpdateEvent { ) {} public listen(): void { - this.socket.on('gm:zone_editor:zone:update', this.handleZoneUpdate.bind(this)) + this.socket.on('gm:zone_editor:zone:update', this.handleEvent.bind(this)) } - private async handleZoneUpdate(data: IPayload, callback: (response: Zone | null) => void): Promise { + private async handleEvent(data: IPayload, callback: (response: Zone | null) => void): Promise { try { const character = await CharacterRepository.getById(this.socket.characterId as number) if (!character) { @@ -146,6 +146,9 @@ export default class ZoneUpdateEvent { callback(zone) + /** + * @TODO #246: Reload zone for players who are currently in the zone + */ zoneManager.unloadZone(data.zoneId) await zoneManager.loadZone(zone) } catch (error: any) { diff --git a/src/utilities/character/rotation.ts b/src/utilities/character/rotation.ts index 2ff2fba..ddf3a43 100644 --- a/src/utilities/character/rotation.ts +++ b/src/utilities/character/rotation.ts @@ -2,33 +2,31 @@ import config from '../config' class Rotation { static calculate(X1: number, Y1: number, X2: number, Y2: number): number { - let rotation = 0 - if (config.ALLOW_DIAGONAL_MOVEMENT) { + // Check diagonal movements if (X1 > X2 && Y1 > Y2) { - rotation = 7 + return 7 } else if (X1 < X2 && Y1 < Y2) { - rotation = 3 + return 3 } else if (X1 > X2 && Y1 < Y2) { - rotation = 5 + return 5 } else if (X1 < X2 && Y1 > Y2) { - rotation = 1 + return 1 } } - if (rotation === 0) { - if (X1 > X2) { - rotation = 6 - } else if (X1 < X2) { - rotation = 2 - } else if (Y1 < Y2) { - rotation = 4 - } else if (Y1 > Y2) { - rotation = 0 - } + // Non-diagonal movements + if (X1 > X2) { + return 6 + } else if (X1 < X2) { + return 2 + } else if (Y1 < Y2) { + return 4 + } else if (Y1 > Y2) { + return 0 } - return rotation + return 0 // Default case } }