rock-mod
Version:
Rock-Mod is a powerful framework designed for creating and managing mods for Grand Theft Auto (GTA) games.
205 lines (204 loc) • 7.05 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CCMPVehicle = void 0;
const CCMPEntity_1 = require("../entity/CCMPEntity");
const utils_1 = require("../../../../shared/common/utils");
const Vectors_1 = require("../../../../shared/common/utils/math/Vectors");
const shared_1 = require("../../../../shared");
const RockMod_1 = require("../../../RockMod");
class CCMPVehicle extends CCMPEntity_1.CCMPEntity {
static _customPrimaryColorMeta = "rockMod:customPrimaryColor";
static _customSecondaryColorMeta = "rockMod:customSecondaryColor";
static _vehicleModsMeta = "rockMod:vehicleMods";
static _neonEnabledMeta = "rockMod:neonEnabled";
static _neonColorMeta = "rockMod:neonColor";
static _windowTintMeta = "rockMod:windowTint";
static _wheelTypeMeta = "rockMod:wheelType";
_ccmpVehicle;
_onDestroy;
_mods = new Map();
_customPrimaryColor = new utils_1.RGBA(0, 0, 0);
_customSecondaryColor = new utils_1.RGBA(0, 0, 0);
get id() {
return this._ccmpVehicle.id;
}
get type() {
return shared_1.BaseObjectType.Vehicle;
}
get isExists() {
return this._ccmpVehicle.isExists;
}
get position() {
const p = this._ccmpVehicle.position;
return new Vectors_1.Vector3D(p.x, p.y, p.z);
}
get dimension() {
return this._ccmpVehicle.dimension;
}
get model() {
return this._ccmpVehicle.model;
}
get rotation() {
const r = this._ccmpVehicle.rotation;
return new Vectors_1.Vector3D(r.x, r.y, r.z);
}
get bodyHealth() {
return this._ccmpVehicle.bodyHealth;
}
get engineHealth() {
return this._ccmpVehicle.engineHealth;
}
get numberPlate() {
return this._ccmpVehicle.numberPlate;
}
get isLocked() {
const lockState = this._ccmpVehicle.lockState;
return lockState !== 0 && lockState !== 1;
}
get isDead() {
return !this.isExists || this.bodyHealth <= 0;
}
get primaryColor() {
return this._ccmpVehicle.primaryColor;
}
get secondaryColor() {
return this._ccmpVehicle.secondaryColor;
}
get customPrimaryColor() {
return this._customPrimaryColor;
}
get customSecondaryColor() {
return this._customSecondaryColor;
}
get driver() {
const ccmpDriver = this._ccmpVehicle.driver;
if (!ccmpDriver)
return null;
return RockMod_1.RockMod.instance.players.findByID(ccmpDriver.id);
}
get passengers() {
const passengers = new Set();
for (const ccmpPassenger of this._ccmpVehicle.passengers) {
const player = RockMod_1.RockMod.instance.players.findByID(ccmpPassenger.id);
if (player) {
passengers.add(player);
}
}
return passengers;
}
get ccmpMeta() {
return this._ccmpVehicle;
}
constructor(options) {
super();
this._ccmpVehicle = options.ccmpVehicle;
this._onDestroy = options.onDestroy;
this._restoreCompatibilityState();
}
destroy() {
if (!this._ccmpVehicle.isExists)
return;
this._ccmpVehicle.destroy();
this._onDestroy(this);
}
setPosition(value) {
this._ccmpVehicle.position = { x: value.x, y: value.y, z: value.z };
}
setDimension(value) {
this._ccmpVehicle.dimension = value;
}
setModel(value) {
this._ccmpVehicle.model = RockMod_1.RockMod.instance.utils.hash(value);
}
setRotation(value) {
this._ccmpVehicle.rotation = { x: value.x, y: value.y, z: value.z };
}
setBodyHealth(value) {
this._ccmpVehicle.bodyHealth = value;
}
setEngineHealth(value) {
this._ccmpVehicle.engineHealth = value;
}
setEngineOn(value) {
this._ccmpVehicle.engineOn = value;
}
setNumberPlate(value) {
this._ccmpVehicle.numberPlate = value;
}
setLocked(value) {
this._ccmpVehicle.lockState = value ? 2 : 1;
}
setPrimaryColor(value) {
this._ccmpVehicle.primaryColor = value;
}
setSecondaryColor(value) {
this._ccmpVehicle.secondaryColor = value;
}
setCustomPrimaryColor(value) {
this._customPrimaryColor = this._toRgba(value);
this._setCompatibilityMeta(CCMPVehicle._customPrimaryColorMeta, this._customPrimaryColor);
}
setCustomSecondaryColor(value) {
this._customSecondaryColor = this._toRgba(value);
this._setCompatibilityMeta(CCMPVehicle._customSecondaryColorMeta, this._customSecondaryColor);
}
setMod(modType, modIndex) {
this._mods.set(Math.trunc(modType), Math.trunc(modIndex));
this._setCompatibilityMeta(CCMPVehicle._vehicleModsMeta, Object.fromEntries(this._mods));
}
getMod(modType) {
return this._mods.get(Math.trunc(modType)) ?? -1;
}
setNeonEnabled(enabled) {
this._setCompatibilityMeta(CCMPVehicle._neonEnabledMeta, enabled);
}
setNeonColor(r, g, b) {
this._setCompatibilityMeta(CCMPVehicle._neonColorMeta, new utils_1.RGBA(r, g, b));
}
setWindowTint(tintType) {
this._setCompatibilityMeta(CCMPVehicle._windowTintMeta, Math.trunc(tintType));
}
setWheelType(wheelType) {
this._setCompatibilityMeta(CCMPVehicle._wheelTypeMeta, Math.trunc(wheelType));
}
setPlateType(plateType) {
this._ccmpVehicle.numberPlateType = plateType;
}
explode() {
this._ccmpVehicle.bodyHealth = 0;
this._ccmpVehicle.engineHealth = -4000;
this._ccmpVehicle.engineOn = false;
}
repair() {
this._ccmpVehicle.bodyHealth = 1000;
this._ccmpVehicle.engineHealth = 1000;
}
_restoreCompatibilityState() {
this._customPrimaryColor = this._readColorMeta(CCMPVehicle._customPrimaryColorMeta);
this._customSecondaryColor = this._readColorMeta(CCMPVehicle._customSecondaryColorMeta);
const mods = this._ccmpVehicle.getStreamSyncedMeta(CCMPVehicle._vehicleModsMeta);
if (!mods || typeof mods !== "object")
return;
for (const [key, value] of Object.entries(mods)) {
const modType = Number(key);
const modIndex = Number(value);
if (Number.isFinite(modType) && Number.isFinite(modIndex)) {
this._mods.set(Math.trunc(modType), Math.trunc(modIndex));
}
}
}
_readColorMeta(key) {
const value = this._ccmpVehicle.getStreamSyncedMeta(key);
if (!value || typeof value !== "object") {
return new utils_1.RGBA(0, 0, 0);
}
return new utils_1.RGBA(Number(value.r) || 0, Number(value.g) || 0, Number(value.b) || 0, value.a);
}
_setCompatibilityMeta(key, value) {
this._ccmpVehicle.setStreamSyncedMeta(key, value);
}
_toRgba(value) {
return new utils_1.RGBA(value.r, value.g, value.b, value.a);
}
}
exports.CCMPVehicle = CCMPVehicle;