79f3fdfd-d392-408a-b939-c6915fc58854.js
5.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
"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();