@armoury/fivem-framework-server 1.0.26 → 1.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,12 +19,6 @@ let SessionService = class SessionService {
19
19
  constructor(armouryResource) {
20
20
  this.armouryResource = armouryResource;
21
21
  }
22
- getClaimValue(sessionId, claimName) {
23
- return this.armouryResource.instance.getClaimValue(sessionId, claimName);
24
- }
25
- setClaim(sessionId, claimName, value) {
26
- return this.armouryResource.instance.setClaim(sessionId, claimName, value);
27
- }
28
22
  getNumPlayersConnected() {
29
23
  return this.armouryResource.instance.getNumPlayersConnected();
30
24
  }
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./models"), exports);
18
+ __exportStar(require("./services"), exports);
@@ -20,3 +20,5 @@ __exportStar(require("./character"), exports);
20
20
  __exportStar(require("./session"), exports);
21
21
  __exportStar(require("./session-update-type"), exports);
22
22
  __exportStar(require("./session-claim"), exports);
23
+ /** Zones */
24
+ __exportStar(require("./zone"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./zone"), exports);
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./zone.detector"), exports);
18
+ __exportStar(require("./zone.registry"), exports);
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZoneDetector = void 0;
4
+ class ZoneDetector {
5
+ static contains(zone, x, y, z) {
6
+ switch (zone.type) {
7
+ case 'sphere':
8
+ return this.containsSphere(zone, x, y, z);
9
+ case 'box':
10
+ return this.containsBox(zone, x, y, z);
11
+ case 'polygon':
12
+ return this.containsPolygon(zone, x, y, z);
13
+ }
14
+ }
15
+ static containsSphere(zone, x, y, z) {
16
+ const dx = x - zone.center[0];
17
+ const dy = y - zone.center[1];
18
+ const dz = z - zone.center[2];
19
+ return dx * dx + dy * dy + dz * dz <= zone.radius * zone.radius;
20
+ }
21
+ static containsBox(zone, x, y, z) {
22
+ const dx = x - zone.center[0];
23
+ const dy = y - zone.center[1];
24
+ const angle = (zone.heading * Math.PI) / 180;
25
+ const cos = Math.cos(angle);
26
+ const sin = Math.sin(angle);
27
+ const localX = dx * cos + dy * sin;
28
+ const localY = -dx * sin + dy * cos;
29
+ return (Math.abs(localX) <= zone.size[0] / 2 &&
30
+ Math.abs(localY) <= zone.size[1] / 2 &&
31
+ Math.abs(z - zone.center[2]) <= zone.size[2] / 2);
32
+ }
33
+ static containsPolygon(zone, x, y, z) {
34
+ if (z < zone.minZ || z > zone.maxZ)
35
+ return false;
36
+ let inside = false;
37
+ const points = zone.points;
38
+ for (let i = 0, j = points.length - 1; i < points.length; j = i++) {
39
+ const a = points[i];
40
+ const b = points[j];
41
+ const intersects = a.y > y !== b.y > y && x < ((b.x - a.x) * (y - a.y)) / (b.y - a.y) + a.x;
42
+ if (intersects)
43
+ inside = !inside;
44
+ }
45
+ return inside;
46
+ }
47
+ }
48
+ exports.ZoneDetector = ZoneDetector;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZoneRegistry = void 0;
4
+ class ZoneRegistry {
5
+ constructor() {
6
+ this._cellSize = 128;
7
+ this._zones = new Map();
8
+ this._cells = new Map();
9
+ }
10
+ replace(zones) {
11
+ this._zones.clear();
12
+ this._cells.clear();
13
+ for (const zone of zones) {
14
+ this.add(zone);
15
+ }
16
+ }
17
+ add(zone) {
18
+ this.remove(zone.id);
19
+ this._zones.set(zone.id, zone);
20
+ const bounds = this.getBounds(zone);
21
+ const minX = Math.floor(bounds.minX / this._cellSize);
22
+ const maxX = Math.floor(bounds.maxX / this._cellSize);
23
+ const minY = Math.floor(bounds.minY / this._cellSize);
24
+ const maxY = Math.floor(bounds.maxY / this._cellSize);
25
+ for (let x = minX; x <= maxX; x++) {
26
+ for (let y = minY; y <= maxY; y++) {
27
+ const key = `${x}:${y}`;
28
+ let cell = this._cells.get(key);
29
+ if (!cell) {
30
+ cell = new Set();
31
+ this._cells.set(key, cell);
32
+ }
33
+ cell.add(zone.id);
34
+ }
35
+ }
36
+ console.log(`Added zone with id ${zone.id}. Cells: ${this._cells.size}, Zones: ${this._zones.size}`);
37
+ }
38
+ remove(id) {
39
+ if (!this._zones.delete(id))
40
+ return;
41
+ const entries = this._cells.entries();
42
+ for (let entry = entries.next(); !entry.done; entry = entries.next()) {
43
+ const [key, cell] = entry.value;
44
+ cell.delete(id);
45
+ if (cell.size === 0) {
46
+ this._cells.delete(key);
47
+ }
48
+ }
49
+ }
50
+ getNearby(x, y, _) {
51
+ const localX = Math.floor(x / this._cellSize);
52
+ const localY = Math.floor(y / this._cellSize);
53
+ const ids = this._cells.get(`${localX}:${localY}`);
54
+ if (!ids)
55
+ return [];
56
+ return Array.from(ids, (id) => this._zones.get(id)).filter((zone) => zone !== undefined);
57
+ }
58
+ getBounds(zone) {
59
+ switch (zone.type) {
60
+ case 'sphere':
61
+ return {
62
+ minX: zone.center[0] - zone.radius,
63
+ maxX: zone.center[0] + zone.radius,
64
+ minY: zone.center[1] - zone.radius,
65
+ maxY: zone.center[1] + zone.radius,
66
+ };
67
+ case 'box': {
68
+ const angle = (zone.heading * Math.PI) / 180;
69
+ const hx = zone.size[0] / 2;
70
+ const hy = zone.size[1] / 2;
71
+ const extentX = Math.abs(Math.cos(angle)) * hx + Math.abs(Math.sin(angle)) * hy;
72
+ const extentY = Math.abs(Math.sin(angle)) * hx + Math.abs(Math.cos(angle)) * hy;
73
+ return {
74
+ minX: zone.center[0] - extentX,
75
+ maxX: zone.center[0] + extentX,
76
+ minY: zone.center[1] - extentY,
77
+ maxY: zone.center[1] + extentY,
78
+ };
79
+ }
80
+ case 'polygon':
81
+ return {
82
+ minX: Math.min(...zone.points.map((p) => p.x)),
83
+ maxX: Math.max(...zone.points.map((p) => p.x)),
84
+ minY: Math.min(...zone.points.map((p) => p.y)),
85
+ maxY: Math.max(...zone.points.map((p) => p.y)),
86
+ };
87
+ }
88
+ }
89
+ }
90
+ exports.ZoneRegistry = ZoneRegistry;
@@ -16,12 +16,6 @@ let SessionService = class SessionService {
16
16
  constructor(armouryResource) {
17
17
  this.armouryResource = armouryResource;
18
18
  }
19
- getClaimValue(sessionId, claimName) {
20
- return this.armouryResource.instance.getClaimValue(sessionId, claimName);
21
- }
22
- setClaim(sessionId, claimName, value) {
23
- return this.armouryResource.instance.setClaim(sessionId, claimName, value);
24
- }
25
19
  getNumPlayersConnected() {
26
20
  return this.armouryResource.instance.getNumPlayersConnected();
27
21
  }
@@ -1 +1,2 @@
1
1
  export * from './models';
2
+ export * from './services';
@@ -4,3 +4,5 @@ export * from './character';
4
4
  export * from './session';
5
5
  export * from './session-update-type';
6
6
  export * from './session-claim';
7
+ /** Zones */
8
+ export * from './zone';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from './zone';
@@ -0,0 +1,2 @@
1
+ export * from './zone.detector';
2
+ export * from './zone.registry';
@@ -0,0 +1,44 @@
1
+ export class ZoneDetector {
2
+ static contains(zone, x, y, z) {
3
+ switch (zone.type) {
4
+ case 'sphere':
5
+ return this.containsSphere(zone, x, y, z);
6
+ case 'box':
7
+ return this.containsBox(zone, x, y, z);
8
+ case 'polygon':
9
+ return this.containsPolygon(zone, x, y, z);
10
+ }
11
+ }
12
+ static containsSphere(zone, x, y, z) {
13
+ const dx = x - zone.center[0];
14
+ const dy = y - zone.center[1];
15
+ const dz = z - zone.center[2];
16
+ return dx * dx + dy * dy + dz * dz <= zone.radius * zone.radius;
17
+ }
18
+ static containsBox(zone, x, y, z) {
19
+ const dx = x - zone.center[0];
20
+ const dy = y - zone.center[1];
21
+ const angle = (zone.heading * Math.PI) / 180;
22
+ const cos = Math.cos(angle);
23
+ const sin = Math.sin(angle);
24
+ const localX = dx * cos + dy * sin;
25
+ const localY = -dx * sin + dy * cos;
26
+ return (Math.abs(localX) <= zone.size[0] / 2 &&
27
+ Math.abs(localY) <= zone.size[1] / 2 &&
28
+ Math.abs(z - zone.center[2]) <= zone.size[2] / 2);
29
+ }
30
+ static containsPolygon(zone, x, y, z) {
31
+ if (z < zone.minZ || z > zone.maxZ)
32
+ return false;
33
+ let inside = false;
34
+ const points = zone.points;
35
+ for (let i = 0, j = points.length - 1; i < points.length; j = i++) {
36
+ const a = points[i];
37
+ const b = points[j];
38
+ const intersects = a.y > y !== b.y > y && x < ((b.x - a.x) * (y - a.y)) / (b.y - a.y) + a.x;
39
+ if (intersects)
40
+ inside = !inside;
41
+ }
42
+ return inside;
43
+ }
44
+ }
@@ -0,0 +1,86 @@
1
+ export class ZoneRegistry {
2
+ constructor() {
3
+ this._cellSize = 128;
4
+ this._zones = new Map();
5
+ this._cells = new Map();
6
+ }
7
+ replace(zones) {
8
+ this._zones.clear();
9
+ this._cells.clear();
10
+ for (const zone of zones) {
11
+ this.add(zone);
12
+ }
13
+ }
14
+ add(zone) {
15
+ this.remove(zone.id);
16
+ this._zones.set(zone.id, zone);
17
+ const bounds = this.getBounds(zone);
18
+ const minX = Math.floor(bounds.minX / this._cellSize);
19
+ const maxX = Math.floor(bounds.maxX / this._cellSize);
20
+ const minY = Math.floor(bounds.minY / this._cellSize);
21
+ const maxY = Math.floor(bounds.maxY / this._cellSize);
22
+ for (let x = minX; x <= maxX; x++) {
23
+ for (let y = minY; y <= maxY; y++) {
24
+ const key = `${x}:${y}`;
25
+ let cell = this._cells.get(key);
26
+ if (!cell) {
27
+ cell = new Set();
28
+ this._cells.set(key, cell);
29
+ }
30
+ cell.add(zone.id);
31
+ }
32
+ }
33
+ console.log(`Added zone with id ${zone.id}. Cells: ${this._cells.size}, Zones: ${this._zones.size}`);
34
+ }
35
+ remove(id) {
36
+ if (!this._zones.delete(id))
37
+ return;
38
+ const entries = this._cells.entries();
39
+ for (let entry = entries.next(); !entry.done; entry = entries.next()) {
40
+ const [key, cell] = entry.value;
41
+ cell.delete(id);
42
+ if (cell.size === 0) {
43
+ this._cells.delete(key);
44
+ }
45
+ }
46
+ }
47
+ getNearby(x, y, _) {
48
+ const localX = Math.floor(x / this._cellSize);
49
+ const localY = Math.floor(y / this._cellSize);
50
+ const ids = this._cells.get(`${localX}:${localY}`);
51
+ if (!ids)
52
+ return [];
53
+ return Array.from(ids, (id) => this._zones.get(id)).filter((zone) => zone !== undefined);
54
+ }
55
+ getBounds(zone) {
56
+ switch (zone.type) {
57
+ case 'sphere':
58
+ return {
59
+ minX: zone.center[0] - zone.radius,
60
+ maxX: zone.center[0] + zone.radius,
61
+ minY: zone.center[1] - zone.radius,
62
+ maxY: zone.center[1] + zone.radius,
63
+ };
64
+ case 'box': {
65
+ const angle = (zone.heading * Math.PI) / 180;
66
+ const hx = zone.size[0] / 2;
67
+ const hy = zone.size[1] / 2;
68
+ const extentX = Math.abs(Math.cos(angle)) * hx + Math.abs(Math.sin(angle)) * hy;
69
+ const extentY = Math.abs(Math.sin(angle)) * hx + Math.abs(Math.cos(angle)) * hy;
70
+ return {
71
+ minX: zone.center[0] - extentX,
72
+ maxX: zone.center[0] + extentX,
73
+ minY: zone.center[1] - extentY,
74
+ maxY: zone.center[1] + extentY,
75
+ };
76
+ }
77
+ case 'polygon':
78
+ return {
79
+ minX: Math.min(...zone.points.map((p) => p.x)),
80
+ maxX: Math.max(...zone.points.map((p) => p.x)),
81
+ minY: Math.min(...zone.points.map((p) => p.y)),
82
+ maxY: Math.max(...zone.points.map((p) => p.y)),
83
+ };
84
+ }
85
+ }
86
+ }
@@ -2,8 +2,6 @@ import { ResourceRef, Session } from '@armoury/fivem-framework-common';
2
2
  export declare class SessionService {
3
3
  private readonly armouryResource;
4
4
  constructor(armouryResource: ResourceRef);
5
- getClaimValue<T>(sessionId: number, claimName: string): T | null;
6
- setClaim<T>(sessionId: number, claimName: string, value: T): T | null;
7
5
  getNumPlayersConnected(): number;
8
6
  getAllPlayerIds(): number[];
9
7
  getAllPlayerPrincipals(): number[];
@@ -1 +1,2 @@
1
1
  export * from './models';
2
+ export * from './services';
@@ -4,3 +4,5 @@ export * from './character';
4
4
  export * from './session';
5
5
  export * from './session-update-type';
6
6
  export * from './session-claim';
7
+ /** Zones */
8
+ export * from './zone';
@@ -0,0 +1,24 @@
1
+ export interface BaseZone {
2
+ id: number;
3
+ }
4
+ export interface SphereZone extends BaseZone {
5
+ type: 'sphere';
6
+ center: [number, number, number];
7
+ radius: number;
8
+ }
9
+ export interface BoxZone extends BaseZone {
10
+ type: 'box';
11
+ center: [number, number, number];
12
+ size: [number, number, number];
13
+ heading: number;
14
+ }
15
+ export interface PolygonZone extends BaseZone {
16
+ type: 'polygon';
17
+ points: {
18
+ x: number;
19
+ y: number;
20
+ }[];
21
+ minZ: number;
22
+ maxZ: number;
23
+ }
24
+ export type Zone = SphereZone | BoxZone | PolygonZone;
@@ -0,0 +1 @@
1
+ export * from './zone';
@@ -0,0 +1,2 @@
1
+ export * from './zone.detector';
2
+ export * from './zone.registry';
@@ -0,0 +1,7 @@
1
+ import { Zone } from '../../models/zone';
2
+ export declare class ZoneDetector {
3
+ static contains(zone: Zone, x: number, y: number, z: number): boolean;
4
+ private static containsSphere;
5
+ private static containsBox;
6
+ private static containsPolygon;
7
+ }
@@ -0,0 +1,11 @@
1
+ import { Zone } from '../../models/zone';
2
+ export declare class ZoneRegistry {
3
+ private readonly _cellSize;
4
+ private readonly _zones;
5
+ private readonly _cells;
6
+ replace(zones: Zone[]): void;
7
+ add(zone: Zone): void;
8
+ remove(id: number): void;
9
+ getNearby(x: number, y: number, _: number): Zone[];
10
+ private getBounds;
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@armoury/fivem-framework-server",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "description": "Server APIs for the Armoury FiveM framework",
5
5
  "main": "dist/cjs/server/index.js",
6
6
  "module": "dist/esm/server/index.js",
@@ -27,7 +27,7 @@
27
27
  "rxjs": "^7.8.1"
28
28
  },
29
29
  "peerDependencies": {
30
- "@armoury/fivem-framework-common": "1.0.26"
30
+ "@armoury/fivem-framework-common": "1.0.28"
31
31
  },
32
32
  "publishConfig": {
33
33
  "access": "public"