UnlockItemModelManager.ts
6.74 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
import { ConfigManager } from "simba-config-manager";
import { GameRecord } from "../../avg/AVG";
import { itemTbl } from "../../config/ItemTbl";
class UnlockItemModelManager1 {
/**存档Key */
private UnlockItems = 'UnlockItems';
/**存档Key */
private ClickedItems = 'ClickedItems';
/**存档Key */
private UnlockedIntroductionItems = 'UnlockedIntroductionItems';
/**解锁的物品ids */
private items: Array<number> = [];
/**点击过的物品ids */
private clickedItem: Array<number> = [];
/**已经解锁简介的物品ids */
private unlockedIntroductionItem: Array<number> = [];
/**配置掉落物品的剧情id和午评id的映射表 */
private _unlockPlotIds: Array<{ itemId: number, plotId: number }> = [];
/**获取配置掉落物品的剧情id和午评id的映射表 */
public get unlockPlotIds(): Array<{ itemId: number, plotId: number }> {
if (this._unlockPlotIds.length == 0) this.analysisItemCfg();
return this._unlockPlotIds
}
public get unlockItems(): Array<number> {
let items: Array<number> = [];
let itemsStr = GameRecord.globalVariables[this.UnlockItems];
if (itemsStr) {
let itemsIdStr: Array<string> = itemsStr.split(',');
itemsIdStr.forEach(id => {
try {
items.push(Number(id));
} catch (error) {
console.error(error);
}
});
}
return items;
}
public get clickedItems(): Array<number> {
this.clickedItem = [];
let itemsStr = GameRecord.globalVariables[this.ClickedItems];
if (itemsStr) {
let itemsIdStr: Array<string> = itemsStr.split(',');
itemsIdStr.forEach(id => {
try {
this.clickedItem.push(Number(id));
} catch (error) {
console.error(error);
}
});
}
return this.clickedItem;
}
public get unlockedIntroductionItems(): Array<number> {
this.unlockedIntroductionItem = [];
let itemsStr = GameRecord.globalVariables[this.UnlockedIntroductionItems];
if (itemsStr) {
let itemsIdStr: Array<string> = itemsStr.split(',');
itemsIdStr.forEach(id => {
try {
this.unlockedIntroductionItem.push(Number(id));
} catch (error) {
console.error(error);
}
});
}
return this.unlockedIntroductionItem;
}
/**
* 保存解锁了简介的物品id到存档
* @param id 点击过的物品id
*/
saveUnlockedIntroductionItemIdToGameRecord(id: number): boolean {
this.unlockedIntroductionItem = [];
let itemsStr = GameRecord.globalVariables[this.UnlockedIntroductionItems];
if (itemsStr) {
let itemsIdStr: Array<string> = itemsStr.split(',');
itemsIdStr.forEach(id => {
try {
this.unlockedIntroductionItem.push(Number(id));
} catch (error) {
console.error(error);
}
});
}
if (this.unlockedIntroductionItem.indexOf(id) == -1) {
this.unlockedIntroductionItem.push(id);
GameRecord.globalVariables[this.UnlockedIntroductionItems] = this.unlockedIntroductionItem.toString();
GameRecord.saveRecord();
return true;
}
return false;
}
/**
* 保存点击过的物品id到存档
* @param id 点击过的物品id
*/
saveClickedItemIdToGameRecord(id: number): boolean {
this.clickedItem = [];
let itemsStr = GameRecord.globalVariables[this.ClickedItems];
if (itemsStr) {
let itemsIdStr: Array<string> = itemsStr.split(',');
itemsIdStr.forEach(id => {
try {
this.clickedItem.push(Number(id));
} catch (error) {
console.error(error);
}
});
}
if (this.clickedItem.indexOf(id) == -1) {
this.clickedItem.push(id);
GameRecord.globalVariables[this.ClickedItems] = this.clickedItem.toString();
GameRecord.saveRecord();
return true;
}
return false;
}
/**
* 保存解锁的物品id到存档
* @param id 解锁的物品id
*/
saveItemIdToGameRecord(id: number): boolean {
this.items = [];
let itemsStr = GameRecord.globalVariables[this.UnlockItems];
if (itemsStr) {
let itemsIdStr: Array<string> = itemsStr.split(',');
itemsIdStr.forEach(id => {
try {
this.items.push(Number(id));
} catch (error) {
console.error(error);
}
});
}
if (this.items.indexOf(id) == -1) {
this.items.push(id);
GameRecord.globalVariables[this.UnlockItems] = this.items.toString();
// GameRecord.autoSave();
return true;
}
return false;
}
/**
* 登录初始化已经解锁的items
*/
loginInitUnlockItems() {
//获取已经存在的items
this.items = [];
let itemsStr = GameRecord.globalVariables[this.UnlockItems];
if (itemsStr) {
let itemsIdStr: Array<string> = itemsStr.split(',');
itemsIdStr.forEach(id => {
try {
this.items.push(Number(id));
} catch (error) {
console.error(error);
}
});
}
//当前剧情应该解锁的所有物品
let itemcfg: { itemId: number, plotId: number }[] = this.unlockPlotIds;
//获取当前的剧情id
let record = GameRecord.getPlotsInfo();
for (let i = 0; i < itemcfg.length; i++) {
let ele = itemcfg[i];
if (ele) {
if (record[`${ele.plotId}`] && record[`${ele.plotId}`].cnt >= 1) {
if (this.items.indexOf(ele.itemId) == -1) {
this.items.push(ele.itemId);
}
}
}
}
GameRecord.globalVariables[this.UnlockItems] = this.items.toString();
// GameRecord.autoSave();
}
/**
* 解析item表结果
*/
analysisItemCfg() {
let ret: { itemId: number, plotId: number }[] = [];
let cfg = ConfigManager.getAllConfig(itemTbl);
for (let id in cfg) {
ret.push({ itemId: Number(id), plotId: cfg[id].plot });
}
this._unlockPlotIds = ret;
}
}
export let UnlockItemModelManager = new UnlockItemModelManager1();