CDKeyEventManager.ts 2.56 KB
import { GameRecord } from "../../avg/AVG";
import { UIManager } from "../../common/gameplay/managers/UIManager";

export default class CDKeyEventManager {
    private CDKeyRemovePlotAD = "CDKeyRemovePlotAD";
    private CDKeyRemovePlotAD_New = "prop_2_1001_num";
    /**单例对象 */
    private static _instance: CDKeyEventManager | undefined;

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

    /**
     * 兑换码去除剧情广告
     */
    cdKeyRemovePlotAD() {
        let cdKeyRemovePlotAd = GameRecord.globalVariables[this.CDKeyRemovePlotAD_New];
        cdKeyRemovePlotAd = cdKeyRemovePlotAd ? cdKeyRemovePlotAd : 0;
        let newCdKeyRemovePlotAd = cdKeyRemovePlotAd + 1
        GameRecord.globalVariables[this.CDKeyRemovePlotAD_New] = newCdKeyRemovePlotAd;
        GameRecord.saveRecord();
        UIManager.showToast("兑换成功,解锁剧情将不再需要观看广告");
    }

    /**
     * 检查是否去除了剧情广告
     */
    checkCDKeyRemovePlotAD(): number {
        let cdKeyRemovePlotAd = 0;
        cdKeyRemovePlotAd = GameRecord.globalVariables[this.CDKeyRemovePlotAD_New];
        cdKeyRemovePlotAd = cdKeyRemovePlotAd ? cdKeyRemovePlotAd : 0;
        return cdKeyRemovePlotAd;
    }

    /**
     * 版本兼容,将旧版的免广告卡存档迁移到新版存档中
     */
    shiftCDKeyRemovePlotAD() {
        let cdKeyRemovePlotAd = GameRecord.globalVariables[this.CDKeyRemovePlotAD];
        if (cdKeyRemovePlotAd && cdKeyRemovePlotAd == "1") {
            GameRecord.globalVariables[this.CDKeyRemovePlotAD_New] = 1;
            GameRecord.globalVariables[this.CDKeyRemovePlotAD] = "0";
            GameRecord.saveRecord();
        }
    }

    /**
     * 根据人物Id改变该人物的好感度
     * @param roleId 人物Id
     * @param like 好感度
     */
    changeRoleLike(roleId: number, like: number) {
        let g = GameRecord.globalVariables["like" + roleId] as number;
        g = g ? g : 0;
        let r = GameRecord.recordVariables["like" + roleId] as number;
        r = r ? r : 0;
        let l = g + r;
        if (l >= 10000) {
            UIManager.showToast("该人物的好感度已满,无法再增加");
            return;
        }
        if (l + like >= 10000) {
            g = 10000 - r;
        } else {
            g += like;
        }
        GameRecord.globalVariables["like" + roleId] = g;
        GameRecord.saveRecord();
    }
}