UnlockSpecialPlotEventManager.ts 2.92 KB
import { UIManager } from "../../common/gameplay/managers/UIManager";
import { GameModelManager } from "./GameModelManager";
import { UnlockItemModelManager } from "./UnlockItemModelManager";
import { UnlockSpecialPlotModelManager } from "./UnlockSpecialPlotModelManager";

export default class UnlockSpecialPlotEventManager {
    /**单例对象 */
    private static _instance: UnlockSpecialPlotEventManager | undefined;

    /**创建单例 */
    public static getInstance(): UnlockSpecialPlotEventManager {
        if (!UnlockSpecialPlotEventManager._instance) {
            UnlockSpecialPlotEventManager._instance = new UnlockSpecialPlotEventManager();
        }
        return UnlockSpecialPlotEventManager._instance;
    }

    /**
     * 兑换码解锁番外
     * @param specialPlotId 要解锁的番外Id
     * @param itemId 要解锁的和物品相关的Id,可为空
     */
    cdKeyUnlockSpecialPlot(specialPlotId: number, itemId?: number) {
        UnlockSpecialPlotModelManager.saveUnlockedSpecialPlotIdByItemIdToGameRecord(specialPlotId);
        if (itemId) {
            UnlockItemModelManager.saveItemIdToGameRecord(itemId);
            UnlockItemModelManager.saveUnlockedIntroductionItemIdToGameRecord(itemId);
        }
        UIManager.showToast("兑换成功,请前往卧室查看呦~~");
    }

    /**
     * 次日登陆解锁番外
     * @param specialPlotId 要解锁的番外Id
     */
    nextDayUnlockedSpecialPlot(specialPlotId: number) {
        //检测手表番外2次日是否需要解锁,手表番外2的番外剧情Id是4
        let needUnlock: boolean = false;
        if (!UnlockSpecialPlotModelManager.checkSpecialPlotIdIsUnlocked(specialPlotId)) {
            needUnlock = true;
        }
        //获取第一次登陆的时间
        UnlockSpecialPlotModelManager.saveFirstDayTime();
        let firstDayTime = UnlockSpecialPlotModelManager.getFirstDayTime();
        if (needUnlock && firstDayTime) {
            let canUnlock: boolean = GameModelManager.checkOverdue(firstDayTime);
            if (canUnlock) {
                UnlockSpecialPlotModelManager.saveUnlockedSpecialPlotIdByItemIdToGameRecord(specialPlotId);
                UIManager.showSceneToast("解锁了新的番外,记得去卧室查看哦~");
            }
        }
    }

    isShowBedRoomRedDotStatus(itemId: number): boolean {
        let allSpecialPlotId = UnlockSpecialPlotModelManager.allSpecialPlotIdByItemId(itemId);
        //判断是否有未解锁的番外
        let unlockedSpecialPlotId = UnlockSpecialPlotModelManager.unlockedSpecialPlotIdByItemId(itemId);
        if (unlockedSpecialPlotId.length !== allSpecialPlotId.length) {
            return true;
        }
        //判断是否有未观看的番外
        let clickedSpecialPlotId = UnlockSpecialPlotModelManager.clickedSpecialPlotIdByItemId(itemId);
        if (clickedSpecialPlotId.length !== allSpecialPlotId.length) {
            return true;
        }
        return false;
    }
}