rock-mod
Version:
Rock-Mod is a powerful framework designed for creating and managing mods for Grand Theft Auto (GTA) games.
42 lines (41 loc) • 1.79 kB
JavaScript
import { Vector3D } from "../../../../shared/common/utils";
import { BaseObjectType } from "../../../../shared/entities";
export class RageRaycastingManager {
testPointToPoint(startPos, endPos, ignoreEntity, flags) {
const result = mp.raycasting.testPointToPoint(new mp.Vector3(startPos.x, startPos.y, startPos.z), new mp.Vector3(endPos.x, endPos.y, endPos.z), this._resolveIgnoreEntity(ignoreEntity), flags);
if (!result) {
return null;
}
return {
entityHandle: typeof result.entity === "number" ? result.entity : result.entity.handle,
position: new Vector3D(result.position.x, result.position.y, result.position.z),
surfaceNormal: new Vector3D(result.surfaceNormal.x, result.surfaceNormal.y, result.surfaceNormal.z),
};
}
_resolveIgnoreEntity(ignoreEntity) {
if (!ignoreEntity) {
return undefined;
}
if (Array.isArray(ignoreEntity)) {
const entities = ignoreEntity
.map((entity) => this._resolveMpEntity(entity))
.filter((entity) => Boolean(entity));
return entities.length > 0 ? entities : undefined;
}
return this._resolveMpEntity(ignoreEntity);
}
_resolveMpEntity(entity) {
switch (entity.type) {
case BaseObjectType.Player:
return mp.players.atHandle(entity.handle);
case BaseObjectType.Vehicle:
return mp.vehicles.atHandle(entity.handle);
case BaseObjectType.Object:
return mp.objects.atHandle(entity.handle);
case BaseObjectType.Ped:
return mp.peds.atHandle(entity.handle);
default:
return undefined;
}
}
}