|
1 | 1 | import { Service, type OnInit } from "@flamework/core"; |
2 | | -import { Players } from "@rbxts/services"; |
3 | | -import { endsWith } from "@rbxts/string-utils"; |
4 | 2 |
|
5 | | -import type { OnCharacterAdd } from "shared/hooks"; |
6 | 3 | import { Events } from "server/network"; |
7 | 4 |
|
8 | | -import type { DatabaseService } from "./third-party/database"; |
9 | | - |
10 | 5 | @Service() |
11 | | -export class CharacterService implements OnInit, OnCharacterAdd { |
12 | | - public constructor( |
13 | | - private readonly db: DatabaseService |
14 | | - ) { } |
15 | | - |
| 6 | +export class CharacterService implements OnInit { |
16 | 7 | public onInit(): void { |
17 | 8 | Events.character.toggleDefaultMovement.connect((player, on) => this.toggleDefaultMovement(player, on)); |
18 | | - this.db.updated.Connect((player, directory, value) => { |
19 | | - if (!endsWith(directory, "settings/invincibility")) return; |
20 | | - this.updateInvincibility(player, false, <boolean>value); |
21 | | - }); |
22 | | - } |
23 | | - |
24 | | - public onCharacterAdd(character: CharacterModel): void { |
25 | | - const player = Players.GetPlayerFromCharacter(character)!; |
26 | | - this.updateInvincibility(player); |
27 | | - } |
28 | | - |
29 | | - public updateInvincibility(player: Player, justPurchased = false, settingOverride?: boolean): void { |
30 | | - const humanoid = (player.Character ?? player.CharacterAdded.Wait()[0]).FindFirstChildOfClass("Humanoid"); |
31 | | - if (humanoid === undefined) return; |
32 | | - |
33 | | - const ownsPass = justPurchased || this.db.ownsInvincibilityPass(player); |
34 | | - const enabled = ownsPass && (settingOverride ?? this.db.get<boolean>(player, "settings/invincibility")); |
35 | | - humanoid.Health = enabled ? math.huge : 100; |
36 | | - humanoid.MaxHealth = enabled ? math.huge : 100; |
37 | 9 | } |
38 | 10 |
|
39 | 11 | public toggleDefaultMovement(player: Player, on: boolean): void { |
|
0 commit comments