UNPKG

lfs-akairo

Version:

LFS Akairo is a framework designed to simplify the creation of InSim applications.

129 lines (128 loc) 4.52 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var cars_exports = {}; __export(cars_exports, { Cars: () => Cars }); module.exports = __toCommonJS(cars_exports); var import_packets = require("node-insim/packets"); class Cars { constructor(akairo) { this.akairo = akairo; } /** * Moves the player's car to specific position. * @param {Player} player The player whose car will be moved * @param coordinates Coordinates of player car (must be parsed) * @param coordinates.x X position of player car * @param coordinates.y Y position of player car * @param coordinates.z Z position of player car * @param coordinates.heading Heading angle of player car */ movePlayerCar(player, coordinates) { this.akairo.insim.send( new import_packets.IS_JRR({ StartPos: new import_packets.ObjectInfo({ X: coordinates.x, Y: coordinates.y, Zbyte: coordinates.z, Heading: coordinates.heading, Flags: 128 }), JRRAction: import_packets.JRRAction.JRR_RESET_NO_REPAIR, UCID: player.uniqueId, PLID: player.playerId }) ); } /** * Resets the player's car to its current position. * @param {Player} player The player whose car will be reset */ resetPlayerCar(player) { const coordinates = this.getPlayerCarCoordinates(player); this.akairo.insim.send( new import_packets.IS_JRR({ StartPos: new import_packets.ObjectInfo({ X: coordinates.x, Y: coordinates.y, Zbyte: coordinates.z, Heading: coordinates.heading, Flags: 128 }), JRRAction: import_packets.JRRAction.JRR_RESET, UCID: player.uniqueId, PLID: player.playerId }) ); } /** * Teleports a player's car to another player's location, with an optional distance offset. * @param {Player} from The player whose car will be teleported * @param {Player} to The player to whom the car will be teleported * @param {number} [distance=4] The distance offset in meters */ teleportPlayerCar(from, to, distance = 4) { const destination = this.getPlayerCarCoordinates(to); this.akairo.insim.send( new import_packets.IS_JRR({ StartPos: new import_packets.ObjectInfo({ X: destination.x + distance * 16, Y: destination.y + distance * 16, Zbyte: destination.z, Heading: destination.heading, Flags: 128 }), JRRAction: import_packets.JRRAction.JRR_RESET_NO_REPAIR, UCID: from.uniqueId, PLID: from.playerId }) ); } /** * Retrieves the coordinates and heading of a player's car. * @param {Player} player The player whose coordinates will be retrieved */ getPlayerCarCoordinates(player) { const x = player.get("essentials.position.raw.x"); const y = player.get("essentials.position.raw.y"); const z = player.get("essentials.position.raw.z"); const heading = player.get("essentials.heading.raw"); return this.parseCoordinates({ x, y, z, heading }); } /** * Parse and converts player car coordinates. * @param coordinates Coordinates of player car * @param coordinates.x X position of player car * @param coordinates.y Y position of player car * @param coordinates.z Z position of player car * @param coordinates.heading Heading angle of player car */ parseCoordinates(coordinates) { const x = coordinates.x / 65536 * 16; const y = coordinates.y / 65536 * 16; const z = coordinates.z / 16384; const heading = coordinates.heading / 256 + 128; return { x, y, z, heading }; } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { Cars });