Skip to content

Commit

Permalink
feat: player and vehicle adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
dockfries committed Aug 30, 2022
1 parent 87db11f commit bd85db6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
18 changes: 14 additions & 4 deletions src/controllers/player.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { OnPlayerText, SendClientMessage } from "@/utils/helper";
import { OnPlayerConnect, OnPlayerDisconnect } from "@/wrapper/callbacks";
import {
GetPlayerDrunkLevel,
Expand All @@ -22,10 +23,13 @@ export class BasePlayer {
// Each instance can be called to callbacks, so you can split the logic.
OnPlayerConnect((playerid: number): void => {
if (this.id === -1) this.id = playerid;
if (playerid === this.id) this.OnConnect();
if (playerid === this.id) this.onConnect();
});
OnPlayerDisconnect((playerid: number, reason: number): void => {
if (playerid === this.id) this.OnDisconnect(reason);
if (playerid === this.id) this.onDisconnect(reason);
});
OnPlayerText((player: BasePlayer, text: string) => {
if (player === this) this.onText(text);
});
}

Expand All @@ -34,9 +38,15 @@ export class BasePlayer {

// Note: The locale and character set must be assigned at application level development time. Otherwise i18n will be problematic.

protected OnConnect(): void {}
protected onConnect(): void {}

protected onDisconnect(reason: number): void {}

protected OnDisconnect(reason: number): void {}
protected onText(text: string): void {}

public sendClientMessage(color: string, msg: string): number {
return SendClientMessage(this, color, msg);
}

/* eslint-enable @typescript-eslint/no-unused-vars */
// ignore class params no used end
Expand Down
18 changes: 5 additions & 13 deletions src/controllers/vehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@ import { OnVehicleDamageStatusUpdate } from "@/wrapper/callbacks";
import { BasePlayer } from "./player";

export class BaseVehicle<T extends BasePlayer> {
constructor() {
private id = -1;
constructor(player: T) {
OnVehicleDamageStatusUpdate((vehicleid: number, playerid: number) => {
this.OnDamageStatusUpdate();
if (playerid === player.id && vehicleid === this.id)
this.onDamageStatusUpdate(player);
});
}
protected OnDamageStatusUpdate(player: T) {}
protected onDamageStatusUpdate(player: T) {}
}

// class CommonPlayer extends BasePlayer {

// }

// class B extends BaseVehicle<CommonPlayer>{
// protected OnDamageStatusUpdate(player: CommonPlayer): void {

// }
// }

0 comments on commit bd85db6

Please sign in to comment.