9f42ba43-18bb-4b35-8e2b-e3268c38dfe7.js 6.86 KB
"use strict";
cc._RF.push(module, '9f42bpDGLtLNY4r4yaMON/n', 'UnlockItemModelManager');
// script/game/model/UnlockItemModelManager.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UnlockItemModelManager = void 0;
const simba_config_manager_1 = require("simba-config-manager");
const AVG_1 = require("../../avg/AVG");
const ItemTbl_1 = require("../../config/ItemTbl");
class UnlockItemModelManager1 {
    constructor() {
        /**存档Key */
        this.UnlockItems = 'UnlockItems';
        /**存档Key */
        this.ClickedItems = 'ClickedItems';
        /**存档Key */
        this.UnlockedIntroductionItems = 'UnlockedIntroductionItems';
        /**解锁的物品ids */
        this.items = [];
        /**点击过的物品ids */
        this.clickedItem = [];
        /**已经解锁简介的物品ids */
        this.unlockedIntroductionItem = [];
        /**配置掉落物品的剧情id和午评id的映射表 */
        this._unlockPlotIds = [];
    }
    /**获取配置掉落物品的剧情id和午评id的映射表 */
    get unlockPlotIds() {
        if (this._unlockPlotIds.length == 0)
            this.analysisItemCfg();
        return this._unlockPlotIds;
    }
    get unlockItems() {
        let items = [];
        let itemsStr = AVG_1.GameRecord.globalVariables[this.UnlockItems];
        if (itemsStr) {
            let itemsIdStr = itemsStr.split(',');
            itemsIdStr.forEach(id => {
                try {
                    items.push(Number(id));
                }
                catch (error) {
                    console.error(error);
                }
            });
        }
        return items;
    }
    get clickedItems() {
        this.clickedItem = [];
        let itemsStr = AVG_1.GameRecord.globalVariables[this.ClickedItems];
        if (itemsStr) {
            let itemsIdStr = itemsStr.split(',');
            itemsIdStr.forEach(id => {
                try {
                    this.clickedItem.push(Number(id));
                }
                catch (error) {
                    console.error(error);
                }
            });
        }
        return this.clickedItem;
    }
    get unlockedIntroductionItems() {
        this.unlockedIntroductionItem = [];
        let itemsStr = AVG_1.GameRecord.globalVariables[this.UnlockedIntroductionItems];
        if (itemsStr) {
            let itemsIdStr = itemsStr.split(',');
            itemsIdStr.forEach(id => {
                try {
                    this.unlockedIntroductionItem.push(Number(id));
                }
                catch (error) {
                    console.error(error);
                }
            });
        }
        return this.unlockedIntroductionItem;
    }
    /**
     * 保存解锁了简介的物品id到存档
     * @param id 点击过的物品id
     */
    saveUnlockedIntroductionItemIdToGameRecord(id) {
        this.unlockedIntroductionItem = [];
        let itemsStr = AVG_1.GameRecord.globalVariables[this.UnlockedIntroductionItems];
        if (itemsStr) {
            let itemsIdStr = itemsStr.split(',');
            itemsIdStr.forEach(id => {
                try {
                    this.unlockedIntroductionItem.push(Number(id));
                }
                catch (error) {
                    console.error(error);
                }
            });
        }
        if (this.unlockedIntroductionItem.indexOf(id) == -1) {
            this.unlockedIntroductionItem.push(id);
            AVG_1.GameRecord.globalVariables[this.UnlockedIntroductionItems] = this.unlockedIntroductionItem.toString();
            AVG_1.GameRecord.saveRecord();
            return true;
        }
        return false;
    }
    /**
     * 保存点击过的物品id到存档
     * @param id 点击过的物品id
     */
    saveClickedItemIdToGameRecord(id) {
        this.clickedItem = [];
        let itemsStr = AVG_1.GameRecord.globalVariables[this.ClickedItems];
        if (itemsStr) {
            let itemsIdStr = itemsStr.split(',');
            itemsIdStr.forEach(id => {
                try {
                    this.clickedItem.push(Number(id));
                }
                catch (error) {
                    console.error(error);
                }
            });
        }
        if (this.clickedItem.indexOf(id) == -1) {
            this.clickedItem.push(id);
            AVG_1.GameRecord.globalVariables[this.ClickedItems] = this.clickedItem.toString();
            AVG_1.GameRecord.saveRecord();
            return true;
        }
        return false;
    }
    /**
     * 保存解锁的物品id到存档
     * @param id 解锁的物品id
     */
    saveItemIdToGameRecord(id) {
        this.items = [];
        let itemsStr = AVG_1.GameRecord.globalVariables[this.UnlockItems];
        if (itemsStr) {
            let itemsIdStr = itemsStr.split(',');
            itemsIdStr.forEach(id => {
                try {
                    this.items.push(Number(id));
                }
                catch (error) {
                    console.error(error);
                }
            });
        }
        if (this.items.indexOf(id) == -1) {
            this.items.push(id);
            AVG_1.GameRecord.globalVariables[this.UnlockItems] = this.items.toString();
            // GameRecord.autoSave();
            return true;
        }
        return false;
    }
    /**
     * 登录初始化已经解锁的items
     */
    loginInitUnlockItems() {
        //获取已经存在的items
        this.items = [];
        let itemsStr = AVG_1.GameRecord.globalVariables[this.UnlockItems];
        if (itemsStr) {
            let itemsIdStr = itemsStr.split(',');
            itemsIdStr.forEach(id => {
                try {
                    this.items.push(Number(id));
                }
                catch (error) {
                    console.error(error);
                }
            });
        }
        //当前剧情应该解锁的所有物品
        let itemcfg = this.unlockPlotIds;
        //获取当前的剧情id
        let record = AVG_1.GameRecord.getPlotsInfo();
        for (let i = 0; i < itemcfg.length; i++) {
            let ele = itemcfg[i];
            if (ele) {
                if (record[`${ele.plotId}`] && record[`${ele.plotId}`].cnt >= 1) {
                    if (this.items.indexOf(ele.itemId) == -1) {
                        this.items.push(ele.itemId);
                    }
                }
            }
        }
        AVG_1.GameRecord.globalVariables[this.UnlockItems] = this.items.toString();
        // GameRecord.autoSave();
    }
    /**
     * 解析item表结果
     */
    analysisItemCfg() {
        let ret = [];
        let cfg = simba_config_manager_1.ConfigManager.getAllConfig(ItemTbl_1.itemTbl);
        for (let id in cfg) {
            ret.push({ itemId: Number(id), plotId: cfg[id].plot });
        }
        this._unlockPlotIds = ret;
    }
}
exports.UnlockItemModelManager = new UnlockItemModelManager1();

cc._RF.pop();