rock-mod
Version:
Rock-Mod is a powerful framework designed for creating and managing mods for Grand Theft Auto (GTA) games.
98 lines (97 loc) • 4.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RageColshapesManager = void 0;
const RageWorldObjectsManager_1 = require("../worldObject/RageWorldObjectsManager");
const RageCircleColshape_1 = require("./RageCircleColshape");
const RageCuboidColshape_1 = require("./RageCuboidColshape");
const RageCylinderColshape_1 = require("./RageCylinderColshape");
const RageRectangleColshape_1 = require("./RageRectangleColshape");
const RageSphereColshape_1 = require("./RageSphereColshape");
const RockMod_1 = require("../../../RockMod");
const types_1 = require("../../../net/common/events/types");
class RageColshapesManager extends RageWorldObjectsManager_1.RageWorldObjectsManager {
_colshapesParticipants = new Map();
constructor() {
super({
baseObjectsType: "colshape",
});
mp.events.add("playerEnterColshape", (mpPlayer, mpColshape) => {
const player = RockMod_1.RockMod.instance.players.getByID(mpPlayer.id);
const colshape = this.getByID(mpColshape.id);
const participants = this.getParticipants(colshape);
participants.add(player);
RockMod_1.RockMod.instance.net.events.emitInternal(types_1.ServerInternalEventName.PlayerEnteredColshape, player, colshape);
});
mp.events.add("playerExitColshape", (mpPlayer, mpColshape) => {
const player = RockMod_1.RockMod.instance.players.getByID(mpPlayer.id);
const colshape = this.getByID(mpColshape.id);
const participants = this.getParticipants(colshape);
participants.delete(player);
RockMod_1.RockMod.instance.net.events.emitInternal(types_1.ServerInternalEventName.PlayerLeftColshape, player, colshape);
});
}
createCircle(options) {
const { range, position, dimension, key } = options;
const { x, y } = position;
const mpEntity = mp.colshapes.newCircle(x, y, range, dimension);
mpEntity.isExists = () => mp.colshapes.exists(mpEntity);
const colshape = new RageCircleColshape_1.RageCircleColshape({ mpEntity, position });
if (key !== undefined)
colshape.setNetData("key", key);
this.registerBaseObject(colshape);
return colshape;
}
createCuboid(options) {
const { width, depth, height, position, dimension, key } = options;
const { x, y, z } = position;
const mpEntity = mp.colshapes.newCuboid(x, y, z, width, depth, height, dimension);
mpEntity.isExists = () => mp.colshapes.exists(mpEntity);
const colshape = new RageCuboidColshape_1.RageCuboidColshape({ mpEntity, position });
if (key !== undefined)
colshape.setNetData("key", key);
this.registerBaseObject(colshape);
return colshape;
}
createCylinder(options) {
const { height, range, position, dimension, key } = options;
const { x, y, z } = position;
const mpEntity = mp.colshapes.newTube(x, y, z, height, range, dimension);
mpEntity.isExists = () => mp.colshapes.exists(mpEntity);
const colshape = new RageCylinderColshape_1.RageCylinderColshape({ mpEntity, position });
if (key !== undefined)
colshape.setNetData("key", key);
this.registerBaseObject(colshape);
return colshape;
}
createRectangle(options) {
const { width, height, position, dimension, key } = options;
const { x, y } = position;
const mpEntity = mp.colshapes.newRectangle(x, y, width, height, dimension);
mpEntity.isExists = () => mp.colshapes.exists(mpEntity);
const colshape = new RageRectangleColshape_1.RageRectangleColshape({ mpEntity, position });
if (key !== undefined)
colshape.setNetData("key", key);
this.registerBaseObject(colshape);
return colshape;
}
createSphere(options) {
const { range, position, dimension, key } = options;
const { x, y, z } = position;
const mpEntity = mp.colshapes.newSphere(x, y, z, range, dimension);
mpEntity.isExists = () => mp.colshapes.exists(mpEntity);
const colshape = new RageSphereColshape_1.RageSphereColshape({ mpEntity, position });
if (key !== undefined)
colshape.setNetData("key", key);
this.registerBaseObject(colshape);
return colshape;
}
getParticipants(colshape) {
let participants = this._colshapesParticipants.get(colshape);
if (!participants) {
participants = new Set();
this._colshapesParticipants.set(colshape, participants);
}
return participants;
}
}
exports.RageColshapesManager = RageColshapesManager;