rock-mod
Version:
Rock-Mod is a powerful framework designed for creating and managing mods for Grand Theft Auto (GTA) games.
332 lines (331 loc) • 13.8 kB
JavaScript
import { BaseObjectType } from "../../../../shared/entities";
import { Vector3D } from "../../../../shared/common/utils";
const ZERO_VECTOR = new Vector3D(0, 0, 0);
/**
* CCMP implementation of the Rock-Mod player facade.
*
* Identity and synced meta are tracked by id. Runtime entity operations are
* delegated to `ccmp.players.getById(id)`, whose `handle` is live for the
* local player and for streamed remote players. Missing remote handles degrade
* to safe defaults/no-ops, matching RageMP-style best-effort client behavior.
*/
export class CCMPPlayer {
constructor(options) {
this._id = options.id;
this._name = options.name;
this._isLocal = options.isLocal;
this._isExists = true;
}
/** Помечает игрока как удалённого — вызывается из `CCMPPlayersManager`. */
markRemoved() {
this._isExists = false;
}
/** Обновляет name (полезно если name приехал позже первого создания). */
setNameInternal(name) {
if (name) {
this._name = name;
}
}
// -- IBaseObject ----------------------------------------------------------
get id() {
return this._id;
}
get remoteId() {
return this._id;
}
get type() {
return BaseObjectType.Player;
}
get isExists() {
return this._isExists;
}
get handle() {
var _a, _b;
return (_b = (_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.handle) !== null && _b !== void 0 ? _b : 0;
}
destroy() {
this._warnOnce("destroy");
}
// -- IWorldObject ---------------------------------------------------------
get position() {
var _a;
const position = (_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.position;
return position ? new Vector3D(position.x, position.y, position.z) : ZERO_VECTOR;
}
get dimension() {
return 0;
}
setPosition(value) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.setPosition(value);
}
setDimension(_value) {
this._warnOnce("setDimension");
}
setCoords(xPos, yPos, zPos, xAxis, yAxis, zAxis, clearArea) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.setCoords(xPos, yPos, zPos, xAxis, yAxis, zAxis, clearArea);
}
// -- IEntity --------------------------------------------------------------
get model() {
var _a, _b;
return (_b = (_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.model) !== null && _b !== void 0 ? _b : 0;
}
get heading() {
var _a, _b;
return (_b = (_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.heading) !== null && _b !== void 0 ? _b : 0;
}
setHeading(heading) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.setHeading(heading);
}
setModel(value) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.setModel(value);
}
get rotation() {
var _a;
const rotation = (_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.rotation;
return rotation ? new Vector3D(rotation.x, rotation.y, rotation.z) : ZERO_VECTOR;
}
setRotation(value) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.setRotation(value);
}
get forwardVector() {
var _a;
const vector = (_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.forwardVector;
return vector ? new Vector3D(vector.x, vector.y, vector.z) : ZERO_VECTOR;
}
freezePosition(freeze) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.freezePosition(freeze);
}
setCollision(collision, keepPhysics) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.setCollision(collision, keepPhysics);
}
setInvincible(invincible) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.setInvincible(invincible);
}
setVisible(visible) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.setVisible(visible);
}
setAlpha(alpha) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.setAlpha(alpha);
}
get alpha() {
var _a, _b;
return (_b = (_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.alpha) !== null && _b !== void 0 ? _b : 255;
}
resetAlpha() {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.resetAlpha();
}
getOffsetFromInWorldCoords(offsetX, offsetY, offsetZ) {
var _a;
const position = (_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.getOffsetFromInWorldCoords(offsetX, offsetY, offsetZ);
return position ? new Vector3D(position.x, position.y, position.z) : ZERO_VECTOR;
}
getBoneIndexByName(boneName) {
var _a, _b;
return (_b = (_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.getBoneIndexByName(boneName)) !== null && _b !== void 0 ? _b : -1;
}
getWorldPositionOfBone(boneIndex) {
var _a;
const position = (_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.getWorldPositionOfBone(boneIndex);
return position ? new Vector3D(position.x, position.y, position.z) : ZERO_VECTOR;
}
getVariable(name) {
const value = ccmp.entities.getStreamSyncedMeta(ccmp.entities.ENTITY_TYPE.Player, this._id, name);
return value === undefined ? null : value;
}
getSyncedMeta(key) {
return ccmp.entities.getStreamSyncedMeta(ccmp.entities.ENTITY_TYPE.Player, this._id, key);
}
hasSyncedMeta(key) {
return ccmp.entities.hasStreamSyncedMeta(ccmp.entities.ENTITY_TYPE.Player, this._id, key);
}
getSyncedMetaKeys() {
return ccmp.entities.getStreamSyncedMetaKeys(ccmp.entities.ENTITY_TYPE.Player, this._id);
}
attachToEntity(target, boneIndex, offset, rotation, p9, useSoftPinning, collision, isPed, vertexIndex, fixedRot) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.attachToEntity(target, boneIndex, offset, rotation, p9, useSoftPinning, collision, isPed, vertexIndex, fixedRot);
}
detach(useDetachVelocity, collision) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.detach(useDetachVelocity, collision);
}
getSpeed() {
var _a, _b;
return (_b = (_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.getSpeed()) !== null && _b !== void 0 ? _b : 0;
}
isPlayingAnim(dictionary, name, taskFlag) {
var _a, _b;
return (_b = (_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.isPlayingAnim(dictionary, name, taskFlag)) !== null && _b !== void 0 ? _b : false;
}
// -- IPlayer --------------------------------------------------------------
get name() {
return this._name;
}
get health() {
return 100;
}
get armour() {
return 0;
}
get isDead() {
return false;
}
get vehicle() {
return null;
}
get isVoice3DEnabled() {
return false;
}
get voiceVolume() {
return 0;
}
get isVoiceActive() {
return false;
}
setVoice3D(_enable) {
this._warnOnce("setVoice3D");
}
setVoiceVolume(_volume) {
this._warnOnce("setVoiceVolume");
}
get isReloading() {
return false;
}
get weapon() {
return 0;
}
getAmmoInClip(_weapon) {
return 0;
}
getWeaponAmmo(_weapon) {
return 0;
}
getBoneIndex(boneId) {
var _a, _b;
return (_b = (_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.getBoneIndex(boneId)) !== null && _b !== void 0 ? _b : -1;
}
setDecoration(collection, overlay) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.setDecoration(collection, overlay);
}
removeDecoration(collection, overlay) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.removeDecoration(collection, overlay);
}
clearDecorations() {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.clearDecorations();
}
setHeadBlendData(shapeFirstId, shapeSecondId, shapeThirdId, skinFirstId, skinSecondId, skinThirdId, shapeMix, skinMix, thirdMix, isParent) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.setHeadBlendData(shapeFirstId, shapeSecondId, shapeThirdId, skinFirstId, skinSecondId, skinThirdId, shapeMix, skinMix, thirdMix, isParent);
}
setFaceFeature(index, value) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.setFaceFeature(index, value);
}
setHeadOverlay(overlayId, index, opacity, _firstColor, _secondColor) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.setHeadOverlay(overlayId, index, opacity);
}
setHeadOverlayColor(overlayId, colorTypeId, firstColor, secondColor) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.setHeadOverlayColor(overlayId, colorTypeId, firstColor, secondColor);
}
setEyeColor(eyeColor) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.setEyeColor(eyeColor);
}
setHairColor(colorId, highlightColorId) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.setHairColor(colorId, highlightColorId);
}
setComponentVariation(componentId, drawableId, textureId, paletteId) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.setComponentVariation(componentId, drawableId, textureId, paletteId);
}
setPropertyVariation(componentId, drawableId, textureId, attach) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.setPropertyVariation(componentId, drawableId, textureId, attach);
}
clearProp(componentId) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.clearProp(componentId);
}
get isLocalPlayer() {
return this._isLocal;
}
taskSwapWeapon() {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.taskSwapWeapon(true);
}
taskEnterVehicle(vehicleHandle, timeout, seat, speed, flag, _p6) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.taskEnterVehicle(vehicleHandle, timeout, seat, speed, flag);
}
clearTasks() {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.clearTasks();
}
clearTasksImmediately() {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.clearTasksImmediately();
}
taskPlayAnim(dictionary, name, blendInSpeed, blendOutSpeed, duration, flag, playbackRate, lockX, lockY, lockZ) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.taskPlayAnim(dictionary, name, blendInSpeed, blendOutSpeed, duration, flag, playbackRate, lockX, lockY, lockZ);
}
stopAnim(dictionary, name, blendOutSpeed) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.stopAnim(dictionary, name, blendOutSpeed);
}
setMovementClipset(_clipset, _speed) {
this._warnOnce("setMovementClipset");
}
resetMovementClipset(_blendDuration) {
this._warnOnce("resetMovementClipset");
}
getBoneCoords(boneId, offsetX, offsetY, offsetZ) {
var _a;
const position = (_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.getBoneCoords(boneId, offsetX, offsetY, offsetZ);
return position ? new Vector3D(position.x, position.y, position.z) : ZERO_VECTOR;
}
setNoCollision(otherHandle, thisFrameOnly) {
var _a;
(_a = this._getNativePlayer()) === null || _a === void 0 ? void 0 : _a.setNoCollision(otherHandle, thisFrameOnly);
}
_getNativePlayer() {
try {
const player = ccmp.players.getById(this._id);
if (player) {
return player;
}
const localPlayer = ccmp.players.local;
return (localPlayer === null || localPlayer === void 0 ? void 0 : localPlayer.id) === this._id ? localPlayer : null;
}
catch (_a) {
return null;
}
}
_warnOnce(method) {
if (CCMPPlayer._warnedMethods.has(method)) {
return;
}
CCMPPlayer._warnedMethods.add(method);
console.warn(`[CCMPPlayer] ${method}() пока не реализован для CCMP — вызов проигнорирован ` +
`(следующие вызовы этого метода будут проигнорированы молча).`);
}
}
/** Глобальный set для one-time warnings, чтобы не флудить лог. */
CCMPPlayer._warnedMethods = new Set();