diff --git a/src/controllers/gangzone/index.ts b/src/controllers/gangzone/index.ts new file mode 100644 index 0000000..d685585 --- /dev/null +++ b/src/controllers/gangzone/index.ts @@ -0,0 +1,119 @@ +import { LimitsEnum } from "@/enums"; +import { IBaseGangZone } from "@/interfaces"; +import { logger } from "@/logger"; +import { + GangZoneCreate, + GangZoneDestroy, + GangZoneFlashForAll, + GangZoneFlashForPlayer, + GangZoneHideForAll, + GangZoneHideForPlayer, + GangZoneShowForAll, + GangZoneShowForPlayer, + GangZoneStopFlashForAll, + GangZoneStopFlashForPlayer, +} from "@/wrapper/functions"; +import { BasePlayer } from "../player"; + +export abstract class BaseGangZone { + private _id = -1; + private static createdCount = 0; + public readonly sourceInfo: IBaseGangZone; + constructor(gangzone: IBaseGangZone) { + this.sourceInfo = gangzone; + } + public create(): void { + if (this.id !== -1) + return logger.warn("[BaseGangZone]: Unable to create the gangzone again"); + if (BaseGangZone.createdCount === LimitsEnum.MAX_GANG_ZONES) + return logger.warn( + "[BaseGangZone]: Unable to continue to create gangzone, maximum allowable quantity has been reached" + ); + const { minx, miny, maxx, maxy } = this.sourceInfo; + this._id = GangZoneCreate(minx, miny, maxx, maxy); + } + + public destroy() { + if (this.id === -1) + return logger.warn( + "[BaseGangZone]: Unable to destroy the gangzone before create" + ); + GangZoneDestroy(this.id); + BaseGangZone.createdCount--; + this._id = -1; + } + + public showForAll(color: string): void | number { + if (this.id === -1) + return logger.warn( + "[BaseGangZone]: Unable to show the gangzone before create" + ); + return GangZoneShowForAll(this.id, color); + } + + public showForPlayer
( + player: P, + color: string + ): void | number { + if (this.id === -1) + return logger.warn( + "[BaseGangZone]: Unable to show the gangzone before create" + ); + return GangZoneShowForPlayer(player.id, this.id, color); + } + + public hideForAll(): void | number { + if (this.id === -1) + return logger.warn( + "[BaseGangZone]: Unable to hide the gangzone before create" + ); + return GangZoneHideForAll(this.id); + } + + public hideForPlayer
(player: P): void | number { + if (this.id === -1) + return logger.warn( + "[BaseGangZone]: Unable to hide the gangzone before create" + ); + return GangZoneHideForPlayer(player.id, this.id); + } + + public flashForAll(flashcolor: string): void | number { + if (this.id === -1) + return logger.warn( + "[BaseGangZone]: Unable to flash the gangzone before create" + ); + return GangZoneFlashForAll(this.id, flashcolor); + } + + public flashForPlayer
( + player: P, + flashcolor: string + ): void | number { + if (this.id === -1) + return logger.warn( + "[BaseGangZone]: Unable to flash the gangzone before create" + ); + return GangZoneFlashForPlayer(player.id, this.id, flashcolor); + } + + public StopFlashForAll(): void | number { + if (this.id === -1) + return logger.warn( + "[BaseGangZone]: Unable to stop flash the gangzone before create" + ); + return GangZoneStopFlashForAll(this.id); + } + + public StopFlashForPlayer
(player: P): void | number {
+ if (this.id === -1)
+ return logger.warn(
+ "[BaseGangZone]: Unable to stop flash the gangzone before create"
+ );
+ return GangZoneStopFlashForPlayer(player.id, this.id);
+ }
+
+ public get id() {
+ return this._id;
+ }
+}
diff --git a/src/controllers/index.ts b/src/controllers/index.ts
index a063de0..7a75e19 100644
--- a/src/controllers/index.ts
+++ b/src/controllers/index.ts
@@ -8,3 +8,4 @@ export * from "./gamemode";
export * from "./netstats";
export * from "./gametext";
export * from "./menu";
+export * from "./gangzone";
diff --git a/src/interfaces/index.ts b/src/interfaces/index.ts
index 5b75ba8..1a6db33 100644
--- a/src/interfaces/index.ts
+++ b/src/interfaces/index.ts
@@ -41,3 +41,27 @@ export interface IPlayerSettings {
locale: string;
charset: string;
}
+
+export interface IVehicle {
+ modelid: number;
+ x: number;
+ y: number;
+ z: number;
+ z_angle: number;
+ color1: string;
+ color2: string;
+ respawn_delay?: number;
+ addsiren?: boolean;
+}
+
+export interface IAnimateInfo {
+ n: string;
+ d: number;
+}
+
+export interface IBaseGangZone {
+ minx: number;
+ miny: number;
+ maxx: number;
+ maxy: number;
+}
diff --git a/src/utils/animateUtils.ts b/src/utils/animateUtils.ts
index 9a65052..070b891 100644
--- a/src/utils/animateUtils.ts
+++ b/src/utils/animateUtils.ts
@@ -1,7 +1,4 @@
-interface IAnimateInfo {
- n: string;
- d: number;
-}
+import { IAnimateInfo } from "@/interfaces";
const animateLib = new Map