CDKeyEventManager.ts
2.56 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
import { GameRecord } from "../../avg/AVG";
import { UIManager } from "../../common/gameplay/managers/UIManager";
export default class CDKeyEventManager {
private CDKeyRemovePlotAD = "CDKeyRemovePlotAD";
private CDKeyRemovePlotAD_New = "prop_2_1001_num";
/**单例对象 */
private static _instance: CDKeyEventManager | undefined;
/**创建单例 */
public static getInstance(): CDKeyEventManager {
if (!CDKeyEventManager._instance) {
CDKeyEventManager._instance = new CDKeyEventManager();
}
return CDKeyEventManager._instance;
}
/**
* 兑换码去除剧情广告
*/
cdKeyRemovePlotAD() {
let cdKeyRemovePlotAd = GameRecord.globalVariables[this.CDKeyRemovePlotAD_New];
cdKeyRemovePlotAd = cdKeyRemovePlotAd ? cdKeyRemovePlotAd : 0;
let newCdKeyRemovePlotAd = cdKeyRemovePlotAd + 1
GameRecord.globalVariables[this.CDKeyRemovePlotAD_New] = newCdKeyRemovePlotAd;
GameRecord.saveRecord();
UIManager.showToast("兑换成功,解锁剧情将不再需要观看广告");
}
/**
* 检查是否去除了剧情广告
*/
checkCDKeyRemovePlotAD(): number {
let cdKeyRemovePlotAd = 0;
cdKeyRemovePlotAd = GameRecord.globalVariables[this.CDKeyRemovePlotAD_New];
cdKeyRemovePlotAd = cdKeyRemovePlotAd ? cdKeyRemovePlotAd : 0;
return cdKeyRemovePlotAd;
}
/**
* 版本兼容,将旧版的免广告卡存档迁移到新版存档中
*/
shiftCDKeyRemovePlotAD() {
let cdKeyRemovePlotAd = GameRecord.globalVariables[this.CDKeyRemovePlotAD];
if (cdKeyRemovePlotAd && cdKeyRemovePlotAd == "1") {
GameRecord.globalVariables[this.CDKeyRemovePlotAD_New] = 1;
GameRecord.globalVariables[this.CDKeyRemovePlotAD] = "0";
GameRecord.saveRecord();
}
}
/**
* 根据人物Id改变该人物的好感度
* @param roleId 人物Id
* @param like 好感度
*/
changeRoleLike(roleId: number, like: number) {
let g = GameRecord.globalVariables["like" + roleId] as number;
g = g ? g : 0;
let r = GameRecord.recordVariables["like" + roleId] as number;
r = r ? r : 0;
let l = g + r;
if (l >= 10000) {
UIManager.showToast("该人物的好感度已满,无法再增加");
return;
}
if (l + like >= 10000) {
g = 10000 - r;
} else {
g += like;
}
GameRecord.globalVariables["like" + roleId] = g;
GameRecord.saveRecord();
}
}