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.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AltVColshapesManager = void 0;
const AltVWorldObjectsManager_1 = require("../worldObject/AltVWorldObjectsManager");
const AltVCircleColshape_1 = require("./AltVCircleColshape");
const AltVCuboidColshape_1 = require("./AltVCuboidColshape");
const AltVCylinderColshape_1 = require("./AltVCylinderColshape");
const AltVRectangleColshape_1 = require("./AltVRectangleColshape");
const AltVSphereColshape_1 = require("./AltVSphereColshape");
const RockMod_1 = require("../../../RockMod");
const types_1 = require("../../../net/common/events/types");
var ColshapeCircle = AltVServer.ColshapeCircle;
var ColshapeCuboid = AltVServer.ColshapeCuboid;
var ColshapeCylinder = AltVServer.ColshapeCylinder;
var ColshapeRectangle = AltVServer.ColshapeRectangle;
var ColshapeSphere = AltVServer.ColshapeSphere;
var BaseObjectType = AltVShared.BaseObjectType;
class AltVColshapesManager extends AltVWorldObjectsManager_1.AltVWorldObjectsManager {
_colshapesParticipants = new Map();
constructor() {
super({
baseObjectsType: "colshape",
});
AltVServer.on("entityEnterColshape", (mpColshape, mpEntity) => {
if (mpEntity.type === BaseObjectType.Player) {
const player = RockMod_1.RockMod.instance.players.getByID(mpEntity.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);
}
});
AltVServer.on("entityLeaveColshape", (mpColshape, mpEntity) => {
if (mpEntity.type === BaseObjectType.Player) {
const player = RockMod_1.RockMod.instance.players.getByID(mpEntity.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 } = options;
const { x, y } = position;
const mpEntity = new ColshapeCircle(x, y, range);
mpEntity.dimension = dimension;
const colshape = new AltVCircleColshape_1.AltVCircleColshape({ mpEntity });
this.registerBaseObject(colshape);
return colshape;
}
createCuboid(options) {
const { width, depth, height, position, dimension } = options;
const { x, y, z } = position;
const mpEntity = new ColshapeCuboid(x, y, z, x + width, y + depth, z + height);
mpEntity.dimension = dimension;
const colshape = new AltVCuboidColshape_1.AltVCuboidColshape({ mpEntity });
this.registerBaseObject(colshape);
return colshape;
}
createCylinder(options) {
const { height, range, position, dimension } = options;
const { x, y, z } = position;
const mpEntity = new ColshapeCylinder(x, y, z, range, height);
mpEntity.dimension = dimension;
const colshape = new AltVCylinderColshape_1.AltVCylinderColshape({ mpEntity });
this.registerBaseObject(colshape);
return colshape;
}
createRectangle(options) {
const { width, height, position, dimension } = options;
const { x, y } = position;
const mpEntity = new ColshapeRectangle(x, y, x + width, y + height);
mpEntity.dimension = dimension;
const colshape = new AltVRectangleColshape_1.AltVRectangleColshape({ mpEntity });
this.registerBaseObject(colshape);
return colshape;
}
createSphere(options) {
const { range, position, dimension } = options;
const { x, y, z } = position;
const mpEntity = new ColshapeSphere(x, y, z, range);
mpEntity.dimension = dimension;
const colshape = new AltVSphereColshape_1.AltVSphereColshape({ mpEntity });
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.AltVColshapesManager = AltVColshapesManager;