-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHWHGiftOfTheElementsExt.user.js
More file actions
527 lines (502 loc) · 23.4 KB
/
Copy pathHWHGiftOfTheElementsExt.user.js
File metadata and controls
527 lines (502 loc) · 23.4 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
// ==UserScript==
// @name HWHGiftOfTheElementsExt
// @name:en HWHGiftOfTheElementsExt
// @name:ru HWHGiftOfTheElementsExt
// @namespace HWHGiftOfTheElementsExt
// @version 3.9
// @description Extension for HeroWarsHelper script
// @description:en Extension for HeroWarsHelper script
// @description:ru Расширение для скрипта HeroWarsHelper
// @author Green
// @license Copyright Green
// @icon https://i.ibb.co/xtmhK7zS/icon.png
// @match https://www.hero-wars.com/*
// @match https://apps-1701433570146040.apps.fbsbx.com/*
// @run-at document-start
// @downloadURL https://github.com/Green-oGo/HWHGiftOfTheElementsExt/raw/refs/heads/main/HWHGiftOfTheElementsExt.user.js
// @updateURL https://github.com/Green-oGo/HWHGiftOfTheElementsExt/raw/refs/heads/main/HWHGiftOfTheElementsExt.user.js
// ==/UserScript==
(function () {
if (!this.HWHClasses) {
console.log('%cObject for extension not found', 'color: red');
return;
}
console.log('%cStart Extension ' + GM_info.script.name + ', v' + GM_info.script.version + ' by ' + GM_info.script.author, 'color: red');
const { addExtentionName } = HWHFuncs;
addExtentionName(GM_info.script.name, GM_info.script.version, GM_info.script.author);
const { buttons } = HWHData;
const { popup, confShow, setProgress, hideProgress, mailGetAll } = HWHFuncs;
const { i18nLangData } = HWHData;
const i18nLangDataEn = {
GIFT_OF_ELEMENTS: 'Gift of the Elements',
GIFT_OF_ELEMENTS_TITLE: 'Spend "Sparks of Power" or Reset "Gifts of the Elements"',
GOE_SPEND_SPARKS_OF_POWER: 'Spend "Sparks of Power"',
GOE_SPEND_SPARKS_OF_POWER_TITLE: 'Spend "Sparks of Power"',
GOE_RESET_GIFTS: 'Reset "Gifts of the Elements"',
GOE_RESET_GIFTS_LIGHT: 'Reset "Gifts of the Elements" <br> <span style="color: aqua;"> level 1 - 29 </span>',
GOE_RESET_GIFTS_LIGHT_TITLE: 'Reset "Gifts of the Elements". You can\'t reset Gift of the Elements level 30.',
GOE_RESET_GIFTS_EXTREME: 'Reset "Gifts of the Elements" <span style="color: red;"> level 30 </span>',
GOE_RESET_GIFTS_EXTREME_TITLE: 'Reset "Gifts of the Elements". There is no limit to the level of the Gift of Elements.',
GOE_SELECT_ACTION: 'Select an action',
GOE_NOTHING_TO_IMPROVE_LVL30: 'Nothing to improve. Account hasn\'t reached team level 30',
GOE_NOTHING_TO_IMPROVE: 'Nothing to improve. All heroes have maximum elemental gift level',
GOE_SPEND_SPARKS_OF_POWER_MESSAGE:
'Available <span style="color: green;"> {titanGift} </span> sparks of power <br> Specify how many sparks of power need to be spent',
GOE_INCORRECT_VALUE: 'Incorrect value',
GOE_IMPROVING_START: 'Improving the Gift of the Elements...',
GOE_NOT_ENOUGH_RESOURCES: 'Not enough gold or sparks of power',
GOE_ALL_HEROES_HAVE_30LVL: '<br>All heroes have reached level 30 in Gifts of the Elements',
GOE_GOLD_IS_GONE: '<br><span style="color: red;"> The gold is gone </span>',
GOE_PROGRESS_OF_IMPROVEMENT_MESSAGE: 'Gift of the Elements has been upgraded to level <span style="color: green;"> {titanGiftLevel} </span>',
GOE_RESULT_OF_IMPROVEMENT: 'Gift of the Elements has been upgraded <span style="color: green;"> {counter} </span> time(s)',
GOE_NOTHING_TO_RESET: 'Nothing to reset',
GOE_IMPOSSIBLE_TO_RESET: 'You don\'t have any heroes with Elemental Gift below level 30',
GOE_RESET_GIFTS_LIGHT_MESSAGE:
`Specify the <span style="color:red;"> maximum </span> reset level for Gift of the Elements
<br> Range: <span style="color:green;"> 1 </span> to <span style="color:green;"> 29 </span>`,
GOE_RESULT_RESET_GIFTS: 'Gift of the Elements has been reset for <span style="color: green;"> {counter} </span> hero(es)',
GOE_RESET_GIFTS_EXTREME_MESSAGE:
`You have <span style="color:green;"> {level30} </span> hero(es) with level <span style="color:green;">30</span> Gift of the Elements
<br> Enter how many level <span style="color:green;">30</span> Gifts of the Elements to reset
<br> <span style="color:red;"> The reset will start with the weakest hero </span> <br> Gifts of the Elements of lower levels will be reset automatically`,
GOE_EXTREME_DO_NOT_HAVE_HERO_30LVL:
'You don\'t have any heroes with Gift of the Elements level 30 <br> Reset Gifts of the Elements to a lower level?',
GOE_EXTREME_RESULT_RESET_GIFTS:
'<br> <span style="color: green;"> {counter30} </span> of them are level <span style="color:green;">30</span>',
GOE_GET_POWER: 'Get power',
GOE_GET_POWER_TITLE: 'Increase the overall power of heroes by the specified amount',
GOE_GET_POWER_MESSAGE:
`By spending sparks of power and gold you can get а maximum <span style="color: green;"> {maxHeroPawer} </span> units of hero power
<br> Specify how much hero power you want to get`,
GOE_GOT_POWER: '<br> Received <span style="color: green;"> {gotPower} </span> hero power',
GOE_NOT_ENOUGH_GOLD:
`<br><br><span style="color: red;">Not enough gold</span> to get all available hero power
<br> Heve gold: <span style="color: green;">{haveGold} </span> <br> Gold needed: <span style="color: red;"> {goldIsNeeded} </span>`,
};
i18nLangData['en'] = Object.assign(i18nLangData['en'], i18nLangDataEn);
const i18nLangDataRu = {
GIFT_OF_ELEMENTS: 'Дар стихий',
GIFT_OF_ELEMENTS_TITLE: 'Потратить "Искры мощи" или Сбросить "Дары стихий"',
GOE_SPEND_SPARKS_OF_POWER: 'Потратить "Искры мощи"',
GOE_SPEND_SPARKS_OF_POWER_TITLE: 'Потратить "Искры мощи"',
GOE_RESET_GIFTS: 'Сбросить "Дары стихий"',
GOE_RESET_GIFTS_LIGHT: 'Сбросить "Дары стихий" <br> <span style="color: aqua;"> 1 - 29 уровня </span>',
GOE_RESET_GIFTS_LIGHT_TITLE: 'Сбросить "Дары стихий". Не сбрасывается 30 уровень дара стихий',
GOE_RESET_GIFTS_EXTREME: 'Сбросить "Дары стихий" <span style="color: red;"> 30 уровня </span>',
GOE_RESET_GIFTS_EXTREME_TITLE: 'Сбросить "Дары стихий". Нет ограничений уровня дара стихий',
GOE_SELECT_ACTION: 'Выберите действие',
GOE_NOTHING_TO_IMPROVE_LVL30: 'Нечего улучшать. Аккаунт не достиг 30 уровня команды',
GOE_NOTHING_TO_IMPROVE: 'Нечего улучшать. У всех героев максимальный уровень дара стихий',
GOE_SPEND_SPARKS_OF_POWER_MESSAGE:
'Доступно <span style="color: green;"> {titanGift} </span> искр мощи <br> Укажите сколько искр мощи потратить',
GOE_INCORRECT_VALUE: 'Некорректное значение',
GOE_IMPROVING_START: 'Улучшаем дар стихий...',
GOE_NOT_ENOUGH_RESOURCES: 'Недостаточно золота или искр мощи',
GOE_ALL_HEROES_HAVE_30LVL: '<br>Достигнут 30 уровень дара стихий у всех героев',
GOE_GOLD_IS_GONE: '<br><span style="color: red;"> Закончилось золото </span>',
GOE_PROGRESS_OF_IMPROVEMENT_MESSAGE: 'Дар стихий улучшен до <span style="color: green;"> {titanGiftLevel} </span> уровня',
GOE_RESULT_OF_IMPROVEMENT: 'Дар стихий улучшен <span style="color: green;"> {counter} </span> раз(а)',
GOE_NOTHING_TO_RESET: 'Нечего сбрасывать',
GOE_IMPOSSIBLE_TO_RESET: 'Нет героев с даром стихий меньше 30 уровня',
GOE_RESET_GIFTS_LIGHT_MESSAGE:
`Укажите <span style="color:red;"> максимальный </span> сбрасываемый уровень дара стихий
<br> Диапазон от <span style="color: green;"> 1 </span> до <span style="color: green;"> 29 </span>`,
GOE_RESULT_RESET_GIFTS: 'Дар стихий сброшен у <span style="color: green;"> {counter} </span> героев(я)',
GOE_RESET_GIFTS_EXTREME_MESSAGE:
`У Вас <span style="color:green;"> {level30} </span> героя(ев) с <span style="color:green;">30</span> уровнем дара стихий
<br> Укажите сколько даров стихий <span style="color:green;">30</span> уровня сбросить
<br> <span style="color:red;"> Сброс начнется с самого слабого героя </span> <br> Дары стихий меньших уровней будут сброшены автоматически`,
GOE_EXTREME_DO_NOT_HAVE_HERO_30LVL:
'У Вас нет героев с 30 уровнем дара стихий <br> Сбросить дары стихий меньшего уровня?',
GOE_EXTREME_RESULT_RESET_GIFTS:
'<br> <span style="color: green;"> {counter30} </span> из них <span style="color:green;">30</span> уровня',
GOE_GET_POWER: 'Увеличить мощь',
GOE_GET_POWER_TITLE: 'Увеличить общую мощи героев на указанное количество',
GOE_GET_POWER_MESSAGE:
`Потратив искры мощи и золото, вы можете получить максимум <span style="color: green;"> {maxHeroPawer} </span> единиц мощи героев
<br> Укажите, сколько мощи героев необходимо получить`,
GOE_GOT_POWER: '<br> Получили мощи героев: <span style="color: green;"> {gotPower} </span>',
GOE_NOT_ENOUGH_GOLD:
`<br><br><span style="color: red;">Не достаточно золота</span>, чтобы получить всю доступную мощь героев
<br> Имеем золота: <span style="color: green;">{haveGold}</span> <br> Необходимо золота: <span style="color: red;"> {goldIsNeeded} </span>`,
};
i18nLangData['ru'] = Object.assign(i18nLangData['ru'], i18nLangDataRu);
// Добавление кнопок в окно Разное
const { othersPopupButtons } = HWHData;
othersPopupButtons.push({
get msg() {
return I18N('GIFT_OF_ELEMENTS');
},
get title() {
return I18N('GIFT_OF_ELEMENTS_TITLE');
},
result: async function () {
await onClickGiftOfTheElements();
},
color: 'pink',
});
async function onClickGiftOfTheElements() {
const popupButtons = [
{
get msg() {
return I18N('GOE_SPEND_SPARKS_OF_POWER');
},
get title() {
return I18N('GOE_SPEND_SPARKS_OF_POWER_TITLE');
},
result: async function () {
await spendSparksPower();
},
color: 'green',
},
{
get msg() {
return I18N('GOE_GET_POWER');
},
get title() {
return I18N('GOE_GET_POWER_TITLE');
},
result: async function () {
await getPower();
},
color: 'green',
},
{
get msg() {
return I18N('GOE_RESET_GIFTS_LIGHT');
},
get title() {
return I18N('GOE_RESET_GIFTS_LIGHT_TITLE');
},
result: async function () {
await resetTitanGifts();
},
},
{
get msg() {
return I18N('GOE_RESET_GIFTS_EXTREME');
},
get title() {
return I18N('GOE_RESET_GIFTS_EXTREME_TITLE');
},
result: async function () {
await resetTitanGifts30LVL();
},
},
];
popupButtons.push({ result: false, isClose: true });
const answer = await popup.confirm(`${I18N('GOE_SELECT_ACTION')}`, popupButtons);
if (typeof answer === 'function') {
answer();
}
}
const powerLevel = [22, 22, 22, 22, 22, 66, 66, 66, 66, 66, 110, 110, 110, 110, 110, 154,
154, 154, 154, 154, 198, 198, 198, 198, 198, 242, 242, 242, 242, 242 ];
// Получить мощь
async function getPower() {
let [heroGetAll, inventory, user] = await new Caller(['heroGetAll', 'inventoryGet', 'userGetInfo']).execute();
let heroes = Object.values(heroGetAll).sort((a, b) => a.titanGiftLevel - b.titanGiftLevel);
const heroSumPowerStart = Object.values(heroGetAll).reduce((a, e) => a + e.power, 0);
const titanGiftLib = lib.getData('titanGift');
let titanGift = inventory.consumable[24];
let titanGiftMax = titanGift;
let gold = user.gold;
let userLevel = user.level;
let calls = [];
let minTitanGiftLevel = heroes[0].titanGiftLevel;
let titanGiftLevel = minTitanGiftLevel;
let titanGiftUpgradeCounter = 0;
let message = '';
if (userLevel < 30) {
confShow(`${I18N('GOE_NOTHING_TO_IMPROVE_LVL30')}`);
return;
}
if (minTitanGiftLevel == 30) {
confShow(`${I18N('GOE_NOTHING_TO_IMPROVE')}`);
return;
}
let result = findMaximumPossiblePower(heroes, titanGift, titanGiftLib);
let maximumPowerWeCanGet = result.maximumPowerWeCanGet;
let needGoldToGetMaxPower = result.needGoldToGetMaxPower;
let notEnoughGold = '';
if (needGoldToGetMaxPower > gold) {
notEnoughGold = I18N('GOE_NOT_ENOUGH_GOLD', {haveGold: gold.toLocaleString(), goldIsNeeded: needGoldToGetMaxPower.toLocaleString() });
}
let needHeroPower = +(await popup.confirm(`${I18N('GOE_GET_POWER_MESSAGE', { maxHeroPawer: maximumPowerWeCanGet.toLocaleString() })} ${notEnoughGold}`, [
{ result: 0, isClose: true },
{ msg: `${I18N('GOE_GET_POWER')}`, isInput: true, default: maximumPowerWeCanGet, color: 'green' },
//{ msg: I18N('BTN_CANCEL'), result: 0, color: 'red' },
]));
if (needHeroPower == 0) {
return;
}
if (!needHeroPower || needHeroPower < 0 || needHeroPower > maximumPowerWeCanGet) {
confShow(`${I18N('GOE_INCORRECT_VALUE')}`);
return;
}
let gotHeroPower = 0;
setProgress(I18N('GOE_IMPROVING_START'), false);
let cycle = true;
while (cycle) {
for (const hero of heroes) {
if (titanGiftLevel >= 30) {
message += I18N('GOE_ALL_HEROES_HAVE_30LVL');
cycle = false;
break;
}
if (hero.titanGiftLevel > titanGiftLevel) {
break;
}
let nextLevelCost = titanGiftLib[hero.titanGiftLevel + 1].cost;
if (titanGift < nextLevelCost.consumable[24] || gold < nextLevelCost.gold) {
if (titanGiftUpgradeCounter == 0 && calls.length == 0) {
setProgress('', true);
confShow(`${I18N('GOE_NOT_ENOUGH_RESOURCES')}`);
return;
}
if (gold < nextLevelCost.gold) {
message += I18N('GOE_GOLD_IS_GONE');
}
cycle = false;
break;
}
calls.push({ name: 'heroTitanGiftLevelUp', args: { heroId: hero.id } });
titanGift -= nextLevelCost.consumable[24];
gold -= nextLevelCost.gold;
gotHeroPower += powerLevel[hero.titanGiftLevel];
if (gotHeroPower >= needHeroPower) {
cycle = false;
break;
}
}
if (calls.length >= 1) {
await Caller.send(calls);
titanGiftUpgradeCounter += calls.length;
heroGetAll = await new Caller('heroGetAll').execute();
heroes = Object.values(heroGetAll).sort((a, b) => a.titanGiftLevel - b.titanGiftLevel);
calls = [];
titanGiftLevel++;
setProgress(I18N('GOE_PROGRESS_OF_IMPROVEMENT_MESSAGE', { titanGiftLevel }), false);
}
}
const heroSumPowerFinish = Object.values(heroGetAll).reduce((a, e) => a + e.power, 0);
message += I18N('GOE_GOT_POWER', { gotPower: (heroSumPowerFinish - heroSumPowerStart).toLocaleString() });
//await new Promise((e) => setTimeout(e, 2000));
setProgress('', true);
confShow(`${I18N('GOE_RESULT_OF_IMPROVEMENT', { counter: titanGiftUpgradeCounter })} ${message}`);
}
function findMaximumPossiblePower(heroes, titanGift, titanGiftLib) {
let mass = {maximumPowerWeCanGet: 0, needGoldToGetMaxPower: 0};
for (let tGiftLvl = heroes[0].titanGiftLevel; tGiftLvl < 30; tGiftLvl++) {
for (let hero of heroes) {
if (hero.titanGiftLevel > tGiftLvl) {
continue;
}
let nextLevelCost = titanGiftLib[tGiftLvl + 1].cost;
if (titanGift < nextLevelCost.consumable[24]) {
return mass;
}
titanGift -= nextLevelCost.consumable[24];
mass.maximumPowerWeCanGet += powerLevel[tGiftLvl];
mass.needGoldToGetMaxPower += nextLevelCost.gold;
}
}
return mass;
}
// Потратить искры мощи
async function spendSparksPower() {
let [heroGetAll, inventory, user] = await new Caller(['heroGetAll', 'inventoryGet', 'userGetInfo']).execute();
let heroes = Object.values(heroGetAll).sort((a, b) => a.titanGiftLevel - b.titanGiftLevel);
const heroSumPowerStart = Object.values(heroGetAll).reduce((a, e) => a + e.power, 0);
const titanGiftLib = lib.getData('titanGift');
let titanGift = inventory.consumable[24];
let titanGiftMax = titanGift;
let gold = user.gold;
let userLevel = user.level;
let calls = [];
let minTitanGiftLevel = heroes[0].titanGiftLevel;
let titanGiftLevel = minTitanGiftLevel;
let titanGiftUpgradeCounter = 0;
let message = '';
if (userLevel < 30) {
confShow(`${I18N('GOE_NOTHING_TO_IMPROVE_LVL30')}`);
return;
}
if (minTitanGiftLevel == 30) {
confShow(`${I18N('GOE_NOTHING_TO_IMPROVE')}`);
return;
}
titanGift = +(await popup.confirm(I18N('GOE_SPEND_SPARKS_OF_POWER_MESSAGE', { titanGift: titanGift.toLocaleString() }), [
{ result: 0, isClose: true },
{ msg: `${I18N('GOE_SPEND_SPARKS_OF_POWER')}`, isInput: true, default: titanGift.toString(), color: 'green' },
//{ msg: I18N('BTN_CANCEL'), result: 0, color: 'red' },
]));
if (titanGift == 0) {
return;
}
if (!titanGift || titanGift < 0 || titanGift > titanGiftMax) {
confShow(`${I18N('GOE_INCORRECT_VALUE')}`);
return;
}
setProgress(I18N('GOE_IMPROVING_START'), false);
let cycle = true;
while (cycle) {
for (const hero of heroes) {
if (titanGiftLevel >= 30) {
message += I18N('GOE_ALL_HEROES_HAVE_30LVL');
cycle = false;
break;
}
if (hero.titanGiftLevel > titanGiftLevel) {
break;
}
let nextLevelCost = titanGiftLib[hero.titanGiftLevel + 1].cost;
if (titanGift < nextLevelCost.consumable[24] || gold < nextLevelCost.gold) {
if (titanGiftUpgradeCounter == 0 && calls.length == 0) {
setProgress('', true);
confShow(`${I18N('GOE_NOT_ENOUGH_RESOURCES')}`);
return;
}
if (gold < nextLevelCost.gold) {
message += I18N('GOE_GOLD_IS_GONE');
}
cycle = false;
break;
}
calls.push({ name: 'heroTitanGiftLevelUp', args: { heroId: hero.id } });
titanGift -= nextLevelCost.consumable[24];
gold -= nextLevelCost.gold;
}
if (calls.length >= 1) {
await Caller.send(calls);
titanGiftUpgradeCounter += calls.length;
heroGetAll = await new Caller(['heroGetAll']).execute();
heroes = Object.values(heroGetAll).sort((a, b) => a.titanGiftLevel - b.titanGiftLevel);
calls = [];
titanGiftLevel++;
setProgress(I18N('GOE_PROGRESS_OF_IMPROVEMENT_MESSAGE', { titanGiftLevel }), false);
}
}
const heroSumPowerFinish = Object.values(heroGetAll).reduce((a, e) => a + e.power, 0);
message += I18N('GOE_GOT_POWER', { gotPower: (heroSumPowerFinish - heroSumPowerStart).toLocaleString() });
//await new Promise((e) => setTimeout(e, 2000));
setProgress('', true);
confShow(`${I18N('GOE_RESULT_OF_IMPROVEMENT', { counter: titanGiftUpgradeCounter })} ${message}`);
}
//Сбросить дары стихий
async function resetTitanGifts() {
const [heroGetAll, user] = await new Caller(['heroGetAll', 'userGetInfo']).execute();
const heroes = Object.values(heroGetAll).sort((a, b) => a.titanGiftLevel - b.titanGiftLevel);
const userLevel = user.level;
let calls = [];
let maxResetTitanGiftLevel = 0;
for (const hero of heroes) {
if (hero.titanGiftLevel > 0) {
maxResetTitanGiftLevel = hero.titanGiftLevel;
break;
}
}
if (userLevel < 30 || maxResetTitanGiftLevel == 0) {
confShow(`${I18N('GOE_NOTHING_TO_RESET')}`);
return;
}
if (maxResetTitanGiftLevel == 30) {
confShow(`${I18N('GOE_IMPOSSIBLE_TO_RESET')}`);
return;
} else {
maxResetTitanGiftLevel = +(await popup.confirm(I18N('GOE_RESET_GIFTS_LIGHT_MESSAGE'), [
{ result: 0, isClose: true },
{ msg: I18N('GOE_RESET_GIFTS'), isInput: true, default: maxResetTitanGiftLevel.toString(), color: 'green' },
//{ msg: I18N('BTN_CANCEL'), result: 0, color: 'red' },
]));
}
if (maxResetTitanGiftLevel == 0) {
return;
}
if (!maxResetTitanGiftLevel || maxResetTitanGiftLevel < 0 || maxResetTitanGiftLevel > 29) {
confShow(`${I18N('GOE_INCORRECT_VALUE')}`);
return;
}
for (const hero of heroes) {
if (hero.titanGiftLevel == 0) {
continue;
}
if (hero.titanGiftLevel > maxResetTitanGiftLevel || hero.titanGiftLevel == 30) {
break;
}
calls.push({ name: 'heroTitanGiftDrop', args: { heroId: hero.id } });
}
if (calls.length == 0) {
confShow(`${I18N('GOE_NOTHING_TO_RESET')}`);
return;
}
await Caller.send(calls);
confShow(`${I18N('GOE_RESULT_RESET_GIFTS', { counter: calls.length })}`);
}
//Сбросить дары стихий 30 уровень
async function resetTitanGifts30LVL() {
const [heroGetAll, user] = await new Caller(['heroGetAll', 'userGetInfo']).execute();
const heroes = Object.values(heroGetAll).sort((a, b) => a.titanGiftLevel - b.titanGiftLevel);
const userLevel = user.level;
const heroesLvl1_29 = Object.values(heroGetAll).filter((e) => e.titanGiftLevel > 0 && e.titanGiftLevel < 30);
const heroesLvl30 = Object.values(heroGetAll)
.filter((e) => e.titanGiftLevel == 30)
.sort((a, b) => a.power - b.power);
let calls = [];
let maxResetTitanGiftLevel = 0;
for (const hero of heroes) {
if (hero.titanGiftLevel > 0) {
maxResetTitanGiftLevel = hero.titanGiftLevel;
break;
}
}
if (userLevel < 30 || maxResetTitanGiftLevel == 0) {
confShow(`${I18N('GOE_NOTHING_TO_RESET')}`);
return;
}
let numberHeroesWithLevel1_29 = heroesLvl1_29.length;
let numberHeroesWithLevel30 = heroesLvl30.length;
let numberHeroesToReset = numberHeroesWithLevel30;
if (numberHeroesWithLevel30 == 0) {
let resultPopup = await popup.confirm(I18N('GOE_EXTREME_DO_NOT_HAVE_HERO_30LVL'), [
{ msg: I18N('GOE_RESET_GIFTS'), result: true, color: 'green' },
{ msg: I18N('BTN_CANCEL'), result: false, color: 'red' },
{ isClose: true, result: false },
]);
if (!resultPopup) {
return;
}
} else {
numberHeroesToReset = +(await popup.confirm(I18N('GOE_RESET_GIFTS_EXTREME_MESSAGE', { level30: numberHeroesWithLevel30 }), [
{ result: 0, isClose: true },
{ msg: I18N('GOE_RESET_GIFTS'), isInput: true, default: numberHeroesToReset.toString(), color: 'green' },
//{ msg: I18N('BTN_CANCEL'), result: 0, color: 'red' },
]));
if (numberHeroesToReset == 0) {
return;
}
if (!numberHeroesToReset || numberHeroesToReset < 0 || numberHeroesToReset > numberHeroesWithLevel30) {
confShow(`${I18N('GOE_INCORRECT_VALUE')}`);
return;
}
}
// 1-29
for (const hero of heroesLvl1_29) {
calls.push({ name: 'heroTitanGiftDrop', args: { heroId: hero.id } });
}
// 30
for (let i = 0; i < numberHeroesToReset; i++) {
calls.push({ name: 'heroTitanGiftDrop', args: { heroId: heroesLvl30[i].id } });
}
if (calls.length == 0) {
confShow(`${I18N('GOE_NOTHING_TO_RESET')}`);
return;
}
await Caller.send(calls);
confShow(
`${I18N('GOE_RESULT_RESET_GIFTS', { counter: calls.length })} ${I18N('GOE_EXTREME_RESULT_RESET_GIFTS', {
counter30: numberHeroesToReset,
})}`
);
}
})();