13297d9a-7696-4c46-96e0-0bbebf0919d2.js
17.1 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
"use strict";
cc._RF.push(module, '132972adpZMRpbgC76/CRnS', 'GameModelManager');
// script/game/model/GameModelManager.ts
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GameModelManager = void 0;
const simba_eventkit_1 = require("simba-eventkit");
const simba_utils_1 = require("simba-utils");
const GameRecord_1 = require("../../avg/game-data/GameRecord");
const PlotModel_1 = require("../../avg/model/PlotModel");
const PlotManager_1 = require("../../avg/PlotManager");
const GameConstData_1 = require("../../common/gameplay/gamedata/GameConstData");
const ConfigManager_1 = require("../../common/gameplay/managers/ConfigManager");
const ResUtils_1 = require("../../common/utils/ResUtils");
const BannerRewardsConfig_1 = require("../../config/BannerRewardsConfig");
const ConstConfig_1 = require("../../config/ConstConfig");
const ItemConfig_1 = require("../../config/ItemConfig");
const Role_1 = require("../../config/Role");
const Enums_1 = require("../Enums");
const GameRoleDataModel_1 = require("./GameRoleDataModel");
const MessageSceneModel_1 = require("./MessageSceneModel");
const EditorEvents_1 = require("../../avg/EditorEvents");
const AchievementConfig_1 = require("../../config/AchievementConfig");
const DailyQuestConfig_1 = require("../../config/DailyQuestConfig");
const DatingEventSceneModel_1 = require("./DatingEventSceneModel");
const DateSceneConfig_1 = require("../../config/DateSceneConfig");
const EditorEnums_1 = require("../../avg/EditorEnums");
const GameEnumData_1 = require("../../common/gameplay/gamedata/GameEnumData");
const I18nConfig_1 = require("../../config/I18nConfig");
var GameModelManager;
(function (GameModelManager) {
let emitter = new simba_eventkit_1.Emitter;
GameModelManager.MessageSceneChanged = emitter.createEvent();
GameModelManager.RedPotReduction = emitter.createEvent(); //红点还原
GameModelManager.MainDatingEventChanged = emitter.createEvent();
/**报幕数据准备就绪事件 */
GameModelManager.ForceClickDataReady = emitter.createEvent();
let messageScenes;
let mainDatingScenes;
let currPlots;
let phoneCallIndex = -1;
let unlockGift = false;
function isGiftUnlock() { return unlockGift; }
GameModelManager.isGiftUnlock = isGiftUnlock;
async function rollbackPhoneCallIfNeeded() {
// if (phoneCallIndex < 0) {
// console.error("Error: no phone call.");
// }
if (phoneCallIndex >= 0 && phoneCallIndex < GameRecord_1.GameRecord.getCurrentRecordItems().length - 1) {
let ret = await PlotManager_1.PlotManager.rollbackToIndex(phoneCallIndex);
savePhoneCall();
return ret;
}
else {
return PlotManager_1.PlotManager.getCurrentPlots();
}
}
GameModelManager.rollbackPhoneCallIfNeeded = rollbackPhoneCallIfNeeded;
//#region //数据模块
let roleDatasMap = new Map();
let languagesMap = new Map(); //语言
//#endregion
function getCurrentChapterId() {
return currPlots[0].chapterId;
}
GameModelManager.getCurrentChapterId = getCurrentChapterId;
function getMessageScenesModel() {
return messageScenes;
}
GameModelManager.getMessageScenesModel = getMessageScenesModel;
function getMessageSceneModel(id) {
return messageScenes.find(v => v.id === id);
}
GameModelManager.getMessageSceneModel = getMessageSceneModel;
function getMainDatingEventScenesModel() {
return mainDatingScenes;
}
GameModelManager.getMainDatingEventScenesModel = getMainDatingEventScenesModel;
function getMainDatingEventSceneModel(id) {
return mainDatingScenes.find(v => v.id === id);
}
GameModelManager.getMainDatingEventSceneModel = getMainDatingEventSceneModel;
async function initConfigData() {
await ConfigManager_1.ConfigManager.initConfigData();
initLanguageConfig();
initRoleConfig();
}
function initRoleConfig() {
let cfg = ConfigManager_1.ConfigManager.getAllConfig(Role_1.role);
for (let id in cfg) {
let element = cfg[id];
if (element) {
let data = new GameRoleDataModel_1.default();
data.setConfig(element);
roleDatasMap.set(element.id, data);
}
}
}
function getLanguagePath() {
return "userdata/language/chinese";
}
async function initLanguageConfig() {
let cfgFile = await ResUtils_1.ResUtils.loadRes(getLanguagePath(), cc.JsonAsset);
if (cfgFile) {
let lans = cfgFile;
for (let i = 0; i < lans.length; ++i) {
let element = lans[i];
if (element) {
languagesMap.set(element.id, element.value);
}
}
}
}
function getLanguageTxt(id) {
if (languagesMap.has(id)) {
return languagesMap.get(id);
}
else {
console.log("current language id is miss " + id);
return "";
}
}
GameModelManager.getLanguageTxt = getLanguageTxt;
function getConfigLanguageTxt(id) {
return ConfigManager_1.ConfigManager.getConfig(I18nConfig_1.i18nConfig, id).cn;
}
GameModelManager.getConfigLanguageTxt = getConfigLanguageTxt;
function getConstConfig(id) {
return ConfigManager_1.ConfigManager.getConfig(ConstConfig_1.constConfig, id);
}
GameModelManager.getConstConfig = getConstConfig;
function getItemConfig(id) {
return ConfigManager_1.ConfigManager.getConfig(ItemConfig_1.itemConfig, id);
}
GameModelManager.getItemConfig = getItemConfig;
function getItemConfigs() {
return ConfigManager_1.ConfigManager.getAllConfig(ItemConfig_1.itemConfig);
}
GameModelManager.getItemConfigs = getItemConfigs;
function getBannerRewardsConfigs() {
return ConfigManager_1.ConfigManager.getAllConfig(BannerRewardsConfig_1.bannerRewardsConfig);
}
GameModelManager.getBannerRewardsConfigs = getBannerRewardsConfigs;
function getBannerRewardsConfig(id) {
return ConfigManager_1.ConfigManager.getConfig(BannerRewardsConfig_1.bannerRewardsConfig, id);
}
GameModelManager.getBannerRewardsConfig = getBannerRewardsConfig;
function getDailyQuestConfigs() {
return ConfigManager_1.ConfigManager.getAllConfig(DailyQuestConfig_1.dailyQuestConfig);
}
GameModelManager.getDailyQuestConfigs = getDailyQuestConfigs;
function getDailyQuestConfig(id) {
return ConfigManager_1.ConfigManager.getConfig(DailyQuestConfig_1.dailyQuestConfig, id);
}
GameModelManager.getDailyQuestConfig = getDailyQuestConfig;
function getAchievementConfigs() {
return ConfigManager_1.ConfigManager.getAllConfig(AchievementConfig_1.achievementConfig);
}
GameModelManager.getAchievementConfigs = getAchievementConfigs;
function getAchievementConfig(id) {
return ConfigManager_1.ConfigManager.getConfig(AchievementConfig_1.achievementConfig, id);
}
GameModelManager.getAchievementConfig = getAchievementConfig;
function getRoleData(id) {
return roleDatasMap.get(id);
}
GameModelManager.getRoleData = getRoleData;
function getPlayerData() {
return GameModelManager.getRoleData(GameConstData_1.GameConstData.GAME_CONST_PLAYER_ROLE_VALUE);
}
GameModelManager.getPlayerData = getPlayerData;
let disposable;
async function init() {
disposable = new simba_eventkit_1.CompositeDisposable;
await initConfigData();
phoneCallIndex = GameRecord_1.GameRecord.recordVariables["gm.pci"];
unlockGift = !!GameRecord_1.GameRecord.recordVariables["gm.unlockGift"];
if (phoneCallIndex === undefined)
phoneCallIndex = -1;
let initRet = [];
{ // init message models
let ids = GameRecord_1.GameRecord.recordVariables["gm.ms"];
if (ids !== undefined) {
messageScenes = ids.map((id) => new MessageSceneModel_1.MessageSceneModel(id));
initRet.push(...messageScenes.map((s) => s.initFromRecords()));
}
}
{ // init main dating models
let ids = GameRecord_1.GameRecord.recordVariables["gm.md"];
if (ids !== undefined) {
mainDatingScenes = ids.map((id) => new DatingEventSceneModel_1.DatingEventSceneModel(id));
initRet.push(...mainDatingScenes.map((s) => s.initFromRecords()));
}
}
if (initRet.length) {
await Promise.all(initRet);
}
disposable.add(PlotManager_1.PlotManager.PlotWillStart.on(handlePlotWillStart));
disposable.add(PlotManager_1.PlotManager.PlotsRollbackEvent.on(handlePlotsRollback));
disposable.add(EditorEvents_1.EditorEvents.UNLOCK_GIFT.on(() => {
unlockGift = true;
GameRecord_1.GameRecord.recordVariables["gm.unlockGift"] = 1;
}));
initPlots();
for (let scene of mainDatingScenes) { // 检查主线剧情状态
if (currPlots[0].plotSceneType !== Enums_1.PlotSceneType.DatingEvent ||
(scene.id !== currPlots[0].plotSceneTypeId && scene.status !== DatingEventSceneModel_1.DatingEventStatus.Completed)) {
scene.status = DatingEventSceneModel_1.DatingEventStatus.Completed;
}
}
}
GameModelManager.init = init;
function save() {
let oldValue = GameRecord_1.GameRecord.recordVariables["gm.ms"];
let newValue = messageScenes.map(v => v.id);
if (!simba_utils_1.shallowEqual(oldValue, newValue)) {
GameRecord_1.GameRecord.recordVariables["gm.ms"] = newValue;
}
oldValue = GameRecord_1.GameRecord.recordVariables["gm.md"];
newValue = mainDatingScenes.map(v => v.id);
if (!simba_utils_1.shallowEqual(oldValue, newValue)) {
GameRecord_1.GameRecord.recordVariables["gm.md"] = newValue;
}
}
function savePhoneCall() {
GameRecord_1.GameRecord.recordVariables["gm.pci"] = phoneCallIndex;
GameRecord_1.GameRecord.saveRecord();
}
async function initPlots() {
let plots = PlotManager_1.PlotManager.getCurrentPlots();
if (!currPlots) {
currPlots = [...plots];
if (!messageScenes) { // 第一次进游戏,根据剧情初始化数据
messageScenes = [];
}
if (!mainDatingScenes) {
mainDatingScenes = [];
}
for (let i = 0; i < plots.length; i++) {
let plot = plots[i];
if (plot.plotSceneType === Enums_1.PlotSceneType.Message) {
let index = messageScenes.findIndex(v => v.id === plot.plotSceneTypeId);
if (index < 0) {
index = 0;
let model = new MessageSceneModel_1.MessageSceneModel(plot.plotSceneTypeId);
model.firstPlot = plot;
messageScenes.unshift(model);
}
// if (plot.sentences[0].content && plot.sentences[0].content.type !== SentenceType.SELECT) {
// messageScenes[index].lastPlot = plot;
// }
}
else if (plot.plotSceneType === Enums_1.PlotSceneType.DatingEvent) {
let cfg = ConfigManager_1.ConfigManager.getConfig(DateSceneConfig_1.dateSceneConfig, plot.plotSceneTypeId);
if (cfg.DateType === EditorEnums_1.DateType.Date_Normal) { // 主线约会剧情
if (plots[0] !== plot) {
console.error("主线约会剧情应在主线开启");
continue;
}
if (mainDatingScenes.findIndex(v => v.id === plot.plotSceneTypeId) < 0) {
let model = new DatingEventSceneModel_1.DatingEventSceneModel(plot.plotSceneTypeId);
model.firstPlot = plot;
model.status = DatingEventSceneModel_1.DatingEventStatus.New;
mainDatingScenes.push(model);
}
}
}
}
save();
}
}
async function handlePlotWillStart(plot, branch) {
handleNewPlot(currPlots[branch], plot, branch);
currPlots[branch] = plot;
// for (let i = 0; i < plots.length; i++) {
// if (!currPlots![i] || (currPlots![i].id !== plots[i].id)) {
// handleNewPlot(currPlots![i], plots[i], i);
// currPlots![i] = plots[i];
// }
// }
}
async function handlePlotsRollback(plots) {
messageScenes = undefined;
currPlots = undefined;
disposable.dispose();
await init();
GameRecord_1.GameRecord.startTransaction();
GameRecord_1.GameRecord.endTransaction(true);
}
async function handleNewPlot(prevPlot, plot, branch) {
if (plot.plotSceneType === Enums_1.PlotSceneType.Message) {
let idx = messageScenes.findIndex(v => v.id === plot.plotSceneTypeId);
if (idx >= 0) { // 原会话中有新消息
let model = messageScenes[idx];
if (idx > 0) {
for (let i = idx; i > 0; i--) {
messageScenes[i] = messageScenes[i - 1];
}
messageScenes[0] = model;
}
if (plot.sentences[0].content && plot.sentences[0].content.type !== PlotModel_1.SentenceType.SELECT) {
// model.lastPlot = plot;
}
}
else { // 新会话
let model = new MessageSceneModel_1.MessageSceneModel(plot.plotSceneTypeId);
model.firstPlot = plot;
if (plot.sentences[0].content && plot.sentences[0].content.type !== PlotModel_1.SentenceType.SELECT) {
// model.lastPlot = plot;
}
messageScenes.unshift(model);
}
GameModelManager.MessageSceneChanged.emit(messageScenes);
save();
}
else if (plot.plotSceneType === Enums_1.PlotSceneType.PhoneCall) {
if (!prevPlot || prevPlot.plotSceneType !== Enums_1.PlotSceneType.PhoneCall) {
phoneCallIndex = GameRecord_1.GameRecord.getCurrentRecordItems().length; // 当前存档还没生成,不需要减1
savePhoneCall();
}
}
else if (plot.plotSceneType === Enums_1.PlotSceneType.DatingEvent) {
let cfg = ConfigManager_1.ConfigManager.getConfig(DateSceneConfig_1.dateSceneConfig, plot.plotSceneTypeId);
if (cfg.DateType === EditorEnums_1.DateType.Date_Normal) { // 主线约会剧情
if (branch !== 0) {
console.error("主线约会剧情应在主线开启");
return;
}
let idx = mainDatingScenes.findIndex(v => v.id === plot.plotSceneTypeId);
if (idx < 0) { // 新开启
let model = new DatingEventSceneModel_1.DatingEventSceneModel(plot.plotSceneTypeId);
model.firstPlot = plot;
model.status = DatingEventSceneModel_1.DatingEventStatus.New;
mainDatingScenes.push(model);
GameModelManager.MainDatingEventChanged.emit(mainDatingScenes);
}
save();
}
}
if (prevPlot && prevPlot.plotSceneType === Enums_1.PlotSceneType.PhoneCall && plot.plotSceneType !== Enums_1.PlotSceneType.PhoneCall) {
phoneCallIndex = -1;
savePhoneCall();
}
if (prevPlot && (prevPlot.plotSceneType !== plot.plotSceneType || prevPlot.plotSceneTypeId !== plot.plotSceneTypeId)) { // 切换场景
if (prevPlot.plotSceneType === Enums_1.PlotSceneType.Message) { // 最后一个是选项的情况下,此时已做选择,记录最后一条剧情
// let model = messageScenes!.find(v => v.id === prevPlot.plotSceneTypeId);
// model!.lastPlot = prevPlot;
}
if (prevPlot.plotSceneType === Enums_1.PlotSceneType.DatingEvent) {
let model = mainDatingScenes.find(v => v.id === prevPlot.plotSceneTypeId);
if (model)
model.status = DatingEventSceneModel_1.DatingEventStatus.Completed;
}
}
}
function checkFuncUnloced(key) {
return GameRecord_1.GameRecord.recordVariables[key] === GameEnumData_1.FuncStateEnum.locked ? false : true;
}
GameModelManager.checkFuncUnloced = checkFuncUnloced;
function checkRedPot(key) {
return GameRecord_1.GameRecord.globalVariables["red_pot_" + key] === GameEnumData_1.RedPotStateEnum.Show;
}
GameModelManager.checkRedPot = checkRedPot;
function setRedPotState(key, state) {
GameRecord_1.GameRecord.globalVariables["red_pot_" + key] = state;
GameRecord_1.GameRecord.autoSave();
}
GameModelManager.setRedPotState = setRedPotState;
})(GameModelManager = exports.GameModelManager || (exports.GameModelManager = {}));
cc._RF.pop();