rock-mod
Version:
Rock-Mod is a powerful framework designed for creating and managing mods for Grand Theft Auto (GTA) games.
111 lines (110 loc) • 5.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CCMPColshapesManager = void 0;
const CCMPWorldObjectsManager_1 = require("../worldObject/CCMPWorldObjectsManager");
const CCMPCircleColshape_1 = require("./CCMPCircleColshape");
const CCMPCuboidColshape_1 = require("./CCMPCuboidColshape");
const CCMPCylinderColshape_1 = require("./CCMPCylinderColshape");
const CCMPSphereColshape_1 = require("./CCMPSphereColshape");
const RockMod_1 = require("../../../RockMod");
const types_1 = require("../../../net/common/events/types");
class CCMPColshapesManager extends CCMPWorldObjectsManager_1.CCMPWorldObjectsManager {
constructor() {
super({
baseObjectsType: "colshape",
});
ccmp.on("playerEnterColshape", (ccmpPlayer, ccmpColshape) => {
if (!ccmpColshape)
return;
const colshape = this.findByID(ccmpColshape.id);
if (!colshape)
return;
const player = RockMod_1.RockMod.instance.players.findByID(ccmpPlayer.id);
if (!player)
return;
RockMod_1.RockMod.instance.net.events.emitInternal(types_1.ServerInternalEventName.PlayerEnteredColshape, player, colshape);
});
ccmp.on("playerExitColshape", (ccmpPlayer, ccmpColshape) => {
if (!ccmpColshape)
return;
const colshape = this.findByID(ccmpColshape.id);
if (!colshape)
return;
const player = RockMod_1.RockMod.instance.players.findByID(ccmpPlayer.id);
if (!player)
return;
RockMod_1.RockMod.instance.net.events.emitInternal(types_1.ServerInternalEventName.PlayerLeftColshape, player, colshape);
});
}
createCircle(options) {
const { position, range, dimension, key } = options;
const extras = key === undefined ? { dimension } : { dimension, key };
const ccmpColshape = ccmp.colshapes.createCircle(position.x, position.y, position.z, range, extras);
if (!ccmpColshape) {
throw new Error("CCMPColshapesManager.createCircle: ccmp.colshapes.createCircle failed (server full?)");
}
const colshape = new CCMPCircleColshape_1.CCMPCircleColshape({
ccmpColshape,
onDestroy: (c) => this.unregisterBaseObject(c),
});
this.registerBaseObject(colshape);
return colshape;
}
createCuboid(options) {
const { position, width, depth, height, dimension, key } = options;
const extras = key === undefined ? { dimension } : { dimension, key };
// CCMP cube uses HALF-extents (centered at position); rock-mod options describe full sizes.
const ccmpColshape = ccmp.colshapes.createCube(position.x, position.y, position.z, width / 2, depth / 2, height / 2, extras);
if (!ccmpColshape) {
throw new Error("CCMPColshapesManager.createCuboid: ccmp.colshapes.createCube failed (server full?)");
}
const colshape = new CCMPCuboidColshape_1.CCMPCuboidColshape({
ccmpColshape,
onDestroy: (c) => this.unregisterBaseObject(c),
});
this.registerBaseObject(colshape);
return colshape;
}
createCylinder(options) {
const { position, range, height, dimension, key } = options;
const extras = key === undefined ? { dimension } : { dimension, key };
const ccmpColshape = ccmp.colshapes.createCylinder(position.x, position.y, position.z, range, height, extras);
if (!ccmpColshape) {
throw new Error("CCMPColshapesManager.createCylinder: ccmp.colshapes.createCylinder failed (server full?)");
}
const colshape = new CCMPCylinderColshape_1.CCMPCylinderColshape({
ccmpColshape,
onDestroy: (c) => this.unregisterBaseObject(c),
});
this.registerBaseObject(colshape);
return colshape;
}
createRectangle(_options) {
throw new Error("CCMPColshapesManager.createRectangle: not supported by CCMP");
}
createSphere(options) {
const { position, range, dimension, key } = options;
const extras = key === undefined ? { dimension } : { dimension, key };
const ccmpColshape = ccmp.colshapes.createSphere(position.x, position.y, position.z, range, extras);
if (!ccmpColshape) {
throw new Error("CCMPColshapesManager.createSphere: ccmp.colshapes.createSphere failed (server full?)");
}
const colshape = new CCMPSphereColshape_1.CCMPSphereColshape({
ccmpColshape,
onDestroy: (c) => this.unregisterBaseObject(c),
});
this.registerBaseObject(colshape);
return colshape;
}
getParticipants(colshape) {
const participants = new Set();
for (const ccmpPlayer of colshape.playersInside) {
const player = RockMod_1.RockMod.instance.players.findByID(ccmpPlayer.id);
if (player) {
participants.add(player);
}
}
return participants;
}
}
exports.CCMPColshapesManager = CCMPColshapesManager;