45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
const PlayerWorker = global.PlayerWorker;
|
|
|
|
module.exports = function (ws, message, player) {
|
|
if (!player.isAlive) return;
|
|
|
|
const worldX = message.getUint16(1);
|
|
const worldY = message.getUint16(3);
|
|
|
|
const destination = player.map.grid.getCell(worldX, worldY);
|
|
if (!player.map.grid.isValidNode(destination)) return
|
|
|
|
const { xw, xh } = player.previousDestination;
|
|
if (destination.xw === xw && destination.xh === xh) return;
|
|
|
|
const position = player.isMoving ? { x: player.nextNode[0], y: player.nextNode[1] } : player.position;
|
|
const { x, y } = position;
|
|
const currentPosition = player.map.grid.getCell(x, y);
|
|
if (currentPosition.xw === destination.xw && currentPosition.xh === destination.xh) return;
|
|
|
|
player.previousDestination = destination;
|
|
|
|
if (player.isMoving) {
|
|
player.intermediateMovementWasStarted = true;
|
|
player.isNewPathReady = false;
|
|
player.isLastNodeFinished = false;
|
|
player.scheduledPath = [];
|
|
};
|
|
|
|
player.cancelDisconnect();
|
|
|
|
if (!player.movementRequestTracker) player.movementRequestTracker = 1;
|
|
else player.movementRequestTracker++;
|
|
|
|
PlayerWorker.postMessage({
|
|
destination,
|
|
position,
|
|
id: player.id,
|
|
mapId: player.map.id,
|
|
wasMoving: player.isMoving,
|
|
movementRequestTracker: player.movementRequestTracker
|
|
});
|
|
|
|
return [x, y, worldX, worldY, player.hp.current / player.hp.maximum, player.attackers.length, player.isAttacking()];
|
|
};
|