GameModelManager.ts
77.9 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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
import { AudioManager } from "simba-cc-audio-manager";
import { ResUtils } from "simba-cc-resutils";
import { ConfigManager } from "simba-config-manager";
import { CompositeDisposable, Emitter } from "simba-eventkit";
import { TimeManager } from "simba-sdk";
import { DeepReadonlyObject, shallowEqual } from "simba-utils";
import { ConditionExpression, GameRecord, getPlot, Language, PlotManager, ReadonlyPlot, ReadonlyPlots, richNodesToCocosString, SentenceType, SpecialPlotId } from "../../avg/AVG";
import { DateType, PageIndex } from "../../avg/EditorEnums";
import { EditorEvents } from "../../avg/EditorEvents";
import { GameConstData } from "../../common/gameplay/gamedata/GameConstData";
import { FuncStateEnum, RedPotStateEnum } from "../../common/gameplay/gamedata/GameEnumData";
import { bedroomItemConfig } from "../../config/BedroomItemConfig";
import { ICharacterVoiceConfig } from "../../config/CharacterVoiceConfig";
import { dateSceneConfig } from "../../config/DateSceneConfig";
import { i18nConfig } from "../../config/I18nConfig";
import { itemConfig } from "../../config/ItemConfig";
import { IItemTbl } from "../../config/ItemTbl";
import { relationLevelConfig } from "../../config/RelationLevelConfig";
import { IRole, role } from "../../config/Role";
import { taoBaoShopUrlConfig } from "../../config/TaoBaoShopUrlConfig";
import { channel } from "../../GameConfig";
import { AutoPopViewType, DiscoverItemType, FreeState, GuideState, PlotSceneType, PlotSessionState, TutorialState, TutorialType, WorkSpaceTaskState } from "../Enums";
import GameDotMgr from "../GameDotMgr";
import { SpecialToastType } from "../ui/SpecialToast";
import { DatingEventSceneModel, DatingEventStatus } from "./DatingEventSceneModel";
import GameRoleDataModel from "./GameRoleDataModel";
import { MessageSceneModel } from "./MessageSceneModel";
import { UnlockSpecialPlotModelManager } from "./UnlockSpecialPlotModelManager";
/**
* 游戏model管理类
*/
export namespace GameModelManager {
let emitter = new Emitter;
export const MessageSceneChanged = emitter.createEvent<(scenes: MessageSceneModel[]) => void>();
export const MainDatingEventChanged = emitter.createEvent<(scenes: DatingEventSceneModel[]) => void>();
export const ApplicaitonGameChanged = emitter.createEvent<(force: boolean) => void>();//进程发生切换
export const MainTabForceClick = emitter.createEvent<(param: { index: number, pureClick: boolean, propId?: number }) => void>();//主界面tab点击
export const GiftItemForceClick = emitter.createEvent<(param: any) => void>();//商城界面指定item点击
export const SininItemClick = emitter.createEvent<(param: any) => void>();//签到界面指定item点击
export const CheckMainTabGuide = emitter.createEvent<() => void>();//主界面检测tab栏引导
export const CheckDateGuide = emitter.createEvent<() => void>();//约会界面检测引导
export const CheckMsgGuide = emitter.createEvent<() => void>();//消息列表界面检测引导
export const UpdatePlayerData = emitter.createEvent<() => void>();//更新主角数据
export const PlayerOptionSkin = emitter.createEvent<() => void>();//玩家操作了皮肤数据
export const NeedAddCoin = emitter.createEvent<(location?: string) => void>();//需要增加金币或者皮肤币
export const RefreshDiscoverTabRed = emitter.createEvent<() => void>();//刷新发现页红点展示
export const RefreshDateCostTipInfo = emitter.createEvent<(show: boolean, costNum?: number, pos?: cc.Vec3) => void>();//刷新约会界面消耗信息节点数据
export const RefreshDateSceneProgress = emitter.createEvent<() => void>();//刷新约会进度
export const CheckDateSceneProgress = emitter.createEvent<() => void>();//检测约会进度
export const ForceClickSendGiftBtn = emitter.createEvent<() => void>();//强制点击聊天中送礼按钮
export const AutoPopView = emitter.createEvent<(view: AutoPopViewType) => void>();//展示自动弹出界面
export const NewPlayerReceiveBtn = emitter.createEvent<() => void>();//新人七天乐点击领取按钮
export const ShowDatingEventArrowGuide = emitter.createEvent<(isShow: boolean, wordPos?: cc.Vec3) => void>();//约会列表界面展示箭头
export const ShowPlotBlocked = emitter.createEvent<() => void>();//展示剧情阻断弹窗
export const ForceEnterDiscoverSubView = emitter.createEvent<(itemType: DiscoverItemType) => void>();//强制进入发现页面子页面
export const PlotBlockedChanged = emitter.createEvent<() => void>();//剧情阻断改变
export const WorkSpaceShowItemDesc = emitter.createEvent<(isShow: boolean, itemId?: number, wPos?: cc.Vec3) => void>();//工作区界面展示物品描述
export const WorkSpaceSelectedStuff = emitter.createEvent<(spaceId: number, roleId: number) => void>();//工作区选定完员工
export const CheckMainTabWorkSpaceRedDot = emitter.createEvent<(isForce?: boolean, forceShow?: boolean) => void>();//检测主界面tab栏下面工作区的红点
export const ForceSetSpaceState = emitter.createEvent<(spaceId: number, state: WorkSpaceTaskState) => void>();//强制改变指定工作区的状态
export const UpdateMainTabArrowGuide = emitter.createEvent<() => void>();//更新主界面tab栏,商城和办公区箭头引导
export const ForceClickMsgItem = emitter.createEvent<(id: number) => void>();
export const ForceClickDatingItem = emitter.createEvent<(id: number) => void>();
/**报幕数据准备就绪事件 */
export const ForceClickDataReady = emitter.createEvent<() => void>();
/**传输掉落物品数据 */
export const TransmitItemData = emitter.createEvent<(pid: number, spriteFrame: cc.SpriteFrame, cfg: DeepReadonlyObject<IItemTbl>) => void>();
export const UnlockItem = emitter.createEvent<(itemId: number) => void>();
/**卧室返回点击UI事件 */
export const BedroomViewBack = emitter.createEvent<(index: number) => void>();
/**返回到卧室界面 */
export const BackToBedRoom = emitter.createEvent<() => void>();
/**回滚数据到指定剧情 */
export const RollBackToPlot = emitter.createEvent<(pid: number) => void>();
/**回滚剧情数据完成刷新所有状态 */
export const RefreshAllStatus = emitter.createEvent<() => void>();
/**触发死亡选项之后的事件派发 */
export const DeadEvent = emitter.createEvent<(pid: number) => void>();
/**关闭约会界面 */
export const CloseDatingSceneView = emitter.createEvent<(id: number) => void>();
/**刷新对应类型的番外 */
export const RefreshExtraPlotByType = emitter.createEvent<(id: number) => void>();
/**关闭番外界面 */
export const CloseExtraSceneView = emitter.createEvent<() => void>();
/**触发剧情属性值变化之后弹起特殊Toast */
export const SpecialToast = emitter.createEvent<(type: SpecialToastType) => void>();
/**从主界面跳转到游戏页面 */
export const JumpToViewInGame = emitter.createEvent<(index: PageIndex) => void>();
/**打开番外界面 */
export const OpenExtraPlotView = emitter.createEvent<() => void>();
/**关闭设置界面 */
export const CloseSettingView = emitter.createEvent<(index: PageIndex) => void>();
let messageScenes: MessageSceneModel[] | undefined;
// let momentScenes: MomentSceneModel[] | undefined;
let mainDatingScenes: DatingEventSceneModel[] | undefined;
export let currPlots: ReadonlyPlot[] | undefined;
let phoneCallIndex: number = -1;
let unlockGift = false;
let defaultUnlockedGiftArr: number[] = [];
let plotUnlockedGiftArr: number[] = [];
let isChangPlotSceneType: boolean = false;
let isMainPlot: boolean = true;
let isNeedEnterCurDateChapter: boolean = true;
let progressSceneId: number | undefined = undefined;
let _autoPopView: AutoPopViewType[] = [];
let _timeTick: number = -1;
let _emap: Map<number, number> = new Map();
let _eLevelMax: number = 0;
let _expUpRole: number = -1;
export function isChangePlotSceneType() { return isChangPlotSceneType }
export function setIsChangePlotSceneType(isChange: boolean) {
isChangPlotSceneType = isChange;
}
export function isMainPlotSceneType() { return isMainPlot }
export function setIsMainPlotSceneType(isChange: boolean) {
isMainPlot = isChange;
}
export function isGiftUnlock() { return unlockGift; }
export async function rollbackPhoneCallIfNeeded() {
// if (phoneCallIndex < 0) {
// console.error("Error: no phone call.");
// }
if (phoneCallIndex >= 0 && phoneCallIndex < GameRecord.getCurrentRecordItems().length - 1) {
let ret = await PlotManager.rollbackToIndex(phoneCallIndex);
savePhoneCall();
return ret;
} else {
return PlotManager.getCurrentPlots();
}
}
//#region //数据模块
let roleDatasMap: Map<number, GameRoleDataModel> = new Map<number, GameRoleDataModel>();
let languagesMap: Map<number, string> = new Map<number, string>(); //语言
//#endregion
export function getCurrentChapterId() {
return currPlots![0].chapterId;
}
export function getMessageScenesModel() {
return messageScenes!;
}
export function getMessageSceneModel(id: number) {
return messageScenes!.find(v => v.id === id);
}
// export function getMomentScenesModel() {
// return momentScenes!;
// }
// export function getMomentSceneModel(id: number) {
// return momentScenes!.find(v => v.id === id);
// }
export function getMainDatingEventScenesModel() {
return mainDatingScenes!;
}
export function getMainDatingEventSceneModel(id: number) {
return mainDatingScenes!.find(v => v.id === id);
}
export function getMainDatingEventScenesModelByChapterindex(chapterIndex: number): DatingEventSceneModel[] {
let scenes: DatingEventSceneModel[] = [];
if (!mainDatingScenes) {
return [];
}
for (let i = 0; i < mainDatingScenes.length; i++) {
if (ConfigManager.getConfig(dateSceneConfig, mainDatingScenes[i].id).chapter_index === chapterIndex) {
scenes.push(mainDatingScenes[i]);
}
}
return scenes;
}
let creating: boolean = false;
/**开启分支剧情,
* plots:如果需要同时开启多个分支剧情,则数组中存储这些分支中对应的起始剧情id
*/
export async function startBranches(plots: number[]) {
if (creating) return;
creating = true;
if (0 === 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 (SpecialPlotId.ToBeContinued === pid || SpecialPlotId.End === pid) {
// console.error("you can not start a branch with SpecialPlotId, id is = ", pid);
continue;
}
let p = await getPlot(pid);
if (!p) {
// console.warn("no plot which plot id is = ", pid);
continue;
}
if (currPlots) {
currPlots.push(p);
}
let hasStarted: boolean = checkIsBranchStarted(pid);
if (hasStarted) {
// cc.warn("branch has been started which start plot id is = ", pid);
continue;
}
console.log('开启新分支pid', pid);
let index = await PlotManager.startNewPlotBranch(pid);
pushBranchToRecord(pid, index);
}
creating = false;
}
/**
*
* @param plotId 检测指定剧情下的分支是否已经开启
* @returns
*/
function checkIsBranchStarted(plotId: number): boolean {
const branchRecordKey: string = "BRANCH_INDEX_ENTRY";
let ret: boolean = false;
let itemArr: { startPlot: number, index: number }[] = [];
let recordStr: string = GameRecord.globalVariables[branchRecordKey] as string;
if (recordStr && "" !== recordStr.trim()) {
itemArr = JSON.parse(recordStr) as { startPlot: number, index: number }[];
}
ret = itemArr.findIndex((v) => v.startPlot === plotId) >= 0;
return ret;
}
/**
*
* @param plotId 将分支计入存档
* @param index
*/
function pushBranchToRecord(plotId: number, index: number) {
const branchRecordKey: string = "BRANCH_INDEX_ENTRY";
let exist: boolean = false;
let itemArr: { startPlot: number, index: number }[] = [];
let recordStr: string = GameRecord.globalVariables[branchRecordKey] as string;
if (recordStr && "" !== recordStr.trim()) {
itemArr = JSON.parse(recordStr) as { startPlot: number, index: number }[];
}
exist = itemArr.findIndex((v) => v.startPlot === plotId) >= 0;
if (!exist) {
itemArr.push({
startPlot: plotId,
index: index
});
GameRecord.globalVariables[branchRecordKey] = JSON.stringify(itemArr);
GameRecord.saveRecord();
}
}
/**
* 获取分支剧情状态(约会状态)
* @param plotSceneTypeId 剧情类型id
* @param start_plot_id 起始剧情id
* @returns 剧情状态
*/
export function getBranchStatus(plotSceneTypeId: number, start_plot_id: number): DatingEventStatus {
let s = DatingEventStatus.New;
let curP = PlotManager.getCurrentPlots();
let progress = curP.findIndex((v) => v.plotSceneTypeId === plotSceneTypeId) >= 0;
let isNew = curP.findIndex((v) => v.plotSceneTypeId === plotSceneTypeId && v.id === start_plot_id) >= 0;
s = isNew ? DatingEventStatus.New : progress ? DatingEventStatus.InProgress : DatingEventStatus.Completed;
return s;
}
/**获取已开启的所有番外id */
export function getAllStartedBranches(): { startPlot: number, index: number }[] {
const branchRecordKey: string = "BRANCH_INDEX_ENTRY";
let itemArr: { startPlot: number, index: number }[] = [];
let recordStr: string = GameRecord.globalVariables[branchRecordKey] as string;
if (recordStr && "" !== recordStr.trim()) {
itemArr = JSON.parse(recordStr) as { startPlot: number, index: number }[];
}
return itemArr;
}
let branchCompleteRecordKey: string = "branch_complete";
/**设置分支完成 */
export function setBranchComplete(branchId: number) {
let rStr = GameRecord.globalVariables[branchCompleteRecordKey] as string;
let rArr: number[] = [];
if (rStr && "" !== rStr) {
rArr = JSON.parse(rStr) as number[];
}
let exist = rArr.findIndex((v) => v === branchId) !== (-1);
if (!exist) {
rArr.push(branchId);
GameRecord.globalVariables[branchCompleteRecordKey] = JSON.stringify(rArr);
GameRecord.saveRecord();
}
}
/**检测分支是否完成 */
export function checkBranchIsComplete(branchId: number): boolean {
let rStr = GameRecord.globalVariables[branchCompleteRecordKey] as string;
let rArr: number[] = [];
if (rStr && "" !== rStr) {
rArr = JSON.parse(rStr) as number[];
}
let exist = rArr.findIndex((v) => v === branchId) !== (-1);
return exist;
}
let branchInProgressRecordKey: string = "branch_InProgress";
/**设置分支完成 */
export function setBranchInProgress(branchId: number) {
let rStr = GameRecord.globalVariables[branchInProgressRecordKey] as string;
let rArr: number[] = [];
if (rStr && "" !== rStr) {
rArr = JSON.parse(rStr) as number[];
}
let exist = rArr.findIndex((v) => v === branchId) !== (-1);
if (!exist) {
rArr.push(branchId);
GameRecord.globalVariables[branchInProgressRecordKey] = JSON.stringify(rArr);
GameRecord.saveRecord();
}
}
/**检测分支是否完成 */
export function checkBranchIsInProgress(branchId: number): boolean {
let rStr = GameRecord.globalVariables[branchInProgressRecordKey] as string;
let rArr: number[] = [];
if (rStr && "" !== rStr) {
rArr = JSON.parse(rStr) as number[];
}
let exist = rArr.findIndex((v) => v === branchId) !== (-1);
return exist;
}
export interface EventResourcesState {
eventId: number,
bgm: string,
backgroud: string
}
export function setEventResources(eventId: number, bgm: string, backgroud: string) {
let eventResources = GameRecord.globalVariables["EventResources"] as EventResourcesState[];
eventResources = eventResources ? eventResources : [];
let isNewEventId = true;
for (let i = 0; i < eventResources.length; i++) {
if (eventResources[i].eventId == eventId) {
if (bgm) {
eventResources[i].bgm = bgm;
}
if (backgroud) {
eventResources[i].backgroud = backgroud;
}
isNewEventId = false;
break;
}
}
if (isNewEventId) {
eventResources.push({
eventId: eventId,
bgm: bgm,
backgroud: backgroud
});
}
}
export function getBranchResources(eventId: number): EventResourcesState {
let eventResources: EventResourcesState = undefined as unknown as EventResourcesState;
let allEventResources = GameRecord.globalVariables["EventResources"] as EventResourcesState[];
if (allEventResources) {
for (let i = 0; i < allEventResources.length; i++) {
if (allEventResources[i].eventId == eventId) {
eventResources = allEventResources[i];
break;
} else {
eventResources = undefined as unknown as EventResourcesState;
}
}
}
return eventResources;
}
async function initConfigData() {
await ConfigManager.initConfigData(false);
await initLanguageConfig();
initRoleConfig();
}
export function getI18LanguageTxt(id: number) {
let i18 = ConfigManager.getConfig(i18nConfig, id);
return i18.cn;
}
function initRoleConfig() {
let cfg = ConfigManager.getAllConfig(role);
for (let id in cfg) {
let element = cfg[id] as IRole;
if (element) {
let data = new GameRoleDataModel();
data.setConfig(element);
roleDatasMap.set(element.id, data);
}
}
}
function getLanguagePath() {
return "userdata/language/chinese"
}
async function initLanguageConfig() {
let cfgFile = await ResUtils.loadRes<any>(getLanguagePath(), cc.JsonAsset);
if (cfgFile) {
let lans: Language[] = cfgFile as Language[];
for (let i = 0; i < lans.length; ++i) {
let element = lans[i] as Language;
if (element) {
languagesMap.set(element.id, element.value);
}
}
}
}
export function getLanguageTxt(id: number): string {
if (languagesMap.has(id)) {
return languagesMap.get(id) as string;
} else {
// console.log("current language id is miss " + id);
return "";
}
}
export function getConfigLanguageTxt(id: number): string {
return ConfigManager.getConfig(i18nConfig, id).cn;
}
export function getItemConfig(id: number) {
return ConfigManager.getConfig(itemConfig, id);
}
export function getItemConfigs() {
return ConfigManager.getAllConfig(itemConfig);
}
// export function getDailyQuestConfigs() {
// return ConfigManager.getAllConfig(dailyQuestConfig)
// }
// export function getDailyQuestConfig(id: number) {
// return ConfigManager.getConfig(dailyQuestConfig, id);
// }
// export function getAchievementConfigs() {
// return ConfigManager.getAllConfig(achievementConfig)
// }
// export function getAchievementConfig(id: number) {
// return ConfigManager.getConfig(achievementConfig, id);
// }
export function getRoleData(id: number) {
if (!roleDatasMap.has(id)) {
return undefined;
}
return roleDatasMap.get(id);
}
export function getPlayerData() {
return GameModelManager.getRoleData(GameConstData.GAME_CONST_PLAYER_ROLE_VALUE)!;
}
// export function addDailyTasks(dailyType: DailyQuestType, count: number) {//每日任务的信息存储
// let dailyCount = GameRecord.globalVariables["DailyQuestType_" + dailyType];
// dailyCount = dailyCount === undefined ? 0 : dailyCount;
// dailyCount += count;
// dispatchCompleteTask(dailyType, dailyCount);
// GameRecord.globalVariables["DailyQuestType_" + dailyType] = dailyCount;
// GameRecord.autoSave();
// }
// function dispatchCompleteTask(dailyType: DailyQuestType, count: number) {
// let cfg = ConfigManager.getConfig(dailyQuestConfig, dailyType);
// let isFinish = count >= cfg.daily_quest_finish_value;
// if (isFinish) {
// GameDotMgr.getInstance().dotTask(TaskDotType.CompleteTask, dailyType);
// }
// }
// export function clearDailyTasks() {//清理每日任务
// for (let index = DailyQuestType.Dq_AdsWatch; index <= DailyQuestType.Dq_MomentPraise; ++index) {
// GameRecord.globalVariables["DailyQuestType_" + index] = 0;
// }
// GameRecord.autoSave();
// }
// export function getDailyTasks(dailyType: DailyQuestType) {
// let dailyCount = GameRecord.globalVariables["DailyQuestType_" + dailyType];
// dailyCount = dailyCount === undefined ? 0 : dailyCount;
// return dailyCount;
// }
let disposable: CompositeDisposable;
export async function init(onProgress?: Function) {
await initConfigData();
if (onProgress) onProgress(0.92);
tipAddGracePlots = [];
phoneCallIndex = GameRecord.recordVariables["gm.pci"] as number;
unlockGift = !!GameRecord.recordVariables["gm.unlockGift"];
if (phoneCallIndex === undefined) phoneCallIndex = -1;
let initRet: Promise<any>[] = [];
{ // init message models
let ids = GameRecord.recordVariables["gm.ms"] as any;
if (ids !== undefined) {
messageScenes = [];
messageScenes = ids.map((id: number) => new MessageSceneModel(id));
initRet.push(...messageScenes!.map((s) => s.initFromRecords()));
} else {
messageScenes = [];
}
}
// { // init moment models
// let ids = GameRecord.recordVariables["gm.mm"] as any;
// if (ids !== undefined) {
// momentScenes = ids.map((id: number) => new MomentSceneModel(id));
// initRet.push(...momentScenes!.map((s) => s.initFromRecords()));
// }
// }
{ // init main dating models
let ids = GameRecord.recordVariables["gm.md"] as any;
if (ids !== undefined) {
mainDatingScenes = [];
mainDatingScenes = ids.map((id: number) => new DatingEventSceneModel(id));
initRet.push(...mainDatingScenes!.map((s) => s.initFromRecords()));
} else {
mainDatingScenes = [];
}
}
{//init application
cc.game.on(cc.game.EVENT_HIDE, () => {
// console.log("enter game background");
AudioManager.pauseMusic();
//ApplicaitonGameChanged.emit(false);
});
cc.game.on(cc.game.EVENT_SHOW, () => {
// console.log("enter game force");
AudioManager.resumeMusic();
// ApplicaitonGameChanged.emit(true);
});
}
if (initRet.length) {
await Promise.all(initRet);
}
if (onProgress) onProgress(0.94);
if (!disposable) {
disposable = new CompositeDisposable;
disposable.add(PlotManager.PlotWillStart.on(handlePlotWillStart));
disposable.add(PlotManager.PlotsRollbackEvent.on(handlePlotsRollback));
disposable.add(EditorEvents.UNLOCK_ITEM.on(onUnlockItem));
disposable.add(EditorEvents.UNLOCK_SPECIAL_PLOT.on(onUnlockSpecialPlot));
disposable.add(EditorEvents.DEAD_EVENT.on(onDeadEvevt));
disposable.add(EditorEvents.SPECIAL_TOAST.on(onSpecialToast));
}
initPlots();
if (onProgress) onProgress(0.96);
for (let scene of mainDatingScenes!) { // 检查主线剧情状态
if (currPlots![0].plotSceneType !== PlotSceneType.DatingEvent ||
(scene.id !== currPlots![0].plotSceneTypeId && scene.status !== DatingEventStatus.Completed)) {
scene.status = DatingEventStatus.Completed;
}
}
//guide listener
// disposable.add(EditorEvents.GUIDE_TAB_MSG.on((param: string) => {
// setGuideMainTabRecord(MainTabs.messageTab, GuideState.Open);
// }));
// disposable.add(EditorEvents.GUIDE_TAB_DATE.on((param: string) => {
// setGuideMainTabRecord(MainTabs.datingEventTab, GuideState.Open);
// }));
// disposable.add(EditorEvents.GUIDE_VIEW_DATE.on((param: string) => {
// setGuideEventItemRecord(param, GuideState.Open);
// }));
// disposable.add(EditorEvents.GUIDE_VIEW_MSG.on((param) => {
// setGuideMsgItemRecord(param, GuideState.Open);
// }));
if (onProgress) onProgress(0.98);
}
function onUnlockItem(itemId: string) {
let s = itemId;
if (s && "" !== s.trim()) {
let n = parseInt(s);
UnlockItem.emit(n);
}
}
function onDeadEvevt(pid: string) {
let s = pid;
if (s && "" !== s.trim()) {
let n = parseInt(s);
DeadEvent.emit(n);
}
}
function onSpecialToast(type: string) {
let s = type;
if (s && "" !== s.trim()) {
let n = parseInt(s) as SpecialToastType;
SpecialToast.emit(n);
}
}
export function onUnlockSpecialPlot(specialPlotId: string) {
let s = specialPlotId;
if (s && "" !== s.trim()) {
let n = parseInt(s);
UnlockSpecialPlotModelManager.saveUnlockedSpecialPlotIdByItemIdToGameRecord(n);
}
}
/**
* set main tab guide record value
* @param index
* @param record
*/
export function setGuideMainTabRecord(index: number, record: GuideState) {
let r = GameRecord.globalVariables["guide_main_tab" + index] as number;
if (r && record <= r) {
return;
}
GameRecord.globalVariables["guide_main_tab" + index] = record;
GameRecord.saveRecord();
}
/**
* get main tab guide index
*/
export function getMainTabGuideIndex(): number {
let index = -1;
const MAX = 4;
for (let i = 0; i < MAX; i++) {
let r = GameRecord.globalVariables["guide_main_tab" + i] as number;
r = r === undefined ? GuideState.close : r;
if (r === GuideState.Open) {
index = i;
}
}
return index;
}
/**
* set event item guide record value
* @param itemKey
* @param record
*/
export function setGuideEventItemRecord(itemKey: string, record: GuideState) {
let r = GameRecord.globalVariables["guide_evt_item"] as number;
r = r === undefined ? GuideState.close : r;
if (record <= r) {
return;
}
GameRecord.globalVariables["guide_evt_item_key"] = itemKey;
GameRecord.globalVariables["guide_evt_item"] = record;
GameRecord.saveRecord();
}
/**
* get event item guide key
*/
export function getEventItemGuideKey(): string {
let key: string = "";
let r = GameRecord.globalVariables["guide_evt_item"] as number;
r = r === undefined ? GuideState.close : r;
let k = GameRecord.globalVariables["guide_evt_item_key"] as string;
if (r && r === GuideState.Open) {
key = k;
}
return key;
}
/**
* set msg guide item record value
* @param itemKey
* @param record
*/
export function setGuideMsgItemRecord(itemKey: string, record: GuideState) {
let r = GameRecord.globalVariables["guide_msg_item"] as number;
r = r === undefined ? GuideState.close : r;
if (record <= r) {
return;
}
GameRecord.globalVariables["guide_msg_item_key"] = itemKey;
GameRecord.globalVariables["guide_msg_item"] = record;
GameRecord.saveRecord();
}
/**
* get msg item guide key
*/
export function getMsgItemGuideKey(): string {
let key: string = "";
let r = GameRecord.globalVariables["guide_msg_item"] as number;
r = r === undefined ? GuideState.close : r;
let k = GameRecord.globalVariables["guide_msg_item_key"] as string;
if (r && r === GuideState.Open) {
key = k;
}
return key;
}
/**
* checkHasGuide , deal layer problem between guide view and sinin view
*/
export function checkHasGuide(): boolean {
let ret: boolean = false;
// let hasMsgGuide = getMsgItemGuideKey() !== "";
// let hasEventGuide = getEventItemGuideKey() !== "";
// let hasGuideTab = getMainTabGuideIndex() !== -1;
// ret = hasGuideTab || hasMsgGuide || hasEventGuide;
return ret;
}
function save() {
let oldValue = GameRecord.recordVariables["gm.ms"];
let newValue = messageScenes!.map(v => v.id) as any;
if (!shallowEqual(oldValue, newValue)) {
GameRecord.recordVariables["gm.ms"] = newValue;
}
// oldValue = GameRecord.recordVariables["gm.mm"];
// newValue = momentScenes!.map(v => v.id) as any;
// if (!shallowEqual(oldValue, newValue)) {
// GameRecord.recordVariables["gm.mm"] = newValue;
// }
oldValue = GameRecord.recordVariables["gm.md"];
newValue = mainDatingScenes!.map(v => v.id) as any;
if (!shallowEqual(oldValue, newValue)) {
GameRecord.recordVariables["gm.md"] = newValue;
}
}
function savePhoneCall() {
GameRecord.recordVariables["gm.pci"] = phoneCallIndex;
GameRecord.saveRecord();
}
async function initPlots() {
let plots = PlotManager.getCurrentPlots();
if (true) {
currPlots = [...plots];
if (!messageScenes) { // 第一次进游戏,根据剧情初始化数据
messageScenes = [];
}
// if (!momentScenes) {
// momentScenes = [];
// }
if (!mainDatingScenes) {
mainDatingScenes = [];
}
for (let i = 0; i < plots.length; i++) {
let plot = plots[i];
if (plot.plotSceneType === PlotSceneType.Message) {
let index = messageScenes.findIndex(v => v.id === plot.plotSceneTypeId);
if (index < 0) {
index = 0;
let model = new 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 === PlotSceneType.Moment) {
// if (momentScenes.findIndex(v => v.id === plot.plotSceneTypeId) < 0) {
// let model = new MomentSceneModel(plot.plotSceneTypeId);
// model.recordIndex = GameRecord.getCurrentRecordItems().length - 1;
// momentScenes.unshift(model);
// }
} else if (plot.plotSceneType === PlotSceneType.DatingEvent) {
let cfg = ConfigManager.getConfig(dateSceneConfig, plot.plotSceneTypeId);
if (cfg.DateType === DateType.Date_Normal) { // 主线约会剧情
if (plots[0] !== plot) { console.error("主线约会剧情应在主线开启"); continue; }
if (mainDatingScenes.findIndex(v => v.id === plot.plotSceneTypeId) < 0) {
let model = new DatingEventSceneModel(plot.plotSceneTypeId);
model.firstPlot = plot;
model.status = DatingEventStatus.New;
mainDatingScenes.push(model);
}
}
}
}
save();
}
}
async function handlePlotWillStart(plot: ReadonlyPlot, branch: number) {
handleNewPlot(currPlots![branch], plot, branch);
currPlots![branch] = plot;
}
async function handlePlotsRollback(plots: ReadonlyPlots) {
// messageScenes = undefined;
// let oldMomentScenes = momentScenes;
// momentScenes = undefined;
// currPlots = undefined;
// disposable.dispose();
// await init();
// GameRecord.startTransaction();
// if (oldMomentScenes) {
// for (let s of oldMomentScenes) {
// if (!momentScenes) {
// s.clearRecords();
// } else {
// if ((momentScenes as MomentSceneModel[]).findIndex(v => v.id === s.id) < 0) {
// s.clearRecords();
// }
// }
// }
// }
// GameRecord.endTransaction(true);
}
async function handleNewPlot(prevPlot: ReadonlyPlot | undefined, plot: ReadonlyPlot, branch: number) {
if (plot.plotSceneType === PlotSceneType.Message) {
let idx = messageScenes!.findIndex(v => v.id === plot.plotSceneTypeId);
if (idx >= 0) { // 原会话中有新消息
let model = messageScenes![idx];
if (idx > 0) {
let reorderIdx = 0;
if (branch > 0 && currPlots && currPlots[0].plotSceneType === PlotSceneType.Message) {
reorderIdx = 1;
}
for (let i = idx; i > reorderIdx; i--) {
messageScenes![i] = messageScenes![i - 1];
}
messageScenes![reorderIdx] = model;
}
if (plot.sentences[0].content && plot.sentences[0].content.type !== SentenceType.SELECT) {
// model.lastPlot = plot;
}
} else { // 新会话
let model = new MessageSceneModel(plot.plotSceneTypeId);
model.firstPlot = plot;
if (plot.sentences[0].content && plot.sentences[0].content.type !== SentenceType.SELECT) {
// model.lastPlot = plot;
}
// 新会话不可能是送礼
// if (branch > 0 && currPlots && currPlots[0].plotSceneType === PlotSceneType.Message) {
// messageScenes!.splice(1, 0, model);
// } else {
messageScenes!.unshift(model);
// }
}
MessageSceneChanged.emit(messageScenes!);
save();
} else if (plot.plotSceneType === PlotSceneType.Moment) {
// let idx = momentScenes!.findIndex(v => v.id === plot.plotSceneTypeId);
// if (idx >= 0) { // 原会话中有新消息
// let model = momentScenes![idx];
// if (idx > 0) {
// for (let i = idx; i > 0; i--) {
// momentScenes![i] = momentScenes![i - 1];
// }
// momentScenes![0] = model;
// }
// } else { // 新会话
// let model = new MomentSceneModel(plot.plotSceneTypeId);
// model.recordIndex = GameRecord.getCurrentRecordItems().length; // 当前存档还没生成,不需要减1
// momentScenes!.unshift(model);
// }
// save();
} else if (plot.plotSceneType === PlotSceneType.PhoneCall) {
if (!prevPlot || prevPlot.plotSceneType !== PlotSceneType.PhoneCall) {
phoneCallIndex = GameRecord.getCurrentRecordItems().length; // 当前存档还没生成,不需要减1
savePhoneCall();
}
} else if (plot.plotSceneType === PlotSceneType.DatingEvent) {
let cfg = ConfigManager.getConfig(dateSceneConfig, plot.plotSceneTypeId);
if (cfg.DateType === 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(plot.plotSceneTypeId);
model.firstPlot = plot;
model.status = DatingEventStatus.New;
mainDatingScenes!.push(model);
MainDatingEventChanged.emit(mainDatingScenes!);
}
save();
}
}
if (prevPlot && prevPlot.plotSceneType === PlotSceneType.PhoneCall && plot.plotSceneType !== PlotSceneType.PhoneCall) {
phoneCallIndex = -1;
savePhoneCall();
}
if (prevPlot && (prevPlot.plotSceneType !== plot.plotSceneType || prevPlot.plotSceneTypeId !== plot.plotSceneTypeId)) { // 切换场景
if (prevPlot.plotSceneType === PlotSceneType.Message) { // 最后一个是选项的情况下,此时已做选择,记录最后一条剧情
// let model = messageScenes!.find(v => v.id === prevPlot.plotSceneTypeId);
// model!.lastPlot = prevPlot;
}
if (prevPlot.plotSceneType === PlotSceneType.DatingEvent) {
let model = mainDatingScenes!.find(v => v.id === prevPlot.plotSceneTypeId);
if (model) model.status = DatingEventStatus.Completed;
}
}
// //main plot line progress and change plot scene (for BI dot);
// let mainPlotLineSession = GameRecord.recordVariables["m_p_l_s"] as number;
// if (0 === branch && (!mainPlotLineSession || !prevPlot || (prevPlot.plotSceneType !== plot.plotSceneType || prevPlot.plotSceneTypeId !== plot.plotSceneTypeId))) {
// mainPlotLineSession = mainPlotLineSession ? mainPlotLineSession : 0;
// if (0 === mainPlotLineSession) {
// GameDotMgr.getInstance().dotPlot(mainPlotLineSession + 1, PlotSessionState.Start);
// } else {
// GameDotMgr.getInstance().dotPlot(mainPlotLineSession, PlotSessionState.End);
// GameDotMgr.getInstance().dotPlot(mainPlotLineSession + 1, PlotSessionState.Start);
// }
// mainPlotLineSession++;
// GameRecord.recordVariables["m_p_l_s"] = mainPlotLineSession;
// let plotScenTypeSession = GameRecord.recordVariables["p_s_t_s" + plot.plotSceneType] as number;
// plotScenTypeSession = plotScenTypeSession ? plotScenTypeSession : 0;
// plotScenTypeSession++;
// GameRecord.recordVariables["p_s_t_s" + plot.plotSceneType] = plotScenTypeSession;
// }
// //main plot line progress
// if (0 === branch && checkIsDotTutorial()) {
// let plotScenTypeSession = GameRecord.recordVariables["p_s_t_s" + plot.plotSceneType] as number;
// plotScenTypeSession = plotScenTypeSession ? plotScenTypeSession : 1;
// let r = GameRecord.recordVariables["p_s_t_i_p"] as number;
// r = r ? r : 0;
// if (!prevPlot || (prevPlot.plotSceneType !== plot.plotSceneType || prevPlot.plotSceneTypeId !== plot.plotSceneTypeId)) {
// r = 1;
// } else {
// r++;
// }
// GameRecord.recordVariables["p_s_t_i_p"] = r;
// }
isChangPlotSceneType = !prevPlot || (prevPlot.plotSceneType !== plot.plotSceneType || prevPlot.plotSceneTypeId !== plot.plotSceneTypeId);
//main plot line progress
if (0 === branch && checkIsDotTutorial()) {
stepMainLinePlotProgress();
}
}
function stepMainLinePlotProgress() {
let r = GameRecord.recordVariables["p_s_t_i_p"] as number;
r = r ? r : 0;
if (isChangPlotSceneType) {
r = 1;
} else {
r++;
}
GameRecord.recordVariables["p_s_t_i_p"] = r;
}
export function dotMainLinePlotStart() {
// main plot line progress and change plot scene (for BI dot);
let plot = PlotManager.getCurrentPlots()[0];
let mainPlotLineSession = GameRecord.globalVariables["m_p_l_s"] as number;//主线总session计数
mainPlotLineSession = mainPlotLineSession ? mainPlotLineSession : 1;
let sKey = "m_l_p_s_started";
let startedSession = GameRecord.globalVariables[sKey] as number;
startedSession = startedSession ? startedSession : 0;
if (startedSession >= mainPlotLineSession) {//max is equal
return;
}
GameDotMgr.getInstance().dotPlot(mainPlotLineSession, PlotSessionState.Start);
GameRecord.globalVariables["m_p_l_s"] = mainPlotLineSession;
let plotScenTypeSession = GameRecord.globalVariables["p_s_t_s" + plot.plotSceneType] as number;
plotScenTypeSession = plotScenTypeSession ? plotScenTypeSession : 0;
plotScenTypeSession++;
GameRecord.globalVariables["p_s_t_s" + plot.plotSceneType] = plotScenTypeSession;//不同场景类型分别session计数
if (checkIsDotTutorial()) {
GameRecord.recordVariables["p_s_t_i_p"] = 1;//主线剧情中,当前场景类型progress进度计数
}
GameRecord.globalVariables[sKey] = mainPlotLineSession;
GameRecord.saveRecord();
}
/**
* 主线剧情结束打点
*/
export function dotMainLinePlotEnd() {
let mainPlotLineSession = GameRecord.globalVariables["m_p_l_s"] as number;
GameDotMgr.getInstance().dotPlot(mainPlotLineSession, PlotSessionState.End);
GameRecord.globalVariables["m_p_l_s"] = mainPlotLineSession + 1;
GameRecord.saveRecord();
}
/**剧情进度打点 */
export function dotPlotProgress() {
let plot = PlotManager.getCurrentPlots()[0];
let plotScenTypeSession = GameRecord.globalVariables["p_s_t_s" + plot.plotSceneType] as number;
let r = GameRecord.recordVariables["p_s_t_i_p"] as number;
let tt = TutorialType.Message;
switch (plot.plotSceneType) {
case PlotSceneType.Message:
{
tt = TutorialType.Message;
}
break;
case PlotSceneType.DatingEvent:
{
tt = TutorialType.Event;
}
break;
case PlotSceneType.PhoneCall:
{
tt = TutorialType.Phone;
}
break;
}
if (r % 5 === 0 || r < 5) {
GameDotMgr.getInstance().dotTutorial(tt, TutorialState.Progress, { session: plotScenTypeSession, progress: r });
}
}
export function checkFuncUnloced(key: string) {
return GameRecord.recordVariables[key] === FuncStateEnum.locked ? false : true;
}
export function checkRedPot(key: string) {
return GameRecord.globalVariables["red_pot_" + key] === RedPotStateEnum.Show;
}
export function setRedPotState(key: string, state: RedPotStateEnum) {
GameRecord.globalVariables["red_pot_" + key] = state;
GameRecord.autoSave();
}
export async function plotUseEnergy(plotId: number) {
if (GameRecord.globalVariables.plotUseEnergy === plotId) return true; // 当前剧情已扣过体力
let player = getPlayerData();
let currEnergy = player.getEnergy();
const costEnergy: boolean = false;//是否消耗体力
if (!costEnergy) {
GameRecord.globalVariables.plotUseEnergy = plotId;
return true;
}
// if (currEnergy >= GameConstData.GAME_CONST_PLOT_ENERGY_COST_VALUE) {
// GameRecord.globalVariables.plotUseEnergy = plotId;
// player.addEnergy(GameConstData.GAME_CONST_PLOT_ENERGY_COST_VALUE * (-1));
// return true;
// }
// // TODO 提示体力不足,跳转购买体力?
// let ret = await UIUtils.showAddEnergy(getItemConfig(GameConstData.GAME_CONST_ENERGY_PROPS_ID), getPlayerData().getProps(GameConstData.GAME_CONST_ENERGY_PROPS_ID));
// if (ret) {
// let itemconfig = GameModelManager.getItemConfig(GameConstData.GAME_CONST_ENERGY_PROPS_ID);
// player.addEnergy(itemconfig.energy_recover - GameConstData.GAME_CONST_PLOT_ENERGY_COST_VALUE);
// GameRecord.globalVariables.plotUseEnergy = plotId;
// UIManager.showToast(GameModelManager.getLanguageTxt(GameTextData.GAME_TEXT_MAIN_ENERGY_ADADDSUCCESS_VALUE));
// return true;
// } else {
// let itemcount = player.getProps(GameConstData.GAME_CONST_ENERGY_PROPS_ID);
// itemcount = itemcount === undefined ? 0 : itemcount;
// if (itemcount <= 0) {
// UIManager.showToast(GameModelManager.getLanguageTxt(GameTextData.GAME_TEXT_MAIN_ENERGY_ADADDFAILED_VALUE));
// }
// return false;
// }
}
// functions about gift
/**
* return:1.return all gifts ids which you can use to show;
* 2.contains default unlocked gifts and plot-unlcked-and really unlocked gifts
*/
// export function getGiftList(): number[] {
// analysisGiftConfigArr();
// let r = getRecordAlreadyUnlockedGifts();
// let ret: number[] = [];
// ret = ret.concat(defaultUnlockedGiftArr, r);
// return ret;
// }
/**
* return:1.return all of the plot-unlocked-gifts ids arr;
*/
export function getRecordAlreadyUnlockedGifts(): number[] {
// let r = GameRecord.getPlotsInfo();
// let a: number[] = [];
// if (r) {
// for (let i = 0; i < plotUnlockedGiftArr.length; i++) {
// let id = plotUnlockedGiftArr[i];
// let pid = ConfigManager.getConfig(itemConfig, id).unlock_plot;
// if (r[pid.toString()]) {
// a.push(id);
// }
// }
// }
let rStr = GameRecord.recordVariables["plot_unlocked_gifts"] as string;
let a: number[] = [];
if (rStr && "" !== rStr.trim()) {
a = JSON.parse(rStr) as number[];
}
return a;
}
/**
* return: 1.return the new unlocked gifts ids ;
* 2.if you has showed this ids, you'd use function resumPlotUnlockedGifts to resume the data;
*/
export function getNewPlotUnlockedGifts(): number[] {
let items = GameRecord.globalVariables["plotunlockgifts"] as number[];
items = items === undefined ? [] : items;
return items;
}
/**
* resumPlotUnlockedGifts
*/
export function resumPlotUnlockedGifts() {
GameRecord.globalVariables["plotunlockgifts"] = [];
GameRecord.autoSave();
}
/**
* checkHasNewGiftUnlocked
*/
export function checkHasNewGiftUnlocked(): boolean {
let g = getNewPlotUnlockedGifts();
return g && g.length > 0;
}
// function analysisGiftConfigArr() {
// if (defaultUnlockedGiftArr.length === 0) {
// defaultUnlockedGiftArr = [];
// plotUnlockedGiftArr = [];
// let tComp = ItemType.Item_Gift;
// let tbl = ConfigManager.getAllConfig(itemConfig);
// let uComp = ItemUnlockType.ItemUnlock_Default;
// for (let id in tbl) {
// let cfg = tbl[id];
// if (cfg && cfg.ItemType === tComp) {
// if (cfg.ItemUnlockType === uComp) {
// defaultUnlockedGiftArr.push(cfg.id);
// } else if (cfg.ItemUnlockType === ItemUnlockType.ItemUnlock_Plot) {
// plotUnlockedGiftArr.push(cfg.id);
// }
// }
// }
// }
// }
function pushNewPlotUnlockedGifts(gifts: number[]): number[] {
let items = GameRecord.globalVariables["plotunlockgifts"] as number[];
items = items === undefined ? [] : items;
for (let i = gifts.length - 1; i >= 0; i--) {
let g = gifts[i];
let index = items.findIndex((v) => v === g);
if (index < 0) {
continue;
} else {
gifts.splice(i, 1);
}
}
items = items.concat(gifts);
GameRecord.globalVariables["plotunlockgifts"] = items;
GameRecord.autoSave();
return items;
}
// function refreshPlotUnlockedGifts(plotId: number) {
// analysisGiftConfigArr();
// let a: number[] = [];
// for (let i = 0; i < plotUnlockedGiftArr.length; i++) {
// let id = plotUnlockedGiftArr[i];
// let pid = ConfigManager.getConfig(itemConfig, id).unlock_plot;
// if (plotId === pid) {
// a.push(id);
// }
// }
// pushNewPlotUnlockedGifts(a);
// }
//voice
export function checkVoiceNeedShowAD(vCfg: ICharacterVoiceConfig) {
let ret = false;
if (vCfg) {
if (vCfg.ads === 0) {
return ret;
}
let voiceAdRecord = GameRecord.globalVariables["voice_ad"] as string;
let arr: number[] = [];
if (voiceAdRecord) {
arr = JSON.parse(voiceAdRecord) as number[];
}
let set = new Set(arr);
ret = !set.has(vCfg.id);
}
return ret;
}
export function pushVoiceShowAdToRecord(voiceId: number) {
let voiceAdRecord = GameRecord.globalVariables["voice_ad"] as string;
let arr: number[] = [];
if (voiceAdRecord) {
arr = JSON.parse(voiceAdRecord) as number[];
}
let set = new Set(arr);
if (!set.has(voiceId)) {
arr.push(voiceId);
}
GameRecord.globalVariables["voice_ad"] = JSON.stringify(arr);
GameRecord.autoSave();
}
export function getCurDayStr(): string {
let t = TimeManager.getTime();
let time = new Date(t);
let y = time.getFullYear();
let m = time.getMonth() + 1;
let d = time.getDate();
let timeStr = y + "_" + m + "_" + d;
return timeStr;
}
export function checkIsDotTutorial(): boolean {
let curPlot = PlotManager.getCurrentPlots()[0];
return curPlot && curPlot.chapterId === GameConstData.GAME_CONST_FIRST_CHAPTER_ID;
}
export function getRolesByRoleType(roleType: number) {
let cfg = ConfigManager.getAllConfig(role);
let roleList: DeepReadonlyObject<IRole>[] = [];
for (const key in cfg) {
let _roleData = cfg[key];
if (roleType == _roleData.RoleType) {
roleList.push(_roleData);
}
}
return roleList;
}
//about lucky draw begin
export function getLastFreeTime(): number {
let time: number = 0;
let recordKey: string = "luck_draw_free_time";
let record = GameRecord.globalVariables[recordKey] as number;
time = record ? record : 0;
return time;
}
export function checkOverdue(time: number, refreshhour: number = 4) {//检测是否过期
let checkTime = new Date(time);
let currentTime = new Date(TimeManager.getTime());
let year = checkTime.getFullYear();
let month = checkTime.getMonth() + 1;
let day = checkTime.getDate();
let hour = checkTime.getHours();
if (currentTime.getFullYear() > year) {
return true;
} else if (currentTime.getMonth() + 1 > month) {
return true;
} if (currentTime.getDate() == day) {
if (hour > 0 && hour < refreshhour) {
if (currentTime.getHours() >= refreshhour) {
return true;
}
}
} else if (currentTime.getDate() > day && currentTime.getHours() >= refreshhour) {
return true;
}
return false;
}
export function setFreeState(state: FreeState) {
GameRecord.globalVariables["free_luckyDraw"] = state;
GameRecord.saveRecord();
}
export function getFreeState(): FreeState {
let r = GameRecord.globalVariables["free_luckyDraw"] as number;
r = r === FreeState.Cost ? FreeState.Cost : FreeState.Free;
return r;
}
export function checkLuckyDrawIsFree(): boolean {
let ret = false;
let lastFreeTime = getLastFreeTime();
let isNewDay: boolean = checkOverdue(lastFreeTime);
let freeState: FreeState = getFreeState();
if (isNewDay) {
ret = true;
setFreeState(FreeState.Free);
} else {
ret = freeState === FreeState.Free;
}
return ret;
}
export function setLastFreeTime(time?: number) {
let recordKey: string = "luck_draw_free_time";
GameRecord.globalVariables[recordKey] = time ? time : TimeManager.getTime();
GameRecord.saveRecord();
}
// export function getRewardPoolConfig(): DeepReadonlyObject<IRewardsPoolConfig> | undefined {
// let ret: DeepReadonlyObject<IRewardsPoolConfig> | undefined = undefined;
// let cfg = ConfigManager.getAllConfig(rewardsPoolConfig);
// for (let id in cfg) {
// let item = cfg[id];
// if (item.pool_active === 1) {
// ret = item;
// break;
// }
// }
// return ret;
// }
export function addSkinItemToRecord(itemId: number) {
let recordKey = "own_skins";
let exist = false;
let recordStr = GameRecord.globalVariables[recordKey] as string;
let skinItemIds: number[] = [];
if (recordStr) {
skinItemIds = JSON.parse(recordStr) as number[];
exist = skinItemIds.findIndex((v) => v === itemId) !== -1;
}
if (!exist) {
skinItemIds.push(itemId);
GameRecord.globalVariables[recordKey] = JSON.stringify(skinItemIds);
GameRecord.saveRecord();
RefreshDiscoverTabRed.emit();
}
}
export function checkHasOwnedSkin(itemId: number): boolean {
let recordKey = "own_skins";
let ret = false;
let recordStr = GameRecord.globalVariables[recordKey] as string;
if (recordStr) {
let skinItemIds: number[] = [];
skinItemIds = JSON.parse(recordStr) as number[];
ret = skinItemIds.findIndex((v) => v === itemId) !== -1;
}
return ret;
}
// export function checkHasGotLuckyDrawSkin(): boolean {
// let ret = false;
// let curPoolCfg = getRewardPoolConfig();
// if (curPoolCfg) {
// ret = checkHasOwnedSkin(curPoolCfg.pool_skin_include[0]);
// }
// return ret;
// }
// export function checkSkinNeedDressGuide(skinId: number): boolean {
// let needGuide: boolean = false;
// if (skinId !== undefined && skinId !== NaN && skinId >= 0) {
// let itemCfg = ConfigManager.getConfig(itemConfig, skinId);
// if (itemCfg) {
// if (itemCfg.ItemType === ItemType.Item_Skin) {
// let r = GameRecord.globalVariables["dressed_skins"] as string;
// if (r && "" !== r.trim()) {
// let arr = JSON.parse(r) as number[];
// needGuide = arr.findIndex((v) => v === skinId) === (-1);
// } else {
// needGuide = true;
// }
// } else {
// throw "id =>" + skinId + "is not a skin item id";
// }
// } else {
// throw "invalid skinId";
// }
// }
// return needGuide;
// }
// export function checkHasSkinNeedDressGuide(): boolean {
// let recordKey = "own_skins";
// let ret = false;
// let skinIds: number[] = [];
// let recordStr = GameRecord.globalVariables[recordKey] as string;
// if (!recordStr || "" === recordStr.trim()) {
// return false;
// } else {
// skinIds = JSON.parse(recordStr) as number[];
// if (skinIds && skinIds.length !== 0) {
// for (let i = 0; i < skinIds.length; i++) {
// let need = checkSkinNeedDressGuide(skinIds[i]);
// if (need) {
// ret = true;
// break;
// }
// }
// }
// }
// return ret;
// }
// export function completeSkinDressGuide(skinId: number) {
// if (skinId !== undefined && skinId !== NaN && skinId >= 0) {
// let itemCfg = ConfigManager.getConfig(itemConfig, skinId);
// if (itemCfg) {
// if (itemCfg.ItemType === ItemType.Item_Skin) {
// let r = GameRecord.globalVariables["dressed_skins"] as string;
// let exist = false;
// let arr: number[] = [];
// if (r && "" !== r.trim()) {
// arr = JSON.parse(r) as number[];
// exist = arr.findIndex((v) => v === skinId) !== (-1);
// }
// if (!exist) {
// arr.push(skinId);
// GameRecord.globalVariables["dressed_skins"] = JSON.stringify(arr);
// GameRecord.saveRecord();
// GameModelManager.RefreshDiscoverTabRed.emit();
// }
// } else {
// throw "id =>" + skinId + "is not a skin item id";
// }
// } else {
// throw "invalid skinId";
// }
// }
// }
export function checkSkinAndGraceCondition(condition: DeepReadonlyObject<ConditionExpression>): boolean {
let ret: boolean = false;
if (condition.groups && condition.groups.length > 0
&& condition.groups[0].items
&& condition.groups[0].items.length > 0
&& condition.groups[0].items[0].target) {
if (condition.groups[0].items[0].target.startsWith("r.like")) {
let roleIdStr = condition.groups[0].items[0].target.replace("r.like", "");
let role = getRoleData(parseInt(roleIdStr));
if (role && role.getRoleLike() >= parseInt(condition.groups[0].items[0].oprand.value)) {
ret = true;
}
}
if (condition.groups[0].items[0].target.startsWith("r.skin")) {
let roleIdStr = condition.groups[0].items[0].target.replace("r.skin", "");
let role = getRoleData(parseInt(roleIdStr));
let v = parseInt(condition.groups[0].items[0].oprand.value);
if (role && role.hasSkin(v) && role.getCurSkin() === v) {
ret = true;
}
}
}
return ret;
}
//about lucky draw end
// export function getDateSceneKeyPlotsProgress(sceneId: number): number {
// let progresss: number = 0;
// let cfg = ConfigManager.getConfig(dateSceneConfig, sceneId);
// let keyPlots = cfg.accomplish_plots;
// if (!keyPlots || keyPlots.length === 0) {
// progresss = 100;
// } else {
// let recordKeyStr: string = "date_key_plots_scene_" + sceneId;
// let recordStr: string = GameRecord.globalVariables[recordKeyStr] as string;
// let recordKeyPlots: number[] = [];
// if (recordStr && "" !== recordStr.trim()) {
// recordKeyPlots = JSON.parse(recordStr) as number[];
// }
// progresss = recordKeyPlots.length / keyPlots.length * 100;
// }
// return progresss;
// }
// export function pushDateSceneKeyPlot(sceneId: number, plotId: number) {
// let progress = getDateSceneKeyPlotsProgress(sceneId);
// if (progress === 100) {
// return;
// }
// let cfg = ConfigManager.getConfig(dateSceneConfig, sceneId);
// let keyPlots = cfg.accomplish_plots;
// if (keyPlots.findIndex((v) => v === plotId) < 0) {
// return;
// }
// let recordKeyStr: string = "date_key_plots_scene_" + sceneId;
// let recordStr: string = GameRecord.globalVariables[recordKeyStr] as string;
// let recordKeyPlots: number[] = [];
// if (recordStr && "" !== recordStr.trim()) {
// recordKeyPlots = JSON.parse(recordStr) as number[];
// }
// if (recordKeyPlots.findIndex((v) => v === plotId) < 0) {
// recordKeyPlots.push(plotId);
// GameRecord.globalVariables[recordKeyStr] = JSON.stringify(recordKeyPlots);
// GameRecord.saveRecord();
// GameModelManager.RefreshDateSceneProgress.emit();
// }
// }
export function getGraceLevelByGraceValue(value: number): number {
let level = 0;
let cfgs = ConfigManager.getAllConfig(relationLevelConfig);
let gCount = 0;
for (let id in cfgs) {
let cfg = cfgs[id];
gCount += cfg.relation_value;
if (value >= gCount) {
level = cfg.id;
}
}
return level;
}
export function checkIsNeedEnterCurDateChapter(): boolean {
return isNeedEnterCurDateChapter;
}
export function setNotNeedEnterCurDateChapter() {
isNeedEnterCurDateChapter = false;
}
// export function setProgressDateScene(sceneId: number | undefined) {
// let allCfg = ConfigManager.getAllConfig(dateAniConfig);
// let content = false;
// for (let id in allCfg) {
// let cfg = allCfg[id];
// if (cfg && cfg.date_id === sceneId) {sss
// content = true;
// }
// }
// if (content) {
// progressSceneId = sceneId;
// }
// }
// function checkIsGiveSkin(): boolean {
// let ret = false;
// if (progressSceneId) {
// let giveSceneId: number = 0;
// let allCfg = ConfigManager.getAllConfig(dateAniConfig);
// for (let id in allCfg) {
// let cfg = allCfg[id];
// if (cfg && cfg.date_id) {
// giveSceneId = cfg.date_id > giveSceneId ? cfg.date_id : giveSceneId;
// }
// }
// ret = giveSceneId === progressSceneId;
// }
// return ret;
// }
// export function getShowDateProgressInfo(): { isSkin: boolean, sceneId: number | undefined } {
// let isSkin = checkIsGiveSkin();
// return { isSkin: isSkin, sceneId: progressSceneId };
// }
export function setUnShowDateProgress() {
progressSceneId = undefined;
}
export function isDiscountAll(): boolean {
return false;
}
// export function checkHasGift(): { hasGift: boolean, gifts?: { id: GamePropType, num: number }[] } {
// let ret: { hasGift: boolean, gifts?: { id: GamePropType, num: number }[] } = { hasGift: false };
// let tbl = ConfigManager.getAllConfig(itemConfig);
// let role = getPlayerData();
// let gifts: { id: GamePropType, num: number }[] = [];
// for (let id in tbl) {
// let cfg = tbl[id];
// if (cfg && ItemType.Item_Gift === cfg.ItemType) {
// if (role) {
// let num = role.getProps(cfg.id);
// num = num ? num : 0;
// if (num > 0) {
// let gift: { id: GamePropType, num: number } = { id: cfg.id, num: num };
// gifts.push(gift);
// }
// }
// }
// }
// ret.hasGift = gifts.length !== 0;
// if (ret.hasGift) {
// ret.gifts = gifts;
// }
// return ret;
// }
export function stepGetNewPlayerGift(isFirst: boolean, time?: number, step?: number) {
let timeRecord = GameRecord.globalVariables["n_p_r_g_s_t"] as number;
timeRecord = timeRecord ? timeRecord : TimeManager.getTime();
time = time ? time : 0;
time = time ? time : timeRecord;
const stepMax: number = 7;
step = step ? step : 1;
let recordKey = "n_p_r_g_s_p";
let record = GameRecord.globalVariables[recordKey] as number;
record = record ? record : 0;
record += step;
let overTime: boolean = checkOverdue(time);
if (record <= stepMax && (overTime || isFirst)) {
GameRecord.globalVariables[recordKey] = record;
GameRecord.globalVariables["n_p_r_g_s_t"] = TimeManager.getTime();
GameRecord.saveRecord();
}
}
export function registerAutoPopView(viewType: AutoPopViewType) {
if (_autoPopView.length === 0) {
_autoPopView.push(viewType);
} else {
if (_autoPopView.findIndex((v) => v === viewType) === (-1)) {
_autoPopView.push(viewType);
}
}
}
export function checkAutoPopView() {
if (_autoPopView.length === 0) {
return;
}
_autoPopView = _autoPopView.sort((v1: AutoPopViewType, v2: AutoPopViewType) => {
return v1 - v2;
});
let v = _autoPopView.pop();
if (v) {
AutoPopView.emit(v);
}
}
export function checkWelfareNeedGuide() {
let time = GameRecord.globalVariables["sininsevendaydatetime"];
time = time === undefined ? 0 : time;
if (checkOverdue(time)) {
return true;
}
return false;
}
export function markResumeFullEnergy() {
let marked = checkResumeFullEnergyMarked();
if (marked) {
return;
}
let timeKeyStr: string = "resume_full_energy_time";
GameRecord.globalVariables[timeKeyStr] = TimeManager.getTime();
GameRecord.saveRecord();
}
export function checkResumeFullEnergyMarked(): boolean {
let mark: boolean = false;
let timeKeyStr: string = "resume_full_energy_time";
let timeRecord = GameRecord.globalVariables[timeKeyStr] as number;
if (timeRecord) {
let over = checkOverdue(timeRecord);
if (!over) {
mark = true;
}
}
return mark;
}
export function checkIsNeedResumeFullEnergy(): boolean {
let isResume: boolean = false;
let timeKeyStr: string = "resume_full_energy_time";
let timeRecord = GameRecord.globalVariables[timeKeyStr] as number;
if (timeRecord) {
let over = checkOverdue(timeRecord);
if (over) {
isResume = true;
}
}
return isResume;
}
export function dealAutoResumeFullEnergy() {
let isResume: boolean = checkIsNeedResumeFullEnergy();
if (isResume) {
let r = getPlayerData();
let e = r.getEnergy();
r.addEnergy(GameConstData.GAME_CONST_ENERGY_MAX - e);
let timeKeyStr: string = "resume_full_energy_time";
GameRecord.globalVariables[timeKeyStr] = 0;
GameRecord.saveRecord();
}
}
export function checkIsOverPlotLimitTime() {
let isOver: boolean = false;
let timeKeyStr: string = "plot_limit_time";
let recordTime = GameRecord.globalVariables[timeKeyStr] as number;
if (recordTime) {
isOver = checkOverdue(recordTime);
} else {
let timeKeyStr: string = "plot_limit_time";
GameRecord.globalVariables[timeKeyStr] = TimeManager.getTime();
}
return isOver;
}
export async function dealBlockedPlot(isAdForce?: boolean) {
let over = checkIsOverPlotLimitTime();
let curPlot = PlotManager.getCurrentPlots()[0];
if (curPlot && curPlot.plotSceneType === PlotSceneType.BlockPlot) {
if (over || isAdForce) {
await PlotManager.completePlot(curPlot);
let timeKeyStr: string = "plot_limit_time";
GameRecord.globalVariables[timeKeyStr] = TimeManager.getTime();
PlotBlockedChanged.emit();
} else {
ShowPlotBlocked.emit();
}
}
}
export function checkIsPlotBlocked(): boolean {
let blocked: boolean = false;
let curPlot = PlotManager.getCurrentPlots()[0];
if (curPlot && curPlot.plotSceneType === PlotSceneType.BlockPlot) {
blocked = true;
}
return blocked;
}
export function getCurPlotBlockedId(): number {
let id = PlotManager.getCurrentPlots()[0].id;
return id;
}
export function checkIsNeedShowPlotBlocked(): boolean {
let show: boolean = false;
let curPlot = PlotManager.getCurrentPlots()[0];
if (curPlot && curPlot.plotSceneType === PlotSceneType.BlockPlot) {
let over = checkIsOverPlotLimitTime();
if (!over) {
show = true;
}
}
return show;
}
export function isPlotBlockedOrToBeContinued(): boolean {
let isPlotBolcked = checkIsPlotBlocked();
let p = PlotManager.getCurrentPlots()[0];
let isToBeContinued = p && p.id === SpecialPlotId.ToBeContinued;
let preConditionFlag = isPlotBolcked || isToBeContinued;
return preConditionFlag;
}
export function getCurMainLinePlotId(): number {
let p = PlotManager.getCurrentPlots()[0];
return p ? p.id : 0;
}
let tipAddGracePlots: number[] = [];
export function checkPlotTipAddGraceAlready(plotId: number): boolean {
let ret = tipAddGracePlots.findIndex((v) => v === plotId) !== (-1);
return ret;
}
export function pushTipAddGracePlot(plotId: number) {
let exist = tipAddGracePlots.findIndex((v) => v === plotId) !== (-1);
if (!exist) {
tipAddGracePlots.push(plotId);
}
}
/**
* 根据卧室物品Id获取对应的淘宝商品类型
* @param itemId 卧室物品Id
* @returns 返回值为卧室物品对应的淘宝商品类型
*/
export function getTypeByBedroomItemId(itemId: number): number {
let type: number = -1;
let cfg = ConfigManager.getAllConfig(bedroomItemConfig);
if (cfg) {
for (const id in cfg) {
if (cfg[id].bedroomItemId == itemId) {
type = cfg[id].itemType;
}
}
}
return type;
}
/**
* 根据商品类型获得该商品对应的淘宝地址链接
* @param type 商品类型
* @returns 返回值为商品类型对应的商品地址
*/
export function getTaoBaoShopUrlByType(type: number): string {
let link: string = "";
let cfg = ConfigManager.getAllConfig(taoBaoShopUrlConfig);
if (cfg) {
for (const id in cfg) {
if (cfg[id].type == type) {
link = cfg[id].websiteUrl;
}
}
}
return link;
}
/**
* 根据商品类型获得该商品对应的有赞地址链接
* @param type 商品类型
* @returns 返回值为商品类型对应的商品地址
*/
export function getYouZanShopUrlByType(type: number): string {
let link: string = "";
let cfg = ConfigManager.getAllConfig(taoBaoShopUrlConfig);
if (cfg) {
for (const id in cfg) {
if (cfg[id].type == type) {
link = cfg[id].youZanUrl;
}
}
}
return link;
}
/**
* 根据网页链接跳转网页
* @param url 要跳转的网页链接
*/
export function jumpToTaobaoShop(url: string) {
if (channel == "dummy") {
let mUrl = url.replace("taobao:", "https:");
window.open(mUrl);
} else {
let packageName: string = "com.taobao.taobao";
let errorTips: string = "您还没有安装淘宝客户端!";
jsb.reflection.callStaticMethod('org/cocos2dx/javascript/AppActivity', 'jumpToTaobaoShop', "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", packageName, url, errorTips);
}
}
/**特殊剧情id数组 */
const SpecialPlotIdArr: number[] = [SpecialPlotId.CustomPlotStart, SpecialPlotId.End, SpecialPlotId.ToBeContinued];
/**根据剧情id获取剧情的内容 */
export async function getPlotContent(plotId: number): Promise<IPlotContent | undefined> {
let plotContent: IPlotContent | undefined = undefined;
let isSpecialPlot = SpecialPlotIdArr.findIndex((v) => v === plotId) !== (-1);
if (isSpecialPlot) {
cc.error("can not get special plot content, plotId = ", plotId);
return undefined;
}
try {
let plot = await getPlot(plotId);
if (plot && plot.sentences && plot.sentences.length !== 0) {
const sentence = plot.sentences[0];
const content = sentence.content;
if (content) {
plotContent = {
plotId: plotId,
roleId: sentence.roleId,
content: []
};
if (content.type === SentenceType.TEXT) {
plotContent.content.push(richNodesToCocosString(content.value));
} else if (content.type === SentenceType.SELECT) {
for (let i = 0; i < content.value.length; i++) {
let value = content.value[i];
if (value.content && value.content.type === SentenceType.TEXT) {
plotContent.content.push(richNodesToCocosString(value.content.value));
} else {
plotContent.content.push(value.summary);
}
}
}
} else {
cc.error("plot has no content , plotId = ", plotId);
}
} else {
cc.warn("plot has no sentence or no such plot , plotId = ", plotId);
}
} catch (error) {
cc.error("getPlotContent error plotId = " + plotId + " error info = ", error);
return undefined;
}
return plotContent;
}
/**
* 设置是否自动弹出公告界面
* @param autoShow 是否自动弹出公告界面
*/
export function setAutoShowNotice(autoShow: boolean) {
let autoShowNoticeInfo: AutoShowNoticeInfo = {
time: TimeManager.getTime(),
autoShow: autoShow,
};
GameRecord.globalVariables["AutoShowNoticeInfo"] = autoShowNoticeInfo;
GameRecord.saveRecord();
}
/**
* 获取是否自动弹出公告界面
* @returns 返回值为是否自动弹出公告界面
*/
export function getAutoShowNotice(): boolean {
let autoShowNoticeInfo = GameRecord.globalVariables["AutoShowNoticeInfo"] as AutoShowNoticeInfo;
let autoShow = true;
if (autoShowNoticeInfo == undefined) {
autoShow = true;
} else {
autoShow = autoShowNoticeInfo.autoShow;
let isOver = checkOverdue(autoShowNoticeInfo.time);
if (isOver) {
autoShow = true;
setAutoShowNotice(autoShow);
}
}
return autoShow;
}
/**
* 设置是否自动弹出紧急公告界面
* @param autoShow 是否自动弹出紧急公告界面
*/
export function setUrgentNoticeInfo(noticeInfo: UrgentNoticeInfo) {
GameRecord.globalVariables["UrgentNoticeInfo"] = noticeInfo;
GameRecord.saveRecord();
}
/**
* 获取是否自动弹出紧急公告界面
* @returns 返回值为是否自动弹出紧急公告界面
*/
export function getUrgentNoticeInfo(): UrgentNoticeInfo {
let noticeInfo = GameRecord.globalVariables["UrgentNoticeInfo"] as UrgentNoticeInfo;
noticeInfo = noticeInfo ? noticeInfo : { readed: false, autoShow: true };
return noticeInfo;
}
/**
* 设置是否自动弹出紧急公告界面
* @param autoShow 是否自动弹出紧急公告界面
*/
export function setNoticeReaded(readed: boolean) {
GameRecord.globalVariables["NoticeReaded"] = readed;
GameRecord.saveRecord();
}
/**
* 获取是否自动弹出紧急公告界面
* @returns 返回值为是否自动弹出紧急公告界面
*/
export function getNoticeReaded(): boolean {
let readed = GameRecord.globalVariables["NoticeReaded"] as boolean;
readed = readed ? readed : false;
return readed;
}
}
export interface IPlotContent {
plotId: number;
roleId: number;
content: string[];
}
export interface AutoShowNoticeInfo {
time: number;
autoShow: boolean;
}
export interface UrgentNoticeInfo {
readed: boolean;
autoShow: boolean;
}