From 9a32621be37be591e65f3a122917b40fc142d30d Mon Sep 17 00:00:00 2001 From: yucarl77 Date: Mon, 29 Aug 2022 09:44:20 +0800 Subject: [PATCH] feat: player fps getter --- src/controllers/player.ts | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/controllers/player.ts b/src/controllers/player.ts index 3649dc4..ff4a8ff 100644 --- a/src/controllers/player.ts +++ b/src/controllers/player.ts @@ -1,5 +1,9 @@ import { OnPlayerConnect, OnPlayerDisconnect } from "@/wrapper/callbacks"; -import { IsPlayerNPC } from "@/wrapper/functions"; +import { + GetPlayerDrunkLevel, + IsPlayerNPC, + SetPlayerDrunkLevel, +} from "@/wrapper/functions"; interface Settings { locale: string; @@ -10,14 +14,29 @@ export class BasePlayer { public id: number; public name: string = ""; public settings: Settings; + private lastDrunkLevel: number = 0; constructor(id: number, settings: Settings) { this.id = id; this.settings = settings; } - get isNpc() { - return IsPlayerNPC(this.id); + get isNpc(): boolean { + return Boolean(IsPlayerNPC(this.id)); + } + + get fps(): number { + const nowDrunkLevel = GetPlayerDrunkLevel(this.id); + if (nowDrunkLevel < 100) { + SetPlayerDrunkLevel(this.id, 2000); + } else { + if (this.lastDrunkLevel != nowDrunkLevel) { + const currFps = this.lastDrunkLevel - nowDrunkLevel; + this.lastDrunkLevel = nowDrunkLevel; + if (currFps > 0 && currFps < 256) return currFps - 1; + } + } + return 0; } get charset() {