37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { phoneSystem } from '../../../features/phone';
|
|
|
|
type PhoneCommandGuardOptions = {
|
|
on?: boolean;
|
|
unlocked?: boolean;
|
|
};
|
|
|
|
export const PhoneCommandGuard = (options?: PhoneCommandGuardOptions): CommandGuard => {
|
|
return (player: PlayerMp) => {
|
|
if (!options) {
|
|
return true;
|
|
}
|
|
|
|
if (!player.character?.phone || !player.character.phone.item) {
|
|
return `You must have a phone.`;
|
|
}
|
|
|
|
if (options.on !== undefined) {
|
|
if (options.on === true && !phoneSystem.isPhoneOn(player.character.phone.item)) {
|
|
return `Your phone must be turned on.`;
|
|
} else if (options.on === false && phoneSystem.isPhoneOn(player.character.phone.item)) {
|
|
return `Your phone must be turned off.`;
|
|
}
|
|
}
|
|
|
|
if (options.unlocked !== undefined) {
|
|
if (options.unlocked === true && !phoneSystem.isPlayerPhoneLocked(player as PlayerMpLoggedIn)) {
|
|
return `Your phone must be locked.`;
|
|
} else if (options.unlocked === false && phoneSystem.isPlayerPhoneLocked(player as PlayerMpLoggedIn)) {
|
|
return `Your phone must be unlocked.`;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
};
|
|
};
|