79f3fdfd-d392-408a-b939-c6915fc58854.js 5.35 KB
"use strict";
cc._RF.push(module, '79f3f3905JAirk5xpFfxYhU', 'ExtraStoryModelManager');
// script/game/model/ExtraStoryModelManager.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExtraStoryModelManager = void 0;
const AVG_1 = require("../../avg/AVG");
const DatingEventSceneModel_1 = require("./DatingEventSceneModel");
const GameModelManager_1 = require("./GameModelManager");
/**
 * 番外剧情管理类
 */
class ExtraStoryModelManager1 {
    constructor() {
        /**是否正在创建 */
        this.creating = false;
        /**是否在番外中 */
        this._isInExtraStoryScene = false;
    }
    get isInExtraStoryScene() {
        return this._isInExtraStoryScene;
    }
    /**开启分支剧情,
    * plots:如果需要同时开启多个分支剧情,则数组中存储这些分支中对应的起始剧情id
    */
    async startBranches(plots, callback) {
        if (this.creating)
            return;
        this.creating = true;
        if (!plots.length) {
            console.warn("no plots to mark as branch start plot id");
            return;
        }
        for (let i = 0; i < plots.length; i++) {
            let pid = plots[i];
            if (AVG_1.SpecialPlotId.ToBeContinued === pid || AVG_1.SpecialPlotId.End === pid) {
                console.error("you can not start a branch with SpecialPlotId, id is = ", pid);
                continue;
            }
            let p = await AVG_1.getPlot(pid);
            if (!p) {
                console.warn("no plot which plot id is = ", pid);
            }
            let itemArrIndex = this.checkIsBranchStarted(pid);
            let recordsLength = AVG_1.GameRecord.getRecords().length;
            let index = recordsLength;
            if (itemArrIndex != -1) {
                index = this.itemArr[itemArrIndex].index;
            }
            await AVG_1.PlotManager.startGameWithRecordIndex(index, pid);
            this._isInExtraStoryScene = true;
            this.pushBranchToRecord(pid, index);
            callback && callback(i, pid);
            console.log("getCurrentPlots: ", AVG_1.PlotManager.getCurrentPlots());
        }
        this.creating = false;
    }
    /**
    *
    * @param plotId 检测指定剧情下的分支是否已经开启
    * @returns
    */
    checkIsBranchStarted(plotId) {
        const branchRecordKey = "BRANCH_INDEX_ENTRY";
        let ret = -1;
        let itemArr = [];
        let recordStr = AVG_1.GameRecord.globalVariables[branchRecordKey];
        if (recordStr && "" !== recordStr.trim()) {
            itemArr = JSON.parse(recordStr);
        }
        ret = itemArr.findIndex((v) => v.startPlot === plotId);
        this.itemArr = itemArr;
        return ret;
    }
    /**
     *
     * @param plotId 将分支计入存档
     * @param index
     */
    pushBranchToRecord(plotId, index) {
        const branchRecordKey = "BRANCH_INDEX_ENTRY";
        let exist = false;
        let itemArr = [];
        let recordStr = AVG_1.GameRecord.globalVariables[branchRecordKey];
        if (recordStr && "" !== recordStr.trim()) {
            itemArr = JSON.parse(recordStr);
        }
        exist = itemArr.findIndex((v) => v.startPlot === plotId) >= 0;
        if (!exist) {
            itemArr.push({
                startPlot: plotId,
                index: index
            });
            AVG_1.GameRecord.globalVariables[branchRecordKey] = JSON.stringify(itemArr);
            AVG_1.GameRecord.saveRecord();
        }
        this.itemArr = itemArr;
    }
    /**
     * 获取分支剧情状态(约会状态)
     * @param plotSceneTypeId 剧情类型(DateSceneConfig的id)id
     * @param start_plot_id 起始剧情id
     * @returns 剧情状态
     */
    getBranchStatus(plotSceneTypeId, start_plot_id) {
        let s = DatingEventSceneModel_1.DatingEventStatus.New;
        let curPs = AVG_1.PlotManager.getCurrentPlots();
        let curP = curPs[0];
        let progress = curP.plotSceneTypeId === plotSceneTypeId && (curP.id != AVG_1.SpecialPlotId.ToBeContinued && curP.id != AVG_1.SpecialPlotId.End);
        let isNew = curP.plotSceneTypeId === plotSceneTypeId && curP.id === start_plot_id;
        s = isNew ? DatingEventSceneModel_1.DatingEventStatus.New : progress ? DatingEventSceneModel_1.DatingEventStatus.InProgress : DatingEventSceneModel_1.DatingEventStatus.Completed;
        console.log('当前剧情状态', s);
        return s;
    }
    /**
     * 进入番外
     * @param startPlotId 开始剧情id
     */
    async enterExtraStoryByStartPlotId(startPlotId) {
        let index = this.checkIsBranchStarted(startPlotId);
        if (index >= 0) {
            await AVG_1.PlotManager.startGameWithRecordIndex(this.itemArr[index].index, startPlotId);
            this._isInExtraStoryScene = true;
            GameModelManager_1.GameModelManager.currPlots = [...AVG_1.PlotManager.getCurrentPlots()];
        }
        else {
            console.error('番外分支没有开启请先开启调用:startBranches');
        }
    }
    /**
     * 退出番外
     */
    async exitExtraStory() {
        let firstPlot = AVG_1.getPlotsIndex().firstPlot;
        await AVG_1.PlotManager.startGameWithRecordIndex(0, firstPlot);
        GameModelManager_1.GameModelManager.currPlots = [...AVG_1.PlotManager.getCurrentPlots()];
        this._isInExtraStoryScene = false;
    }
}
exports.ExtraStoryModelManager = new ExtraStoryModelManager1();

cc._RF.pop();