5180 fichiers 38.5 Mo 0 téléchargements 208 vues mis à jour il y a 5 heures ui
nitro-v36-with-renderer-v36 / src / hooks / navigator / useRoomCreateLimitAlert.ts
useRoomCreateLimitAlert.ts 2 Ko Télécharger le fichier
import { CanCreateRoomEvent } from '@octane/renderer';
import { localizeWithFallback } from '../../api';
import { useMessageEvent } from '../events';
import { useNotification } from '../notification';

export const ROOM_CREATE_ALLOWED = 0;
export const HC_CENTER_LINK = 'habboUI/open/hccenter';

export interface RoomLimitAlert {
    title: string;
    message: string;
    clickUrl: string | null;
    clickUrlText: string | null;
}

/**
 * AIR (navigator IncomingMessages, CanCreateRoom): "${navigator.createroom.limitreached}" with the limit,
 * captioned "${navigator.createroom.error}". A VIP gets a plain alert; everyone else gets AIR's
 * ClubPromoAlertView, whose "${navigator.createroom.vippromo}" link opens Habbo Club.
 */
export const buildRoomLimitAlert = (roomLimit: number, hasVip: boolean): RoomLimitAlert => {
    const limit = String(roomLimit);

    return {
        title: localizeWithFallback('navigator.createroom.error', 'Room creation failed.'),
        message: localizeWithFallback('navigator.createroom.limitreached', `You have reached the limit of ${limit} rooms.`, ['limit'], [limit]),
        clickUrl: hasVip ? null : HC_CENTER_LINK,
        clickUrlText: hasVip ? null : localizeWithFallback('navigator.createroom.vippromo', 'HC members can have even more rooms! >>')
    };
};

/**
 * The server answers a create over the room limit with CanCreateRoom (count >= max) instead of
 * FlatCreated. Show AIR's message and hand the creator its lockout back.
 */
export const useRoomCreateLimitAlert = (hasVip: boolean, onLimitReached: () => void) => {
    const { simpleAlert = null } = useNotification();

    useMessageEvent<CanCreateRoomEvent>(CanCreateRoomEvent, (event) => {
        const parser = event.getParser();

        if (!parser || parser.resultCode === ROOM_CREATE_ALLOWED) return;

        onLimitReached();

        const alert = buildRoomLimitAlert(parser.roomLimit, hasVip);

        simpleAlert?.(alert.message, null, alert.clickUrl, alert.clickUrlText, alert.title);
    });
};
15Sujets
1Dépôts
20Membres
2En ligne
Profile
Inscrit
Dernière visite
Messages
0
Votes positifs
0
Votes négatifs
0

Nous utilisons des cookies pour assurer le bon fonctionnement du site et améliorer votre expérience. en savoir plus

Autoriser