HwH_Pizza_Style

Automation of actions for the game Hero Wars

  1. // ==UserScript==
  2. // @name HwH_Pizza_Style
  3. // @name:en HwH_Pizza_Style
  4. // @name:ru HwH_Pizza_Style
  5. // @namespace HwH_Pizza_Style
  6. // @version 2.318
  7. // @description Automation of actions for the game Hero Wars
  8. // @description:en Automation of actions for the game Hero Wars
  9. // @description:ru Автоматизация действий для игры Хроники Хаоса
  10. // @author ZingerY, Pizza_clan
  11. // @license Copyright ZingerY
  12. // @homepage https://zingery.ru/scripts/HeroWarsHelper.user.js
  13. // @icon https://zingery.ru/scripts/VaultBoyIco16.ico
  14. // @icon64 https://zingery.ru/scripts/VaultBoyIco64.png
  15. // @match https://www.hero-wars.com/*
  16. // @match https://apps-1701433570146040.apps.fbsbx.com/*
  17. // @run-at document-start
  18. // ==/UserScript==
  19.  
  20. (function() {
  21. /**
  22. * Start script
  23. *
  24. * Стартуем скрипт
  25. */
  26. console.log('%cStart ' + GM_info.script.name + ', v' + GM_info.script.version + ' by ' + GM_info.script.author, 'color: red');
  27. /**
  28. * Script info
  29. *
  30. * Информация о скрипте
  31. */
  32. this.scriptInfo = (({name, version, author, homepage, lastModified}, updateUrl) =>
  33. ({name, version, author, homepage, lastModified, updateUrl}))
  34. (GM_info.script, GM_info.scriptUpdateURL);
  35. this.GM_info = GM_info;
  36. /**
  37. * Information for completing daily quests
  38. *
  39. * Информация для выполнения ежендевных квестов
  40. */
  41. const questsInfo = {};
  42. /**
  43. * Is the game data loaded
  44. *
  45. * Загружены ли данные игры
  46. */
  47. let isLoadGame = false;
  48. /**
  49. * Headers of the last request
  50. *
  51. * Заголовки последнего запроса
  52. */
  53. let lastHeaders = {};
  54. /**
  55. * Information about sent gifts
  56. *
  57. * Информация об отправленных подарках
  58. */
  59. let freebieCheckInfo = null;
  60. /**
  61. * missionTimer
  62. *
  63. * missionTimer
  64. */
  65. let missionBattle = null;
  66. /**
  67. * User data
  68. *
  69. * Данные пользователя
  70. */
  71. let userInfo;
  72. this.isTimeBetweenNewDays = function () {
  73. if (userInfo.timeZone <= 3) {
  74. return false;
  75. }
  76. const nextDayTs = new Date(userInfo.nextDayTs * 1e3);
  77. const nextServerDayTs = new Date(userInfo.nextServerDayTs * 1e3);
  78. if (nextDayTs > nextServerDayTs) {
  79. nextDayTs.setDate(nextDayTs.getDate() - 1);
  80. }
  81. const now = Date.now();
  82. if (now > nextDayTs && now < nextServerDayTs) {
  83. return true;
  84. }
  85. return false;
  86. };
  87.  
  88. function getUserInfo() {
  89. return userInfo;
  90. }
  91. /**
  92. * Original methods for working with AJAX
  93. *
  94. * Оригинальные методы для работы с AJAX
  95. */
  96. const original = {
  97. open: XMLHttpRequest.prototype.open,
  98. send: XMLHttpRequest.prototype.send,
  99. setRequestHeader: XMLHttpRequest.prototype.setRequestHeader,
  100. SendWebSocket: WebSocket.prototype.send,
  101. fetch: fetch,
  102. };
  103.  
  104. // Sentry blocking
  105. // Блокировка наблюдателя
  106. this.fetch = function (url, options) {
  107. /**
  108. * Checking URL for blocking
  109. * Проверяем URL на блокировку
  110. */
  111. if (url.includes('sentry.io')) {
  112. console.log('%cFetch blocked', 'color: red');
  113. console.log(url, options);
  114. const body = {
  115. id: md5(Date.now()),
  116. };
  117. let info = {};
  118. try {
  119. info = JSON.parse(options.body);
  120. } catch (e) {}
  121. if (info.event_id) {
  122. body.id = info.event_id;
  123. }
  124. /**
  125. * Mock response for blocked URL
  126. *
  127. * Мокаем ответ для заблокированного URL
  128. */
  129. const mockResponse = new Response('Custom blocked response', {
  130. status: 200,
  131. headers: { 'Content-Type': 'application/json' },
  132. body,
  133. });
  134. return Promise.resolve(mockResponse);
  135. } else {
  136. /**
  137. * Call the original fetch function for all other URLs
  138. * Вызываем оригинальную функцию fetch для всех других URL
  139. */
  140. return original.fetch.apply(this, arguments);
  141. }
  142. };
  143.  
  144. /**
  145. * Decoder for converting byte data to JSON string
  146. *
  147. * Декодер для перобразования байтовых данных в JSON строку
  148. */
  149. const decoder = new TextDecoder("utf-8");
  150. /**
  151. * Stores a history of requests
  152. *
  153. * Хранит историю запросов
  154. */
  155. let requestHistory = {};
  156. /**
  157. * URL for API requests
  158. *
  159. * URL для запросов к API
  160. */
  161. let apiUrl = '';
  162.  
  163. /**
  164. * Connecting to the game code
  165. *
  166. * Подключение к коду игры
  167. */
  168. this.cheats = new hackGame();
  169. /**
  170. * The function of calculating the results of the battle
  171. *
  172. * Функция расчета результатов боя
  173. */
  174. this.BattleCalc = cheats.BattleCalc;
  175. /**
  176. * Sending a request available through the console
  177. *
  178. * Отправка запроса доступная через консоль
  179. */
  180. this.SendRequest = send;
  181. /**
  182. * Simple combat calculation available through the console
  183. *
  184. * Простой расчет боя доступный через консоль
  185. */
  186. this.Calc = function (data) {
  187. const type = getBattleType(data?.type);
  188. return new Promise((resolve, reject) => {
  189. try {
  190. BattleCalc(data, type, resolve);
  191. } catch (e) {
  192. reject(e);
  193. }
  194. })
  195. }
  196. /**
  197. * Short asynchronous request
  198. * Usage example (returns information about a character):
  199. * const userInfo = await Send('{"calls":[{"name":"userGetInfo","args":{},"ident":"body"}]}')
  200. *
  201. * Короткий асинхронный запрос
  202. * Пример использования (возвращает информацию о персонаже):
  203. * const userInfo = await Send('{"calls":[{"name":"userGetInfo","args":{},"ident":"body"}]}')
  204. */
  205. this.Send = function (json, pr) {
  206. return new Promise((resolve, reject) => {
  207. try {
  208. send(json, resolve, pr);
  209. } catch (e) {
  210. reject(e);
  211. }
  212. })
  213. }
  214.  
  215. this.xyz = (({ name, version, author }) => ({ name, version, author }))(GM_info.script);
  216. const i18nLangData = {
  217. /* English translation by BaBa */
  218. en: {
  219. /* Checkboxes */
  220. SKIP_FIGHTS: 'Skip battle',
  221. SKIP_FIGHTS_TITLE: 'Skip battle in Outland and the arena of the titans, auto-pass in the tower and campaign',
  222. ENDLESS_CARDS: 'Infinite cards',
  223. ENDLESS_CARDS_TITLE: 'Disable Divination Cards wasting',
  224. AUTO_EXPEDITION: 'Auto Expedition',
  225. AUTO_EXPEDITION_TITLE: 'Auto-sending expeditions',
  226. CANCEL_FIGHT: 'Cancel battle',
  227. CANCEL_FIGHT_TITLE: 'Ability to cancel manual combat on GW, CoW and Asgard',
  228. GIFTS: 'Gifts',
  229. GIFTS_TITLE: 'Collect gifts automatically',
  230. BATTLE_RECALCULATION: 'Battle recalculation',
  231. BATTLE_RECALCULATION_TITLE: 'Preliminary calculation of the battle',
  232. QUANTITY_CONTROL: 'Quantity control',
  233. QUANTITY_CONTROL_TITLE: 'Ability to specify the number of opened "lootboxes"',
  234. REPEAT_CAMPAIGN: 'Repeat missions',
  235. REPEAT_CAMPAIGN_TITLE: 'Auto-repeat battles in the campaign',
  236. DISABLE_DONAT: 'Disable donation',
  237. DISABLE_DONAT_TITLE: 'Removes all donation offers',
  238. DAILY_QUESTS: 'Quests',
  239. DAILY_QUESTS_TITLE: 'Complete daily quests',
  240. AUTO_QUIZ: 'AutoQuiz',
  241. AUTO_QUIZ_TITLE: 'Automatically receive correct answers to quiz questions',
  242. SECRET_WEALTH_CHECKBOX: 'Automatic purchase in the store "Secret Wealth" when entering the game',
  243. HIDE_SERVERS: 'Collapse servers',
  244. HIDE_SERVERS_TITLE: 'Hide unused servers',
  245. /* Input fields */
  246. HOW_MUCH_TITANITE: 'How much titanite to farm',
  247. COMBAT_SPEED: 'Combat Speed Multiplier',
  248. NUMBER_OF_TEST: 'Number of test fights',
  249. NUMBER_OF_AUTO_BATTLE: 'Number of auto-battle attempts',
  250. /* Buttons */
  251. RUN_SCRIPT: 'Run the',
  252. TO_DO_EVERYTHING: 'Do All',
  253. TO_DO_EVERYTHING_TITLE: 'Perform multiple actions of your choice',
  254. OUTLAND: 'Outland',
  255. OUTLAND_TITLE: 'Collect Outland',
  256. TITAN_ARENA: 'ToE',
  257. TITAN_ARENA_TITLE: 'Complete the titan arena',
  258. DUNGEON: 'Dungeon',
  259. DUNGEON_TITLE: 'Go through the dungeon',
  260. SEER: 'Seer',
  261. SEER_TITLE: 'Roll the Seer',
  262. TOWER: 'Tower',
  263. TOWER_TITLE: 'Pass the tower',
  264. EXPEDITIONS: 'Expeditions',
  265. EXPEDITIONS_TITLE: 'Sending and collecting expeditions',
  266. SYNC: 'Sync',
  267. SYNC_TITLE: 'Partial synchronization of game data without reloading the page',
  268. ARCHDEMON: 'Archdemon',
  269. FURNACE_OF_SOULS: 'Furnace of souls',
  270. ARCHDEMON_TITLE: 'Hitting kills and collecting rewards',
  271. ESTER_EGGS: 'Easter eggs',
  272. ESTER_EGGS_TITLE: 'Collect all Easter eggs or rewards',
  273. REWARDS: 'Rewards',
  274. REWARDS_TITLE: 'Collect all quest rewards',
  275. MAIL: 'Mail',
  276. MAIL_TITLE: 'Collect all mail, except letters with energy and charges of the portal',
  277. MINIONS: 'Minions',
  278. MINIONS_TITLE: 'Attack minions with saved packs',
  279. ADVENTURE: 'Adventure',
  280. ADVENTURE_TITLE: 'Passes the adventure along the specified route',
  281. STORM: 'Storm',
  282. STORM_TITLE: 'Passes the Storm along the specified route',
  283. SANCTUARY: 'Sanctuary',
  284. SANCTUARY_TITLE: 'Fast travel to Sanctuary',
  285. GUILD_WAR: 'Guild War',
  286. GUILD_WAR_TITLE: 'Fast travel to Guild War',
  287. SECRET_WEALTH: 'Secret Wealth',
  288. SECRET_WEALTH_TITLE: 'Buy something in the store "Secret Wealth"',
  289. /* Misc */
  290. BOTTOM_URLS:
  291. '<a href="https://t.me/+0oMwICyV1aQ1MDAy" target="_blank" title="Telegram"><svg width="20" height="20" style="margin:2px" viewBox="0 0 1e3 1e3" xmlns="http://www.w3.org/2000/svg"><defs><linearGradient id="a" x1="50%" x2="50%" y2="99.258%"><stop stop-color="#2AABEE" offset="0"/><stop stop-color="#229ED9" offset="1"/></linearGradient></defs><g fill-rule="evenodd"><circle cx="500" cy="500" r="500" fill="url(#a)"/><path d="m226.33 494.72c145.76-63.505 242.96-105.37 291.59-125.6 138.86-57.755 167.71-67.787 186.51-68.119 4.1362-0.072862 13.384 0.95221 19.375 5.8132 5.0584 4.1045 6.4501 9.6491 7.1161 13.541 0.666 3.8915 1.4953 12.756 0.83608 19.683-7.5246 79.062-40.084 270.92-56.648 359.47-7.0089 37.469-20.81 50.032-34.17 51.262-29.036 2.6719-51.085-19.189-79.207-37.624-44.007-28.847-68.867-46.804-111.58-74.953-49.366-32.531-17.364-50.411 10.769-79.631 7.3626-7.6471 135.3-124.01 137.77-134.57 0.30968-1.3202 0.59708-6.2414-2.3265-8.8399s-7.2385-1.7099-10.352-1.0032c-4.4137 1.0017-74.715 47.468-210.9 139.4-19.955 13.702-38.029 20.379-54.223 20.029-17.853-0.3857-52.194-10.094-77.723-18.393-31.313-10.178-56.199-15.56-54.032-32.846 1.1287-9.0037 13.528-18.212 37.197-27.624z" fill="#fff"/></g></svg></a><a href="https://www.patreon.com/HeroWarsUserScripts" target="_blank" title="Patreon"><svg width="20" height="20" viewBox="0 0 1080 1080" xmlns="http://www.w3.org/2000/svg"><g fill="#FFF" stroke="None"><path d="m1033 324.45c-0.19-137.9-107.59-250.92-233.6-291.7-156.48-50.64-362.86-43.3-512.28 27.2-181.1 85.46-237.99 272.66-240.11 459.36-1.74 153.5 13.58 557.79 241.62 560.67 169.44 2.15 194.67-216.18 273.07-321.33 55.78-74.81 127.6-95.94 216.01-117.82 151.95-37.61 255.51-157.53 255.29-316.38z"/></g></svg></a>',
  292. GIFTS_SENT: 'Gifts sent!',
  293. DO_YOU_WANT: 'Do you really want to do this?',
  294. BTN_RUN: 'Run',
  295. BTN_CANCEL: 'Cancel',
  296. BTN_OK: 'OK',
  297. MSG_HAVE_BEEN_DEFEATED: 'You have been defeated!',
  298. BTN_AUTO: 'Auto',
  299. MSG_YOU_APPLIED: 'You applied',
  300. MSG_DAMAGE: 'damage',
  301. MSG_CANCEL_AND_STAT: 'Auto (F5) and show statistic',
  302. MSG_REPEAT_MISSION: 'Repeat the mission?',
  303. BTN_REPEAT: 'Repeat',
  304. BTN_NO: 'No',
  305. MSG_SPECIFY_QUANT: 'Specify Quantity:',
  306. BTN_OPEN: 'Open',
  307. QUESTION_COPY: 'Question copied to clipboard',
  308. ANSWER_KNOWN: 'The answer is known',
  309. ANSWER_NOT_KNOWN: 'ATTENTION THE ANSWER IS NOT KNOWN',
  310. BEING_RECALC: 'The battle is being recalculated',
  311. THIS_TIME: 'This time',
  312. VICTORY: '<span style="color:green;">VICTORY</span>',
  313. DEFEAT: '<span style="color:red;">DEFEAT</span>',
  314. CHANCE_TO_WIN: 'Chance to win <span style="color: red;">based on pre-calculation</span>',
  315. OPEN_DOLLS: 'nesting dolls recursively',
  316. SENT_QUESTION: 'Question sent',
  317. SETTINGS: 'Settings',
  318. MSG_BAN_ATTENTION: '<p style="color:red;">Using this feature may result in a ban.</p> Continue?',
  319. BTN_YES_I_AGREE: 'Yes, I understand the risks!',
  320. BTN_NO_I_AM_AGAINST: 'No, I refuse it!',
  321. VALUES: 'Values',
  322. EXPEDITIONS_SENT: 'Expeditions:<br>Collected: {countGet}<br>Sent: {countSend}',
  323. EXPEDITIONS_NOTHING: 'Nothing to collect/send',
  324. EXPEDITIONS_NOTTIME: 'It is not time for expeditions',
  325. TITANIT: 'Titanit',
  326. COMPLETED: 'completed',
  327. FLOOR: 'Floor',
  328. LEVEL: 'Level',
  329. BATTLES: 'battles',
  330. EVENT: 'Event',
  331. NOT_AVAILABLE: 'not available',
  332. NO_HEROES: 'No heroes',
  333. DAMAGE_AMOUNT: 'Damage amount',
  334. NOTHING_TO_COLLECT: 'Nothing to collect',
  335. COLLECTED: 'Collected',
  336. REWARD: 'rewards',
  337. REMAINING_ATTEMPTS: 'Remaining attempts',
  338. BATTLES_CANCELED: 'Battles canceled',
  339. MINION_RAID: 'Minion Raid',
  340. STOPPED: 'Stopped',
  341. REPETITIONS: 'Repetitions',
  342. MISSIONS_PASSED: 'Missions passed',
  343. STOP: 'stop',
  344. TOTAL_OPEN: 'Total open',
  345. OPEN: 'Open',
  346. ROUND_STAT: 'Damage statistics for ',
  347. BATTLE: 'battles',
  348. MINIMUM: 'Minimum',
  349. MAXIMUM: 'Maximum',
  350. AVERAGE: 'Average',
  351. NOT_THIS_TIME: 'Not this time',
  352. RETRY_LIMIT_EXCEEDED: 'Retry limit exceeded',
  353. SUCCESS: 'Success',
  354. RECEIVED: 'Received',
  355. LETTERS: 'letters',
  356. PORTALS: 'portals',
  357. ATTEMPTS: 'attempts',
  358. /* Quests */
  359. QUEST_10001: 'Upgrade the skills of heroes 3 times',
  360. QUEST_10002: 'Complete 10 missions',
  361. QUEST_10003: 'Complete 3 heroic missions',
  362. QUEST_10004: 'Fight 3 times in the Arena or Grand Arena',
  363. QUEST_10006: 'Use the exchange of emeralds 1 time',
  364. QUEST_10007: 'Perform 1 summon in the Solu Atrium',
  365. QUEST_10016: 'Send gifts to guildmates',
  366. QUEST_10018: 'Use an experience potion',
  367. QUEST_10019: 'Open 1 chest in the Tower',
  368. QUEST_10020: 'Open 3 chests in Outland',
  369. QUEST_10021: 'Collect 75 Titanite in the Guild Dungeon',
  370. QUEST_10021: 'Collect 150 Titanite in the Guild Dungeon',
  371. QUEST_10023: 'Upgrade Gift of the Elements by 1 level',
  372. QUEST_10024: 'Level up any artifact once',
  373. QUEST_10025: 'Start Expedition 1',
  374. QUEST_10026: 'Start 4 Expeditions',
  375. QUEST_10027: 'Win 1 battle of the Tournament of Elements',
  376. QUEST_10028: 'Level up any titan artifact',
  377. QUEST_10029: 'Unlock the Orb of Titan Artifacts',
  378. QUEST_10030: 'Upgrade any Skin of any hero 1 time',
  379. QUEST_10031: 'Win 6 battles of the Tournament of Elements',
  380. QUEST_10043: 'Start or Join an Adventure',
  381. QUEST_10044: 'Use Summon Pets 1 time',
  382. QUEST_10046: 'Open 3 chests in Adventure',
  383. QUEST_10047: 'Get 150 Guild Activity Points',
  384. NOTHING_TO_DO: 'Nothing to do',
  385. YOU_CAN_COMPLETE: 'You can complete quests',
  386. BTN_DO_IT: 'Do it',
  387. NOT_QUEST_COMPLETED: 'Not a single quest completed',
  388. COMPLETED_QUESTS: 'Completed quests',
  389. /* everything button */
  390. ASSEMBLE_OUTLAND: 'Assemble Outland',
  391. PASS_THE_TOWER: 'Pass the tower',
  392. CHECK_EXPEDITIONS: 'Check Expeditions',
  393. COMPLETE_TOE: 'Complete ToE',
  394. COMPLETE_DUNGEON: 'Complete the dungeon',
  395. COLLECT_MAIL: 'Collect mail',
  396. COLLECT_MISC: 'Collect some bullshit',
  397. COLLECT_MISC_TITLE: 'Collect Easter Eggs, Skin Gems, Keys, Arena Coins and Soul Crystal',
  398. COLLECT_QUEST_REWARDS: 'Collect quest rewards',
  399. MAKE_A_SYNC: 'Make a sync',
  400.  
  401. RUN_FUNCTION: 'Run the following functions?',
  402. BTN_GO: 'Go!',
  403. PERFORMED: 'Performed',
  404. DONE: 'Done',
  405. ERRORS_OCCURRES: 'Errors occurred while executing',
  406. COPY_ERROR: 'Copy error information to clipboard',
  407. BTN_YES: 'Yes',
  408. ALL_TASK_COMPLETED: 'All tasks completed',
  409.  
  410. UNKNOWN: 'unknown',
  411. ENTER_THE_PATH: 'Enter the path of adventure using commas or dashes',
  412. START_ADVENTURE: 'Start your adventure along this path!',
  413. INCORRECT_WAY: 'Incorrect path in adventure: {from} -> {to}',
  414. BTN_CANCELED: 'Canceled',
  415. MUST_TWO_POINTS: 'The path must contain at least 2 points.',
  416. MUST_ONLY_NUMBERS: 'The path must contain only numbers and commas',
  417. NOT_ON_AN_ADVENTURE: 'You are not on an adventure',
  418. YOU_IN_NOT_ON_THE_WAY: 'Your location is not on the way',
  419. ATTEMPTS_NOT_ENOUGH: 'Your attempts are not enough to complete the path, continue?',
  420. YES_CONTINUE: 'Yes, continue!',
  421. NOT_ENOUGH_AP: 'Not enough action points',
  422. ATTEMPTS_ARE_OVER: 'The attempts are over',
  423. MOVES: 'Moves',
  424. BUFF_GET_ERROR: 'Buff getting error',
  425. BATTLE_END_ERROR: 'Battle end error',
  426. AUTOBOT: 'Autobot',
  427. FAILED_TO_WIN_AUTO: 'Failed to win the auto battle',
  428. ERROR_OF_THE_BATTLE_COPY: 'An error occurred during the passage of the battle<br>Copy the error to the clipboard?',
  429. ERROR_DURING_THE_BATTLE: 'Error during the battle',
  430. NO_CHANCE_WIN: 'No chance of winning this fight: 0/',
  431. LOST_HEROES: 'You have won, but you have lost one or several heroes',
  432. VICTORY_IMPOSSIBLE: 'Is victory impossible, should we focus on the result?',
  433. FIND_COEFF: 'Find the coefficient greater than',
  434. BTN_PASS: 'PASS',
  435. BRAWLS: 'Brawls',
  436. BRAWLS_TITLE: 'Activates the ability to auto-brawl',
  437. START_AUTO_BRAWLS: 'Start Auto Brawls?',
  438. LOSSES: 'Losses',
  439. WINS: 'Wins',
  440. FIGHTS: 'Fights',
  441. STAGE: 'Stage',
  442. DONT_HAVE_LIVES: "You don't have lives",
  443. LIVES: 'Lives',
  444. SECRET_WEALTH_ALREADY: 'Item for Pet Potions already purchased',
  445. SECRET_WEALTH_NOT_ENOUGH: 'Not Enough Pet Potion, You Have {available}, Need {need}',
  446. SECRET_WEALTH_UPGRADE_NEW_PET: 'After purchasing the Pet Potion, it will not be enough to upgrade a new pet',
  447. SECRET_WEALTH_PURCHASED: 'Purchased {count} {name}',
  448. SECRET_WEALTH_CANCELED: 'Secret Wealth: Purchase Canceled',
  449. SECRET_WEALTH_BUY: 'You have {available} Pet Potion.<br>Do you want to buy {countBuy} {name} for {price} Pet Potion?',
  450. DAILY_BONUS: 'Daily bonus',
  451. DO_DAILY_QUESTS: 'Do daily quests',
  452. ACTIONS: 'Actions',
  453. ACTIONS_TITLE: 'Dialog box with various actions',
  454. OTHERS: 'Others',
  455. OTHERS_TITLE: 'Others',
  456. CHOOSE_ACTION: 'Choose an action',
  457. OPEN_LOOTBOX: 'You have {lootBox} boxes, should we open them?',
  458. STAMINA: 'Energy',
  459. BOXES_OVER: 'The boxes are over',
  460. NO_BOXES: 'No boxes',
  461. NO_MORE_ACTIVITY: 'No more activity for items today',
  462. EXCHANGE_ITEMS: 'Exchange items for activity points (max {maxActive})?',
  463. GET_ACTIVITY: 'Get Activity',
  464. NOT_ENOUGH_ITEMS: 'Not enough items',
  465. ACTIVITY_RECEIVED: 'Activity received',
  466. NO_PURCHASABLE_HERO_SOULS: 'No purchasable Hero Souls',
  467. PURCHASED_HERO_SOULS: 'Purchased {countHeroSouls} Hero Souls',
  468. NOT_ENOUGH_EMERALDS_540: 'Not enough emeralds, you need {imgEmerald}540 you have {imgEmerald}{currentStarMoney}',
  469. BUY_OUTLAND_BTN: 'Buy {count} chests {imgEmerald}{countEmerald}',
  470. CHESTS_NOT_AVAILABLE: 'Chests not available',
  471. OUTLAND_CHESTS_RECEIVED: 'Outland chests received',
  472. RAID_NOT_AVAILABLE: 'The raid is not available or there are no spheres',
  473. RAID_ADVENTURE: 'Raid {adventureId} adventure!',
  474. SOMETHING_WENT_WRONG: 'Something went wrong',
  475. ADVENTURE_COMPLETED: 'Adventure {adventureId} completed {times} times',
  476. CLAN_STAT_COPY: 'Clan statistics copied to clipboard',
  477. GET_ENERGY: 'Get Energy',
  478. GET_ENERGY_TITLE: 'Opens platinum boxes one at a time until you get 250 energy',
  479. ITEM_EXCHANGE: 'Item Exchange',
  480. ITEM_EXCHANGE_TITLE: 'Exchanges items for the specified amount of activity',
  481. BUY_SOULS: 'Buy souls',
  482. BUY_SOULS_TITLE: 'Buy hero souls from all available shops',
  483. BUY_OUTLAND: 'Buy Outland',
  484. BUY_OUTLAND_TITLE: 'Buy 9 chests in Outland for 540 emeralds',
  485. RAID: 'Raid',
  486. AUTO_RAID_ADVENTURE: 'Raid adventure',
  487. AUTO_RAID_ADVENTURE_TITLE: 'Raid adventure set number of times',
  488. CLAN_STAT: 'Clan statistics',
  489. CLAN_STAT_TITLE: 'Copies clan statistics to the clipboard',
  490. BTN_AUTO_F5: 'Auto (F5)',
  491. BOSS_DAMAGE: 'Boss Damage: ',
  492. NOTHING_BUY: 'Nothing to buy',
  493. LOTS_BOUGHT: '{countBuy} lots bought for gold',
  494. BUY_FOR_GOLD: 'Buy for gold',
  495. BUY_FOR_GOLD_TITLE: 'Buy items for gold in the Town Shop and in the Pet Soul Stone Shop',
  496. REWARDS_AND_MAIL: 'Rewards and Mail',
  497. REWARDS_AND_MAIL_TITLE: 'Collects rewards and mail',
  498. COLLECT_REWARDS_AND_MAIL: 'Collected {countQuests} rewards and {countMail} letters',
  499. TIMER_ALREADY: 'Timer already started {time}',
  500. NO_ATTEMPTS_TIMER_START: 'No attempts, timer started {time}',
  501. EPIC_BRAWL_RESULT: 'Wins: {wins}/{attempts}, Coins: {coins}, Streak: {progress}/{nextStage} [Close]{end}',
  502. ATTEMPT_ENDED: '<br>Attempts ended, timer started {time}',
  503. EPIC_BRAWL: 'Cosmic Battle',
  504. EPIC_BRAWL_TITLE: 'Spends attempts in the Cosmic Battle',
  505. RELOAD_GAME: 'Reload game',
  506. TIMER: 'Timer:',
  507. SHOW_ERRORS: 'Show errors',
  508. SHOW_ERRORS_TITLE: 'Show server request errors',
  509. ERROR_MSG: 'Error: {name}<br>{description}',
  510. EVENT_AUTO_BOSS:
  511. 'Maximum number of battles for calculation:</br>{length} ∗ {countTestBattle} = {maxCalcBattle}</br>If you have a weak computer, it may take a long time for this, click on the cross to cancel.</br>Should I search for the best pack from all or the first suitable one?',
  512. BEST_SLOW: 'Best (slower)',
  513. FIRST_FAST: 'First (faster)',
  514. FREEZE_INTERFACE: 'Calculating... <br>The interface may freeze.',
  515. ERROR_F12: 'Error, details in the console (F12)',
  516. FAILED_FIND_WIN_PACK: 'Failed to find a winning pack',
  517. BEST_PACK: 'Best pack:',
  518. BOSS_HAS_BEEN_DEF: 'Boss {bossLvl} has been defeated.',
  519. NOT_ENOUGH_ATTEMPTS_BOSS: 'Not enough attempts to defeat boss {bossLvl}, retry?',
  520. BOSS_VICTORY_IMPOSSIBLE:
  521. 'Based on the recalculation of {battles} battles, victory has not been achieved. Would you like to continue the search for a winning battle in real battles?',
  522. BOSS_HAS_BEEN_DEF_TEXT:
  523. 'Boss {bossLvl} defeated in<br>{countBattle}/{countMaxBattle} attempts{winTimer}<br>(Please synchronize or restart the game to update the data)',
  524. MAP: 'Map: ',
  525. PLAYER_POS: 'Player positions:',
  526. NY_GIFTS: 'Gifts',
  527. NY_GIFTS_TITLE: "Open all New Year's gifts",
  528. NY_NO_GIFTS: 'No gifts not received',
  529. NY_GIFTS_COLLECTED: '{count} gifts collected',
  530. CHANGE_MAP: 'Island map',
  531. CHANGE_MAP_TITLE: 'Change island map',
  532. SELECT_ISLAND_MAP: 'Select an island map:',
  533. MAP_NUM: 'Map {num}',
  534. SECRET_WEALTH_SHOP: 'Secret Wealth {name}: ',
  535. SHOPS: 'Shops',
  536. SHOPS_DEFAULT: 'Default',
  537. SHOPS_DEFAULT_TITLE: 'Default stores',
  538. SHOPS_LIST: 'Shops {number}',
  539. SHOPS_LIST_TITLE: 'List of shops {number}',
  540. SHOPS_WARNING:
  541. 'Stores<br><span style="color:red">If you buy brawl store coins for emeralds, you must use them immediately, otherwise they will disappear after restarting the game!</span>',
  542. MINIONS_WARNING: 'The hero packs for attacking minions are incomplete, should I continue?',
  543. FAST_SEASON: 'Fast season',
  544. FAST_SEASON_TITLE: 'Skip the map selection screen in a season',
  545. SET_NUMBER_LEVELS: 'Specify the number of levels:',
  546. POSSIBLE_IMPROVE_LEVELS: 'It is possible to improve only {count} levels.<br>Improving?',
  547. NOT_ENOUGH_RESOURECES: 'Not enough resources',
  548. IMPROVED_LEVELS: 'Improved levels: {count}',
  549. ARTIFACTS_UPGRADE: 'Artifacts Upgrade',
  550. ARTIFACTS_UPGRADE_TITLE: 'Upgrades the specified amount of the cheapest hero artifacts',
  551. SKINS_UPGRADE: 'Skins Upgrade',
  552. SKINS_UPGRADE_TITLE: 'Upgrades the specified amount of the cheapest hero skins',
  553. HINT: '<br>Hint: ',
  554. PICTURE: '<br>Picture: ',
  555. ANSWER: '<br>Answer: ',
  556. NO_HEROES_PACK: 'Fight at least one battle to save the attacking team',
  557. BRAWL_AUTO_PACK: 'Automatic selection of packs',
  558. BRAWL_AUTO_PACK_NOT_CUR_HERO: 'Automatic pack selection is not suitable for the current hero',
  559. BRAWL_DAILY_TASK_COMPLETED: 'Daily task completed, continue attacking?',
  560. CALC_STAT: 'Calculate statistics',
  561. ELEMENT_TOURNAMENT_REWARD: 'Unclaimed bonus for Elemental Tournament',
  562. BTN_TRY_FIX_IT: 'Fix it',
  563. BTN_TRY_FIX_IT_TITLE: 'Enable auto attack combat correction',
  564. DAMAGE_FIXED: 'Damage fixed from {lastDamage} to {maxDamage}!',
  565. DAMAGE_NO_FIXED: 'Failed to fix damage: {lastDamage}',
  566. LETS_FIX: "Let's fix",
  567. COUNT_FIXED: 'For {count} attempts',
  568. DEFEAT_TURN_TIMER: 'Defeat! Turn on the timer to complete the mission?',
  569. SEASON_REWARD: 'Season Rewards',
  570. SEASON_REWARD_TITLE: 'Collects available free rewards from all current seasons',
  571. SEASON_REWARD_COLLECTED: 'Collected {count} season rewards',
  572. SELL_HERO_SOULS: 'Sell ​​souls',
  573. SELL_HERO_SOULS_TITLE: 'Exchanges all absolute star hero souls for gold',
  574. GOLD_RECEIVED: 'Gold received: {gold}',
  575. OPEN_ALL_EQUIP_BOXES: 'Open all Equipment Fragment Box?',
  576. SERVER_NOT_ACCEPT: 'The server did not accept the result',
  577. INVASION_BOSS_BUFF: 'For {bossLvl} boss need buff {needBuff} you have {haveBuff}}',
  578. HERO_POWER: 'Hero Power',
  579. HERO_POWER_TITLE: 'Displays the current and maximum power of heroes',
  580. MAX_POWER_REACHED: 'Maximum power reached: {power}',
  581. CURRENT_POWER: 'Current power: {power}',
  582. POWER_TO_MAX: 'Power left to reach maximum: <span style="color:{color};">{power}</span><br>',
  583. },
  584. ru: {
  585. /* Чекбоксы */
  586. SKIP_FIGHTS: 'Пропуск боев',
  587. SKIP_FIGHTS_TITLE: 'Пропуск боев в запределье и арене титанов, автопропуск в башне и кампании',
  588. ENDLESS_CARDS: 'Бесконечные карты',
  589. ENDLESS_CARDS_TITLE: 'Отключить трату карт предсказаний',
  590. AUTO_EXPEDITION: 'АвтоЭкспедиции',
  591. AUTO_EXPEDITION_TITLE: 'Автоотправка экспедиций',
  592. CANCEL_FIGHT: 'Отмена боя',
  593. CANCEL_FIGHT_TITLE: 'Возможность отмены ручного боя на ВГ, СМ и в Асгарде',
  594. GIFTS: 'Подарки',
  595. GIFTS_TITLE: 'Собирать подарки автоматически',
  596. BATTLE_RECALCULATION: 'Прерасчет боя',
  597. BATTLE_RECALCULATION_TITLE: 'Предварительный расчет боя',
  598. QUANTITY_CONTROL: 'Контроль кол-ва',
  599. QUANTITY_CONTROL_TITLE: 'Возможность указывать количество открываемых "лутбоксов"',
  600. REPEAT_CAMPAIGN: 'Повтор в кампании',
  601. REPEAT_CAMPAIGN_TITLE: 'Автоповтор боев в кампании',
  602. DISABLE_DONAT: 'Отключить донат',
  603. DISABLE_DONAT_TITLE: 'Убирает все предложения доната',
  604. DAILY_QUESTS: 'Квесты',
  605. DAILY_QUESTS_TITLE: 'Выполнять ежедневные квесты',
  606. AUTO_QUIZ: 'АвтоВикторина',
  607. AUTO_QUIZ_TITLE: 'Автоматическое получение правильных ответов на вопросы викторины',
  608. SECRET_WEALTH_CHECKBOX: 'Автоматическая покупка в магазине "Тайное Богатство" при заходе в игру',
  609. HIDE_SERVERS: 'Свернуть сервера',
  610. HIDE_SERVERS_TITLE: 'Скрывать неиспользуемые сервера',
  611. /* Поля ввода */
  612. HOW_MUCH_TITANITE: 'Сколько фармим титанита',
  613. COMBAT_SPEED: 'Множитель ускорения боя',
  614. NUMBER_OF_TEST: 'Количество тестовых боев',
  615. NUMBER_OF_AUTO_BATTLE: 'Количество попыток автобоев',
  616. /* Кнопки */
  617. RUN_SCRIPT: 'Запустить скрипт',
  618. TO_DO_EVERYTHING: 'Сделать все',
  619. TO_DO_EVERYTHING_TITLE: 'Выполнить несколько действий',
  620. OUTLAND: 'Запределье',
  621. OUTLAND_TITLE: 'Собрать Запределье',
  622. TITAN_ARENA: 'Турнир Стихий',
  623. TITAN_ARENA_TITLE: 'Автопрохождение Турнира Стихий',
  624. DUNGEON: 'Подземелье',
  625. DUNGEON_TITLE: 'Автопрохождение подземелья',
  626. SEER: 'Провидец',
  627. SEER_TITLE: 'Покрутить Провидца',
  628. TOWER: 'Башня',
  629. TOWER_TITLE: 'Автопрохождение башни',
  630. EXPEDITIONS: 'Экспедиции',
  631. EXPEDITIONS_TITLE: 'Отправка и сбор экспедиций',
  632. SYNC: 'Синхронизация',
  633. SYNC_TITLE: 'Частичная синхронизация данных игры без перезагрузки сатраницы',
  634. ARCHDEMON: 'Архидемон',
  635. FURNACE_OF_SOULS: 'Горнило душ',
  636. ARCHDEMON_TITLE: 'Набивает килы и собирает награду',
  637. ESTER_EGGS: 'Пасхалки',
  638. ESTER_EGGS_TITLE: 'Собрать все пасхалки или награды',
  639. REWARDS: 'Награды',
  640. REWARDS_TITLE: 'Собрать все награды за задания',
  641. MAIL: 'Почта',
  642. MAIL_TITLE: 'Собрать всю почту, кроме писем с энергией и зарядами портала',
  643. MINIONS: 'Прислужники',
  644. MINIONS_TITLE: 'Атакует прислужников сохраннеными пачками',
  645. ADVENTURE: 'Приключение',
  646. ADVENTURE_TITLE: 'Проходит приключение по указанному маршруту',
  647. STORM: 'Буря',
  648. STORM_TITLE: 'Проходит бурю по указанному маршруту',
  649. SANCTUARY: 'Святилище',
  650. SANCTUARY_TITLE: 'Быстрый переход к Святилищу',
  651. GUILD_WAR: 'Война гильдий',
  652. GUILD_WAR_TITLE: 'Быстрый переход к Войне гильдий',
  653. SECRET_WEALTH: 'Тайное богатство',
  654. SECRET_WEALTH_TITLE: 'Купить что-то в магазине "Тайное богатство"',
  655. /* Разное */
  656. BOTTOM_URLS:
  657. '<a href="https://t.me/+q6gAGCRpwyFkNTYy" target="_blank" title="Telegram"><svg width="20" height="20" style="margin:2px" viewBox="0 0 1e3 1e3" xmlns="http://www.w3.org/2000/svg"><defs><linearGradient id="a" x1="50%" x2="50%" y2="99.258%"><stop stop-color="#2AABEE" offset="0"/><stop stop-color="#229ED9" offset="1"/></linearGradient></defs><g fill-rule="evenodd"><circle cx="500" cy="500" r="500" fill="url(#a)"/><path d="m226.33 494.72c145.76-63.505 242.96-105.37 291.59-125.6 138.86-57.755 167.71-67.787 186.51-68.119 4.1362-0.072862 13.384 0.95221 19.375 5.8132 5.0584 4.1045 6.4501 9.6491 7.1161 13.541 0.666 3.8915 1.4953 12.756 0.83608 19.683-7.5246 79.062-40.084 270.92-56.648 359.47-7.0089 37.469-20.81 50.032-34.17 51.262-29.036 2.6719-51.085-19.189-79.207-37.624-44.007-28.847-68.867-46.804-111.58-74.953-49.366-32.531-17.364-50.411 10.769-79.631 7.3626-7.6471 135.3-124.01 137.77-134.57 0.30968-1.3202 0.59708-6.2414-2.3265-8.8399s-7.2385-1.7099-10.352-1.0032c-4.4137 1.0017-74.715 47.468-210.9 139.4-19.955 13.702-38.029 20.379-54.223 20.029-17.853-0.3857-52.194-10.094-77.723-18.393-31.313-10.178-56.199-15.56-54.032-32.846 1.1287-9.0037 13.528-18.212 37.197-27.624z" fill="#fff"/></g></svg></a><a href="https://vk.com/invite/YNPxKGX" target="_blank" title="Вконтакте"><svg width="20" height="20" style="margin:2px" viewBox="0 0 101 100" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#a)"><path d="M0.5 48C0.5 25.3726 0.5 14.0589 7.52944 7.02944C14.5589 0 25.8726 0 48.5 0H52.5C75.1274 0 86.4411 0 93.4706 7.02944C100.5 14.0589 100.5 25.3726 100.5 48V52C100.5 74.6274 100.5 85.9411 93.4706 92.9706C86.4411 100 75.1274 100 52.5 100H48.5C25.8726 100 14.5589 100 7.52944 92.9706C0.5 85.9411 0.5 74.6274 0.5 52V48Z" fill="#07f"/><path d="m53.708 72.042c-22.792 0-35.792-15.625-36.333-41.625h11.417c0.375 19.083 8.7915 27.167 15.458 28.833v-28.833h10.75v16.458c6.5833-0.7083 13.499-8.2082 15.832-16.458h10.75c-1.7917 10.167-9.2917 17.667-14.625 20.75 5.3333 2.5 13.875 9.0417 17.125 20.875h-11.834c-2.5417-7.9167-8.8745-14.042-17.25-14.875v14.875h-1.2919z" fill="#fff"/></g><defs><clipPath id="a"><rect transform="translate(.5)" width="100" height="100" fill="#fff"/></clipPath></defs></svg></a>',
  658. GIFTS_SENT: 'Подарки отправлены!',
  659. DO_YOU_WANT: 'Вы действительно хотите это сделать?',
  660. BTN_RUN: 'Запускай',
  661. BTN_CANCEL: 'Отмена',
  662. BTN_OK: 'Ок',
  663. MSG_HAVE_BEEN_DEFEATED: 'Вы потерпели поражение!',
  664. BTN_AUTO: 'Авто',
  665. MSG_YOU_APPLIED: 'Вы нанесли',
  666. MSG_DAMAGE: 'урона',
  667. MSG_CANCEL_AND_STAT: 'Авто (F5) и показать Статистику',
  668. MSG_REPEAT_MISSION: 'Повторить миссию?',
  669. BTN_REPEAT: 'Повторить',
  670. BTN_NO: 'Нет',
  671. MSG_SPECIFY_QUANT: 'Указать количество:',
  672. BTN_OPEN: 'Открыть',
  673. QUESTION_COPY: 'Вопрос скопирован в буфер обмена',
  674. ANSWER_KNOWN: 'Ответ известен',
  675. ANSWER_NOT_KNOWN: 'ВНИМАНИЕ ОТВЕТ НЕ ИЗВЕСТЕН',
  676. BEING_RECALC: 'Идет прерасчет боя',
  677. THIS_TIME: 'На этот раз',
  678. VICTORY: '<span style="color:green;">ПОБЕДА</span>',
  679. DEFEAT: '<span style="color:red;">ПОРАЖЕНИЕ</span>',
  680. CHANCE_TO_WIN: 'Шансы на победу <span style="color:red;">на основе прерасчета</span>',
  681. OPEN_DOLLS: 'матрешек рекурсивно',
  682. SENT_QUESTION: 'Вопрос отправлен',
  683. SETTINGS: 'Настройки',
  684. MSG_BAN_ATTENTION: '<p style="color:red;">Использование этой функции может привести к бану.</p> Продолжить?',
  685. BTN_YES_I_AGREE: 'Да, я беру на себя все риски!',
  686. BTN_NO_I_AM_AGAINST: 'Нет, я отказываюсь от этого!',
  687. VALUES: 'Значения',
  688. EXPEDITIONS_SENT: 'Экспедиции:<br>Собрано: {countGet}<br>Отправлено: {countSend}',
  689. EXPEDITIONS_NOTHING: 'Нечего собирать/отправлять',
  690. EXPEDITIONS_NOTTIME: 'Не время для экспедиций',
  691. TITANIT: 'Титанит',
  692. COMPLETED: 'завершено',
  693. FLOOR: 'Этаж',
  694. LEVEL: 'Уровень',
  695. BATTLES: 'бои',
  696. EVENT: 'Эвент',
  697. NOT_AVAILABLE: 'недоступен',
  698. NO_HEROES: 'Нет героев',
  699. DAMAGE_AMOUNT: 'Количество урона',
  700. NOTHING_TO_COLLECT: 'Нечего собирать',
  701. COLLECTED: 'Собрано',
  702. REWARD: 'наград',
  703. REMAINING_ATTEMPTS: 'Осталось попыток',
  704. BATTLES_CANCELED: 'Битв отменено',
  705. MINION_RAID: 'Рейд прислужников',
  706. STOPPED: 'Остановлено',
  707. REPETITIONS: 'Повторений',
  708. MISSIONS_PASSED: 'Миссий пройдено',
  709. STOP: 'остановить',
  710. TOTAL_OPEN: 'Всего открыто',
  711. OPEN: 'Открыто',
  712. ROUND_STAT: 'Статистика урона за',
  713. BATTLE: 'боев',
  714. MINIMUM: 'Минимальный',
  715. MAXIMUM: 'Максимальный',
  716. AVERAGE: 'Средний',
  717. NOT_THIS_TIME: 'Не в этот раз',
  718. RETRY_LIMIT_EXCEEDED: 'Превышен лимит попыток',
  719. SUCCESS: 'Успех',
  720. RECEIVED: 'Получено',
  721. LETTERS: 'писем',
  722. PORTALS: 'порталов',
  723. ATTEMPTS: 'попыток',
  724. QUEST_10001: 'Улучши умения героев 3 раза',
  725. QUEST_10002: 'Пройди 10 миссий',
  726. QUEST_10003: 'Пройди 3 героические миссии',
  727. QUEST_10004: 'Сразись 3 раза на Арене или Гранд Арене',
  728. QUEST_10006: 'Используй обмен изумрудов 1 раз',
  729. QUEST_10007: 'Соверши 1 призыв в Атриуме Душ',
  730. QUEST_10016: 'Отправь подарки согильдийцам',
  731. QUEST_10018: 'Используй зелье опыта',
  732. QUEST_10019: 'Открой 1 сундук в Башне',
  733. QUEST_10020: 'Открой 3 сундука в Запределье',
  734. QUEST_10021: 'Собери 75 Титанита в Подземелье Гильдии',
  735. QUEST_10021: 'Собери 150 Титанита в Подземелье Гильдии',
  736. QUEST_10023: 'Прокачай Дар Стихий на 1 уровень',
  737. QUEST_10024: 'Повысь уровень любого артефакта один раз',
  738. QUEST_10025: 'Начни 1 Экспедицию',
  739. QUEST_10026: 'Начни 4 Экспедиции',
  740. QUEST_10027: 'Победи в 1 бою Турнира Стихий',
  741. QUEST_10028: 'Повысь уровень любого артефакта титанов',
  742. QUEST_10029: 'Открой сферу артефактов титанов',
  743. QUEST_10030: 'Улучши облик любого героя 1 раз',
  744. QUEST_10031: 'Победи в 6 боях Турнира Стихий',
  745. QUEST_10043: 'Начни или присоеденись к Приключению',
  746. QUEST_10044: 'Воспользуйся призывом питомцев 1 раз',
  747. QUEST_10046: 'Открой 3 сундука в Приключениях',
  748. QUEST_10047: 'Набери 150 очков активности в Гильдии',
  749. NOTHING_TO_DO: 'Нечего выполнять',
  750. YOU_CAN_COMPLETE: 'Можно выполнить квесты',
  751. BTN_DO_IT: 'Выполняй',
  752. NOT_QUEST_COMPLETED: 'Ни одного квеста не выполенно',
  753. COMPLETED_QUESTS: 'Выполнено квестов',
  754. /* everything button */
  755. ASSEMBLE_OUTLAND: 'Собрать Запределье',
  756. PASS_THE_TOWER: 'Пройти башню',
  757. CHECK_EXPEDITIONS: 'Проверить экспедиции',
  758. COMPLETE_TOE: 'Пройти Турнир Стихий',
  759. COMPLETE_DUNGEON: 'Пройти подземелье',
  760. COLLECT_MAIL: 'Собрать почту',
  761. COLLECT_MISC: 'Собрать всякую херню',
  762. COLLECT_MISC_TITLE: 'Собрать пасхалки, камни облика, ключи, монеты арены и Хрусталь души',
  763. COLLECT_QUEST_REWARDS: 'Собрать награды за квесты',
  764. MAKE_A_SYNC: 'Сделать синхронизацию',
  765.  
  766. RUN_FUNCTION: 'Выполнить следующие функции?',
  767. BTN_GO: 'Погнали!',
  768. PERFORMED: 'Выполняется',
  769. DONE: 'Выполнено',
  770. ERRORS_OCCURRES: 'Призошли ошибки при выполнении',
  771. COPY_ERROR: 'Скопировать в буфер информацию об ошибке',
  772. BTN_YES: 'Да',
  773. ALL_TASK_COMPLETED: 'Все задачи выполнены',
  774.  
  775. UNKNOWN: 'Неизвестно',
  776. ENTER_THE_PATH: 'Введите путь приключения через запятые или дефисы',
  777. START_ADVENTURE: 'Начать приключение по этому пути!',
  778. INCORRECT_WAY: 'Неверный путь в приключении: {from} -> {to}',
  779. BTN_CANCELED: 'Отменено',
  780. MUST_TWO_POINTS: 'Путь должен состоять минимум из 2х точек',
  781. MUST_ONLY_NUMBERS: 'Путь должен содержать только цифры и запятые',
  782. NOT_ON_AN_ADVENTURE: 'Вы не в приключении',
  783. YOU_IN_NOT_ON_THE_WAY: 'Указанный путь должен включать точку вашего положения',
  784. ATTEMPTS_NOT_ENOUGH: 'Ваших попыток не достаточно для завершения пути, продолжить?',
  785. YES_CONTINUE: 'Да, продолжай!',
  786. NOT_ENOUGH_AP: 'Попыток не достаточно',
  787. ATTEMPTS_ARE_OVER: 'Попытки закончились',
  788. MOVES: 'Ходы',
  789. BUFF_GET_ERROR: 'Ошибка при получении бафа',
  790. BATTLE_END_ERROR: 'Ошибка завершения боя',
  791. AUTOBOT: 'АвтоБой',
  792. FAILED_TO_WIN_AUTO: 'Не удалось победить в автобою',
  793. ERROR_OF_THE_BATTLE_COPY: 'Призошли ошибка в процессе прохождения боя<br>Скопировать ошибку в буфер обмена?',
  794. ERROR_DURING_THE_BATTLE: 'Ошибка в процессе прохождения боя',
  795. NO_CHANCE_WIN: 'Нет шансов победить в этом бою: 0/',
  796. LOST_HEROES: 'Вы победили, но потеряли одного или несколько героев!',
  797. VICTORY_IMPOSSIBLE: 'Победа не возможна, бъем на результат?',
  798. FIND_COEFF: 'Поиск коэффициента больше чем',
  799. BTN_PASS: 'ПРОПУСК',
  800. BRAWLS: 'Потасовки',
  801. BRAWLS_TITLE: 'Включает возможность автопотасовок',
  802. START_AUTO_BRAWLS: 'Запустить Автопотасовки?',
  803. LOSSES: 'Поражений',
  804. WINS: 'Побед',
  805. FIGHTS: 'Боев',
  806. STAGE: 'Стадия',
  807. DONT_HAVE_LIVES: 'У Вас нет жизней',
  808. LIVES: 'Жизни',
  809. SECRET_WEALTH_ALREADY: 'товар за Зелья питомцев уже куплен',
  810. SECRET_WEALTH_NOT_ENOUGH: 'Не достаточно Зелье Питомца, у Вас {available}, нужно {need}',
  811. SECRET_WEALTH_UPGRADE_NEW_PET: 'После покупки Зелье Питомца будет не достаточно для прокачки нового питомца',
  812. SECRET_WEALTH_PURCHASED: 'Куплено {count} {name}',
  813. SECRET_WEALTH_CANCELED: 'Тайное богатство: покупка отменена',
  814. SECRET_WEALTH_BUY: 'У вас {available} Зелье Питомца.<br>Вы хотите купить {countBuy} {name} за {price} Зелье Питомца?',
  815. DAILY_BONUS: 'Ежедневная награда',
  816. DO_DAILY_QUESTS: 'Сделать ежедневные квесты',
  817. ACTIONS: 'Действия',
  818. ACTIONS_TITLE: 'Диалоговое окно с различными действиями',
  819. OTHERS: 'Разное',
  820. OTHERS_TITLE: 'Диалоговое окно с дополнительными различными действиями',
  821. CHOOSE_ACTION: 'Выберите действие',
  822. OPEN_LOOTBOX: 'У Вас {lootBox} ящиков, откываем?',
  823. STAMINA: 'Энергия',
  824. BOXES_OVER: 'Ящики закончились',
  825. NO_BOXES: 'Нет ящиков',
  826. NO_MORE_ACTIVITY: 'Больше активности за предметы сегодня не получить',
  827. EXCHANGE_ITEMS: 'Обменять предметы на очки активности (не более {maxActive})?',
  828. GET_ACTIVITY: 'Получить активность',
  829. NOT_ENOUGH_ITEMS: 'Предметов недостаточно',
  830. ACTIVITY_RECEIVED: 'Получено активности',
  831. NO_PURCHASABLE_HERO_SOULS: 'Нет доступных для покупки душ героев',
  832. PURCHASED_HERO_SOULS: 'Куплено {countHeroSouls} душ героев',
  833. NOT_ENOUGH_EMERALDS_540: 'Недостаточно изюма, нужно {imgEmerald}540 у Вас {imgEmerald}{currentStarMoney}',
  834. BUY_OUTLAND_BTN: 'Купить {count} сундуков {imgEmerald}{countEmerald}',
  835. CHESTS_NOT_AVAILABLE: 'Сундуки не доступны',
  836. OUTLAND_CHESTS_RECEIVED: 'Получено сундуков Запределья',
  837. RAID_NOT_AVAILABLE: 'Рейд не доступен или сфер нет',
  838. RAID_ADVENTURE: 'Рейд {adventureId} приключения!',
  839. SOMETHING_WENT_WRONG: 'Что-то пошло не так',
  840. ADVENTURE_COMPLETED: 'Приключение {adventureId} пройдено {times} раз',
  841. CLAN_STAT_COPY: 'Клановая статистика скопирована в буфер обмена',
  842. GET_ENERGY: 'Получить энергию',
  843. GET_ENERGY_TITLE: 'Открывает платиновые шкатулки по одной до получения 250 энергии',
  844. ITEM_EXCHANGE: 'Обмен предметов',
  845. ITEM_EXCHANGE_TITLE: 'Обменивает предметы на указанное количество активности',
  846. BUY_SOULS: 'Купить души',
  847. BUY_SOULS_TITLE: 'Купить души героев из всех доступных магазинов',
  848. BUY_OUTLAND: 'Купить Запределье',
  849. BUY_OUTLAND_TITLE: 'Купить 9 сундуков в Запределье за 540 изумрудов',
  850. RAID: 'Рейд',
  851. AUTO_RAID_ADVENTURE: 'Рейд приключения',
  852. AUTO_RAID_ADVENTURE_TITLE: 'Рейд приключения заданное количество раз',
  853. CLAN_STAT: 'Клановая статистика',
  854. CLAN_STAT_TITLE: 'Копирует клановую статистику в буфер обмена',
  855. BTN_AUTO_F5: 'Авто (F5)',
  856. BOSS_DAMAGE: 'Урон по боссу: ',
  857. NOTHING_BUY: 'Нечего покупать',
  858. LOTS_BOUGHT: 'За золото куплено {countBuy} лотов',
  859. BUY_FOR_GOLD: 'Скупить за золото',
  860. BUY_FOR_GOLD_TITLE: 'Скупить предметы за золото в Городской лавке и в магазине Камней Душ Питомцев',
  861. REWARDS_AND_MAIL: 'Награды и почта',
  862. REWARDS_AND_MAIL_TITLE: 'Собирает награды и почту',
  863. COLLECT_REWARDS_AND_MAIL: 'Собрано {countQuests} наград и {countMail} писем',
  864. TIMER_ALREADY: 'Таймер уже запущен {time}',
  865. NO_ATTEMPTS_TIMER_START: 'Попыток нет, запущен таймер {time}',
  866. EPIC_BRAWL_RESULT: '{i} Победы: {wins}/{attempts}, Монеты: {coins}, Серия: {progress}/{nextStage} [Закрыть]{end}',
  867. ATTEMPT_ENDED: '<br>Попытки закончились, запущен таймер {time}',
  868. EPIC_BRAWL: 'Вселенская битва',
  869. EPIC_BRAWL_TITLE: 'Тратит попытки во Вселенской битве',
  870. RELOAD_GAME: 'Перезагрузить игру',
  871. TIMER: 'Таймер:',
  872. SHOW_ERRORS: 'Отображать ошибки',
  873. SHOW_ERRORS_TITLE: 'Отображать ошибки запросов к серверу',
  874. ERROR_MSG: 'Ошибка: {name}<br>{description}',
  875. EVENT_AUTO_BOSS:
  876. 'Максимальное количество боев для расчета:</br>{length} * {countTestBattle} = {maxCalcBattle}</br>Если у Вас слабый компьютер на это может потребоваться много времени, нажмите крестик для отмены.</br>Искать лучший пак из всех или первый подходящий?',
  877. BEST_SLOW: 'Лучший (медленее)',
  878. FIRST_FAST: 'Первый (быстрее)',
  879. FREEZE_INTERFACE: 'Идет расчет... <br> Интерфейс может зависнуть.',
  880. ERROR_F12: 'Ошибка, подробности в консоли (F12)',
  881. FAILED_FIND_WIN_PACK: 'Победный пак найти не удалось',
  882. BEST_PACK: 'Наилучший пак: ',
  883. BOSS_HAS_BEEN_DEF: 'Босс {bossLvl} побежден',
  884. NOT_ENOUGH_ATTEMPTS_BOSS: 'Для победы босса ${bossLvl} не хватило попыток, повторить?',
  885. BOSS_VICTORY_IMPOSSIBLE:
  886. 'По результатам прерасчета {battles} боев победу получить не удалось. Вы хотите продолжить поиск победного боя на реальных боях?',
  887. BOSS_HAS_BEEN_DEF_TEXT:
  888. 'Босс {bossLvl} побежден за<br>{countBattle}/{countMaxBattle} попыток{winTimer}<br>(Сделайте синхронизацию или перезагрузите игру для обновления данных)',
  889. MAP: 'Карта: ',
  890. PLAYER_POS: 'Позиции игроков:',
  891. NY_GIFTS: 'Подарки',
  892. NY_GIFTS_TITLE: 'Открыть все новогодние подарки',
  893. NY_NO_GIFTS: 'Нет не полученных подарков',
  894. NY_GIFTS_COLLECTED: 'Собрано {count} подарков',
  895. CHANGE_MAP: 'Карта острова',
  896. CHANGE_MAP_TITLE: 'Сменить карту острова',
  897. SELECT_ISLAND_MAP: 'Выберите карту острова:',
  898. MAP_NUM: 'Карта {num}',
  899. SECRET_WEALTH_SHOP: 'Тайное богатство {name}: ',
  900. SHOPS: 'Магазины',
  901. SHOPS_DEFAULT: 'Стандартные',
  902. SHOPS_DEFAULT_TITLE: 'Стандартные магазины',
  903. SHOPS_LIST: 'Магазины {number}',
  904. SHOPS_LIST_TITLE: 'Список магазинов {number}',
  905. SHOPS_WARNING:
  906. 'Магазины<br><span style="color:red">Если Вы купите монеты магазинов потасовок за изумруды, то их надо использовать сразу, иначе после перезагрузки игры они пропадут!</span>',
  907. MINIONS_WARNING: 'Пачки героев для атаки приспешников неполные, продолжить?',
  908. FAST_SEASON: 'Быстрый сезон',
  909. FAST_SEASON_TITLE: 'Пропуск экрана с выбором карты в сезоне',
  910. SET_NUMBER_LEVELS: 'Указать колличество уровней:',
  911. POSSIBLE_IMPROVE_LEVELS: 'Возможно улучшить только {count} уровней.<br>Улучшаем?',
  912. NOT_ENOUGH_RESOURECES: 'Не хватает ресурсов',
  913. IMPROVED_LEVELS: 'Улучшено уровней: {count}',
  914. ARTIFACTS_UPGRADE: 'Улучшение артефактов',
  915. ARTIFACTS_UPGRADE_TITLE: 'Улучшает указанное количество самых дешевых артефактов героев',
  916. SKINS_UPGRADE: 'Улучшение обликов',
  917. SKINS_UPGRADE_TITLE: 'Улучшает указанное количество самых дешевых обликов героев',
  918. HINT: '<br>Подсказка: ',
  919. PICTURE: '<br>На картинке: ',
  920. ANSWER: '<br>Ответ: ',
  921. NO_HEROES_PACK: 'Проведите хотя бы один бой для сохранения атакующей команды',
  922. BRAWL_AUTO_PACK: 'Автоподбор пачки',
  923. BRAWL_AUTO_PACK_NOT_CUR_HERO: 'Автоматический подбор пачки не подходит для текущего героя',
  924. BRAWL_DAILY_TASK_COMPLETED: 'Ежедневное задание выполнено, продолжить атаку?',
  925. CALC_STAT: 'Посчитать статистику',
  926. ELEMENT_TOURNAMENT_REWARD: 'Несобранная награда за Турнир Стихий',
  927. BTN_TRY_FIX_IT: 'Исправить',
  928. BTN_TRY_FIX_IT_TITLE: 'Включить исправление боев при автоатаке',
  929. DAMAGE_FIXED: 'Урон исправлен с {lastDamage} до {maxDamage}!',
  930. DAMAGE_NO_FIXED: 'Не удалось исправить урон: {lastDamage}',
  931. LETS_FIX: 'Исправляем',
  932. COUNT_FIXED: 'За {count} попыток',
  933. DEFEAT_TURN_TIMER: 'Поражение! Включить таймер для завершения миссии?',
  934. SEASON_REWARD: 'Награды сезонов',
  935. SEASON_REWARD_TITLE: 'Собирает доступные бесплатные награды со всех текущих сезонов',
  936. SEASON_REWARD_COLLECTED: 'Собрано {count} наград сезонов',
  937. SELL_HERO_SOULS: 'Продать души',
  938. SELL_HERO_SOULS_TITLE: 'Обменивает все души героев с абсолютной звездой на золото',
  939. GOLD_RECEIVED: 'Получено золота: {gold}',
  940. OPEN_ALL_EQUIP_BOXES: 'Открыть все ящики фрагментов экипировки?',
  941. SERVER_NOT_ACCEPT: 'Сервер не принял результат',
  942. INVASION_BOSS_BUFF: 'Для {bossLvl} босса нужен баф {needBuff} у вас {haveBuff}',
  943. HERO_POWER: 'Сила героев',
  944. HERO_POWER_TITLE: 'Отображает текущую и максимальную силу героев',
  945. MAX_POWER_REACHED: 'Максимальная достигнутая мощь: {power}',
  946. CURRENT_POWER: 'Текущая мощь: {power}',
  947. POWER_TO_MAX: 'До максимума мощи осталось: <span style="color:{color};">{power}</span><br>',
  948. },
  949. };
  950.  
  951. function getLang() {
  952. let lang = '';
  953. if (typeof NXFlashVars !== 'undefined') {
  954. lang = NXFlashVars.interface_lang
  955. }
  956. if (!lang) {
  957. lang = (navigator.language || navigator.userLanguage).substr(0, 2);
  958. }
  959. if (lang == 'ru') {
  960. return lang;
  961. }
  962. return 'en';
  963. }
  964.  
  965. this.I18N = function (constant, replace) {
  966. const selectLang = getLang();
  967. if (constant && constant in i18nLangData[selectLang]) {
  968. const result = i18nLangData[selectLang][constant];
  969. if (replace) {
  970. return result.sprintf(replace);
  971. }
  972. return result;
  973. }
  974. return `% ${constant} %`;
  975. };
  976.  
  977. String.prototype.sprintf = String.prototype.sprintf ||
  978. function () {
  979. "use strict";
  980. var str = this.toString();
  981. if (arguments.length) {
  982. var t = typeof arguments[0];
  983. var key;
  984. var args = ("string" === t || "number" === t) ?
  985. Array.prototype.slice.call(arguments)
  986. : arguments[0];
  987.  
  988. for (key in args) {
  989. str = str.replace(new RegExp("\\{" + key + "\\}", "gi"), args[key]);
  990. }
  991. }
  992.  
  993. return str;
  994. };
  995.  
  996. /**
  997. * Checkboxes
  998. *
  999. * Чекбоксы
  1000. */
  1001. const checkboxes = {
  1002. passBattle: {
  1003. label: I18N('SKIP_FIGHTS'),
  1004. cbox: null,
  1005. title: I18N('SKIP_FIGHTS_TITLE'),
  1006. default: true,
  1007. },
  1008. sendExpedition: {
  1009. label: I18N('AUTO_EXPEDITION'),
  1010. cbox: null,
  1011. title: I18N('AUTO_EXPEDITION_TITLE'),
  1012. default: true,
  1013. },
  1014. cancelBattle: {
  1015. label: I18N('CANCEL_FIGHT'),
  1016. cbox: null,
  1017. title: I18N('CANCEL_FIGHT_TITLE'),
  1018. default: true,
  1019. },
  1020. preCalcBattle: {
  1021. label: I18N('BATTLE_RECALCULATION'),
  1022. cbox: null,
  1023. title: I18N('BATTLE_RECALCULATION_TITLE'),
  1024. default: true,
  1025. },
  1026. countControl: {
  1027. label: I18N('QUANTITY_CONTROL'),
  1028. cbox: null,
  1029. title: I18N('QUANTITY_CONTROL_TITLE'),
  1030. default: true,
  1031. },
  1032. repeatMission: {
  1033. label: I18N('REPEAT_CAMPAIGN'),
  1034. cbox: null,
  1035. title: I18N('REPEAT_CAMPAIGN_TITLE'),
  1036. default: false,
  1037. },
  1038. noOfferDonat: {
  1039. label: I18N('DISABLE_DONAT'),
  1040. cbox: null,
  1041. title: I18N('DISABLE_DONAT_TITLE'),
  1042. /**
  1043. * A crutch to get the field before getting the character id
  1044. *
  1045. * Костыль чтоб получать поле до получения id персонажа
  1046. */
  1047. default: (() => {
  1048. $result = false;
  1049. try {
  1050. $result = JSON.parse(localStorage[GM_info.script.name + ':noOfferDonat']);
  1051. } catch (e) {
  1052. $result = false;
  1053. }
  1054. return $result || false;
  1055. })(),
  1056. },
  1057. dailyQuests: {
  1058. label: I18N('DAILY_QUESTS'),
  1059. cbox: null,
  1060. title: I18N('DAILY_QUESTS_TITLE'),
  1061. default: true,
  1062. },
  1063. // Потасовки
  1064. autoBrawls: {
  1065. label: I18N('BRAWLS'),
  1066. cbox: null,
  1067. title: I18N('BRAWLS_TITLE'),
  1068. default: (() => {
  1069. $result = true;
  1070. try {
  1071. $result = JSON.parse(localStorage[GM_info.script.name + ':autoBrawls']);
  1072. } catch (e) {
  1073. $result = false;
  1074. }
  1075. return $result || false;
  1076. })(),
  1077. hide: false,
  1078. },
  1079. getAnswer: {
  1080. label: I18N('AUTO_QUIZ'),
  1081. cbox: null,
  1082. title: I18N('AUTO_QUIZ_TITLE'),
  1083. default: false,
  1084. hide: true,
  1085. },
  1086. tryFixIt_v2: {
  1087. label: I18N('BTN_TRY_FIX_IT'),
  1088. cbox: null,
  1089. title: I18N('BTN_TRY_FIX_IT_TITLE'),
  1090. default: false,
  1091. hide: false,
  1092. },
  1093. showErrors: {
  1094. label: I18N('SHOW_ERRORS'),
  1095. cbox: null,
  1096. title: I18N('SHOW_ERRORS_TITLE'),
  1097. default: true,
  1098. },
  1099. buyForGold: {
  1100. label: I18N('BUY_FOR_GOLD'),
  1101. cbox: null,
  1102. title: I18N('BUY_FOR_GOLD_TITLE'),
  1103. default: true,
  1104. },
  1105. hideServers: {
  1106. label: I18N('HIDE_SERVERS'),
  1107. cbox: null,
  1108. title: I18N('HIDE_SERVERS_TITLE'),
  1109. default: true,
  1110. },
  1111. fastSeason: {
  1112. label: I18N('FAST_SEASON'),
  1113. cbox: null,
  1114. title: I18N('FAST_SEASON_TITLE'),
  1115. default: true,
  1116. },
  1117. };
  1118. /**
  1119. * Get checkbox state
  1120. *
  1121. * Получить состояние чекбокса
  1122. */
  1123. function isChecked(checkBox) {
  1124. if (!(checkBox in checkboxes)) {
  1125. return false;
  1126. }
  1127. return checkboxes[checkBox].cbox?.checked;
  1128. }
  1129. /**
  1130. * Input fields
  1131. *
  1132. * Поля ввода
  1133. */
  1134. const inputs = {
  1135. countTitanit: {
  1136. input: null,
  1137. title: I18N('HOW_MUCH_TITANITE'),
  1138. default: 175,
  1139. },
  1140. speedBattle: {
  1141. input: null,
  1142. title: I18N('COMBAT_SPEED'),
  1143. default: 4,
  1144. },
  1145. countTestBattle: {
  1146. input: null,
  1147. title: I18N('NUMBER_OF_TEST'),
  1148. default: 5,
  1149. },
  1150. countAutoBattle: {
  1151. input: null,
  1152. title: I18N('NUMBER_OF_AUTO_BATTLE'),
  1153. default: 20,
  1154. },
  1155. FPS: {
  1156. input: null,
  1157. title: 'FPS',
  1158. default: 30,
  1159. }
  1160. }
  1161. /**
  1162. * Checks the checkbox
  1163. *
  1164. * Поплучить данные поля ввода
  1165. */
  1166. function getInput(inputName) {
  1167. return inputs[inputName]?.input?.value;
  1168. }
  1169.  
  1170. /**
  1171. * Control FPS
  1172. *
  1173. * Контроль FPS
  1174. */
  1175. let nextAnimationFrame = Date.now();
  1176. const oldRequestAnimationFrame = this.requestAnimationFrame;
  1177. this.requestAnimationFrame = async function (e) {
  1178. const FPS = Number(getInput('FPS')) || -1;
  1179. const now = Date.now();
  1180. const delay = nextAnimationFrame - now;
  1181. nextAnimationFrame = Math.max(now, nextAnimationFrame) + Math.min(1e3 / FPS, 1e3);
  1182. if (delay > 0) {
  1183. await new Promise((e) => setTimeout(e, delay));
  1184. }
  1185. oldRequestAnimationFrame(e);
  1186. };
  1187. /**
  1188. * Button List
  1189. *
  1190. * Список кнопочек
  1191. */
  1192. const buttons = {
  1193. getOutland: {
  1194. name: I18N('TO_DO_EVERYTHING'),
  1195. title: I18N('TO_DO_EVERYTHING_TITLE'),
  1196. func: testDoYourBest,
  1197. },
  1198. doActions: {
  1199. name: I18N('ACTIONS'),
  1200. title: I18N('ACTIONS_TITLE'),
  1201. func: async function () {
  1202. const popupButtons = [
  1203. {
  1204. msg: I18N('OUTLAND'),
  1205. result: function () {
  1206. confShow(`${I18N('RUN_SCRIPT')} ${I18N('OUTLAND')}?`, getOutland);
  1207. },
  1208. title: I18N('OUTLAND_TITLE'),
  1209. },
  1210. {
  1211. msg: I18N('TOWER'),
  1212. result: function () {
  1213. confShow(`${I18N('RUN_SCRIPT')} ${I18N('TOWER')}?`, testTower);
  1214. },
  1215. title: I18N('TOWER_TITLE'),
  1216. },
  1217. {
  1218. msg: I18N('EXPEDITIONS'),
  1219. result: function () {
  1220. confShow(`${I18N('RUN_SCRIPT')} ${I18N('EXPEDITIONS')}?`, checkExpedition);
  1221. },
  1222. title: I18N('EXPEDITIONS_TITLE'),
  1223. },
  1224. {
  1225. msg: I18N('MINIONS'),
  1226. result: function () {
  1227. confShow(`${I18N('RUN_SCRIPT')} ${I18N('MINIONS')}?`, testRaidNodes);
  1228. },
  1229. title: I18N('MINIONS_TITLE'),
  1230. },
  1231. {
  1232. msg: I18N('ESTER_EGGS'),
  1233. result: function () {
  1234. confShow(`${I18N('RUN_SCRIPT')} ${I18N('ESTER_EGGS')}?`, offerFarmAllReward);
  1235. },
  1236. title: I18N('ESTER_EGGS_TITLE'),
  1237. },
  1238. {
  1239. msg: I18N('STORM'),
  1240. result: function () {
  1241. testAdventure('solo');
  1242. },
  1243. title: I18N('STORM_TITLE'),
  1244. },
  1245. {
  1246. msg: I18N('REWARDS'),
  1247. result: function () {
  1248. confShow(`${I18N('RUN_SCRIPT')} ${I18N('REWARDS')}?`, questAllFarm);
  1249. },
  1250. title: I18N('REWARDS_TITLE'),
  1251. },
  1252. {
  1253. msg: I18N('MAIL'),
  1254. result: function () {
  1255. confShow(`${I18N('RUN_SCRIPT')} ${I18N('MAIL')}?`, mailGetAll);
  1256. },
  1257. title: I18N('MAIL_TITLE'),
  1258. },
  1259. {
  1260. msg: I18N('SEER'),
  1261. result: function () {
  1262. confShow(`${I18N('RUN_SCRIPT')} ${I18N('SEER')}?`, rollAscension);
  1263. },
  1264. title: I18N('SEER_TITLE'),
  1265. },
  1266. /*
  1267. {
  1268. msg: I18N('NY_GIFTS'),
  1269. result: getGiftNewYear,
  1270. title: I18N('NY_GIFTS_TITLE'),
  1271. },
  1272. */
  1273. ];
  1274. popupButtons.push({ result: false, isClose: true });
  1275. const answer = await popup.confirm(`${I18N('CHOOSE_ACTION')}:`, popupButtons);
  1276. if (typeof answer === 'function') {
  1277. answer();
  1278. }
  1279. },
  1280. },
  1281. doOthers: {
  1282. name: I18N('OTHERS'),
  1283. title: I18N('OTHERS_TITLE'),
  1284. func: async function () {
  1285. const popupButtons = [
  1286. {
  1287. msg: I18N('GET_ENERGY'),
  1288. result: farmStamina,
  1289. title: I18N('GET_ENERGY_TITLE'),
  1290. },
  1291. {
  1292. msg: I18N('ITEM_EXCHANGE'),
  1293. result: fillActive,
  1294. title: I18N('ITEM_EXCHANGE_TITLE'),
  1295. },
  1296. {
  1297. msg: I18N('BUY_SOULS'),
  1298. result: function () {
  1299. confShow(`${I18N('RUN_SCRIPT')} ${I18N('BUY_SOULS')}?`, buyHeroFragments);
  1300. },
  1301. title: I18N('BUY_SOULS_TITLE'),
  1302. },
  1303. {
  1304. msg: I18N('BUY_FOR_GOLD'),
  1305. result: function () {
  1306. confShow(`${I18N('RUN_SCRIPT')} ${I18N('BUY_FOR_GOLD')}?`, buyInStoreForGold);
  1307. },
  1308. title: I18N('BUY_FOR_GOLD_TITLE'),
  1309. },
  1310. {
  1311. msg: I18N('BUY_OUTLAND'),
  1312. result: bossOpenChestPay,
  1313. title: I18N('BUY_OUTLAND_TITLE'),
  1314. },
  1315. {
  1316. msg: I18N('AUTO_RAID_ADVENTURE'),
  1317. result: autoRaidAdventure,
  1318. title: I18N('AUTO_RAID_ADVENTURE_TITLE'),
  1319. },
  1320. {
  1321. msg: I18N('CLAN_STAT'),
  1322. result: clanStatistic,
  1323. title: I18N('CLAN_STAT_TITLE'),
  1324. },
  1325. {
  1326. msg: I18N('EPIC_BRAWL'),
  1327. result: async function () {
  1328. confShow(`${I18N('RUN_SCRIPT')} ${I18N('EPIC_BRAWL')}?`, () => {
  1329. const brawl = new epicBrawl();
  1330. brawl.start();
  1331. });
  1332. },
  1333. title: I18N('EPIC_BRAWL_TITLE'),
  1334. },
  1335. {
  1336. msg: I18N('ARTIFACTS_UPGRADE'),
  1337. result: updateArtifacts,
  1338. title: I18N('ARTIFACTS_UPGRADE_TITLE'),
  1339. },
  1340. {
  1341. msg: I18N('SKINS_UPGRADE'),
  1342. result: updateSkins,
  1343. title: I18N('SKINS_UPGRADE_TITLE'),
  1344. },
  1345. {
  1346. msg: I18N('SEASON_REWARD'),
  1347. result: farmBattlePass,
  1348. title: I18N('SEASON_REWARD_TITLE'),
  1349. },
  1350. {
  1351. msg: I18N('SELL_HERO_SOULS'),
  1352. result: sellHeroSoulsForGold,
  1353. title: I18N('SELL_HERO_SOULS_TITLE'),
  1354. },
  1355. {
  1356. msg: I18N('CHANGE_MAP'),
  1357. result: async function () {
  1358. const maps = Object.values(lib.data.seasonAdventure.list)
  1359. .filter((e) => e.map.cells.length > 2)
  1360. .map((i) => ({
  1361. msg: I18N('MAP_NUM', { num: i.id }),
  1362. result: i.id,
  1363. }));
  1364.  
  1365. const result = await popup.confirm(I18N('SELECT_ISLAND_MAP'), [...maps, { result: false, isClose: true }]);
  1366. if (result) {
  1367. cheats.changeIslandMap(result);
  1368. }
  1369. },
  1370. title: I18N('CHANGE_MAP_TITLE'),
  1371. },
  1372. {
  1373. msg: I18N('HERO_POWER'),
  1374. result: async () => {
  1375. const calls = ['userGetInfo', 'heroGetAll'].map((name) => ({
  1376. name,
  1377. args: {},
  1378. ident: name,
  1379. }));
  1380. const [maxHeroSumPower, heroSumPower] = await Send({ calls }).then((e) => [
  1381. e.results[0].result.response.maxSumPower.heroes,
  1382. Object.values(e.results[1].result.response).reduce((a, e) => a + e.power, 0),
  1383. ]);
  1384. const power = maxHeroSumPower - heroSumPower;
  1385. let msg =
  1386. I18N('MAX_POWER_REACHED', { power: maxHeroSumPower.toLocaleString() }) +
  1387. '<br>' +
  1388. I18N('CURRENT_POWER', { power: heroSumPower.toLocaleString() }) +
  1389. '<br>' +
  1390. I18N('POWER_TO_MAX', { power: power.toLocaleString(), color: power >= 4000 ? 'green' : 'red' });
  1391. await popup.confirm(msg, [{ msg: I18N('BTN_OK'), result: 0 }]);
  1392. },
  1393. title: I18N('HERO_POWER_TITLE'),
  1394. },
  1395. ];
  1396. popupButtons.push({ result: false, isClose: true });
  1397. const answer = await popup.confirm(`${I18N('CHOOSE_ACTION')}:`, popupButtons);
  1398. if (typeof answer === 'function') {
  1399. answer();
  1400. }
  1401. },
  1402. },
  1403. testTitanArena: {
  1404. name: I18N('TITAN_ARENA'),
  1405. title: I18N('TITAN_ARENA_TITLE'),
  1406. func: function () {
  1407. confShow(`${I18N('RUN_SCRIPT')} ${I18N('TITAN_ARENA')}?`, testTitanArena);
  1408. },
  1409. },
  1410. testDungeon: {
  1411. name: I18N('DUNGEON'),
  1412. title: I18N('DUNGEON_TITLE'),
  1413. func: function () {
  1414. confShow(`${I18N('RUN_SCRIPT')} ${I18N('DUNGEON')}?`, testDungeon);
  1415. },
  1416. },
  1417. // Архидемон
  1418. bossRatingEvent: {
  1419. name: I18N('ARCHDEMON'),
  1420. title: I18N('ARCHDEMON_TITLE'),
  1421. func: function () {
  1422. confShow(`${I18N('RUN_SCRIPT')} ${I18N('ARCHDEMON')}?`, bossRatingEvent);
  1423. },
  1424. hide: true,
  1425. },
  1426. // Горнило душ
  1427. bossRatingEvent: {
  1428. name: I18N('FURNACE_OF_SOULS'),
  1429. title: I18N('ARCHDEMON_TITLE'),
  1430. func: function () {
  1431. confShow(`${I18N('RUN_SCRIPT')} ${I18N('FURNACE_OF_SOULS')}?`, bossRatingEventSouls);
  1432. },
  1433. hide: true,
  1434. },
  1435. rewardsAndMailFarm: {
  1436. name: I18N('REWARDS_AND_MAIL'),
  1437. title: I18N('REWARDS_AND_MAIL_TITLE'),
  1438. func: function () {
  1439. confShow(`${I18N('RUN_SCRIPT')} ${I18N('REWARDS_AND_MAIL')}?`, rewardsAndMailFarm);
  1440. },
  1441. },
  1442. testAdventure: {
  1443. name: I18N('ADVENTURE'),
  1444. title: I18N('ADVENTURE_TITLE'),
  1445. func: () => {
  1446. testAdventure();
  1447. },
  1448. },
  1449. goToSanctuary: {
  1450. name: I18N('SANCTUARY'),
  1451. title: I18N('SANCTUARY_TITLE'),
  1452. func: cheats.goSanctuary,
  1453. },
  1454. goToClanWar: {
  1455. name: I18N('GUILD_WAR'),
  1456. title: I18N('GUILD_WAR_TITLE'),
  1457. func: cheats.goClanWar,
  1458. },
  1459. dailyQuests: {
  1460. name: I18N('DAILY_QUESTS'),
  1461. title: I18N('DAILY_QUESTS_TITLE'),
  1462. func: async function () {
  1463. const quests = new dailyQuests(
  1464. () => {},
  1465. () => {}
  1466. );
  1467. await quests.autoInit();
  1468. quests.start();
  1469. },
  1470. },
  1471. newDay: {
  1472. name: I18N('SYNC'),
  1473. title: I18N('SYNC_TITLE'),
  1474. func: function () {
  1475. confShow(`${I18N('RUN_SCRIPT')} ${I18N('SYNC')}?`, cheats.refreshGame);
  1476. },
  1477. },
  1478. };
  1479. /**
  1480. * Display buttons
  1481. *
  1482. * Вывести кнопочки
  1483. */
  1484. function addControlButtons() {
  1485. for (let name in buttons) {
  1486. button = buttons[name];
  1487. if (button.hide) {
  1488. continue;
  1489. }
  1490. button['button'] = scriptMenu.addButton(button.name, button.func, button.title);
  1491. }
  1492. }
  1493. /**
  1494. * Adds links
  1495. *
  1496. * Добавляет ссылки
  1497. */
  1498. function addBottomUrls() {
  1499. scriptMenu.addHeader(I18N('BOTTOM_URLS'));
  1500. }
  1501. /**
  1502. * Stop repetition of the mission
  1503. *
  1504. * Остановить повтор миссии
  1505. */
  1506. let isStopSendMission = false;
  1507. /**
  1508. * There is a repetition of the mission
  1509. *
  1510. * Идет повтор миссии
  1511. */
  1512. let isSendsMission = false;
  1513. /**
  1514. * Data on the past mission
  1515. *
  1516. * Данные о прошедшей мисии
  1517. */
  1518. let lastMissionStart = {}
  1519. /**
  1520. * Start time of the last battle in the company
  1521. *
  1522. * Время начала последнего боя в кампании
  1523. */
  1524. let lastMissionBattleStart = 0;
  1525. /**
  1526. * Data for calculating the last battle with the boss
  1527. *
  1528. * Данные для расчете последнего боя с боссом
  1529. */
  1530. let lastBossBattle = null;
  1531. /**
  1532. * Information about the last battle
  1533. *
  1534. * Данные о прошедшей битве
  1535. */
  1536. let lastBattleArg = {}
  1537. let lastBossBattleStart = null;
  1538. this.addBattleTimer = 4;
  1539. this.invasionTimer = 2500;
  1540. const invasionInfo = {
  1541. buff: 0,
  1542. bossLvl: 130,
  1543. };
  1544. const invasionDataPacks = {
  1545. 130: { buff: 0, pet: 6004, heroes: [58, 48, 16, 65, 59], favor: { 16: 6004, 48: 6001, 58: 6002, 59: 6005, 65: 6000 } },
  1546. 140: { buff: 0, pet: 6006, heroes: [1, 4, 13, 58, 65], favor: { 1: 6001, 4: 6006, 13: 6002, 58: 6005, 65: 6000 } },
  1547. 150: { buff: 0, pet: 6006, heroes: [1, 12, 17, 21, 65], favor: { 1: 6001, 12: 6003, 17: 6006, 21: 6002, 65: 6000 } },
  1548. 160: { buff: 0, pet: 6008, heroes: [12, 21, 34, 58, 65], favor: { 12: 6003, 21: 6006, 34: 6008, 58: 6002, 65: 6001 } },
  1549. 170: { buff: 0, pet: 6005, heroes: [33, 12, 65, 21, 4], favor: { 4: 6001, 12: 6003, 21: 6006, 33: 6008, 65: 6000 } },
  1550. 180: { buff: 20, pet: 6009, heroes: [58, 13, 5, 17, 65], favor: { 5: 6006, 13: 6003, 58: 6005 } },
  1551. 190: { buff: 0, pet: 6006, heroes: [1, 12, 21, 36, 65], favor: { 1: 6004, 12: 6003, 21: 6006, 36: 6005, 65: 6000 } },
  1552. 200: { buff: 0, pet: 6006, heroes: [12, 1, 13, 2, 65], favor: { 2: 6001, 12: 6003, 13: 6006, 65: 6000 } },
  1553. 210: { buff: 15, pet: 6005, heroes: [12, 21, 33, 58, 65], favor: { 12: 6003, 21: 6006, 33: 6008, 58: 6005, 65: 6001 } },
  1554. 220: { buff: 5, pet: 6006, heroes: [58, 13, 7, 34, 65], favor: { 7: 6002, 13: 6008, 34: 6006, 58: 6005, 65: 6001 } },
  1555. 230: { buff: 35, pet: 6005, heroes: [5, 7, 13, 58, 65], favor: { 5: 6006, 7: 6003, 13: 6002, 58: 6005, 65: 6000 } },
  1556. 240: { buff: 0, pet: 6005, heroes: [12, 58, 1, 36, 65], favor: { 1: 6006, 12: 6003, 36: 6005, 65: 6001 } },
  1557. 250: { buff: 15, pet: 6005, heroes: [12, 36, 4, 16, 65], favor: { 12: 6003, 16: 6004, 36: 6005, 65: 6001 } },
  1558. 260: { buff: 15, pet: 6005, heroes: [48, 12, 36, 65, 4], favor: { 4: 6006, 12: 6003, 36: 6005, 48: 6000, 65: 6007 } },
  1559. 270: { buff: 35, pet: 6005, heroes: [12, 58, 36, 4, 65], favor: { 4: 6006, 12: 6003, 36: 6005 } },
  1560. 280: { buff: 80, pet: 6005, heroes: [21, 36, 48, 7, 65], favor: { 7: 6003, 21: 6006, 36: 6005, 48: 6001, 65: 6000 } },
  1561. 290: { buff: 95, pet: 6008, heroes: [12, 21, 36, 35, 65], favor: { 12: 6003, 21: 6006, 36: 6005, 65: 6007 } },
  1562. 300: { buff: 25, pet: 6005, heroes: [12, 13, 4, 34, 65], favor: { 4: 6006, 12: 6003, 13: 6007, 34: 6002 } },
  1563. 310: { buff: 45, pet: 6005, heroes: [12, 21, 58, 33, 65], favor: { 12: 6003, 21: 6006, 33: 6002, 58: 6005, 65: 6007 } },
  1564. 320: { buff: 70, pet: 6005, heroes: [12, 48, 2, 6, 65], favor: { 6: 6005, 12: 6003 } },
  1565. 330: { buff: 70, pet: 6005, heroes: [12, 21, 36, 5, 65], favor: { 5: 6002, 12: 6003, 21: 6006, 36: 6005, 65: 6000 } },
  1566. 340: { buff: 55, pet: 6009, heroes: [12, 36, 13, 6, 65], favor: { 6: 6005, 12: 6003, 13: 6002, 36: 6006, 65: 6000 } },
  1567. 350: { buff: 100, pet: 6005, heroes: [12, 21, 58, 34, 65], favor: { 12: 6003, 21: 6006, 58: 6005 } },
  1568. 360: { buff: 85, pet: 6007, heroes: [12, 21, 36, 4, 65], favor: { 4: 6006, 12: 6003, 21: 6002, 36: 6005 } },
  1569. 370: { buff: 90, pet: 6008, heroes: [12, 21, 36, 13, 65], favor: { 12: 6003, 13: 6007, 21: 6006, 36: 6005, 65: 6001 } },
  1570. 380: { buff: 165, pet: 6005, heroes: [12, 33, 36, 4, 65], favor: { 4: 6001, 12: 6003, 33: 6006 } },
  1571. 390: { buff: 235, pet: 6005, heroes: [21, 58, 48, 2, 65], favor: { 2: 6005, 21: 6002 } },
  1572. 400: { buff: 125, pet: 6006, heroes: [12, 21, 36, 48, 65], favor: { 12: 6003, 21: 6006, 36: 6005, 48: 6001, 65: 6007 } },
  1573. };
  1574. /**
  1575. * The name of the function of the beginning of the battle
  1576. *
  1577. * Имя функции начала боя
  1578. */
  1579. let nameFuncStartBattle = '';
  1580. /**
  1581. * The name of the function of the end of the battle
  1582. *
  1583. * Имя функции конца боя
  1584. */
  1585. let nameFuncEndBattle = '';
  1586. /**
  1587. * Data for calculating the last battle
  1588. *
  1589. * Данные для расчета последнего боя
  1590. */
  1591. let lastBattleInfo = null;
  1592. /**
  1593. * The ability to cancel the battle
  1594. *
  1595. * Возможность отменить бой
  1596. */
  1597. let isCancalBattle = true;
  1598.  
  1599. function setIsCancalBattle(value) {
  1600. isCancalBattle = value;
  1601. }
  1602.  
  1603. /**
  1604. * Certificator of the last open nesting doll
  1605. *
  1606. * Идетификатор последней открытой матрешки
  1607. */
  1608. let lastRussianDollId = null;
  1609. /**
  1610. * Cancel the training guide
  1611. *
  1612. * Отменить обучающее руководство
  1613. */
  1614. this.isCanceledTutorial = false;
  1615.  
  1616. /**
  1617. * Data from the last question of the quiz
  1618. *
  1619. * Данные последнего вопроса викторины
  1620. */
  1621. let lastQuestion = null;
  1622. /**
  1623. * Answer to the last question of the quiz
  1624. *
  1625. * Ответ на последний вопрос викторины
  1626. */
  1627. let lastAnswer = null;
  1628. /**
  1629. * Flag for opening keys or titan artifact spheres
  1630. *
  1631. * Флаг открытия ключей или сфер артефактов титанов
  1632. */
  1633. let artifactChestOpen = false;
  1634. /**
  1635. * The name of the function to open keys or orbs of titan artifacts
  1636. *
  1637. * Имя функции открытия ключей или сфер артефактов титанов
  1638. */
  1639. let artifactChestOpenCallName = '';
  1640. let correctShowOpenArtifact = 0;
  1641. /**
  1642. * Data for the last battle in the dungeon
  1643. * (Fix endless cards)
  1644. *
  1645. * Данные для последнего боя в подземке
  1646. * (Исправление бесконечных карт)
  1647. */
  1648. let lastDungeonBattleData = null;
  1649. /**
  1650. * Start time of the last battle in the dungeon
  1651. *
  1652. * Время начала последнего боя в подземелье
  1653. */
  1654. let lastDungeonBattleStart = 0;
  1655. /**
  1656. * Subscription end time
  1657. *
  1658. * Время окончания подписки
  1659. */
  1660. let subEndTime = 0;
  1661. /**
  1662. * Number of prediction cards
  1663. *
  1664. * Количество карт предсказаний
  1665. */
  1666. let countPredictionCard = 0;
  1667.  
  1668. /**
  1669. * Brawl pack
  1670. *
  1671. * Пачка для потасовок
  1672. */
  1673. let brawlsPack = null;
  1674. /**
  1675. * Autobrawl started
  1676. *
  1677. * Автопотасовка запущена
  1678. */
  1679. let isBrawlsAutoStart = false;
  1680. let clanDominationGetInfo = null;
  1681. /**
  1682. * Copies the text to the clipboard
  1683. *
  1684. * Копирует тест в буфер обмена
  1685. * @param {*} text copied text // копируемый текст
  1686. */
  1687. function copyText(text) {
  1688. let copyTextarea = document.createElement("textarea");
  1689. copyTextarea.style.opacity = "0";
  1690. copyTextarea.textContent = text;
  1691. document.body.appendChild(copyTextarea);
  1692. copyTextarea.select();
  1693. document.execCommand("copy");
  1694. document.body.removeChild(copyTextarea);
  1695. delete copyTextarea;
  1696. }
  1697. /**
  1698. * Returns the history of requests
  1699. *
  1700. * Возвращает историю запросов
  1701. */
  1702. this.getRequestHistory = function() {
  1703. return requestHistory;
  1704. }
  1705. /**
  1706. * Generates a random integer from min to max
  1707. *
  1708. * Гененирует случайное целое число от min до max
  1709. */
  1710. const random = function (min, max) {
  1711. return Math.floor(Math.random() * (max - min + 1) + min);
  1712. }
  1713. const randf = function (min, max) {
  1714. return Math.random() * (max - min + 1) + min;
  1715. };
  1716. /**
  1717. * Clearing the request history
  1718. *
  1719. * Очистка истоии запросов
  1720. */
  1721. setInterval(function () {
  1722. let now = Date.now();
  1723. for (let i in requestHistory) {
  1724. const time = +i.split('_')[0];
  1725. if (now - time > 300000) {
  1726. delete requestHistory[i];
  1727. }
  1728. }
  1729. }, 300000);
  1730. /**
  1731. * Displays the dialog box
  1732. *
  1733. * Отображает диалоговое окно
  1734. */
  1735. function confShow(message, yesCallback, noCallback) {
  1736. let buts = [];
  1737. message = message || I18N('DO_YOU_WANT');
  1738. noCallback = noCallback || (() => {});
  1739. if (yesCallback) {
  1740. buts = [
  1741. { msg: I18N('BTN_RUN'), result: true},
  1742. { msg: I18N('BTN_CANCEL'), result: false, isCancel: true},
  1743. ]
  1744. } else {
  1745. yesCallback = () => {};
  1746. buts = [
  1747. { msg: I18N('BTN_OK'), result: true},
  1748. ];
  1749. }
  1750. popup.confirm(message, buts).then((e) => {
  1751. // dialogPromice = null;
  1752. if (e) {
  1753. yesCallback();
  1754. } else {
  1755. noCallback();
  1756. }
  1757. });
  1758. }
  1759. /**
  1760. * Override/proxy the method for creating a WS package send
  1761. *
  1762. * Переопределяем/проксируем метод создания отправки WS пакета
  1763. */
  1764. WebSocket.prototype.send = function (data) {
  1765. if (!this.isSetOnMessage) {
  1766. const oldOnmessage = this.onmessage;
  1767. this.onmessage = function (event) {
  1768. try {
  1769. const data = JSON.parse(event.data);
  1770. if (!this.isWebSocketLogin && data.result.type == "iframeEvent.login") {
  1771. this.isWebSocketLogin = true;
  1772. } else if (data.result.type == "iframeEvent.login") {
  1773. return;
  1774. }
  1775. } catch (e) { }
  1776. return oldOnmessage.apply(this, arguments);
  1777. }
  1778. this.isSetOnMessage = true;
  1779. }
  1780. original.SendWebSocket.call(this, data);
  1781. }
  1782. /**
  1783. * Overriding/Proxying the Ajax Request Creation Method
  1784. *
  1785. * Переопределяем/проксируем метод создания Ajax запроса
  1786. */
  1787. XMLHttpRequest.prototype.open = function (method, url, async, user, password) {
  1788. this.uniqid = Date.now() + '_' + random(1000000, 10000000);
  1789. this.errorRequest = false;
  1790. if (method == 'POST' && url.includes('.nextersglobal.com/api/') && /api\/$/.test(url)) {
  1791. if (!apiUrl) {
  1792. apiUrl = url;
  1793. const socialInfo = /heroes-(.+?)\./.exec(apiUrl);
  1794. console.log(socialInfo);
  1795. }
  1796. requestHistory[this.uniqid] = {
  1797. method,
  1798. url,
  1799. error: [],
  1800. headers: {},
  1801. request: null,
  1802. response: null,
  1803. signature: [],
  1804. calls: {},
  1805. };
  1806. } else if (method == 'POST' && url.includes('error.nextersglobal.com/client/')) {
  1807. this.errorRequest = true;
  1808. }
  1809. return original.open.call(this, method, url, async, user, password);
  1810. };
  1811. /**
  1812. * Overriding/Proxying the header setting method for the AJAX request
  1813. *
  1814. * Переопределяем/проксируем метод установки заголовков для AJAX запроса
  1815. */
  1816. XMLHttpRequest.prototype.setRequestHeader = function (name, value, check) {
  1817. if (this.uniqid in requestHistory) {
  1818. requestHistory[this.uniqid].headers[name] = value;
  1819. } else {
  1820. check = true;
  1821. }
  1822.  
  1823. if (name == 'X-Auth-Signature') {
  1824. requestHistory[this.uniqid].signature.push(value);
  1825. if (!check) {
  1826. return;
  1827. }
  1828. }
  1829.  
  1830. return original.setRequestHeader.call(this, name, value);
  1831. };
  1832. /**
  1833. * Overriding/Proxying the AJAX Request Sending Method
  1834. *
  1835. * Переопределяем/проксируем метод отправки AJAX запроса
  1836. */
  1837. XMLHttpRequest.prototype.send = async function (sourceData) {
  1838. if (this.uniqid in requestHistory) {
  1839. let tempData = null;
  1840. if (getClass(sourceData) == "ArrayBuffer") {
  1841. tempData = decoder.decode(sourceData);
  1842. } else {
  1843. tempData = sourceData;
  1844. }
  1845. requestHistory[this.uniqid].request = tempData;
  1846. let headers = requestHistory[this.uniqid].headers;
  1847. lastHeaders = Object.assign({}, headers);
  1848. /**
  1849. * Game loading event
  1850. *
  1851. * Событие загрузки игры
  1852. */
  1853. if (headers["X-Request-Id"] > 2 && !isLoadGame) {
  1854. isLoadGame = true;
  1855. if (cheats.libGame) {
  1856. lib.setData(cheats.libGame);
  1857. } else {
  1858. lib.setData(await cheats.LibLoad());
  1859. }
  1860. addControls();
  1861. addControlButtons();
  1862. addBottomUrls();
  1863.  
  1864. if (isChecked('sendExpedition')) {
  1865. const isTimeBetweenDays = isTimeBetweenNewDays();
  1866. if (!isTimeBetweenDays) {
  1867. checkExpedition();
  1868. } else {
  1869. setProgress(I18N('EXPEDITIONS_NOTTIME'), true);
  1870. }
  1871. }
  1872.  
  1873. getAutoGifts();
  1874.  
  1875. cheats.activateHacks();
  1876. justInfo();
  1877. if (isChecked('dailyQuests')) {
  1878. testDailyQuests();
  1879. }
  1880.  
  1881. if (isChecked('buyForGold')) {
  1882. buyInStoreForGold();
  1883. }
  1884. }
  1885. /**
  1886. * Outgoing request data processing
  1887. *
  1888. * Обработка данных исходящего запроса
  1889. */
  1890. sourceData = await checkChangeSend.call(this, sourceData, tempData);
  1891. /**
  1892. * Handling incoming request data
  1893. *
  1894. * Обработка данных входящего запроса
  1895. */
  1896. const oldReady = this.onreadystatechange;
  1897. this.onreadystatechange = async function (e) {
  1898. if (this.errorRequest) {
  1899. return oldReady.apply(this, arguments);
  1900. }
  1901. if(this.readyState == 4 && this.status == 200) {
  1902. isTextResponse = this.responseType === "text" || this.responseType === "";
  1903. let response = isTextResponse ? this.responseText : this.response;
  1904. requestHistory[this.uniqid].response = response;
  1905. /**
  1906. * Replacing incoming request data
  1907. *
  1908. * Заменна данных входящего запроса
  1909. */
  1910. if (isTextResponse) {
  1911. await checkChangeResponse.call(this, response);
  1912. }
  1913. /**
  1914. * A function to run after the request is executed
  1915. *
  1916. * Функция запускаемая после выполения запроса
  1917. */
  1918. if (typeof this.onReadySuccess == 'function') {
  1919. setTimeout(this.onReadySuccess, 500);
  1920. }
  1921. /** Удаляем из истории запросов битвы с боссом */
  1922. if ('invasion_bossStart' in requestHistory[this.uniqid].calls) delete requestHistory[this.uniqid];
  1923. }
  1924. if (oldReady) {
  1925. try {
  1926. return oldReady.apply(this, arguments);
  1927. } catch(e) {
  1928. console.log(oldReady);
  1929. console.error('Error in oldReady:', e);
  1930. }
  1931.  
  1932. }
  1933. }
  1934. }
  1935. if (this.errorRequest) {
  1936. const oldReady = this.onreadystatechange;
  1937. this.onreadystatechange = function () {
  1938. Object.defineProperty(this, 'status', {
  1939. writable: true
  1940. });
  1941. this.status = 200;
  1942. Object.defineProperty(this, 'readyState', {
  1943. writable: true
  1944. });
  1945. this.readyState = 4;
  1946. Object.defineProperty(this, 'responseText', {
  1947. writable: true
  1948. });
  1949. this.responseText = JSON.stringify({
  1950. "result": true
  1951. });
  1952. if (typeof this.onReadySuccess == 'function') {
  1953. setTimeout(this.onReadySuccess, 200);
  1954. }
  1955. return oldReady.apply(this, arguments);
  1956. }
  1957. this.onreadystatechange();
  1958. } else {
  1959. try {
  1960. return original.send.call(this, sourceData);
  1961. } catch(e) {
  1962. debugger;
  1963. }
  1964. }
  1965. };
  1966. /**
  1967. * Processing and substitution of outgoing data
  1968. *
  1969. * Обработка и подмена исходящих данных
  1970. */
  1971. async function checkChangeSend(sourceData, tempData) {
  1972. try {
  1973. /**
  1974. * A function that replaces battle data with incorrect ones to cancel combatя
  1975. *
  1976. * Функция заменяющая данные боя на неверные для отмены боя
  1977. */
  1978. const fixBattle = function (heroes) {
  1979. for (const ids in heroes) {
  1980. hero = heroes[ids];
  1981. hero.energy = random(1, 999);
  1982. if (hero.hp > 0) {
  1983. hero.hp = random(1, hero.hp);
  1984. }
  1985. }
  1986. }
  1987. /**
  1988. * Dialog window 2
  1989. *
  1990. * Диалоговое окно 2
  1991. */
  1992. const showMsg = async function (msg, ansF, ansS) {
  1993. if (typeof popup == 'object') {
  1994. return await popup.confirm(msg, [
  1995. {msg: ansF, result: false},
  1996. {msg: ansS, result: true},
  1997. ]);
  1998. } else {
  1999. return !confirm(`${msg}\n ${ansF} (${I18N('BTN_OK')})\n ${ansS} (${I18N('BTN_CANCEL')})`);
  2000. }
  2001. }
  2002. /**
  2003. * Dialog window 3
  2004. *
  2005. * Диалоговое окно 3
  2006. */
  2007. const showMsgs = async function (msg, ansF, ansS, ansT) {
  2008. return await popup.confirm(msg, [
  2009. {msg: ansF, result: 0},
  2010. {msg: ansS, result: 1},
  2011. {msg: ansT, result: 2},
  2012. ]);
  2013. }
  2014.  
  2015. let changeRequest = false;
  2016. testData = JSON.parse(tempData);
  2017. for (const call of testData.calls) {
  2018. if (!artifactChestOpen) {
  2019. requestHistory[this.uniqid].calls[call.name] = call.ident;
  2020. }
  2021. /**
  2022. * Cancellation of the battle in adventures, on VG and with minions of Asgard
  2023. * Отмена боя в приключениях, на ВГ и с прислужниками Асгарда
  2024. */
  2025. if ((call.name == 'adventure_endBattle' ||
  2026. call.name == 'adventureSolo_endBattle' ||
  2027. call.name == 'clanWarEndBattle' &&
  2028. isChecked('cancelBattle') ||
  2029. call.name == 'crossClanWar_endBattle' &&
  2030. isChecked('cancelBattle') ||
  2031. call.name == 'brawl_endBattle' ||
  2032. call.name == 'towerEndBattle' ||
  2033. call.name == 'invasion_bossEnd' ||
  2034. call.name == 'titanArenaEndBattle' ||
  2035. call.name == 'bossEndBattle' ||
  2036. call.name == 'clanRaid_endNodeBattle') &&
  2037. isCancalBattle) {
  2038. nameFuncEndBattle = call.name;
  2039.  
  2040. if (isChecked('tryFixIt_v2') &&
  2041. !call.args.result.win &&
  2042. (call.name == 'brawl_endBattle' ||
  2043. //call.name == 'crossClanWar_endBattle' ||
  2044. call.name == 'epicBrawl_endBattle' ||
  2045. //call.name == 'clanWarEndBattle' ||
  2046. call.name == 'adventure_endBattle' ||
  2047. call.name == 'titanArenaEndBattle' ||
  2048. call.name == 'bossEndBattle' ||
  2049. call.name == 'adventureSolo_endBattle') &&
  2050. lastBattleInfo) {
  2051. const noFixWin = call.name == 'clanWarEndBattle' || call.name == 'crossClanWar_endBattle';
  2052. const cloneBattle = structuredClone(lastBattleInfo);
  2053. lastBattleInfo = null;
  2054. try {
  2055. const { BestOrWinFixBattle } = HWHClasses;
  2056. const bFix = new BestOrWinFixBattle(cloneBattle);
  2057. bFix.setNoMakeWin(noFixWin);
  2058. let endTime = Date.now() + 3e4;
  2059. if (endTime < cloneBattle.endTime) {
  2060. endTime = cloneBattle.endTime;
  2061. }
  2062. const result = await bFix.start(cloneBattle.endTime, 150);
  2063.  
  2064. if (result.result.win) {
  2065. call.args.result = result.result;
  2066. call.args.progress = result.progress;
  2067. changeRequest = true;
  2068. } else if (result.value) {
  2069. if (
  2070. await popup.confirm('Поражение<br>Лучший результат: ' + result.value + '%', [
  2071. { msg: 'Отмена', result: 0 },
  2072. { msg: 'Принять', result: 1 },
  2073. ])
  2074. ) {
  2075. call.args.result = result.result;
  2076. call.args.progress = result.progress;
  2077. changeRequest = true;
  2078. }
  2079. }
  2080. } catch (error) {
  2081. console.error(error);
  2082. }
  2083. }
  2084.  
  2085. if (!call.args.result.win) {
  2086. let resultPopup = false;
  2087. if (call.name == 'adventure_endBattle' ||
  2088. //call.name == 'invasion_bossEnd' ||
  2089. call.name == 'bossEndBattle' ||
  2090. call.name == 'adventureSolo_endBattle') {
  2091. resultPopup = await showMsgs(I18N('MSG_HAVE_BEEN_DEFEATED'), I18N('BTN_OK'), I18N('BTN_CANCEL'), I18N('BTN_AUTO'));
  2092. } else if (call.name == 'clanWarEndBattle' ||
  2093. call.name == 'crossClanWar_endBattle') {
  2094. resultPopup = await showMsg(I18N('MSG_HAVE_BEEN_DEFEATED'), I18N('BTN_OK'), I18N('BTN_AUTO_F5'));
  2095. } else if (call.name !== 'epicBrawl_endBattle' && call.name !== 'titanArenaEndBattle') {
  2096. resultPopup = await showMsg(I18N('MSG_HAVE_BEEN_DEFEATED'), I18N('BTN_OK'), I18N('BTN_CANCEL'));
  2097. }
  2098. if (resultPopup) {
  2099. if (call.name == 'invasion_bossEnd') {
  2100. this.errorRequest = true;
  2101. }
  2102. fixBattle(call.args.progress[0].attackers.heroes);
  2103. fixBattle(call.args.progress[0].defenders.heroes);
  2104. changeRequest = true;
  2105. if (resultPopup > 1) {
  2106. this.onReadySuccess = testAutoBattle;
  2107. // setTimeout(bossBattle, 1000);
  2108. }
  2109. }
  2110. } else if (call.args.result.stars < 3 && call.name == 'towerEndBattle') {
  2111. resultPopup = await showMsg(I18N('LOST_HEROES'), I18N('BTN_OK'), I18N('BTN_CANCEL'), I18N('BTN_AUTO'));
  2112. if (resultPopup) {
  2113. fixBattle(call.args.progress[0].attackers.heroes);
  2114. fixBattle(call.args.progress[0].defenders.heroes);
  2115. changeRequest = true;
  2116. if (resultPopup > 1) {
  2117. this.onReadySuccess = testAutoBattle;
  2118. }
  2119. }
  2120. }
  2121. // Потасовки
  2122. if (isChecked('autoBrawls') && !isBrawlsAutoStart && call.name == 'brawl_endBattle') {}
  2123. }
  2124. /**
  2125. * Save pack for Brawls
  2126. *
  2127. * Сохраняем пачку для потасовок
  2128. */
  2129. if (isChecked('autoBrawls') && !isBrawlsAutoStart && call.name == 'brawl_startBattle') {
  2130. console.log(JSON.stringify(call.args));
  2131. brawlsPack = call.args;
  2132. if (
  2133. await popup.confirm(
  2134. I18N('START_AUTO_BRAWLS'),
  2135. [
  2136. { msg: I18N('BTN_NO'), result: false },
  2137. { msg: I18N('BTN_YES'), result: true },
  2138. ],
  2139. [
  2140. {
  2141. name: 'isAuto',
  2142. label: I18N('BRAWL_AUTO_PACK'),
  2143. checked: false,
  2144. },
  2145. ]
  2146. )
  2147. ) {
  2148. isBrawlsAutoStart = true;
  2149. const isAuto = popup.getCheckBoxes().find((e) => e.name === 'isAuto');
  2150. this.errorRequest = true;
  2151. testBrawls(isAuto.checked);
  2152. }
  2153. }
  2154. /**
  2155. * Canceled fight in Asgard
  2156. * Отмена боя в Асгарде
  2157. */
  2158. if (call.name == 'clanRaid_endBossBattle' && isChecked('cancelBattle')) {
  2159. const bossDamage = call.args.progress[0].defenders.heroes[1].extra;
  2160. let maxDamage = bossDamage.damageTaken + bossDamage.damageTakenNextLevel;
  2161. const lastDamage = maxDamage;
  2162.  
  2163. const testFunc = [];
  2164.  
  2165. if (testFuntions.masterFix) {
  2166. testFunc.push({ msg: 'masterFix', isInput: true, default: 100 });
  2167. }
  2168.  
  2169. const resultPopup = await popup.confirm(
  2170. `${I18N('MSG_YOU_APPLIED')} ${lastDamage.toLocaleString()} ${I18N('MSG_DAMAGE')}.`,
  2171. [
  2172. { msg: I18N('BTN_OK'), result: false },
  2173. { msg: I18N('BTN_AUTO_F5'), result: 1 },
  2174. { msg: I18N('BTN_TRY_FIX_IT'), result: 2 },
  2175. ...testFunc,
  2176. ],
  2177. [
  2178. {
  2179. name: 'isStat',
  2180. label: I18N('CALC_STAT'),
  2181. checked: false,
  2182. },
  2183. ]
  2184. );
  2185. if (resultPopup) {
  2186. if (resultPopup == 2) {
  2187. setProgress(I18N('LETS_FIX'), false);
  2188. await new Promise((e) => setTimeout(e, 0));
  2189. const cloneBattle = structuredClone(lastBossBattle);
  2190. const endTime = cloneBattle.endTime - 1e4;
  2191. console.log('fixBossBattleStart');
  2192.  
  2193. const { BossFixBattle } = HWHClasses;
  2194. const bFix = new BossFixBattle(cloneBattle);
  2195. const result = await bFix.start(endTime, 600);
  2196. console.log(result);
  2197.  
  2198. let msgResult = I18N('DAMAGE_NO_FIXED', {
  2199. lastDamage: lastDamage.toLocaleString()
  2200. });
  2201. if (result.value > lastDamage) {
  2202. call.args.result = result.result;
  2203. call.args.progress = result.progress;
  2204. msgResult = I18N('DAMAGE_FIXED', {
  2205. lastDamage: lastDamage.toLocaleString(),
  2206. maxDamage: result.value.toLocaleString(),
  2207. });
  2208. }
  2209. console.log(lastDamage, '>', result.value);
  2210. setProgress(
  2211. msgResult +
  2212. '<br/>' +
  2213. I18N('COUNT_FIXED', {
  2214. count: result.maxCount,
  2215. }),
  2216. false,
  2217. hideProgress
  2218. );
  2219. } else if (resultPopup > 3) {
  2220. const cloneBattle = structuredClone(lastBossBattle);
  2221. const { masterFixBattle } = HWHClasses;
  2222. const mFix = new masterFixBattle(cloneBattle);
  2223. const result = await mFix.start(cloneBattle.endTime, resultPopup);
  2224. console.log(result);
  2225. let msgResult = I18N('DAMAGE_NO_FIXED', {
  2226. lastDamage: lastDamage.toLocaleString(),
  2227. });
  2228. if (result.value > lastDamage) {
  2229. maxDamage = result.value;
  2230. call.args.result = result.result;
  2231. call.args.progress = result.progress;
  2232. msgResult = I18N('DAMAGE_FIXED', {
  2233. lastDamage: lastDamage.toLocaleString(),
  2234. maxDamage: maxDamage.toLocaleString(),
  2235. });
  2236. }
  2237. console.log('Урон:', lastDamage, maxDamage);
  2238. setProgress(msgResult, false, hideProgress);
  2239. } else {
  2240. fixBattle(call.args.progress[0].attackers.heroes);
  2241. fixBattle(call.args.progress[0].defenders.heroes);
  2242. }
  2243. changeRequest = true;
  2244. }
  2245. const isStat = popup.getCheckBoxes().find((e) => e.name === 'isStat');
  2246. if (isStat.checked) {
  2247. this.onReadySuccess = testBossBattle;
  2248. }
  2249. }
  2250. /**
  2251. * Save the Asgard Boss Attack Pack
  2252. * Сохраняем пачку для атаки босса Асгарда
  2253. */
  2254. if (call.name == 'clanRaid_startBossBattle') {
  2255. console.log(JSON.stringify(call.args));
  2256. }
  2257. /**
  2258. * Saving the request to start the last battle
  2259. * Сохранение запроса начала последнего боя
  2260. */
  2261. if (
  2262. call.name == 'clanWarAttack' ||
  2263. call.name == 'crossClanWar_startBattle' ||
  2264. call.name == 'adventure_turnStartBattle' ||
  2265. call.name == 'adventureSolo_turnStartBattle' ||
  2266. call.name == 'bossAttack' ||
  2267. call.name == 'invasion_bossStart' ||
  2268. call.name == 'towerStartBattle'
  2269. ) {
  2270. nameFuncStartBattle = call.name;
  2271. lastBattleArg = call.args;
  2272.  
  2273. if (call.name == 'invasion_bossStart') {
  2274. const timePassed = Date.now() - lastBossBattleStart;
  2275. if (timePassed < invasionTimer) {
  2276. await new Promise((e) => setTimeout(e, invasionTimer - timePassed));
  2277. }
  2278. invasionTimer -= 1;
  2279. }
  2280. lastBossBattleStart = Date.now();
  2281. }
  2282. if (call.name == 'invasion_bossEnd') {
  2283. const lastBattle = lastBattleInfo;
  2284. if (lastBattle && call.args.result.win) {
  2285. lastBattle.progress = call.args.progress;
  2286. const result = await Calc(lastBattle);
  2287. let timer = getTimer(result.battleTime, 1) + addBattleTimer;
  2288. const period = Math.ceil((Date.now() - lastBossBattleStart) / 1000);
  2289. console.log(timer, period);
  2290. if (period < timer) {
  2291. timer = timer - period;
  2292. await countdownTimer(timer);
  2293. }
  2294. }
  2295. }
  2296. /**
  2297. * Disable spending divination cards
  2298. * Отключить трату карт предсказаний
  2299. */
  2300. if (call.name == 'dungeonEndBattle') {
  2301. if (call.args.isRaid) {
  2302. if (countPredictionCard <= 0) {
  2303. delete call.args.isRaid;
  2304. changeRequest = true;
  2305. } else if (countPredictionCard > 0) {
  2306. countPredictionCard--;
  2307. }
  2308. }
  2309. console.log(`Cards: ${countPredictionCard}`);
  2310. /**
  2311. * Fix endless cards
  2312. * Исправление бесконечных карт
  2313. */
  2314. const lastBattle = lastDungeonBattleData;
  2315. if (lastBattle && !call.args.isRaid) {
  2316. if (changeRequest) {
  2317. lastBattle.progress = [{ attackers: { input: ["auto", 0, 0, "auto", 0, 0] } }];
  2318. } else {
  2319. lastBattle.progress = call.args.progress;
  2320. }
  2321. const result = await Calc(lastBattle);
  2322.  
  2323. if (changeRequest) {
  2324. call.args.progress = result.progress;
  2325. call.args.result = result.result;
  2326. }
  2327. let timer = result.battleTimer + addBattleTimer;
  2328. const period = Math.ceil((Date.now() - lastDungeonBattleStart) / 1000);
  2329. console.log(timer, period);
  2330. if (period < timer) {
  2331. timer = timer - period;
  2332. await countdownTimer(timer);
  2333. }
  2334. }
  2335. }
  2336. /**
  2337. * Quiz Answer
  2338. * Ответ на викторину
  2339. */
  2340. if (call.name == 'quizAnswer') {
  2341. /**
  2342. * Automatically changes the answer to the correct one if there is one.
  2343. * Автоматически меняет ответ на правильный если он есть
  2344. */
  2345. if (lastAnswer && isChecked('getAnswer')) {
  2346. call.args.answerId = lastAnswer;
  2347. lastAnswer = null;
  2348. changeRequest = true;
  2349. }
  2350. }
  2351. /**
  2352. * Present
  2353. * Подарки
  2354. */
  2355. if (call.name == 'freebieCheck') {
  2356. freebieCheckInfo = call;
  2357. }
  2358. /** missionTimer */
  2359. if (call.name == 'missionEnd' && missionBattle) {
  2360. let startTimer = false;
  2361. if (!call.args.result.win) {
  2362. startTimer = await popup.confirm(I18N('DEFEAT_TURN_TIMER'), [
  2363. { msg: I18N('BTN_NO'), result: false },
  2364. { msg: I18N('BTN_YES'), result: true },
  2365. ]);
  2366. }
  2367.  
  2368. if (call.args.result.win || startTimer) {
  2369. missionBattle.progress = call.args.progress;
  2370. missionBattle.result = call.args.result;
  2371. const result = await Calc(missionBattle);
  2372.  
  2373. let timer = result.battleTimer + addBattleTimer;
  2374. const period = Math.ceil((Date.now() - lastMissionBattleStart) / 1000);
  2375. if (period < timer) {
  2376. timer = timer - period;
  2377. await countdownTimer(timer);
  2378. }
  2379. missionBattle = null;
  2380. } else {
  2381. this.errorRequest = true;
  2382. }
  2383. }
  2384. /**
  2385. * Getting mission data for auto-repeat
  2386. * Получение данных миссии для автоповтора
  2387. */
  2388. if (isChecked('repeatMission') &&
  2389. call.name == 'missionEnd') {
  2390. let missionInfo = {
  2391. id: call.args.id,
  2392. result: call.args.result,
  2393. heroes: call.args.progress[0].attackers.heroes,
  2394. count: 0,
  2395. }
  2396. setTimeout(async () => {
  2397. if (!isSendsMission && await popup.confirm(I18N('MSG_REPEAT_MISSION'), [
  2398. { msg: I18N('BTN_REPEAT'), result: true},
  2399. { msg: I18N('BTN_NO'), result: false},
  2400. ])) {
  2401. isStopSendMission = false;
  2402. isSendsMission = true;
  2403. sendsMission(missionInfo);
  2404. }
  2405. }, 0);
  2406. }
  2407. /**
  2408. * Getting mission data
  2409. * Получение данных миссии
  2410. * missionTimer
  2411. */
  2412. if (call.name == 'missionStart') {
  2413. lastMissionStart = call.args;
  2414. lastMissionBattleStart = Date.now();
  2415. }
  2416. /**
  2417. * Specify the quantity for Titan Orbs and Pet Eggs
  2418. * Указать количество для сфер титанов и яиц петов
  2419. */
  2420. if (isChecked('countControl') &&
  2421. (call.name == 'pet_chestOpen' ||
  2422. call.name == 'titanUseSummonCircle') &&
  2423. call.args.amount > 1) {
  2424. const startAmount = call.args.amount;
  2425. const result = await popup.confirm(I18N('MSG_SPECIFY_QUANT'), [
  2426. { msg: I18N('BTN_OPEN'), isInput: true, default: 1},
  2427. ]);
  2428. if (result) {
  2429. const item = call.name == 'pet_chestOpen' ? { id: 90, type: 'consumable' } : { id: 13, type: 'coin' };
  2430. cheats.updateInventory({
  2431. [item.type]: {
  2432. [item.id]: -(result - startAmount),
  2433. },
  2434. });
  2435. call.args.amount = result;
  2436. changeRequest = true;
  2437. }
  2438. }
  2439. /**
  2440. * Specify the amount for keys and spheres of titan artifacts
  2441. * Указать колличество для ключей и сфер артефактов титанов
  2442. */
  2443. if (isChecked('countControl') &&
  2444. (call.name == 'artifactChestOpen' ||
  2445. call.name == 'titanArtifactChestOpen') &&
  2446. call.args.amount > 1 &&
  2447. call.args.free &&
  2448. !changeRequest) {
  2449. artifactChestOpenCallName = call.name;
  2450. const startAmount = call.args.amount;
  2451. let result = await popup.confirm(I18N('MSG_SPECIFY_QUANT'), [
  2452. { msg: I18N('BTN_OPEN'), isInput: true, default: 1 },
  2453. ]);
  2454. if (result) {
  2455. const openChests = result;
  2456. let sphere = result < 10 ? 1 : 10;
  2457. call.args.amount = sphere;
  2458. for (let count = openChests - sphere; count > 0; count -= sphere) {
  2459. if (count < 10) sphere = 1;
  2460. const ident = artifactChestOpenCallName + "_" + count;
  2461. testData.calls.push({
  2462. name: artifactChestOpenCallName,
  2463. args: {
  2464. amount: sphere,
  2465. free: true,
  2466. },
  2467. ident: ident
  2468. });
  2469. if (!Array.isArray(requestHistory[this.uniqid].calls[call.name])) {
  2470. requestHistory[this.uniqid].calls[call.name] = [requestHistory[this.uniqid].calls[call.name]];
  2471. }
  2472. requestHistory[this.uniqid].calls[call.name].push(ident);
  2473. }
  2474.  
  2475. const consumableId = call.name == 'artifactChestOpen' ? 45 : 55;
  2476. cheats.updateInventory({
  2477. consumable: {
  2478. [consumableId]: -(openChests - startAmount),
  2479. },
  2480. });
  2481. artifactChestOpen = true;
  2482. changeRequest = true;
  2483. }
  2484. }
  2485. if (call.name == 'consumableUseLootBox') {
  2486. lastRussianDollId = call.args.libId;
  2487. /**
  2488. * Specify quantity for gold caskets
  2489. * Указать количество для золотых шкатулок
  2490. */
  2491. if (isChecked('countControl') &&
  2492. call.args.libId == 148 &&
  2493. call.args.amount > 1) {
  2494. const result = await popup.confirm(I18N('MSG_SPECIFY_QUANT'), [
  2495. { msg: I18N('BTN_OPEN'), isInput: true, default: call.args.amount},
  2496. ]);
  2497. call.args.amount = result;
  2498. changeRequest = true;
  2499. }
  2500. if (isChecked('countControl') && call.args.libId >= 362 && call.args.libId <= 389) {
  2501. this.massOpen = call.args.libId;
  2502. }
  2503. }
  2504. if (call.name == 'invasion_bossStart' && isChecked('tryFixIt_v2') && call.args.id == 217) {
  2505. const pack = invasionDataPacks[invasionInfo.bossLvl];
  2506. if (pack.buff != invasionInfo.buff) {
  2507. setProgress(
  2508. I18N('INVASION_BOSS_BUFF', {
  2509. bossLvl: invasionInfo.bossLvl,
  2510. needBuff: pack.buff,
  2511. haveBuff: invasionInfo.buff,
  2512. }),
  2513. false
  2514. );
  2515. } else {
  2516. call.args.pet = pack.pet;
  2517. call.args.heroes = pack.heroes;
  2518. call.args.favor = pack.favor;
  2519. changeRequest = true;
  2520. }
  2521. }
  2522. /**
  2523. * Changing the maximum number of raids in the campaign
  2524. * Изменение максимального количества рейдов в кампании
  2525. */
  2526. // if (call.name == 'missionRaid') {
  2527. // if (isChecked('countControl') && call.args.times > 1) {
  2528. // const result = +(await popup.confirm(I18N('MSG_SPECIFY_QUANT'), [
  2529. // { msg: I18N('BTN_RUN'), isInput: true, default: call.args.times },
  2530. // ]));
  2531. // call.args.times = result > call.args.times ? call.args.times : result;
  2532. // changeRequest = true;
  2533. // }
  2534. // }
  2535. }
  2536.  
  2537. let headers = requestHistory[this.uniqid].headers;
  2538. if (changeRequest) {
  2539. sourceData = JSON.stringify(testData);
  2540. headers['X-Auth-Signature'] = getSignature(headers, sourceData);
  2541. }
  2542.  
  2543. let signature = headers['X-Auth-Signature'];
  2544. if (signature) {
  2545. original.setRequestHeader.call(this, 'X-Auth-Signature', signature);
  2546. }
  2547. } catch (err) {
  2548. console.log("Request(send, " + this.uniqid + "):\n", sourceData, "Error:\n", err);
  2549. }
  2550. return sourceData;
  2551. }
  2552. /**
  2553. * Processing and substitution of incoming data
  2554. *
  2555. * Обработка и подмена входящих данных
  2556. */
  2557. async function checkChangeResponse(response) {
  2558. try {
  2559. isChange = false;
  2560. let nowTime = Math.round(Date.now() / 1000);
  2561. callsIdent = requestHistory[this.uniqid].calls;
  2562. respond = JSON.parse(response);
  2563. /**
  2564. * If the request returned an error removes the error (removes synchronization errors)
  2565. * Если запрос вернул ошибку удаляет ошибку (убирает ошибки синхронизации)
  2566. */
  2567. if (respond.error) {
  2568. isChange = true;
  2569. console.error(respond.error);
  2570. if (isChecked('showErrors')) {
  2571. popup.confirm(I18N('ERROR_MSG', {
  2572. name: respond.error.name,
  2573. description: respond.error.description,
  2574. }));
  2575. }
  2576. if (respond.error.name != 'AccountBan') {
  2577. delete respond.error;
  2578. respond.results = [];
  2579. }
  2580. }
  2581. let mainReward = null;
  2582. const allReward = {};
  2583. let countTypeReward = 0;
  2584. let readQuestInfo = false;
  2585. for (const call of respond.results) {
  2586. /**
  2587. * Obtaining initial data for completing quests
  2588. * Получение исходных данных для выполнения квестов
  2589. */
  2590. if (readQuestInfo) {
  2591. questsInfo[call.ident] = call.result.response;
  2592. }
  2593. /**
  2594. * Getting a user ID
  2595. * Получение идетификатора пользователя
  2596. */
  2597. if (call.ident == callsIdent['registration']) {
  2598. userId = call.result.response.userId;
  2599. if (localStorage['userId'] != userId) {
  2600. localStorage['newGiftSendIds'] = '';
  2601. localStorage['userId'] = userId;
  2602. }
  2603. await openOrMigrateDatabase(userId);
  2604. readQuestInfo = true;
  2605. }
  2606. /**
  2607. * Hiding donation offers 1
  2608. * Скрываем предложения доната 1
  2609. */
  2610. if (call.ident == callsIdent['billingGetAll'] && getSaveVal('noOfferDonat')) {
  2611. const billings = call.result.response?.billings;
  2612. const bundle = call.result.response?.bundle;
  2613. if (billings && bundle) {
  2614. call.result.response.billings = call.result.response.billings.filter((e) => ['repeatableOffer'].includes(e.type));
  2615. call.result.response.bundle = [];
  2616. isChange = true;
  2617. }
  2618. }
  2619. /**
  2620. * Hiding donation offers 2
  2621. * Скрываем предложения доната 2
  2622. */
  2623. if (getSaveVal('noOfferDonat') &&
  2624. (call.ident == callsIdent['offerGetAll'] ||
  2625. call.ident == callsIdent['specialOffer_getAll'])) {
  2626. let offers = call.result.response;
  2627. if (offers) {
  2628. call.result.response = offers.filter(
  2629. (e) => !['addBilling', 'bundleCarousel'].includes(e.type) || ['idleResource', 'stagesOffer'].includes(e.offerType)
  2630. );
  2631. isChange = true;
  2632. }
  2633. }
  2634. /**
  2635. * Hiding donation offers 3
  2636. * Скрываем предложения доната 3
  2637. */
  2638. if (getSaveVal('noOfferDonat') && call.result?.bundleUpdate) {
  2639. delete call.result.bundleUpdate;
  2640. isChange = true;
  2641. }
  2642. /**
  2643. * Hiding donation offers 4
  2644. * Скрываем предложения доната 4
  2645. */
  2646. if (call.result?.specialOffers) {
  2647. const offers = call.result.specialOffers;
  2648. call.result.specialOffers = offers.filter(
  2649. (e) => !['addBilling', 'bundleCarousel'].includes(e.type) || ['idleResource', 'stagesOffer'].includes(e.offerType)
  2650. );
  2651. isChange = true;
  2652. }
  2653. /**
  2654. * Copies a quiz question to the clipboard
  2655. * Копирует вопрос викторины в буфер обмена и получает на него ответ если есть
  2656. */
  2657. if (call.ident == callsIdent['quizGetNewQuestion']) {
  2658. let quest = call.result.response;
  2659. console.log(quest.question);
  2660. copyText(quest.question);
  2661. setProgress(I18N('QUESTION_COPY'), true);
  2662. quest.lang = null;
  2663. if (typeof NXFlashVars !== 'undefined') {
  2664. quest.lang = NXFlashVars.interface_lang;
  2665. }
  2666. lastQuestion = quest;
  2667. if (isChecked('getAnswer')) {
  2668. const answer = await getAnswer(lastQuestion);
  2669. let showText = '';
  2670. if (answer) {
  2671. lastAnswer = answer;
  2672. console.log(answer);
  2673. showText = `${I18N('ANSWER_KNOWN')}: ${answer}`;
  2674. } else {
  2675. showText = I18N('ANSWER_NOT_KNOWN');
  2676. }
  2677.  
  2678. try {
  2679. const hint = hintQuest(quest);
  2680. if (hint) {
  2681. showText += I18N('HINT') + hint;
  2682. }
  2683. } catch(e) {}
  2684.  
  2685. setProgress(showText, true);
  2686. }
  2687. }
  2688. /**
  2689. * Submits a question with an answer to the database
  2690. * Отправляет вопрос с ответом в базу данных
  2691. */
  2692. if (call.ident == callsIdent['quizAnswer']) {
  2693. const answer = call.result.response;
  2694. if (lastQuestion) {
  2695. const answerInfo = {
  2696. answer,
  2697. question: lastQuestion,
  2698. lang: null,
  2699. }
  2700. if (typeof NXFlashVars !== 'undefined') {
  2701. answerInfo.lang = NXFlashVars.interface_lang;
  2702. }
  2703. lastQuestion = null;
  2704. setTimeout(sendAnswerInfo, 0, answerInfo);
  2705. }
  2706. }
  2707. /**
  2708. * Get user data
  2709. * Получить даныне пользователя
  2710. */
  2711. if (call.ident == callsIdent['userGetInfo']) {
  2712. let user = call.result.response;
  2713. document.title = user.name;
  2714. userInfo = Object.assign({}, user);
  2715. delete userInfo.refillable;
  2716. if (!questsInfo['userGetInfo']) {
  2717. questsInfo['userGetInfo'] = user;
  2718. }
  2719. }
  2720. /**
  2721. * Start of the battle for recalculation
  2722. * Начало боя для прерасчета
  2723. */
  2724. if (call.ident == callsIdent['clanWarAttack'] ||
  2725. call.ident == callsIdent['crossClanWar_startBattle'] ||
  2726. call.ident == callsIdent['bossAttack'] ||
  2727. call.ident == callsIdent['battleGetReplay'] ||
  2728. call.ident == callsIdent['brawl_startBattle'] ||
  2729. call.ident == callsIdent['adventureSolo_turnStartBattle'] ||
  2730. call.ident == callsIdent['invasion_bossStart'] ||
  2731. call.ident == callsIdent['titanArenaStartBattle'] ||
  2732. call.ident == callsIdent['towerStartBattle'] ||
  2733. call.ident == callsIdent['epicBrawl_startBattle'] ||
  2734. call.ident == callsIdent['adventure_turnStartBattle']) {
  2735. let battle = call.result.response.battle || call.result.response.replay;
  2736. if (call.ident == callsIdent['brawl_startBattle'] ||
  2737. call.ident == callsIdent['bossAttack'] ||
  2738. call.ident == callsIdent['towerStartBattle'] ||
  2739. call.ident == callsIdent['invasion_bossStart']) {
  2740. battle = call.result.response;
  2741. }
  2742. lastBattleInfo = battle;
  2743. if (call.ident == callsIdent['battleGetReplay'] && call.result.response.replay.type === "clan_raid") {
  2744. if (call?.result?.response?.replay?.result?.damage) {
  2745. const damages = Object.values(call.result.response.replay.result.damage);
  2746. const bossDamage = damages.reduce((a, v) => a + v, 0);
  2747. setProgress(I18N('BOSS_DAMAGE') + bossDamage.toLocaleString(), false, hideProgress);
  2748. continue;
  2749. }
  2750. }
  2751. if (!isChecked('preCalcBattle')) {
  2752. continue;
  2753. }
  2754. const preCalcBattle = structuredClone(battle);
  2755. setProgress(I18N('BEING_RECALC'));
  2756. let battleDuration = 120;
  2757. try {
  2758. const typeBattle = getBattleType(preCalcBattle.type);
  2759. battleDuration = +lib.data.battleConfig[typeBattle.split('_')[1]].config.battleDuration;
  2760. } catch (e) { }
  2761. //console.log(battle.type);
  2762. function getBattleInfo(battle, isRandSeed) {
  2763. return new Promise(function (resolve) {
  2764. if (isRandSeed) {
  2765. battle.seed = Math.floor(Date.now() / 1000) + random(0, 1e3);
  2766. }
  2767. BattleCalc(battle, getBattleType(battle.type), e => resolve(e));
  2768. });
  2769. }
  2770. let actions = [getBattleInfo(preCalcBattle, false)];
  2771. let countTestBattle = getInput('countTestBattle');
  2772. if (call.ident == callsIdent['invasion_bossStart'] ) {
  2773. countTestBattle = 0;
  2774. }
  2775. if (call.ident == callsIdent['battleGetReplay']) {
  2776. preCalcBattle.progress = [{ attackers: { input: ['auto', 0, 0, 'auto', 0, 0] } }];
  2777. }
  2778. for (let i = 0; i < countTestBattle; i++) {
  2779. actions.push(getBattleInfo(preCalcBattle, true));
  2780. }
  2781. Promise.all(actions)
  2782. .then(e => {
  2783. e = e.map(n => ({win: n.result.win, time: n.battleTime}));
  2784. let firstBattle = e.shift();
  2785. const timer = Math.floor(battleDuration - firstBattle.time);
  2786. const min = ('00' + Math.floor(timer / 60)).slice(-2);
  2787. const sec = ('00' + Math.floor(timer - min * 60)).slice(-2);
  2788. let msg = `${I18N('THIS_TIME')} ${firstBattle.win ? I18N('VICTORY') : I18N('DEFEAT')}`;
  2789. if (e.length) {
  2790. const countWin = e.reduce((w, s) => w + s.win, 0);
  2791. msg += ` ${I18N('CHANCE_TO_WIN')}: ${Math.floor((countWin / e.length) * 100)}% (${e.length})`;
  2792. }
  2793. msg += `, ${min}:${sec}`
  2794. setProgress(msg, false, hideProgress)
  2795. });
  2796. }
  2797. /**
  2798. * Start of the Asgard boss fight
  2799. * Начало боя с боссом Асгарда
  2800. */
  2801. if (call.ident == callsIdent['clanRaid_startBossBattle']) {
  2802. lastBossBattle = call.result.response.battle;
  2803. lastBossBattle.endTime = Date.now() + 160 * 1000;
  2804. if (isChecked('preCalcBattle')) {
  2805. const result = await Calc(lastBossBattle).then(e => e.progress[0].defenders.heroes[1].extra);
  2806. const bossDamage = result.damageTaken + result.damageTakenNextLevel;
  2807. setProgress(I18N('BOSS_DAMAGE') + bossDamage.toLocaleString(), false, hideProgress);
  2808. }
  2809. }
  2810. /**
  2811. * Cancel tutorial
  2812. * Отмена туториала
  2813. */
  2814. if (isCanceledTutorial && call.ident == callsIdent['tutorialGetInfo']) {
  2815. let chains = call.result.response.chains;
  2816. for (let n in chains) {
  2817. chains[n] = 9999;
  2818. }
  2819. isChange = true;
  2820. }
  2821. /**
  2822. * Opening keys and spheres of titan artifacts
  2823. * Открытие ключей и сфер артефактов титанов
  2824. */
  2825. if (artifactChestOpen &&
  2826. (call.ident == callsIdent[artifactChestOpenCallName] ||
  2827. (callsIdent[artifactChestOpenCallName] && callsIdent[artifactChestOpenCallName].includes(call.ident)))) {
  2828. let reward = call.result.response[artifactChestOpenCallName == 'artifactChestOpen' ? 'chestReward' : 'reward'];
  2829.  
  2830. reward.forEach(e => {
  2831. for (let f in e) {
  2832. if (!allReward[f]) {
  2833. allReward[f] = {};
  2834. }
  2835. for (let o in e[f]) {
  2836. if (!allReward[f][o]) {
  2837. allReward[f][o] = e[f][o];
  2838. countTypeReward++;
  2839. } else {
  2840. allReward[f][o] += e[f][o];
  2841. }
  2842. }
  2843. }
  2844. });
  2845.  
  2846. if (!call.ident.includes(artifactChestOpenCallName)) {
  2847. mainReward = call.result.response;
  2848. }
  2849. }
  2850.  
  2851. if (countTypeReward > 20) {
  2852. correctShowOpenArtifact = 3;
  2853. } else {
  2854. correctShowOpenArtifact = 0;
  2855. }
  2856. /**
  2857. * Sum the result of opening Pet Eggs
  2858. * Суммирование результата открытия яиц питомцев
  2859. */
  2860. if (isChecked('countControl') && call.ident == callsIdent['pet_chestOpen']) {
  2861. const rewards = call.result.response.rewards;
  2862. if (rewards.length > 10) {
  2863. /**
  2864. * Removing pet cards
  2865. * Убираем карточки петов
  2866. */
  2867. for (const reward of rewards) {
  2868. if (reward.petCard) {
  2869. delete reward.petCard;
  2870. }
  2871. }
  2872. }
  2873. rewards.forEach(e => {
  2874. for (let f in e) {
  2875. if (!allReward[f]) {
  2876. allReward[f] = {};
  2877. }
  2878. for (let o in e[f]) {
  2879. if (!allReward[f][o]) {
  2880. allReward[f][o] = e[f][o];
  2881. } else {
  2882. allReward[f][o] += e[f][o];
  2883. }
  2884. }
  2885. }
  2886. });
  2887. call.result.response.rewards = [allReward];
  2888. isChange = true;
  2889. }
  2890. /**
  2891. * Removing titan cards
  2892. * Убираем карточки титанов
  2893. */
  2894. if (call.ident == callsIdent['titanUseSummonCircle']) {
  2895. if (call.result.response.rewards.length > 10) {
  2896. for (const reward of call.result.response.rewards) {
  2897. if (reward.titanCard) {
  2898. delete reward.titanCard;
  2899. }
  2900. }
  2901. isChange = true;
  2902. }
  2903. }
  2904. /**
  2905. * Auto-repeat opening matryoshkas
  2906. * АвтоПовтор открытия матрешек
  2907. */
  2908. if (isChecked('countControl') && call.ident == callsIdent['consumableUseLootBox']) {
  2909. let [countLootBox, lootBox] = Object.entries(call.result.response).pop();
  2910. countLootBox = +countLootBox;
  2911. let newCount = 0;
  2912. if (lootBox?.consumable && lootBox.consumable[lastRussianDollId]) {
  2913. newCount += lootBox.consumable[lastRussianDollId];
  2914. delete lootBox.consumable[lastRussianDollId];
  2915. }
  2916. if (
  2917. newCount &&
  2918. (await popup.confirm(`${I18N('BTN_OPEN')} ${newCount} ${I18N('OPEN_DOLLS')}?`, [
  2919. { msg: I18N('BTN_OPEN'), result: true },
  2920. { msg: I18N('BTN_NO'), result: false, isClose: true },
  2921. ]))
  2922. ) {
  2923. const [count, recursionResult] = await openRussianDolls(lastRussianDollId, newCount);
  2924. countLootBox += +count;
  2925. mergeItemsObj(lootBox, recursionResult);
  2926. isChange = true;
  2927. }
  2928.  
  2929. if (this.massOpen) {
  2930. if (
  2931. await popup.confirm(I18N('OPEN_ALL_EQUIP_BOXES'), [
  2932. { msg: I18N('BTN_OPEN'), result: true },
  2933. { msg: I18N('BTN_NO'), result: false, isClose: true },
  2934. ])
  2935. ) {
  2936. const consumable = await Send({ calls: [{ name: 'inventoryGet', args: {}, ident: 'inventoryGet' }] }).then((e) =>
  2937. Object.entries(e.results[0].result.response.consumable)
  2938. );
  2939. const calls = [];
  2940. const deleteItems = {};
  2941. for (const [libId, amount] of consumable) {
  2942. if (libId != this.massOpen && libId >= 362 && libId <= 389) {
  2943. calls.push({
  2944. name: 'consumableUseLootBox',
  2945. args: { libId, amount },
  2946. ident: 'consumableUseLootBox_' + libId,
  2947. });
  2948. deleteItems[libId] = -amount;
  2949. }
  2950. }
  2951. const responses = await Send({ calls }).then((e) => e.results.map((r) => r.result.response).flat());
  2952.  
  2953. for (const loot of responses) {
  2954. const [count, result] = Object.entries(loot).pop();
  2955. countLootBox += +count;
  2956.  
  2957. mergeItemsObj(lootBox, result);
  2958. }
  2959. isChange = true;
  2960.  
  2961. this.onReadySuccess = () => {
  2962. cheats.updateInventory({ consumable: deleteItems });
  2963. cheats.refreshInventory();
  2964. };
  2965. }
  2966. }
  2967.  
  2968. if (isChange) {
  2969. call.result.response = {
  2970. [countLootBox]: lootBox,
  2971. };
  2972. }
  2973. }
  2974. /**
  2975. * Dungeon recalculation (fix endless cards)
  2976. * Прерасчет подземки (исправление бесконечных карт)
  2977. */
  2978. if (call.ident == callsIdent['dungeonStartBattle']) {
  2979. lastDungeonBattleData = call.result.response;
  2980. lastDungeonBattleStart = Date.now();
  2981. }
  2982. /**
  2983. * Getting the number of prediction cards
  2984. * Получение количества карт предсказаний
  2985. */
  2986. if (call.ident == callsIdent['inventoryGet']) {
  2987. countPredictionCard = call.result.response.consumable[81] || 0;
  2988. }
  2989. /**
  2990. * Getting subscription status
  2991. * Получение состояния подписки
  2992. */
  2993. if (call.ident == callsIdent['subscriptionGetInfo']) {
  2994. const subscription = call.result.response.subscription;
  2995. if (subscription) {
  2996. subEndTime = subscription.endTime * 1000;
  2997. }
  2998. }
  2999. /**
  3000. * Getting prediction cards
  3001. * Получение карт предсказаний
  3002. */
  3003. if (call.ident == callsIdent['questFarm']) {
  3004. const consumable = call.result.response?.consumable;
  3005. if (consumable && consumable[81]) {
  3006. countPredictionCard += consumable[81];
  3007. console.log(`Cards: ${countPredictionCard}`);
  3008. }
  3009. }
  3010. /**
  3011. * Hiding extra servers
  3012. * Скрытие лишних серверов
  3013. */
  3014. if (call.ident == callsIdent['serverGetAll'] && isChecked('hideServers')) {
  3015. let servers = call.result.response.users.map(s => s.serverId)
  3016. call.result.response.servers = call.result.response.servers.filter(s => servers.includes(s.id));
  3017. isChange = true;
  3018. }
  3019. /**
  3020. * Displays player positions in the adventure
  3021. * Отображает позиции игроков в приключении
  3022. */
  3023. if (call.ident == callsIdent['adventure_getLobbyInfo']) {
  3024. const users = Object.values(call.result.response.users);
  3025. const mapIdent = call.result.response.mapIdent;
  3026. const adventureId = call.result.response.adventureId;
  3027. const maps = {
  3028. adv_strongford_3pl_hell: 9,
  3029. adv_valley_3pl_hell: 10,
  3030. adv_ghirwil_3pl_hell: 11,
  3031. adv_angels_3pl_hell: 12,
  3032. }
  3033. let msg = I18N('MAP') + (mapIdent in maps ? maps[mapIdent] : adventureId);
  3034. msg += '<br>' + I18N('PLAYER_POS');
  3035. for (const user of users) {
  3036. msg += `<br>${user.user.name} - ${user.currentNode}`;
  3037. }
  3038. setProgress(msg, false, hideProgress);
  3039. }
  3040. /**
  3041. * Automatic launch of a raid at the end of the adventure
  3042. * Автоматический запуск рейда при окончании приключения
  3043. */
  3044. if (call.ident == callsIdent['adventure_end']) {
  3045. autoRaidAdventure()
  3046. }
  3047. /** Удаление лавки редкостей */
  3048. if (call.ident == callsIdent['missionRaid']) {
  3049. if (call.result?.heroesMerchant) {
  3050. delete call.result.heroesMerchant;
  3051. isChange = true;
  3052. }
  3053. }
  3054. /** missionTimer */
  3055. if (call.ident == callsIdent['missionStart']) {
  3056. missionBattle = call.result.response;
  3057. }
  3058. /** Награды турнира стихий */
  3059. if (call.ident == callsIdent['hallOfFameGetTrophies']) {
  3060. const trophys = call.result.response;
  3061. const calls = [];
  3062. for (const week in trophys) {
  3063. const trophy = trophys[week];
  3064. if (!trophy.championRewardFarmed) {
  3065. calls.push({
  3066. name: 'hallOfFameFarmTrophyReward',
  3067. args: { trophyId: week, rewardType: 'champion' },
  3068. ident: 'body_champion_' + week,
  3069. });
  3070. }
  3071. if (Object.keys(trophy.clanReward).length && !trophy.clanRewardFarmed) {
  3072. calls.push({
  3073. name: 'hallOfFameFarmTrophyReward',
  3074. args: { trophyId: week, rewardType: 'clan' },
  3075. ident: 'body_clan_' + week,
  3076. });
  3077. }
  3078. }
  3079. if (calls.length) {
  3080. Send({ calls })
  3081. .then((e) => e.results.map((e) => e.result.response))
  3082. .then(async results => {
  3083. let coin18 = 0,
  3084. coin19 = 0,
  3085. gold = 0,
  3086. starmoney = 0;
  3087. for (const r of results) {
  3088. coin18 += r?.coin ? +r.coin[18] : 0;
  3089. coin19 += r?.coin ? +r.coin[19] : 0;
  3090. gold += r?.gold ? +r.gold : 0;
  3091. starmoney += r?.starmoney ? +r.starmoney : 0;
  3092. }
  3093.  
  3094. let msg = I18N('ELEMENT_TOURNAMENT_REWARD') + '<br>';
  3095. if (coin18) {
  3096. msg += cheats.translate('LIB_COIN_NAME_18') + `: ${coin18}<br>`;
  3097. }
  3098. if (coin19) {
  3099. msg += cheats.translate('LIB_COIN_NAME_19') + `: ${coin19}<br>`;
  3100. }
  3101. if (gold) {
  3102. msg += cheats.translate('LIB_PSEUDO_COIN') + `: ${gold}<br>`;
  3103. }
  3104. if (starmoney) {
  3105. msg += cheats.translate('LIB_PSEUDO_STARMONEY') + `: ${starmoney}<br>`;
  3106. }
  3107.  
  3108. await popup.confirm(msg, [{ msg: I18N('BTN_OK'), result: 0 }]);
  3109. });
  3110. }
  3111. }
  3112. if (call.ident == callsIdent['clanDomination_getInfo']) {
  3113. clanDominationGetInfo = call.result.response;
  3114. }
  3115. if (call.ident == callsIdent['clanRaid_endBossBattle']) {
  3116. console.log(call.result.response);
  3117. const damage = Object.values(call.result.response.damage).reduce((a, e) => a + e);
  3118. if (call.result.response.result.afterInvalid) {
  3119. addProgress('<br>' + I18N('SERVER_NOT_ACCEPT'));
  3120. }
  3121. addProgress('<br>Server > ' + I18N('BOSS_DAMAGE') + damage.toLocaleString());
  3122. }
  3123. if (call.ident == callsIdent['invasion_getInfo']) {
  3124. const r = call.result.response;
  3125. if (r?.actions?.length) {
  3126. const boss = r.actions.find((e) => e.payload.id === 217);
  3127. invasionInfo.buff = r.buffAmount;
  3128. invasionInfo.bossLvl = boss.payload.level;
  3129. if (isChecked('tryFixIt_v2')) {
  3130. const pack = invasionDataPacks[invasionInfo.bossLvl];
  3131. setProgress(
  3132. I18N('INVASION_BOSS_BUFF', {
  3133. bossLvl: invasionInfo.bossLvl,
  3134. needBuff: pack.buff,
  3135. haveBuff: invasionInfo.buff
  3136. }),
  3137. false
  3138. );
  3139. }
  3140. }
  3141. }
  3142. if (call.ident == callsIdent['workshopBuff_create']) {
  3143. const r = call.result.response;
  3144. if (r.id == 1) {
  3145. invasionInfo.buff = r.amount;
  3146. if (isChecked('tryFixIt_v2')) {
  3147. const pack = invasionDataPacks[invasionInfo.bossLvl];
  3148. setProgress(
  3149. I18N('INVASION_BOSS_BUFF', {
  3150. bossLvl: invasionInfo.bossLvl,
  3151. needBuff: pack.buff,
  3152. haveBuff: invasionInfo.buff,
  3153. }),
  3154. false
  3155. );
  3156. }
  3157. }
  3158. }
  3159. /*
  3160. if (call.ident == callsIdent['chatGetAll'] && call.args.chatType == 'clanDomination' && !callsIdent['clanDomination_mapState']) {
  3161. this.onReadySuccess = async function () {
  3162. const result = await Send({
  3163. calls: [
  3164. {
  3165. name: 'clanDomination_mapState',
  3166. args: {},
  3167. ident: 'clanDomination_mapState',
  3168. },
  3169. ],
  3170. }).then((e) => e.results[0].result.response);
  3171. let townPositions = result.townPositions;
  3172. let positions = {};
  3173. for (let pos in townPositions) {
  3174. let townPosition = townPositions[pos];
  3175. positions[townPosition.position] = townPosition;
  3176. }
  3177. Object.assign(clanDominationGetInfo, {
  3178. townPositions: positions,
  3179. });
  3180. let userPositions = result.userPositions;
  3181. for (let pos in clanDominationGetInfo.townPositions) {
  3182. let townPosition = clanDominationGetInfo.townPositions[pos];
  3183. if (townPosition.status) {
  3184. userPositions[townPosition.userId] = +pos;
  3185. }
  3186. }
  3187. cheats.updateMap(result);
  3188. };
  3189. }
  3190. if (call.ident == callsIdent['clanDomination_mapState']) {
  3191. const townPositions = call.result.response.townPositions;
  3192. const userPositions = call.result.response.userPositions;
  3193. for (let pos in townPositions) {
  3194. let townPos = townPositions[pos];
  3195. if (townPos.status) {
  3196. userPositions[townPos.userId] = townPos.position;
  3197. }
  3198. }
  3199. isChange = true;
  3200. }
  3201. */
  3202. }
  3203.  
  3204. if (mainReward && artifactChestOpen) {
  3205. console.log(allReward);
  3206. mainReward[artifactChestOpenCallName == 'artifactChestOpen' ? 'chestReward' : 'reward'] = [allReward];
  3207. artifactChestOpen = false;
  3208. artifactChestOpenCallName = '';
  3209. isChange = true;
  3210. }
  3211. } catch(err) {
  3212. console.log("Request(response, " + this.uniqid + "):\n", "Error:\n", response, err);
  3213. }
  3214.  
  3215. if (isChange) {
  3216. Object.defineProperty(this, 'responseText', {
  3217. writable: true
  3218. });
  3219. this.responseText = JSON.stringify(respond);
  3220. }
  3221. }
  3222.  
  3223. /**
  3224. * Request an answer to a question
  3225. *
  3226. * Запрос ответа на вопрос
  3227. */
  3228. async function getAnswer(question) {
  3229. // c29tZSBzdHJhbmdlIHN5bWJvbHM=
  3230. const quizAPI = new ZingerYWebsiteAPI('getAnswer.php', arguments, { question });
  3231. return new Promise((resolve, reject) => {
  3232. quizAPI.request().then((data) => {
  3233. if (data.result) {
  3234. resolve(data.result);
  3235. } else {
  3236. resolve(false);
  3237. }
  3238. }).catch((error) => {
  3239. console.error(error);
  3240. resolve(false);
  3241. });
  3242. })
  3243. }
  3244.  
  3245. /**
  3246. * Submitting a question and answer to a database
  3247. *
  3248. * Отправка вопроса и ответа в базу данных
  3249. */
  3250. function sendAnswerInfo(answerInfo) {
  3251. // c29tZSBub25zZW5zZQ==
  3252. const quizAPI = new ZingerYWebsiteAPI('setAnswer.php', arguments, { answerInfo });
  3253. quizAPI.request().then((data) => {
  3254. if (data.result) {
  3255. console.log(I18N('SENT_QUESTION'));
  3256. }
  3257. });
  3258. }
  3259.  
  3260. /**
  3261. * Returns the battle type by preset type
  3262. *
  3263. * Возвращает тип боя по типу пресета
  3264. */
  3265. function getBattleType(strBattleType) {
  3266. if (!strBattleType) {
  3267. return null;
  3268. }
  3269. switch (strBattleType) {
  3270. case 'titan_pvp':
  3271. return 'get_titanPvp';
  3272. case 'titan_pvp_manual':
  3273. case 'titan_clan_pvp':
  3274. case 'clan_pvp_titan':
  3275. case 'clan_global_pvp_titan':
  3276. case 'brawl_titan':
  3277. case 'challenge_titan':
  3278. case 'titan_mission':
  3279. return 'get_titanPvpManual';
  3280. case 'clan_raid': // Asgard Boss // Босс асгарда
  3281. case 'adventure': // Adventures // Приключения
  3282. case 'clan_global_pvp':
  3283. case 'epic_brawl':
  3284. case 'clan_pvp':
  3285. return 'get_clanPvp';
  3286. case 'dungeon_titan':
  3287. case 'titan_tower':
  3288. return 'get_titan';
  3289. case 'tower':
  3290. case 'clan_dungeon':
  3291. return 'get_tower';
  3292. case 'pve':
  3293. case 'mission':
  3294. return 'get_pve';
  3295. case 'mission_boss':
  3296. return 'get_missionBoss';
  3297. case 'challenge':
  3298. case 'pvp_manual':
  3299. return 'get_pvpManual';
  3300. case 'grand':
  3301. case 'arena':
  3302. case 'pvp':
  3303. case 'clan_domination':
  3304. return 'get_pvp';
  3305. case 'core':
  3306. return 'get_core';
  3307. default: {
  3308. if (strBattleType.includes('invasion')) {
  3309. return 'get_invasion';
  3310. }
  3311. if (strBattleType.includes('boss')) {
  3312. return 'get_boss';
  3313. }
  3314. if (strBattleType.includes('titan_arena')) {
  3315. return 'get_titanPvpManual';
  3316. }
  3317. return 'get_clanPvp';
  3318. }
  3319. }
  3320. }
  3321. /**
  3322. * Returns the class name of the passed object
  3323. *
  3324. * Возвращает название класса переданного объекта
  3325. */
  3326. function getClass(obj) {
  3327. return {}.toString.call(obj).slice(8, -1);
  3328. }
  3329. /**
  3330. * Calculates the request signature
  3331. *
  3332. * Расчитывает сигнатуру запроса
  3333. */
  3334. this.getSignature = function(headers, data) {
  3335. const sign = {
  3336. signature: '',
  3337. length: 0,
  3338. add: function (text) {
  3339. this.signature += text;
  3340. if (this.length < this.signature.length) {
  3341. this.length = 3 * (this.signature.length + 1) >> 1;
  3342. }
  3343. },
  3344. }
  3345. sign.add(headers["X-Request-Id"]);
  3346. sign.add(':');
  3347. sign.add(headers["X-Auth-Token"]);
  3348. sign.add(':');
  3349. sign.add(headers["X-Auth-Session-Id"]);
  3350. sign.add(':');
  3351. sign.add(data);
  3352. sign.add(':');
  3353. sign.add('LIBRARY-VERSION=1');
  3354. sign.add('UNIQUE-SESSION-ID=' + headers["X-Env-Unique-Session-Id"]);
  3355.  
  3356. return md5(sign.signature);
  3357. }
  3358.  
  3359. class HotkeyManager {
  3360. constructor() {
  3361. if (HotkeyManager.instance) {
  3362. return HotkeyManager.instance;
  3363. }
  3364. this.hotkeys = [];
  3365. document.addEventListener('keydown', this.handleKeyDown.bind(this));
  3366. HotkeyManager.instance = this;
  3367. }
  3368.  
  3369. handleKeyDown(event) {
  3370. const key = event.key.toLowerCase();
  3371. const mods = {
  3372. ctrl: event.ctrlKey,
  3373. alt: event.altKey,
  3374. shift: event.shiftKey,
  3375. };
  3376.  
  3377. this.hotkeys.forEach((hotkey) => {
  3378. if (hotkey.key === key && hotkey.ctrl === mods.ctrl && hotkey.alt === mods.alt && hotkey.shift === mods.shift) {
  3379. hotkey.callback(hotkey);
  3380. }
  3381. });
  3382. }
  3383.  
  3384. add(key, opt = {}, callback) {
  3385. this.hotkeys.push({
  3386. key: key.toLowerCase(),
  3387. callback,
  3388. ctrl: opt.ctrl || false,
  3389. alt: opt.alt || false,
  3390. shift: opt.shift || false,
  3391. });
  3392. }
  3393.  
  3394. remove(key, opt = {}) {
  3395. this.hotkeys = this.hotkeys.filter((hotkey) => {
  3396. return !(
  3397. hotkey.key === key.toLowerCase() &&
  3398. hotkey.ctrl === (opt.ctrl || false) &&
  3399. hotkey.alt === (opt.alt || false) &&
  3400. hotkey.shift === (opt.shift || false)
  3401. );
  3402. });
  3403. }
  3404.  
  3405. static getInst() {
  3406. if (!HotkeyManager.instance) {
  3407. new HotkeyManager();
  3408. }
  3409. return HotkeyManager.instance;
  3410. }
  3411. }
  3412.  
  3413. class MouseClicker {
  3414. constructor(element) {
  3415. if (MouseClicker.instance) {
  3416. return MouseClicker.instance;
  3417. }
  3418. this.element = element;
  3419. this.mouse = {
  3420. bubbles: true,
  3421. cancelable: true,
  3422. clientX: 0,
  3423. clientY: 0,
  3424. };
  3425. this.element.addEventListener('mousemove', this.handleMouseMove.bind(this));
  3426. this.clickInfo = {};
  3427. this.nextTimeoutId = 1;
  3428. MouseClicker.instance = this;
  3429. }
  3430.  
  3431. handleMouseMove(event) {
  3432. this.mouse.clientX = event.clientX;
  3433. this.mouse.clientY = event.clientY;
  3434. }
  3435.  
  3436. click(options) {
  3437. options = options || this.mouse;
  3438. this.element.dispatchEvent(new MouseEvent('mousedown', options));
  3439. this.element.dispatchEvent(new MouseEvent('mouseup', options));
  3440. }
  3441.  
  3442. start(interval = 1000, clickCount = Infinity) {
  3443. const currentMouse = { ...this.mouse };
  3444. const timeoutId = this.nextTimeoutId++;
  3445. let count = 0;
  3446.  
  3447. const clickTimeout = () => {
  3448. this.click(currentMouse);
  3449. count++;
  3450. if (count < clickCount) {
  3451. this.clickInfo[timeoutId].timeout = setTimeout(clickTimeout, interval);
  3452. } else {
  3453. delete this.clickInfo[timeoutId];
  3454. }
  3455. };
  3456.  
  3457. this.clickInfo[timeoutId] = {
  3458. timeout: setTimeout(clickTimeout, interval),
  3459. count: clickCount,
  3460. };
  3461. return timeoutId;
  3462. }
  3463.  
  3464. stop(timeoutId) {
  3465. if (this.clickInfo[timeoutId]) {
  3466. clearTimeout(this.clickInfo[timeoutId].timeout);
  3467. delete this.clickInfo[timeoutId];
  3468. }
  3469. }
  3470.  
  3471. stopAll() {
  3472. for (const timeoutId in this.clickInfo) {
  3473. clearTimeout(this.clickInfo[timeoutId].timeout);
  3474. }
  3475. this.clickInfo = {};
  3476. }
  3477.  
  3478. static getInst(element) {
  3479. if (!MouseClicker.instance) {
  3480. new MouseClicker(element);
  3481. }
  3482. return MouseClicker.instance;
  3483. }
  3484. }
  3485.  
  3486. let extintionsList = [];
  3487. /**
  3488. * Creates an interface
  3489. *
  3490. * Создает интерфейс
  3491. */
  3492. function createInterface() {
  3493. popup.init();
  3494. scriptMenu.init({
  3495. showMenu: true
  3496. });
  3497. scriptMenu.addHeader(GM_info.script.name, justInfo);
  3498. const versionHeader = scriptMenu.addHeader('v' + GM_info.script.version);
  3499. if (extintionsList.length) {
  3500. versionHeader.title = '';
  3501. versionHeader.style.color = 'red';
  3502. for (const extintion of extintionsList) {
  3503. const { name, ver, author } = extintion;
  3504. versionHeader.title += name + ', v' + ver + ' by ' + author + '\n';
  3505. }
  3506. }
  3507. // AutoClicker
  3508. const hkm = new HotkeyManager();
  3509. const fc = document.getElementById('flash-content') || document.getElementById('game');
  3510. const mc = new MouseClicker(fc);
  3511. function toggleClicker(self, timeout) {
  3512. if (self.onClick) {
  3513. console.log('Останавливаем клики');
  3514. mc.stop(self.onClick);
  3515. self.onClick = false;
  3516. } else {
  3517. console.log('Стартуем клики');
  3518. self.onClick = mc.start(timeout);
  3519. }
  3520. }
  3521. hkm.add('L', { ctrl: true }, (self) => {
  3522. console.log('Нажата комбинация "Ctrl+L"');
  3523. toggleClicker(self, 20);
  3524. });
  3525. hkm.add('M', { ctrl: true }, (self) => {
  3526. console.log('Нажата комбинация "Ctrl+M"');
  3527. toggleClicker(self, 100);
  3528. });
  3529. }
  3530.  
  3531. function addExtentionName(name, ver, author) {
  3532. extintionsList.push({
  3533. name,
  3534. ver,
  3535. author,
  3536. });
  3537. }
  3538.  
  3539. function addControls() {
  3540. createInterface();
  3541. const checkboxDetails = scriptMenu.addDetails(I18N('SETTINGS'));
  3542. for (let name in checkboxes) {
  3543. if (checkboxes[name].hide) {
  3544. continue;
  3545. }
  3546. checkboxes[name].cbox = scriptMenu.addCheckbox(checkboxes[name].label, checkboxes[name].title, checkboxDetails);
  3547. /**
  3548. * Getting the state of checkboxes from storage
  3549. * Получаем состояние чекбоксов из storage
  3550. */
  3551. let val = storage.get(name, null);
  3552. if (val != null) {
  3553. checkboxes[name].cbox.checked = val;
  3554. } else {
  3555. storage.set(name, checkboxes[name].default);
  3556. checkboxes[name].cbox.checked = checkboxes[name].default;
  3557. }
  3558. /**
  3559. * Tracing the change event of the checkbox for writing to storage
  3560. * Отсеживание события изменения чекбокса для записи в storage
  3561. */
  3562. checkboxes[name].cbox.dataset['name'] = name;
  3563. checkboxes[name].cbox.addEventListener('change', async function (event) {
  3564. const nameCheckbox = this.dataset['name'];
  3565. /*
  3566. if (this.checked && nameCheckbox == 'cancelBattle') {
  3567. this.checked = false;
  3568. if (await popup.confirm(I18N('MSG_BAN_ATTENTION'), [
  3569. { msg: I18N('BTN_NO_I_AM_AGAINST'), result: true },
  3570. { msg: I18N('BTN_YES_I_AGREE'), result: false },
  3571. ])) {
  3572. return;
  3573. }
  3574. this.checked = true;
  3575. }
  3576. */
  3577. storage.set(nameCheckbox, this.checked);
  3578. })
  3579. }
  3580.  
  3581. const inputDetails = scriptMenu.addDetails(I18N('VALUES'));
  3582. for (let name in inputs) {
  3583. inputs[name].input = scriptMenu.addInputText(inputs[name].title, false, inputDetails);
  3584. /**
  3585. * Get inputText state from storage
  3586. * Получаем состояние inputText из storage
  3587. */
  3588. let val = storage.get(name, null);
  3589. if (val != null) {
  3590. inputs[name].input.value = val;
  3591. } else {
  3592. storage.set(name, inputs[name].default);
  3593. inputs[name].input.value = inputs[name].default;
  3594. }
  3595. /**
  3596. * Tracing a field change event for a record in storage
  3597. * Отсеживание события изменения поля для записи в storage
  3598. */
  3599. inputs[name].input.dataset['name'] = name;
  3600. inputs[name].input.addEventListener('input', function () {
  3601. const inputName = this.dataset['name'];
  3602. let value = +this.value;
  3603. if (!value || Number.isNaN(value)) {
  3604. value = storage.get(inputName, inputs[inputName].default);
  3605. inputs[name].input.value = value;
  3606. }
  3607. storage.set(inputName, value);
  3608. })
  3609. }
  3610. }
  3611.  
  3612. /**
  3613. * Sending a request
  3614. *
  3615. * Отправка запроса
  3616. */
  3617. function send(json, callback, pr) {
  3618. if (typeof json == 'string') {
  3619. json = JSON.parse(json);
  3620. }
  3621. for (const call of json.calls) {
  3622. if (!call?.context?.actionTs) {
  3623. call.context = {
  3624. actionTs: Math.floor(performance.now())
  3625. }
  3626. }
  3627. }
  3628. json = JSON.stringify(json);
  3629. /**
  3630. * We get the headlines of the previous intercepted request
  3631. * Получаем заголовки предыдущего перехваченого запроса
  3632. */
  3633. let headers = lastHeaders;
  3634. /**
  3635. * We increase the header of the query Certifier by 1
  3636. * Увеличиваем заголовок идетификатора запроса на 1
  3637. */
  3638. headers["X-Request-Id"]++;
  3639. /**
  3640. * We calculate the title with the signature
  3641. * Расчитываем заголовок с сигнатурой
  3642. */
  3643. headers["X-Auth-Signature"] = getSignature(headers, json);
  3644. /**
  3645. * Create a new ajax request
  3646. * Создаем новый AJAX запрос
  3647. */
  3648. let xhr = new XMLHttpRequest;
  3649. /**
  3650. * Indicate the previously saved URL for API queries
  3651. * Указываем ранее сохраненный URL для API запросов
  3652. */
  3653. xhr.open('POST', apiUrl, true);
  3654. /**
  3655. * Add the function to the event change event
  3656. * Добавляем функцию к событию смены статуса запроса
  3657. */
  3658. xhr.onreadystatechange = function() {
  3659. /**
  3660. * If the result of the request is obtained, we call the flask function
  3661. * Если результат запроса получен вызываем колбек функцию
  3662. */
  3663. if(xhr.readyState == 4) {
  3664. callback(xhr.response, pr);
  3665. }
  3666. };
  3667. /**
  3668. * Indicate the type of request
  3669. * Указываем тип запроса
  3670. */
  3671. xhr.responseType = 'json';
  3672. /**
  3673. * We set the request headers
  3674. * Задаем заголовки запроса
  3675. */
  3676. for(let nameHeader in headers) {
  3677. let head = headers[nameHeader];
  3678. xhr.setRequestHeader(nameHeader, head);
  3679. }
  3680. /**
  3681. * Sending a request
  3682. * Отправляем запрос
  3683. */
  3684. xhr.send(json);
  3685. }
  3686.  
  3687. let hideTimeoutProgress = 0;
  3688. /**
  3689. * Hide progress
  3690. *
  3691. * Скрыть прогресс
  3692. */
  3693. function hideProgress(timeout) {
  3694. timeout = timeout || 0;
  3695. clearTimeout(hideTimeoutProgress);
  3696. hideTimeoutProgress = setTimeout(function () {
  3697. scriptMenu.setStatus('');
  3698. }, timeout);
  3699. }
  3700. /**
  3701. * Progress display
  3702. *
  3703. * Отображение прогресса
  3704. */
  3705. function setProgress(text, hide, onclick) {
  3706. scriptMenu.setStatus(text, onclick);
  3707. hide = hide || false;
  3708. if (hide) {
  3709. hideProgress(3000);
  3710. }
  3711. }
  3712.  
  3713. /**
  3714. * Progress added
  3715. *
  3716. * Дополнение прогресса
  3717. */
  3718. function addProgress(text) {
  3719. scriptMenu.addStatus(text);
  3720. }
  3721.  
  3722. /**
  3723. * Returns the timer value depending on the subscription
  3724. *
  3725. * Возвращает значение таймера в зависимости от подписки
  3726. */
  3727. function getTimer(time, div) {
  3728. let speedDiv = 5;
  3729. if (subEndTime < Date.now()) {
  3730. speedDiv = div || 1.5;
  3731. }
  3732. return Math.max(Math.ceil(time / speedDiv + 1.5), 4);
  3733. }
  3734.  
  3735. function startSlave() {
  3736. const { slaveFixBattle } = HWHClasses;
  3737. const sFix = new slaveFixBattle();
  3738. sFix.wsStart();
  3739. }
  3740.  
  3741. this.testFuntions = {
  3742. hideProgress,
  3743. setProgress,
  3744. addProgress,
  3745. masterFix: false,
  3746. startSlave,
  3747. };
  3748.  
  3749. this.HWHFuncs = {
  3750. send,
  3751. I18N,
  3752. isChecked,
  3753. getInput,
  3754. copyText,
  3755. confShow,
  3756. hideProgress,
  3757. setProgress,
  3758. addProgress,
  3759. getTimer,
  3760. addExtentionName,
  3761. getUserInfo,
  3762. setIsCancalBattle,
  3763. random,
  3764. };
  3765.  
  3766. this.HWHClasses = {
  3767. checkChangeSend,
  3768. checkChangeResponse,
  3769. };
  3770. /**
  3771. * Calculates HASH MD5 from string
  3772. *
  3773. * Расчитывает HASH MD5 из строки
  3774. *
  3775. * [js-md5]{@link https://github.com/emn178/js-md5}
  3776. *
  3777. * @namespace md5
  3778. * @version 0.7.3
  3779. * @author Chen, Yi-Cyuan [emn178@gmail.com]
  3780. * @copyright Chen, Yi-Cyuan 2014-2017
  3781. * @license MIT
  3782. */
  3783. !function(){"use strict";function t(t){if(t)d[0]=d[16]=d[1]=d[2]=d[3]=d[4]=d[5]=d[6]=d[7]=d[8]=d[9]=d[10]=d[11]=d[12]=d[13]=d[14]=d[15]=0,this.blocks=d,this.buffer8=l;else if(a){var r=new ArrayBuffer(68);this.buffer8=new Uint8Array(r),this.blocks=new Uint32Array(r)}else this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.h0=this.h1=this.h2=this.h3=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}var r="input is invalid type",e="object"==typeof window,i=e?window:{};i.JS_MD5_NO_WINDOW&&(e=!1);var s=!e&&"object"==typeof self,h=!i.JS_MD5_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;h?i=global:s&&(i=self);var f=!i.JS_MD5_NO_COMMON_JS&&"object"==typeof module&&module.exports,o="function"==typeof define&&define.amd,a=!i.JS_MD5_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,n="0123456789abcdef".split(""),u=[128,32768,8388608,-2147483648],y=[0,8,16,24],c=["hex","array","digest","buffer","arrayBuffer","base64"],p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),d=[],l;if(a){var A=new ArrayBuffer(68);l=new Uint8Array(A),d=new Uint32Array(A)}!i.JS_MD5_NO_NODE_JS&&Array.isArray||(Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}),!a||!i.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView||(ArrayBuffer.isView=function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer});var b=function(r){return function(e){return new t(!0).update(e)[r]()}},v=function(){var r=b("hex");h&&(r=w(r)),r.create=function(){return new t},r.update=function(t){return r.create().update(t)};for(var e=0;e<c.length;++e){var i=c[e];r[i]=b(i)}return r},w=function(t){var e=eval("require('crypto')"),i=eval("require('buffer').Buffer"),s=function(s){if("string"==typeof s)return e.createHash("md5").update(s,"utf8").digest("hex");if(null===s||void 0===s)throw r;return s.constructor===ArrayBuffer&&(s=new Uint8Array(s)),Array.isArray(s)||ArrayBuffer.isView(s)||s.constructor===i?e.createHash("md5").update(new i(s)).digest("hex"):t(s)};return s};t.prototype.update=function(t){if(!this.finalized){var e,i=typeof t;if("string"!==i){if("object"!==i)throw r;if(null===t)throw r;if(a&&t.constructor===ArrayBuffer)t=new Uint8Array(t);else if(!(Array.isArray(t)||a&&ArrayBuffer.isView(t)))throw r;e=!0}for(var s,h,f=0,o=t.length,n=this.blocks,u=this.buffer8;f<o;){if(this.hashed&&(this.hashed=!1,n[0]=n[16],n[16]=n[1]=n[2]=n[3]=n[4]=n[5]=n[6]=n[7]=n[8]=n[9]=n[10]=n[11]=n[12]=n[13]=n[14]=n[15]=0),e)if(a)for(h=this.start;f<o&&h<64;++f)u[h++]=t[f];else for(h=this.start;f<o&&h<64;++f)n[h>>2]|=t[f]<<y[3&h++];else if(a)for(h=this.start;f<o&&h<64;++f)(s=t.charCodeAt(f))<128?u[h++]=s:s<2048?(u[h++]=192|s>>6,u[h++]=128|63&s):s<55296||s>=57344?(u[h++]=224|s>>12,u[h++]=128|s>>6&63,u[h++]=128|63&s):(s=65536+((1023&s)<<10|1023&t.charCodeAt(++f)),u[h++]=240|s>>18,u[h++]=128|s>>12&63,u[h++]=128|s>>6&63,u[h++]=128|63&s);else for(h=this.start;f<o&&h<64;++f)(s=t.charCodeAt(f))<128?n[h>>2]|=s<<y[3&h++]:s<2048?(n[h>>2]|=(192|s>>6)<<y[3&h++],n[h>>2]|=(128|63&s)<<y[3&h++]):s<55296||s>=57344?(n[h>>2]|=(224|s>>12)<<y[3&h++],n[h>>2]|=(128|s>>6&63)<<y[3&h++],n[h>>2]|=(128|63&s)<<y[3&h++]):(s=65536+((1023&s)<<10|1023&t.charCodeAt(++f)),n[h>>2]|=(240|s>>18)<<y[3&h++],n[h>>2]|=(128|s>>12&63)<<y[3&h++],n[h>>2]|=(128|s>>6&63)<<y[3&h++],n[h>>2]|=(128|63&s)<<y[3&h++]);this.lastByteIndex=h,this.bytes+=h-this.start,h>=64?(this.start=h-64,this.hash(),this.hashed=!0):this.start=h}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296<<0,this.bytes=this.bytes%4294967296),this}},t.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,r=this.lastByteIndex;t[r>>2]|=u[3&r],r>=56&&(this.hashed||this.hash(),t[0]=t[16],t[16]=t[1]=t[2]=t[3]=t[4]=t[5]=t[6]=t[7]=t[8]=t[9]=t[10]=t[11]=t[12]=t[13]=t[14]=t[15]=0),t[14]=this.bytes<<3,t[15]=this.hBytes<<3|this.bytes>>>29,this.hash()}},t.prototype.hash=function(){var t,r,e,i,s,h,f=this.blocks;this.first?r=((r=((t=((t=f[0]-680876937)<<7|t>>>25)-271733879<<0)^(e=((e=(-271733879^(i=((i=(-1732584194^2004318071&t)+f[1]-117830708)<<12|i>>>20)+t<<0)&(-271733879^t))+f[2]-1126478375)<<17|e>>>15)+i<<0)&(i^t))+f[3]-1316259209)<<22|r>>>10)+e<<0:(t=this.h0,r=this.h1,e=this.h2,r=((r+=((t=((t+=((i=this.h3)^r&(e^i))+f[0]-680876936)<<7|t>>>25)+r<<0)^(e=((e+=(r^(i=((i+=(e^t&(r^e))+f[1]-389564586)<<12|i>>>20)+t<<0)&(t^r))+f[2]+606105819)<<17|e>>>15)+i<<0)&(i^t))+f[3]-1044525330)<<22|r>>>10)+e<<0),r=((r+=((t=((t+=(i^r&(e^i))+f[4]-176418897)<<7|t>>>25)+r<<0)^(e=((e+=(r^(i=((i+=(e^t&(r^e))+f[5]+1200080426)<<12|i>>>20)+t<<0)&(t^r))+f[6]-1473231341)<<17|e>>>15)+i<<0)&(i^t))+f[7]-45705983)<<22|r>>>10)+e<<0,r=((r+=((t=((t+=(i^r&(e^i))+f[8]+1770035416)<<7|t>>>25)+r<<0)^(e=((e+=(r^(i=((i+=(e^t&(r^e))+f[9]-1958414417)<<12|i>>>20)+t<<0)&(t^r))+f[10]-42063)<<17|e>>>15)+i<<0)&(i^t))+f[11]-1990404162)<<22|r>>>10)+e<<0,r=((r+=((t=((t+=(i^r&(e^i))+f[12]+1804603682)<<7|t>>>25)+r<<0)^(e=((e+=(r^(i=((i+=(e^t&(r^e))+f[13]-40341101)<<12|i>>>20)+t<<0)&(t^r))+f[14]-1502002290)<<17|e>>>15)+i<<0)&(i^t))+f[15]+1236535329)<<22|r>>>10)+e<<0,r=((r+=((i=((i+=(r^e&((t=((t+=(e^i&(r^e))+f[1]-165796510)<<5|t>>>27)+r<<0)^r))+f[6]-1069501632)<<9|i>>>23)+t<<0)^t&((e=((e+=(t^r&(i^t))+f[11]+643717713)<<14|e>>>18)+i<<0)^i))+f[0]-373897302)<<20|r>>>12)+e<<0,r=((r+=((i=((i+=(r^e&((t=((t+=(e^i&(r^e))+f[5]-701558691)<<5|t>>>27)+r<<0)^r))+f[10]+38016083)<<9|i>>>23)+t<<0)^t&((e=((e+=(t^r&(i^t))+f[15]-660478335)<<14|e>>>18)+i<<0)^i))+f[4]-405537848)<<20|r>>>12)+e<<0,r=((r+=((i=((i+=(r^e&((t=((t+=(e^i&(r^e))+f[9]+568446438)<<5|t>>>27)+r<<0)^r))+f[14]-1019803690)<<9|i>>>23)+t<<0)^t&((e=((e+=(t^r&(i^t))+f[3]-187363961)<<14|e>>>18)+i<<0)^i))+f[8]+1163531501)<<20|r>>>12)+e<<0,r=((r+=((i=((i+=(r^e&((t=((t+=(e^i&(r^e))+f[13]-1444681467)<<5|t>>>27)+r<<0)^r))+f[2]-51403784)<<9|i>>>23)+t<<0)^t&((e=((e+=(t^r&(i^t))+f[7]+1735328473)<<14|e>>>18)+i<<0)^i))+f[12]-1926607734)<<20|r>>>12)+e<<0,r=((r+=((h=(i=((i+=((s=r^e)^(t=((t+=(s^i)+f[5]-378558)<<4|t>>>28)+r<<0))+f[8]-2022574463)<<11|i>>>21)+t<<0)^t)^(e=((e+=(h^r)+f[11]+1839030562)<<16|e>>>16)+i<<0))+f[14]-35309556)<<23|r>>>9)+e<<0,r=((r+=((h=(i=((i+=((s=r^e)^(t=((t+=(s^i)+f[1]-1530992060)<<4|t>>>28)+r<<0))+f[4]+1272893353)<<11|i>>>21)+t<<0)^t)^(e=((e+=(h^r)+f[7]-155497632)<<16|e>>>16)+i<<0))+f[10]-1094730640)<<23|r>>>9)+e<<0,r=((r+=((h=(i=((i+=((s=r^e)^(t=((t+=(s^i)+f[13]+681279174)<<4|t>>>28)+r<<0))+f[0]-358537222)<<11|i>>>21)+t<<0)^t)^(e=((e+=(h^r)+f[3]-722521979)<<16|e>>>16)+i<<0))+f[6]+76029189)<<23|r>>>9)+e<<0,r=((r+=((h=(i=((i+=((s=r^e)^(t=((t+=(s^i)+f[9]-640364487)<<4|t>>>28)+r<<0))+f[12]-421815835)<<11|i>>>21)+t<<0)^t)^(e=((e+=(h^r)+f[15]+530742520)<<16|e>>>16)+i<<0))+f[2]-995338651)<<23|r>>>9)+e<<0,r=((r+=((i=((i+=(r^((t=((t+=(e^(r|~i))+f[0]-198630844)<<6|t>>>26)+r<<0)|~e))+f[7]+1126891415)<<10|i>>>22)+t<<0)^((e=((e+=(t^(i|~r))+f[14]-1416354905)<<15|e>>>17)+i<<0)|~t))+f[5]-57434055)<<21|r>>>11)+e<<0,r=((r+=((i=((i+=(r^((t=((t+=(e^(r|~i))+f[12]+1700485571)<<6|t>>>26)+r<<0)|~e))+f[3]-1894986606)<<10|i>>>22)+t<<0)^((e=((e+=(t^(i|~r))+f[10]-1051523)<<15|e>>>17)+i<<0)|~t))+f[1]-2054922799)<<21|r>>>11)+e<<0,r=((r+=((i=((i+=(r^((t=((t+=(e^(r|~i))+f[8]+1873313359)<<6|t>>>26)+r<<0)|~e))+f[15]-30611744)<<10|i>>>22)+t<<0)^((e=((e+=(t^(i|~r))+f[6]-1560198380)<<15|e>>>17)+i<<0)|~t))+f[13]+1309151649)<<21|r>>>11)+e<<0,r=((r+=((i=((i+=(r^((t=((t+=(e^(r|~i))+f[4]-145523070)<<6|t>>>26)+r<<0)|~e))+f[11]-1120210379)<<10|i>>>22)+t<<0)^((e=((e+=(t^(i|~r))+f[2]+718787259)<<15|e>>>17)+i<<0)|~t))+f[9]-343485551)<<21|r>>>11)+e<<0,this.first?(this.h0=t+1732584193<<0,this.h1=r-271733879<<0,this.h2=e-1732584194<<0,this.h3=i+271733878<<0,this.first=!1):(this.h0=this.h0+t<<0,this.h1=this.h1+r<<0,this.h2=this.h2+e<<0,this.h3=this.h3+i<<0)},t.prototype.hex=function(){this.finalize();var t=this.h0,r=this.h1,e=this.h2,i=this.h3;return n[t>>4&15]+n[15&t]+n[t>>12&15]+n[t>>8&15]+n[t>>20&15]+n[t>>16&15]+n[t>>28&15]+n[t>>24&15]+n[r>>4&15]+n[15&r]+n[r>>12&15]+n[r>>8&15]+n[r>>20&15]+n[r>>16&15]+n[r>>28&15]+n[r>>24&15]+n[e>>4&15]+n[15&e]+n[e>>12&15]+n[e>>8&15]+n[e>>20&15]+n[e>>16&15]+n[e>>28&15]+n[e>>24&15]+n[i>>4&15]+n[15&i]+n[i>>12&15]+n[i>>8&15]+n[i>>20&15]+n[i>>16&15]+n[i>>28&15]+n[i>>24&15]},t.prototype.toString=t.prototype.hex,t.prototype.digest=function(){this.finalize();var t=this.h0,r=this.h1,e=this.h2,i=this.h3;return[255&t,t>>8&255,t>>16&255,t>>24&255,255&r,r>>8&255,r>>16&255,r>>24&255,255&e,e>>8&255,e>>16&255,e>>24&255,255&i,i>>8&255,i>>16&255,i>>24&255]},t.prototype.array=t.prototype.digest,t.prototype.arrayBuffer=function(){this.finalize();var t=new ArrayBuffer(16),r=new Uint32Array(t);return r[0]=this.h0,r[1]=this.h1,r[2]=this.h2,r[3]=this.h3,t},t.prototype.buffer=t.prototype.arrayBuffer,t.prototype.base64=function(){for(var t,r,e,i="",s=this.array(),h=0;h<15;)t=s[h++],r=s[h++],e=s[h++],i+=p[t>>>2]+p[63&(t<<4|r>>>4)]+p[63&(r<<2|e>>>6)]+p[63&e];return t=s[h],i+=p[t>>>2]+p[t<<4&63]+"=="};var _=v();f?module.exports=_:(i.md5=_,o&&define(function(){return _}))}();
  3784.  
  3785. /**
  3786. * Script for beautiful dialog boxes
  3787. *
  3788. * Скрипт для красивых диалоговых окошек
  3789. */
  3790. const popup = new (function () {
  3791. this.popUp,
  3792. this.downer,
  3793. this.middle,
  3794. this.msgText,
  3795. this.buttons = [];
  3796. this.checkboxes = [];
  3797. this.dialogPromice = null;
  3798. this.isInit = false;
  3799.  
  3800. this.init = function () {
  3801. if (this.isInit) {
  3802. return;
  3803. }
  3804. addStyle();
  3805. addBlocks();
  3806. addEventListeners();
  3807. this.isInit = true;
  3808. }
  3809.  
  3810. const addEventListeners = () => {
  3811. document.addEventListener('keyup', (e) => {
  3812. if (e.key == 'Escape') {
  3813. if (this.dialogPromice) {
  3814. const { func, result } = this.dialogPromice;
  3815. this.dialogPromice = null;
  3816. popup.hide();
  3817. func(result);
  3818. }
  3819. }
  3820. });
  3821. }
  3822.  
  3823. const addStyle = () => {
  3824. let style = document.createElement('style');
  3825. style.innerText = `
  3826. .PopUp_ {
  3827. position: absolute;
  3828. min-width: 300px;
  3829. max-width: 500px;
  3830. max-height: 600px;
  3831. background-color: #190e08e6;
  3832. z-index: 10001;
  3833. top: 169px;
  3834. left: 345px;
  3835. border: 3px #ce9767 solid;
  3836. border-radius: 10px;
  3837. display: flex;
  3838. flex-direction: column;
  3839. justify-content: space-around;
  3840. padding: 15px 9px;
  3841. box-sizing: border-box;
  3842. }
  3843.  
  3844. .PopUp_back {
  3845. position: absolute;
  3846. background-color: #00000066;
  3847. width: 100%;
  3848. height: 100%;
  3849. z-index: 10000;
  3850. top: 0;
  3851. left: 0;
  3852. }
  3853.  
  3854. .PopUp_close {
  3855. width: 40px;
  3856. height: 40px;
  3857. position: absolute;
  3858. right: -18px;
  3859. top: -18px;
  3860. border: 3px solid #c18550;
  3861. border-radius: 20px;
  3862. background: radial-gradient(circle, rgba(190,30,35,1) 0%, rgba(0,0,0,1) 100%);
  3863. background-position-y: 3px;
  3864. box-shadow: -1px 1px 3px black;
  3865. cursor: pointer;
  3866. box-sizing: border-box;
  3867. }
  3868.  
  3869. .PopUp_close:hover {
  3870. filter: brightness(1.2);
  3871. }
  3872.  
  3873. .PopUp_crossClose {
  3874. width: 100%;
  3875. height: 100%;
  3876. background-size: 65%;
  3877. background-position: center;
  3878. background-repeat: no-repeat;
  3879. background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='%23f4cd73' d='M 0.826 12.559 C 0.431 12.963 3.346 15.374 3.74 14.97 C 4.215 15.173 8.167 10.457 7.804 10.302 C 7.893 10.376 11.454 14.64 11.525 14.372 C 12.134 15.042 15.118 12.086 14.638 11.689 C 14.416 11.21 10.263 7.477 10.402 7.832 C 10.358 7.815 11.731 7.101 14.872 3.114 C 14.698 2.145 13.024 1.074 12.093 1.019 C 11.438 0.861 8.014 5.259 8.035 5.531 C 7.86 5.082 3.61 1.186 3.522 1.59 C 2.973 1.027 0.916 4.611 1.17 4.873 C 0.728 4.914 5.088 7.961 5.61 7.995 C 5.225 7.532 0.622 12.315 0.826 12.559 Z'/%3e%3c/svg%3e")
  3880. }
  3881.  
  3882. .PopUp_blocks {
  3883. width: 100%;
  3884. height: 50%;
  3885. display: flex;
  3886. justify-content: space-evenly;
  3887. align-items: center;
  3888. flex-wrap: wrap;
  3889. justify-content: center;
  3890. }
  3891.  
  3892. .PopUp_blocks:last-child {
  3893. margin-top: 25px;
  3894. }
  3895.  
  3896. .PopUp_buttons {
  3897. display: flex;
  3898. margin: 7px 10px;
  3899. flex-direction: column;
  3900. }
  3901.  
  3902. .PopUp_button {
  3903. background-color: #52A81C;
  3904. border-radius: 5px;
  3905. box-shadow: inset 0px -4px 10px, inset 0px 3px 2px #99fe20, 0px 0px 4px, 0px -3px 1px #d7b275, 0px 0px 0px 3px #ce9767;
  3906. cursor: pointer;
  3907. padding: 4px 12px 6px;
  3908. }
  3909.  
  3910. .PopUp_input {
  3911. text-align: center;
  3912. font-size: 16px;
  3913. height: 27px;
  3914. border: 1px solid #cf9250;
  3915. border-radius: 9px 9px 0px 0px;
  3916. background: transparent;
  3917. color: #fce1ac;
  3918. padding: 1px 10px;
  3919. box-sizing: border-box;
  3920. box-shadow: 0px 0px 4px, 0px 0px 0px 3px #ce9767;
  3921. }
  3922.  
  3923. .PopUp_checkboxes {
  3924. display: flex;
  3925. flex-direction: column;
  3926. margin: 15px 15px -5px 15px;
  3927. align-items: flex-start;
  3928. }
  3929.  
  3930. .PopUp_ContCheckbox {
  3931. margin: 2px 0px;
  3932. }
  3933.  
  3934. .PopUp_checkbox {
  3935. position: absolute;
  3936. z-index: -1;
  3937. opacity: 0;
  3938. }
  3939. .PopUp_checkbox+label {
  3940. display: inline-flex;
  3941. align-items: center;
  3942. user-select: none;
  3943.  
  3944. font-size: 15px;
  3945. font-family: sans-serif;
  3946. font-weight: 600;
  3947. font-stretch: condensed;
  3948. letter-spacing: 1px;
  3949. color: #fce1ac;
  3950. text-shadow: 0px 0px 1px;
  3951. }
  3952. .PopUp_checkbox+label::before {
  3953. content: '';
  3954. display: inline-block;
  3955. width: 20px;
  3956. height: 20px;
  3957. border: 1px solid #cf9250;
  3958. border-radius: 7px;
  3959. margin-right: 7px;
  3960. }
  3961. .PopUp_checkbox:checked+label::before {
  3962. background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%2388cb13' d='M6.564.75l-3.59 3.612-1.538-1.55L0 4.26 2.974 7.25 8 2.193z'/%3e%3c/svg%3e");
  3963. }
  3964.  
  3965. .PopUp_input::placeholder {
  3966. color: #fce1ac75;
  3967. }
  3968.  
  3969. .PopUp_input:focus {
  3970. outline: 0;
  3971. }
  3972.  
  3973. .PopUp_input + .PopUp_button {
  3974. border-radius: 0px 0px 5px 5px;
  3975. padding: 2px 18px 5px;
  3976. }
  3977.  
  3978. .PopUp_button:hover {
  3979. filter: brightness(1.2);
  3980. }
  3981.  
  3982. .PopUp_button:active {
  3983. box-shadow: inset 0px 5px 10px, inset 0px 1px 2px #99fe20, 0px 0px 4px, 0px -3px 1px #d7b275, 0px 0px 0px 3px #ce9767;
  3984. }
  3985.  
  3986. .PopUp_text {
  3987. font-size: 22px;
  3988. font-family: sans-serif;
  3989. font-weight: 600;
  3990. font-stretch: condensed;
  3991. letter-spacing: 1px;
  3992. text-align: center;
  3993. }
  3994.  
  3995. .PopUp_buttonText {
  3996. color: #E4FF4C;
  3997. text-shadow: 0px 1px 2px black;
  3998. }
  3999.  
  4000. .PopUp_msgText {
  4001. color: #FDE5B6;
  4002. text-shadow: 0px 0px 2px;
  4003. }
  4004.  
  4005. .PopUp_hideBlock {
  4006. display: none;
  4007. }
  4008. `;
  4009. document.head.appendChild(style);
  4010. }
  4011.  
  4012. const addBlocks = () => {
  4013. this.back = document.createElement('div');
  4014. this.back.classList.add('PopUp_back');
  4015. this.back.classList.add('PopUp_hideBlock');
  4016. document.body.append(this.back);
  4017.  
  4018. this.popUp = document.createElement('div');
  4019. this.popUp.classList.add('PopUp_');
  4020. this.back.append(this.popUp);
  4021.  
  4022. let upper = document.createElement('div')
  4023. upper.classList.add('PopUp_blocks');
  4024. this.popUp.append(upper);
  4025.  
  4026. this.middle = document.createElement('div')
  4027. this.middle.classList.add('PopUp_blocks');
  4028. this.middle.classList.add('PopUp_checkboxes');
  4029. this.popUp.append(this.middle);
  4030.  
  4031. this.downer = document.createElement('div')
  4032. this.downer.classList.add('PopUp_blocks');
  4033. this.popUp.append(this.downer);
  4034.  
  4035. this.msgText = document.createElement('div');
  4036. this.msgText.classList.add('PopUp_text', 'PopUp_msgText');
  4037. upper.append(this.msgText);
  4038. }
  4039.  
  4040. this.showBack = function () {
  4041. this.back.classList.remove('PopUp_hideBlock');
  4042. }
  4043.  
  4044. this.hideBack = function () {
  4045. this.back.classList.add('PopUp_hideBlock');
  4046. }
  4047.  
  4048. this.show = function () {
  4049. if (this.checkboxes.length) {
  4050. this.middle.classList.remove('PopUp_hideBlock');
  4051. }
  4052. this.showBack();
  4053. this.popUp.classList.remove('PopUp_hideBlock');
  4054. this.popUp.style.left = (window.innerWidth - this.popUp.offsetWidth) / 2 + 'px';
  4055. this.popUp.style.top = (window.innerHeight - this.popUp.offsetHeight) / 3 + 'px';
  4056. }
  4057.  
  4058. this.hide = function () {
  4059. this.hideBack();
  4060. this.popUp.classList.add('PopUp_hideBlock');
  4061. }
  4062.  
  4063. this.addAnyButton = (option) => {
  4064. const contButton = document.createElement('div');
  4065. contButton.classList.add('PopUp_buttons');
  4066. this.downer.append(contButton);
  4067.  
  4068. let inputField = {
  4069. value: option.result || option.default
  4070. }
  4071. if (option.isInput) {
  4072. inputField = document.createElement('input');
  4073. inputField.type = 'text';
  4074. if (option.placeholder) {
  4075. inputField.placeholder = option.placeholder;
  4076. }
  4077. if (option.default) {
  4078. inputField.value = option.default;
  4079. }
  4080. inputField.classList.add('PopUp_input');
  4081. contButton.append(inputField);
  4082. }
  4083.  
  4084. const button = document.createElement('div');
  4085. button.classList.add('PopUp_button');
  4086. button.title = option.title || '';
  4087. contButton.append(button);
  4088.  
  4089. const buttonText = document.createElement('div');
  4090. buttonText.classList.add('PopUp_text', 'PopUp_buttonText');
  4091. buttonText.innerHTML = option.msg;
  4092. button.append(buttonText);
  4093.  
  4094. return { button, contButton, inputField };
  4095. }
  4096.  
  4097. this.addCloseButton = () => {
  4098. let button = document.createElement('div')
  4099. button.classList.add('PopUp_close');
  4100. this.popUp.append(button);
  4101.  
  4102. let crossClose = document.createElement('div')
  4103. crossClose.classList.add('PopUp_crossClose');
  4104. button.append(crossClose);
  4105.  
  4106. return { button, contButton: button };
  4107. }
  4108.  
  4109. this.addButton = (option, buttonClick) => {
  4110.  
  4111. const { button, contButton, inputField } = option.isClose ? this.addCloseButton() : this.addAnyButton(option);
  4112. if (option.isClose) {
  4113. this.dialogPromice = { func: buttonClick, result: option.result };
  4114. }
  4115. button.addEventListener('click', () => {
  4116. let result = '';
  4117. if (option.isInput) {
  4118. result = inputField.value;
  4119. }
  4120. if (option.isClose || option.isCancel) {
  4121. this.dialogPromice = null;
  4122. }
  4123. buttonClick(result);
  4124. });
  4125.  
  4126. this.buttons.push(contButton);
  4127. }
  4128.  
  4129. this.clearButtons = () => {
  4130. while (this.buttons.length) {
  4131. this.buttons.pop().remove();
  4132. }
  4133. }
  4134.  
  4135. this.addCheckBox = (checkBox) => {
  4136. const contCheckbox = document.createElement('div');
  4137. contCheckbox.classList.add('PopUp_ContCheckbox');
  4138. this.middle.append(contCheckbox);
  4139.  
  4140. const checkbox = document.createElement('input');
  4141. checkbox.type = 'checkbox';
  4142. checkbox.id = 'PopUpCheckbox' + this.checkboxes.length;
  4143. checkbox.dataset.name = checkBox.name;
  4144. checkbox.checked = checkBox.checked;
  4145. checkbox.label = checkBox.label;
  4146. checkbox.title = checkBox.title || '';
  4147. checkbox.classList.add('PopUp_checkbox');
  4148. contCheckbox.appendChild(checkbox)
  4149.  
  4150. const checkboxLabel = document.createElement('label');
  4151. checkboxLabel.innerText = checkBox.label;
  4152. checkboxLabel.title = checkBox.title || '';
  4153. checkboxLabel.setAttribute('for', checkbox.id);
  4154. contCheckbox.appendChild(checkboxLabel);
  4155.  
  4156. this.checkboxes.push(checkbox);
  4157. }
  4158.  
  4159. this.clearCheckBox = () => {
  4160. this.middle.classList.add('PopUp_hideBlock');
  4161. while (this.checkboxes.length) {
  4162. this.checkboxes.pop().parentNode.remove();
  4163. }
  4164. }
  4165.  
  4166. this.setMsgText = (text) => {
  4167. this.msgText.innerHTML = text;
  4168. }
  4169.  
  4170. this.getCheckBoxes = () => {
  4171. const checkBoxes = [];
  4172.  
  4173. for (const checkBox of this.checkboxes) {
  4174. checkBoxes.push({
  4175. name: checkBox.dataset.name,
  4176. label: checkBox.label,
  4177. checked: checkBox.checked
  4178. });
  4179. }
  4180.  
  4181. return checkBoxes;
  4182. }
  4183.  
  4184. this.confirm = async (msg, buttOpt, checkBoxes = []) => {
  4185. if (!this.isInit) {
  4186. this.init();
  4187. }
  4188. this.clearButtons();
  4189. this.clearCheckBox();
  4190. return new Promise((complete, failed) => {
  4191. this.setMsgText(msg);
  4192. if (!buttOpt) {
  4193. buttOpt = [{ msg: 'Ok', result: true, isInput: false }];
  4194. }
  4195. for (const checkBox of checkBoxes) {
  4196. this.addCheckBox(checkBox);
  4197. }
  4198. for (let butt of buttOpt) {
  4199. this.addButton(butt, (result) => {
  4200. result = result || butt.result;
  4201. complete(result);
  4202. popup.hide();
  4203. });
  4204. if (butt.isCancel) {
  4205. this.dialogPromice = { func: complete, result: butt.result };
  4206. }
  4207. }
  4208. this.show();
  4209. });
  4210. }
  4211. });
  4212.  
  4213. this.HWHFuncs.popup = popup;
  4214.  
  4215. /**
  4216. * Script control panel
  4217. *
  4218. * Панель управления скриптом
  4219. */
  4220. const scriptMenu = new (function () {
  4221.  
  4222. this.mainMenu,
  4223. this.buttons = [],
  4224. this.checkboxes = [];
  4225. this.option = {
  4226. showMenu: false,
  4227. showDetails: {}
  4228. };
  4229.  
  4230. this.init = function (option = {}) {
  4231. this.option = Object.assign(this.option, option);
  4232. this.option.showDetails = this.loadShowDetails();
  4233. addStyle();
  4234. addBlocks();
  4235. }
  4236.  
  4237. const addStyle = () => {
  4238. style = document.createElement('style');
  4239. style.innerText = `
  4240. .scriptMenu_status {
  4241. position: absolute;
  4242. z-index: 10001;
  4243. /* max-height: 30px; */
  4244. top: -1px;
  4245. left: 30%;
  4246. cursor: pointer;
  4247. border-radius: 0px 0px 10px 10px;
  4248. background: #190e08e6;
  4249. border: 1px #ce9767 solid;
  4250. font-size: 18px;
  4251. font-family: sans-serif;
  4252. font-weight: 600;
  4253. font-stretch: condensed;
  4254. letter-spacing: 1px;
  4255. color: #fce1ac;
  4256. text-shadow: 0px 0px 1px;
  4257. transition: 0.5s;
  4258. padding: 2px 10px 3px;
  4259. }
  4260. .scriptMenu_statusHide {
  4261. top: -35px;
  4262. height: 30px;
  4263. overflow: hidden;
  4264. }
  4265. .scriptMenu_label {
  4266. position: absolute;
  4267. top: 30%;
  4268. left: -4px;
  4269. z-index: 9999;
  4270. cursor: pointer;
  4271. width: 30px;
  4272. height: 30px;
  4273. background: radial-gradient(circle, #47a41b 0%, #1a2f04 100%);
  4274. border: 1px solid #1a2f04;
  4275. border-radius: 5px;
  4276. box-shadow:
  4277. inset 0px 2px 4px #83ce26,
  4278. inset 0px -4px 6px #1a2f04,
  4279. 0px 0px 2px black,
  4280. 0px 0px 0px 2px #ce9767;
  4281. }
  4282. .scriptMenu_label:hover {
  4283. filter: brightness(1.2);
  4284. }
  4285. .scriptMenu_arrowLabel {
  4286. width: 100%;
  4287. height: 100%;
  4288. background-size: 75%;
  4289. background-position: center;
  4290. background-repeat: no-repeat;
  4291. background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='%2388cb13' d='M7.596 7.304a.802.802 0 0 1 0 1.392l-6.363 3.692C.713 12.69 0 12.345 0 11.692V4.308c0-.653.713-.998 1.233-.696l6.363 3.692Z'/%3e%3cpath fill='%2388cb13' d='M15.596 7.304a.802.802 0 0 1 0 1.392l-6.363 3.692C8.713 12.69 8 12.345 8 11.692V4.308c0-.653.713-.998 1.233-.696l6.363 3.692Z'/%3e%3c/svg%3e");
  4292. box-shadow: 0px 1px 2px #000;
  4293. border-radius: 5px;
  4294. filter: drop-shadow(0px 1px 2px #000D);
  4295. }
  4296. .scriptMenu_main {
  4297. position: absolute;
  4298. max-width: 285px;
  4299. z-index: 9999;
  4300. top: 50%;
  4301. transform: translateY(-40%);
  4302. background: #190e08e6;
  4303. border: 1px #ce9767 solid;
  4304. border-radius: 0px 10px 10px 0px;
  4305. border-left: none;
  4306. padding: 5px 10px 5px 5px;
  4307. box-sizing: border-box;
  4308. font-size: 15px;
  4309. font-family: sans-serif;
  4310. font-weight: 600;
  4311. font-stretch: condensed;
  4312. letter-spacing: 1px;
  4313. color: #fce1ac;
  4314. text-shadow: 0px 0px 1px;
  4315. transition: 1s;
  4316. display: flex;
  4317. flex-direction: column;
  4318. flex-wrap: nowrap;
  4319. }
  4320. .scriptMenu_showMenu {
  4321. display: none;
  4322. }
  4323. .scriptMenu_showMenu:checked~.scriptMenu_main {
  4324. left: 0px;
  4325. }
  4326. .scriptMenu_showMenu:not(:checked)~.scriptMenu_main {
  4327. left: -300px;
  4328. }
  4329. .scriptMenu_divInput {
  4330. margin: 2px;
  4331. }
  4332. .scriptMenu_divInputText {
  4333. margin: 2px;
  4334. align-self: center;
  4335. display: flex;
  4336. }
  4337. .scriptMenu_checkbox {
  4338. position: absolute;
  4339. z-index: -1;
  4340. opacity: 0;
  4341. }
  4342. .scriptMenu_checkbox+label {
  4343. display: inline-flex;
  4344. align-items: center;
  4345. user-select: none;
  4346. }
  4347. .scriptMenu_checkbox+label::before {
  4348. content: '';
  4349. display: inline-block;
  4350. width: 20px;
  4351. height: 20px;
  4352. border: 1px solid #cf9250;
  4353. border-radius: 7px;
  4354. margin-right: 7px;
  4355. }
  4356. .scriptMenu_checkbox:checked+label::before {
  4357. background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%2388cb13' d='M6.564.75l-3.59 3.612-1.538-1.55L0 4.26 2.974 7.25 8 2.193z'/%3e%3c/svg%3e");
  4358. }
  4359. .scriptMenu_close {
  4360. width: 40px;
  4361. height: 40px;
  4362. position: absolute;
  4363. right: -18px;
  4364. top: -18px;
  4365. border: 3px solid #c18550;
  4366. border-radius: 20px;
  4367. background: radial-gradient(circle, rgba(190,30,35,1) 0%, rgba(0,0,0,1) 100%);
  4368. background-position-y: 3px;
  4369. box-shadow: -1px 1px 3px black;
  4370. cursor: pointer;
  4371. box-sizing: border-box;
  4372. }
  4373. .scriptMenu_close:hover {
  4374. filter: brightness(1.2);
  4375. }
  4376. .scriptMenu_crossClose {
  4377. width: 100%;
  4378. height: 100%;
  4379. background-size: 65%;
  4380. background-position: center;
  4381. background-repeat: no-repeat;
  4382. background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='%23f4cd73' d='M 0.826 12.559 C 0.431 12.963 3.346 15.374 3.74 14.97 C 4.215 15.173 8.167 10.457 7.804 10.302 C 7.893 10.376 11.454 14.64 11.525 14.372 C 12.134 15.042 15.118 12.086 14.638 11.689 C 14.416 11.21 10.263 7.477 10.402 7.832 C 10.358 7.815 11.731 7.101 14.872 3.114 C 14.698 2.145 13.024 1.074 12.093 1.019 C 11.438 0.861 8.014 5.259 8.035 5.531 C 7.86 5.082 3.61 1.186 3.522 1.59 C 2.973 1.027 0.916 4.611 1.17 4.873 C 0.728 4.914 5.088 7.961 5.61 7.995 C 5.225 7.532 0.622 12.315 0.826 12.559 Z'/%3e%3c/svg%3e")
  4383. }
  4384. .scriptMenu_button {
  4385. user-select: none;
  4386. border-radius: 5px;
  4387. cursor: pointer;
  4388. padding: 5px 14px 8px;
  4389. margin: 4px;
  4390. background: radial-gradient(circle, rgba(165,120,56,1) 80%, rgba(0,0,0,1) 110%);
  4391. box-shadow: inset 0px -4px 6px #442901, inset 0px 1px 6px #442901, inset 0px 0px 6px, 0px 0px 4px, 0px 0px 0px 2px #ce9767;
  4392. }
  4393. .scriptMenu_button:hover {
  4394. filter: brightness(1.2);
  4395. }
  4396. .scriptMenu_button:active {
  4397. box-shadow: inset 0px 4px 6px #442901, inset 0px 4px 6px #442901, inset 0px 0px 6px, 0px 0px 4px, 0px 0px 0px 2px #ce9767;
  4398. }
  4399. .scriptMenu_buttonText {
  4400. color: #fce5b7;
  4401. text-shadow: 0px 1px 2px black;
  4402. text-align: center;
  4403. }
  4404. .scriptMenu_header {
  4405. text-align: center;
  4406. align-self: center;
  4407. font-size: 15px;
  4408. margin: 0px 15px;
  4409. }
  4410. .scriptMenu_header a {
  4411. color: #fce5b7;
  4412. text-decoration: none;
  4413. }
  4414. .scriptMenu_InputText {
  4415. text-align: center;
  4416. width: 130px;
  4417. height: 24px;
  4418. border: 1px solid #cf9250;
  4419. border-radius: 9px;
  4420. background: transparent;
  4421. color: #fce1ac;
  4422. padding: 0px 10px;
  4423. box-sizing: border-box;
  4424. }
  4425. .scriptMenu_InputText:focus {
  4426. filter: brightness(1.2);
  4427. outline: 0;
  4428. }
  4429. .scriptMenu_InputText::placeholder {
  4430. color: #fce1ac75;
  4431. }
  4432. .scriptMenu_Summary {
  4433. cursor: pointer;
  4434. margin-left: 7px;
  4435. }
  4436. .scriptMenu_Details {
  4437. align-self: center;
  4438. }
  4439. `;
  4440. document.head.appendChild(style);
  4441. }
  4442.  
  4443. const addBlocks = () => {
  4444. const main = document.createElement('div');
  4445. document.body.appendChild(main);
  4446.  
  4447. this.status = document.createElement('div');
  4448. this.status.classList.add('scriptMenu_status');
  4449. this.setStatus('');
  4450. main.appendChild(this.status);
  4451.  
  4452. const label = document.createElement('label');
  4453. label.classList.add('scriptMenu_label');
  4454. label.setAttribute('for', 'checkbox_showMenu');
  4455. main.appendChild(label);
  4456.  
  4457. const arrowLabel = document.createElement('div');
  4458. arrowLabel.classList.add('scriptMenu_arrowLabel');
  4459. label.appendChild(arrowLabel);
  4460.  
  4461. const checkbox = document.createElement('input');
  4462. checkbox.type = 'checkbox';
  4463. checkbox.id = 'checkbox_showMenu';
  4464. checkbox.checked = this.option.showMenu;
  4465. checkbox.classList.add('scriptMenu_showMenu');
  4466. main.appendChild(checkbox);
  4467.  
  4468. this.mainMenu = document.createElement('div');
  4469. this.mainMenu.classList.add('scriptMenu_main');
  4470. main.appendChild(this.mainMenu);
  4471.  
  4472. const closeButton = document.createElement('label');
  4473. closeButton.classList.add('scriptMenu_close');
  4474. closeButton.setAttribute('for', 'checkbox_showMenu');
  4475. this.mainMenu.appendChild(closeButton);
  4476.  
  4477. const crossClose = document.createElement('div');
  4478. crossClose.classList.add('scriptMenu_crossClose');
  4479. closeButton.appendChild(crossClose);
  4480. }
  4481.  
  4482. this.setStatus = (text, onclick) => {
  4483. if (!text) {
  4484. this.status.classList.add('scriptMenu_statusHide');
  4485. this.status.innerHTML = '';
  4486. } else {
  4487. this.status.classList.remove('scriptMenu_statusHide');
  4488. this.status.innerHTML = text;
  4489. }
  4490.  
  4491. if (typeof onclick == 'function') {
  4492. this.status.addEventListener("click", onclick, {
  4493. once: true
  4494. });
  4495. }
  4496. }
  4497.  
  4498. this.addStatus = (text) => {
  4499. if (!this.status.innerHTML) {
  4500. this.status.classList.remove('scriptMenu_statusHide');
  4501. }
  4502. this.status.innerHTML += text;
  4503. }
  4504.  
  4505. /**
  4506. * Adding a text element
  4507. *
  4508. * Добавление текстового элемента
  4509. * @param {String} text text // текст
  4510. * @param {Function} func Click function // функция по клику
  4511. * @param {HTMLDivElement} main parent // родитель
  4512. */
  4513. this.addHeader = (text, func, main) => {
  4514. main = main || this.mainMenu;
  4515. const header = document.createElement('div');
  4516. header.classList.add('scriptMenu_header');
  4517. header.innerHTML = text;
  4518. if (typeof func == 'function') {
  4519. header.addEventListener('click', func);
  4520. }
  4521. main.appendChild(header);
  4522. return header;
  4523. }
  4524.  
  4525. /**
  4526. * Adding a button
  4527. *
  4528. * Добавление кнопки
  4529. * @param {String} text
  4530. * @param {Function} func
  4531. * @param {String} title
  4532. * @param {HTMLDivElement} main parent // родитель
  4533. */
  4534. this.addButton = (text, func, title, main) => {
  4535. main = main || this.mainMenu;
  4536. const button = document.createElement('div');
  4537. button.classList.add('scriptMenu_button');
  4538. button.title = title;
  4539. button.addEventListener('click', func);
  4540. main.appendChild(button);
  4541.  
  4542. const buttonText = document.createElement('div');
  4543. buttonText.classList.add('scriptMenu_buttonText');
  4544. buttonText.innerText = text;
  4545. button.appendChild(buttonText);
  4546. this.buttons.push(button);
  4547.  
  4548. return button;
  4549. }
  4550.  
  4551. /**
  4552. * Adding checkbox
  4553. *
  4554. * Добавление чекбокса
  4555. * @param {String} label
  4556. * @param {String} title
  4557. * @param {HTMLDivElement} main parent // родитель
  4558. * @returns
  4559. */
  4560. this.addCheckbox = (label, title, main) => {
  4561. main = main || this.mainMenu;
  4562. const divCheckbox = document.createElement('div');
  4563. divCheckbox.classList.add('scriptMenu_divInput');
  4564. divCheckbox.title = title;
  4565. main.appendChild(divCheckbox);
  4566.  
  4567. const checkbox = document.createElement('input');
  4568. checkbox.type = 'checkbox';
  4569. checkbox.id = 'scriptMenuCheckbox' + this.checkboxes.length;
  4570. checkbox.classList.add('scriptMenu_checkbox');
  4571. divCheckbox.appendChild(checkbox)
  4572.  
  4573. const checkboxLabel = document.createElement('label');
  4574. checkboxLabel.innerText = label;
  4575. checkboxLabel.setAttribute('for', checkbox.id);
  4576. divCheckbox.appendChild(checkboxLabel);
  4577.  
  4578. this.checkboxes.push(checkbox);
  4579. return checkbox;
  4580. }
  4581.  
  4582. /**
  4583. * Adding input field
  4584. *
  4585. * Добавление поля ввода
  4586. * @param {String} title
  4587. * @param {String} placeholder
  4588. * @param {HTMLDivElement} main parent // родитель
  4589. * @returns
  4590. */
  4591. this.addInputText = (title, placeholder, main) => {
  4592. main = main || this.mainMenu;
  4593. const divInputText = document.createElement('div');
  4594. divInputText.classList.add('scriptMenu_divInputText');
  4595. divInputText.title = title;
  4596. main.appendChild(divInputText);
  4597.  
  4598. const newInputText = document.createElement('input');
  4599. newInputText.type = 'text';
  4600. if (placeholder) {
  4601. newInputText.placeholder = placeholder;
  4602. }
  4603. newInputText.classList.add('scriptMenu_InputText');
  4604. divInputText.appendChild(newInputText)
  4605. return newInputText;
  4606. }
  4607.  
  4608. /**
  4609. * Adds a dropdown block
  4610. *
  4611. * Добавляет раскрывающийся блок
  4612. * @param {String} summary
  4613. * @param {String} name
  4614. * @returns
  4615. */
  4616. this.addDetails = (summaryText, name = null) => {
  4617. const details = document.createElement('details');
  4618. details.classList.add('scriptMenu_Details');
  4619. this.mainMenu.appendChild(details);
  4620.  
  4621. const summary = document.createElement('summary');
  4622. summary.classList.add('scriptMenu_Summary');
  4623. summary.innerText = summaryText;
  4624. if (name) {
  4625. const self = this;
  4626. details.open = this.option.showDetails[name];
  4627. details.dataset.name = name;
  4628. summary.addEventListener('click', () => {
  4629. self.option.showDetails[details.dataset.name] = !details.open;
  4630. self.saveShowDetails(self.option.showDetails);
  4631. });
  4632. }
  4633. details.appendChild(summary);
  4634.  
  4635. return details;
  4636. }
  4637.  
  4638. /**
  4639. * Saving the expanded state of the details blocks
  4640. *
  4641. * Сохранение состояния развенутости блоков details
  4642. * @param {*} value
  4643. */
  4644. this.saveShowDetails = (value) => {
  4645. localStorage.setItem('scriptMenu_showDetails', JSON.stringify(value));
  4646. }
  4647.  
  4648. /**
  4649. * Loading the state of expanded blocks details
  4650. *
  4651. * Загрузка состояния развенутости блоков details
  4652. * @returns
  4653. */
  4654. this.loadShowDetails = () => {
  4655. let showDetails = localStorage.getItem('scriptMenu_showDetails');
  4656.  
  4657. if (!showDetails) {
  4658. return {};
  4659. }
  4660.  
  4661. try {
  4662. showDetails = JSON.parse(showDetails);
  4663. } catch (e) {
  4664. return {};
  4665. }
  4666.  
  4667. return showDetails;
  4668. }
  4669. });
  4670.  
  4671. /**
  4672. * Пример использования
  4673. scriptMenu.init();
  4674. scriptMenu.addHeader('v1.508');
  4675. scriptMenu.addCheckbox('testHack', 'Тестовый взлом игры!');
  4676. scriptMenu.addButton('Запуск!', () => console.log('click'), 'подсказака');
  4677. scriptMenu.addInputText('input подсказака');
  4678. */
  4679. /**
  4680. * Game Library
  4681. *
  4682. * Игровая библиотека
  4683. */
  4684. class Library {
  4685. defaultLibUrl = 'https://heroesru-a.akamaihd.net/vk/v1101/lib/lib.json';
  4686.  
  4687. constructor() {
  4688. if (!Library.instance) {
  4689. Library.instance = this;
  4690. }
  4691.  
  4692. return Library.instance;
  4693. }
  4694.  
  4695. async load() {
  4696. try {
  4697. await this.getUrlLib();
  4698. console.log(this.defaultLibUrl);
  4699. this.data = await fetch(this.defaultLibUrl).then(e => e.json())
  4700. } catch (error) {
  4701. console.error('Не удалось загрузить библиотеку', error)
  4702. }
  4703. }
  4704.  
  4705. async getUrlLib() {
  4706. try {
  4707. const db = new Database('hw_cache', 'cache');
  4708. await db.open();
  4709. const cacheLibFullUrl = await db.get('lib/lib.json.gz', false);
  4710. this.defaultLibUrl = cacheLibFullUrl.fullUrl.split('.gz').shift();
  4711. } catch(e) {}
  4712. }
  4713.  
  4714. getData(id) {
  4715. return this.data[id];
  4716. }
  4717.  
  4718. setData(data) {
  4719. this.data = data;
  4720. }
  4721. }
  4722.  
  4723. this.lib = new Library();
  4724. /**
  4725. * Database
  4726. *
  4727. * База данных
  4728. */
  4729. class Database {
  4730. constructor(dbName, storeName) {
  4731. this.dbName = dbName;
  4732. this.storeName = storeName;
  4733. this.db = null;
  4734. }
  4735.  
  4736. async open() {
  4737. return new Promise((resolve, reject) => {
  4738. const request = indexedDB.open(this.dbName);
  4739.  
  4740. request.onerror = () => {
  4741. reject(new Error(`Failed to open database ${this.dbName}`));
  4742. };
  4743.  
  4744. request.onsuccess = () => {
  4745. this.db = request.result;
  4746. resolve();
  4747. };
  4748.  
  4749. request.onupgradeneeded = (event) => {
  4750. const db = event.target.result;
  4751. if (!db.objectStoreNames.contains(this.storeName)) {
  4752. db.createObjectStore(this.storeName);
  4753. }
  4754. };
  4755. });
  4756. }
  4757.  
  4758. async set(key, value) {
  4759. return new Promise((resolve, reject) => {
  4760. const transaction = this.db.transaction([this.storeName], 'readwrite');
  4761. const store = transaction.objectStore(this.storeName);
  4762. const request = store.put(value, key);
  4763.  
  4764. request.onerror = () => {
  4765. reject(new Error(`Failed to save value with key ${key}`));
  4766. };
  4767.  
  4768. request.onsuccess = () => {
  4769. resolve();
  4770. };
  4771. });
  4772. }
  4773.  
  4774. async get(key, def) {
  4775. return new Promise((resolve, reject) => {
  4776. const transaction = this.db.transaction([this.storeName], 'readonly');
  4777. const store = transaction.objectStore(this.storeName);
  4778. const request = store.get(key);
  4779.  
  4780. request.onerror = () => {
  4781. resolve(def);
  4782. };
  4783.  
  4784. request.onsuccess = () => {
  4785. resolve(request.result);
  4786. };
  4787. });
  4788. }
  4789.  
  4790. async delete(key) {
  4791. return new Promise((resolve, reject) => {
  4792. const transaction = this.db.transaction([this.storeName], 'readwrite');
  4793. const store = transaction.objectStore(this.storeName);
  4794. const request = store.delete(key);
  4795.  
  4796. request.onerror = () => {
  4797. reject(new Error(`Failed to delete value with key ${key}`));
  4798. };
  4799.  
  4800. request.onsuccess = () => {
  4801. resolve();
  4802. };
  4803. });
  4804. }
  4805. }
  4806.  
  4807. /**
  4808. * Returns the stored value
  4809. *
  4810. * Возвращает сохраненное значение
  4811. */
  4812. function getSaveVal(saveName, def) {
  4813. const result = storage.get(saveName, def);
  4814. return result;
  4815. }
  4816. this.HWHFuncs.getSaveVal = getSaveVal;
  4817.  
  4818. /**
  4819. * Stores value
  4820. *
  4821. * Сохраняет значение
  4822. */
  4823. function setSaveVal(saveName, value) {
  4824. storage.set(saveName, value);
  4825. }
  4826. this.HWHFuncs.setSaveVal = setSaveVal;
  4827.  
  4828. /**
  4829. * Database initialization
  4830. *
  4831. * Инициализация базы данных
  4832. */
  4833. const db = new Database(GM_info.script.name, 'settings');
  4834.  
  4835. /**
  4836. * Data store
  4837. *
  4838. * Хранилище данных
  4839. */
  4840. const storage = {
  4841. userId: 0,
  4842. /**
  4843. * Default values
  4844. *
  4845. * Значения по умолчанию
  4846. */
  4847. values: [
  4848. ...Object.entries(checkboxes).map(e => ({ [e[0]]: e[1].default })),
  4849. ...Object.entries(inputs).map(e => ({ [e[0]]: e[1].default })),
  4850. ].reduce((acc, obj) => ({ ...acc, ...obj }), {}),
  4851. name: GM_info.script.name,
  4852. get: function (key, def) {
  4853. if (key in this.values) {
  4854. return this.values[key];
  4855. }
  4856. return def;
  4857. },
  4858. set: function (key, value) {
  4859. this.values[key] = value;
  4860. db.set(this.userId, this.values).catch(
  4861. e => null
  4862. );
  4863. localStorage[this.name + ':' + key] = value;
  4864. },
  4865. delete: function (key) {
  4866. delete this.values[key];
  4867. db.set(this.userId, this.values);
  4868. delete localStorage[this.name + ':' + key];
  4869. }
  4870. }
  4871.  
  4872. /**
  4873. * Returns all keys from localStorage that start with prefix (for migration)
  4874. *
  4875. * Возвращает все ключи из localStorage которые начинаются с prefix (для миграции)
  4876. */
  4877. function getAllValuesStartingWith(prefix) {
  4878. const values = [];
  4879. for (let i = 0; i < localStorage.length; i++) {
  4880. const key = localStorage.key(i);
  4881. if (key.startsWith(prefix)) {
  4882. const val = localStorage.getItem(key);
  4883. const keyValue = key.split(':')[1];
  4884. values.push({ key: keyValue, val });
  4885. }
  4886. }
  4887. return values;
  4888. }
  4889.  
  4890. /**
  4891. * Opens or migrates to a database
  4892. *
  4893. * Открывает или мигрирует в базу данных
  4894. */
  4895. async function openOrMigrateDatabase(userId) {
  4896. storage.userId = userId;
  4897. try {
  4898. await db.open();
  4899. } catch(e) {
  4900. return;
  4901. }
  4902. let settings = await db.get(userId, false);
  4903.  
  4904. if (settings) {
  4905. storage.values = settings;
  4906. return;
  4907. }
  4908.  
  4909. const values = getAllValuesStartingWith(GM_info.script.name);
  4910. for (const value of values) {
  4911. let val = null;
  4912. try {
  4913. val = JSON.parse(value.val);
  4914. } catch {
  4915. break;
  4916. }
  4917. storage.values[value.key] = val;
  4918. }
  4919. await db.set(userId, storage.values);
  4920. }
  4921.  
  4922. class ZingerYWebsiteAPI {
  4923. /**
  4924. * Class for interaction with the API of the zingery.ru website
  4925. * Intended only for use with the HeroWarsHelper script:
  4926. * https://greasyfork.org/ru/scripts/450693-herowarshelper
  4927. * Copyright ZingerY
  4928. */
  4929. url = 'https://zingery.ru/heroes/';
  4930. // YWJzb2x1dGVseSB1c2VsZXNzIGxpbmU=
  4931. constructor(urn, env, data = {}) {
  4932. this.urn = urn;
  4933. this.fd = {
  4934. now: Date.now(),
  4935. fp: this.constructor.toString().replaceAll(/\s/g, ''),
  4936. env: env.callee.toString().replaceAll(/\s/g, ''),
  4937. info: (({ name, version, author }) => [name, version, author])(GM_info.script),
  4938. ...data,
  4939. };
  4940. }
  4941.  
  4942. sign() {
  4943. return md5([...this.fd.info, ~(this.fd.now % 1e3), this.fd.fp].join('_'));
  4944. }
  4945.  
  4946. encode(data) {
  4947. return btoa(encodeURIComponent(JSON.stringify(data)));
  4948. }
  4949.  
  4950. decode(data) {
  4951. return JSON.parse(decodeURIComponent(atob(data)));
  4952. }
  4953.  
  4954. headers() {
  4955. return {
  4956. 'X-Request-Signature': this.sign(),
  4957. 'X-Script-Name': GM_info.script.name,
  4958. 'X-Script-Version': GM_info.script.version,
  4959. 'X-Script-Author': GM_info.script.author,
  4960. 'X-Script-ZingerY': 42,
  4961. };
  4962. }
  4963.  
  4964. async request() {
  4965. try {
  4966. const response = await fetch(this.url + this.urn, {
  4967. method: 'POST',
  4968. headers: this.headers(),
  4969. body: this.encode(this.fd),
  4970. });
  4971. const text = await response.text();
  4972. return this.decode(text);
  4973. } catch (e) {
  4974. console.error(e);
  4975. return [];
  4976. }
  4977. }
  4978. /**
  4979. * Класс для взаимодействия с API сайта zingery.ru
  4980. * Предназначен только для использования со скриптом HeroWarsHelper:
  4981. * https://greasyfork.org/ru/scripts/450693-herowarshelper
  4982. * Copyright ZingerY
  4983. */
  4984. }
  4985.  
  4986. /**
  4987. * Sending expeditions
  4988. *
  4989. * Отправка экспедиций
  4990. */
  4991. function checkExpedition() {
  4992. const { Expedition } = HWHClasses;
  4993. return new Promise((resolve, reject) => {
  4994. const expedition = new Expedition(resolve, reject);
  4995. expedition.start();
  4996. });
  4997. }
  4998.  
  4999. class Expedition {
  5000. checkExpedInfo = {
  5001. calls: [
  5002. {
  5003. name: 'expeditionGet',
  5004. args: {},
  5005. ident: 'expeditionGet',
  5006. },
  5007. {
  5008. name: 'heroGetAll',
  5009. args: {},
  5010. ident: 'heroGetAll',
  5011. },
  5012. ],
  5013. };
  5014.  
  5015. constructor(resolve, reject) {
  5016. this.resolve = resolve;
  5017. this.reject = reject;
  5018. }
  5019.  
  5020. async start() {
  5021. const data = await Send(JSON.stringify(this.checkExpedInfo));
  5022.  
  5023. const expedInfo = data.results[0].result.response;
  5024. const dataHeroes = data.results[1].result.response;
  5025. const dataExped = { useHeroes: [], exped: [] };
  5026. const calls = [];
  5027.  
  5028. /**
  5029. * Adding expeditions to collect
  5030. * Добавляем экспедиции для сбора
  5031. */
  5032. let countGet = 0;
  5033. for (var n in expedInfo) {
  5034. const exped = expedInfo[n];
  5035. const dateNow = Date.now() / 1000;
  5036. if (exped.status == 2 && exped.endTime != 0 && dateNow > exped.endTime) {
  5037. countGet++;
  5038. calls.push({
  5039. name: 'expeditionFarm',
  5040. args: { expeditionId: exped.id },
  5041. ident: 'expeditionFarm_' + exped.id,
  5042. });
  5043. } else {
  5044. dataExped.useHeroes = dataExped.useHeroes.concat(exped.heroes);
  5045. }
  5046. if (exped.status == 1) {
  5047. dataExped.exped.push({ id: exped.id, power: exped.power });
  5048. }
  5049. }
  5050. dataExped.exped = dataExped.exped.sort((a, b) => b.power - a.power);
  5051.  
  5052. /**
  5053. * Putting together a list of heroes
  5054. * Собираем список героев
  5055. */
  5056. const heroesArr = [];
  5057. for (let n in dataHeroes) {
  5058. const hero = dataHeroes[n];
  5059. if (hero.xp > 0 && !dataExped.useHeroes.includes(hero.id)) {
  5060. let heroPower = hero.power;
  5061. // Лара Крофт * 3
  5062. if (hero.id == 63 && hero.color >= 16) {
  5063. heroPower *= 3;
  5064. }
  5065. heroesArr.push({ id: hero.id, power: heroPower });
  5066. }
  5067. }
  5068.  
  5069. /**
  5070. * Adding expeditions to send
  5071. * Добавляем экспедиции для отправки
  5072. */
  5073. let countSend = 0;
  5074. heroesArr.sort((a, b) => a.power - b.power);
  5075. for (const exped of dataExped.exped) {
  5076. let heroesIds = this.selectionHeroes(heroesArr, exped.power);
  5077. if (heroesIds && heroesIds.length > 4) {
  5078. for (let q in heroesArr) {
  5079. if (heroesIds.includes(heroesArr[q].id)) {
  5080. delete heroesArr[q];
  5081. }
  5082. }
  5083. countSend++;
  5084. calls.push({
  5085. name: 'expeditionSendHeroes',
  5086. args: {
  5087. expeditionId: exped.id,
  5088. heroes: heroesIds,
  5089. },
  5090. ident: 'expeditionSendHeroes_' + exped.id,
  5091. });
  5092. }
  5093. }
  5094.  
  5095. if (calls.length) {
  5096. await Send({ calls });
  5097. this.end(I18N('EXPEDITIONS_SENT', {countGet, countSend}));
  5098. return;
  5099. }
  5100.  
  5101. this.end(I18N('EXPEDITIONS_NOTHING'));
  5102. }
  5103.  
  5104. /**
  5105. * Selection of heroes for expeditions
  5106. *
  5107. * Подбор героев для экспедиций
  5108. */
  5109. selectionHeroes(heroes, power) {
  5110. const resultHeroers = [];
  5111. const heroesIds = [];
  5112. for (let q = 0; q < 5; q++) {
  5113. for (let i in heroes) {
  5114. let hero = heroes[i];
  5115. if (heroesIds.includes(hero.id)) {
  5116. continue;
  5117. }
  5118.  
  5119. const summ = resultHeroers.reduce((acc, hero) => acc + hero.power, 0);
  5120. const need = Math.round((power - summ) / (5 - resultHeroers.length));
  5121. if (hero.power > need) {
  5122. resultHeroers.push(hero);
  5123. heroesIds.push(hero.id);
  5124. break;
  5125. }
  5126. }
  5127. }
  5128.  
  5129. const summ = resultHeroers.reduce((acc, hero) => acc + hero.power, 0);
  5130. if (summ < power) {
  5131. return false;
  5132. }
  5133. return heroesIds;
  5134. }
  5135.  
  5136. /**
  5137. * Ends expedition script
  5138. *
  5139. * Завершает скрипт экспедиции
  5140. */
  5141. end(msg) {
  5142. setProgress(msg, true);
  5143. this.resolve();
  5144. }
  5145. }
  5146.  
  5147. this.HWHClasses.Expedition = Expedition;
  5148.  
  5149. /**
  5150. * Walkthrough of the dungeon
  5151. *
  5152. * Прохождение подземелья
  5153. */
  5154. function testDungeon() {
  5155. const { executeDungeon } = HWHClasses;
  5156. return new Promise((resolve, reject) => {
  5157. const dung = new executeDungeon(resolve, reject);
  5158. const titanit = getInput('countTitanit');
  5159. dung.start(titanit);
  5160. });
  5161. }
  5162.  
  5163. /**
  5164. * Walkthrough of the dungeon
  5165. *
  5166. * Прохождение подземелья
  5167. */
  5168. function executeDungeon(resolve, reject) {
  5169. dungeonActivity = 0;
  5170. maxDungeonActivity = 175;
  5171.  
  5172. titanGetAll = [];
  5173.  
  5174. teams = {
  5175. heroes: [],
  5176. earth: [],
  5177. fire: [],
  5178. neutral: [],
  5179. water: [],
  5180. }
  5181.  
  5182. titanStats = [];
  5183.  
  5184. titansStates = {};
  5185.  
  5186. let talentMsg = '';
  5187. let talentMsgReward = '';
  5188.  
  5189. callsExecuteDungeon = {
  5190. calls: [{
  5191. name: "dungeonGetInfo",
  5192. args: {},
  5193. ident: "dungeonGetInfo"
  5194. }, {
  5195. name: "teamGetAll",
  5196. args: {},
  5197. ident: "teamGetAll"
  5198. }, {
  5199. name: "teamGetFavor",
  5200. args: {},
  5201. ident: "teamGetFavor"
  5202. }, {
  5203. name: "clanGetInfo",
  5204. args: {},
  5205. ident: "clanGetInfo"
  5206. }, {
  5207. name: "titanGetAll",
  5208. args: {},
  5209. ident: "titanGetAll"
  5210. }, {
  5211. name: "inventoryGet",
  5212. args: {},
  5213. ident: "inventoryGet"
  5214. }]
  5215. }
  5216.  
  5217. this.start = function(titanit) {
  5218. maxDungeonActivity = titanit || getInput('countTitanit');
  5219. send(JSON.stringify(callsExecuteDungeon), startDungeon);
  5220. }
  5221.  
  5222. /**
  5223. * Getting data on the dungeon
  5224. *
  5225. * Получаем данные по подземелью
  5226. */
  5227. function startDungeon(e) {
  5228. res = e.results;
  5229. dungeonGetInfo = res[0].result.response;
  5230. if (!dungeonGetInfo) {
  5231. endDungeon('noDungeon', res);
  5232. return;
  5233. }
  5234. teamGetAll = res[1].result.response;
  5235. teamGetFavor = res[2].result.response;
  5236. dungeonActivity = res[3].result.response.stat.todayDungeonActivity;
  5237. titanGetAll = Object.values(res[4].result.response);
  5238. countPredictionCard = res[5].result.response.consumable[81];
  5239.  
  5240. teams.hero = {
  5241. favor: teamGetFavor.dungeon_hero,
  5242. heroes: teamGetAll.dungeon_hero.filter(id => id < 6000),
  5243. teamNum: 0,
  5244. }
  5245. heroPet = teamGetAll.dungeon_hero.filter(id => id >= 6000).pop();
  5246. if (heroPet) {
  5247. teams.hero.pet = heroPet;
  5248. }
  5249.  
  5250. teams.neutral = {
  5251. favor: {},
  5252. heroes: getTitanTeam(titanGetAll, 'neutral'),
  5253. teamNum: 0,
  5254. };
  5255. teams.water = {
  5256. favor: {},
  5257. heroes: getTitanTeam(titanGetAll, 'water'),
  5258. teamNum: 0,
  5259. };
  5260. teams.fire = {
  5261. favor: {},
  5262. heroes: getTitanTeam(titanGetAll, 'fire'),
  5263. teamNum: 0,
  5264. };
  5265. teams.earth = {
  5266. favor: {},
  5267. heroes: getTitanTeam(titanGetAll, 'earth'),
  5268. teamNum: 0,
  5269. };
  5270.  
  5271.  
  5272. checkFloor(dungeonGetInfo);
  5273. }
  5274.  
  5275. function getTitanTeam(titans, type) {
  5276. switch (type) {
  5277. case 'neutral':
  5278. return titans.sort((a, b) => b.power - a.power).slice(0, 5).map(e => e.id);
  5279. case 'water':
  5280. return titans.filter(e => e.id.toString().slice(2, 3) == '0').map(e => e.id);
  5281. case 'fire':
  5282. return titans.filter(e => e.id.toString().slice(2, 3) == '1').map(e => e.id);
  5283. case 'earth':
  5284. return titans.filter(e => e.id.toString().slice(2, 3) == '2').map(e => e.id);
  5285. }
  5286. }
  5287.  
  5288. function getNeutralTeam() {
  5289. const titans = titanGetAll.filter(e => !titansStates[e.id]?.isDead)
  5290. return titans.sort((a, b) => b.power - a.power).slice(0, 5).map(e => e.id);
  5291. }
  5292.  
  5293. function fixTitanTeam(titans) {
  5294. titans.heroes = titans.heroes.filter(e => !titansStates[e]?.isDead);
  5295. return titans;
  5296. }
  5297.  
  5298. /**
  5299. * Checking the floor
  5300. *
  5301. * Проверяем этаж
  5302. */
  5303. async function checkFloor(dungeonInfo) {
  5304. if (!('floor' in dungeonInfo) || dungeonInfo.floor?.state == 2) {
  5305. saveProgress();
  5306. return;
  5307. }
  5308. checkTalent(dungeonInfo);
  5309. // console.log(dungeonInfo, dungeonActivity);
  5310. setProgress(`${I18N('DUNGEON')}: ${I18N('TITANIT')} ${dungeonActivity}/${maxDungeonActivity} ${talentMsg}`);
  5311. if (dungeonActivity >= maxDungeonActivity) {
  5312. endDungeon('endDungeon', 'maxActive ' + dungeonActivity + '/' + maxDungeonActivity);
  5313. return;
  5314. }
  5315. titansStates = dungeonInfo.states.titans;
  5316. titanStats = titanObjToArray(titansStates);
  5317. const floorChoices = dungeonInfo.floor.userData;
  5318. const floorType = dungeonInfo.floorType;
  5319. //const primeElement = dungeonInfo.elements.prime;
  5320. if (floorType == "battle") {
  5321. const calls = [];
  5322. for (let teamNum in floorChoices) {
  5323. attackerType = floorChoices[teamNum].attackerType;
  5324. const args = fixTitanTeam(teams[attackerType]);
  5325. if (attackerType == 'neutral') {
  5326. args.heroes = getNeutralTeam();
  5327. }
  5328. if (!args.heroes.length) {
  5329. continue;
  5330. }
  5331. args.teamNum = teamNum;
  5332. calls.push({
  5333. name: "dungeonStartBattle",
  5334. args,
  5335. ident: "body_" + teamNum
  5336. })
  5337. }
  5338. if (!calls.length) {
  5339. endDungeon('endDungeon', 'All Dead');
  5340. return;
  5341. }
  5342. const battleDatas = await Send(JSON.stringify({ calls }))
  5343. .then(e => e.results.map(n => n.result.response))
  5344. const battleResults = [];
  5345. for (n in battleDatas) {
  5346. battleData = battleDatas[n]
  5347. battleData.progress = [{ attackers: { input: ["auto", 0, 0, "auto", 0, 0] } }];
  5348. battleResults.push(await Calc(battleData).then(result => {
  5349. result.teamNum = n;
  5350. result.attackerType = floorChoices[n].attackerType;
  5351. return result;
  5352. }));
  5353. }
  5354. processingPromises(battleResults)
  5355. }
  5356. }
  5357.  
  5358. async function checkTalent(dungeonInfo) {
  5359. const talent = dungeonInfo.talent;
  5360. if (!talent) {
  5361. return;
  5362. }
  5363. const dungeonFloor = +dungeonInfo.floorNumber;
  5364. const talentFloor = +talent.floorRandValue;
  5365. let doorsAmount = 3 - talent.conditions.doorsAmount;
  5366.  
  5367. if (dungeonFloor === talentFloor && (!doorsAmount || !talent.conditions?.farmedDoors[dungeonFloor])) {
  5368. const reward = await Send({
  5369. calls: [
  5370. { name: 'heroTalent_getReward', args: { talentType: 'tmntDungeonTalent', reroll: false }, ident: 'group_0_body' },
  5371. { name: 'heroTalent_farmReward', args: { talentType: 'tmntDungeonTalent' }, ident: 'group_1_body' },
  5372. ],
  5373. }).then((e) => e.results[0].result.response);
  5374. const type = Object.keys(reward).pop();
  5375. const itemId = Object.keys(reward[type]).pop();
  5376. const count = reward[type][itemId];
  5377. const itemName = cheats.translate(`LIB_${type.toUpperCase()}_NAME_${itemId}`);
  5378. talentMsgReward += `<br> ${count} ${itemName}`;
  5379. doorsAmount++;
  5380. }
  5381. talentMsg = `<br>TMNT Talent: ${doorsAmount}/3 ${talentMsgReward}<br>`;
  5382. }
  5383.  
  5384. function processingPromises(results) {
  5385. let selectBattle = results[0];
  5386. if (results.length < 2) {
  5387. // console.log(selectBattle);
  5388. if (!selectBattle.result.win) {
  5389. endDungeon('dungeonEndBattle\n', selectBattle);
  5390. return;
  5391. }
  5392. endBattle(selectBattle);
  5393. return;
  5394. }
  5395.  
  5396. selectBattle = false;
  5397. let bestState = -1000;
  5398. for (const result of results) {
  5399. const recovery = getState(result);
  5400. if (recovery > bestState) {
  5401. bestState = recovery;
  5402. selectBattle = result
  5403. }
  5404. }
  5405. // console.log(selectBattle.teamNum, results);
  5406. if (!selectBattle || bestState <= -1000) {
  5407. endDungeon('dungeonEndBattle\n', results);
  5408. return;
  5409. }
  5410.  
  5411. startBattle(selectBattle.teamNum, selectBattle.attackerType)
  5412. .then(endBattle);
  5413. }
  5414.  
  5415. /**
  5416. * Let's start the fight
  5417. *
  5418. * Начинаем бой
  5419. */
  5420. function startBattle(teamNum, attackerType) {
  5421. return new Promise(function (resolve, reject) {
  5422. args = fixTitanTeam(teams[attackerType]);
  5423. args.teamNum = teamNum;
  5424. if (attackerType == 'neutral') {
  5425. const titans = titanGetAll.filter(e => !titansStates[e.id]?.isDead)
  5426. args.heroes = titans.sort((a, b) => b.power - a.power).slice(0, 5).map(e => e.id);
  5427. }
  5428. startBattleCall = {
  5429. calls: [{
  5430. name: "dungeonStartBattle",
  5431. args,
  5432. ident: "body"
  5433. }]
  5434. }
  5435. send(JSON.stringify(startBattleCall), resultBattle, {
  5436. resolve,
  5437. teamNum,
  5438. attackerType
  5439. });
  5440. });
  5441. }
  5442. /**
  5443. * Returns the result of the battle in a promise
  5444. *
  5445. * Возращает резульат боя в промис
  5446. */
  5447. function resultBattle(resultBattles, args) {
  5448. battleData = resultBattles.results[0].result.response;
  5449. battleType = "get_tower";
  5450. if (battleData.type == "dungeon_titan") {
  5451. battleType = "get_titan";
  5452. }
  5453. battleData.progress = [{ attackers: { input: ["auto", 0, 0, "auto", 0, 0] } }];
  5454. BattleCalc(battleData, battleType, function (result) {
  5455. result.teamNum = args.teamNum;
  5456. result.attackerType = args.attackerType;
  5457. args.resolve(result);
  5458. });
  5459. }
  5460. /**
  5461. * Finishing the fight
  5462. *
  5463. * Заканчиваем бой
  5464. */
  5465. async function endBattle(battleInfo) {
  5466. if (battleInfo.result.win) {
  5467. const args = {
  5468. result: battleInfo.result,
  5469. progress: battleInfo.progress,
  5470. }
  5471. if (countPredictionCard > 0) {
  5472. args.isRaid = true;
  5473. } else {
  5474. const timer = getTimer(battleInfo.battleTime);
  5475. console.log(timer);
  5476. await countdownTimer(timer, `${I18N('DUNGEON')}: ${I18N('TITANIT')} ${dungeonActivity}/${maxDungeonActivity} ${talentMsg}`);
  5477. }
  5478. const calls = [{
  5479. name: "dungeonEndBattle",
  5480. args,
  5481. ident: "body"
  5482. }];
  5483. lastDungeonBattleData = null;
  5484. send(JSON.stringify({ calls }), resultEndBattle);
  5485. } else {
  5486. endDungeon('dungeonEndBattle win: false\n', battleInfo);
  5487. }
  5488. }
  5489.  
  5490. /**
  5491. * Getting and processing battle results
  5492. *
  5493. * Получаем и обрабатываем результаты боя
  5494. */
  5495. function resultEndBattle(e) {
  5496. if ('error' in e) {
  5497. popup.confirm(I18N('ERROR_MSG', {
  5498. name: e.error.name,
  5499. description: e.error.description,
  5500. }));
  5501. endDungeon('errorRequest', e);
  5502. return;
  5503. }
  5504. battleResult = e.results[0].result.response;
  5505. if ('error' in battleResult) {
  5506. endDungeon('errorBattleResult', battleResult);
  5507. return;
  5508. }
  5509. dungeonGetInfo = battleResult.dungeon ?? battleResult;
  5510. dungeonActivity += battleResult.reward.dungeonActivity ?? 0;
  5511. checkFloor(dungeonGetInfo);
  5512. }
  5513.  
  5514. /**
  5515. * Returns the coefficient of condition of the
  5516. * difference in titanium before and after the battle
  5517. *
  5518. * Возвращает коэффициент состояния титанов после боя
  5519. */
  5520. function getState(result) {
  5521. if (!result.result.win) {
  5522. return -1000;
  5523. }
  5524.  
  5525. let beforeSumFactor = 0;
  5526. const beforeTitans = result.battleData.attackers;
  5527. for (let titanId in beforeTitans) {
  5528. const titan = beforeTitans[titanId];
  5529. const state = titan.state;
  5530. let factor = 1;
  5531. if (state) {
  5532. const hp = state.hp / titan.hp;
  5533. const energy = state.energy / 1e3;
  5534. factor = hp + energy / 20
  5535. }
  5536. beforeSumFactor += factor;
  5537. }
  5538.  
  5539. let afterSumFactor = 0;
  5540. const afterTitans = result.progress[0].attackers.heroes;
  5541. for (let titanId in afterTitans) {
  5542. const titan = afterTitans[titanId];
  5543. const hp = titan.hp / beforeTitans[titanId].hp;
  5544. const energy = titan.energy / 1e3;
  5545. const factor = hp + energy / 20;
  5546. afterSumFactor += factor;
  5547. }
  5548. return afterSumFactor - beforeSumFactor;
  5549. }
  5550.  
  5551. /**
  5552. * Converts an object with IDs to an array with IDs
  5553. *
  5554. * Преобразует объект с идетификаторами в массив с идетификаторами
  5555. */
  5556. function titanObjToArray(obj) {
  5557. let titans = [];
  5558. for (let id in obj) {
  5559. obj[id].id = id;
  5560. titans.push(obj[id]);
  5561. }
  5562. return titans;
  5563. }
  5564.  
  5565. function saveProgress() {
  5566. let saveProgressCall = {
  5567. calls: [{
  5568. name: "dungeonSaveProgress",
  5569. args: {},
  5570. ident: "body"
  5571. }]
  5572. }
  5573. send(JSON.stringify(saveProgressCall), resultEndBattle);
  5574. }
  5575.  
  5576. function endDungeon(reason, info) {
  5577. console.warn(reason, info);
  5578. setProgress(`${I18N('DUNGEON')} ${I18N('COMPLETED')}`, true);
  5579. resolve();
  5580. }
  5581. }
  5582.  
  5583. this.HWHClasses.executeDungeon = executeDungeon;
  5584.  
  5585. /**
  5586. * Passing the tower
  5587. *
  5588. * Прохождение башни
  5589. */
  5590. function testTower() {
  5591. const { executeTower } = HWHClasses;
  5592. return new Promise((resolve, reject) => {
  5593. tower = new executeTower(resolve, reject);
  5594. tower.start();
  5595. });
  5596. }
  5597.  
  5598. /**
  5599. * Passing the tower
  5600. *
  5601. * Прохождение башни
  5602. */
  5603. function executeTower(resolve, reject) {
  5604. lastTowerInfo = {};
  5605.  
  5606. scullCoin = 0;
  5607.  
  5608. heroGetAll = [];
  5609.  
  5610. heroesStates = {};
  5611.  
  5612. argsBattle = {
  5613. heroes: [],
  5614. favor: {},
  5615. };
  5616.  
  5617. callsExecuteTower = {
  5618. calls: [{
  5619. name: "towerGetInfo",
  5620. args: {},
  5621. ident: "towerGetInfo"
  5622. }, {
  5623. name: "teamGetAll",
  5624. args: {},
  5625. ident: "teamGetAll"
  5626. }, {
  5627. name: "teamGetFavor",
  5628. args: {},
  5629. ident: "teamGetFavor"
  5630. }, {
  5631. name: "inventoryGet",
  5632. args: {},
  5633. ident: "inventoryGet"
  5634. }, {
  5635. name: "heroGetAll",
  5636. args: {},
  5637. ident: "heroGetAll"
  5638. }]
  5639. }
  5640.  
  5641. buffIds = [
  5642. {id: 0, cost: 0, isBuy: false}, // plug // заглушка
  5643. {id: 1, cost: 1, isBuy: true}, // 3% attack // 3% атака
  5644. {id: 2, cost: 6, isBuy: true}, // 2% attack // 2% атака
  5645. {id: 3, cost: 16, isBuy: true}, // 4% attack // 4% атака
  5646. {id: 4, cost: 40, isBuy: true}, // 8% attack // 8% атака
  5647. {id: 5, cost: 1, isBuy: true}, // 10% armor // 10% броня
  5648. {id: 6, cost: 6, isBuy: true}, // 5% armor // 5% броня
  5649. {id: 7, cost: 16, isBuy: true}, // 10% armor // 10% броня
  5650. {id: 8, cost: 40, isBuy: true}, // 20% armor // 20% броня
  5651. { id: 9, cost: 1, isBuy: true }, // 10% protection from magic // 10% защита от магии
  5652. { id: 10, cost: 6, isBuy: true }, // 5% protection from magic // 5% защита от магии
  5653. { id: 11, cost: 16, isBuy: true }, // 10% protection from magic // 10% защита от магии
  5654. { id: 12, cost: 40, isBuy: true }, // 20% protection from magic // 20% защита от магии
  5655. { id: 13, cost: 1, isBuy: false }, // 40% health hero // 40% здоровья герою
  5656. { id: 14, cost: 6, isBuy: false }, // 40% health hero // 40% здоровья герою
  5657. { id: 15, cost: 16, isBuy: false }, // 80% health hero // 80% здоровья герою
  5658. { id: 16, cost: 40, isBuy: false }, // 40% health to all heroes // 40% здоровья всем героям
  5659. { id: 17, cost: 1, isBuy: false }, // 40% energy to the hero // 40% энергии герою
  5660. { id: 18, cost: 3, isBuy: false }, // 40% energy to the hero // 40% энергии герою
  5661. { id: 19, cost: 8, isBuy: false }, // 80% energy to the hero // 80% энергии герою
  5662. { id: 20, cost: 20, isBuy: false }, // 40% energy to all heroes // 40% энергии всем героям
  5663. { id: 21, cost: 40, isBuy: false }, // Hero Resurrection // Воскрешение героя
  5664. ]
  5665.  
  5666. this.start = function () {
  5667. send(JSON.stringify(callsExecuteTower), startTower);
  5668. }
  5669.  
  5670. /**
  5671. * Getting data on the Tower
  5672. *
  5673. * Получаем данные по башне
  5674. */
  5675. function startTower(e) {
  5676. res = e.results;
  5677. towerGetInfo = res[0].result.response;
  5678. if (!towerGetInfo) {
  5679. endTower('noTower', res);
  5680. return;
  5681. }
  5682. teamGetAll = res[1].result.response;
  5683. teamGetFavor = res[2].result.response;
  5684. inventoryGet = res[3].result.response;
  5685. heroGetAll = Object.values(res[4].result.response);
  5686.  
  5687. scullCoin = inventoryGet.coin[7] ?? 0;
  5688.  
  5689. argsBattle.favor = teamGetFavor.tower;
  5690. argsBattle.heroes = heroGetAll.sort((a, b) => b.power - a.power).slice(0, 5).map(e => e.id);
  5691. pet = teamGetAll.tower.filter(id => id >= 6000).pop();
  5692. if (pet) {
  5693. argsBattle.pet = pet;
  5694. }
  5695.  
  5696. checkFloor(towerGetInfo);
  5697. }
  5698.  
  5699. function fixHeroesTeam(argsBattle) {
  5700. let fixHeroes = argsBattle.heroes.filter(e => !heroesStates[e]?.isDead);
  5701. if (fixHeroes.length < 5) {
  5702. heroGetAll = heroGetAll.filter(e => !heroesStates[e.id]?.isDead);
  5703. fixHeroes = heroGetAll.sort((a, b) => b.power - a.power).slice(0, 5).map(e => e.id);
  5704. Object.keys(argsBattle.favor).forEach(e => {
  5705. if (!fixHeroes.includes(+e)) {
  5706. delete argsBattle.favor[e];
  5707. }
  5708. })
  5709. }
  5710. argsBattle.heroes = fixHeroes;
  5711. return argsBattle;
  5712. }
  5713.  
  5714. /**
  5715. * Check the floor
  5716. *
  5717. * Проверяем этаж
  5718. */
  5719. function checkFloor(towerInfo) {
  5720. lastTowerInfo = towerInfo;
  5721. maySkipFloor = +towerInfo.maySkipFloor;
  5722. floorNumber = +towerInfo.floorNumber;
  5723. heroesStates = towerInfo.states.heroes;
  5724. floorInfo = towerInfo.floor;
  5725.  
  5726. /**
  5727. * Is there at least one chest open on the floor
  5728. * Открыт ли на этаже хоть один сундук
  5729. */
  5730. isOpenChest = false;
  5731. if (towerInfo.floorType == "chest") {
  5732. isOpenChest = towerInfo.floor.chests.reduce((n, e) => n + e.opened, 0);
  5733. }
  5734.  
  5735. setProgress(`${I18N('TOWER')}: ${I18N('FLOOR')} ${floorNumber}`);
  5736. if (floorNumber > 49) {
  5737. if (isOpenChest) {
  5738. endTower('alreadyOpenChest 50 floor', floorNumber);
  5739. return;
  5740. }
  5741. }
  5742. /**
  5743. * If the chest is open and you can skip floors, then move on
  5744. * Если сундук открыт и можно скипать этажи, то переходим дальше
  5745. */
  5746. if (towerInfo.mayFullSkip && +towerInfo.teamLevel == 130) {
  5747. if (floorNumber == 1) {
  5748. fullSkipTower();
  5749. return;
  5750. }
  5751. if (isOpenChest) {
  5752. nextOpenChest(floorNumber);
  5753. } else {
  5754. nextChestOpen(floorNumber);
  5755. }
  5756. return;
  5757. }
  5758.  
  5759. // console.log(towerInfo, scullCoin);
  5760. switch (towerInfo.floorType) {
  5761. case "battle":
  5762. if (floorNumber <= maySkipFloor) {
  5763. skipFloor();
  5764. return;
  5765. }
  5766. if (floorInfo.state == 2) {
  5767. nextFloor();
  5768. return;
  5769. }
  5770. startBattle().then(endBattle);
  5771. return;
  5772. case "buff":
  5773. checkBuff(towerInfo);
  5774. return;
  5775. case "chest":
  5776. openChest(floorNumber);
  5777. return;
  5778. default:
  5779. console.log('!', towerInfo.floorType, towerInfo);
  5780. break;
  5781. }
  5782. }
  5783.  
  5784. /**
  5785. * Let's start the fight
  5786. *
  5787. * Начинаем бой
  5788. */
  5789. function startBattle() {
  5790. return new Promise(function (resolve, reject) {
  5791. towerStartBattle = {
  5792. calls: [{
  5793. name: "towerStartBattle",
  5794. args: fixHeroesTeam(argsBattle),
  5795. ident: "body"
  5796. }]
  5797. }
  5798. send(JSON.stringify(towerStartBattle), resultBattle, resolve);
  5799. });
  5800. }
  5801. /**
  5802. * Returns the result of the battle in a promise
  5803. *
  5804. * Возращает резульат боя в промис
  5805. */
  5806. function resultBattle(resultBattles, resolve) {
  5807. battleData = resultBattles.results[0].result.response;
  5808. battleType = "get_tower";
  5809. BattleCalc(battleData, battleType, function (result) {
  5810. resolve(result);
  5811. });
  5812. }
  5813. /**
  5814. * Finishing the fight
  5815. *
  5816. * Заканчиваем бой
  5817. */
  5818. function endBattle(battleInfo) {
  5819. if (battleInfo.result.stars >= 3) {
  5820. endBattleCall = {
  5821. calls: [{
  5822. name: "towerEndBattle",
  5823. args: {
  5824. result: battleInfo.result,
  5825. progress: battleInfo.progress,
  5826. },
  5827. ident: "body"
  5828. }]
  5829. }
  5830. send(JSON.stringify(endBattleCall), resultEndBattle);
  5831. } else {
  5832. endTower('towerEndBattle win: false\n', battleInfo);
  5833. }
  5834. }
  5835.  
  5836. /**
  5837. * Getting and processing battle results
  5838. *
  5839. * Получаем и обрабатываем результаты боя
  5840. */
  5841. function resultEndBattle(e) {
  5842. battleResult = e.results[0].result.response;
  5843. if ('error' in battleResult) {
  5844. endTower('errorBattleResult', battleResult);
  5845. return;
  5846. }
  5847. if ('reward' in battleResult) {
  5848. scullCoin += battleResult.reward?.coin[7] ?? 0;
  5849. }
  5850. nextFloor();
  5851. }
  5852.  
  5853. function nextFloor() {
  5854. nextFloorCall = {
  5855. calls: [{
  5856. name: "towerNextFloor",
  5857. args: {},
  5858. ident: "body"
  5859. }]
  5860. }
  5861. send(JSON.stringify(nextFloorCall), checkDataFloor);
  5862. }
  5863.  
  5864. function openChest(floorNumber) {
  5865. floorNumber = floorNumber || 0;
  5866. openChestCall = {
  5867. calls: [{
  5868. name: "towerOpenChest",
  5869. args: {
  5870. num: 2
  5871. },
  5872. ident: "body"
  5873. }]
  5874. }
  5875. send(JSON.stringify(openChestCall), floorNumber < 50 ? nextFloor : lastChest);
  5876. }
  5877.  
  5878. function lastChest() {
  5879. endTower('openChest 50 floor', floorNumber);
  5880. }
  5881.  
  5882. function skipFloor() {
  5883. skipFloorCall = {
  5884. calls: [{
  5885. name: "towerSkipFloor",
  5886. args: {},
  5887. ident: "body"
  5888. }]
  5889. }
  5890. send(JSON.stringify(skipFloorCall), checkDataFloor);
  5891. }
  5892.  
  5893. function checkBuff(towerInfo) {
  5894. buffArr = towerInfo.floor;
  5895. promises = [];
  5896. for (let buff of buffArr) {
  5897. buffInfo = buffIds[buff.id];
  5898. if (buffInfo.isBuy && buffInfo.cost <= scullCoin) {
  5899. scullCoin -= buffInfo.cost;
  5900. promises.push(buyBuff(buff.id));
  5901. }
  5902. }
  5903. Promise.all(promises).then(nextFloor);
  5904. }
  5905.  
  5906. function buyBuff(buffId) {
  5907. return new Promise(function (resolve, reject) {
  5908. buyBuffCall = {
  5909. calls: [{
  5910. name: "towerBuyBuff",
  5911. args: {
  5912. buffId
  5913. },
  5914. ident: "body"
  5915. }]
  5916. }
  5917. send(JSON.stringify(buyBuffCall), resolve);
  5918. });
  5919. }
  5920.  
  5921. function checkDataFloor(result) {
  5922. towerInfo = result.results[0].result.response;
  5923. if ('reward' in towerInfo && towerInfo.reward?.coin) {
  5924. scullCoin += towerInfo.reward?.coin[7] ?? 0;
  5925. }
  5926. if ('tower' in towerInfo) {
  5927. towerInfo = towerInfo.tower;
  5928. }
  5929. if ('skullReward' in towerInfo) {
  5930. scullCoin += towerInfo.skullReward?.coin[7] ?? 0;
  5931. }
  5932. checkFloor(towerInfo);
  5933. }
  5934. /**
  5935. * Getting tower rewards
  5936. *
  5937. * Получаем награды башни
  5938. */
  5939. function farmTowerRewards(reason) {
  5940. let { pointRewards, points } = lastTowerInfo;
  5941. let pointsAll = Object.getOwnPropertyNames(pointRewards);
  5942. let farmPoints = pointsAll.filter(e => +e <= +points && !pointRewards[e]);
  5943. if (!farmPoints.length) {
  5944. return;
  5945. }
  5946. let farmTowerRewardsCall = {
  5947. calls: [{
  5948. name: "tower_farmPointRewards",
  5949. args: {
  5950. points: farmPoints
  5951. },
  5952. ident: "tower_farmPointRewards"
  5953. }]
  5954. }
  5955.  
  5956. if (scullCoin > 0) {
  5957. farmTowerRewardsCall.calls.push({
  5958. name: "tower_farmSkullReward",
  5959. args: {},
  5960. ident: "tower_farmSkullReward"
  5961. });
  5962. }
  5963.  
  5964. send(JSON.stringify(farmTowerRewardsCall), () => { });
  5965. }
  5966.  
  5967. function fullSkipTower() {
  5968. /**
  5969. * Next chest
  5970. *
  5971. * Следующий сундук
  5972. */
  5973. function nextChest(n) {
  5974. return {
  5975. name: "towerNextChest",
  5976. args: {},
  5977. ident: "group_" + n + "_body"
  5978. }
  5979. }
  5980. /**
  5981. * Open chest
  5982. *
  5983. * Открыть сундук
  5984. */
  5985. function openChest(n) {
  5986. return {
  5987. name: "towerOpenChest",
  5988. args: {
  5989. "num": 2
  5990. },
  5991. ident: "group_" + n + "_body"
  5992. }
  5993. }
  5994.  
  5995. const fullSkipTowerCall = {
  5996. calls: []
  5997. }
  5998.  
  5999. let n = 0;
  6000. for (let i = 0; i < 15; i++) {
  6001. // 15 сундуков
  6002. fullSkipTowerCall.calls.push(nextChest(++n));
  6003. fullSkipTowerCall.calls.push(openChest(++n));
  6004. // +5 сундуков, 250 изюма // towerOpenChest
  6005. // if (i < 5) {
  6006. // fullSkipTowerCall.calls.push(openChest(++n, 2));
  6007. // }
  6008. }
  6009.  
  6010. fullSkipTowerCall.calls.push({
  6011. name: 'towerGetInfo',
  6012. args: {},
  6013. ident: 'group_' + ++n + '_body',
  6014. });
  6015.  
  6016. send(JSON.stringify(fullSkipTowerCall), data => {
  6017. for (const r of data.results) {
  6018. const towerInfo = r?.result?.response;
  6019. if (towerInfo && 'skullReward' in towerInfo) {
  6020. scullCoin += towerInfo.skullReward?.coin[7] ?? 0;
  6021. }
  6022. }
  6023. data.results[0] = data.results[data.results.length - 1];
  6024. checkDataFloor(data);
  6025. });
  6026. }
  6027.  
  6028. function nextChestOpen(floorNumber) {
  6029. const calls = [{
  6030. name: "towerOpenChest",
  6031. args: {
  6032. num: 2
  6033. },
  6034. ident: "towerOpenChest"
  6035. }];
  6036.  
  6037. Send(JSON.stringify({ calls })).then(e => {
  6038. nextOpenChest(floorNumber);
  6039. });
  6040. }
  6041.  
  6042. function nextOpenChest(floorNumber) {
  6043. if (floorNumber > 49) {
  6044. endTower('openChest 50 floor', floorNumber);
  6045. return;
  6046. }
  6047.  
  6048. let nextOpenChestCall = {
  6049. calls: [{
  6050. name: "towerNextChest",
  6051. args: {},
  6052. ident: "towerNextChest"
  6053. }, {
  6054. name: "towerOpenChest",
  6055. args: {
  6056. num: 2
  6057. },
  6058. ident: "towerOpenChest"
  6059. }]
  6060. }
  6061. send(JSON.stringify(nextOpenChestCall), checkDataFloor);
  6062. }
  6063.  
  6064. function endTower(reason, info) {
  6065. console.log(reason, info);
  6066. if (reason != 'noTower') {
  6067. farmTowerRewards(reason);
  6068. }
  6069. setProgress(`${I18N('TOWER')} ${I18N('COMPLETED')}!`, true);
  6070. resolve();
  6071. }
  6072. }
  6073.  
  6074. this.HWHClasses.executeTower = executeTower;
  6075.  
  6076. /**
  6077. * Passage of the arena of the titans
  6078. *
  6079. * Прохождение арены титанов
  6080. */
  6081. function testTitanArena() {
  6082. const { executeTitanArena } = HWHClasses;
  6083. return new Promise((resolve, reject) => {
  6084. titAren = new executeTitanArena(resolve, reject);
  6085. titAren.start();
  6086. });
  6087. }
  6088.  
  6089. /**
  6090. * Passage of the arena of the titans
  6091. *
  6092. * Прохождение арены титанов
  6093. */
  6094. function executeTitanArena(resolve, reject) {
  6095. let titan_arena = [];
  6096. let finishListBattle = [];
  6097. /**
  6098. * ID of the current batch
  6099. *
  6100. * Идетификатор текущей пачки
  6101. */
  6102. let currentRival = 0;
  6103. /**
  6104. * Number of attempts to finish off the pack
  6105. *
  6106. * Количество попыток добития пачки
  6107. */
  6108. let attempts = 0;
  6109. /**
  6110. * Was there an attempt to finish off the current shooting range
  6111. *
  6112. * Была ли попытка добития текущего тира
  6113. */
  6114. let isCheckCurrentTier = false;
  6115. /**
  6116. * Current shooting range
  6117. *
  6118. * Текущий тир
  6119. */
  6120. let currTier = 0;
  6121. /**
  6122. * Number of battles on the current dash
  6123. *
  6124. * Количество битв на текущем тире
  6125. */
  6126. let countRivalsTier = 0;
  6127.  
  6128. let callsStart = {
  6129. calls: [{
  6130. name: "titanArenaGetStatus",
  6131. args: {},
  6132. ident: "titanArenaGetStatus"
  6133. }, {
  6134. name: "teamGetAll",
  6135. args: {},
  6136. ident: "teamGetAll"
  6137. }]
  6138. }
  6139.  
  6140. this.start = function () {
  6141. send(JSON.stringify(callsStart), startTitanArena);
  6142. }
  6143.  
  6144. function startTitanArena(data) {
  6145. let titanArena = data.results[0].result.response;
  6146. if (titanArena.status == 'disabled') {
  6147. endTitanArena('disabled', titanArena);
  6148. return;
  6149. }
  6150.  
  6151. let teamGetAll = data.results[1].result.response;
  6152. titan_arena = teamGetAll.titan_arena;
  6153.  
  6154. checkTier(titanArena)
  6155. }
  6156.  
  6157. function checkTier(titanArena) {
  6158. if (titanArena.status == "peace_time") {
  6159. endTitanArena('Peace_time', titanArena);
  6160. return;
  6161. }
  6162. currTier = titanArena.tier;
  6163. if (currTier) {
  6164. setProgress(`${I18N('TITAN_ARENA')}: ${I18N('LEVEL')} ${currTier}`);
  6165. }
  6166.  
  6167. if (titanArena.status == "completed_tier") {
  6168. titanArenaCompleteTier();
  6169. return;
  6170. }
  6171. /**
  6172. * Checking for the possibility of a raid
  6173. * Проверка на возможность рейда
  6174. */
  6175. if (titanArena.canRaid) {
  6176. titanArenaStartRaid();
  6177. return;
  6178. }
  6179. /**
  6180. * Check was an attempt to achieve the current shooting range
  6181. * Проверка была ли попытка добития текущего тира
  6182. */
  6183. if (!isCheckCurrentTier) {
  6184. checkRivals(titanArena.rivals);
  6185. return;
  6186. }
  6187.  
  6188. endTitanArena('Done or not canRaid', titanArena);
  6189. }
  6190. /**
  6191. * Submit dash information for verification
  6192. *
  6193. * Отправка информации о тире на проверку
  6194. */
  6195. function checkResultInfo(data) {
  6196. let titanArena = data.results[0].result.response;
  6197. checkTier(titanArena);
  6198. }
  6199. /**
  6200. * Finish the current tier
  6201. *
  6202. * Завершить текущий тир
  6203. */
  6204. function titanArenaCompleteTier() {
  6205. isCheckCurrentTier = false;
  6206. let calls = [{
  6207. name: "titanArenaCompleteTier",
  6208. args: {},
  6209. ident: "body"
  6210. }];
  6211. send(JSON.stringify({calls}), checkResultInfo);
  6212. }
  6213. /**
  6214. * Gathering points to be completed
  6215. *
  6216. * Собираем точки которые нужно добить
  6217. */
  6218. function checkRivals(rivals) {
  6219. finishListBattle = [];
  6220. for (let n in rivals) {
  6221. if (rivals[n].attackScore < 250) {
  6222. finishListBattle.push(n);
  6223. }
  6224. }
  6225. console.log('checkRivals', finishListBattle);
  6226. countRivalsTier = finishListBattle.length;
  6227. roundRivals();
  6228. }
  6229. /**
  6230. * Selecting the next point to finish off
  6231. *
  6232. * Выбор следующей точки для добития
  6233. */
  6234. function roundRivals() {
  6235. let countRivals = finishListBattle.length;
  6236. if (!countRivals) {
  6237. /**
  6238. * Whole range checked
  6239. *
  6240. * Весь тир проверен
  6241. */
  6242. isCheckCurrentTier = true;
  6243. titanArenaGetStatus();
  6244. return;
  6245. }
  6246. // setProgress('TitanArena: Уровень ' + currTier + ' Бои: ' + (countRivalsTier - countRivals + 1) + '/' + countRivalsTier);
  6247. currentRival = finishListBattle.pop();
  6248. attempts = +currentRival;
  6249. // console.log('roundRivals', currentRival);
  6250. titanArenaStartBattle(currentRival);
  6251. }
  6252. /**
  6253. * The start of a solo battle
  6254. *
  6255. * Начало одиночной битвы
  6256. */
  6257. function titanArenaStartBattle(rivalId) {
  6258. let calls = [{
  6259. name: "titanArenaStartBattle",
  6260. args: {
  6261. rivalId: rivalId,
  6262. titans: titan_arena
  6263. },
  6264. ident: "body"
  6265. }];
  6266. send(JSON.stringify({calls}), calcResult);
  6267. }
  6268. /**
  6269. * Calculation of the results of the battle
  6270. *
  6271. * Расчет результатов боя
  6272. */
  6273. function calcResult(data) {
  6274. let battlesInfo = data.results[0].result.response.battle;
  6275. /**
  6276. * If attempts are equal to the current battle number we make
  6277. * Если попытки равны номеру текущего боя делаем прерасчет
  6278. */
  6279. if (attempts == currentRival) {
  6280. preCalcBattle(battlesInfo);
  6281. return;
  6282. }
  6283. /**
  6284. * If there are still attempts, we calculate a new battle
  6285. * Если попытки еще есть делаем расчет нового боя
  6286. */
  6287. if (attempts > 0) {
  6288. attempts--;
  6289. calcBattleResult(battlesInfo)
  6290. .then(resultCalcBattle);
  6291. return;
  6292. }
  6293. /**
  6294. * Otherwise, go to the next opponent
  6295. * Иначе переходим к следующему сопернику
  6296. */
  6297. roundRivals();
  6298. }
  6299. /**
  6300. * Processing the results of the battle calculation
  6301. *
  6302. * Обработка результатов расчета битвы
  6303. */
  6304. function resultCalcBattle(resultBattle) {
  6305. // console.log('resultCalcBattle', currentRival, attempts, resultBattle.result.win);
  6306. /**
  6307. * If the current calculation of victory is not a chance or the attempt ended with the finish the battle
  6308. * Если текущий расчет победа или шансов нет или попытки кончились завершаем бой
  6309. */
  6310. if (resultBattle.result.win || !attempts) {
  6311. titanArenaEndBattle({
  6312. progress: resultBattle.progress,
  6313. result: resultBattle.result,
  6314. rivalId: resultBattle.battleData.typeId
  6315. });
  6316. return;
  6317. }
  6318. /**
  6319. * If not victory and there are attempts we start a new battle
  6320. * Если не победа и есть попытки начинаем новый бой
  6321. */
  6322. titanArenaStartBattle(resultBattle.battleData.typeId);
  6323. }
  6324. /**
  6325. * Returns the promise of calculating the results of the battle
  6326. *
  6327. * Возращает промис расчета результатов битвы
  6328. */
  6329. function getBattleInfo(battle, isRandSeed) {
  6330. return new Promise(function (resolve) {
  6331. if (isRandSeed) {
  6332. battle.seed = Math.floor(Date.now() / 1000) + random(0, 1e3);
  6333. }
  6334. // console.log(battle.seed);
  6335. BattleCalc(battle, "get_titanClanPvp", e => resolve(e));
  6336. });
  6337. }
  6338. /**
  6339. * Recalculate battles
  6340. *
  6341. * Прерасчтет битвы
  6342. */
  6343. function preCalcBattle(battle) {
  6344. let actions = [getBattleInfo(battle, false)];
  6345. const countTestBattle = getInput('countTestBattle');
  6346. for (let i = 0; i < countTestBattle; i++) {
  6347. actions.push(getBattleInfo(battle, true));
  6348. }
  6349. Promise.all(actions)
  6350. .then(resultPreCalcBattle);
  6351. }
  6352. /**
  6353. * Processing the results of the battle recalculation
  6354. *
  6355. * Обработка результатов прерасчета битвы
  6356. */
  6357. function resultPreCalcBattle(e) {
  6358. let wins = e.map(n => n.result.win);
  6359. let firstBattle = e.shift();
  6360. let countWin = wins.reduce((w, s) => w + s);
  6361. const countTestBattle = getInput('countTestBattle');
  6362. console.log('resultPreCalcBattle', `${countWin}/${countTestBattle}`)
  6363. if (countWin > 0) {
  6364. attempts = getInput('countAutoBattle');
  6365. } else {
  6366. attempts = 0;
  6367. }
  6368. resultCalcBattle(firstBattle);
  6369. }
  6370.  
  6371. /**
  6372. * Complete an arena battle
  6373. *
  6374. * Завершить битву на арене
  6375. */
  6376. function titanArenaEndBattle(args) {
  6377. let calls = [{
  6378. name: "titanArenaEndBattle",
  6379. args,
  6380. ident: "body"
  6381. }];
  6382. send(JSON.stringify({calls}), resultTitanArenaEndBattle);
  6383. }
  6384.  
  6385. function resultTitanArenaEndBattle(e) {
  6386. let attackScore = e.results[0].result.response.attackScore;
  6387. let numReval = countRivalsTier - finishListBattle.length;
  6388. setProgress(`${I18N('TITAN_ARENA')}: ${I18N('LEVEL')} ${currTier} </br>${I18N('BATTLES')}: ${numReval}/${countRivalsTier} - ${attackScore}`);
  6389. /**
  6390. * TODO: Might need to improve the results.
  6391. * TODO: Возможно стоит сделать улучшение результатов
  6392. */
  6393. // console.log('resultTitanArenaEndBattle', e)
  6394. console.log('resultTitanArenaEndBattle', numReval + '/' + countRivalsTier, attempts)
  6395. roundRivals();
  6396. }
  6397. /**
  6398. * Arena State
  6399. *
  6400. * Состояние арены
  6401. */
  6402. function titanArenaGetStatus() {
  6403. let calls = [{
  6404. name: "titanArenaGetStatus",
  6405. args: {},
  6406. ident: "body"
  6407. }];
  6408. send(JSON.stringify({calls}), checkResultInfo);
  6409. }
  6410. /**
  6411. * Arena Raid Request
  6412. *
  6413. * Запрос рейда арены
  6414. */
  6415. function titanArenaStartRaid() {
  6416. let calls = [{
  6417. name: "titanArenaStartRaid",
  6418. args: {
  6419. titans: titan_arena
  6420. },
  6421. ident: "body"
  6422. }];
  6423. send(JSON.stringify({calls}), calcResults);
  6424. }
  6425.  
  6426. function calcResults(data) {
  6427. let battlesInfo = data.results[0].result.response;
  6428. let {attackers, rivals} = battlesInfo;
  6429.  
  6430. let promises = [];
  6431. for (let n in rivals) {
  6432. rival = rivals[n];
  6433. promises.push(calcBattleResult({
  6434. attackers: attackers,
  6435. defenders: [rival.team],
  6436. seed: rival.seed,
  6437. typeId: n,
  6438. }));
  6439. }
  6440.  
  6441. Promise.all(promises)
  6442. .then(results => {
  6443. const endResults = {};
  6444. for (let info of results) {
  6445. let id = info.battleData.typeId;
  6446. endResults[id] = {
  6447. progress: info.progress,
  6448. result: info.result,
  6449. }
  6450. }
  6451. titanArenaEndRaid(endResults);
  6452. });
  6453. }
  6454.  
  6455. function calcBattleResult(battleData) {
  6456. return new Promise(function (resolve, reject) {
  6457. BattleCalc(battleData, "get_titanClanPvp", resolve);
  6458. });
  6459. }
  6460.  
  6461. /**
  6462. * Sending Raid Results
  6463. *
  6464. * Отправка результатов рейда
  6465. */
  6466. function titanArenaEndRaid(results) {
  6467. titanArenaEndRaidCall = {
  6468. calls: [{
  6469. name: "titanArenaEndRaid",
  6470. args: {
  6471. results
  6472. },
  6473. ident: "body"
  6474. }]
  6475. }
  6476. send(JSON.stringify(titanArenaEndRaidCall), checkRaidResults);
  6477. }
  6478.  
  6479. function checkRaidResults(data) {
  6480. results = data.results[0].result.response.results;
  6481. isSucsesRaid = true;
  6482. for (let i in results) {
  6483. isSucsesRaid &&= (results[i].attackScore >= 250);
  6484. }
  6485.  
  6486. if (isSucsesRaid) {
  6487. titanArenaCompleteTier();
  6488. } else {
  6489. titanArenaGetStatus();
  6490. }
  6491. }
  6492.  
  6493. function titanArenaFarmDailyReward() {
  6494. titanArenaFarmDailyRewardCall = {
  6495. calls: [{
  6496. name: "titanArenaFarmDailyReward",
  6497. args: {},
  6498. ident: "body"
  6499. }]
  6500. }
  6501. send(JSON.stringify(titanArenaFarmDailyRewardCall), () => {console.log('Done farm daily reward')});
  6502. }
  6503.  
  6504. function endTitanArena(reason, info) {
  6505. if (!['Peace_time', 'disabled'].includes(reason)) {
  6506. titanArenaFarmDailyReward();
  6507. }
  6508. console.log(reason, info);
  6509. setProgress(`${I18N('TITAN_ARENA')} ${I18N('COMPLETED')}!`, true);
  6510. resolve();
  6511. }
  6512. }
  6513.  
  6514. this.HWHClasses.executeTitanArena = executeTitanArena;
  6515.  
  6516. function hackGame() {
  6517. const self = this;
  6518. selfGame = null;
  6519. bindId = 1e9;
  6520. this.libGame = null;
  6521. this.doneLibLoad = () => {}
  6522.  
  6523. /**
  6524. * List of correspondence of used classes to their names
  6525. *
  6526. * Список соответствия используемых классов их названиям
  6527. */
  6528. ObjectsList = [
  6529. { name: 'BattlePresets', prop: 'game.battle.controller.thread.BattlePresets' },
  6530. { name: 'DataStorage', prop: 'game.data.storage.DataStorage' },
  6531. { name: 'BattleConfigStorage', prop: 'game.data.storage.battle.BattleConfigStorage' },
  6532. { name: 'BattleInstantPlay', prop: 'game.battle.controller.instant.BattleInstantPlay' },
  6533. { name: 'MultiBattleInstantReplay', prop: 'game.battle.controller.instant.MultiBattleInstantReplay' },
  6534. { name: 'MultiBattleResult', prop: 'game.battle.controller.MultiBattleResult' },
  6535.  
  6536. { name: 'PlayerMissionData', prop: 'game.model.user.mission.PlayerMissionData' },
  6537. { name: 'PlayerMissionBattle', prop: 'game.model.user.mission.PlayerMissionBattle' },
  6538. { name: 'GameModel', prop: 'game.model.GameModel' },
  6539. { name: 'CommandManager', prop: 'game.command.CommandManager' },
  6540. { name: 'MissionCommandList', prop: 'game.command.rpc.mission.MissionCommandList' },
  6541. { name: 'RPCCommandBase', prop: 'game.command.rpc.RPCCommandBase' },
  6542. { name: 'PlayerTowerData', prop: 'game.model.user.tower.PlayerTowerData' },
  6543. { name: 'TowerCommandList', prop: 'game.command.tower.TowerCommandList' },
  6544. { name: 'PlayerHeroTeamResolver', prop: 'game.model.user.hero.PlayerHeroTeamResolver' },
  6545. { name: 'BattlePausePopup', prop: 'game.view.popup.battle.BattlePausePopup' },
  6546. { name: 'BattlePopup', prop: 'game.view.popup.battle.BattlePopup' },
  6547. { name: 'DisplayObjectContainer', prop: 'starling.display.DisplayObjectContainer' },
  6548. { name: 'GuiClipContainer', prop: 'engine.core.clipgui.GuiClipContainer' },
  6549. { name: 'BattlePausePopupClip', prop: 'game.view.popup.battle.BattlePausePopupClip' },
  6550. { name: 'ClipLabel', prop: 'game.view.gui.components.ClipLabel' },
  6551. { name: 'ClipLabelBase', prop: 'game.view.gui.components.ClipLabelBase' },
  6552. { name: 'Translate', prop: 'com.progrestar.common.lang.Translate' },
  6553. { name: 'ClipButtonLabeledCentered', prop: 'game.view.gui.components.ClipButtonLabeledCentered' },
  6554. { name: 'BattlePausePopupMediator', prop: 'game.mediator.gui.popup.battle.BattlePausePopupMediator' },
  6555. { name: 'SettingToggleButton', prop: 'game.mechanics.settings.popup.view.SettingToggleButton' },
  6556. { name: 'PlayerDungeonData', prop: 'game.mechanics.dungeon.model.PlayerDungeonData' },
  6557. { name: 'NextDayUpdatedManager', prop: 'game.model.user.NextDayUpdatedManager' },
  6558. { name: 'BattleController', prop: 'game.battle.controller.BattleController' },
  6559. { name: 'BattleSettingsModel', prop: 'game.battle.controller.BattleSettingsModel' },
  6560. { name: 'BooleanProperty', prop: 'engine.core.utils.property.BooleanProperty' },
  6561. { name: 'RuleStorage', prop: 'game.data.storage.rule.RuleStorage' },
  6562. { name: 'BattleConfig', prop: 'battle.BattleConfig' },
  6563. { name: 'BattleGuiMediator', prop: 'game.battle.gui.BattleGuiMediator' },
  6564. { name: 'BooleanPropertyWriteable', prop: 'engine.core.utils.property.BooleanPropertyWriteable' },
  6565. { name: 'BattleLogEncoder', prop: 'battle.log.BattleLogEncoder' },
  6566. { name: 'BattleLogReader', prop: 'battle.log.BattleLogReader' },
  6567. { name: 'PlayerSubscriptionInfoValueObject', prop: 'game.model.user.subscription.PlayerSubscriptionInfoValueObject' },
  6568. { name: 'AdventureMapCamera', prop: 'game.mechanics.adventure.popup.map.AdventureMapCamera' },
  6569. ];
  6570.  
  6571. /**
  6572. * Contains the game classes needed to write and override game methods
  6573. *
  6574. * Содержит классы игры необходимые для написания и подмены методов игры
  6575. */
  6576. Game = {
  6577. /**
  6578. * Function 'e'
  6579. * Функция 'e'
  6580. */
  6581. bindFunc: function (a, b) {
  6582. if (null == b)
  6583. return null;
  6584. null == b.__id__ && (b.__id__ = bindId++);
  6585. var c;
  6586. null == a.hx__closures__ ? a.hx__closures__ = {} :
  6587. c = a.hx__closures__[b.__id__];
  6588. null == c && (c = b.bind(a), a.hx__closures__[b.__id__] = c);
  6589. return c
  6590. },
  6591. };
  6592.  
  6593. /**
  6594. * Connects to game objects via the object creation event
  6595. *
  6596. * Подключается к объектам игры через событие создания объекта
  6597. */
  6598. function connectGame() {
  6599. for (let obj of ObjectsList) {
  6600. /**
  6601. * https: //stackoverflow.com/questions/42611719/how-to-intercept-and-modify-a-specific-property-for-any-object
  6602. */
  6603. Object.defineProperty(Object.prototype, obj.prop, {
  6604. set: function (value) {
  6605. if (!selfGame) {
  6606. selfGame = this;
  6607. }
  6608. if (!Game[obj.name]) {
  6609. Game[obj.name] = value;
  6610. }
  6611. // console.log('set ' + obj.prop, this, value);
  6612. this[obj.prop + '_'] = value;
  6613. },
  6614. get: function () {
  6615. // console.log('get ' + obj.prop, this);
  6616. return this[obj.prop + '_'];
  6617. }
  6618. });
  6619. }
  6620. }
  6621.  
  6622. /**
  6623. * Game.BattlePresets
  6624. * @param {bool} a isReplay
  6625. * @param {bool} b autoToggleable
  6626. * @param {bool} c auto On Start
  6627. * @param {object} d config
  6628. * @param {bool} f showBothTeams
  6629. */
  6630. /**
  6631. * Returns the results of the battle to the callback function
  6632. * Возвращает в функцию callback результаты боя
  6633. * @param {*} battleData battle data данные боя
  6634. * @param {*} battleConfig combat configuration type options:
  6635. *
  6636. * тип конфигурации боя варианты:
  6637. *
  6638. * "get_invasion", "get_titanPvpManual", "get_titanPvp",
  6639. * "get_titanClanPvp","get_clanPvp","get_titan","get_boss",
  6640. * "get_tower","get_pve","get_pvpManual","get_pvp","get_core"
  6641. *
  6642. * You can specify the xYc function in the game.assets.storage.BattleAssetStorage class
  6643. *
  6644. * Можно уточнить в классе game.assets.storage.BattleAssetStorage функция xYc
  6645. * @param {*} callback функция в которую вернуться результаты боя
  6646. */
  6647. this.BattleCalc = function (battleData, battleConfig, callback) {
  6648. // battleConfig = battleConfig || getBattleType(battleData.type)
  6649. if (!Game.BattlePresets) throw Error('Use connectGame');
  6650. battlePresets = new Game.BattlePresets(battleData.progress, !1, !0, Game.DataStorage[getFn(Game.DataStorage, 24)][getF(Game.BattleConfigStorage, battleConfig)](), !1);
  6651. let battleInstantPlay;
  6652. if (battleData.progress?.length > 1) {
  6653. battleInstantPlay = new Game.MultiBattleInstantReplay(battleData, battlePresets);
  6654. } else {
  6655. battleInstantPlay = new Game.BattleInstantPlay(battleData, battlePresets);
  6656. }
  6657. battleInstantPlay[getProtoFn(Game.BattleInstantPlay, 9)].add((battleInstant) => {
  6658. const MBR_2 = getProtoFn(Game.MultiBattleResult, 2);
  6659. const battleResults = battleInstant[getF(Game.BattleInstantPlay, 'get_result')]();
  6660. const battleData = battleInstant[getF(Game.BattleInstantPlay, 'get_rawBattleInfo')]();
  6661. const battleLogs = [];
  6662. const timeLimit = battlePresets[getF(Game.BattlePresets, 'get_timeLimit')]();
  6663. let battleTime = 0;
  6664. let battleTimer = 0;
  6665. for (const battleResult of battleResults[MBR_2]) {
  6666. const battleLog = Game.BattleLogEncoder.read(new Game.BattleLogReader(battleResult));
  6667. battleLogs.push(battleLog);
  6668. const maxTime = Math.max(...battleLog.map((e) => (e.time < timeLimit && e.time !== 168.8 ? e.time : 0)));
  6669. battleTimer += getTimer(maxTime)
  6670. battleTime += maxTime;
  6671. }
  6672. callback({
  6673. battleLogs,
  6674. battleTime,
  6675. battleTimer,
  6676. battleData,
  6677. progress: battleResults[getF(Game.MultiBattleResult, 'get_progress')](),
  6678. result: battleResults[getF(Game.MultiBattleResult, 'get_result')](),
  6679. });
  6680. });
  6681. battleInstantPlay.start();
  6682. }
  6683.  
  6684. /**
  6685. * Returns a function with the specified name from the class
  6686. *
  6687. * Возвращает из класса функцию с указанным именем
  6688. * @param {Object} classF Class // класс
  6689. * @param {String} nameF function name // имя функции
  6690. * @param {String} pos name and alias order // порядок имени и псевдонима
  6691. * @returns
  6692. */
  6693. function getF(classF, nameF, pos) {
  6694. pos = pos || false;
  6695. let prop = Object.entries(classF.prototype.__properties__)
  6696. if (!pos) {
  6697. return prop.filter((e) => e[1] == nameF).pop()[0];
  6698. } else {
  6699. return prop.filter((e) => e[0] == nameF).pop()[1];
  6700. }
  6701. }
  6702.  
  6703. /**
  6704. * Returns a function with the specified name from the class
  6705. *
  6706. * Возвращает из класса функцию с указанным именем
  6707. * @param {Object} classF Class // класс
  6708. * @param {String} nameF function name // имя функции
  6709. * @returns
  6710. */
  6711. function getFnP(classF, nameF) {
  6712. let prop = Object.entries(classF.__properties__)
  6713. return prop.filter((e) => e[1] == nameF).pop()[0];
  6714. }
  6715.  
  6716. /**
  6717. * Returns the function name with the specified ordinal from the class
  6718. *
  6719. * Возвращает имя функции с указаным порядковым номером из класса
  6720. * @param {Object} classF Class // класс
  6721. * @param {Number} nF Order number of function // порядковый номер функции
  6722. * @returns
  6723. */
  6724. function getFn(classF, nF) {
  6725. let prop = Object.keys(classF);
  6726. return prop[nF];
  6727. }
  6728.  
  6729. /**
  6730. * Returns the name of the function with the specified serial number from the prototype of the class
  6731. *
  6732. * Возвращает имя функции с указаным порядковым номером из прототипа класса
  6733. * @param {Object} classF Class // класс
  6734. * @param {Number} nF Order number of function // порядковый номер функции
  6735. * @returns
  6736. */
  6737. function getProtoFn(classF, nF) {
  6738. let prop = Object.keys(classF.prototype);
  6739. return prop[nF];
  6740. }
  6741. /**
  6742. * Description of replaced functions
  6743. *
  6744. * Описание подменяемых функций
  6745. */
  6746. replaceFunction = {
  6747. company: function () {
  6748. let PMD_12 = getProtoFn(Game.PlayerMissionData, 12);
  6749. let oldSkipMisson = Game.PlayerMissionData.prototype[PMD_12];
  6750. Game.PlayerMissionData.prototype[PMD_12] = function (a, b, c) {
  6751. if (!isChecked('passBattle')) {
  6752. oldSkipMisson.call(this, a, b, c);
  6753. return;
  6754. }
  6755.  
  6756. try {
  6757. this[getProtoFn(Game.PlayerMissionData, 9)] = new Game.PlayerMissionBattle(a, b, c);
  6758.  
  6759. var a = new Game.BattlePresets(
  6760. !1,
  6761. !1,
  6762. !0,
  6763. Game.DataStorage[getFn(Game.DataStorage, 24)][getProtoFn(Game.BattleConfigStorage, 20)](),
  6764. !1
  6765. );
  6766. a = new Game.BattleInstantPlay(c, a);
  6767. a[getProtoFn(Game.BattleInstantPlay, 9)].add(Game.bindFunc(this, this.P$h));
  6768. a.start();
  6769. } catch (error) {
  6770. console.error('company', error);
  6771. oldSkipMisson.call(this, a, b, c);
  6772. }
  6773. };
  6774.  
  6775. Game.PlayerMissionData.prototype.P$h = function (a) {
  6776. let GM_2 = getFn(Game.GameModel, 2);
  6777. let GM_P2 = getProtoFn(Game.GameModel, 2);
  6778. let CM_20 = getProtoFn(Game.CommandManager, 20);
  6779. let MCL_2 = getProtoFn(Game.MissionCommandList, 2);
  6780. let MBR_15 = getF(Game.MultiBattleResult, 'get_result');
  6781. let RPCCB_15 = getProtoFn(Game.RPCCommandBase, 16);
  6782. let PMD_32 = getProtoFn(Game.PlayerMissionData, 32);
  6783. Game.GameModel[GM_2]()[GM_P2][CM_20][MCL_2](a[MBR_15]())[RPCCB_15](Game.bindFunc(this, this[PMD_32]));
  6784. };
  6785. },
  6786. /*
  6787. tower: function () {
  6788. let PTD_67 = getProtoFn(Game.PlayerTowerData, 67);
  6789. let oldSkipTower = Game.PlayerTowerData.prototype[PTD_67];
  6790. Game.PlayerTowerData.prototype[PTD_67] = function (a) {
  6791. if (!isChecked('passBattle')) {
  6792. oldSkipTower.call(this, a);
  6793. return;
  6794. }
  6795. try {
  6796. var p = new Game.BattlePresets(
  6797. !1,
  6798. !1,
  6799. !0,
  6800. Game.DataStorage[getFn(Game.DataStorage, 24)][getProtoFn(Game.BattleConfigStorage, 20)](),
  6801. !1
  6802. );
  6803. a = new Game.BattleInstantPlay(a, p);
  6804. a[getProtoFn(Game.BattleInstantPlay, 9)].add(Game.bindFunc(this, this.P$h));
  6805. a.start();
  6806. } catch (error) {
  6807. console.error('tower', error);
  6808. oldSkipMisson.call(this, a, b, c);
  6809. }
  6810. };
  6811.  
  6812. Game.PlayerTowerData.prototype.P$h = function (a) {
  6813. const GM_2 = getFnP(Game.GameModel, 'get_instance');
  6814. const GM_P2 = getProtoFn(Game.GameModel, 2);
  6815. const CM_29 = getProtoFn(Game.CommandManager, 29);
  6816. const TCL_5 = getProtoFn(Game.TowerCommandList, 5);
  6817. const MBR_15 = getF(Game.MultiBattleResult, 'get_result');
  6818. const RPCCB_15 = getProtoFn(Game.RPCCommandBase, 17);
  6819. const PTD_78 = getProtoFn(Game.PlayerTowerData, 78);
  6820. Game.GameModel[GM_2]()[GM_P2][CM_29][TCL_5](a[MBR_15]())[RPCCB_15](Game.bindFunc(this, this[PTD_78]));
  6821. };
  6822. },
  6823. */
  6824. // skipSelectHero: function() {
  6825. // if (!HOST) throw Error('Use connectGame');
  6826. // Game.PlayerHeroTeamResolver.prototype[getProtoFn(Game.PlayerHeroTeamResolver, 3)] = () => false;
  6827. // },
  6828. passBattle: function () {
  6829. let BPP_4 = getProtoFn(Game.BattlePausePopup, 4);
  6830. let oldPassBattle = Game.BattlePausePopup.prototype[BPP_4];
  6831. Game.BattlePausePopup.prototype[BPP_4] = function (a) {
  6832. if (!isChecked('passBattle')) {
  6833. oldPassBattle.call(this, a);
  6834. return;
  6835. }
  6836. try {
  6837. Game.BattlePopup.prototype[getProtoFn(Game.BattlePausePopup, 4)].call(this, a);
  6838. this[getProtoFn(Game.BattlePausePopup, 3)]();
  6839. this[getProtoFn(Game.DisplayObjectContainer, 3)](this.clip[getProtoFn(Game.GuiClipContainer, 2)]());
  6840. this.clip[getProtoFn(Game.BattlePausePopupClip, 1)][getProtoFn(Game.ClipLabelBase, 9)](
  6841. Game.Translate.translate('UI_POPUP_BATTLE_PAUSE')
  6842. );
  6843.  
  6844. this.clip[getProtoFn(Game.BattlePausePopupClip, 2)][getProtoFn(Game.ClipButtonLabeledCentered, 2)](
  6845. Game.Translate.translate('UI_POPUP_BATTLE_RETREAT'),
  6846. ((q = this[getProtoFn(Game.BattlePausePopup, 1)]), Game.bindFunc(q, q[getProtoFn(Game.BattlePausePopupMediator, 17)]))
  6847. );
  6848. this.clip[getProtoFn(Game.BattlePausePopupClip, 5)][getProtoFn(Game.ClipButtonLabeledCentered, 2)](
  6849. this[getProtoFn(Game.BattlePausePopup, 1)][getProtoFn(Game.BattlePausePopupMediator, 14)](),
  6850. this[getProtoFn(Game.BattlePausePopup, 1)][getProtoFn(Game.BattlePausePopupMediator, 13)]()
  6851. ? ((q = this[getProtoFn(Game.BattlePausePopup, 1)]), Game.bindFunc(q, q[getProtoFn(Game.BattlePausePopupMediator, 18)]))
  6852. : ((q = this[getProtoFn(Game.BattlePausePopup, 1)]), Game.bindFunc(q, q[getProtoFn(Game.BattlePausePopupMediator, 18)]))
  6853. );
  6854.  
  6855. this.clip[getProtoFn(Game.BattlePausePopupClip, 5)][getProtoFn(Game.ClipButtonLabeledCentered, 0)][
  6856. getProtoFn(Game.ClipLabelBase, 24)
  6857. ]();
  6858. this.clip[getProtoFn(Game.BattlePausePopupClip, 3)][getProtoFn(Game.SettingToggleButton, 3)](
  6859. this[getProtoFn(Game.BattlePausePopup, 1)][getProtoFn(Game.BattlePausePopupMediator, 9)]()
  6860. );
  6861. this.clip[getProtoFn(Game.BattlePausePopupClip, 4)][getProtoFn(Game.SettingToggleButton, 3)](
  6862. this[getProtoFn(Game.BattlePausePopup, 1)][getProtoFn(Game.BattlePausePopupMediator, 10)]()
  6863. );
  6864. this.clip[getProtoFn(Game.BattlePausePopupClip, 6)][getProtoFn(Game.SettingToggleButton, 3)](
  6865. this[getProtoFn(Game.BattlePausePopup, 1)][getProtoFn(Game.BattlePausePopupMediator, 11)]()
  6866. );
  6867. } catch (error) {
  6868. console.error('passBattle', error);
  6869. oldPassBattle.call(this, a);
  6870. }
  6871. };
  6872.  
  6873. let retreatButtonLabel = getF(Game.BattlePausePopupMediator, 'get_retreatButtonLabel');
  6874. let oldFunc = Game.BattlePausePopupMediator.prototype[retreatButtonLabel];
  6875. Game.BattlePausePopupMediator.prototype[retreatButtonLabel] = function () {
  6876. if (isChecked('passBattle')) {
  6877. return I18N('BTN_PASS');
  6878. } else {
  6879. return oldFunc.call(this);
  6880. }
  6881. };
  6882. },
  6883. endlessCards: function () {
  6884. let PDD_21 = getProtoFn(Game.PlayerDungeonData, 21);
  6885. let oldEndlessCards = Game.PlayerDungeonData.prototype[PDD_21];
  6886. Game.PlayerDungeonData.prototype[PDD_21] = function () {
  6887. if (countPredictionCard <= 0) {
  6888. return true;
  6889. } else {
  6890. return oldEndlessCards.call(this);
  6891. }
  6892. };
  6893. },
  6894. speedBattle: function () {
  6895. const get_timeScale = getF(Game.BattleController, 'get_timeScale');
  6896. const oldSpeedBattle = Game.BattleController.prototype[get_timeScale];
  6897. Game.BattleController.prototype[get_timeScale] = function () {
  6898. const speedBattle = Number.parseFloat(getInput('speedBattle'));
  6899. if (!speedBattle) {
  6900. return oldSpeedBattle.call(this);
  6901. }
  6902. try {
  6903. const BC_12 = getProtoFn(Game.BattleController, 12);
  6904. const BSM_12 = getProtoFn(Game.BattleSettingsModel, 12);
  6905. const BP_get_value = getF(Game.BooleanProperty, 'get_value');
  6906. if (this[BC_12][BSM_12][BP_get_value]()) {
  6907. return 0;
  6908. }
  6909. const BSM_2 = getProtoFn(Game.BattleSettingsModel, 2);
  6910. const BC_49 = getProtoFn(Game.BattleController, 49);
  6911. const BSM_1 = getProtoFn(Game.BattleSettingsModel, 1);
  6912. const BC_14 = getProtoFn(Game.BattleController, 14);
  6913. const BC_3 = getFn(Game.BattleController, 3);
  6914. if (this[BC_12][BSM_2][BP_get_value]()) {
  6915. var a = speedBattle * this[BC_49]();
  6916. } else {
  6917. a = this[BC_12][BSM_1][BP_get_value]();
  6918. const maxSpeed = Math.max(...this[BC_14]);
  6919. const multiple = a == this[BC_14].indexOf(maxSpeed) ? (maxSpeed >= 4 ? speedBattle : this[BC_14][a]) : this[BC_14][a];
  6920. a = multiple * Game.BattleController[BC_3][BP_get_value]() * this[BC_49]();
  6921. }
  6922. const BSM_24 = getProtoFn(Game.BattleSettingsModel, 24);
  6923. a > this[BC_12][BSM_24][BP_get_value]() && (a = this[BC_12][BSM_24][BP_get_value]());
  6924. const DS_23 = getFn(Game.DataStorage, 23);
  6925. const get_battleSpeedMultiplier = getF(Game.RuleStorage, 'get_battleSpeedMultiplier', true);
  6926. var b = Game.DataStorage[DS_23][get_battleSpeedMultiplier]();
  6927. const R_1 = getFn(selfGame.Reflect, 1);
  6928. const BC_1 = getFn(Game.BattleController, 1);
  6929. const get_config = getF(Game.BattlePresets, 'get_config');
  6930. null != b &&
  6931. (a = selfGame.Reflect[R_1](b, this[BC_1][get_config]().ident)
  6932. ? a * selfGame.Reflect[R_1](b, this[BC_1][get_config]().ident)
  6933. : a * selfGame.Reflect[R_1](b, 'default'));
  6934. return a;
  6935. } catch (error) {
  6936. console.error('passBatspeedBattletle', error);
  6937. return oldSpeedBattle.call(this);
  6938. }
  6939. };
  6940. },
  6941.  
  6942. /**
  6943. * Acceleration button without Valkyries favor
  6944. *
  6945. * Кнопка ускорения без Покровительства Валькирий
  6946. */
  6947. battleFastKey: function () {
  6948. const BGM_44 = getProtoFn(Game.BattleGuiMediator, 44);
  6949. const oldBattleFastKey = Game.BattleGuiMediator.prototype[BGM_44];
  6950. Game.BattleGuiMediator.prototype[BGM_44] = function () {
  6951. let flag = true;
  6952. //console.log(flag)
  6953. if (!flag) {
  6954. return oldBattleFastKey.call(this);
  6955. }
  6956. try {
  6957. const BGM_9 = getProtoFn(Game.BattleGuiMediator, 9);
  6958. const BGM_10 = getProtoFn(Game.BattleGuiMediator, 10);
  6959. const BPW_0 = getProtoFn(Game.BooleanPropertyWriteable, 0);
  6960. this[BGM_9][BPW_0](true);
  6961. this[BGM_10][BPW_0](true);
  6962. } catch (error) {
  6963. console.error(error);
  6964. return oldBattleFastKey.call(this);
  6965. }
  6966. };
  6967. },
  6968. fastSeason: function () {
  6969. const GameNavigator = selfGame['game.screen.navigator.GameNavigator'];
  6970. const oldFuncName = getProtoFn(GameNavigator, 18);
  6971. const newFuncName = getProtoFn(GameNavigator, 16);
  6972. const oldFastSeason = GameNavigator.prototype[oldFuncName];
  6973. const newFastSeason = GameNavigator.prototype[newFuncName];
  6974. GameNavigator.prototype[oldFuncName] = function (a, b) {
  6975. if (isChecked('fastSeason')) {
  6976. return newFastSeason.apply(this, [a]);
  6977. } else {
  6978. return oldFastSeason.apply(this, [a, b]);
  6979. }
  6980. };
  6981. },
  6982. ShowChestReward: function () {
  6983. const TitanArtifactChest = selfGame['game.mechanics.titan_arena.mediator.chest.TitanArtifactChestRewardPopupMediator'];
  6984. const getOpenAmountTitan = getF(TitanArtifactChest, 'get_openAmount');
  6985. const oldGetOpenAmountTitan = TitanArtifactChest.prototype[getOpenAmountTitan];
  6986. TitanArtifactChest.prototype[getOpenAmountTitan] = function () {
  6987. if (correctShowOpenArtifact) {
  6988. correctShowOpenArtifact--;
  6989. return 100;
  6990. }
  6991. return oldGetOpenAmountTitan.call(this);
  6992. };
  6993.  
  6994. const ArtifactChest = selfGame['game.view.popup.artifactchest.rewardpopup.ArtifactChestRewardPopupMediator'];
  6995. const getOpenAmount = getF(ArtifactChest, 'get_openAmount');
  6996. const oldGetOpenAmount = ArtifactChest.prototype[getOpenAmount];
  6997. ArtifactChest.prototype[getOpenAmount] = function () {
  6998. if (correctShowOpenArtifact) {
  6999. correctShowOpenArtifact--;
  7000. return 100;
  7001. }
  7002. return oldGetOpenAmount.call(this);
  7003. };
  7004. },
  7005. fixCompany: function () {
  7006. const GameBattleView = selfGame['game.mediator.gui.popup.battle.GameBattleView'];
  7007. const BattleThread = selfGame['game.battle.controller.thread.BattleThread'];
  7008. const getOnViewDisposed = getF(BattleThread, 'get_onViewDisposed');
  7009. const getThread = getF(GameBattleView, 'get_thread');
  7010. const oldFunc = GameBattleView.prototype[getThread];
  7011. GameBattleView.prototype[getThread] = function () {
  7012. return (
  7013. oldFunc.call(this) || {
  7014. [getOnViewDisposed]: async () => {},
  7015. }
  7016. );
  7017. };
  7018. },
  7019. BuyTitanArtifact: function () {
  7020. const BIP_4 = getProtoFn(selfGame['game.view.popup.shop.buy.BuyItemPopup'], 4);
  7021. const BuyItemPopup = selfGame['game.view.popup.shop.buy.BuyItemPopup'];
  7022. const oldFunc = BuyItemPopup.prototype[BIP_4];
  7023. BuyItemPopup.prototype[BIP_4] = function () {
  7024. if (isChecked('countControl')) {
  7025. const BuyTitanArtifactItemPopup = selfGame['game.view.popup.shop.buy.BuyTitanArtifactItemPopup'];
  7026. const BTAP_0 = getProtoFn(BuyTitanArtifactItemPopup, 0);
  7027. if (this[BTAP_0]) {
  7028. const BuyTitanArtifactPopupMediator = selfGame['game.mediator.gui.popup.shop.buy.BuyTitanArtifactItemPopupMediator'];
  7029. const BTAM_1 = getProtoFn(BuyTitanArtifactPopupMediator, 1);
  7030. const BuyItemPopupMediator = selfGame['game.mediator.gui.popup.shop.buy.BuyItemPopupMediator'];
  7031. const BIPM_5 = getProtoFn(BuyItemPopupMediator, 5);
  7032. const BIPM_7 = getProtoFn(BuyItemPopupMediator, 7);
  7033. const BIPM_9 = getProtoFn(BuyItemPopupMediator, 9);
  7034.  
  7035. let need = Math.min(this[BTAP_0][BTAM_1](), this[BTAP_0][BIPM_7]);
  7036. need = need ? need : 60;
  7037. this[BTAP_0][BIPM_9] = need;
  7038. this[BTAP_0][BIPM_5] = 10;
  7039. }
  7040. }
  7041. oldFunc.call(this);
  7042. };
  7043. },
  7044. ClanQuestsFastFarm: function () {
  7045. const VipRuleValueObject = selfGame['game.data.storage.rule.VipRuleValueObject'];
  7046. const getClanQuestsFastFarm = getF(VipRuleValueObject, 'get_clanQuestsFastFarm', 1);
  7047. VipRuleValueObject.prototype[getClanQuestsFastFarm] = function () {
  7048. return 0;
  7049. };
  7050. },
  7051. adventureCamera: function () {
  7052. const AMC_40 = getProtoFn(Game.AdventureMapCamera, 40);
  7053. const AMC_5 = getProtoFn(Game.AdventureMapCamera, 5);
  7054. const oldFunc = Game.AdventureMapCamera.prototype[AMC_40];
  7055. Game.AdventureMapCamera.prototype[AMC_40] = function (a) {
  7056. this[AMC_5] = 0.4;
  7057. oldFunc.bind(this)(a);
  7058. };
  7059. },
  7060. unlockMission: function () {
  7061. const WorldMapStoryDrommerHelper = selfGame['game.mediator.gui.worldmap.WorldMapStoryDrommerHelper'];
  7062. const WMSDH_4 = getFn(WorldMapStoryDrommerHelper, 4);
  7063. const WMSDH_7 = getFn(WorldMapStoryDrommerHelper, 7);
  7064. WorldMapStoryDrommerHelper[WMSDH_4] = function () {
  7065. return true;
  7066. };
  7067. WorldMapStoryDrommerHelper[WMSDH_7] = function () {
  7068. return true;
  7069. };
  7070. },
  7071. };
  7072.  
  7073. /**
  7074. * Starts replacing recorded functions
  7075. *
  7076. * Запускает замену записанных функций
  7077. */
  7078. this.activateHacks = function () {
  7079. if (!selfGame) throw Error('Use connectGame');
  7080. for (let func in replaceFunction) {
  7081. try {
  7082. replaceFunction[func]();
  7083. } catch (error) {
  7084. console.error(error);
  7085. }
  7086. }
  7087. }
  7088.  
  7089. /**
  7090. * Returns the game object
  7091. *
  7092. * Возвращает объект игры
  7093. */
  7094. this.getSelfGame = function () {
  7095. return selfGame;
  7096. }
  7097.  
  7098. /**
  7099. * Updates game data
  7100. *
  7101. * Обновляет данные игры
  7102. */
  7103. this.refreshGame = function () {
  7104. (new Game.NextDayUpdatedManager)[getProtoFn(Game.NextDayUpdatedManager, 5)]();
  7105. try {
  7106. cheats.refreshInventory();
  7107. } catch (e) { }
  7108. }
  7109.  
  7110. /**
  7111. * Update inventory
  7112. *
  7113. * Обновляет инвентарь
  7114. */
  7115. this.refreshInventory = async function () {
  7116. const GM_INST = getFnP(Game.GameModel, "get_instance");
  7117. const GM_0 = getProtoFn(Game.GameModel, 0);
  7118. const P_24 = getProtoFn(selfGame["game.model.user.Player"], 24);
  7119. const Player = Game.GameModel[GM_INST]()[GM_0];
  7120. Player[P_24] = new selfGame["game.model.user.inventory.PlayerInventory"]
  7121. Player[P_24].init(await Send({calls:[{name:"inventoryGet",args:{},ident:"body"}]}).then(e => e.results[0].result.response))
  7122. }
  7123. this.updateInventory = function (reward) {
  7124. const GM_INST = getFnP(Game.GameModel, 'get_instance');
  7125. const GM_0 = getProtoFn(Game.GameModel, 0);
  7126. const P_24 = getProtoFn(selfGame['game.model.user.Player'], 24);
  7127. const Player = Game.GameModel[GM_INST]()[GM_0];
  7128. Player[P_24].init(reward);
  7129. };
  7130.  
  7131. this.updateMap = function (data) {
  7132. const PCDD_21 = getProtoFn(selfGame['game.mechanics.clanDomination.model.PlayerClanDominationData'], 21);
  7133. const P_60 = getProtoFn(selfGame['game.model.user.Player'], 60);
  7134. const GM_0 = getProtoFn(Game.GameModel, 0);
  7135. const getInstance = getFnP(selfGame['Game'], 'get_instance');
  7136. const PlayerClanDominationData = Game.GameModel[getInstance]()[GM_0];
  7137. PlayerClanDominationData[P_60][PCDD_21].update(data);
  7138. };
  7139.  
  7140. /**
  7141. * Change the play screen on windowName
  7142. *
  7143. * Сменить экран игры на windowName
  7144. *
  7145. * Possible options:
  7146. *
  7147. * Возможные варианты:
  7148. *
  7149. * MISSION, ARENA, GRAND, CHEST, SKILLS, SOCIAL_GIFT, CLAN, ENCHANT, TOWER, RATING, CHALLENGE, BOSS, CHAT, CLAN_DUNGEON, CLAN_CHEST, TITAN_GIFT, CLAN_RAID, ASGARD, HERO_ASCENSION, ROLE_ASCENSION, ASCENSION_CHEST, TITAN_MISSION, TITAN_ARENA, TITAN_ARTIFACT, TITAN_ARTIFACT_CHEST, TITAN_VALLEY, TITAN_SPIRITS, TITAN_ARTIFACT_MERCHANT, TITAN_ARENA_HALL_OF_FAME, CLAN_PVP, CLAN_PVP_MERCHANT, CLAN_GLOBAL_PVP, CLAN_GLOBAL_PVP_TITAN, ARTIFACT, ZEPPELIN, ARTIFACT_CHEST, ARTIFACT_MERCHANT, EXPEDITIONS, SUBSCRIPTION, NY2018_GIFTS, NY2018_TREE, NY2018_WELCOME, ADVENTURE, ADVENTURESOLO, SANCTUARY, PET_MERCHANT, PET_LIST, PET_SUMMON, BOSS_RATING_EVENT, BRAWL
  7150. */
  7151. this.goNavigtor = function (windowName) {
  7152. let mechanicStorage = selfGame["game.data.storage.mechanic.MechanicStorage"];
  7153. let window = mechanicStorage[windowName];
  7154. let event = new selfGame["game.mediator.gui.popup.PopupStashEventParams"];
  7155. let Game = selfGame['Game'];
  7156. let navigator = getF(Game, "get_navigator")
  7157. let navigate = getProtoFn(selfGame["game.screen.navigator.GameNavigator"], 20)
  7158. let instance = getFnP(Game, 'get_instance');
  7159. Game[instance]()[navigator]()[navigate](window, event);
  7160. }
  7161.  
  7162. /**
  7163. * Move to the sanctuary cheats.goSanctuary()
  7164. *
  7165. * Переместиться в святилище cheats.goSanctuary()
  7166. */
  7167. this.goSanctuary = () => {
  7168. this.goNavigtor("SANCTUARY");
  7169. }
  7170.  
  7171. /**
  7172. * Go to Guild War
  7173. *
  7174. * Перейти к Войне Гильдий
  7175. */
  7176. this.goClanWar = function() {
  7177. let instance = getFnP(Game.GameModel, 'get_instance')
  7178. let player = Game.GameModel[instance]().A;
  7179. let clanWarSelect = selfGame["game.mechanics.cross_clan_war.popup.selectMode.CrossClanWarSelectModeMediator"];
  7180. new clanWarSelect(player).open();
  7181. }
  7182.  
  7183. /**
  7184. * Go to BrawlShop
  7185. *
  7186. * Переместиться в BrawlShop
  7187. */
  7188. this.goBrawlShop = () => {
  7189. const instance = getFnP(Game.GameModel, 'get_instance')
  7190. const P_36 = getProtoFn(selfGame["game.model.user.Player"], 36);
  7191. const PSD_0 = getProtoFn(selfGame["game.model.user.shop.PlayerShopData"], 0);
  7192. const IM_0 = getProtoFn(selfGame["haxe.ds.IntMap"], 0);
  7193. const PSDE_4 = getProtoFn(selfGame["game.model.user.shop.PlayerShopDataEntry"], 4);
  7194.  
  7195. const player = Game.GameModel[instance]().A;
  7196. const shop = player[P_36][PSD_0][IM_0][1038][PSDE_4];
  7197. const shopPopup = new selfGame["game.mechanics.brawl.mediator.BrawlShopPopupMediator"](player, shop)
  7198. shopPopup.open(new selfGame["game.mediator.gui.popup.PopupStashEventParams"])
  7199. }
  7200.  
  7201. /**
  7202. * Returns all stores from game data
  7203. *
  7204. * Возвращает все магазины из данных игры
  7205. */
  7206. this.getShops = () => {
  7207. const instance = getFnP(Game.GameModel, 'get_instance')
  7208. const P_36 = getProtoFn(selfGame["game.model.user.Player"], 36);
  7209. const PSD_0 = getProtoFn(selfGame["game.model.user.shop.PlayerShopData"], 0);
  7210. const IM_0 = getProtoFn(selfGame["haxe.ds.IntMap"], 0);
  7211.  
  7212. const player = Game.GameModel[instance]().A;
  7213. return player[P_36][PSD_0][IM_0];
  7214. }
  7215.  
  7216. /**
  7217. * Returns the store from the game data by ID
  7218. *
  7219. * Возвращает магазин из данных игры по идетификатору
  7220. */
  7221. this.getShop = (id) => {
  7222. const PSDE_4 = getProtoFn(selfGame["game.model.user.shop.PlayerShopDataEntry"], 4);
  7223. const shops = this.getShops();
  7224. const shop = shops[id]?.[PSDE_4];
  7225. return shop;
  7226. }
  7227.  
  7228. /**
  7229. * Change island map
  7230. *
  7231. * Сменить карту острова
  7232. */
  7233. this.changeIslandMap = (mapId = 2) => {
  7234. const GameInst = getFnP(selfGame['Game'], 'get_instance');
  7235. const GM_0 = getProtoFn(Game.GameModel, 0);
  7236. const P_59 = getProtoFn(selfGame["game.model.user.Player"], 60);
  7237. const PSAD_31 = getProtoFn(selfGame['game.mechanics.season_adventure.model.PlayerSeasonAdventureData'], 31);
  7238. const Player = Game.GameModel[GameInst]()[GM_0];
  7239. Player[P_59][PSAD_31]({ id: mapId, seasonAdventure: { id: mapId, startDate: 1701914400, endDate: 1709690400, closed: false } });
  7240.  
  7241. const GN_15 = getProtoFn(selfGame["game.screen.navigator.GameNavigator"], 17)
  7242. const navigator = getF(selfGame['Game'], "get_navigator");
  7243. selfGame['Game'][GameInst]()[navigator]()[GN_15](new selfGame["game.mediator.gui.popup.PopupStashEventParams"]);
  7244. }
  7245.  
  7246. /**
  7247. * Game library availability tracker
  7248. *
  7249. * Отслеживание доступности игровой библиотеки
  7250. */
  7251. function checkLibLoad() {
  7252. timeout = setTimeout(() => {
  7253. if (Game.GameModel) {
  7254. changeLib();
  7255. } else {
  7256. checkLibLoad();
  7257. }
  7258. }, 100)
  7259. }
  7260.  
  7261. /**
  7262. * Game library data spoofing
  7263. *
  7264. * Подмена данных игровой библиотеки
  7265. */
  7266. function changeLib() {
  7267. console.log('lib connect');
  7268. const originalStartFunc = Game.GameModel.prototype.start;
  7269. Game.GameModel.prototype.start = function (a, b, c) {
  7270. self.libGame = b.raw;
  7271. self.doneLibLoad(self.libGame);
  7272. try {
  7273. const levels = b.raw.seasonAdventure.level;
  7274. for (const id in levels) {
  7275. const level = levels[id];
  7276. level.clientData.graphics.fogged = level.clientData.graphics.visible
  7277. }
  7278. const adv = b.raw.seasonAdventure.list[1];
  7279. adv.clientData.asset = 'dialog_season_adventure_tiles';
  7280. } catch (e) {
  7281. console.warn(e);
  7282. }
  7283. originalStartFunc.call(this, a, b, c);
  7284. }
  7285. }
  7286.  
  7287. this.LibLoad = function() {
  7288. return new Promise((e) => {
  7289. this.doneLibLoad = e;
  7290. });
  7291. }
  7292.  
  7293. /**
  7294. * Returns the value of a language constant
  7295. *
  7296. * Возвращает значение языковой константы
  7297. * @param {*} langConst language constant // языковая константа
  7298. * @returns
  7299. */
  7300. this.translate = function (langConst) {
  7301. return Game.Translate.translate(langConst);
  7302. }
  7303.  
  7304. connectGame();
  7305. checkLibLoad();
  7306. }
  7307.  
  7308. /**
  7309. * Auto collection of gifts
  7310. *
  7311. * Автосбор подарков
  7312. */
  7313. function getAutoGifts() {
  7314. // c3ltYm9scyB0aGF0IG1lYW4gbm90aGluZw==
  7315. let valName = 'giftSendIds_' + userInfo.id;
  7316.  
  7317. if (!localStorage['clearGift' + userInfo.id]) {
  7318. localStorage[valName] = '';
  7319. localStorage['clearGift' + userInfo.id] = '+';
  7320. }
  7321.  
  7322. if (!localStorage[valName]) {
  7323. localStorage[valName] = '';
  7324. }
  7325.  
  7326. const giftsAPI = new ZingerYWebsiteAPI('getGifts.php', arguments);
  7327. /**
  7328. * Submit a request to receive gift codes
  7329. *
  7330. * Отправка запроса для получения кодов подарков
  7331. */
  7332. giftsAPI.request().then((data) => {
  7333. let freebieCheckCalls = {
  7334. calls: [],
  7335. };
  7336. data.forEach((giftId, n) => {
  7337. if (localStorage[valName].includes(giftId)) return;
  7338. freebieCheckCalls.calls.push({
  7339. name: 'registration',
  7340. args: {
  7341. user: { referrer: {} },
  7342. giftId,
  7343. },
  7344. context: {
  7345. actionTs: Math.floor(performance.now()),
  7346. cookie: window?.NXAppInfo?.session_id || null,
  7347. },
  7348. ident: giftId,
  7349. });
  7350. });
  7351.  
  7352. if (!freebieCheckCalls.calls.length) {
  7353. return;
  7354. }
  7355.  
  7356. send(JSON.stringify(freebieCheckCalls), (e) => {
  7357. let countGetGifts = 0;
  7358. const gifts = [];
  7359. for (check of e.results) {
  7360. gifts.push(check.ident);
  7361. if (check.result.response != null) {
  7362. countGetGifts++;
  7363. }
  7364. }
  7365. const saveGifts = localStorage[valName].split(';');
  7366. localStorage[valName] = [...saveGifts, ...gifts].slice(-50).join(';');
  7367. console.log(`${I18N('GIFTS')}: ${countGetGifts}`);
  7368. });
  7369. });
  7370. }
  7371.  
  7372. /**
  7373. * To fill the kills in the Forge of Souls
  7374. *
  7375. * Набить килов в горниле душ
  7376. */
  7377. async function bossRatingEvent() {
  7378. const topGet = await Send(JSON.stringify({ calls: [{ name: "topGet", args: { type: "bossRatingTop", extraId: 0 }, ident: "body" }] }));
  7379. if (!topGet || !topGet.results[0].result.response[0]) {
  7380. setProgress(`${I18N('EVENT')} ${I18N('NOT_AVAILABLE')}`, true);
  7381. return;
  7382. }
  7383. const replayId = topGet.results[0].result.response[0].userData.replayId;
  7384. const result = await Send(JSON.stringify({
  7385. calls: [
  7386. { name: "battleGetReplay", args: { id: replayId }, ident: "battleGetReplay" },
  7387. { name: "heroGetAll", args: {}, ident: "heroGetAll" },
  7388. { name: "pet_getAll", args: {}, ident: "pet_getAll" },
  7389. { name: "offerGetAll", args: {}, ident: "offerGetAll" }
  7390. ]
  7391. }));
  7392. const bossEventInfo = result.results[3].result.response.find(e => e.offerType == "bossEvent");
  7393. if (!bossEventInfo) {
  7394. setProgress(`${I18N('EVENT')} ${I18N('NOT_AVAILABLE')}`, true);
  7395. return;
  7396. }
  7397. const usedHeroes = bossEventInfo.progress.usedHeroes;
  7398. const party = Object.values(result.results[0].result.response.replay.attackers);
  7399. const availableHeroes = Object.values(result.results[1].result.response).map(e => e.id);
  7400. const availablePets = Object.values(result.results[2].result.response).map(e => e.id);
  7401. const calls = [];
  7402. /**
  7403. * First pack
  7404. *
  7405. * Первая пачка
  7406. */
  7407. const args = {
  7408. heroes: [],
  7409. favor: {}
  7410. }
  7411. for (let hero of party) {
  7412. if (hero.id >= 6000 && availablePets.includes(hero.id)) {
  7413. args.pet = hero.id;
  7414. continue;
  7415. }
  7416. if (!availableHeroes.includes(hero.id) || usedHeroes.includes(hero.id)) {
  7417. continue;
  7418. }
  7419. args.heroes.push(hero.id);
  7420. if (hero.favorPetId) {
  7421. args.favor[hero.id] = hero.favorPetId;
  7422. }
  7423. }
  7424. if (args.heroes.length) {
  7425. calls.push({
  7426. name: "bossRatingEvent_startBattle",
  7427. args,
  7428. ident: "body_0"
  7429. });
  7430. }
  7431. /**
  7432. * Other packs
  7433. *
  7434. * Другие пачки
  7435. */
  7436. let heroes = [];
  7437. let count = 1;
  7438. while (heroId = availableHeroes.pop()) {
  7439. if (args.heroes.includes(heroId) || usedHeroes.includes(heroId)) {
  7440. continue;
  7441. }
  7442. heroes.push(heroId);
  7443. if (heroes.length == 5) {
  7444. calls.push({
  7445. name: "bossRatingEvent_startBattle",
  7446. args: {
  7447. heroes: [...heroes],
  7448. pet: availablePets[Math.floor(Math.random() * availablePets.length)]
  7449. },
  7450. ident: "body_" + count
  7451. });
  7452. heroes = [];
  7453. count++;
  7454. }
  7455. }
  7456.  
  7457. if (!calls.length) {
  7458. setProgress(`${I18N('NO_HEROES')}`, true);
  7459. return;
  7460. }
  7461.  
  7462. const resultBattles = await Send(JSON.stringify({ calls }));
  7463. console.log(resultBattles);
  7464. rewardBossRatingEvent();
  7465. }
  7466.  
  7467. /**
  7468. * Collecting Rewards from the Forge of Souls
  7469. *
  7470. * Сбор награды из Горнила Душ
  7471. */
  7472. function rewardBossRatingEvent() {
  7473. let rewardBossRatingCall = '{"calls":[{"name":"offerGetAll","args":{},"ident":"offerGetAll"}]}';
  7474. send(rewardBossRatingCall, function (data) {
  7475. let bossEventInfo = data.results[0].result.response.find(e => e.offerType == "bossEvent");
  7476. if (!bossEventInfo) {
  7477. setProgress(`${I18N('EVENT')} ${I18N('NOT_AVAILABLE')}`, true);
  7478. return;
  7479. }
  7480.  
  7481. let farmedChests = bossEventInfo.progress.farmedChests;
  7482. let score = bossEventInfo.progress.score;
  7483. setProgress(`${I18N('DAMAGE_AMOUNT')}: ${score}`);
  7484. let revard = bossEventInfo.reward;
  7485.  
  7486. let getRewardCall = {
  7487. calls: []
  7488. }
  7489.  
  7490. let count = 0;
  7491. for (let i = 1; i < 10; i++) {
  7492. if (farmedChests.includes(i)) {
  7493. continue;
  7494. }
  7495. if (score < revard[i].score) {
  7496. break;
  7497. }
  7498. getRewardCall.calls.push({
  7499. name: "bossRatingEvent_getReward",
  7500. args: {
  7501. rewardId: i
  7502. },
  7503. ident: "body_" + i
  7504. });
  7505. count++;
  7506. }
  7507. if (!count) {
  7508. setProgress(`${I18N('NOTHING_TO_COLLECT')}`, true);
  7509. return;
  7510. }
  7511.  
  7512. send(JSON.stringify(getRewardCall), e => {
  7513. console.log(e);
  7514. setProgress(`${I18N('COLLECTED')} ${e?.results?.length} ${I18N('REWARD')}`, true);
  7515. });
  7516. });
  7517. }
  7518.  
  7519. /**
  7520. * Collect Easter eggs and event rewards
  7521. *
  7522. * Собрать пасхалки и награды событий
  7523. */
  7524. function offerFarmAllReward() {
  7525. const offerGetAllCall = '{"calls":[{"name":"offerGetAll","args":{},"ident":"offerGetAll"}]}';
  7526. return Send(offerGetAllCall).then((data) => {
  7527. const offerGetAll = data.results[0].result.response.filter(e => e.type == "reward" && !e?.freeRewardObtained && e.reward);
  7528. if (!offerGetAll.length) {
  7529. setProgress(`${I18N('NOTHING_TO_COLLECT')}`, true);
  7530. return;
  7531. }
  7532.  
  7533. const calls = [];
  7534. for (let reward of offerGetAll) {
  7535. calls.push({
  7536. name: "offerFarmReward",
  7537. args: {
  7538. offerId: reward.id
  7539. },
  7540. ident: "offerFarmReward_" + reward.id
  7541. });
  7542. }
  7543.  
  7544. return Send(JSON.stringify({ calls })).then(e => {
  7545. console.log(e);
  7546. setProgress(`${I18N('COLLECTED')} ${e?.results?.length} ${I18N('REWARD')}`, true);
  7547. });
  7548. });
  7549. }
  7550.  
  7551. /**
  7552. * Assemble Outland
  7553. *
  7554. * Собрать запределье
  7555. */
  7556. function getOutland() {
  7557. return new Promise(function (resolve, reject) {
  7558. send('{"calls":[{"name":"bossGetAll","args":{},"ident":"bossGetAll"}]}', e => {
  7559. let bosses = e.results[0].result.response;
  7560.  
  7561. let bossRaidOpenChestCall = {
  7562. calls: []
  7563. };
  7564.  
  7565. for (let boss of bosses) {
  7566. if (boss.mayRaid) {
  7567. bossRaidOpenChestCall.calls.push({
  7568. name: "bossRaid",
  7569. args: {
  7570. bossId: boss.id
  7571. },
  7572. ident: "bossRaid_" + boss.id
  7573. });
  7574. bossRaidOpenChestCall.calls.push({
  7575. name: "bossOpenChest",
  7576. args: {
  7577. bossId: boss.id,
  7578. amount: 1,
  7579. starmoney: 0
  7580. },
  7581. ident: "bossOpenChest_" + boss.id
  7582. });
  7583. } else if (boss.chestId == 1) {
  7584. bossRaidOpenChestCall.calls.push({
  7585. name: "bossOpenChest",
  7586. args: {
  7587. bossId: boss.id,
  7588. amount: 1,
  7589. starmoney: 0
  7590. },
  7591. ident: "bossOpenChest_" + boss.id
  7592. });
  7593. }
  7594. }
  7595.  
  7596. if (!bossRaidOpenChestCall.calls.length) {
  7597. setProgress(`${I18N('OUTLAND')} ${I18N('NOTHING_TO_COLLECT')}`, true);
  7598. resolve();
  7599. return;
  7600. }
  7601.  
  7602. send(JSON.stringify(bossRaidOpenChestCall), e => {
  7603. setProgress(`${I18N('OUTLAND')} ${I18N('COLLECTED')}`, true);
  7604. resolve();
  7605. });
  7606. });
  7607. });
  7608. }
  7609.  
  7610. /**
  7611. * Collect all rewards
  7612. *
  7613. * Собрать все награды
  7614. */
  7615. function questAllFarm() {
  7616. return new Promise(function (resolve, reject) {
  7617. let questGetAllCall = {
  7618. calls: [{
  7619. name: "questGetAll",
  7620. args: {},
  7621. ident: "body"
  7622. }]
  7623. }
  7624. send(JSON.stringify(questGetAllCall), function (data) {
  7625. let questGetAll = data.results[0].result.response;
  7626. const questAllFarmCall = {
  7627. calls: []
  7628. }
  7629. let number = 0;
  7630. for (let quest of questGetAll) {
  7631. if (quest.id < 1e6 && quest.state == 2) {
  7632. questAllFarmCall.calls.push({
  7633. name: "questFarm",
  7634. args: {
  7635. questId: quest.id
  7636. },
  7637. ident: `group_${number}_body`
  7638. });
  7639. number++;
  7640. }
  7641. }
  7642.  
  7643. if (!questAllFarmCall.calls.length) {
  7644. setProgress(`${I18N('COLLECTED')} ${number} ${I18N('REWARD')}`, true);
  7645. resolve();
  7646. return;
  7647. }
  7648.  
  7649. send(JSON.stringify(questAllFarmCall), function (res) {
  7650. console.log(res);
  7651. setProgress(`${I18N('COLLECTED')} ${number} ${I18N('REWARD')}`, true);
  7652. resolve();
  7653. });
  7654. });
  7655. })
  7656. }
  7657.  
  7658. /**
  7659. * Mission auto repeat
  7660. *
  7661. * Автоповтор миссии
  7662. * isStopSendMission = false;
  7663. * isSendsMission = true;
  7664. **/
  7665. this.sendsMission = async function (param) {
  7666. if (isStopSendMission) {
  7667. isSendsMission = false;
  7668. console.log(I18N('STOPPED'));
  7669. setProgress('');
  7670. await popup.confirm(`${I18N('STOPPED')}<br>${I18N('REPETITIONS')}: ${param.count}`, [{
  7671. msg: 'Ok',
  7672. result: true
  7673. }, ])
  7674. return;
  7675. }
  7676. lastMissionBattleStart = Date.now();
  7677. let missionStartCall = {
  7678. "calls": [{
  7679. "name": "missionStart",
  7680. "args": lastMissionStart,
  7681. "ident": "body"
  7682. }]
  7683. }
  7684. /**
  7685. * Mission Request
  7686. *
  7687. * Запрос на выполнение мисии
  7688. */
  7689. SendRequest(JSON.stringify(missionStartCall), async e => {
  7690. if (e['error']) {
  7691. isSendsMission = false;
  7692. console.log(e['error']);
  7693. setProgress('');
  7694. let msg = e['error'].name + ' ' + e['error'].description + `<br>${I18N('REPETITIONS')}: ${param.count}`;
  7695. await popup.confirm(msg, [
  7696. {msg: 'Ok', result: true},
  7697. ])
  7698. return;
  7699. }
  7700. /**
  7701. * Mission data calculation
  7702. *
  7703. * Расчет данных мисии
  7704. */
  7705. BattleCalc(e.results[0].result.response, 'get_tower', async r => {
  7706. /** missionTimer */
  7707. let timer = getTimer(r.battleTime) + 5;
  7708. const period = Math.ceil((Date.now() - lastMissionBattleStart) / 1000);
  7709. if (period < timer) {
  7710. timer = timer - period;
  7711. await countdownTimer(timer, `${I18N('MISSIONS_PASSED')}: ${param.count}`);
  7712. }
  7713.  
  7714. let missionEndCall = {
  7715. "calls": [{
  7716. "name": "missionEnd",
  7717. "args": {
  7718. "id": param.id,
  7719. "result": r.result,
  7720. "progress": r.progress
  7721. },
  7722. "ident": "body"
  7723. }]
  7724. }
  7725. /**
  7726. * Mission Completion Request
  7727. *
  7728. * Запрос на завершение миссии
  7729. */
  7730. SendRequest(JSON.stringify(missionEndCall), async (e) => {
  7731. if (e['error']) {
  7732. isSendsMission = false;
  7733. console.log(e['error']);
  7734. setProgress('');
  7735. let msg = e['error'].name + ' ' + e['error'].description + `<br>${I18N('REPETITIONS')}: ${param.count}`;
  7736. await popup.confirm(msg, [
  7737. {msg: 'Ok', result: true},
  7738. ])
  7739. return;
  7740. }
  7741. r = e.results[0].result.response;
  7742. if (r['error']) {
  7743. isSendsMission = false;
  7744. console.log(r['error']);
  7745. setProgress('');
  7746. await popup.confirm(`<br>${I18N('REPETITIONS')}: ${param.count}` + ' 3 ' + r['error'], [
  7747. {msg: 'Ok', result: true},
  7748. ])
  7749. return;
  7750. }
  7751.  
  7752. param.count++;
  7753. setProgress(`${I18N('MISSIONS_PASSED')}: ${param.count} (${I18N('STOP')})`, false, () => {
  7754. isStopSendMission = true;
  7755. });
  7756. setTimeout(sendsMission, 1, param);
  7757. });
  7758. })
  7759. });
  7760. }
  7761.  
  7762. /**
  7763. * Opening of russian dolls
  7764. *
  7765. * Открытие матрешек
  7766. */
  7767. async function openRussianDolls(libId, amount) {
  7768. let sum = 0;
  7769. const sumResult = {};
  7770. let count = 0;
  7771.  
  7772. while (amount) {
  7773. sum += amount;
  7774. setProgress(`${I18N('TOTAL_OPEN')} ${sum}`);
  7775. const calls = [
  7776. {
  7777. name: 'consumableUseLootBox',
  7778. args: { libId, amount },
  7779. ident: 'body',
  7780. },
  7781. ];
  7782. const response = await Send(JSON.stringify({ calls })).then((e) => e.results[0].result.response);
  7783. let [countLootBox, result] = Object.entries(response).pop();
  7784. count += +countLootBox;
  7785. let newCount = 0;
  7786.  
  7787. if (result?.consumable && result.consumable[libId]) {
  7788. newCount = result.consumable[libId];
  7789. delete result.consumable[libId];
  7790. }
  7791.  
  7792. mergeItemsObj(sumResult, result);
  7793. amount = newCount;
  7794. }
  7795.  
  7796. setProgress(`${I18N('TOTAL_OPEN')} ${sum}`, 5000);
  7797. return [count, sumResult];
  7798. }
  7799.  
  7800. function mergeItemsObj(obj1, obj2) {
  7801. for (const key in obj2) {
  7802. if (obj1[key]) {
  7803. if (typeof obj1[key] == 'object') {
  7804. for (const innerKey in obj2[key]) {
  7805. obj1[key][innerKey] = (obj1[key][innerKey] || 0) + obj2[key][innerKey];
  7806. }
  7807. } else {
  7808. obj1[key] += obj2[key] || 0;
  7809. }
  7810. } else {
  7811. obj1[key] = obj2[key];
  7812. }
  7813. }
  7814.  
  7815. return obj1;
  7816. }
  7817.  
  7818. /**
  7819. * Collect all mail, except letters with energy and charges of the portal
  7820. *
  7821. * Собрать всю почту, кроме писем с энергией и зарядами портала
  7822. */
  7823. function mailGetAll() {
  7824. const getMailInfo = '{"calls":[{"name":"mailGetAll","args":{},"ident":"body"}]}';
  7825.  
  7826. return Send(getMailInfo).then(dataMail => {
  7827. const letters = dataMail.results[0].result.response.letters;
  7828. const letterIds = lettersFilter(letters);
  7829. if (!letterIds.length) {
  7830. setProgress(I18N('NOTHING_TO_COLLECT'), true);
  7831. return;
  7832. }
  7833.  
  7834. const calls = [
  7835. { name: "mailFarm", args: { letterIds }, ident: "body" }
  7836. ];
  7837.  
  7838. return Send(JSON.stringify({ calls })).then(res => {
  7839. const lettersIds = res.results[0].result.response;
  7840. if (lettersIds) {
  7841. const countLetters = Object.keys(lettersIds).length;
  7842. setProgress(`${I18N('RECEIVED')} ${countLetters} ${I18N('LETTERS')}`, true);
  7843. }
  7844. });
  7845. });
  7846. }
  7847.  
  7848. /**
  7849. * Filters received emails
  7850. *
  7851. * Фильтрует получаемые письма
  7852. */
  7853. function lettersFilter(letters) {
  7854. const lettersIds = [];
  7855. for (let l in letters) {
  7856. letter = letters[l];
  7857. const reward = letter?.reward;
  7858. if (!reward || !Object.keys(reward).length) {
  7859. continue;
  7860. }
  7861. /**
  7862. * Mail Collection Exceptions
  7863. *
  7864. * Исключения на сбор писем
  7865. */
  7866. const isFarmLetter = !(
  7867. /** Portals // сферы портала */
  7868. (reward?.refillable ? reward.refillable[45] : false) ||
  7869. /** Energy // энергия */
  7870. (reward?.stamina ? reward.stamina : false) ||
  7871. /** accelerating energy gain // ускорение набора энергии */
  7872. (reward?.buff ? true : false) ||
  7873. /** VIP Points // вип очки */
  7874. (reward?.vipPoints ? reward.vipPoints : false) ||
  7875. /** souls of heroes // душы героев */
  7876. (reward?.fragmentHero ? true : false) ||
  7877. /** heroes // герои */
  7878. (reward?.bundleHeroReward ? true : false)
  7879. );
  7880. if (isFarmLetter) {
  7881. lettersIds.push(~~letter.id);
  7882. continue;
  7883. }
  7884. /**
  7885. * Если до окончания годности письма менее 24 часов,
  7886. * то оно собирается не смотря на исключения
  7887. */
  7888. const availableUntil = +letter?.availableUntil;
  7889. if (availableUntil) {
  7890. const maxTimeLeft = 24 * 60 * 60 * 1000;
  7891. const timeLeft = (new Date(availableUntil * 1000) - new Date())
  7892. console.log('Time left:', timeLeft)
  7893. if (timeLeft < maxTimeLeft) {
  7894. lettersIds.push(~~letter.id);
  7895. continue;
  7896. }
  7897. }
  7898. }
  7899. return lettersIds;
  7900. }
  7901.  
  7902. /**
  7903. * Displaying information about the areas of the portal and attempts on the VG
  7904. *
  7905. * Отображение информации о сферах портала и попытках на ВГ
  7906. */
  7907. async function justInfo() {
  7908. return new Promise(async (resolve, reject) => {
  7909. const calls = [{
  7910. name: "userGetInfo",
  7911. args: {},
  7912. ident: "userGetInfo"
  7913. },
  7914. {
  7915. name: "clanWarGetInfo",
  7916. args: {},
  7917. ident: "clanWarGetInfo"
  7918. },
  7919. {
  7920. name: "titanArenaGetStatus",
  7921. args: {},
  7922. ident: "titanArenaGetStatus"
  7923. }];
  7924. const result = await Send(JSON.stringify({ calls }));
  7925. const infos = result.results;
  7926. const portalSphere = infos[0].result.response.refillable.find(n => n.id == 45);
  7927. const clanWarMyTries = infos[1].result.response?.myTries ?? 0;
  7928. const arePointsMax = infos[1].result.response?.arePointsMax;
  7929. const titansLevel = +(infos[2].result.response?.tier ?? 0);
  7930. const titansStatus = infos[2].result.response?.status; //peace_time || battle
  7931.  
  7932. const sanctuaryButton = buttons['goToSanctuary'].button;
  7933. const clanWarButton = buttons['goToClanWar'].button;
  7934. const titansArenaButton = buttons['testTitanArena'].button;
  7935.  
  7936. if (portalSphere.amount) {
  7937. sanctuaryButton.style.color = portalSphere.amount >= 3 ? 'red' : 'brown';
  7938. sanctuaryButton.title = `${I18N('SANCTUARY_TITLE')}\n${portalSphere.amount} ${I18N('PORTALS')}`;
  7939. } else {
  7940. sanctuaryButton.style.color = '';
  7941. sanctuaryButton.title = I18N('SANCTUARY_TITLE');
  7942. }
  7943. if (clanWarMyTries && !arePointsMax) {
  7944. clanWarButton.style.color = 'red';
  7945. clanWarButton.title = `${I18N('GUILD_WAR_TITLE')}\n${clanWarMyTries}${I18N('ATTEMPTS')}`;
  7946. } else {
  7947. clanWarButton.style.color = '';
  7948. clanWarButton.title = I18N('GUILD_WAR_TITLE');
  7949. }
  7950.  
  7951. if (titansLevel < 7 && titansStatus == 'battle') {
  7952. const partColor = Math.floor(125 * titansLevel / 7);
  7953. titansArenaButton.style.color = `rgb(255,${partColor},${partColor})`;
  7954. titansArenaButton.title = `${I18N('TITAN_ARENA_TITLE')}\n${titansLevel} ${I18N('LEVEL')}`;
  7955. } else {
  7956. titansArenaButton.style.color = '';
  7957. titansArenaButton.title = I18N('TITAN_ARENA_TITLE');
  7958. }
  7959.  
  7960. const imgPortal =
  7961. 'data:image/gif;base64,R0lGODlhLwAvAHAAACH5BAEAAP8ALAAAAAAvAC8AhwAAABkQWgjF3krO3ghSjAhSzinF3u+tGWvO3s5rGSmE5gha7+/OWghSrWvmnClShCmUlAiE5u+MGe/W3mvvWmspUmvvGSnOWinOnCnOGWsZjErvnAiUlErvWmsIUkrvGQjOWgjOnAjOGUoZjM6MGe/OIWvv5q1KGSnv5mulGe/vWs7v3ozv3kqEGYxKGWuEWmtSKUrv3mNaCEpKUs7OWiml5ggxWmMpEAgZpRlaCO/35q1rGRkxKWtarSkZrRljKSkZhAjv3msIGRk6CEparQhjWq3v3kql3ozOGe/vnM6tGYytWu9rGWuEGYzO3kqE3gil5s6MWq3vnGvFnM7vWoxrGc5KGYyMWs6tWq2MGYzOnO+tWmvFWkqlWoxrWgAZhEqEWq2tWoytnIyt3krFnGul3mulWmulnEIpUkqlGUqlnK3OnK2MWs7OnClSrSmUte+tnGvFGYytGYzvWs5rWowpGa3O3u/OnErFWoyMnGuE3muEnEqEnIyMGYzOWs7OGe9r3u9rWq3vWq1rWq1r3invWimlWu+t3q0pWq2t3u8pWu8p3q0p3invnCnvGe/vGa2tGa3vGa2tnK0pGe9rnK1rnCmlGe8pGe8pnK0pnGsZrSkp3msp3s7vGYzvnM7vnIzvGc6tnM5r3oxr3gilWs6t3owpWs4pWs4p3owp3s5rnIxrnAilGc4pGc4pnIwpnAgp3kop3s7O3u9KGe+MWoxKWoyM3kIIUgiUte+MnErFGc5KWowIGe9K3u9KWq3OWq1KWq1K3gjvWimEWu+M3q0IWq2M3u8IWu8I3q0I3gjvnAjvGa3OGa2MnK0IGe9KnK1KnCmEGe8IGe8InK0InEoZrSkI3msI3s6MnM5K3oxK3giEWs6M3owIWs4IWs4I3owI3s5KnIxKnAiEGc4IGc4InIwInAgI3koI3kJaCAgQKUIpEGtKUkJSKUIIECla7ylazmtahGta70pa70pahGtazkpazmtrWiExUkprUiljWikQKRkQCAAQCAAACAAAAAj/AP8JHEiwoMGDCBMqXMiwocODJlBIRBHDxMOLBmMEkSjAgICPE2Mw/OUH4z8TGz+agBIBCsuWUAQE0WLwzkAkKZZcnAilhk+fA1bUiEC0ZZABJOD8IyHhwJYDkpakafJQ4kooR5yw0LFihQ4WJhAMKCoARRYSTJgkUOInBZK2DiX2rGHEiI67eFcYATtAAVEoKEiQSFBFDs4UKbg0lGgAigIEeCNzrWvCxIChEcoy3dGiSoITTRQvnCLRrxOveI2McbKahevKJmooiKkFy4Gzg5tMMaMwitwIj/PqGPCugL0CT47ANhEjQg3Atg9IT5CiS4uEUcRIBH4EtREETuB9/xn/BUcBBbBXGGgpoPaBEid23EuXgvdBJhtQGFCwwA7eMgs0gEMDBJD3hR7KbRVbSwP8UcIWJNwjIRLXGZRAAhLVsIACR9y1whMNfNGAHgiUcUSBX8ADWwwKzCYADTSUcMA9ebwQmkFYMMFGhgu80x1XTxSAwxNdGWGCAiG6YQBzly3QkhYxlsDGP1cg4YBBaC0h1zsLPGHXCkfA00AZeu11hALl1VBZXwW0RAaMDGDxTxNdTGEQExJoiUINXCpwmhFOKJCcVmCdOR56MezXJhRvwFlCC2lcWVAUEjBxRobw9HhEXUYekWBlsoVoQEWyFbAAFPRIQQMDJcDQhRhYSv+QZ1kGcAnPYya4BhZYlb1TQ4iI+tVmBPpIQQWrMORxkKwSsEFrDaa+8xgCy1mmgLSHxtDXAhtGMIOxDKjgAkLM7iAAYD4VJ+0RAyAgVl++ikfAESxy62QB365awrjLyprAcxEY4FOmXEp7LbctjlfAAE1yGwEBYBirAgP8GtTUARIMM1QBPrVYQAHF9dgiml/Mexl/3DbAwxnHMqBExQVdLAEMjRXQgHOyydaibPCgqEDH3JrawDosUDExCTATZJuMJ0AAxRNXtLFFPD+P/DB58AC9wH4N4BMxDRPvkPRAbLx3AAlVMLBFCXeQgIaIKJKHQ9X8+forAetMsaoKB7j/MAhCL5j9VFNPJYBGiCGW18CtsvWIs5j7gLEGqyV81gxC6ZBQQgkSMEUCLQckMMLHNhcAD3B+8TdyA0PPACWrB8SH0BItyHAAAwdE4YILTSUww8cELwAyt7D4JSberkd5wA4neIFQE020sMPmJZBwAi0SJMBOA6WTXgAsDYDPOj7r3KNFy5WfkEBCKbTQBQzTM+By5wm4YAPr+LM+IIE27LPOFWswmgqqZ4UEXCEhLUjBGWbgAs3JD2OfWcc68GEDArCOAASwAfnWUYUwtIEKSVCBCiSgPuclpAlImMI9YNDAzeFuMEwQ2w3W4Q530PAGLthBFNqwghCKMAoF3MEB/xNihvr8Ix4sdCCrJja47CVAMFjAwid6eJcQWi8BO4jHQl6AGFjdwwUnOMF75CfCMpoxCTpAoxoZMBgs3qMh7ZODQFYYxgSMsQThCpcK0BiZJNxBCZ7zwhsbYqO3wCoe7AjjCaxAggNUcY94mcDa3qMECWSBHYN0CBfj0IQliEFCMFjkIulAAisUkBZYyB4USxAFCZnkH1xsgltSYCMYyACMpizghS7kOTZIKJMmeYEZzCCH6iCmBS1IRzpkcEsXVMGZMMgHJvfwyoLsYQ9nmMIUuDAFPIAhH8pUZjLbcY89rKKaC9nDFeLxy3vkYwbJTMcL0InOeOSjBVShJz2pqQvPfvrznwANKEMCAgA7';
  7962.  
  7963. setProgress('<img src="' + imgPortal + '" style="height: 25px;position: relative;top: 5px;"> ' + `${portalSphere.amount} </br> ${I18N('GUILD_WAR')}: ${clanWarMyTries}`, true);
  7964. resolve();
  7965. });
  7966. }
  7967.  
  7968. async function getDailyBonus() {
  7969. const dailyBonusInfo = await Send(JSON.stringify({
  7970. calls: [{
  7971. name: "dailyBonusGetInfo",
  7972. args: {},
  7973. ident: "body"
  7974. }]
  7975. })).then(e => e.results[0].result.response);
  7976. const { availableToday, availableVip, currentDay } = dailyBonusInfo;
  7977.  
  7978. if (!availableToday) {
  7979. console.log('Уже собрано');
  7980. return;
  7981. }
  7982.  
  7983. const currentVipPoints = +userInfo.vipPoints;
  7984. const dailyBonusStat = lib.getData('dailyBonusStatic');
  7985. const vipInfo = lib.getData('level').vip;
  7986. let currentVipLevel = 0;
  7987. for (let i in vipInfo) {
  7988. vipLvl = vipInfo[i];
  7989. if (currentVipPoints >= vipLvl.vipPoints) {
  7990. currentVipLevel = vipLvl.level;
  7991. }
  7992. }
  7993. const vipLevelDouble = dailyBonusStat[`${currentDay}_0_0`].vipLevelDouble;
  7994.  
  7995. const calls = [{
  7996. name: "dailyBonusFarm",
  7997. args: {
  7998. vip: availableVip && currentVipLevel >= vipLevelDouble ? 1 : 0
  7999. },
  8000. ident: "body"
  8001. }];
  8002.  
  8003. const result = await Send(JSON.stringify({ calls }));
  8004. if (result.error) {
  8005. console.error(result.error);
  8006. return;
  8007. }
  8008.  
  8009. const reward = result.results[0].result.response;
  8010. const type = Object.keys(reward).pop();
  8011. const itemId = Object.keys(reward[type]).pop();
  8012. const count = reward[type][itemId];
  8013. const itemName = cheats.translate(`LIB_${type.toUpperCase()}_NAME_${itemId}`);
  8014.  
  8015. console.log(`Ежедневная награда: Получено ${count} ${itemName}`, reward);
  8016. }
  8017.  
  8018. async function farmStamina(lootBoxId = 148) {
  8019. const lootBox = await Send('{"calls":[{"name":"inventoryGet","args":{},"ident":"inventoryGet"}]}')
  8020. .then(e => e.results[0].result.response.consumable[148]);
  8021.  
  8022. /** Добавить другие ящики */
  8023. /**
  8024. * 144 - медная шкатулка
  8025. * 145 - бронзовая шкатулка
  8026. * 148 - платиновая шкатулка
  8027. */
  8028. if (!lootBox) {
  8029. setProgress(I18N('NO_BOXES'), true);
  8030. return;
  8031. }
  8032.  
  8033. let maxFarmEnergy = getSaveVal('maxFarmEnergy', 100);
  8034. const result = await popup.confirm(I18N('OPEN_LOOTBOX', { lootBox }), [
  8035. { result: false, isClose: true },
  8036. { msg: I18N('BTN_YES'), result: true },
  8037. { msg: I18N('STAMINA'), isInput: true, default: maxFarmEnergy },
  8038. ]);
  8039. if (!+result) {
  8040. return;
  8041. }
  8042.  
  8043. if ((typeof result) !== 'boolean' && Number.parseInt(result)) {
  8044. maxFarmEnergy = +result;
  8045. setSaveVal('maxFarmEnergy', maxFarmEnergy);
  8046. } else {
  8047. maxFarmEnergy = 0;
  8048. }
  8049.  
  8050. let collectEnergy = 0;
  8051. for (let count = lootBox; count > 0; count--) {
  8052. const response = await Send('{"calls":[{"name":"consumableUseLootBox","args":{"libId":148,"amount":1},"ident":"body"}]}').then(
  8053. (e) => e.results[0].result.response
  8054. );
  8055. const result = Object.values(response).pop();
  8056. if ('stamina' in result) {
  8057. setProgress(`${I18N('OPEN')}: ${lootBox - count}/${lootBox} ${I18N('STAMINA')} +${result.stamina}<br>${I18N('STAMINA')}: ${collectEnergy}`, false);
  8058. console.log(`${ I18N('STAMINA') } + ${ result.stamina }`);
  8059. if (!maxFarmEnergy) {
  8060. return;
  8061. }
  8062. collectEnergy += +result.stamina;
  8063. if (collectEnergy >= maxFarmEnergy) {
  8064. console.log(`${I18N('STAMINA')} + ${ collectEnergy }`);
  8065. setProgress(`${I18N('STAMINA')} + ${ collectEnergy }`, false);
  8066. return;
  8067. }
  8068. } else {
  8069. setProgress(`${I18N('OPEN')}: ${lootBox - count}/${lootBox}<br>${I18N('STAMINA')}: ${collectEnergy}`, false);
  8070. console.log(result);
  8071. }
  8072. }
  8073.  
  8074. setProgress(I18N('BOXES_OVER'), true);
  8075. }
  8076.  
  8077. async function fillActive() {
  8078. const data = await Send(JSON.stringify({
  8079. calls: [{
  8080. name: "questGetAll",
  8081. args: {},
  8082. ident: "questGetAll"
  8083. }, {
  8084. name: "inventoryGet",
  8085. args: {},
  8086. ident: "inventoryGet"
  8087. }, {
  8088. name: "clanGetInfo",
  8089. args: {},
  8090. ident: "clanGetInfo"
  8091. }
  8092. ]
  8093. })).then(e => e.results.map(n => n.result.response));
  8094.  
  8095. const quests = data[0];
  8096. const inv = data[1];
  8097. const stat = data[2].stat;
  8098. const maxActive = 2000 - stat.todayItemsActivity;
  8099. if (maxActive <= 0) {
  8100. setProgress(I18N('NO_MORE_ACTIVITY'), true);
  8101. return;
  8102. }
  8103. let countGetActive = 0;
  8104. const quest = quests.find(e => e.id > 10046 && e.id < 10051);
  8105. if (quest) {
  8106. countGetActive = 1750 - quest.progress;
  8107. }
  8108. if (countGetActive <= 0) {
  8109. countGetActive = maxActive;
  8110. }
  8111. console.log(countGetActive);
  8112.  
  8113. countGetActive = +(await popup.confirm(I18N('EXCHANGE_ITEMS', { maxActive }), [
  8114. { result: false, isClose: true },
  8115. { msg: I18N('GET_ACTIVITY'), isInput: true, default: countGetActive.toString() },
  8116. ]));
  8117.  
  8118. if (!countGetActive) {
  8119. return;
  8120. }
  8121.  
  8122. if (countGetActive > maxActive) {
  8123. countGetActive = maxActive;
  8124. }
  8125.  
  8126. const items = lib.getData('inventoryItem');
  8127.  
  8128. let itemsInfo = [];
  8129. for (let type of ['gear', 'scroll']) {
  8130. for (let i in inv[type]) {
  8131. const v = items[type][i]?.enchantValue || 0;
  8132. itemsInfo.push({
  8133. id: i,
  8134. count: inv[type][i],
  8135. v,
  8136. type
  8137. })
  8138. }
  8139. const invType = 'fragment' + type.toLowerCase().charAt(0).toUpperCase() + type.slice(1);
  8140. for (let i in inv[invType]) {
  8141. const v = items[type][i]?.fragmentEnchantValue || 0;
  8142. itemsInfo.push({
  8143. id: i,
  8144. count: inv[invType][i],
  8145. v,
  8146. type: invType
  8147. })
  8148. }
  8149. }
  8150. itemsInfo = itemsInfo.filter(e => e.v < 4 && e.count > 200);
  8151. itemsInfo = itemsInfo.sort((a, b) => b.count - a.count);
  8152. console.log(itemsInfo);
  8153. const activeItem = itemsInfo.shift();
  8154. console.log(activeItem);
  8155. const countItem = Math.ceil(countGetActive / activeItem.v);
  8156. if (countItem > activeItem.count) {
  8157. setProgress(I18N('NOT_ENOUGH_ITEMS'), true);
  8158. console.log(activeItem);
  8159. return;
  8160. }
  8161.  
  8162. await Send(JSON.stringify({
  8163. calls: [{
  8164. name: "clanItemsForActivity",
  8165. args: {
  8166. items: {
  8167. [activeItem.type]: {
  8168. [activeItem.id]: countItem
  8169. }
  8170. }
  8171. },
  8172. ident: "body"
  8173. }]
  8174. })).then(e => {
  8175. /** TODO: Вывести потраченые предметы */
  8176. console.log(e);
  8177. setProgress(`${I18N('ACTIVITY_RECEIVED')}: ` + e.results[0].result.response, true);
  8178. });
  8179. }
  8180.  
  8181. async function buyHeroFragments() {
  8182. const result = await Send('{"calls":[{"name":"inventoryGet","args":{},"ident":"inventoryGet"},{"name":"shopGetAll","args":{},"ident":"shopGetAll"}]}')
  8183. .then(e => e.results.map(n => n.result.response));
  8184. const inv = result[0];
  8185. const shops = Object.values(result[1]).filter(shop => [4, 5, 6, 8, 9, 10, 17].includes(shop.id));
  8186. const calls = [];
  8187.  
  8188. for (let shop of shops) {
  8189. const slots = Object.values(shop.slots);
  8190. for (const slot of slots) {
  8191. /* Уже куплено */
  8192. if (slot.bought) {
  8193. continue;
  8194. }
  8195. /* Не душа героя */
  8196. if (!('fragmentHero' in slot.reward)) {
  8197. continue;
  8198. }
  8199. const coin = Object.keys(slot.cost).pop();
  8200. const coinId = Object.keys(slot.cost[coin]).pop();
  8201. const stock = inv[coin][coinId] || 0;
  8202. /* Не хватает на покупку */
  8203. if (slot.cost[coin][coinId] > stock) {
  8204. continue;
  8205. }
  8206. inv[coin][coinId] -= slot.cost[coin][coinId];
  8207. calls.push({
  8208. name: "shopBuy",
  8209. args: {
  8210. shopId: shop.id,
  8211. slot: slot.id,
  8212. cost: slot.cost,
  8213. reward: slot.reward,
  8214. },
  8215. ident: `shopBuy_${shop.id}_${slot.id}`,
  8216. })
  8217. }
  8218. }
  8219.  
  8220. if (!calls.length) {
  8221. setProgress(I18N('NO_PURCHASABLE_HERO_SOULS'), true);
  8222. return;
  8223. }
  8224.  
  8225. const bought = await Send(JSON.stringify({ calls })).then(e => e.results.map(n => n.result.response));
  8226. if (!bought) {
  8227. console.log('что-то пошло не так')
  8228. return;
  8229. }
  8230.  
  8231. let countHeroSouls = 0;
  8232. for (const buy of bought) {
  8233. countHeroSouls += +Object.values(Object.values(buy).pop()).pop();
  8234. }
  8235. console.log(countHeroSouls, bought, calls);
  8236. setProgress(I18N('PURCHASED_HERO_SOULS', { countHeroSouls }), true);
  8237. }
  8238.  
  8239. /** Открыть платные сундуки в Запределье за 90 */
  8240. async function bossOpenChestPay() {
  8241. const callsNames = ['userGetInfo', 'bossGetAll', 'specialOffer_getAll', 'getTime'];
  8242. const info = await Send({ calls: callsNames.map((name) => ({ name, args: {}, ident: name })) }).then((e) =>
  8243. e.results.map((n) => n.result.response)
  8244. );
  8245.  
  8246. const user = info[0];
  8247. const boses = info[1];
  8248. const offers = info[2];
  8249. const time = info[3];
  8250.  
  8251. const discountOffer = offers.find((e) => e.offerType == 'costReplaceOutlandChest');
  8252.  
  8253. let discount = 1;
  8254. if (discountOffer && discountOffer.endTime > time) {
  8255. discount = 1 - discountOffer.offerData.outlandChest.discountPercent / 100;
  8256. }
  8257.  
  8258. cost9chests = 540 * discount;
  8259. cost18chests = 1740 * discount;
  8260. costFirstChest = 90 * discount;
  8261. costSecondChest = 200 * discount;
  8262.  
  8263. const currentStarMoney = user.starMoney;
  8264. if (currentStarMoney < cost9chests) {
  8265. setProgress('Недостаточно изюма, нужно ' + cost9chests + ' у Вас ' + currentStarMoney, true);
  8266. return;
  8267. }
  8268.  
  8269. const imgEmerald =
  8270. "<img style='position: relative;top: 3px;' src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAXCAYAAAD+4+QTAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAY8SURBVEhLpVV5bFVlFv/d7a19W3tfN1pKabGFAm3Rlg4toAWRiH+AioiaqAkaE42NycRR0ZnomJnJYHAJERGNyx/GJYoboo2igKVSMUUKreW1pRvUvr7XvvXe9+7qeW1nGJaJycwvObnny/fl/L7zO+c7l8EV0LAKzA+H83lAFAC/BeDJN2gnc5yd/WaQ8Q0NCCnAANkU+ZfjIpKqJWBOd4EDbHagueBPb1tWuesi9Rqn86zJZDbAMTp4xoSFzMaa4FVe6fra3bbzQbYN6A8Cmrz0qoBx8gzMmaj/QfKHWyxs+4e1DiC78M9v5TTn1RtbVH+kMWlJCCad100VOmQiUWFnNLg4HW42QeYEl3KnIiP5Bzu/dr27o0UistD48k2d8rF9Sib9GZKaejAnOmrs2/6e3VR3q7idF41GWVA41uQQ1RMY00ZJrChcrAYvx8HHaSjil8LLilCY98BORylBKlWQHhjzfvfFnuTfPn1O+xFolzM7s5nMI80rSl7qib8ykRNcWyaUosBWgnN6BL3pHuRwucjmnBTUCjfHwElkNiaNPHYr0mYCKnMeE/r3OC2NQiZZheHsfQ9Vu1uAM+eBIX2W5Nqsh/ewtxlrhl75NtUviDpwq+s+NOXWwWFhKKCd6iCQVByV2qSb0wEo5PvhY9YikGrH3uAdiBtBDIdVVAvlyfjBOffuesTcDxySqD3mUxaOPLZ6aktAOS/kqHaYigN7gnsxMGnDAuEuiPw6ymIt3MwaZFFQB7MeTmYjPLSWjTTCioQ5XCOMJIPeoInD/SNOviy6heLmALkckRTyf3xLbtQ8k6sdOodcxoocMoXU9JoFdF8VESMMiWRJmykyedqXTInaQJnOTtYDcJtZ+DXkRSrOou1cCoHx4LptL0nLgYU8kWhwlFgrNV2wFnEmVAr+w9gUzkwQic2DoNmLYe0QgkYXIuYg4uYYosYQJs1fMGkEpqWzUVucDh9E37gCIWFgvY9FcbniEipii6hbwZVilP0kXB/jysrrPLqU3yDG0JzXhA3OjWgsXo8UG6XbR6AxScqJjJHo/gmY0+9FIOn80I0UkukQFohJNFZmwV/uhosX2j59KPuF8JgS5CI3wHB90RUdKL12pMs7Z3VvfH6WyOajPt+Deb7FRDCBmNmNpNmPhHEWCW0IMXUQaTVEtVPhseYTZRCBeB86h8+hY0yDodsHfny+4NETB7JOLN74TXqmu1Yu4ixHuj3ii0/eaatx7RgY/NYKtR2tm+6B7lbwTGg3bDQ06MLTcsoJettR4DqaC8+u/gfe6HwZOzuGQU8JDR5f1B2+6uHWp8RPSjfsj5/dDyMzfIAj3bqSK8bGW579ECPWXRViHTijDK2BPojcPCxkbXCZflh1H5ISkCCSWJxI8jcjmErhnaHh6fdzdbZTd0aKd7Q+5T/gqj6VyBBkwmfG0QySkkHDJq19dDrgvP3GQq/Pt6h/8mesLqqFz+6DRq0qWkR4uGzEYhrGJBktNdvQGfoJH490YwmNuwKt+LWvWubtAk6GlPHhfw/LCyQz0BXEZOaoLcDf1lAt2z1z5nIhlIsL0Csfo90sWDkHXDYXaq2VWFZShffOfoQc0qOIzT9wbGvpXxOYGgG6SdwLuJSE6mPT1ZNdUdM9fyi8YlnTEiHLc423GBPaFBSVQcrQqcMYrJrbjElVRUf8FIq57K4z/8x7rL9f7ymsb0vHz83GmsXlJJSlsXKhxn3w+YSyrC48vKB0zVbLYqHCUYEe5SekaRYznBuLvU1olwbBmvr4r/v4RzteN4761x+Wxg9dGPH/wkzhL8WRHkMvKo7j/sc/Swfir7ZT/WTYSapc6LwFhc4qSKwLEYHXoz/bnzv8dOw7+4ojyYkvLyfI4MokhNToSKZwYf+6u3e39P3y8XH6AeY5yxHiBcx11OA8rZO9qTdaNx9/n9KPyUdnOulKuFyui6GHAAkHpEDBptqauaKtcMySRBW3HH2Do1+9WbP9GXocVGj5okJfit8jATY06Dh+MBIyiwZrrylb4XXneO1BV9df7n/tMb0/0J17O9LJU7Nn/x+UrKvOyOq58dXtNz0Q2Luz+cUnrqe1q+qmyv8q9/+EypuXZrK2kdEwgW3R5pW/r8I0gN8AVk6uP7Y929oAAAAASUVORK5CYII='>";
  8271.  
  8272. if (currentStarMoney < cost9chests) {
  8273. setProgress(I18N('NOT_ENOUGH_EMERALDS_540', { currentStarMoney, imgEmerald }), true);
  8274. return;
  8275. }
  8276.  
  8277. const buttons = [{ result: false, isClose: true }];
  8278.  
  8279. if (currentStarMoney >= cost9chests) {
  8280. buttons.push({
  8281. msg: I18N('BUY_OUTLAND_BTN', { count: 9, countEmerald: cost9chests, imgEmerald }),
  8282. result: [costFirstChest, costFirstChest, 0],
  8283. });
  8284. }
  8285.  
  8286. if (currentStarMoney >= cost18chests) {
  8287. buttons.push({
  8288. msg: I18N('BUY_OUTLAND_BTN', { count: 18, countEmerald: cost18chests, imgEmerald }),
  8289. result: [costFirstChest, costFirstChest, 0, costSecondChest, costSecondChest, 0],
  8290. });
  8291. }
  8292.  
  8293. const answer = await popup.confirm(`<div style="margin-bottom: 15px;">${I18N('BUY_OUTLAND')}</div>`, buttons);
  8294.  
  8295. if (!answer) {
  8296. return;
  8297. }
  8298.  
  8299. const callBoss = [];
  8300. let n = 0;
  8301. for (let boss of boses) {
  8302. const bossId = boss.id;
  8303. if (boss.chestNum != 2) {
  8304. continue;
  8305. }
  8306. const calls = [];
  8307. for (const starmoney of answer) {
  8308. calls.push({
  8309. name: 'bossOpenChest',
  8310. args: {
  8311. amount: 1,
  8312. bossId,
  8313. starmoney,
  8314. },
  8315. ident: 'bossOpenChest_' + ++n,
  8316. });
  8317. }
  8318. callBoss.push(calls);
  8319. }
  8320.  
  8321. if (!callBoss.length) {
  8322. setProgress(I18N('CHESTS_NOT_AVAILABLE'), true);
  8323. return;
  8324. }
  8325.  
  8326. let count = 0;
  8327. let errors = 0;
  8328. for (const calls of callBoss) {
  8329. const result = await Send({ calls });
  8330. console.log(result);
  8331. if (result?.results) {
  8332. count += result.results.length;
  8333. } else {
  8334. errors++;
  8335. }
  8336. }
  8337.  
  8338. setProgress(`${I18N('OUTLAND_CHESTS_RECEIVED')}: ${count}`, true);
  8339. }
  8340.  
  8341. async function autoRaidAdventure() {
  8342. const calls = [
  8343. {
  8344. name: "userGetInfo",
  8345. args: {},
  8346. ident: "userGetInfo"
  8347. },
  8348. {
  8349. name: "adventure_raidGetInfo",
  8350. args: {},
  8351. ident: "adventure_raidGetInfo"
  8352. }
  8353. ];
  8354. const result = await Send(JSON.stringify({ calls }))
  8355. .then(e => e.results.map(n => n.result.response));
  8356.  
  8357. const portalSphere = result[0].refillable.find(n => n.id == 45);
  8358. const adventureRaid = Object.entries(result[1].raid).filter(e => e[1]).pop()
  8359. const adventureId = adventureRaid ? adventureRaid[0] : 0;
  8360.  
  8361. if (!portalSphere.amount || !adventureId) {
  8362. setProgress(I18N('RAID_NOT_AVAILABLE'), true);
  8363. return;
  8364. }
  8365.  
  8366. const countRaid = +(await popup.confirm(I18N('RAID_ADVENTURE', { adventureId }), [
  8367. { result: false, isClose: true },
  8368. { msg: I18N('RAID'), isInput: true, default: portalSphere.amount },
  8369. ]));
  8370.  
  8371. if (!countRaid) {
  8372. return;
  8373. }
  8374.  
  8375. if (countRaid > portalSphere.amount) {
  8376. countRaid = portalSphere.amount;
  8377. }
  8378.  
  8379. const resultRaid = await Send(JSON.stringify({
  8380. calls: [...Array(countRaid)].map((e, i) => ({
  8381. name: "adventure_raid",
  8382. args: {
  8383. adventureId
  8384. },
  8385. ident: `body_${i}`
  8386. }))
  8387. })).then(e => e.results.map(n => n.result.response));
  8388.  
  8389. if (!resultRaid.length) {
  8390. console.log(resultRaid);
  8391. setProgress(I18N('SOMETHING_WENT_WRONG'), true);
  8392. return;
  8393. }
  8394.  
  8395. console.log(resultRaid, adventureId, portalSphere.amount);
  8396. setProgress(I18N('ADVENTURE_COMPLETED', { adventureId, times: resultRaid.length }), true);
  8397. }
  8398.  
  8399. /** Вывести всю клановую статистику в консоль браузера */
  8400. async function clanStatistic() {
  8401. const copy = function (text) {
  8402. const copyTextarea = document.createElement("textarea");
  8403. copyTextarea.style.opacity = "0";
  8404. copyTextarea.textContent = text;
  8405. document.body.appendChild(copyTextarea);
  8406. copyTextarea.select();
  8407. document.execCommand("copy");
  8408. document.body.removeChild(copyTextarea);
  8409. delete copyTextarea;
  8410. }
  8411. const calls = [
  8412. { name: "clanGetInfo", args: {}, ident: "clanGetInfo" },
  8413. { name: "clanGetWeeklyStat", args: {}, ident: "clanGetWeeklyStat" },
  8414. { name: "clanGetLog", args: {}, ident: "clanGetLog" },
  8415. ];
  8416.  
  8417. const result = await Send(JSON.stringify({ calls }));
  8418.  
  8419. const dataClanInfo = result.results[0].result.response;
  8420. const dataClanStat = result.results[1].result.response;
  8421. const dataClanLog = result.results[2].result.response;
  8422.  
  8423. const membersStat = {};
  8424. for (let i = 0; i < dataClanStat.stat.length; i++) {
  8425. membersStat[dataClanStat.stat[i].id] = dataClanStat.stat[i];
  8426. }
  8427.  
  8428. const joinStat = {};
  8429. historyLog = dataClanLog.history;
  8430. for (let j in historyLog) {
  8431. his = historyLog[j];
  8432. if (his.event == 'join') {
  8433. joinStat[his.userId] = his.ctime;
  8434. }
  8435. }
  8436.  
  8437. const infoArr = [];
  8438. const members = dataClanInfo.clan.members;
  8439. for (let n in members) {
  8440. var member = [
  8441. n,
  8442. members[n].name,
  8443. members[n].level,
  8444. dataClanInfo.clan.warriors.includes(+n) ? 1 : 0,
  8445. (new Date(members[n].lastLoginTime * 1000)).toLocaleString().replace(',', ''),
  8446. joinStat[n] ? (new Date(joinStat[n] * 1000)).toLocaleString().replace(',', '') : '',
  8447. membersStat[n].activity.reverse().join('\t'),
  8448. membersStat[n].adventureStat.reverse().join('\t'),
  8449. membersStat[n].clanGifts.reverse().join('\t'),
  8450. membersStat[n].clanWarStat.reverse().join('\t'),
  8451. membersStat[n].dungeonActivity.reverse().join('\t'),
  8452. ];
  8453. infoArr.push(member);
  8454. }
  8455. const info = infoArr.sort((a, b) => (b[2] - a[2])).map((e) => e.join('\t')).join('\n');
  8456. console.log(info);
  8457. copy(info);
  8458. setProgress(I18N('CLAN_STAT_COPY'), true);
  8459. }
  8460.  
  8461. async function buyInStoreForGold() {
  8462. const result = await Send('{"calls":[{"name":"shopGetAll","args":{},"ident":"body"},{"name":"userGetInfo","args":{},"ident":"userGetInfo"}]}').then(e => e.results.map(n => n.result.response));
  8463. const shops = result[0];
  8464. const user = result[1];
  8465. let gold = user.gold;
  8466. const calls = [];
  8467. if (shops[17]) {
  8468. const slots = shops[17].slots;
  8469. for (let i = 1; i <= 2; i++) {
  8470. if (!slots[i].bought) {
  8471. const costGold = slots[i].cost.gold;
  8472. if ((gold - costGold) < 0) {
  8473. continue;
  8474. }
  8475. gold -= costGold;
  8476. calls.push({
  8477. name: "shopBuy",
  8478. args: {
  8479. shopId: 17,
  8480. slot: i,
  8481. cost: slots[i].cost,
  8482. reward: slots[i].reward,
  8483. },
  8484. ident: 'body_' + i,
  8485. })
  8486. }
  8487. }
  8488. }
  8489. const slots = shops[1].slots;
  8490. for (let i = 4; i <= 6; i++) {
  8491. if (!slots[i].bought && slots[i]?.cost?.gold) {
  8492. const costGold = slots[i].cost.gold;
  8493. if ((gold - costGold) < 0) {
  8494. continue;
  8495. }
  8496. gold -= costGold;
  8497. calls.push({
  8498. name: "shopBuy",
  8499. args: {
  8500. shopId: 1,
  8501. slot: i,
  8502. cost: slots[i].cost,
  8503. reward: slots[i].reward,
  8504. },
  8505. ident: 'body_' + i,
  8506. })
  8507. }
  8508. }
  8509.  
  8510. if (!calls.length) {
  8511. setProgress(I18N('NOTHING_BUY'), true);
  8512. return;
  8513. }
  8514.  
  8515. const resultBuy = await Send(JSON.stringify({ calls })).then(e => e.results.map(n => n.result.response));
  8516. console.log(resultBuy);
  8517. const countBuy = resultBuy.length;
  8518. setProgress(I18N('LOTS_BOUGHT', { countBuy }), true);
  8519. }
  8520.  
  8521. function rewardsAndMailFarm() {
  8522. return new Promise(function (resolve, reject) {
  8523. let questGetAllCall = {
  8524. calls: [{
  8525. name: "questGetAll",
  8526. args: {},
  8527. ident: "questGetAll"
  8528. }, {
  8529. name: "mailGetAll",
  8530. args: {},
  8531. ident: "mailGetAll"
  8532. }]
  8533. }
  8534. send(JSON.stringify(questGetAllCall), function (data) {
  8535. if (!data) return;
  8536. const questGetAll = data.results[0].result.response.filter((e) => e.state == 2);
  8537. const questBattlePass = lib.getData('quest').battlePass;
  8538. const questChainBPass = lib.getData('battlePass').questChain;
  8539. const listBattlePass = lib.getData('battlePass').list;
  8540.  
  8541. const questAllFarmCall = {
  8542. calls: [],
  8543. };
  8544. const questIds = [];
  8545. for (let quest of questGetAll) {
  8546. if (quest.id >= 2001e4) {
  8547. continue;
  8548. }
  8549. if (quest.id > 1e6 && quest.id < 2e7) {
  8550. const questInfo = questBattlePass[quest.id];
  8551. const chain = questChainBPass[questInfo.chain];
  8552. if (chain.requirement?.battlePassTicket) {
  8553. continue;
  8554. }
  8555. const battlePass = listBattlePass[chain.battlePass];
  8556. const startTime = battlePass.startCondition.time.value * 1e3
  8557. const endTime = new Date(startTime + battlePass.duration * 1e3);
  8558. if (startTime > Date.now() || endTime < Date.now()) {
  8559. continue;
  8560. }
  8561. }
  8562. if (quest.id >= 2e7) {
  8563. questIds.push(quest.id);
  8564. continue;
  8565. }
  8566. questAllFarmCall.calls.push({
  8567. name: 'questFarm',
  8568. args: {
  8569. questId: quest.id,
  8570. },
  8571. ident: `questFarm_${quest.id}`,
  8572. });
  8573. }
  8574.  
  8575. if (questIds.length) {
  8576. questAllFarmCall.calls.push({
  8577. name: 'quest_questsFarm',
  8578. args: { questIds },
  8579. ident: 'quest_questsFarm',
  8580. });
  8581. }
  8582.  
  8583. let letters = data?.results[1]?.result?.response?.letters;
  8584. letterIds = lettersFilter(letters);
  8585.  
  8586. if (letterIds.length) {
  8587. questAllFarmCall.calls.push({
  8588. name: 'mailFarm',
  8589. args: { letterIds },
  8590. ident: 'mailFarm',
  8591. });
  8592. }
  8593.  
  8594. if (!questAllFarmCall.calls.length) {
  8595. setProgress(I18N('NOTHING_TO_COLLECT'), true);
  8596. resolve();
  8597. return;
  8598. }
  8599.  
  8600. send(JSON.stringify(questAllFarmCall), async function (res) {
  8601. let countQuests = 0;
  8602. let countMail = 0;
  8603. let questsIds = [];
  8604. for (let call of res.results) {
  8605. if (call.ident.includes('questFarm')) {
  8606. countQuests++;
  8607. } else if (call.ident.includes('questsFarm')) {
  8608. countQuests += Object.keys(call.result.response).length;
  8609. } else if (call.ident.includes('mailFarm')) {
  8610. countMail = Object.keys(call.result.response).length;
  8611. }
  8612.  
  8613. const newQuests = call.result.newQuests;
  8614. if (newQuests) {
  8615. for (let quest of newQuests) {
  8616. if ((quest.id < 1e6 || (quest.id >= 2e7 && quest.id < 2001e4)) && quest.state == 2) {
  8617. questsIds.push(quest.id);
  8618. }
  8619. }
  8620. }
  8621. }
  8622.  
  8623. while (questsIds.length) {
  8624. const questIds = [];
  8625. const calls = [];
  8626. for (let questId of questsIds) {
  8627. if (questId < 1e6) {
  8628. calls.push({
  8629. name: 'questFarm',
  8630. args: {
  8631. questId,
  8632. },
  8633. ident: `questFarm_${questId}`,
  8634. });
  8635. countQuests++;
  8636. } else if (questId >= 2e7 && questId < 2001e4) {
  8637. questIds.push(questId);
  8638. countQuests++;
  8639. }
  8640. }
  8641. calls.push({
  8642. name: 'quest_questsFarm',
  8643. args: { questIds },
  8644. ident: 'body',
  8645. });
  8646. const results = await Send({ calls }).then((e) => e.results.map((e) => e.result));
  8647. questsIds = [];
  8648. for (const result of results) {
  8649. const newQuests = result.newQuests;
  8650. if (newQuests) {
  8651. for (let quest of newQuests) {
  8652. if (quest.state == 2) {
  8653. questsIds.push(quest.id);
  8654. }
  8655. }
  8656. }
  8657. }
  8658. }
  8659.  
  8660. setProgress(I18N('COLLECT_REWARDS_AND_MAIL', { countQuests, countMail }), true);
  8661. resolve();
  8662. });
  8663. });
  8664. })
  8665. }
  8666.  
  8667. class epicBrawl {
  8668. timeout = null;
  8669. time = null;
  8670.  
  8671. constructor() {
  8672. if (epicBrawl.inst) {
  8673. return epicBrawl.inst;
  8674. }
  8675. epicBrawl.inst = this;
  8676. return this;
  8677. }
  8678.  
  8679. runTimeout(func, timeDiff) {
  8680. const worker = new Worker(URL.createObjectURL(new Blob([`
  8681. self.onmessage = function(e) {
  8682. const timeDiff = e.data;
  8683.  
  8684. if (timeDiff > 0) {
  8685. setTimeout(() => {
  8686. self.postMessage(1);
  8687. self.close();
  8688. }, timeDiff);
  8689. }
  8690. };
  8691. `])));
  8692. worker.postMessage(timeDiff);
  8693. worker.onmessage = () => {
  8694. func();
  8695. };
  8696. return true;
  8697. }
  8698.  
  8699. timeDiff(date1, date2) {
  8700. const date1Obj = new Date(date1);
  8701. const date2Obj = new Date(date2);
  8702.  
  8703. const timeDiff = Math.abs(date2Obj - date1Obj);
  8704.  
  8705. const totalSeconds = timeDiff / 1000;
  8706. const minutes = Math.floor(totalSeconds / 60);
  8707. const seconds = Math.floor(totalSeconds % 60);
  8708.  
  8709. const formattedMinutes = String(minutes).padStart(2, '0');
  8710. const formattedSeconds = String(seconds).padStart(2, '0');
  8711.  
  8712. return `${formattedMinutes}:${formattedSeconds}`;
  8713. }
  8714.  
  8715. check() {
  8716. console.log(new Date(this.time))
  8717. if (Date.now() > this.time) {
  8718. this.timeout = null;
  8719. this.start()
  8720. return;
  8721. }
  8722. this.timeout = this.runTimeout(() => this.check(), 6e4);
  8723. return this.timeDiff(this.time, Date.now())
  8724. }
  8725.  
  8726. async start() {
  8727. if (this.timeout) {
  8728. const time = this.timeDiff(this.time, Date.now());
  8729. console.log(new Date(this.time))
  8730. setProgress(I18N('TIMER_ALREADY', { time }), false, hideProgress);
  8731. return;
  8732. }
  8733. setProgress(I18N('EPIC_BRAWL'), false, hideProgress);
  8734. const teamInfo = await Send('{"calls":[{"name":"teamGetAll","args":{},"ident":"teamGetAll"},{"name":"teamGetFavor","args":{},"ident":"teamGetFavor"},{"name":"userGetInfo","args":{},"ident":"userGetInfo"}]}').then(e => e.results.map(n => n.result.response));
  8735. const refill = teamInfo[2].refillable.find(n => n.id == 52)
  8736. this.time = (refill.lastRefill + 3600) * 1000
  8737. const attempts = refill.amount;
  8738. if (!attempts) {
  8739. console.log(new Date(this.time));
  8740. const time = this.check();
  8741. setProgress(I18N('NO_ATTEMPTS_TIMER_START', { time }), false, hideProgress);
  8742. return;
  8743. }
  8744.  
  8745. if (!teamInfo[0].epic_brawl) {
  8746. setProgress(I18N('NO_HEROES_PACK'), false, hideProgress);
  8747. return;
  8748. }
  8749.  
  8750. const args = {
  8751. heroes: teamInfo[0].epic_brawl.filter(e => e < 1000),
  8752. pet: teamInfo[0].epic_brawl.filter(e => e > 6000).pop(),
  8753. favor: teamInfo[1].epic_brawl,
  8754. }
  8755.  
  8756. let wins = 0;
  8757. let coins = 0;
  8758. let streak = { progress: 0, nextStage: 0 };
  8759. for (let i = attempts; i > 0; i--) {
  8760. const info = await Send(JSON.stringify({
  8761. calls: [
  8762. { name: "epicBrawl_getEnemy", args: {}, ident: "epicBrawl_getEnemy" }, { name: "epicBrawl_startBattle", args, ident: "epicBrawl_startBattle" }
  8763. ]
  8764. })).then(e => e.results.map(n => n.result.response));
  8765.  
  8766. const { progress, result } = await Calc(info[1].battle);
  8767. const endResult = await Send(JSON.stringify({ calls: [{ name: "epicBrawl_endBattle", args: { progress, result }, ident: "epicBrawl_endBattle" }, { name: "epicBrawl_getWinStreak", args: {}, ident: "epicBrawl_getWinStreak" }] })).then(e => e.results.map(n => n.result.response));
  8768.  
  8769. const resultInfo = endResult[0].result;
  8770. streak = endResult[1];
  8771.  
  8772. wins += resultInfo.win;
  8773. coins += resultInfo.reward ? resultInfo.reward.coin[39] : 0;
  8774.  
  8775. console.log(endResult[0].result)
  8776. if (endResult[1].progress == endResult[1].nextStage) {
  8777. const farm = await Send('{"calls":[{"name":"epicBrawl_farmWinStreak","args":{},"ident":"body"}]}').then(e => e.results[0].result.response);
  8778. coins += farm.coin[39];
  8779. }
  8780.  
  8781. setProgress(I18N('EPIC_BRAWL_RESULT', {
  8782. i, wins, attempts, coins,
  8783. progress: streak.progress,
  8784. nextStage: streak.nextStage,
  8785. end: '',
  8786. }), false, hideProgress);
  8787. }
  8788.  
  8789. console.log(new Date(this.time));
  8790. const time = this.check();
  8791. setProgress(I18N('EPIC_BRAWL_RESULT', {
  8792. wins, attempts, coins,
  8793. i: '',
  8794. progress: streak.progress,
  8795. nextStage: streak.nextStage,
  8796. end: I18N('ATTEMPT_ENDED', { time }),
  8797. }), false, hideProgress);
  8798. }
  8799. }
  8800.  
  8801. function countdownTimer(seconds, message) {
  8802. message = message || I18N('TIMER');
  8803. const stopTimer = Date.now() + seconds * 1e3
  8804. return new Promise(resolve => {
  8805. const interval = setInterval(async () => {
  8806. const now = Date.now();
  8807. setProgress(`${message} ${((stopTimer - now) / 1000).toFixed(2)}`, false);
  8808. if (now > stopTimer) {
  8809. clearInterval(interval);
  8810. setProgress('', 1);
  8811. resolve();
  8812. }
  8813. }, 100);
  8814. });
  8815. }
  8816.  
  8817. this.HWHFuncs.countdownTimer = countdownTimer;
  8818.  
  8819. /** Набить килов в горниле душк */
  8820. async function bossRatingEventSouls() {
  8821. const data = await Send({
  8822. calls: [
  8823. { name: "heroGetAll", args: {}, ident: "teamGetAll" },
  8824. { name: "offerGetAll", args: {}, ident: "offerGetAll" },
  8825. { name: "pet_getAll", args: {}, ident: "pet_getAll" },
  8826. ]
  8827. });
  8828. const bossEventInfo = data.results[1].result.response.find(e => e.offerType == "bossEvent");
  8829. if (!bossEventInfo) {
  8830. setProgress('Эвент завершен', true);
  8831. return;
  8832. }
  8833.  
  8834. if (bossEventInfo.progress.score > 250) {
  8835. setProgress('Уже убито больше 250 врагов');
  8836. rewardBossRatingEventSouls();
  8837. return;
  8838. }
  8839. const availablePets = Object.values(data.results[2].result.response).map(e => e.id);
  8840. const heroGetAllList = data.results[0].result.response;
  8841. const usedHeroes = bossEventInfo.progress.usedHeroes;
  8842. const heroList = [];
  8843.  
  8844. for (let heroId in heroGetAllList) {
  8845. let hero = heroGetAllList[heroId];
  8846. if (usedHeroes.includes(hero.id)) {
  8847. continue;
  8848. }
  8849. heroList.push(hero.id);
  8850. }
  8851.  
  8852. if (!heroList.length) {
  8853. setProgress('Нет героев', true);
  8854. return;
  8855. }
  8856.  
  8857. const pet = availablePets.includes(6005) ? 6005 : availablePets[Math.floor(Math.random() * availablePets.length)];
  8858. const petLib = lib.getData('pet');
  8859. let count = 1;
  8860.  
  8861. for (const heroId of heroList) {
  8862. const args = {
  8863. heroes: [heroId],
  8864. pet
  8865. }
  8866. /** Поиск питомца для героя */
  8867. for (const petId of availablePets) {
  8868. if (petLib[petId].favorHeroes.includes(heroId)) {
  8869. args.favor = {
  8870. [heroId]: petId
  8871. }
  8872. break;
  8873. }
  8874. }
  8875.  
  8876. const calls = [{
  8877. name: "bossRatingEvent_startBattle",
  8878. args,
  8879. ident: "body"
  8880. }, {
  8881. name: "offerGetAll",
  8882. args: {},
  8883. ident: "offerGetAll"
  8884. }];
  8885.  
  8886. const res = await Send({ calls });
  8887. count++;
  8888.  
  8889. if ('error' in res) {
  8890. console.error(res.error);
  8891. setProgress('Перезагрузите игру и попробуйте позже', true);
  8892. return;
  8893. }
  8894.  
  8895. const eventInfo = res.results[1].result.response.find(e => e.offerType == "bossEvent");
  8896. if (eventInfo.progress.score > 250) {
  8897. break;
  8898. }
  8899. setProgress('Количество убитых врагов: ' + eventInfo.progress.score + '<br>Использовано ' + count + ' героев');
  8900. }
  8901.  
  8902. rewardBossRatingEventSouls();
  8903. }
  8904. /** Сбор награды из Горнила Душ */
  8905. async function rewardBossRatingEventSouls() {
  8906. const data = await Send({
  8907. calls: [
  8908. { name: "offerGetAll", args: {}, ident: "offerGetAll" }
  8909. ]
  8910. });
  8911.  
  8912. const bossEventInfo = data.results[0].result.response.find(e => e.offerType == "bossEvent");
  8913. if (!bossEventInfo) {
  8914. setProgress('Эвент завершен', true);
  8915. return;
  8916. }
  8917.  
  8918. const farmedChests = bossEventInfo.progress.farmedChests;
  8919. const score = bossEventInfo.progress.score;
  8920. // setProgress('Количество убитых врагов: ' + score);
  8921. const revard = bossEventInfo.reward;
  8922. const calls = [];
  8923.  
  8924. let count = 0;
  8925. for (let i = 1; i < 10; i++) {
  8926. if (farmedChests.includes(i)) {
  8927. continue;
  8928. }
  8929. if (score < revard[i].score) {
  8930. break;
  8931. }
  8932. calls.push({
  8933. name: "bossRatingEvent_getReward",
  8934. args: {
  8935. rewardId: i
  8936. },
  8937. ident: "body_" + i
  8938. });
  8939. count++;
  8940. }
  8941. if (!count) {
  8942. setProgress('Нечего собирать', true);
  8943. return;
  8944. }
  8945.  
  8946. Send({ calls }).then(e => {
  8947. console.log(e);
  8948. setProgress('Собрано ' + e?.results?.length + ' наград', true);
  8949. })
  8950. }
  8951. /**
  8952. * Spin the Seer
  8953. *
  8954. * Покрутить провидца
  8955. */
  8956. async function rollAscension() {
  8957. const refillable = await Send({calls:[
  8958. {
  8959. name:"userGetInfo",
  8960. args:{},
  8961. ident:"userGetInfo"
  8962. }
  8963. ]}).then(e => e.results[0].result.response.refillable);
  8964. const i47 = refillable.find(i => i.id == 47);
  8965. if (i47?.amount) {
  8966. await Send({ calls: [{ name: "ascensionChest_open", args: { paid: false, amount: 1 }, ident: "body" }] });
  8967. setProgress(I18N('DONE'), true);
  8968. } else {
  8969. setProgress(I18N('NOT_ENOUGH_AP'), true);
  8970. }
  8971. }
  8972.  
  8973. /**
  8974. * Collect gifts for the New Year
  8975. *
  8976. * Собрать подарки на новый год
  8977. */
  8978. function getGiftNewYear() {
  8979. Send({ calls: [{ name: "newYearGiftGet", args: { type: 0 }, ident: "body" }] }).then(e => {
  8980. const gifts = e.results[0].result.response.gifts;
  8981. const calls = gifts.filter(e => e.opened == 0).map(e => ({
  8982. name: "newYearGiftOpen",
  8983. args: {
  8984. giftId: e.id
  8985. },
  8986. ident: `body_${e.id}`
  8987. }));
  8988. if (!calls.length) {
  8989. setProgress(I18N('NY_NO_GIFTS'), 5000);
  8990. return;
  8991. }
  8992. Send({ calls }).then(e => {
  8993. console.log(e.results)
  8994. const msg = I18N('NY_GIFTS_COLLECTED', { count: e.results.length });
  8995. console.log(msg);
  8996. setProgress(msg, 5000);
  8997. });
  8998. })
  8999. }
  9000.  
  9001. async function updateArtifacts() {
  9002. const count = +await popup.confirm(I18N('SET_NUMBER_LEVELS'), [
  9003. { msg: I18N('BTN_GO'), isInput: true, default: 10 },
  9004. { result: false, isClose: true }
  9005. ]);
  9006. if (!count) {
  9007. return;
  9008. }
  9009. const quest = new questRun;
  9010. await quest.autoInit();
  9011. const heroes = Object.values(quest.questInfo['heroGetAll']);
  9012. const inventory = quest.questInfo['inventoryGet'];
  9013. const calls = [];
  9014. for (let i = count; i > 0; i--) {
  9015. const upArtifact = quest.getUpgradeArtifact();
  9016. if (!upArtifact.heroId) {
  9017. if (await popup.confirm(I18N('POSSIBLE_IMPROVE_LEVELS', { count: calls.length }), [
  9018. { msg: I18N('YES'), result: true },
  9019. { result: false, isClose: true }
  9020. ])) {
  9021. break;
  9022. } else {
  9023. return;
  9024. }
  9025. }
  9026. const hero = heroes.find(e => e.id == upArtifact.heroId);
  9027. hero.artifacts[upArtifact.slotId].level++;
  9028. inventory[upArtifact.costCurrency][upArtifact.costId] -= upArtifact.costValue;
  9029. calls.push({
  9030. name: "heroArtifactLevelUp",
  9031. args: {
  9032. heroId: upArtifact.heroId,
  9033. slotId: upArtifact.slotId
  9034. },
  9035. ident: `heroArtifactLevelUp_${i}`
  9036. });
  9037. }
  9038.  
  9039. if (!calls.length) {
  9040. console.log(I18N('NOT_ENOUGH_RESOURECES'));
  9041. setProgress(I18N('NOT_ENOUGH_RESOURECES'), false);
  9042. return;
  9043. }
  9044.  
  9045. await Send(JSON.stringify({ calls })).then(e => {
  9046. if ('error' in e) {
  9047. console.log(I18N('NOT_ENOUGH_RESOURECES'));
  9048. setProgress(I18N('NOT_ENOUGH_RESOURECES'), false);
  9049. } else {
  9050. console.log(I18N('IMPROVED_LEVELS', { count: e.results.length }));
  9051. setProgress(I18N('IMPROVED_LEVELS', { count: e.results.length }), false);
  9052. }
  9053. });
  9054. }
  9055.  
  9056. window.sign = a => {
  9057. const i = this['\x78\x79\x7a'];
  9058. return md5([i['\x6e\x61\x6d\x65'], i['\x76\x65\x72\x73\x69\x6f\x6e'], i['\x61\x75\x74\x68\x6f\x72'], ~(a % 1e3)]['\x6a\x6f\x69\x6e']('\x5f'))
  9059. }
  9060.  
  9061. async function updateSkins() {
  9062. const count = +await popup.confirm(I18N('SET_NUMBER_LEVELS'), [
  9063. { msg: I18N('BTN_GO'), isInput: true, default: 10 },
  9064. { result: false, isClose: true }
  9065. ]);
  9066. if (!count) {
  9067. return;
  9068. }
  9069.  
  9070. const quest = new questRun;
  9071. await quest.autoInit();
  9072. const heroes = Object.values(quest.questInfo['heroGetAll']);
  9073. const inventory = quest.questInfo['inventoryGet'];
  9074. const calls = [];
  9075. for (let i = count; i > 0; i--) {
  9076. const upSkin = quest.getUpgradeSkin();
  9077. if (!upSkin.heroId) {
  9078. if (await popup.confirm(I18N('POSSIBLE_IMPROVE_LEVELS', { count: calls.length }), [
  9079. { msg: I18N('YES'), result: true },
  9080. { result: false, isClose: true }
  9081. ])) {
  9082. break;
  9083. } else {
  9084. return;
  9085. }
  9086. }
  9087. const hero = heroes.find(e => e.id == upSkin.heroId);
  9088. hero.skins[upSkin.skinId]++;
  9089. inventory[upSkin.costCurrency][upSkin.costCurrencyId] -= upSkin.cost;
  9090. calls.push({
  9091. name: "heroSkinUpgrade",
  9092. args: {
  9093. heroId: upSkin.heroId,
  9094. skinId: upSkin.skinId
  9095. },
  9096. ident: `heroSkinUpgrade_${i}`
  9097. })
  9098. }
  9099.  
  9100. if (!calls.length) {
  9101. console.log(I18N('NOT_ENOUGH_RESOURECES'));
  9102. setProgress(I18N('NOT_ENOUGH_RESOURECES'), false);
  9103. return;
  9104. }
  9105.  
  9106. await Send(JSON.stringify({ calls })).then(e => {
  9107. if ('error' in e) {
  9108. console.log(I18N('NOT_ENOUGH_RESOURECES'));
  9109. setProgress(I18N('NOT_ENOUGH_RESOURECES'), false);
  9110. } else {
  9111. console.log(I18N('IMPROVED_LEVELS', { count: e.results.length }));
  9112. setProgress(I18N('IMPROVED_LEVELS', { count: e.results.length }), false);
  9113. }
  9114. });
  9115. }
  9116.  
  9117. function getQuestionInfo(img, nameOnly = false) {
  9118. const libHeroes = Object.values(lib.data.hero);
  9119. const parts = img.split(':');
  9120. const id = parts[1];
  9121. switch (parts[0]) {
  9122. case 'titanArtifact_id':
  9123. return cheats.translate("LIB_TITAN_ARTIFACT_NAME_" + id);
  9124. case 'titan':
  9125. return cheats.translate("LIB_HERO_NAME_" + id);
  9126. case 'skill':
  9127. return cheats.translate("LIB_SKILL_" + id);
  9128. case 'inventoryItem_gear':
  9129. return cheats.translate("LIB_GEAR_NAME_" + id);
  9130. case 'inventoryItem_coin':
  9131. return cheats.translate("LIB_COIN_NAME_" + id);
  9132. case 'artifact':
  9133. if (nameOnly) {
  9134. return cheats.translate("LIB_ARTIFACT_NAME_" + id);
  9135. }
  9136. heroes = libHeroes.filter(h => h.id < 100 && h.artifacts.includes(+id));
  9137. return {
  9138. /** Как называется этот артефакт? */
  9139. name: cheats.translate("LIB_ARTIFACT_NAME_" + id),
  9140. /** Какому герою принадлежит этот артефакт? */
  9141. heroes: heroes.map(h => cheats.translate("LIB_HERO_NAME_" + h.id))
  9142. };
  9143. case 'hero':
  9144. if (nameOnly) {
  9145. return cheats.translate("LIB_HERO_NAME_" + id);
  9146. }
  9147. artifacts = lib.data.hero[id].artifacts;
  9148. return {
  9149. /** Как зовут этого героя? */
  9150. name: cheats.translate("LIB_HERO_NAME_" + id),
  9151. /** Какой артефакт принадлежит этому герою? */
  9152. artifact: artifacts.map(a => cheats.translate("LIB_ARTIFACT_NAME_" + a))
  9153. };
  9154. }
  9155. }
  9156.  
  9157. function hintQuest(quest) {
  9158. const result = {};
  9159. if (quest?.questionIcon) {
  9160. const info = getQuestionInfo(quest.questionIcon);
  9161. if (info?.heroes) {
  9162. /** Какому герою принадлежит этот артефакт? */
  9163. result.answer = quest.answers.filter(e => info.heroes.includes(e.answerText.slice(1)));
  9164. }
  9165. if (info?.artifact) {
  9166. /** Какой артефакт принадлежит этому герою? */
  9167. result.answer = quest.answers.filter(e => info.artifact.includes(e.answerText.slice(1)));
  9168. }
  9169. if (typeof info == 'string') {
  9170. result.info = { name: info };
  9171. } else {
  9172. result.info = info;
  9173. }
  9174. }
  9175.  
  9176. if (quest.answers[0]?.answerIcon) {
  9177. result.answer = quest.answers.filter(e => quest.question.includes(getQuestionInfo(e.answerIcon, true)))
  9178. }
  9179.  
  9180. if ((!result?.answer || !result.answer.length) && !result.info?.name) {
  9181. return false;
  9182. }
  9183.  
  9184. let resultText = '';
  9185. if (result?.info) {
  9186. resultText += I18N('PICTURE') + result.info.name;
  9187. }
  9188. console.log(result);
  9189. if (result?.answer && result.answer.length) {
  9190. resultText += I18N('ANSWER') + result.answer[0].id + (!result.answer[0].answerIcon ? ' - ' + result.answer[0].answerText : '');
  9191. }
  9192.  
  9193. return resultText;
  9194. }
  9195.  
  9196. async function farmBattlePass() {
  9197. const isFarmReward = (reward) => {
  9198. return !(reward?.buff || reward?.fragmentHero || reward?.bundleHeroReward);
  9199. };
  9200.  
  9201. const battlePassProcess = (pass) => {
  9202. if (!pass.id) {return []}
  9203. const levels = Object.values(lib.data.battlePass.level).filter(x => x.battlePass == pass.id)
  9204. const last_level = levels[levels.length - 1];
  9205. let actual = Math.max(...levels.filter(p => pass.exp >= p.experience).map(p => p.level))
  9206.  
  9207. if (pass.exp > last_level.experience) {
  9208. actual = last_level.level + (pass.exp - last_level.experience) / last_level.experienceByLevel;
  9209. }
  9210. const calls = [];
  9211. for(let i = 1; i <= actual; i++) {
  9212. const level = i >= last_level.level ? last_level : levels.find(l => l.level === i);
  9213. const reward = {free: level?.freeReward, paid:level?.paidReward};
  9214.  
  9215. if (!pass.rewards[i]?.free && isFarmReward(reward.free)) {
  9216. const args = {level: i, free:true};
  9217. if (!pass.gold) { args.id = pass.id }
  9218. calls.push({ name: 'battlePass_farmReward', args, ident: `${pass.gold ? 'body' : 'spesial'}_free_${args.id}_${i}` });
  9219. }
  9220. if (pass.ticket && !pass.rewards[i]?.paid && isFarmReward(reward.paid)) {
  9221. const args = {level: i, free:false};
  9222. if (!pass.gold) { args.id = pass.id}
  9223. calls.push({ name: 'battlePass_farmReward', args, ident: `${pass.gold ? 'body' : 'spesial'}_paid_${args.id}_${i}` });
  9224. }
  9225. }
  9226. return calls;
  9227. }
  9228.  
  9229. const passes = await Send({
  9230. calls: [
  9231. { name: 'battlePass_getInfo', args: {}, ident: 'getInfo' },
  9232. { name: 'battlePass_getSpecial', args: {}, ident: 'getSpecial' },
  9233. ],
  9234. }).then((e) => [{...e.results[0].result.response?.battlePass, gold: true}, ...Object.values(e.results[1].result.response)]);
  9235.  
  9236. const calls = passes.map(p => battlePassProcess(p)).flat()
  9237.  
  9238. if (!calls.length) {
  9239. setProgress(I18N('NOTHING_TO_COLLECT'));
  9240. return;
  9241. }
  9242.  
  9243. let results = await Send({calls});
  9244. if (results.error) {
  9245. console.log(results.error);
  9246. setProgress(I18N('SOMETHING_WENT_WRONG'));
  9247. } else {
  9248. setProgress(I18N('SEASON_REWARD_COLLECTED', {count: results.results.length}), true);
  9249. }
  9250. }
  9251.  
  9252. async function sellHeroSoulsForGold() {
  9253. let { fragmentHero, heroes } = await Send({
  9254. calls: [
  9255. { name: 'inventoryGet', args: {}, ident: 'inventoryGet' },
  9256. { name: 'heroGetAll', args: {}, ident: 'heroGetAll' },
  9257. ],
  9258. })
  9259. .then((e) => e.results.map((r) => r.result.response))
  9260. .then((e) => ({ fragmentHero: e[0].fragmentHero, heroes: e[1] }));
  9261.  
  9262. const calls = [];
  9263. for (let i in fragmentHero) {
  9264. if (heroes[i] && heroes[i].star == 6) {
  9265. calls.push({
  9266. name: 'inventorySell',
  9267. args: {
  9268. type: 'hero',
  9269. libId: i,
  9270. amount: fragmentHero[i],
  9271. fragment: true,
  9272. },
  9273. ident: 'inventorySell_' + i,
  9274. });
  9275. }
  9276. }
  9277. if (!calls.length) {
  9278. console.log(0);
  9279. return 0;
  9280. }
  9281. const rewards = await Send({ calls }).then((e) => e.results.map((r) => r.result?.response?.gold || 0));
  9282. const gold = rewards.reduce((e, a) => e + a, 0);
  9283. setProgress(I18N('GOLD_RECEIVED', { gold }), true);
  9284. }
  9285.  
  9286. /**
  9287. * Attack of the minions of Asgard
  9288. *
  9289. * Атака прислужников Асгарда
  9290. */
  9291. function testRaidNodes() {
  9292. const { executeRaidNodes } = HWHClasses;
  9293. return new Promise((resolve, reject) => {
  9294. const tower = new executeRaidNodes(resolve, reject);
  9295. tower.start();
  9296. });
  9297. }
  9298.  
  9299. /**
  9300. * Attack of the minions of Asgard
  9301. *
  9302. * Атака прислужников Асгарда
  9303. */
  9304. function executeRaidNodes(resolve, reject) {
  9305. let raidData = {
  9306. teams: [],
  9307. favor: {},
  9308. nodes: [],
  9309. attempts: 0,
  9310. countExecuteBattles: 0,
  9311. cancelBattle: 0,
  9312. }
  9313.  
  9314. callsExecuteRaidNodes = {
  9315. calls: [{
  9316. name: "clanRaid_getInfo",
  9317. args: {},
  9318. ident: "clanRaid_getInfo"
  9319. }, {
  9320. name: "teamGetAll",
  9321. args: {},
  9322. ident: "teamGetAll"
  9323. }, {
  9324. name: "teamGetFavor",
  9325. args: {},
  9326. ident: "teamGetFavor"
  9327. }]
  9328. }
  9329.  
  9330. this.start = function () {
  9331. send(JSON.stringify(callsExecuteRaidNodes), startRaidNodes);
  9332. }
  9333.  
  9334. async function startRaidNodes(data) {
  9335. res = data.results;
  9336. clanRaidInfo = res[0].result.response;
  9337. teamGetAll = res[1].result.response;
  9338. teamGetFavor = res[2].result.response;
  9339.  
  9340. let index = 0;
  9341. let isNotFullPack = false;
  9342. for (let team of teamGetAll.clanRaid_nodes) {
  9343. if (team.length < 6) {
  9344. isNotFullPack = true;
  9345. }
  9346. raidData.teams.push({
  9347. data: {},
  9348. heroes: team.filter(id => id < 6000),
  9349. pet: team.filter(id => id >= 6000).pop(),
  9350. battleIndex: index++
  9351. });
  9352. }
  9353. raidData.favor = teamGetFavor.clanRaid_nodes;
  9354.  
  9355. if (isNotFullPack) {
  9356. if (await popup.confirm(I18N('MINIONS_WARNING'), [
  9357. { msg: I18N('BTN_NO'), result: true },
  9358. { msg: I18N('BTN_YES'), result: false },
  9359. ])) {
  9360. endRaidNodes('isNotFullPack');
  9361. return;
  9362. }
  9363. }
  9364.  
  9365. raidData.nodes = clanRaidInfo.nodes;
  9366. raidData.attempts = clanRaidInfo.attempts;
  9367. setIsCancalBattle(false);
  9368.  
  9369. checkNodes();
  9370. }
  9371.  
  9372. function getAttackNode() {
  9373. for (let nodeId in raidData.nodes) {
  9374. let node = raidData.nodes[nodeId];
  9375. let points = 0
  9376. for (team of node.teams) {
  9377. points += team.points;
  9378. }
  9379. let now = Date.now() / 1000;
  9380. if (!points && now > node.timestamps.start && now < node.timestamps.end) {
  9381. let countTeam = node.teams.length;
  9382. delete raidData.nodes[nodeId];
  9383. return {
  9384. nodeId,
  9385. countTeam
  9386. };
  9387. }
  9388. }
  9389. return null;
  9390. }
  9391.  
  9392. function checkNodes() {
  9393. setProgress(`${I18N('REMAINING_ATTEMPTS')}: ${raidData.attempts}`);
  9394. let nodeInfo = getAttackNode();
  9395. if (nodeInfo && raidData.attempts) {
  9396. startNodeBattles(nodeInfo);
  9397. return;
  9398. }
  9399.  
  9400. endRaidNodes('EndRaidNodes');
  9401. }
  9402.  
  9403. function startNodeBattles(nodeInfo) {
  9404. let {nodeId, countTeam} = nodeInfo;
  9405. let teams = raidData.teams.slice(0, countTeam);
  9406. let heroes = raidData.teams.map(e => e.heroes).flat();
  9407. let favor = {...raidData.favor};
  9408. for (let heroId in favor) {
  9409. if (!heroes.includes(+heroId)) {
  9410. delete favor[heroId];
  9411. }
  9412. }
  9413.  
  9414. let calls = [{
  9415. name: "clanRaid_startNodeBattles",
  9416. args: {
  9417. nodeId,
  9418. teams,
  9419. favor
  9420. },
  9421. ident: "body"
  9422. }];
  9423.  
  9424. send(JSON.stringify({calls}), resultNodeBattles);
  9425. }
  9426.  
  9427. function resultNodeBattles(e) {
  9428. if (e['error']) {
  9429. endRaidNodes('nodeBattlesError', e['error']);
  9430. return;
  9431. }
  9432.  
  9433. console.log(e);
  9434. let battles = e.results[0].result.response.battles;
  9435. let promises = [];
  9436. let battleIndex = 0;
  9437. for (let battle of battles) {
  9438. battle.battleIndex = battleIndex++;
  9439. promises.push(calcBattleResult(battle));
  9440. }
  9441.  
  9442. Promise.all(promises)
  9443. .then(results => {
  9444. const endResults = {};
  9445. let isAllWin = true;
  9446. for (let r of results) {
  9447. isAllWin &&= r.result.win;
  9448. }
  9449. if (!isAllWin) {
  9450. cancelEndNodeBattle(results[0]);
  9451. return;
  9452. }
  9453. raidData.countExecuteBattles = results.length;
  9454. let timeout = 500;
  9455. for (let r of results) {
  9456. setTimeout(endNodeBattle, timeout, r);
  9457. timeout += 500;
  9458. }
  9459. });
  9460. }
  9461. /**
  9462. * Returns the battle calculation promise
  9463. *
  9464. * Возвращает промис расчета боя
  9465. */
  9466. function calcBattleResult(battleData) {
  9467. return new Promise(function (resolve, reject) {
  9468. BattleCalc(battleData, "get_clanPvp", resolve);
  9469. });
  9470. }
  9471. /**
  9472. * Cancels the fight
  9473. *
  9474. * Отменяет бой
  9475. */
  9476. function cancelEndNodeBattle(r) {
  9477. const fixBattle = function (heroes) {
  9478. for (const ids in heroes) {
  9479. hero = heroes[ids];
  9480. hero.energy = random(1, 999);
  9481. if (hero.hp > 0) {
  9482. hero.hp = random(1, hero.hp);
  9483. }
  9484. }
  9485. }
  9486. fixBattle(r.progress[0].attackers.heroes);
  9487. fixBattle(r.progress[0].defenders.heroes);
  9488. endNodeBattle(r);
  9489. }
  9490. /**
  9491. * Ends the fight
  9492. *
  9493. * Завершает бой
  9494. */
  9495. function endNodeBattle(r) {
  9496. let nodeId = r.battleData.result.nodeId;
  9497. let battleIndex = r.battleData.battleIndex;
  9498. let calls = [{
  9499. name: "clanRaid_endNodeBattle",
  9500. args: {
  9501. nodeId,
  9502. battleIndex,
  9503. result: r.result,
  9504. progress: r.progress
  9505. },
  9506. ident: "body"
  9507. }]
  9508.  
  9509. SendRequest(JSON.stringify({calls}), battleResult);
  9510. }
  9511. /**
  9512. * Processing the results of the battle
  9513. *
  9514. * Обработка результатов боя
  9515. */
  9516. function battleResult(e) {
  9517. if (e['error']) {
  9518. endRaidNodes('missionEndError', e['error']);
  9519. return;
  9520. }
  9521. r = e.results[0].result.response;
  9522. if (r['error']) {
  9523. if (r.reason == "invalidBattle") {
  9524. raidData.cancelBattle++;
  9525. checkNodes();
  9526. } else {
  9527. endRaidNodes('missionEndError', e['error']);
  9528. }
  9529. return;
  9530. }
  9531.  
  9532. if (!(--raidData.countExecuteBattles)) {
  9533. raidData.attempts--;
  9534. checkNodes();
  9535. }
  9536. }
  9537. /**
  9538. * Completing a task
  9539. *
  9540. * Завершение задачи
  9541. */
  9542. function endRaidNodes(reason, info) {
  9543. setIsCancalBattle(true);
  9544. let textCancel = raidData.cancelBattle ? ` ${I18N('BATTLES_CANCELED')}: ${raidData.cancelBattle}` : '';
  9545. setProgress(`${I18N('MINION_RAID')} ${I18N('COMPLETED')}! ${textCancel}`, true);
  9546. console.log(reason, info);
  9547. resolve();
  9548. }
  9549. }
  9550.  
  9551. this.HWHClasses.executeRaidNodes = executeRaidNodes;
  9552.  
  9553. /**
  9554. * Asgard Boss Attack Replay
  9555. *
  9556. * Повтор атаки босса Асгарда
  9557. */
  9558. function testBossBattle() {
  9559. const { executeBossBattle } = HWHClasses;
  9560. return new Promise((resolve, reject) => {
  9561. const bossBattle = new executeBossBattle(resolve, reject);
  9562. bossBattle.start(lastBossBattle);
  9563. });
  9564. }
  9565.  
  9566. /**
  9567. * Asgard Boss Attack Replay
  9568. *
  9569. * Повтор атаки босса Асгарда
  9570. */
  9571. function executeBossBattle(resolve, reject) {
  9572.  
  9573. this.start = function (battleInfo) {
  9574. preCalcBattle(battleInfo);
  9575. }
  9576.  
  9577. function getBattleInfo(battle) {
  9578. return new Promise(function (resolve) {
  9579. battle.seed = Math.floor(Date.now() / 1000) + random(0, 1e3);
  9580. BattleCalc(battle, getBattleType(battle.type), e => {
  9581. let extra = e.progress[0].defenders.heroes[1].extra;
  9582. resolve(extra.damageTaken + extra.damageTakenNextLevel);
  9583. });
  9584. });
  9585. }
  9586.  
  9587. function preCalcBattle(battle) {
  9588. let actions = [];
  9589. const countTestBattle = getInput('countTestBattle');
  9590. for (let i = 0; i < countTestBattle; i++) {
  9591. actions.push(getBattleInfo(battle, true));
  9592. }
  9593. Promise.all(actions)
  9594. .then(resultPreCalcBattle);
  9595. }
  9596.  
  9597. async function resultPreCalcBattle(damages) {
  9598. let maxDamage = 0;
  9599. let minDamage = 1e10;
  9600. let avgDamage = 0;
  9601. for (let damage of damages) {
  9602. avgDamage += damage
  9603. if (damage > maxDamage) {
  9604. maxDamage = damage;
  9605. }
  9606. if (damage < minDamage) {
  9607. minDamage = damage;
  9608. }
  9609. }
  9610. avgDamage /= damages.length;
  9611. console.log(damages.map(e => e.toLocaleString()).join('\n'), avgDamage, maxDamage);
  9612.  
  9613. await popup.confirm(
  9614. `${I18N('ROUND_STAT')} ${damages.length} ${I18N('BATTLE')}:` +
  9615. `<br>${I18N('MINIMUM')}: ` + minDamage.toLocaleString() +
  9616. `<br>${I18N('MAXIMUM')}: ` + maxDamage.toLocaleString() +
  9617. `<br>${I18N('AVERAGE')}: ` + avgDamage.toLocaleString()
  9618. , [
  9619. { msg: I18N('BTN_OK'), result: 0},
  9620. ])
  9621. endBossBattle(I18N('BTN_CANCEL'));
  9622. }
  9623.  
  9624. /**
  9625. * Completing a task
  9626. *
  9627. * Завершение задачи
  9628. */
  9629. function endBossBattle(reason, info) {
  9630. console.log(reason, info);
  9631. resolve();
  9632. }
  9633. }
  9634.  
  9635. this.HWHClasses.executeBossBattle = executeBossBattle;
  9636.  
  9637. class FixBattle {
  9638. minTimer = 3.3;
  9639. maxTimer = 17.3;
  9640.  
  9641. constructor(battle, isTimeout = true) {
  9642. this.battle = structuredClone(battle);
  9643. this.isTimeout = isTimeout;
  9644. }
  9645.  
  9646. timeout(callback, timeout) {
  9647. if (this.isTimeout) {
  9648. this.worker.postMessage(timeout);
  9649. this.worker.onmessage = callback;
  9650. } else {
  9651. callback();
  9652. }
  9653. }
  9654.  
  9655. randTimer() {
  9656. return Math.random() * (this.maxTimer - this.minTimer + 1) + this.minTimer;
  9657. }
  9658.  
  9659. setAvgTime(startTime) {
  9660. this.fixTime += Date.now() - startTime;
  9661. this.avgTime = this.fixTime / this.count;
  9662. }
  9663.  
  9664. init() {
  9665. this.fixTime = 0;
  9666. this.lastTimer = 0;
  9667. this.index = 0;
  9668. this.lastBossDamage = 0;
  9669. this.bestResult = {
  9670. count: 0,
  9671. timer: 0,
  9672. value: 0,
  9673. result: null,
  9674. progress: null,
  9675. };
  9676. this.lastBattleResult = {
  9677. win: false,
  9678. };
  9679. this.worker = new Worker(
  9680. URL.createObjectURL(
  9681. new Blob([
  9682. `self.onmessage = function(e) {
  9683. const timeout = e.data;
  9684. setTimeout(() => {
  9685. self.postMessage(1);
  9686. }, timeout);
  9687. };`,
  9688. ])
  9689. )
  9690. );
  9691. }
  9692.  
  9693. async start(endTime = Date.now() + 6e4, maxCount = 100) {
  9694. this.endTime = endTime;
  9695. this.maxCount = maxCount;
  9696. this.init();
  9697. return await new Promise((resolve) => {
  9698. this.resolve = resolve;
  9699. this.count = 0;
  9700. this.loop();
  9701. });
  9702. }
  9703.  
  9704. endFix() {
  9705. this.bestResult.maxCount = this.count;
  9706. this.worker.terminate();
  9707. this.resolve(this.bestResult);
  9708. }
  9709.  
  9710. async loop() {
  9711. const start = Date.now();
  9712. if (this.isEndLoop()) {
  9713. this.endFix();
  9714. return;
  9715. }
  9716. this.count++;
  9717. try {
  9718. this.lastResult = await Calc(this.battle);
  9719. } catch (e) {
  9720. this.updateProgressTimer(this.index++);
  9721. this.timeout(this.loop.bind(this), 0);
  9722. return;
  9723. }
  9724. const { progress, result } = this.lastResult;
  9725. this.lastBattleResult = result;
  9726. this.lastBattleProgress = progress;
  9727. this.setAvgTime(start);
  9728. this.checkResult();
  9729. this.showResult();
  9730. this.updateProgressTimer();
  9731. this.timeout(this.loop.bind(this), 0);
  9732. }
  9733.  
  9734. isEndLoop() {
  9735. return this.count >= this.maxCount || this.endTime < Date.now();
  9736. }
  9737.  
  9738. updateProgressTimer(index = 0) {
  9739. this.lastTimer = this.randTimer();
  9740. this.battle.progress = [{ attackers: { input: ['auto', 0, 0, 'auto', index, this.lastTimer] } }];
  9741. }
  9742.  
  9743. showResult() {
  9744. console.log(
  9745. this.count,
  9746. this.avgTime.toFixed(2),
  9747. (this.endTime - Date.now()) / 1000,
  9748. this.lastTimer.toFixed(2),
  9749. this.lastBossDamage.toLocaleString(),
  9750. this.bestResult.value.toLocaleString()
  9751. );
  9752. }
  9753.  
  9754. checkResult() {
  9755. const { damageTaken, damageTakenNextLevel } = this.lastBattleProgress[0].defenders.heroes[1].extra;
  9756. this.lastBossDamage = damageTaken + damageTakenNextLevel;
  9757. if (this.lastBossDamage > this.bestResult.value) {
  9758. this.bestResult = {
  9759. count: this.count,
  9760. timer: this.lastTimer,
  9761. value: this.lastBossDamage,
  9762. result: structuredClone(this.lastBattleResult),
  9763. progress: structuredClone(this.lastBattleProgress),
  9764. };
  9765. }
  9766. }
  9767.  
  9768. stopFix() {
  9769. this.endTime = 0;
  9770. }
  9771. }
  9772.  
  9773. this.HWHClasses.FixBattle = FixBattle;
  9774.  
  9775. class WinFixBattle extends FixBattle {
  9776. checkResult() {
  9777. if (this.lastBattleResult.win) {
  9778. this.bestResult = {
  9779. count: this.count,
  9780. timer: this.lastTimer,
  9781. value: this.lastBattleResult.stars,
  9782. result: structuredClone(this.lastBattleResult),
  9783. progress: structuredClone(this.lastBattleProgress),
  9784. battleTimer: this.lastResult.battleTimer,
  9785. };
  9786. }
  9787. }
  9788.  
  9789. setWinTimer(value) {
  9790. this.winTimer = value;
  9791. }
  9792.  
  9793. setMaxTimer(value) {
  9794. this.maxTimer = value;
  9795. }
  9796.  
  9797. randTimer() {
  9798. if (this.winTimer) {
  9799. return this.winTimer;
  9800. }
  9801. return super.randTimer();
  9802. }
  9803.  
  9804. isEndLoop() {
  9805. return super.isEndLoop() || this.bestResult.result?.win;
  9806. }
  9807.  
  9808. showResult() {
  9809. console.log(
  9810. this.count,
  9811. this.avgTime.toFixed(2),
  9812. (this.endTime - Date.now()) / 1000,
  9813. this.lastResult.battleTime,
  9814. this.lastTimer,
  9815. this.bestResult.value
  9816. );
  9817. const endTime = ((this.endTime - Date.now()) / 1000).toFixed(2);
  9818. const avgTime = this.avgTime.toFixed(2);
  9819. const msg = `${I18N('LETS_FIX')} ${this.count}/${this.maxCount}<br/>${endTime}s<br/>${avgTime}ms`;
  9820. setProgress(msg, false, this.stopFix.bind(this));
  9821. }
  9822. }
  9823.  
  9824. this.HWHClasses.WinFixBattle = WinFixBattle;
  9825.  
  9826. class BestOrWinFixBattle extends WinFixBattle {
  9827. isNoMakeWin = false;
  9828.  
  9829. getState(result) {
  9830. let beforeSumFactor = 0;
  9831. const beforeHeroes = result.battleData.defenders[0];
  9832. for (let heroId in beforeHeroes) {
  9833. const hero = beforeHeroes[heroId];
  9834. const state = hero.state;
  9835. let factor = 1;
  9836. if (state) {
  9837. const hp = state.hp / (hero?.hp || 1);
  9838. const energy = state.energy / 1e3;
  9839. factor = hp + energy / 20;
  9840. }
  9841. beforeSumFactor += factor;
  9842. }
  9843.  
  9844. let afterSumFactor = 0;
  9845. const afterHeroes = result.progress[0].defenders.heroes;
  9846. for (let heroId in afterHeroes) {
  9847. const hero = afterHeroes[heroId];
  9848. const hp = hero.hp / (beforeHeroes[heroId]?.hp || 1);
  9849. const energy = hero.energy / 1e3;
  9850. const factor = hp + energy / 20;
  9851. afterSumFactor += factor;
  9852. }
  9853. return 100 - Math.floor((afterSumFactor / beforeSumFactor) * 1e4) / 100;
  9854. }
  9855.  
  9856. setNoMakeWin(value) {
  9857. this.isNoMakeWin = value;
  9858. }
  9859.  
  9860. checkResult() {
  9861. const state = this.getState(this.lastResult);
  9862. console.log(state);
  9863.  
  9864. if (state > this.bestResult.value) {
  9865. if (!(this.isNoMakeWin && this.lastBattleResult.win)) {
  9866. this.bestResult = {
  9867. count: this.count,
  9868. timer: this.lastTimer,
  9869. value: state,
  9870. result: structuredClone(this.lastBattleResult),
  9871. progress: structuredClone(this.lastBattleProgress),
  9872. battleTimer: this.lastResult.battleTimer,
  9873. };
  9874. }
  9875. }
  9876. }
  9877. }
  9878.  
  9879. this.HWHClasses.BestOrWinFixBattle = BestOrWinFixBattle;
  9880.  
  9881. class BossFixBattle extends FixBattle {
  9882. showResult() {
  9883. super.showResult();
  9884. //setTimeout(() => {
  9885. const best = this.bestResult;
  9886. const maxDmg = best.value.toLocaleString();
  9887. const avgTime = this.avgTime.toLocaleString();
  9888. const msg = `${I18N('LETS_FIX')} ${this.count}/${this.maxCount}<br/>${maxDmg}<br/>${avgTime}ms`;
  9889. setProgress(msg, false, this.stopFix.bind(this));
  9890. //}, 0);
  9891. }
  9892. }
  9893.  
  9894. this.HWHClasses.BossFixBattle = BossFixBattle;
  9895.  
  9896. class DungeonFixBattle extends FixBattle {
  9897. init() {
  9898. super.init();
  9899. this.isTimeout = false;
  9900. }
  9901.  
  9902. setState() {
  9903. const result = this.lastResult;
  9904. let beforeSumFactor = 0;
  9905. const beforeHeroes = result.battleData.attackers;
  9906. for (let heroId in beforeHeroes) {
  9907. const hero = beforeHeroes[heroId];
  9908. const state = hero.state;
  9909. let factor = 1;
  9910. if (state) {
  9911. const hp = state.hp / (hero?.hp || 1);
  9912. const energy = state.energy / 1e3;
  9913. factor = hp + energy / 20;
  9914. }
  9915. beforeSumFactor += factor;
  9916. }
  9917.  
  9918. let afterSumFactor = 0;
  9919. const afterHeroes = result.progress[0].attackers.heroes;
  9920. for (let heroId in afterHeroes) {
  9921. const hero = afterHeroes[heroId];
  9922. const hp = hero.hp / (beforeHeroes[heroId]?.hp || 1);
  9923. const energy = hero.energy / 1e3;
  9924. const factor = hp + energy / 20;
  9925. afterSumFactor += factor;
  9926. }
  9927. this.lastState = Math.floor((afterSumFactor / beforeSumFactor) * 1e4) / 100;
  9928. }
  9929.  
  9930. checkResult() {
  9931. this.setState();
  9932. if (this.lastResult.result.win && this.lastState > this.bestResult.value) {
  9933. this.bestResult = {
  9934. count: this.count,
  9935. timer: this.lastTimer,
  9936. value: this.lastState,
  9937. result: this.lastResult.result,
  9938. progress: this.lastResult.progress,
  9939. };
  9940. }
  9941. }
  9942.  
  9943. showResult() {
  9944. console.log(
  9945. this.count,
  9946. this.avgTime.toFixed(2),
  9947. (this.endTime - Date.now()) / 1000,
  9948. this.lastTimer.toFixed(2),
  9949. this.lastState.toLocaleString(),
  9950. this.bestResult.value.toLocaleString()
  9951. );
  9952. }
  9953. }
  9954.  
  9955. this.HWHClasses.DungeonFixBattle = DungeonFixBattle;
  9956.  
  9957. const masterWsMixin = {
  9958. wsStart() {
  9959. const socket = new WebSocket(this.url);
  9960.  
  9961. socket.onopen = () => {
  9962. console.log('Connected to server');
  9963.  
  9964. // Пример создания новой задачи
  9965. const newTask = {
  9966. type: 'newTask',
  9967. battle: this.battle,
  9968. endTime: this.endTime - 1e4,
  9969. maxCount: this.maxCount,
  9970. };
  9971. socket.send(JSON.stringify(newTask));
  9972. };
  9973.  
  9974. socket.onmessage = this.onmessage.bind(this);
  9975.  
  9976. socket.onclose = () => {
  9977. console.log('Disconnected from server');
  9978. };
  9979.  
  9980. this.ws = socket;
  9981. },
  9982.  
  9983. onmessage(event) {
  9984. const data = JSON.parse(event.data);
  9985. switch (data.type) {
  9986. case 'newTask': {
  9987. console.log('newTask:', data);
  9988. this.id = data.id;
  9989. this.countExecutor = data.count;
  9990. break;
  9991. }
  9992. case 'getSolTask': {
  9993. console.log('getSolTask:', data);
  9994. this.endFix(data.solutions);
  9995. break;
  9996. }
  9997. case 'resolveTask': {
  9998. console.log('resolveTask:', data);
  9999. if (data.id === this.id && data.solutions.length === this.countExecutor) {
  10000. this.worker.terminate();
  10001. this.endFix(data.solutions);
  10002. }
  10003. break;
  10004. }
  10005. default:
  10006. console.log('Unknown message type:', data.type);
  10007. }
  10008. },
  10009.  
  10010. getTask() {
  10011. this.ws.send(
  10012. JSON.stringify({
  10013. type: 'getSolTask',
  10014. id: this.id,
  10015. })
  10016. );
  10017. },
  10018. };
  10019.  
  10020. /*
  10021. mFix = new action.masterFixBattle(battle)
  10022. await mFix.start(Date.now() + 6e4, 1);
  10023. */
  10024. class masterFixBattle extends FixBattle {
  10025. constructor(battle, url = 'wss://localho.st:3000') {
  10026. super(battle, true);
  10027. this.url = url;
  10028. }
  10029.  
  10030. async start(endTime, maxCount) {
  10031. this.endTime = endTime;
  10032. this.maxCount = maxCount;
  10033. this.init();
  10034. this.wsStart();
  10035. return await new Promise((resolve) => {
  10036. this.resolve = resolve;
  10037. const timeout = this.endTime - Date.now();
  10038. this.timeout(this.getTask.bind(this), timeout);
  10039. });
  10040. }
  10041.  
  10042. async endFix(solutions) {
  10043. this.ws.close();
  10044. let maxCount = 0;
  10045. for (const solution of solutions) {
  10046. maxCount += solution.maxCount;
  10047. if (solution.value > this.bestResult.value) {
  10048. this.bestResult = solution;
  10049. }
  10050. }
  10051. this.count = maxCount;
  10052. super.endFix();
  10053. }
  10054. }
  10055.  
  10056. Object.assign(masterFixBattle.prototype, masterWsMixin);
  10057.  
  10058. this.HWHClasses.masterFixBattle = masterFixBattle;
  10059.  
  10060. class masterWinFixBattle extends WinFixBattle {
  10061. constructor(battle, url = 'wss://localho.st:3000') {
  10062. super(battle, true);
  10063. this.url = url;
  10064. }
  10065.  
  10066. async start(endTime, maxCount) {
  10067. this.endTime = endTime;
  10068. this.maxCount = maxCount;
  10069. this.init();
  10070. this.wsStart();
  10071. return await new Promise((resolve) => {
  10072. this.resolve = resolve;
  10073. const timeout = this.endTime - Date.now();
  10074. this.timeout(this.getTask.bind(this), timeout);
  10075. });
  10076. }
  10077.  
  10078. async endFix(solutions) {
  10079. this.ws.close();
  10080. let maxCount = 0;
  10081. for (const solution of solutions) {
  10082. maxCount += solution.maxCount;
  10083. if (solution.value > this.bestResult.value) {
  10084. this.bestResult = solution;
  10085. }
  10086. }
  10087. this.count = maxCount;
  10088. super.endFix();
  10089. }
  10090. }
  10091.  
  10092. Object.assign(masterWinFixBattle.prototype, masterWsMixin);
  10093.  
  10094. this.HWHClasses.masterWinFixBattle = masterWinFixBattle;
  10095.  
  10096. const slaveWsMixin = {
  10097. wsStop() {
  10098. this.ws.close();
  10099. },
  10100.  
  10101. wsStart() {
  10102. const socket = new WebSocket(this.url);
  10103.  
  10104. socket.onopen = () => {
  10105. console.log('Connected to server');
  10106. };
  10107. socket.onmessage = this.onmessage.bind(this);
  10108. socket.onclose = () => {
  10109. console.log('Disconnected from server');
  10110. };
  10111.  
  10112. this.ws = socket;
  10113. },
  10114.  
  10115. async onmessage(event) {
  10116. const data = JSON.parse(event.data);
  10117. switch (data.type) {
  10118. case 'newTask': {
  10119. console.log('newTask:', data.task);
  10120. const { battle, endTime, maxCount } = data.task;
  10121. this.battle = battle;
  10122. const id = data.task.id;
  10123. const solution = await this.start(endTime, maxCount);
  10124. this.ws.send(
  10125. JSON.stringify({
  10126. type: 'resolveTask',
  10127. id,
  10128. solution,
  10129. })
  10130. );
  10131. break;
  10132. }
  10133. default:
  10134. console.log('Unknown message type:', data.type);
  10135. }
  10136. },
  10137. };
  10138. /*
  10139. sFix = new action.slaveFixBattle();
  10140. sFix.wsStart()
  10141. */
  10142. class slaveFixBattle extends FixBattle {
  10143. constructor(url = 'wss://localho.st:3000') {
  10144. super(null, false);
  10145. this.isTimeout = false;
  10146. this.url = url;
  10147. }
  10148. }
  10149.  
  10150. Object.assign(slaveFixBattle.prototype, slaveWsMixin);
  10151.  
  10152. this.HWHClasses.slaveFixBattle = slaveFixBattle;
  10153.  
  10154. class slaveWinFixBattle extends WinFixBattle {
  10155. constructor(url = 'wss://localho.st:3000') {
  10156. super(null, false);
  10157. this.isTimeout = false;
  10158. this.url = url;
  10159. }
  10160. }
  10161.  
  10162. Object.assign(slaveWinFixBattle.prototype, slaveWsMixin);
  10163.  
  10164. this.HWHClasses.slaveWinFixBattle = slaveWinFixBattle;
  10165. /**
  10166. * Auto-repeat attack
  10167. *
  10168. * Автоповтор атаки
  10169. */
  10170. function testAutoBattle() {
  10171. const { executeAutoBattle } = HWHClasses;
  10172. return new Promise((resolve, reject) => {
  10173. const bossBattle = new executeAutoBattle(resolve, reject);
  10174. bossBattle.start(lastBattleArg, lastBattleInfo);
  10175. });
  10176. }
  10177.  
  10178. /**
  10179. * Auto-repeat attack
  10180. *
  10181. * Автоповтор атаки
  10182. */
  10183. function executeAutoBattle(resolve, reject) {
  10184. let battleArg = {};
  10185. let countBattle = 0;
  10186. let countError = 0;
  10187. let findCoeff = 0;
  10188. let dataNotEeceived = 0;
  10189. let stopAutoBattle = false;
  10190.  
  10191. let isSetWinTimer = false;
  10192. const svgJustice = '<svg width="20" height="20" viewBox="0 0 124 125" xmlns="http://www.w3.org/2000/svg" style="fill: #fff;"><g><path d="m54 0h-1c-7.25 6.05-17.17 6.97-25.78 10.22-8.6 3.25-23.68 1.07-23.22 12.78s-0.47 24.08 1 35 2.36 18.36 7 28c4.43-8.31-3.26-18.88-3-30 0.26-11.11-2.26-25.29-1-37 11.88-4.16 26.27-0.42 36.77-9.23s20.53 6.05 29.23-0.77c-6.65-2.98-14.08-4.96-20-9z"/></g><g><path d="m108 5c-11.05 2.96-27.82 2.2-35.08 11.92s-14.91 14.71-22.67 23.33c-7.77 8.62-14.61 15.22-22.25 23.75 7.05 11.93 14.33 2.58 20.75-4.25 6.42-6.82 12.98-13.03 19.5-19.5s12.34-13.58 19.75-18.25c2.92 7.29-8.32 12.65-13.25 18.75-4.93 6.11-12.19 11.48-17.5 17.5s-12.31 11.38-17.25 17.75c10.34 14.49 17.06-3.04 26.77-10.23s15.98-16.89 26.48-24.52c10.5-7.64 12.09-24.46 14.75-36.25z"/></g><g><path d="m60 25c-11.52-6.74-24.53 8.28-38 6 0.84 9.61-1.96 20.2 2 29 5.53-4.04-4.15-23.2 4.33-26.67 8.48-3.48 18.14-1.1 24.67-8.33 2.73 0.3 4.81 2.98 7 0z"/></g><g><path d="m100 75c3.84-11.28 5.62-25.85 3-38-4.2 5.12-3.5 13.58-4 20s-3.52 13.18 1 18z"/></g><g><path d="m55 94c15.66-5.61 33.71-20.85 29-39-3.07 8.05-4.3 16.83-10.75 23.25s-14.76 8.35-18.25 15.75z"/></g><g><path d="m0 94v7c6.05 3.66 9.48 13.3 18 11-3.54-11.78 8.07-17.05 14-25 6.66 1.52 13.43 16.26 19 5-11.12-9.62-20.84-21.33-32-31-9.35 6.63 4.76 11.99 6 19-7.88 5.84-13.24 17.59-25 14z"/></g><g><path d="m82 125h26v-19h16v-1c-11.21-8.32-18.38-21.74-30-29-8.59 10.26-19.05 19.27-27 30h15v19z"/></g><g><path d="m68 110c-7.68-1.45-15.22 4.83-21.92-1.08s-11.94-5.72-18.08-11.92c-3.03 8.84 10.66 9.88 16.92 16.08s17.09 3.47 23.08-3.08z"/></g></svg>';
  10193. const svgBoss = '<svg width="20" height="20" viewBox="0 0 40 41" xmlns="http://www.w3.org/2000/svg" style="fill: #fff;"><g><path d="m21 12c-2.19-3.23 5.54-10.95-0.97-10.97-6.52-0.02 1.07 7.75-1.03 10.97-2.81 0.28-5.49-0.2-8-1-0.68 3.53 0.55 6.06 4 4 0.65 7.03 1.11 10.95 1.67 18.33 0.57 7.38 6.13 7.2 6.55-0.11 0.42-7.3 1.35-11.22 1.78-18.22 3.53 1.9 4.73-0.42 4-4-2.61 0.73-5.14 1.35-8 1m-1 17c-1.59-3.6-1.71-10.47 0-14 1.59 3.6 1.71 10.47 0 14z"/></g><g><path d="m6 19c-1.24-4.15 2.69-8.87 1-12-3.67 4.93-6.52 10.57-6 17 5.64-0.15 8.82 4.98 13 8 1.3-6.54-0.67-12.84-8-13z"/></g><g><path d="m33 7c0.38 5.57 2.86 14.79-7 15v10c4.13-2.88 7.55-7.97 13-8 0.48-6.46-2.29-12.06-6-17z"/></g></svg>';
  10194. const svgAttempt = '<svg width="20" height="20" viewBox="0 0 645 645" xmlns="http://www.w3.org/2000/svg" style="fill: #fff;"><g><path d="m442 26c-8.8 5.43-6.6 21.6-12.01 30.99-2.5 11.49-5.75 22.74-8.99 34.01-40.61-17.87-92.26-15.55-133.32-0.32-72.48 27.31-121.88 100.19-142.68 171.32 10.95-4.49 19.28-14.97 29.3-21.7 50.76-37.03 121.21-79.04 183.47-44.07 16.68 5.8 2.57 21.22-0.84 31.7-4.14 12.19-11.44 23.41-13.93 36.07 56.01-17.98 110.53-41.23 166-61-20.49-59.54-46.13-117.58-67-177z"/></g><g><path d="m563 547c23.89-16.34 36.1-45.65 47.68-71.32 23.57-62.18 7.55-133.48-28.38-186.98-15.1-22.67-31.75-47.63-54.3-63.7 1.15 14.03 6.71 26.8 8.22 40.78 12.08 61.99 15.82 148.76-48.15 183.29-10.46-0.54-15.99-16.1-24.32-22.82-8.2-7.58-14.24-19.47-23.75-24.25-4.88 59.04-11.18 117.71-15 177 62.9 5.42 126.11 9.6 189 15-4.84-9.83-17.31-15.4-24.77-24.23-9.02-7.06-17.8-15.13-26.23-22.77z"/></g><g><path d="m276 412c-10.69-15.84-30.13-25.9-43.77-40.23-15.39-12.46-30.17-25.94-45.48-38.52-15.82-11.86-29.44-28.88-46.75-37.25-19.07 24.63-39.96 48.68-60.25 72.75-18.71 24.89-42.41 47.33-58.75 73.25 22.4-2.87 44.99-13.6 66.67-13.67 0.06 22.8 10.69 42.82 20.41 62.59 49.09 93.66 166.6 114.55 261.92 96.08-6.07-9.2-22.11-9.75-31.92-16.08-59.45-26.79-138.88-75.54-127.08-151.92 21.66-2.39 43.42-4.37 65-7z"/></g></svg>';
  10195.  
  10196. this.start = function (battleArgs, battleInfo) {
  10197. battleArg = battleArgs;
  10198. if (nameFuncStartBattle == 'invasion_bossStart') {
  10199. startBattle();
  10200. return;
  10201. }
  10202. preCalcBattle(battleInfo);
  10203. }
  10204. /**
  10205. * Returns a promise for combat recalculation
  10206. *
  10207. * Возвращает промис для прерасчета боя
  10208. */
  10209. function getBattleInfo(battle) {
  10210. return new Promise(function (resolve) {
  10211. battle.seed = Math.floor(Date.now() / 1000) + random(0, 1e3);
  10212. Calc(battle).then(e => {
  10213. e.coeff = calcCoeff(e, 'defenders');
  10214. resolve(e);
  10215. });
  10216. });
  10217. }
  10218. /**
  10219. * Battle recalculation
  10220. *
  10221. * Прерасчет боя
  10222. */
  10223. function preCalcBattle(battle) {
  10224. let actions = [];
  10225. const countTestBattle = getInput('countTestBattle');
  10226. for (let i = 0; i < countTestBattle; i++) {
  10227. actions.push(getBattleInfo(battle));
  10228. }
  10229. Promise.all(actions)
  10230. .then(resultPreCalcBattle);
  10231. }
  10232. /**
  10233. * Processing the results of the battle recalculation
  10234. *
  10235. * Обработка результатов прерасчета боя
  10236. */
  10237. async function resultPreCalcBattle(results) {
  10238. let countWin = results.reduce((s, w) => w.result.win + s, 0);
  10239. setProgress(`${I18N('CHANCE_TO_WIN')} ${Math.floor(countWin / results.length * 100)}% (${results.length})`, false, hideProgress);
  10240. if (countWin > 0) {
  10241. setIsCancalBattle(false);
  10242. startBattle();
  10243. return;
  10244. }
  10245.  
  10246. let minCoeff = 100;
  10247. let maxCoeff = -100;
  10248. let avgCoeff = 0;
  10249. results.forEach(e => {
  10250. if (e.coeff < minCoeff) minCoeff = e.coeff;
  10251. if (e.coeff > maxCoeff) maxCoeff = e.coeff;
  10252. avgCoeff += e.coeff;
  10253. });
  10254. avgCoeff /= results.length;
  10255.  
  10256. if (nameFuncStartBattle == 'invasion_bossStart' ||
  10257. nameFuncStartBattle == 'bossAttack') {
  10258. const result = await popup.confirm(
  10259. I18N('BOSS_VICTORY_IMPOSSIBLE', { battles: results.length }), [
  10260. { msg: I18N('BTN_CANCEL'), result: false, isCancel: true },
  10261. { msg: I18N('BTN_DO_IT'), result: true },
  10262. ])
  10263. if (result) {
  10264. setIsCancalBattle(false);
  10265. startBattle();
  10266. return;
  10267. }
  10268. setProgress(I18N('NOT_THIS_TIME'), true);
  10269. endAutoBattle('invasion_bossStart');
  10270. return;
  10271. }
  10272.  
  10273. const result = await popup.confirm(
  10274. I18N('VICTORY_IMPOSSIBLE') +
  10275. `<br>${I18N('ROUND_STAT')} ${results.length} ${I18N('BATTLE')}:` +
  10276. `<br>${I18N('MINIMUM')}: ` + minCoeff.toLocaleString() +
  10277. `<br>${I18N('MAXIMUM')}: ` + maxCoeff.toLocaleString() +
  10278. `<br>${I18N('AVERAGE')}: ` + avgCoeff.toLocaleString() +
  10279. `<br>${I18N('FIND_COEFF')} ` + avgCoeff.toLocaleString(), [
  10280. { msg: I18N('BTN_CANCEL'), result: 0, isCancel: true },
  10281. { msg: I18N('BTN_GO'), isInput: true, default: Math.round(avgCoeff * 1000) / 1000 },
  10282. ])
  10283. if (result) {
  10284. findCoeff = result;
  10285. setIsCancalBattle(false);
  10286. startBattle();
  10287. return;
  10288. }
  10289. setProgress(I18N('NOT_THIS_TIME'), true);
  10290. endAutoBattle(I18N('NOT_THIS_TIME'));
  10291. }
  10292.  
  10293. /**
  10294. * Calculation of the combat result coefficient
  10295. *
  10296. * Расчет коэфициента результата боя
  10297. */
  10298. function calcCoeff(result, packType) {
  10299. let beforeSumFactor = 0;
  10300. const beforePack = result.battleData[packType][0];
  10301. for (let heroId in beforePack) {
  10302. const hero = beforePack[heroId];
  10303. const state = hero.state;
  10304. let factor = 1;
  10305. if (state) {
  10306. const hp = state.hp / state.maxHp;
  10307. const energy = state.energy / 1e3;
  10308. factor = hp + energy / 20;
  10309. }
  10310. beforeSumFactor += factor;
  10311. }
  10312.  
  10313. let afterSumFactor = 0;
  10314. const afterPack = result.progress[0][packType].heroes;
  10315. for (let heroId in afterPack) {
  10316. const hero = afterPack[heroId];
  10317. const stateHp = beforePack[heroId]?.state?.hp || beforePack[heroId]?.stats?.hp;
  10318. const hp = hero.hp / stateHp;
  10319. const energy = hero.energy / 1e3;
  10320. const factor = hp + energy / 20;
  10321. afterSumFactor += factor;
  10322. }
  10323. const resultCoeff = -(afterSumFactor - beforeSumFactor);
  10324. return Math.round(resultCoeff * 1000) / 1000;
  10325. }
  10326. /**
  10327. * Start battle
  10328. *
  10329. * Начало боя
  10330. */
  10331. function startBattle() {
  10332. countBattle++;
  10333. const countMaxBattle = getInput('countAutoBattle');
  10334. // setProgress(countBattle + '/' + countMaxBattle);
  10335. if (countBattle > countMaxBattle) {
  10336. setProgress(`${I18N('RETRY_LIMIT_EXCEEDED')}: ${countMaxBattle}`, true);
  10337. endAutoBattle(`${I18N('RETRY_LIMIT_EXCEEDED')}: ${countMaxBattle}`)
  10338. return;
  10339. }
  10340. if (stopAutoBattle) {
  10341. setProgress(I18N('STOPPED'), true);
  10342. endAutoBattle('STOPPED');
  10343. return;
  10344. }
  10345. send({calls: [{
  10346. name: nameFuncStartBattle,
  10347. args: battleArg,
  10348. ident: "body"
  10349. }]}, calcResultBattle);
  10350. }
  10351. /**
  10352. * Battle calculation
  10353. *
  10354. * Расчет боя
  10355. */
  10356. async function calcResultBattle(e) {
  10357. if (!e) {
  10358. console.log('данные не были получены');
  10359. if (dataNotEeceived < 10) {
  10360. dataNotEeceived++;
  10361. startBattle();
  10362. return;
  10363. }
  10364. endAutoBattle('Error', 'данные не были получены ' + dataNotEeceived + ' раз');
  10365. return;
  10366. }
  10367. if ('error' in e) {
  10368. if (e.error.description === 'too many tries') {
  10369. invasionTimer += 100;
  10370. countBattle--;
  10371. countError++;
  10372. console.log(`Errors: ${countError}`, e.error);
  10373. startBattle();
  10374. return;
  10375. }
  10376. const result = await popup.confirm(I18N('ERROR_DURING_THE_BATTLE') + '<br>' + e.error.description, [
  10377. { msg: I18N('BTN_OK'), result: false },
  10378. { msg: I18N('RELOAD_GAME'), result: true },
  10379. ]);
  10380. endAutoBattle('Error', e.error);
  10381. if (result) {
  10382. location.reload();
  10383. }
  10384. return;
  10385. }
  10386. let battle = e.results[0].result.response.battle
  10387. if (nameFuncStartBattle == 'towerStartBattle' ||
  10388. nameFuncStartBattle == 'bossAttack' ||
  10389. nameFuncStartBattle == 'invasion_bossStart') {
  10390. battle = e.results[0].result.response;
  10391. }
  10392. lastBattleInfo = battle;
  10393. BattleCalc(battle, getBattleType(battle.type), resultBattle);
  10394. }
  10395. /**
  10396. * Processing the results of the battle
  10397. *
  10398. * Обработка результатов боя
  10399. */
  10400. async function resultBattle(e) {
  10401. const isWin = e.result.win;
  10402. if (isWin) {
  10403. endBattle(e, false);
  10404. return;
  10405. } else if (isChecked('tryFixIt_v2')) {
  10406. const { WinFixBattle } = HWHClasses;
  10407. const cloneBattle = structuredClone(e.battleData);
  10408. const bFix = new WinFixBattle(cloneBattle);
  10409. let attempts = Infinity;
  10410. if (nameFuncStartBattle == 'invasion_bossStart' && !isSetWinTimer) {
  10411. let winTimer = await popup.confirm(`Secret number:`, [
  10412. { result: false, isClose: true },
  10413. { msg: 'Go', isInput: true, default: '0' },
  10414. ]);
  10415. winTimer = Number.parseFloat(winTimer);
  10416. if (winTimer) {
  10417. attempts = 5;
  10418. bFix.setWinTimer(winTimer);
  10419. }
  10420. isSetWinTimer = true;
  10421. }
  10422. let endTime = Date.now() + 6e4;
  10423. if (nameFuncStartBattle == 'invasion_bossStart') {
  10424. endTime = Date.now() + 6e4 * 4;
  10425. bFix.setMaxTimer(120.3);
  10426. }
  10427. const result = await bFix.start(endTime, attempts);
  10428. console.log(result);
  10429. if (result.value) {
  10430. endBattle(result, false);
  10431. return;
  10432. }
  10433. }
  10434. const countMaxBattle = getInput('countAutoBattle');
  10435. if (findCoeff) {
  10436. const coeff = calcCoeff(e, 'defenders');
  10437. setProgress(`${countBattle}/${countMaxBattle}, ${coeff}`);
  10438. if (coeff > findCoeff) {
  10439. endBattle(e, false);
  10440. return;
  10441. }
  10442. } else {
  10443. if (nameFuncStartBattle == 'invasion_bossStart') {
  10444. const bossLvl = lastBattleInfo.typeId >= 130 ? lastBattleInfo.typeId : '';
  10445. const justice = lastBattleInfo?.effects?.attackers?.percentInOutDamageModAndEnergyIncrease_any_99_100_300_99_1000_300 || 0;
  10446. setProgress(`${svgBoss} ${bossLvl} ${svgJustice} ${justice} <br>${svgAttempt} ${countBattle}/${countMaxBattle}`, false, () => {
  10447. stopAutoBattle = true;
  10448. });
  10449. await new Promise((resolve) => setTimeout(resolve, 5000));
  10450. } else {
  10451. setProgress(`${countBattle}/${countMaxBattle}`);
  10452. }
  10453. }
  10454. if (nameFuncStartBattle == 'towerStartBattle' ||
  10455. nameFuncStartBattle == 'bossAttack' ||
  10456. nameFuncStartBattle == 'invasion_bossStart') {
  10457. startBattle();
  10458. return;
  10459. }
  10460. cancelEndBattle(e);
  10461. }
  10462. /**
  10463. * Cancel fight
  10464. *
  10465. * Отмена боя
  10466. */
  10467. function cancelEndBattle(r) {
  10468. const fixBattle = function (heroes) {
  10469. for (const ids in heroes) {
  10470. hero = heroes[ids];
  10471. hero.energy = random(1, 999);
  10472. if (hero.hp > 0) {
  10473. hero.hp = random(1, hero.hp);
  10474. }
  10475. }
  10476. }
  10477. fixBattle(r.progress[0].attackers.heroes);
  10478. fixBattle(r.progress[0].defenders.heroes);
  10479. endBattle(r, true);
  10480. }
  10481. /**
  10482. * End of the fight
  10483. *
  10484. * Завершение боя */
  10485. function endBattle(battleResult, isCancal) {
  10486. let calls = [{
  10487. name: nameFuncEndBattle,
  10488. args: {
  10489. result: battleResult.result,
  10490. progress: battleResult.progress
  10491. },
  10492. ident: "body"
  10493. }];
  10494.  
  10495. if (nameFuncStartBattle == 'invasion_bossStart') {
  10496. calls[0].args.id = lastBattleArg.id;
  10497. }
  10498.  
  10499. send(JSON.stringify({
  10500. calls
  10501. }), async e => {
  10502. console.log(e);
  10503. if (isCancal) {
  10504. startBattle();
  10505. return;
  10506. }
  10507.  
  10508. setProgress(`${I18N('SUCCESS')}!`, 5000)
  10509. if (nameFuncStartBattle == 'invasion_bossStart' ||
  10510. nameFuncStartBattle == 'bossAttack') {
  10511. const countMaxBattle = getInput('countAutoBattle');
  10512. const bossLvl = lastBattleInfo.typeId >= 130 ? lastBattleInfo.typeId : '';
  10513. const justice = lastBattleInfo?.effects?.attackers?.percentInOutDamageModAndEnergyIncrease_any_99_100_300_99_1000_300 || 0;
  10514. let winTimer = '';
  10515. if (nameFuncStartBattle == 'invasion_bossStart') {
  10516. winTimer = '<br>Secret number: ' + battleResult.progress[0].attackers.input[5];
  10517. }
  10518. const result = await popup.confirm(
  10519. I18N('BOSS_HAS_BEEN_DEF_TEXT', {
  10520. bossLvl: `${svgBoss} ${bossLvl} ${svgJustice} ${justice}`,
  10521. countBattle: svgAttempt + ' ' + countBattle,
  10522. countMaxBattle,
  10523. winTimer,
  10524. }),
  10525. [
  10526. { msg: I18N('BTN_OK'), result: 0 },
  10527. { msg: I18N('MAKE_A_SYNC'), result: 1 },
  10528. { msg: I18N('RELOAD_GAME'), result: 2 },
  10529. ]
  10530. );
  10531. if (result) {
  10532. if (result == 1) {
  10533. cheats.refreshGame();
  10534. }
  10535. if (result == 2) {
  10536. location.reload();
  10537. }
  10538. }
  10539.  
  10540. }
  10541. endAutoBattle(`${I18N('SUCCESS')}!`)
  10542. });
  10543. }
  10544. /**
  10545. * Completing a task
  10546. *
  10547. * Завершение задачи
  10548. */
  10549. function endAutoBattle(reason, info) {
  10550. setIsCancalBattle(true);
  10551. console.log(reason, info);
  10552. resolve();
  10553. }
  10554. }
  10555.  
  10556. this.HWHClasses.executeAutoBattle = executeAutoBattle;
  10557.  
  10558. function testDailyQuests() {
  10559. const { dailyQuests } = HWHClasses;
  10560. return new Promise((resolve, reject) => {
  10561. const quests = new dailyQuests(resolve, reject);
  10562. quests.init(questsInfo);
  10563. quests.start();
  10564. });
  10565. }
  10566.  
  10567. /**
  10568. * Automatic completion of daily quests
  10569. *
  10570. * Автоматическое выполнение ежедневных квестов
  10571. */
  10572. class dailyQuests {
  10573. /**
  10574. * Send(' {"calls":[{"name":"userGetInfo","args":{},"ident":"body"}]}').then(e => console.log(e))
  10575. * Send(' {"calls":[{"name":"heroGetAll","args":{},"ident":"body"}]}').then(e => console.log(e))
  10576. * Send(' {"calls":[{"name":"titanGetAll","args":{},"ident":"body"}]}').then(e => console.log(e))
  10577. * Send(' {"calls":[{"name":"inventoryGet","args":{},"ident":"body"}]}').then(e => console.log(e))
  10578. * Send(' {"calls":[{"name":"questGetAll","args":{},"ident":"body"}]}').then(e => console.log(e))
  10579. * Send(' {"calls":[{"name":"bossGetAll","args":{},"ident":"body"}]}').then(e => console.log(e))
  10580. */
  10581. callsList = ['userGetInfo', 'heroGetAll', 'titanGetAll', 'inventoryGet', 'questGetAll', 'bossGetAll', 'missionGetAll'];
  10582.  
  10583. dataQuests = {
  10584. 10001: {
  10585. description: 'Улучши умения героев 3 раза', // ++++++++++++++++
  10586. doItCall: () => {
  10587. const upgradeSkills = this.getUpgradeSkills();
  10588. return upgradeSkills.map(({ heroId, skill }, index) => ({
  10589. name: 'heroUpgradeSkill',
  10590. args: { heroId, skill },
  10591. ident: `heroUpgradeSkill_${index}`,
  10592. }));
  10593. },
  10594. isWeCanDo: () => {
  10595. const upgradeSkills = this.getUpgradeSkills();
  10596. let sumGold = 0;
  10597. for (const skill of upgradeSkills) {
  10598. sumGold += this.skillCost(skill.value);
  10599. if (!skill.heroId) {
  10600. return false;
  10601. }
  10602. }
  10603. return this.questInfo['userGetInfo'].gold > sumGold;
  10604. },
  10605. },
  10606. 10002: {
  10607. description: 'Пройди 10 миссий', // --------------
  10608. isWeCanDo: () => false,
  10609. },
  10610. 10003: {
  10611. description: 'Пройди 3 героические миссии', // ++++++++++++++++
  10612. isWeCanDo: () => {
  10613. const vipPoints = +this.questInfo.userGetInfo.vipPoints;
  10614. const goldTicket = !!this.questInfo.inventoryGet.consumable[151];
  10615. return (vipPoints > 100 || goldTicket) && this.getHeroicMissionId();
  10616. },
  10617. doItCall: () => {
  10618. const selectedMissionId = this.getHeroicMissionId();
  10619. const goldTicket = !!this.questInfo.inventoryGet.consumable[151];
  10620. const vipLevel = Math.max(...lib.data.level.vip.filter(l => l.vipPoints <= +this.questInfo.userGetInfo.vipPoints).map(l => l.level));
  10621. // Возвращаем массив команд для рейда
  10622. if (vipLevel >= 5 || goldTicket) {
  10623. return [{ name: 'missionRaid', args: { id: selectedMissionId, times: 3 }, ident: 'missionRaid_1' }];
  10624. } else {
  10625. return [
  10626. { name: 'missionRaid', args: { id: selectedMissionId, times: 1 }, ident: 'missionRaid_1' },
  10627. { name: 'missionRaid', args: { id: selectedMissionId, times: 1 }, ident: 'missionRaid_2' },
  10628. { name: 'missionRaid', args: { id: selectedMissionId, times: 1 }, ident: 'missionRaid_3' },
  10629. ];
  10630. }
  10631. },
  10632. },
  10633. 10004: {
  10634. description: 'Сразись 3 раза на Арене или Гранд Арене', // --------------
  10635. isWeCanDo: () => false,
  10636. },
  10637. 10006: {
  10638. description: 'Используй обмен изумрудов 1 раз', // ++++++++++++++++
  10639. doItCall: () => [
  10640. {
  10641. name: 'refillableAlchemyUse',
  10642. args: { multi: false },
  10643. ident: 'refillableAlchemyUse',
  10644. },
  10645. ],
  10646. isWeCanDo: () => {
  10647. const starMoney = this.questInfo['userGetInfo'].starMoney;
  10648. return starMoney >= 20;
  10649. },
  10650. },
  10651. 10007: {
  10652. description: 'Соверши 1 призыв в Атриуме Душ', // ++++++++++++++++
  10653. doItCall: () => [{ name: 'gacha_open', args: { ident: 'heroGacha', free: true, pack: false }, ident: 'gacha_open' }],
  10654. isWeCanDo: () => {
  10655. const soulCrystal = this.questInfo['inventoryGet'].coin[38];
  10656. return soulCrystal > 0;
  10657. },
  10658. },
  10659. 10016: {
  10660. description: 'Отправь подарки согильдийцам', // ++++++++++++++++
  10661. doItCall: () => [{ name: 'clanSendDailyGifts', args: {}, ident: 'clanSendDailyGifts' }],
  10662. isWeCanDo: () => true,
  10663. },
  10664. 10018: {
  10665. description: 'Используй зелье опыта', // ++++++++++++++++
  10666. doItCall: () => {
  10667. const expHero = this.getExpHero();
  10668. return [
  10669. {
  10670. name: 'consumableUseHeroXp',
  10671. args: {
  10672. heroId: expHero.heroId,
  10673. libId: expHero.libId,
  10674. amount: 1,
  10675. },
  10676. ident: 'consumableUseHeroXp',
  10677. },
  10678. ];
  10679. },
  10680. isWeCanDo: () => {
  10681. const expHero = this.getExpHero();
  10682. return expHero.heroId && expHero.libId;
  10683. },
  10684. },
  10685. 10019: {
  10686. description: 'Открой 1 сундук в Башне',
  10687. doItFunc: testTower,
  10688. isWeCanDo: () => false,
  10689. },
  10690. 10020: {
  10691. description: 'Открой 3 сундука в Запределье', // Готово
  10692. doItCall: () => {
  10693. return this.getOutlandChest();
  10694. },
  10695. isWeCanDo: () => {
  10696. const outlandChest = this.getOutlandChest();
  10697. return outlandChest.length > 0;
  10698. },
  10699. },
  10700. 10021: {
  10701. description: 'Собери 75 Титанита в Подземелье Гильдии',
  10702. isWeCanDo: () => false,
  10703. },
  10704. 10022: {
  10705. description: 'Собери 150 Титанита в Подземелье Гильдии',
  10706. doItFunc: testDungeon,
  10707. isWeCanDo: () => false,
  10708. },
  10709. 10023: {
  10710. description: 'Прокачай Дар Стихий на 1 уровень', // Готово
  10711. doItCall: () => {
  10712. const heroId = this.getHeroIdTitanGift();
  10713. return [
  10714. { name: 'heroTitanGiftLevelUp', args: { heroId }, ident: 'heroTitanGiftLevelUp' },
  10715. { name: 'heroTitanGiftDrop', args: { heroId }, ident: 'heroTitanGiftDrop' },
  10716. ];
  10717. },
  10718. isWeCanDo: () => {
  10719. const heroId = this.getHeroIdTitanGift();
  10720. return heroId;
  10721. },
  10722. },
  10723. 10024: {
  10724. description: 'Повысь уровень любого артефакта один раз', // Готово
  10725. doItCall: () => {
  10726. const upArtifact = this.getUpgradeArtifact();
  10727. return [
  10728. {
  10729. name: 'heroArtifactLevelUp',
  10730. args: {
  10731. heroId: upArtifact.heroId,
  10732. slotId: upArtifact.slotId,
  10733. },
  10734. ident: `heroArtifactLevelUp`,
  10735. },
  10736. ];
  10737. },
  10738. isWeCanDo: () => {
  10739. const upgradeArtifact = this.getUpgradeArtifact();
  10740. return upgradeArtifact.heroId;
  10741. },
  10742. },
  10743. 10025: {
  10744. description: 'Начни 1 Экспедицию',
  10745. doItFunc: checkExpedition,
  10746. isWeCanDo: () => false,
  10747. },
  10748. 10026: {
  10749. description: 'Начни 4 Экспедиции', // --------------
  10750. doItFunc: checkExpedition,
  10751. isWeCanDo: () => false,
  10752. },
  10753. 10027: {
  10754. description: 'Победи в 1 бою Турнира Стихий',
  10755. doItFunc: testTitanArena,
  10756. isWeCanDo: () => false,
  10757. },
  10758. 10028: {
  10759. description: 'Повысь уровень любого артефакта титанов', // Готово
  10760. doItCall: () => {
  10761. const upTitanArtifact = this.getUpgradeTitanArtifact();
  10762. return [
  10763. {
  10764. name: 'titanArtifactLevelUp',
  10765. args: {
  10766. titanId: upTitanArtifact.titanId,
  10767. slotId: upTitanArtifact.slotId,
  10768. },
  10769. ident: `titanArtifactLevelUp`,
  10770. },
  10771. ];
  10772. },
  10773. isWeCanDo: () => {
  10774. const upgradeTitanArtifact = this.getUpgradeTitanArtifact();
  10775. return upgradeTitanArtifact.titanId;
  10776. },
  10777. },
  10778. 10029: {
  10779. description: 'Открой сферу артефактов титанов', // ++++++++++++++++
  10780. doItCall: () => [{ name: 'titanArtifactChestOpen', args: { amount: 1, free: true }, ident: 'titanArtifactChestOpen' }],
  10781. isWeCanDo: () => {
  10782. return this.questInfo['inventoryGet']?.consumable[55] > 0;
  10783. },
  10784. },
  10785. 10030: {
  10786. description: 'Улучши облик любого героя 1 раз', // Готово
  10787. doItCall: () => {
  10788. const upSkin = this.getUpgradeSkin();
  10789. return [
  10790. {
  10791. name: 'heroSkinUpgrade',
  10792. args: {
  10793. heroId: upSkin.heroId,
  10794. skinId: upSkin.skinId,
  10795. },
  10796. ident: `heroSkinUpgrade`,
  10797. },
  10798. ];
  10799. },
  10800. isWeCanDo: () => {
  10801. const upgradeSkin = this.getUpgradeSkin();
  10802. return upgradeSkin.heroId;
  10803. },
  10804. },
  10805. 10031: {
  10806. description: 'Победи в 6 боях Турнира Стихий', // --------------
  10807. doItFunc: testTitanArena,
  10808. isWeCanDo: () => false,
  10809. },
  10810. 10043: {
  10811. description: 'Начни или присоеденись к Приключению', // --------------
  10812. isWeCanDo: () => false,
  10813. },
  10814. 10044: {
  10815. description: 'Воспользуйся призывом питомцев 1 раз', // ++++++++++++++++
  10816. doItCall: () => [{ name: 'pet_chestOpen', args: { amount: 1, paid: false }, ident: 'pet_chestOpen' }],
  10817. isWeCanDo: () => {
  10818. return this.questInfo['inventoryGet']?.consumable[90] > 0;
  10819. },
  10820. },
  10821. 10046: {
  10822. /**
  10823. * TODO: Watch Adventure
  10824. * TODO: Смотреть приключение
  10825. */
  10826. description: 'Открой 3 сундука в Приключениях',
  10827. isWeCanDo: () => false,
  10828. },
  10829. 10047: {
  10830. description: 'Набери 150 очков активности в Гильдии', // Готово
  10831. doItCall: () => {
  10832. const enchantRune = this.getEnchantRune();
  10833. return [
  10834. {
  10835. name: 'heroEnchantRune',
  10836. args: {
  10837. heroId: enchantRune.heroId,
  10838. tier: enchantRune.tier,
  10839. items: {
  10840. consumable: { [enchantRune.itemId]: 1 },
  10841. },
  10842. },
  10843. ident: `heroEnchantRune`,
  10844. },
  10845. ];
  10846. },
  10847. isWeCanDo: () => {
  10848. const userInfo = this.questInfo['userGetInfo'];
  10849. const enchantRune = this.getEnchantRune();
  10850. return enchantRune.heroId && userInfo.gold > 1e3;
  10851. },
  10852. },
  10853. };
  10854.  
  10855. constructor(resolve, reject, questInfo) {
  10856. this.resolve = resolve;
  10857. this.reject = reject;
  10858. }
  10859.  
  10860. init(questInfo) {
  10861. this.questInfo = questInfo;
  10862. this.isAuto = false;
  10863. }
  10864.  
  10865. async autoInit(isAuto) {
  10866. this.isAuto = isAuto || false;
  10867. const quests = {};
  10868. const calls = this.callsList.map((name) => ({
  10869. name,
  10870. args: {},
  10871. ident: name,
  10872. }));
  10873. const result = await Send(JSON.stringify({ calls })).then((e) => e.results);
  10874. for (const call of result) {
  10875. quests[call.ident] = call.result.response;
  10876. }
  10877. this.questInfo = quests;
  10878. }
  10879.  
  10880. async start() {
  10881. const weCanDo = [];
  10882. const selectedActions = getSaveVal('selectedActions', {});
  10883. for (let quest of this.questInfo['questGetAll']) {
  10884. if (quest.id in this.dataQuests && quest.state == 1) {
  10885. if (!selectedActions[quest.id]) {
  10886. selectedActions[quest.id] = {
  10887. checked: false,
  10888. };
  10889. }
  10890.  
  10891. const isWeCanDo = this.dataQuests[quest.id].isWeCanDo;
  10892. if (!isWeCanDo.call(this)) {
  10893. continue;
  10894. }
  10895.  
  10896. weCanDo.push({
  10897. name: quest.id,
  10898. label: I18N(`QUEST_${quest.id}`),
  10899. checked: selectedActions[quest.id].checked,
  10900. });
  10901. }
  10902. }
  10903.  
  10904. if (!weCanDo.length) {
  10905. this.end(I18N('NOTHING_TO_DO'));
  10906. return;
  10907. }
  10908.  
  10909. console.log(weCanDo);
  10910. let taskList = [];
  10911. if (this.isAuto) {
  10912. taskList = weCanDo;
  10913. } else {
  10914. const answer = await popup.confirm(
  10915. `${I18N('YOU_CAN_COMPLETE')}:`,
  10916. [
  10917. { msg: I18N('BTN_DO_IT'), result: true },
  10918. { msg: I18N('BTN_CANCEL'), result: false, isCancel: true },
  10919. ],
  10920. weCanDo
  10921. );
  10922. if (!answer) {
  10923. this.end('');
  10924. return;
  10925. }
  10926. taskList = popup.getCheckBoxes();
  10927. taskList.forEach((e) => {
  10928. selectedActions[e.name].checked = e.checked;
  10929. });
  10930. setSaveVal('selectedActions', selectedActions);
  10931. }
  10932.  
  10933. const calls = [];
  10934. let countChecked = 0;
  10935. for (const task of taskList) {
  10936. if (task.checked) {
  10937. countChecked++;
  10938. const quest = this.dataQuests[task.name];
  10939. console.log(quest.description);
  10940.  
  10941. if (quest.doItCall) {
  10942. const doItCall = quest.doItCall.call(this);
  10943. calls.push(...doItCall);
  10944. }
  10945. }
  10946. }
  10947.  
  10948. if (!countChecked) {
  10949. this.end(I18N('NOT_QUEST_COMPLETED'));
  10950. return;
  10951. }
  10952.  
  10953. const result = await Send(JSON.stringify({ calls }));
  10954. if (result.error) {
  10955. console.error(result.error, result.error.call);
  10956. }
  10957. this.end(`${I18N('COMPLETED_QUESTS')}: ${countChecked}`);
  10958. }
  10959.  
  10960. errorHandling(error) {
  10961. //console.error(error);
  10962. let errorInfo = error.toString() + '\n';
  10963. try {
  10964. const errorStack = error.stack.split('\n');
  10965. const endStack = errorStack.map((e) => e.split('@')[0]).indexOf('testDoYourBest');
  10966. errorInfo += errorStack.slice(0, endStack).join('\n');
  10967. } catch (e) {
  10968. errorInfo += error.stack;
  10969. }
  10970. copyText(errorInfo);
  10971. }
  10972.  
  10973. skillCost(lvl) {
  10974. return 573 * lvl ** 0.9 + lvl ** 2.379;
  10975. }
  10976.  
  10977. getUpgradeSkills() {
  10978. const heroes = Object.values(this.questInfo['heroGetAll']);
  10979. const upgradeSkills = [
  10980. { heroId: 0, slotId: 0, value: 130 },
  10981. { heroId: 0, slotId: 0, value: 130 },
  10982. { heroId: 0, slotId: 0, value: 130 },
  10983. ];
  10984. const skillLib = lib.getData('skill');
  10985. /**
  10986. * color - 1 (белый) открывает 1 навык
  10987. * color - 2 (зеленый) открывает 2 навык
  10988. * color - 4 (синий) открывает 3 навык
  10989. * color - 7 (фиолетовый) открывает 4 навык
  10990. */
  10991. const colors = [1, 2, 4, 7];
  10992. for (const hero of heroes) {
  10993. const level = hero.level;
  10994. const color = hero.color;
  10995. for (let skillId in hero.skills) {
  10996. const tier = skillLib[skillId].tier;
  10997. const sVal = hero.skills[skillId];
  10998. if (color < colors[tier] || tier < 1 || tier > 4) {
  10999. continue;
  11000. }
  11001. for (let upSkill of upgradeSkills) {
  11002. if (sVal < upSkill.value && sVal < level) {
  11003. upSkill.value = sVal;
  11004. upSkill.heroId = hero.id;
  11005. upSkill.skill = tier;
  11006. break;
  11007. }
  11008. }
  11009. }
  11010. }
  11011. return upgradeSkills;
  11012. }
  11013.  
  11014. getUpgradeArtifact() {
  11015. const heroes = Object.values(this.questInfo['heroGetAll']);
  11016. const inventory = this.questInfo['inventoryGet'];
  11017. const upArt = { heroId: 0, slotId: 0, level: 100 };
  11018.  
  11019. const heroLib = lib.getData('hero');
  11020. const artifactLib = lib.getData('artifact');
  11021.  
  11022. for (const hero of heroes) {
  11023. const heroInfo = heroLib[hero.id];
  11024. const level = hero.level;
  11025. if (level < 20) {
  11026. continue;
  11027. }
  11028.  
  11029. for (let slotId in hero.artifacts) {
  11030. const art = hero.artifacts[slotId];
  11031. /* Текущая звезданость арта */
  11032. const star = art.star;
  11033. if (!star) {
  11034. continue;
  11035. }
  11036. /* Текущий уровень арта */
  11037. const level = art.level;
  11038. if (level >= 100) {
  11039. continue;
  11040. }
  11041. /* Идентификатор арта в библиотеке */
  11042. const artifactId = heroInfo.artifacts[slotId];
  11043. const artInfo = artifactLib.id[artifactId];
  11044. const costNextLevel = artifactLib.type[artInfo.type].levels[level + 1].cost;
  11045.  
  11046. const costCurrency = Object.keys(costNextLevel).pop();
  11047. const costValues = Object.entries(costNextLevel[costCurrency]).pop();
  11048. const costId = costValues[0];
  11049. const costValue = +costValues[1];
  11050.  
  11051. /** TODO: Возможно стоит искать самый высокий уровень который можно качнуть? */
  11052. if (level < upArt.level && inventory[costCurrency][costId] >= costValue) {
  11053. upArt.level = level;
  11054. upArt.heroId = hero.id;
  11055. upArt.slotId = slotId;
  11056. upArt.costCurrency = costCurrency;
  11057. upArt.costId = costId;
  11058. upArt.costValue = costValue;
  11059. }
  11060. }
  11061. }
  11062. return upArt;
  11063. }
  11064.  
  11065. getUpgradeSkin() {
  11066. const heroes = Object.values(this.questInfo['heroGetAll']);
  11067. const inventory = this.questInfo['inventoryGet'];
  11068. const upSkin = { heroId: 0, skinId: 0, level: 60, cost: 1500 };
  11069.  
  11070. const skinLib = lib.getData('skin');
  11071.  
  11072. for (const hero of heroes) {
  11073. const level = hero.level;
  11074. if (level < 20) {
  11075. continue;
  11076. }
  11077.  
  11078. for (let skinId in hero.skins) {
  11079. /* Текущий уровень скина */
  11080. const level = hero.skins[skinId];
  11081. if (level >= 60) {
  11082. continue;
  11083. }
  11084. /* Идентификатор скина в библиотеке */
  11085. const skinInfo = skinLib[skinId];
  11086. if (!skinInfo.statData.levels?.[level + 1]) {
  11087. continue;
  11088. }
  11089. const costNextLevel = skinInfo.statData.levels[level + 1].cost;
  11090.  
  11091. const costCurrency = Object.keys(costNextLevel).pop();
  11092. const costCurrencyId = Object.keys(costNextLevel[costCurrency]).pop();
  11093. const costValue = +costNextLevel[costCurrency][costCurrencyId];
  11094.  
  11095. /** TODO: Возможно стоит искать самый высокий уровень который можно качнуть? */
  11096. if (level < upSkin.level && costValue < upSkin.cost && inventory[costCurrency][costCurrencyId] >= costValue) {
  11097. upSkin.cost = costValue;
  11098. upSkin.level = level;
  11099. upSkin.heroId = hero.id;
  11100. upSkin.skinId = skinId;
  11101. upSkin.costCurrency = costCurrency;
  11102. upSkin.costCurrencyId = costCurrencyId;
  11103. }
  11104. }
  11105. }
  11106. return upSkin;
  11107. }
  11108.  
  11109. getUpgradeTitanArtifact() {
  11110. const titans = Object.values(this.questInfo['titanGetAll']);
  11111. const inventory = this.questInfo['inventoryGet'];
  11112. const userInfo = this.questInfo['userGetInfo'];
  11113. const upArt = { titanId: 0, slotId: 0, level: 120 };
  11114.  
  11115. const titanLib = lib.getData('titan');
  11116. const artTitanLib = lib.getData('titanArtifact');
  11117.  
  11118. for (const titan of titans) {
  11119. const titanInfo = titanLib[titan.id];
  11120. // const level = titan.level
  11121. // if (level < 20) {
  11122. // continue;
  11123. // }
  11124.  
  11125. for (let slotId in titan.artifacts) {
  11126. const art = titan.artifacts[slotId];
  11127. /* Текущая звезданость арта */
  11128. const star = art.star;
  11129. if (!star) {
  11130. continue;
  11131. }
  11132. /* Текущий уровень арта */
  11133. const level = art.level;
  11134. if (level >= 120) {
  11135. continue;
  11136. }
  11137. /* Идентификатор арта в библиотеке */
  11138. const artifactId = titanInfo.artifacts[slotId];
  11139. const artInfo = artTitanLib.id[artifactId];
  11140. const costNextLevel = artTitanLib.type[artInfo.type].levels[level + 1].cost;
  11141.  
  11142. const costCurrency = Object.keys(costNextLevel).pop();
  11143. let costValue = 0;
  11144. let currentValue = 0;
  11145. if (costCurrency == 'gold') {
  11146. costValue = costNextLevel[costCurrency];
  11147. currentValue = userInfo.gold;
  11148. } else {
  11149. const costValues = Object.entries(costNextLevel[costCurrency]).pop();
  11150. const costId = costValues[0];
  11151. costValue = +costValues[1];
  11152. currentValue = inventory[costCurrency][costId];
  11153. }
  11154.  
  11155. /** TODO: Возможно стоит искать самый высокий уровень который можно качнуть? */
  11156. if (level < upArt.level && currentValue >= costValue) {
  11157. upArt.level = level;
  11158. upArt.titanId = titan.id;
  11159. upArt.slotId = slotId;
  11160. break;
  11161. }
  11162. }
  11163. }
  11164. return upArt;
  11165. }
  11166.  
  11167. getEnchantRune() {
  11168. const heroes = Object.values(this.questInfo['heroGetAll']);
  11169. const inventory = this.questInfo['inventoryGet'];
  11170. const enchRune = { heroId: 0, tier: 0, exp: 43750, itemId: 0 };
  11171. for (let i = 1; i <= 4; i++) {
  11172. if (inventory.consumable[i] > 0) {
  11173. enchRune.itemId = i;
  11174. break;
  11175. }
  11176. return enchRune;
  11177. }
  11178.  
  11179. const runeLib = lib.getData('rune');
  11180. const runeLvls = Object.values(runeLib.level);
  11181. /**
  11182. * color - 4 (синий) открывает 1 и 2 символ
  11183. * color - 7 (фиолетовый) открывает 3 символ
  11184. * color - 8 (фиолетовый +1) открывает 4 символ
  11185. * color - 9 (фиолетовый +2) открывает 5 символ
  11186. */
  11187. // TODO: кажется надо учесть уровень команды
  11188. const colors = [4, 4, 7, 8, 9];
  11189. for (const hero of heroes) {
  11190. const color = hero.color;
  11191.  
  11192. for (let runeTier in hero.runes) {
  11193. /* Проверка на доступность руны */
  11194. if (color < colors[runeTier]) {
  11195. continue;
  11196. }
  11197. /* Текущий опыт руны */
  11198. const exp = hero.runes[runeTier];
  11199. if (exp >= 43750) {
  11200. continue;
  11201. }
  11202.  
  11203. let level = 0;
  11204. if (exp) {
  11205. for (let lvl of runeLvls) {
  11206. if (exp >= lvl.enchantValue) {
  11207. level = lvl.level;
  11208. } else {
  11209. break;
  11210. }
  11211. }
  11212. }
  11213. /** Уровень героя необходимый для уровня руны */
  11214. const heroLevel = runeLib.level[level].heroLevel;
  11215. if (hero.level < heroLevel) {
  11216. continue;
  11217. }
  11218.  
  11219. /** TODO: Возможно стоит искать самый высокий уровень который можно качнуть? */
  11220. if (exp < enchRune.exp) {
  11221. enchRune.exp = exp;
  11222. enchRune.heroId = hero.id;
  11223. enchRune.tier = runeTier;
  11224. break;
  11225. }
  11226. }
  11227. }
  11228. return enchRune;
  11229. }
  11230.  
  11231. getOutlandChest() {
  11232. const bosses = this.questInfo['bossGetAll'];
  11233.  
  11234. const calls = [];
  11235.  
  11236. for (let boss of bosses) {
  11237. if (boss.mayRaid) {
  11238. calls.push({
  11239. name: 'bossRaid',
  11240. args: {
  11241. bossId: boss.id,
  11242. },
  11243. ident: 'bossRaid_' + boss.id,
  11244. });
  11245. calls.push({
  11246. name: 'bossOpenChest',
  11247. args: {
  11248. bossId: boss.id,
  11249. amount: 1,
  11250. starmoney: 0,
  11251. },
  11252. ident: 'bossOpenChest_' + boss.id,
  11253. });
  11254. } else if (boss.chestId == 1) {
  11255. calls.push({
  11256. name: 'bossOpenChest',
  11257. args: {
  11258. bossId: boss.id,
  11259. amount: 1,
  11260. starmoney: 0,
  11261. },
  11262. ident: 'bossOpenChest_' + boss.id,
  11263. });
  11264. }
  11265. }
  11266.  
  11267. return calls;
  11268. }
  11269.  
  11270. getExpHero() {
  11271. const heroes = Object.values(this.questInfo['heroGetAll']);
  11272. const inventory = this.questInfo['inventoryGet'];
  11273. const expHero = { heroId: 0, exp: 3625195, libId: 0 };
  11274. /** зелья опыта (consumable 9, 10, 11, 12) */
  11275. for (let i = 9; i <= 12; i++) {
  11276. if (inventory.consumable[i]) {
  11277. expHero.libId = i;
  11278. break;
  11279. }
  11280. }
  11281.  
  11282. for (const hero of heroes) {
  11283. const exp = hero.xp;
  11284. if (exp < expHero.exp) {
  11285. expHero.heroId = hero.id;
  11286. }
  11287. }
  11288. return expHero;
  11289. }
  11290.  
  11291. getHeroIdTitanGift() {
  11292. const heroes = Object.values(this.questInfo['heroGetAll']);
  11293. const inventory = this.questInfo['inventoryGet'];
  11294. const user = this.questInfo['userGetInfo'];
  11295. const titanGiftLib = lib.getData('titanGift');
  11296. /** Искры */
  11297. const titanGift = inventory.consumable[24];
  11298. let heroId = 0;
  11299. let minLevel = 30;
  11300.  
  11301. if (titanGift < 250 || user.gold < 7000) {
  11302. return 0;
  11303. }
  11304.  
  11305. for (const hero of heroes) {
  11306. if (hero.titanGiftLevel >= 30) {
  11307. continue;
  11308. }
  11309.  
  11310. if (!hero.titanGiftLevel) {
  11311. return hero.id;
  11312. }
  11313.  
  11314. const cost = titanGiftLib[hero.titanGiftLevel].cost;
  11315. if (minLevel > hero.titanGiftLevel && titanGift >= cost.consumable[24] && user.gold >= cost.gold) {
  11316. minLevel = hero.titanGiftLevel;
  11317. heroId = hero.id;
  11318. }
  11319. }
  11320.  
  11321. return heroId;
  11322. }
  11323.  
  11324. getHeroicMissionId() {
  11325. // Получаем доступные миссии с 3 звездами
  11326. const availableMissionsToRaid = Object.values(this.questInfo.missionGetAll)
  11327. .filter((mission) => mission.stars === 3)
  11328. .map((mission) => mission.id);
  11329.  
  11330. // Получаем героев для улучшения, у которых меньше 6 звезд
  11331. const heroesToUpgrade = Object.values(this.questInfo.heroGetAll)
  11332. .filter((hero) => hero.star < 6)
  11333. .sort((a, b) => b.power - a.power)
  11334. .map((hero) => hero.id);
  11335.  
  11336. // Получаем героические миссии, которые доступны для рейдов
  11337. const heroicMissions = Object.values(lib.data.mission).filter((mission) => mission.isHeroic && availableMissionsToRaid.includes(mission.id));
  11338.  
  11339. // Собираем дропы из героических миссий
  11340. const drops = heroicMissions.map((mission) => {
  11341. const lastWave = mission.normalMode.waves[mission.normalMode.waves.length - 1];
  11342. const allRewards = lastWave.enemies[lastWave.enemies.length - 1]
  11343. .drop.map((drop) => drop.reward);
  11344.  
  11345. const heroId = +Object.keys(allRewards.find((reward) => reward.fragmentHero).fragmentHero).pop();
  11346.  
  11347. return { id: mission.id, heroId };
  11348. });
  11349.  
  11350. // Определяем, какие дропы подходят для героев, которых нужно улучшить
  11351. const heroDrops = heroesToUpgrade.map((heroId) => drops.find((drop) => drop.heroId == heroId)).filter((drop) => drop);
  11352. const firstMission = heroDrops[0];
  11353. // Выбираем миссию для рейда
  11354. const selectedMissionId = firstMission ? firstMission.id : 1;
  11355.  
  11356. const stamina = this.questInfo.userGetInfo.refillable.find((x) => x.id == 1).amount;
  11357. const costMissions = 3 * lib.data.mission[selectedMissionId].normalMode.teamExp;
  11358. if (stamina < costMissions) {
  11359. console.log('Энергии не достаточно');
  11360. return 0;
  11361. }
  11362. return selectedMissionId;
  11363. }
  11364.  
  11365. end(status) {
  11366. setProgress(status, true);
  11367. this.resolve();
  11368. }
  11369. }
  11370.  
  11371. this.questRun = dailyQuests;
  11372. this.HWHClasses.dailyQuests = dailyQuests;
  11373.  
  11374. function testDoYourBest() {
  11375. const { doYourBest } = HWHClasses;
  11376. return new Promise((resolve, reject) => {
  11377. const doIt = new doYourBest(resolve, reject);
  11378. doIt.start();
  11379. });
  11380. }
  11381.  
  11382. /**
  11383. * Do everything button
  11384. *
  11385. * Кнопка сделать все
  11386. */
  11387. class doYourBest {
  11388.  
  11389. funcList = [
  11390. {
  11391. name: 'getOutland',
  11392. label: I18N('ASSEMBLE_OUTLAND'),
  11393. checked: false
  11394. },
  11395. {
  11396. name: 'testTower',
  11397. label: I18N('PASS_THE_TOWER'),
  11398. checked: false
  11399. },
  11400. {
  11401. name: 'checkExpedition',
  11402. label: I18N('CHECK_EXPEDITIONS'),
  11403. checked: false
  11404. },
  11405. {
  11406. name: 'testTitanArena',
  11407. label: I18N('COMPLETE_TOE'),
  11408. checked: false
  11409. },
  11410. {
  11411. name: 'mailGetAll',
  11412. label: I18N('COLLECT_MAIL'),
  11413. checked: false
  11414. },
  11415. {
  11416. name: 'collectAllStuff',
  11417. label: I18N('COLLECT_MISC'),
  11418. title: I18N('COLLECT_MISC_TITLE'),
  11419. checked: false
  11420. },
  11421. {
  11422. name: 'getDailyBonus',
  11423. label: I18N('DAILY_BONUS'),
  11424. checked: false
  11425. },
  11426. {
  11427. name: 'dailyQuests',
  11428. label: I18N('DO_DAILY_QUESTS'),
  11429. checked: false
  11430. },
  11431. {
  11432. name: 'rollAscension',
  11433. label: I18N('SEER_TITLE'),
  11434. checked: false
  11435. },
  11436. {
  11437. name: 'questAllFarm',
  11438. label: I18N('COLLECT_QUEST_REWARDS'),
  11439. checked: false
  11440. },
  11441. {
  11442. name: 'testDungeon',
  11443. label: I18N('COMPLETE_DUNGEON'),
  11444. checked: false
  11445. },
  11446. {
  11447. name: 'synchronization',
  11448. label: I18N('MAKE_A_SYNC'),
  11449. checked: false
  11450. },
  11451. {
  11452. name: 'reloadGame',
  11453. label: I18N('RELOAD_GAME'),
  11454. checked: false
  11455. },
  11456. ];
  11457.  
  11458. functions = {
  11459. getOutland,
  11460. testTower,
  11461. checkExpedition,
  11462. testTitanArena,
  11463. mailGetAll,
  11464. collectAllStuff: async () => {
  11465. await offerFarmAllReward();
  11466. await Send('{"calls":[{"name":"subscriptionFarm","args":{},"ident":"body"},{"name":"zeppelinGiftFarm","args":{},"ident":"zeppelinGiftFarm"},{"name":"grandFarmCoins","args":{},"ident":"grandFarmCoins"},{"name":"gacha_refill","args":{"ident":"heroGacha"},"ident":"gacha_refill"}]}');
  11467. },
  11468. dailyQuests: async function () {
  11469. const quests = new dailyQuests(() => { }, () => { });
  11470. await quests.autoInit(true);
  11471. await quests.start();
  11472. },
  11473. rollAscension,
  11474. getDailyBonus,
  11475. questAllFarm,
  11476. testDungeon,
  11477. synchronization: async () => {
  11478. cheats.refreshGame();
  11479. },
  11480. reloadGame: async () => {
  11481. location.reload();
  11482. },
  11483. }
  11484.  
  11485. constructor(resolve, reject, questInfo) {
  11486. this.resolve = resolve;
  11487. this.reject = reject;
  11488. this.questInfo = questInfo
  11489. }
  11490.  
  11491. async start() {
  11492. const selectedDoIt = getSaveVal('selectedDoIt', {});
  11493.  
  11494. this.funcList.forEach(task => {
  11495. if (!selectedDoIt[task.name]) {
  11496. selectedDoIt[task.name] = {
  11497. checked: task.checked
  11498. }
  11499. } else {
  11500. task.checked = selectedDoIt[task.name].checked
  11501. }
  11502. });
  11503.  
  11504. const answer = await popup.confirm(I18N('RUN_FUNCTION'), [
  11505. { msg: I18N('BTN_CANCEL'), result: false, isCancel: true },
  11506. { msg: I18N('BTN_GO'), result: true },
  11507. ], this.funcList);
  11508.  
  11509. if (!answer) {
  11510. this.end('');
  11511. return;
  11512. }
  11513.  
  11514. const taskList = popup.getCheckBoxes();
  11515. taskList.forEach(task => {
  11516. selectedDoIt[task.name].checked = task.checked;
  11517. });
  11518. setSaveVal('selectedDoIt', selectedDoIt);
  11519. for (const task of popup.getCheckBoxes()) {
  11520. if (task.checked) {
  11521. try {
  11522. setProgress(`${task.label} <br>${I18N('PERFORMED')}!`);
  11523. await this.functions[task.name]();
  11524. setProgress(`${task.label} <br>${I18N('DONE')}!`);
  11525. } catch (error) {
  11526. if (await popup.confirm(`${I18N('ERRORS_OCCURRES')}:<br> ${task.label} <br>${I18N('COPY_ERROR')}?`, [
  11527. { msg: I18N('BTN_NO'), result: false },
  11528. { msg: I18N('BTN_YES'), result: true },
  11529. ])) {
  11530. this.errorHandling(error);
  11531. }
  11532. }
  11533. }
  11534. }
  11535. setTimeout((msg) => {
  11536. this.end(msg);
  11537. }, 2000, I18N('ALL_TASK_COMPLETED'));
  11538. return;
  11539. }
  11540.  
  11541. errorHandling(error) {
  11542. //console.error(error);
  11543. let errorInfo = error.toString() + '\n';
  11544. try {
  11545. const errorStack = error.stack.split('\n');
  11546. const endStack = errorStack.map(e => e.split('@')[0]).indexOf("testDoYourBest");
  11547. errorInfo += errorStack.slice(0, endStack).join('\n');
  11548. } catch (e) {
  11549. errorInfo += error.stack;
  11550. }
  11551. copyText(errorInfo);
  11552. }
  11553.  
  11554. end(status) {
  11555. setProgress(status, true);
  11556. this.resolve();
  11557. }
  11558. }
  11559.  
  11560. this.HWHClasses.doYourBest = doYourBest;
  11561.  
  11562. /**
  11563. * Passing the adventure along the specified route
  11564. *
  11565. * Прохождение приключения по указанному маршруту
  11566. */
  11567. function testAdventure(type) {
  11568. const { executeAdventure } = HWHClasses;
  11569. return new Promise((resolve, reject) => {
  11570. const bossBattle = new executeAdventure(resolve, reject);
  11571. bossBattle.start(type);
  11572. });
  11573. }
  11574.  
  11575. /**
  11576. * Passing the adventure along the specified route
  11577. *
  11578. * Прохождение приключения по указанному маршруту
  11579. */
  11580. class executeAdventure {
  11581.  
  11582. type = 'default';
  11583.  
  11584. actions = {
  11585. default: {
  11586. getInfo: "adventure_getInfo",
  11587. startBattle: 'adventure_turnStartBattle',
  11588. endBattle: 'adventure_endBattle',
  11589. collectBuff: 'adventure_turnCollectBuff'
  11590. },
  11591. solo: {
  11592. getInfo: "adventureSolo_getInfo",
  11593. startBattle: 'adventureSolo_turnStartBattle',
  11594. endBattle: 'adventureSolo_endBattle',
  11595. collectBuff: 'adventureSolo_turnCollectBuff'
  11596. }
  11597. }
  11598.  
  11599. terminatеReason = I18N('UNKNOWN');
  11600. callAdventureInfo = {
  11601. name: "adventure_getInfo",
  11602. args: {},
  11603. ident: "adventure_getInfo"
  11604. }
  11605. callTeamGetAll = {
  11606. name: "teamGetAll",
  11607. args: {},
  11608. ident: "teamGetAll"
  11609. }
  11610. callTeamGetFavor = {
  11611. name: "teamGetFavor",
  11612. args: {},
  11613. ident: "teamGetFavor"
  11614. }
  11615. callStartBattle = {
  11616. name: "adventure_turnStartBattle",
  11617. args: {},
  11618. ident: "body"
  11619. }
  11620. callEndBattle = {
  11621. name: "adventure_endBattle",
  11622. args: {
  11623. result: {},
  11624. progress: {},
  11625. },
  11626. ident: "body"
  11627. }
  11628. callCollectBuff = {
  11629. name: "adventure_turnCollectBuff",
  11630. args: {},
  11631. ident: "body"
  11632. }
  11633.  
  11634. constructor(resolve, reject) {
  11635. this.resolve = resolve;
  11636. this.reject = reject;
  11637. }
  11638.  
  11639. async start(type) {
  11640. this.type = type || this.type;
  11641. this.callAdventureInfo.name = this.actions[this.type].getInfo;
  11642. const data = await Send(JSON.stringify({
  11643. calls: [
  11644. this.callAdventureInfo,
  11645. this.callTeamGetAll,
  11646. this.callTeamGetFavor
  11647. ]
  11648. }));
  11649. return this.checkAdventureInfo(data.results);
  11650. }
  11651.  
  11652. async getPath() {
  11653. const oldVal = getSaveVal('adventurePath', '');
  11654. const keyPath = `adventurePath:${this.mapIdent}`;
  11655. const answer = await popup.confirm(I18N('ENTER_THE_PATH'), [
  11656. {
  11657. msg: I18N('START_ADVENTURE'),
  11658. placeholder: '1,2,3,4,5,6',
  11659. isInput: true,
  11660. default: getSaveVal(keyPath, oldVal)
  11661. },
  11662. {
  11663. msg: I18N('BTN_CANCEL'),
  11664. result: false,
  11665. isCancel: true
  11666. },
  11667. ]);
  11668. if (!answer) {
  11669. this.terminatеReason = I18N('BTN_CANCELED');
  11670. return false;
  11671. }
  11672.  
  11673. let path = answer.split(',');
  11674. if (path.length < 2) {
  11675. path = answer.split('-');
  11676. }
  11677. if (path.length < 2) {
  11678. this.terminatеReason = I18N('MUST_TWO_POINTS');
  11679. return false;
  11680. }
  11681.  
  11682. for (let p in path) {
  11683. path[p] = +path[p].trim()
  11684. if (Number.isNaN(path[p])) {
  11685. this.terminatеReason = I18N('MUST_ONLY_NUMBERS');
  11686. return false;
  11687. }
  11688. }
  11689.  
  11690. if (!this.checkPath(path)) {
  11691. return false;
  11692. }
  11693. setSaveVal(keyPath, answer);
  11694. return path;
  11695. }
  11696.  
  11697. checkPath(path) {
  11698. for (let i = 0; i < path.length - 1; i++) {
  11699. const currentPoint = path[i];
  11700. const nextPoint = path[i + 1];
  11701.  
  11702. const isValidPath = this.paths.some(p =>
  11703. (p.from_id === currentPoint && p.to_id === nextPoint) ||
  11704. (p.from_id === nextPoint && p.to_id === currentPoint)
  11705. );
  11706.  
  11707. if (!isValidPath) {
  11708. this.terminatеReason = I18N('INCORRECT_WAY', {
  11709. from: currentPoint,
  11710. to: nextPoint,
  11711. });
  11712. return false;
  11713. }
  11714. }
  11715.  
  11716. return true;
  11717. }
  11718.  
  11719. async checkAdventureInfo(data) {
  11720. this.advInfo = data[0].result.response;
  11721. if (!this.advInfo) {
  11722. this.terminatеReason = I18N('NOT_ON_AN_ADVENTURE') ;
  11723. return this.end();
  11724. }
  11725. const heroesTeam = data[1].result.response.adventure_hero;
  11726. const favor = data[2]?.result.response.adventure_hero;
  11727. const heroes = heroesTeam.slice(0, 5);
  11728. const pet = heroesTeam[5];
  11729. this.args = {
  11730. pet,
  11731. heroes,
  11732. favor,
  11733. path: [],
  11734. broadcast: false
  11735. }
  11736. const advUserInfo = this.advInfo.users[userInfo.id];
  11737. this.turnsLeft = advUserInfo.turnsLeft;
  11738. this.currentNode = advUserInfo.currentNode;
  11739. this.nodes = this.advInfo.nodes;
  11740. this.paths = this.advInfo.paths;
  11741. this.mapIdent = this.advInfo.mapIdent;
  11742.  
  11743. this.path = await this.getPath();
  11744. if (!this.path) {
  11745. return this.end();
  11746. }
  11747.  
  11748. if (this.currentNode == 1 && this.path[0] != 1) {
  11749. this.path.unshift(1);
  11750. }
  11751.  
  11752. return this.loop();
  11753. }
  11754.  
  11755. async loop() {
  11756. const position = this.path.indexOf(+this.currentNode);
  11757. if (!(~position)) {
  11758. this.terminatеReason = I18N('YOU_IN_NOT_ON_THE_WAY');
  11759. return this.end();
  11760. }
  11761. this.path = this.path.slice(position);
  11762. if ((this.path.length - 1) > this.turnsLeft &&
  11763. await popup.confirm(I18N('ATTEMPTS_NOT_ENOUGH'), [
  11764. { msg: I18N('YES_CONTINUE'), result: false },
  11765. { msg: I18N('BTN_NO'), result: true },
  11766. ])) {
  11767. this.terminatеReason = I18N('NOT_ENOUGH_AP');
  11768. return this.end();
  11769. }
  11770. const toPath = [];
  11771. for (const nodeId of this.path) {
  11772. if (!this.turnsLeft) {
  11773. this.terminatеReason = I18N('ATTEMPTS_ARE_OVER');
  11774. return this.end();
  11775. }
  11776. toPath.push(nodeId);
  11777. console.log(toPath);
  11778. if (toPath.length > 1) {
  11779. setProgress(toPath.join(' > ') + ` ${I18N('MOVES')}: ` + this.turnsLeft);
  11780. }
  11781. if (nodeId == this.currentNode) {
  11782. continue;
  11783. }
  11784.  
  11785. const nodeInfo = this.getNodeInfo(nodeId);
  11786. if (nodeInfo.type == 'TYPE_COMBAT') {
  11787. if (nodeInfo.state == 'empty') {
  11788. this.turnsLeft--;
  11789. continue;
  11790. }
  11791.  
  11792. /**
  11793. * Disable regular battle cancellation
  11794. *
  11795. * Отключаем штатную отменую боя
  11796. */
  11797. setIsCancalBattle(false);
  11798. if (await this.battle(toPath)) {
  11799. this.turnsLeft--;
  11800. toPath.splice(0, toPath.indexOf(nodeId));
  11801. nodeInfo.state = 'empty';
  11802. setIsCancalBattle(true);
  11803. continue;
  11804. }
  11805. setIsCancalBattle(true);
  11806. return this.end()
  11807. }
  11808.  
  11809. if (nodeInfo.type == 'TYPE_PLAYERBUFF') {
  11810. const buff = this.checkBuff(nodeInfo);
  11811. if (buff == null) {
  11812. continue;
  11813. }
  11814.  
  11815. if (await this.collectBuff(buff, toPath)) {
  11816. this.turnsLeft--;
  11817. toPath.splice(0, toPath.indexOf(nodeId));
  11818. continue;
  11819. }
  11820. this.terminatеReason = I18N('BUFF_GET_ERROR');
  11821. return this.end();
  11822. }
  11823. }
  11824. this.terminatеReason = I18N('SUCCESS');
  11825. return this.end();
  11826. }
  11827.  
  11828. /**
  11829. * Carrying out a fight
  11830. *
  11831. * Проведение боя
  11832. */
  11833. async battle(path, preCalc = true) {
  11834. const data = await this.startBattle(path);
  11835. try {
  11836. const battle = data.results[0].result.response.battle;
  11837. const result = await Calc(battle);
  11838. if (result.result.win) {
  11839. const info = await this.endBattle(result);
  11840. if (info.results[0].result.response?.error) {
  11841. this.terminatеReason = I18N('BATTLE_END_ERROR');
  11842. return false;
  11843. }
  11844. } else {
  11845. await this.cancelBattle(result);
  11846.  
  11847. if (preCalc && await this.preCalcBattle(battle)) {
  11848. path = path.slice(-2);
  11849. for (let i = 1; i <= getInput('countAutoBattle'); i++) {
  11850. setProgress(`${I18N('AUTOBOT')}: ${i}/${getInput('countAutoBattle')}`);
  11851. const result = await this.battle(path, false);
  11852. if (result) {
  11853. setProgress(I18N('VICTORY'));
  11854. return true;
  11855. }
  11856. }
  11857. this.terminatеReason = I18N('FAILED_TO_WIN_AUTO');
  11858. return false;
  11859. }
  11860. return false;
  11861. }
  11862. } catch (error) {
  11863. console.error(error);
  11864. if (await popup.confirm(I18N('ERROR_OF_THE_BATTLE_COPY'), [
  11865. { msg: I18N('BTN_NO'), result: false },
  11866. { msg: I18N('BTN_YES'), result: true },
  11867. ])) {
  11868. this.errorHandling(error, data);
  11869. }
  11870. this.terminatеReason = I18N('ERROR_DURING_THE_BATTLE');
  11871. return false;
  11872. }
  11873. return true;
  11874. }
  11875.  
  11876. /**
  11877. * Recalculate battles
  11878. *
  11879. * Прерасчтет битвы
  11880. */
  11881. async preCalcBattle(battle) {
  11882. const countTestBattle = getInput('countTestBattle');
  11883. for (let i = 0; i < countTestBattle; i++) {
  11884. battle.seed = Math.floor(Date.now() / 1000) + random(0, 1e3);
  11885. const result = await Calc(battle);
  11886. if (result.result.win) {
  11887. console.log(i, countTestBattle);
  11888. return true;
  11889. }
  11890. }
  11891. this.terminatеReason = I18N('NO_CHANCE_WIN') + countTestBattle;
  11892. return false;
  11893. }
  11894.  
  11895. /**
  11896. * Starts a fight
  11897. *
  11898. * Начинает бой
  11899. */
  11900. startBattle(path) {
  11901. this.args.path = path;
  11902. this.callStartBattle.name = this.actions[this.type].startBattle;
  11903. this.callStartBattle.args = this.args
  11904. const calls = [this.callStartBattle];
  11905. return Send(JSON.stringify({ calls }));
  11906. }
  11907.  
  11908. cancelBattle(battle) {
  11909. const fixBattle = function (heroes) {
  11910. for (const ids in heroes) {
  11911. const hero = heroes[ids];
  11912. hero.energy = random(1, 999);
  11913. if (hero.hp > 0) {
  11914. hero.hp = random(1, hero.hp);
  11915. }
  11916. }
  11917. }
  11918. fixBattle(battle.progress[0].attackers.heroes);
  11919. fixBattle(battle.progress[0].defenders.heroes);
  11920. return this.endBattle(battle);
  11921. }
  11922.  
  11923. /**
  11924. * Ends the fight
  11925. *
  11926. * Заканчивает бой
  11927. */
  11928. endBattle(battle) {
  11929. this.callEndBattle.name = this.actions[this.type].endBattle;
  11930. this.callEndBattle.args.result = battle.result
  11931. this.callEndBattle.args.progress = battle.progress
  11932. const calls = [this.callEndBattle];
  11933. return Send(JSON.stringify({ calls }));
  11934. }
  11935.  
  11936. /**
  11937. * Checks if you can get a buff
  11938. *
  11939. * Проверяет можно ли получить баф
  11940. */
  11941. checkBuff(nodeInfo) {
  11942. let id = null;
  11943. let value = 0;
  11944. for (const buffId in nodeInfo.buffs) {
  11945. const buff = nodeInfo.buffs[buffId];
  11946. if (buff.owner == null && buff.value > value) {
  11947. id = buffId;
  11948. value = buff.value;
  11949. }
  11950. }
  11951. nodeInfo.buffs[id].owner = 'Я';
  11952. return id;
  11953. }
  11954.  
  11955. /**
  11956. * Collects a buff
  11957. *
  11958. * Собирает баф
  11959. */
  11960. async collectBuff(buff, path) {
  11961. this.callCollectBuff.name = this.actions[this.type].collectBuff;
  11962. this.callCollectBuff.args = { buff, path };
  11963. const calls = [this.callCollectBuff];
  11964. return Send(JSON.stringify({ calls }));
  11965. }
  11966.  
  11967. getNodeInfo(nodeId) {
  11968. return this.nodes.find(node => node.id == nodeId);
  11969. }
  11970.  
  11971. errorHandling(error, data) {
  11972. //console.error(error);
  11973. let errorInfo = error.toString() + '\n';
  11974. try {
  11975. const errorStack = error.stack.split('\n');
  11976. const endStack = errorStack.map(e => e.split('@')[0]).indexOf("testAdventure");
  11977. errorInfo += errorStack.slice(0, endStack).join('\n');
  11978. } catch (e) {
  11979. errorInfo += error.stack;
  11980. }
  11981. if (data) {
  11982. errorInfo += '\nData: ' + JSON.stringify(data);
  11983. }
  11984. copyText(errorInfo);
  11985. }
  11986.  
  11987. end() {
  11988. setIsCancalBattle(true);
  11989. setProgress(this.terminatеReason, true);
  11990. console.log(this.terminatеReason);
  11991. this.resolve();
  11992. }
  11993. }
  11994.  
  11995. this.HWHClasses.executeAdventure = executeAdventure;
  11996.  
  11997. /**
  11998. * Passage of brawls
  11999. *
  12000. * Прохождение потасовок
  12001. */
  12002. function testBrawls(isAuto) {
  12003. const { executeBrawls } = HWHClasses;
  12004. return new Promise((resolve, reject) => {
  12005. const brawls = new executeBrawls(resolve, reject);
  12006. brawls.start(brawlsPack, isAuto);
  12007. });
  12008. }
  12009. /**
  12010. * Passage of brawls
  12011. *
  12012. * Прохождение потасовок
  12013. */
  12014. class executeBrawls {
  12015. callBrawlQuestGetInfo = {
  12016. name: "brawl_questGetInfo",
  12017. args: {},
  12018. ident: "brawl_questGetInfo"
  12019. }
  12020. callBrawlFindEnemies = {
  12021. name: "brawl_findEnemies",
  12022. args: {},
  12023. ident: "brawl_findEnemies"
  12024. }
  12025. callBrawlQuestFarm = {
  12026. name: "brawl_questFarm",
  12027. args: {},
  12028. ident: "brawl_questFarm"
  12029. }
  12030. callUserGetInfo = {
  12031. name: "userGetInfo",
  12032. args: {},
  12033. ident: "userGetInfo"
  12034. }
  12035. callTeamGetMaxUpgrade = {
  12036. name: "teamGetMaxUpgrade",
  12037. args: {},
  12038. ident: "teamGetMaxUpgrade"
  12039. }
  12040. callBrawlGetInfo = {
  12041. name: "brawl_getInfo",
  12042. args: {},
  12043. ident: "brawl_getInfo"
  12044. }
  12045.  
  12046. stats = {
  12047. win: 0,
  12048. loss: 0,
  12049. count: 0,
  12050. }
  12051.  
  12052. stage = {
  12053. '3': 1,
  12054. '7': 2,
  12055. '12': 3,
  12056. }
  12057.  
  12058. attempts = 0;
  12059.  
  12060. constructor(resolve, reject) {
  12061. this.resolve = resolve;
  12062. this.reject = reject;
  12063.  
  12064. const allHeroIds = Object.keys(lib.getData('hero'));
  12065. this.callTeamGetMaxUpgrade.args.units = {
  12066. hero: allHeroIds.filter((id) => +id < 1000),
  12067. titan: allHeroIds.filter((id) => +id >= 4000 && +id < 4100),
  12068. pet: allHeroIds.filter((id) => +id >= 6000 && +id < 6100),
  12069. };
  12070. }
  12071.  
  12072. async start(args, isAuto) {
  12073. this.isAuto = isAuto;
  12074. this.args = args;
  12075. setIsCancalBattle(false);
  12076. this.brawlInfo = await this.getBrawlInfo();
  12077. this.attempts = this.brawlInfo.attempts;
  12078.  
  12079. if (!this.attempts && !this.info.boughtEndlessLivesToday) {
  12080. this.end(I18N('DONT_HAVE_LIVES'));
  12081. return;
  12082. }
  12083.  
  12084. while (1) {
  12085. if (!isBrawlsAutoStart) {
  12086. this.end(I18N('BTN_CANCELED'));
  12087. return;
  12088. }
  12089.  
  12090. const maxStage = this.brawlInfo.questInfo.stage;
  12091. const stage = this.stage[maxStage];
  12092. const progress = this.brawlInfo.questInfo.progress;
  12093.  
  12094. setProgress(
  12095. `${I18N('STAGE')} ${stage}: ${progress}/${maxStage}<br>${I18N('FIGHTS')}: ${this.stats.count}<br>${I18N('WINS')}: ${
  12096. this.stats.win
  12097. }<br>${I18N('LOSSES')}: ${this.stats.loss}<br>${I18N('LIVES')}: ${this.attempts}<br>${I18N('STOP')}`,
  12098. false,
  12099. function () {
  12100. isBrawlsAutoStart = false;
  12101. }
  12102. );
  12103.  
  12104. if (this.brawlInfo.questInfo.canFarm) {
  12105. const result = await this.questFarm();
  12106. console.log(result);
  12107. }
  12108.  
  12109. if (!this.continueAttack && this.brawlInfo.questInfo.stage == 12 && this.brawlInfo.questInfo.progress == 12) {
  12110. if (
  12111. await popup.confirm(I18N('BRAWL_DAILY_TASK_COMPLETED'), [
  12112. { msg: I18N('BTN_NO'), result: true },
  12113. { msg: I18N('BTN_YES'), result: false },
  12114. ])
  12115. ) {
  12116. this.end(I18N('SUCCESS'));
  12117. return;
  12118. } else {
  12119. this.continueAttack = true;
  12120. }
  12121. }
  12122.  
  12123. if (!this.attempts && !this.info.boughtEndlessLivesToday) {
  12124. this.end(I18N('DONT_HAVE_LIVES'));
  12125. return;
  12126. }
  12127.  
  12128. const enemie = Object.values(this.brawlInfo.findEnemies).shift();
  12129.  
  12130. // Автоматический подбор пачки
  12131. if (this.isAuto) {
  12132. if (this.mandatoryId <= 4000 && this.mandatoryId != 13) {
  12133. this.end(I18N('BRAWL_AUTO_PACK_NOT_CUR_HERO'));
  12134. return;
  12135. }
  12136. if (this.mandatoryId >= 4000 && this.mandatoryId < 4100) {
  12137. this.args = await this.updateTitanPack(enemie.heroes);
  12138. } else if (this.mandatoryId < 4000 && this.mandatoryId == 13) {
  12139. this.args = await this.updateHeroesPack(enemie.heroes);
  12140. }
  12141. }
  12142.  
  12143. const result = await this.battle(enemie.userId);
  12144. this.brawlInfo = {
  12145. questInfo: result[1].result.response,
  12146. findEnemies: result[2].result.response,
  12147. };
  12148. }
  12149. }
  12150.  
  12151. async updateTitanPack(enemieHeroes) {
  12152. const packs = [
  12153. [4033, 4040, 4041, 4042, 4043],
  12154. [4032, 4040, 4041, 4042, 4043],
  12155. [4031, 4040, 4041, 4042, 4043],
  12156. [4030, 4040, 4041, 4042, 4043],
  12157. [4032, 4033, 4040, 4042, 4043],
  12158. [4030, 4033, 4041, 4042, 4043],
  12159. [4031, 4033, 4040, 4042, 4043],
  12160. [4032, 4033, 4040, 4041, 4043],
  12161. [4023, 4040, 4041, 4042, 4043],
  12162. [4030, 4033, 4040, 4042, 4043],
  12163. [4031, 4033, 4040, 4041, 4043],
  12164. [4022, 4040, 4041, 4042, 4043],
  12165. [4030, 4033, 4040, 4041, 4043],
  12166. [4021, 4040, 4041, 4042, 4043],
  12167. [4020, 4040, 4041, 4042, 4043],
  12168. [4023, 4033, 4040, 4042, 4043],
  12169. [4030, 4032, 4033, 4042, 4043],
  12170. [4023, 4033, 4040, 4041, 4043],
  12171. [4031, 4032, 4033, 4040, 4043],
  12172. [4030, 4032, 4033, 4041, 4043],
  12173. [4030, 4031, 4033, 4042, 4043],
  12174. [4013, 4040, 4041, 4042, 4043],
  12175. [4030, 4032, 4033, 4040, 4043],
  12176. [4030, 4031, 4033, 4041, 4043],
  12177. [4012, 4040, 4041, 4042, 4043],
  12178. [4030, 4031, 4033, 4040, 4043],
  12179. [4011, 4040, 4041, 4042, 4043],
  12180. [4010, 4040, 4041, 4042, 4043],
  12181. [4023, 4032, 4033, 4042, 4043],
  12182. [4022, 4032, 4033, 4042, 4043],
  12183. [4023, 4032, 4033, 4041, 4043],
  12184. [4021, 4032, 4033, 4042, 4043],
  12185. [4022, 4032, 4033, 4041, 4043],
  12186. [4023, 4030, 4033, 4042, 4043],
  12187. [4023, 4032, 4033, 4040, 4043],
  12188. [4013, 4033, 4040, 4042, 4043],
  12189. [4020, 4032, 4033, 4042, 4043],
  12190. [4021, 4032, 4033, 4041, 4043],
  12191. [4022, 4030, 4033, 4042, 4043],
  12192. [4022, 4032, 4033, 4040, 4043],
  12193. [4023, 4030, 4033, 4041, 4043],
  12194. [4023, 4031, 4033, 4040, 4043],
  12195. [4013, 4033, 4040, 4041, 4043],
  12196. [4020, 4031, 4033, 4042, 4043],
  12197. [4020, 4032, 4033, 4041, 4043],
  12198. [4021, 4030, 4033, 4042, 4043],
  12199. [4021, 4032, 4033, 4040, 4043],
  12200. [4022, 4030, 4033, 4041, 4043],
  12201. [4022, 4031, 4033, 4040, 4043],
  12202. [4023, 4030, 4033, 4040, 4043],
  12203. [4030, 4031, 4032, 4033, 4043],
  12204. [4003, 4040, 4041, 4042, 4043],
  12205. [4020, 4030, 4033, 4042, 4043],
  12206. [4020, 4031, 4033, 4041, 4043],
  12207. [4020, 4032, 4033, 4040, 4043],
  12208. [4021, 4030, 4033, 4041, 4043],
  12209. [4021, 4031, 4033, 4040, 4043],
  12210. [4022, 4030, 4033, 4040, 4043],
  12211. [4030, 4031, 4032, 4033, 4042],
  12212. [4002, 4040, 4041, 4042, 4043],
  12213. [4020, 4030, 4033, 4041, 4043],
  12214. [4020, 4031, 4033, 4040, 4043],
  12215. [4021, 4030, 4033, 4040, 4043],
  12216. [4030, 4031, 4032, 4033, 4041],
  12217. [4001, 4040, 4041, 4042, 4043],
  12218. [4030, 4031, 4032, 4033, 4040],
  12219. [4000, 4040, 4041, 4042, 4043],
  12220. [4013, 4032, 4033, 4042, 4043],
  12221. [4012, 4032, 4033, 4042, 4043],
  12222. [4013, 4032, 4033, 4041, 4043],
  12223. [4023, 4031, 4032, 4033, 4043],
  12224. [4011, 4032, 4033, 4042, 4043],
  12225. [4012, 4032, 4033, 4041, 4043],
  12226. [4013, 4030, 4033, 4042, 4043],
  12227. [4013, 4032, 4033, 4040, 4043],
  12228. [4023, 4030, 4032, 4033, 4043],
  12229. [4003, 4033, 4040, 4042, 4043],
  12230. [4013, 4023, 4040, 4042, 4043],
  12231. [4010, 4032, 4033, 4042, 4043],
  12232. [4011, 4032, 4033, 4041, 4043],
  12233. [4012, 4030, 4033, 4042, 4043],
  12234. [4012, 4032, 4033, 4040, 4043],
  12235. [4013, 4030, 4033, 4041, 4043],
  12236. [4013, 4031, 4033, 4040, 4043],
  12237. [4023, 4030, 4031, 4033, 4043],
  12238. [4003, 4033, 4040, 4041, 4043],
  12239. [4013, 4023, 4040, 4041, 4043],
  12240. [4010, 4031, 4033, 4042, 4043],
  12241. [4010, 4032, 4033, 4041, 4043],
  12242. [4011, 4030, 4033, 4042, 4043],
  12243. [4011, 4032, 4033, 4040, 4043],
  12244. [4012, 4030, 4033, 4041, 4043],
  12245. [4012, 4031, 4033, 4040, 4043],
  12246. [4013, 4030, 4033, 4040, 4043],
  12247. [4010, 4030, 4033, 4042, 4043],
  12248. [4010, 4031, 4033, 4041, 4043],
  12249. [4010, 4032, 4033, 4040, 4043],
  12250. [4011, 4030, 4033, 4041, 4043],
  12251. [4011, 4031, 4033, 4040, 4043],
  12252. [4012, 4030, 4033, 4040, 4043],
  12253. [4010, 4030, 4033, 4041, 4043],
  12254. [4010, 4031, 4033, 4040, 4043],
  12255. [4011, 4030, 4033, 4040, 4043],
  12256. [4003, 4032, 4033, 4042, 4043],
  12257. [4002, 4032, 4033, 4042, 4043],
  12258. [4003, 4032, 4033, 4041, 4043],
  12259. [4013, 4031, 4032, 4033, 4043],
  12260. [4001, 4032, 4033, 4042, 4043],
  12261. [4002, 4032, 4033, 4041, 4043],
  12262. [4003, 4030, 4033, 4042, 4043],
  12263. [4003, 4032, 4033, 4040, 4043],
  12264. [4013, 4030, 4032, 4033, 4043],
  12265. [4003, 4023, 4040, 4042, 4043],
  12266. [4000, 4032, 4033, 4042, 4043],
  12267. [4001, 4032, 4033, 4041, 4043],
  12268. [4002, 4030, 4033, 4042, 4043],
  12269. [4002, 4032, 4033, 4040, 4043],
  12270. [4003, 4030, 4033, 4041, 4043],
  12271. [4003, 4031, 4033, 4040, 4043],
  12272. [4020, 4022, 4023, 4042, 4043],
  12273. [4013, 4030, 4031, 4033, 4043],
  12274. [4003, 4023, 4040, 4041, 4043],
  12275. [4000, 4031, 4033, 4042, 4043],
  12276. [4000, 4032, 4033, 4041, 4043],
  12277. [4001, 4030, 4033, 4042, 4043],
  12278. [4001, 4032, 4033, 4040, 4043],
  12279. [4002, 4030, 4033, 4041, 4043],
  12280. [4002, 4031, 4033, 4040, 4043],
  12281. [4003, 4030, 4033, 4040, 4043],
  12282. [4021, 4022, 4023, 4040, 4043],
  12283. [4020, 4022, 4023, 4041, 4043],
  12284. [4020, 4021, 4023, 4042, 4043],
  12285. [4023, 4030, 4031, 4032, 4033],
  12286. [4000, 4030, 4033, 4042, 4043],
  12287. [4000, 4031, 4033, 4041, 4043],
  12288. [4000, 4032, 4033, 4040, 4043],
  12289. [4001, 4030, 4033, 4041, 4043],
  12290. [4001, 4031, 4033, 4040, 4043],
  12291. [4002, 4030, 4033, 4040, 4043],
  12292. [4020, 4022, 4023, 4040, 4043],
  12293. [4020, 4021, 4023, 4041, 4043],
  12294. [4022, 4030, 4031, 4032, 4033],
  12295. [4000, 4030, 4033, 4041, 4043],
  12296. [4000, 4031, 4033, 4040, 4043],
  12297. [4001, 4030, 4033, 4040, 4043],
  12298. [4020, 4021, 4023, 4040, 4043],
  12299. [4021, 4030, 4031, 4032, 4033],
  12300. [4020, 4030, 4031, 4032, 4033],
  12301. [4003, 4031, 4032, 4033, 4043],
  12302. [4020, 4022, 4023, 4033, 4043],
  12303. [4003, 4030, 4032, 4033, 4043],
  12304. [4003, 4013, 4040, 4042, 4043],
  12305. [4020, 4021, 4023, 4033, 4043],
  12306. [4003, 4030, 4031, 4033, 4043],
  12307. [4003, 4013, 4040, 4041, 4043],
  12308. [4013, 4030, 4031, 4032, 4033],
  12309. [4012, 4030, 4031, 4032, 4033],
  12310. [4011, 4030, 4031, 4032, 4033],
  12311. [4010, 4030, 4031, 4032, 4033],
  12312. [4013, 4023, 4031, 4032, 4033],
  12313. [4013, 4023, 4030, 4032, 4033],
  12314. [4020, 4022, 4023, 4032, 4033],
  12315. [4013, 4023, 4030, 4031, 4033],
  12316. [4021, 4022, 4023, 4030, 4033],
  12317. [4020, 4022, 4023, 4031, 4033],
  12318. [4020, 4021, 4023, 4032, 4033],
  12319. [4020, 4021, 4022, 4023, 4043],
  12320. [4003, 4030, 4031, 4032, 4033],
  12321. [4020, 4022, 4023, 4030, 4033],
  12322. [4020, 4021, 4023, 4031, 4033],
  12323. [4020, 4021, 4022, 4023, 4042],
  12324. [4002, 4030, 4031, 4032, 4033],
  12325. [4020, 4021, 4023, 4030, 4033],
  12326. [4020, 4021, 4022, 4023, 4041],
  12327. [4001, 4030, 4031, 4032, 4033],
  12328. [4020, 4021, 4022, 4023, 4040],
  12329. [4000, 4030, 4031, 4032, 4033],
  12330. [4003, 4023, 4031, 4032, 4033],
  12331. [4013, 4020, 4022, 4023, 4043],
  12332. [4003, 4023, 4030, 4032, 4033],
  12333. [4010, 4012, 4013, 4042, 4043],
  12334. [4013, 4020, 4021, 4023, 4043],
  12335. [4003, 4023, 4030, 4031, 4033],
  12336. [4011, 4012, 4013, 4040, 4043],
  12337. [4010, 4012, 4013, 4041, 4043],
  12338. [4010, 4011, 4013, 4042, 4043],
  12339. [4020, 4021, 4022, 4023, 4033],
  12340. [4010, 4012, 4013, 4040, 4043],
  12341. [4010, 4011, 4013, 4041, 4043],
  12342. [4020, 4021, 4022, 4023, 4032],
  12343. [4010, 4011, 4013, 4040, 4043],
  12344. [4020, 4021, 4022, 4023, 4031],
  12345. [4020, 4021, 4022, 4023, 4030],
  12346. [4003, 4013, 4031, 4032, 4033],
  12347. [4010, 4012, 4013, 4033, 4043],
  12348. [4003, 4020, 4022, 4023, 4043],
  12349. [4013, 4020, 4022, 4023, 4033],
  12350. [4003, 4013, 4030, 4032, 4033],
  12351. [4010, 4011, 4013, 4033, 4043],
  12352. [4003, 4020, 4021, 4023, 4043],
  12353. [4013, 4020, 4021, 4023, 4033],
  12354. [4003, 4013, 4030, 4031, 4033],
  12355. [4010, 4012, 4013, 4023, 4043],
  12356. [4003, 4020, 4022, 4023, 4033],
  12357. [4010, 4012, 4013, 4032, 4033],
  12358. [4010, 4011, 4013, 4023, 4043],
  12359. [4003, 4020, 4021, 4023, 4033],
  12360. [4011, 4012, 4013, 4030, 4033],
  12361. [4010, 4012, 4013, 4031, 4033],
  12362. [4010, 4011, 4013, 4032, 4033],
  12363. [4013, 4020, 4021, 4022, 4023],
  12364. [4010, 4012, 4013, 4030, 4033],
  12365. [4010, 4011, 4013, 4031, 4033],
  12366. [4012, 4020, 4021, 4022, 4023],
  12367. [4010, 4011, 4013, 4030, 4033],
  12368. [4011, 4020, 4021, 4022, 4023],
  12369. [4010, 4020, 4021, 4022, 4023],
  12370. [4010, 4012, 4013, 4023, 4033],
  12371. [4000, 4002, 4003, 4042, 4043],
  12372. [4010, 4011, 4013, 4023, 4033],
  12373. [4001, 4002, 4003, 4040, 4043],
  12374. [4000, 4002, 4003, 4041, 4043],
  12375. [4000, 4001, 4003, 4042, 4043],
  12376. [4010, 4011, 4012, 4013, 4043],
  12377. [4003, 4020, 4021, 4022, 4023],
  12378. [4000, 4002, 4003, 4040, 4043],
  12379. [4000, 4001, 4003, 4041, 4043],
  12380. [4010, 4011, 4012, 4013, 4042],
  12381. [4002, 4020, 4021, 4022, 4023],
  12382. [4000, 4001, 4003, 4040, 4043],
  12383. [4010, 4011, 4012, 4013, 4041],
  12384. [4001, 4020, 4021, 4022, 4023],
  12385. [4010, 4011, 4012, 4013, 4040],
  12386. [4000, 4020, 4021, 4022, 4023],
  12387. [4001, 4002, 4003, 4033, 4043],
  12388. [4000, 4002, 4003, 4033, 4043],
  12389. [4003, 4010, 4012, 4013, 4043],
  12390. [4003, 4013, 4020, 4022, 4023],
  12391. [4000, 4001, 4003, 4033, 4043],
  12392. [4003, 4010, 4011, 4013, 4043],
  12393. [4003, 4013, 4020, 4021, 4023],
  12394. [4010, 4011, 4012, 4013, 4033],
  12395. [4010, 4011, 4012, 4013, 4032],
  12396. [4010, 4011, 4012, 4013, 4031],
  12397. [4010, 4011, 4012, 4013, 4030],
  12398. [4001, 4002, 4003, 4023, 4043],
  12399. [4000, 4002, 4003, 4023, 4043],
  12400. [4003, 4010, 4012, 4013, 4033],
  12401. [4000, 4002, 4003, 4032, 4033],
  12402. [4000, 4001, 4003, 4023, 4043],
  12403. [4003, 4010, 4011, 4013, 4033],
  12404. [4001, 4002, 4003, 4030, 4033],
  12405. [4000, 4002, 4003, 4031, 4033],
  12406. [4000, 4001, 4003, 4032, 4033],
  12407. [4010, 4011, 4012, 4013, 4023],
  12408. [4000, 4002, 4003, 4030, 4033],
  12409. [4000, 4001, 4003, 4031, 4033],
  12410. [4010, 4011, 4012, 4013, 4022],
  12411. [4000, 4001, 4003, 4030, 4033],
  12412. [4010, 4011, 4012, 4013, 4021],
  12413. [4010, 4011, 4012, 4013, 4020],
  12414. [4001, 4002, 4003, 4013, 4043],
  12415. [4001, 4002, 4003, 4023, 4033],
  12416. [4000, 4002, 4003, 4013, 4043],
  12417. [4000, 4002, 4003, 4023, 4033],
  12418. [4003, 4010, 4012, 4013, 4023],
  12419. [4000, 4001, 4003, 4013, 4043],
  12420. [4000, 4001, 4003, 4023, 4033],
  12421. [4003, 4010, 4011, 4013, 4023],
  12422. [4001, 4002, 4003, 4013, 4033],
  12423. [4000, 4002, 4003, 4013, 4033],
  12424. [4000, 4001, 4003, 4013, 4033],
  12425. [4000, 4001, 4002, 4003, 4043],
  12426. [4003, 4010, 4011, 4012, 4013],
  12427. [4000, 4001, 4002, 4003, 4042],
  12428. [4002, 4010, 4011, 4012, 4013],
  12429. [4000, 4001, 4002, 4003, 4041],
  12430. [4001, 4010, 4011, 4012, 4013],
  12431. [4000, 4001, 4002, 4003, 4040],
  12432. [4000, 4010, 4011, 4012, 4013],
  12433. [4001, 4002, 4003, 4013, 4023],
  12434. [4000, 4002, 4003, 4013, 4023],
  12435. [4000, 4001, 4003, 4013, 4023],
  12436. [4000, 4001, 4002, 4003, 4033],
  12437. [4000, 4001, 4002, 4003, 4032],
  12438. [4000, 4001, 4002, 4003, 4031],
  12439. [4000, 4001, 4002, 4003, 4030],
  12440. [4000, 4001, 4002, 4003, 4023],
  12441. [4000, 4001, 4002, 4003, 4022],
  12442. [4000, 4001, 4002, 4003, 4021],
  12443. [4000, 4001, 4002, 4003, 4020],
  12444. [4000, 4001, 4002, 4003, 4013],
  12445. [4000, 4001, 4002, 4003, 4012],
  12446. [4000, 4001, 4002, 4003, 4011],
  12447. [4000, 4001, 4002, 4003, 4010],
  12448. ].filter((p) => p.includes(this.mandatoryId));
  12449.  
  12450. const bestPack = {
  12451. pack: packs[0],
  12452. winRate: 0,
  12453. countBattle: 0,
  12454. id: 0,
  12455. };
  12456.  
  12457. for (const id in packs) {
  12458. const pack = packs[id];
  12459. const attackers = this.maxUpgrade.filter((e) => pack.includes(e.id)).reduce((obj, e) => ({ ...obj, [e.id]: e }), {});
  12460. const battle = {
  12461. attackers,
  12462. defenders: [enemieHeroes],
  12463. type: 'brawl_titan',
  12464. };
  12465. const isRandom = this.isRandomBattle(battle);
  12466. const stat = {
  12467. count: 0,
  12468. win: 0,
  12469. winRate: 0,
  12470. };
  12471. for (let i = 1; i <= 20; i++) {
  12472. battle.seed = Math.floor(Date.now() / 1000) + Math.random() * 1000;
  12473. const result = await Calc(battle);
  12474. stat.win += result.result.win;
  12475. stat.count += 1;
  12476. stat.winRate = stat.win / stat.count;
  12477. if (!isRandom || (i >= 2 && stat.winRate < 0.65) || (i >= 10 && stat.winRate == 1)) {
  12478. break;
  12479. }
  12480. }
  12481.  
  12482. if (!isRandom && stat.win) {
  12483. return {
  12484. favor: {},
  12485. heroes: pack,
  12486. };
  12487. }
  12488. if (stat.winRate > 0.85) {
  12489. return {
  12490. favor: {},
  12491. heroes: pack,
  12492. };
  12493. }
  12494. if (stat.winRate > bestPack.winRate) {
  12495. bestPack.countBattle = stat.count;
  12496. bestPack.winRate = stat.winRate;
  12497. bestPack.pack = pack;
  12498. bestPack.id = id;
  12499. }
  12500. }
  12501.  
  12502. //console.log(bestPack.id, bestPack.pack, bestPack.winRate, bestPack.countBattle);
  12503. return {
  12504. favor: {},
  12505. heroes: bestPack.pack,
  12506. };
  12507. }
  12508.  
  12509. isRandomPack(pack) {
  12510. const ids = Object.keys(pack);
  12511. return ids.includes('4023') || ids.includes('4021');
  12512. }
  12513.  
  12514. isRandomBattle(battle) {
  12515. return this.isRandomPack(battle.attackers) || this.isRandomPack(battle.defenders[0]);
  12516. }
  12517.  
  12518. async updateHeroesPack(enemieHeroes) {
  12519. const packs = [{id:1,args:{userId:-830021,heroes:[63,13,9,48,1],pet:6006,favor:{1:6004,9:6005,13:6002,48:6e3,63:6009}},attackers:{1:{id:1,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{2:130,3:130,4:130,5:130,6022:130,8268:1,8269:1},power:198058,star:6,runes:[43750,43750,43750,43750,43750],skins:{1:60,54:60,95:60,154:60,250:60,325:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6004,type:"hero",perks:[4,1],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,9,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,9,10]},agility:3093,hp:419649,intelligence:3644,physicalAttack:11481.6,strength:17049,armor:12720,dodge:17232.28,magicPenetration:22780,magicPower:55816,magicResist:1580,modifiedSkillTier:5,skin:0,favorPetId:6004,favorPower:11064},9:{id:9,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{335:130,336:130,337:130,338:130,6027:130,8270:1,8271:1},power:195886,star:6,runes:[43750,43750,43750,43750,43750],skins:{9:60,41:60,163:60,189:60,311:60,338:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6005,type:"hero",perks:[7,2,20],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,9,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,9,10]},agility:3068,hp:227134,intelligence:19003,physicalAttack:7020.32,strength:3068,armor:19995,dodge:14644,magicPower:64780.6,magicResist:31597,modifiedSkillTier:5,skin:0,favorPetId:6005,favorPower:11064},13:{id:"13",xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{452:130,453:130,454:130,455:130,6012:130,8274:1,8275:1},power:194833,star:6,runes:[43750,43750,43750,43750,43750],skins:{13:60,38:60,148:60,199:60,240:60,335:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6002,type:"hero",perks:[7,2,21],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,9,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,9,10]},agility:2885,hp:344763,intelligence:17625,physicalAttack:50,strength:3020,armor:19060,magicPenetration:58138.6,magicPower:70100.6,magicResist:27227,modifiedSkillTier:4,skin:0,favorPetId:6002,favorPower:11064},48:{id:48,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{240:130,241:130,242:130,243:130,6002:130},power:190584,star:6,runes:[43750,43750,43750,43750,43750],skins:{103:60,165:60,217:60,296:60,326:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6e3,type:"hero",perks:[5,2],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,10]},agility:17308,hp:397737,intelligence:2888,physicalAttack:40298.32,physicalCritChance:12280,strength:3169,armor:12185,armorPenetration:20137.6,magicResist:24816,skin:0,favorPetId:6e3,favorPower:11064},63:{id:63,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{442:130,443:130,444:130,445:130,6041:130,8272:1,8273:1},power:193520,star:6,runes:[43750,43750,43750,43750,43750],skins:{341:60,350:60,351:60,352:1},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6009,type:"hero",perks:[6,1,21],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,9,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,9,10]},agility:17931,hp:488832,intelligence:2737,physicalAttack:54213.6,strength:2877,armor:800,armorPenetration:32477.6,magicResist:8526,physicalCritChance:9545,modifiedSkillTier:3,skin:0,favorPetId:6009,favorPower:11064},6006:{id:6006,color:10,star:6,xp:450551,level:130,slots:[25,50,50,25,50,50],skills:{6030:130,6031:130},power:181943,type:"pet",perks:[5,9],name:null,intelligence:11064,magicPenetration:47911,strength:12360}}},{id:2,args:{userId:-830049,heroes:[46,13,52,49,4],pet:6006,favor:{4:6001,13:6002,46:6006,49:6004,52:6003}},attackers:{4:{id:4,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{255:130,256:130,257:130,258:130,6007:130},power:189782,star:6,runes:[43750,43750,43750,43750,43750],skins:{4:60,35:60,92:60,161:60,236:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6001,type:"hero",perks:[4,5,2,22],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,10]},agility:3065,hp:482631,intelligence:3402,physicalAttack:2800,strength:17488,armor:56262.6,magicPower:51021,magicResist:36971,skin:0,favorPetId:6001,favorPower:11064},13:{id:"13",xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{452:130,453:130,454:130,455:130,6012:130,8274:1,8275:1},power:194833,star:6,runes:[43750,43750,43750,43750,43750],skins:{13:60,38:60,148:60,199:60,240:60,335:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6002,type:"hero",perks:[7,2,21],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,9,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,9,10]},agility:2885,hp:344763,intelligence:17625,physicalAttack:50,strength:3020,armor:19060,magicPenetration:58138.6,magicPower:70100.6,magicResist:27227,modifiedSkillTier:4,skin:0,favorPetId:6002,favorPower:11064},46:{id:46,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{230:130,231:130,232:130,233:130,6032:130},power:189653,star:6,runes:[43750,43750,43750,43750,43750],skins:{101:60,159:60,178:60,262:60,315:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6006,type:"hero",perks:[9,5,1,22],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,10]},agility:2122,hp:637517,intelligence:16208,physicalAttack:50,strength:5151,armor:38507.6,magicPower:74495.6,magicResist:22237,skin:0,favorPetId:6006,favorPower:11064},49:{id:49,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{245:130,246:130,247:130,248:130,6022:130},power:193163,star:6,runes:[43750,43750,43750,43750,43750],skins:{104:60,191:60,252:60,305:60,329:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6004,type:"hero",perks:[10,1,22],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,10]},agility:17935,hp:250405,intelligence:2790,physicalAttack:40413.6,strength:2987,armor:11655,dodge:14844.28,magicResist:3175,physicalCritChance:14135,skin:0,favorPetId:6004,favorPower:11064},52:{id:52,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{310:130,311:130,312:130,313:130,6017:130},power:185075,star:6,runes:[43750,43750,43750,43750,43750],skins:{188:60,213:60,248:60,297:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6003,type:"hero",perks:[5,8,2,13,15,22],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,10]},agility:18270,hp:226207,intelligence:2620,physicalAttack:44206,strength:3260,armor:13150,armorPenetration:40301,magicPower:9957.6,magicResist:33892.6,skin:0,favorPetId:6003,favorPower:11064},6006:{id:6006,color:10,star:6,xp:450551,level:130,slots:[25,50,50,25,50,50],skills:{6030:130,6031:130},power:181943,type:"pet",perks:[5,9],name:null,intelligence:11064,magicPenetration:47911,strength:12360}}},{id:3,args:{userId:8263225,heroes:[29,63,13,48,1],pet:6006,favor:{1:6004,13:6002,29:6006,48:6e3,63:6003}},attackers:{1:{id:1,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{2:130,3:130,4:130,5:130,6022:130,8268:1,8269:1},power:198058,star:6,runes:[43750,43750,43750,43750,43750],skins:{1:60,54:60,95:60,154:60,250:60,325:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6004,type:"hero",perks:[4,1],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,9,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,9,10]},agility:3093,hp:419649,intelligence:3644,physicalAttack:11481.6,strength:17049,armor:12720,dodge:17232.28,magicPenetration:22780,magicPower:55816,magicResist:1580,modifiedSkillTier:5,skin:0,favorPetId:6004,favorPower:11064},13:{id:"13",xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{452:130,453:130,454:130,455:130,6012:130,8274:1,8275:1},power:194833,star:6,runes:[43750,43750,43750,43750,43750],skins:{13:60,38:60,148:60,199:60,240:60,335:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6002,type:"hero",perks:[7,2,21],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,9,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,9,10]},agility:2885,hp:344763,intelligence:17625,physicalAttack:50,strength:3020,armor:19060,magicPenetration:58138.6,magicPower:70100.6,magicResist:27227,modifiedSkillTier:4,skin:0,favorPetId:6002,favorPower:11064},29:{id:29,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{145:130,146:130,147:130,148:130,6032:130},power:189790,star:6,runes:[43750,43750,43750,43750,43750],skins:{29:60,72:60,88:60,147:60,242:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6006,type:"hero",perks:[9,5,2,22],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,10]},agility:2885,hp:491431,intelligence:18331,physicalAttack:106,strength:3020,armor:37716.6,magicPower:76792.6,magicResist:31377,skin:0,favorPetId:6006,favorPower:11064},48:{id:48,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{240:130,241:130,242:130,243:130,6002:130},power:190584,star:6,runes:[43750,43750,43750,43750,43750],skins:{103:60,165:60,217:60,296:60,326:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6e3,type:"hero",perks:[5,2],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,10]},agility:17308,hp:397737,intelligence:2888,physicalAttack:40298.32,physicalCritChance:12280,strength:3169,armor:12185,armorPenetration:20137.6,magicResist:24816,skin:0,favorPetId:6e3,favorPower:11064},63:{id:63,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{442:130,443:130,444:130,445:130,6017:130,8272:1,8273:1},power:191031,star:6,runes:[43750,43750,43750,43750,43750],skins:{341:60,350:60,351:60,352:1},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6003,type:"hero",perks:[6,1,21],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,9,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,9,10]},agility:17931,hp:488832,intelligence:2737,physicalAttack:44256,strength:2877,armor:800,armorPenetration:22520,magicPower:9957.6,magicResist:18483.6,physicalCritChance:9545,modifiedSkillTier:3,skin:0,favorPetId:6003,favorPower:11064},6006:{id:6006,color:10,star:6,xp:450551,level:130,slots:[25,50,50,25,50,50],skills:{6030:130,6031:130},power:181943,type:"pet",perks:[5,9],name:null,intelligence:11064,magicPenetration:47911,strength:12360}}},{id:4,args:{userId:8263247,heroes:[55,13,40,51,1],pet:6006,favor:{1:6007,13:6002,40:6004,51:6006,55:6001}},attackers:{1:{id:1,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{2:130,3:130,4:130,5:130,6035:130,8268:1,8269:1},power:195170,star:6,runes:[43750,43750,43750,43750,43750],skins:{1:60,54:60,95:60,154:60,250:60,325:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6007,type:"hero",perks:[4,1],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,9,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,9,10]},agility:3093,hp:419649,intelligence:3644,physicalAttack:1524,strength:17049,armor:22677.6,dodge:14245,magicPenetration:22780,magicPower:65773.6,magicResist:1580,modifiedSkillTier:5,skin:0,favorPetId:6007,favorPower:11064},13:{id:"13",xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{452:130,453:130,454:130,455:130,6012:130,8274:1,8275:1},power:194833,star:6,runes:[43750,43750,43750,43750,43750],skins:{13:60,38:60,148:60,199:60,240:60,335:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6002,type:"hero",perks:[7,2,21],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,9,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,9,10]},agility:2885,hp:344763,intelligence:17625,physicalAttack:50,strength:3020,armor:19060,magicPenetration:58138.6,magicPower:70100.6,magicResist:27227,modifiedSkillTier:4,skin:0,favorPetId:6002,favorPower:11064},40:{id:40,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{200:130,201:130,202:130,203:130,6022:130,8244:1,8245:1},power:192541,star:6,runes:[43750,43750,43750,43750,43750],skins:{53:60,89:60,129:60,168:60,314:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6004,type:"hero",perks:[5,9,1],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,9,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,9,10]},agility:17540,hp:343191,intelligence:2805,physicalAttack:48430.6,strength:2976,armor:24410,dodge:15732.28,magicResist:17633,modifiedSkillTier:3,skin:0,favorPetId:6004,favorPower:11064},51:{id:51,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{305:130,306:130,307:130,308:130,6032:130},power:190005,star:6,runes:[43750,43750,43750,43750,43750],skins:{181:60,219:60,260:60,290:60,334:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6006,type:"hero",perks:[5,9,1,12],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,10]},agility:2526,hp:438205,intelligence:18851,physicalAttack:50,strength:2921,armor:39442.6,magicPower:88978.6,magicResist:22960,skin:0,favorPetId:6006,favorPower:11064},55:{id:55,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{325:130,326:130,327:130,328:130,6007:130},power:190529,star:6,runes:[43750,43750,43750,43750,43750],skins:{239:60,278:60,309:60,327:60,346:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6001,type:"hero",perks:[7,1],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,10]},agility:2631,hp:499591,intelligence:19438,physicalAttack:50,strength:3286,armor:32892.6,armorPenetration:36870,magicPower:60704,magicResist:10010,skin:0,favorPetId:6001,favorPower:11064},6006:{id:6006,color:10,star:6,xp:450551,level:130,slots:[25,50,50,25,50,50],skills:{6030:130,6031:130},power:181943,type:"pet",perks:[5,9],name:null,intelligence:11064,magicPenetration:47911,strength:12360}}},{id:5,args:{userId:8263303,heroes:[31,29,13,40,1],pet:6004,favor:{1:6001,13:6007,29:6002,31:6006,40:6004}},attackers:{1:{id:1,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{2:130,3:130,4:130,5:130,6007:130,8268:1,8269:1},power:195170,star:6,runes:[43750,43750,43750,43750,43750],skins:{1:60,54:60,95:60,154:60,250:60,325:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6001,type:"hero",perks:[4,1],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,9,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,9,10]},agility:3093,hp:519225,intelligence:3644,physicalAttack:1524,strength:17049,armor:22677.6,dodge:14245,magicPenetration:22780,magicPower:55816,magicResist:1580,modifiedSkillTier:5,skin:0,favorPetId:6001,favorPower:11064},13:{id:"13",xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{452:130,453:130,454:130,455:130,6035:130,8274:1,8275:1},power:194833,star:6,runes:[43750,43750,43750,43750,43750],skins:{13:60,38:60,148:60,199:60,240:60,335:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6007,type:"hero",perks:[7,2,21],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,9,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,9,10]},agility:2885,hp:344763,intelligence:17625,physicalAttack:50,strength:3020,armor:29017.6,magicPenetration:48181,magicPower:70100.6,magicResist:27227,modifiedSkillTier:4,skin:0,favorPetId:6007,favorPower:11064},29:{id:29,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{145:130,146:130,147:130,148:130,6012:130},power:189790,star:6,runes:[43750,43750,43750,43750,43750],skins:{29:60,72:60,88:60,147:60,242:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6002,type:"hero",perks:[9,5,2,22],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,10]},agility:2885,hp:491431,intelligence:18331,physicalAttack:106,strength:3020,armor:27759,magicPenetration:9957.6,magicPower:76792.6,magicResist:31377,skin:0,favorPetId:6002,favorPower:11064},31:{id:31,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{155:130,156:130,157:130,158:130,6032:130},power:190305,star:6,runes:[43750,43750,43750,43750,43750],skins:{44:60,94:60,133:60,200:60,295:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6006,type:"hero",perks:[9,5,2,20],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,10]},agility:2781,dodge:12620,hp:374484,intelligence:18945,physicalAttack:78,strength:2916,armor:28049.6,magicPower:67686.6,magicResist:15252,skin:0,favorPetId:6006,favorPower:11064},40:{id:40,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{200:130,201:130,202:130,203:130,6022:130,8244:1,8245:1},power:192541,star:6,runes:[43750,43750,43750,43750,43750],skins:{53:60,89:60,129:60,168:60,314:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6004,type:"hero",perks:[5,9,1],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,9,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,9,10]},agility:17540,hp:343191,intelligence:2805,physicalAttack:48430.6,strength:2976,armor:24410,dodge:15732.28,magicResist:17633,modifiedSkillTier:3,skin:0,favorPetId:6004,favorPower:11064},6004:{id:6004,color:10,star:6,xp:450551,level:130,slots:[25,50,50,25,50,50],skills:{6020:130,6021:130},power:181943,type:"pet",perks:[5],name:null,armorPenetration:47911,intelligence:11064,strength:12360}}},{id:6,args:{userId:8263317,heroes:[62,13,9,56,61],pet:6003,favor:{9:6004,13:6002,56:6006,61:6001,62:6003}},attackers:{9:{id:9,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{335:130,336:130,337:130,338:130,6022:130,8270:1,8271:1},power:198525,star:6,runes:[43750,43750,43750,43750,43750],skins:{9:60,41:60,163:60,189:60,311:60,338:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6004,type:"hero",perks:[7,2,20],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,9,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,9,10]},agility:3068,hp:227134,intelligence:19003,physicalAttack:10007.6,strength:3068,armor:19995,dodge:17631.28,magicPower:54823,magicResist:31597,modifiedSkillTier:5,skin:0,favorPetId:6004,favorPower:11064},13:{id:"13",xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{452:130,453:130,454:130,455:130,6012:130,8274:1,8275:1},power:194833,star:6,runes:[43750,43750,43750,43750,43750],skins:{13:60,38:60,148:60,199:60,240:60,335:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6002,type:"hero",perks:[7,2,21],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,9,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,9,10]},agility:2885,hp:344763,intelligence:17625,physicalAttack:50,strength:3020,armor:19060,magicPenetration:58138.6,magicPower:70100.6,magicResist:27227,modifiedSkillTier:4,skin:0,favorPetId:6002,favorPower:11064},56:{id:56,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{376:130,377:130,378:130,379:130,6032:130},power:184420,star:6,runes:[43750,43750,43750,43750,43750],skins:{264:60,279:60,294:60,321:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6006,type:"hero",perks:[5,7,1,21],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,10]},agility:2791,hp:235111,intelligence:18813,physicalAttack:50,strength:2656,armor:22982.6,magicPenetration:48159,magicPower:75598.6,magicResist:13990,skin:0,favorPetId:6006,favorPower:11064},61:{id:61,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{411:130,412:130,413:130,414:130,6007:130},power:184868,star:6,runes:[43750,43750,43750,43750,43750],skins:{302:60,306:60,323:60,340:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6001,type:"hero",perks:[4,2,22],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,10]},agility:2545,hp:466176,intelligence:3320,physicalAttack:34305,strength:18309,armor:31077.6,magicResist:24101,physicalCritChance:9009,skin:0,favorPetId:6001,favorPower:11064},62:{id:62,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{437:130,438:130,439:130,440:130,6017:130},power:173991,star:6,runes:[43750,43750,43750,43750,43750],skins:{320:60,343:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6003,type:"hero",perks:[8,7,2,22],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,10]},agility:2530,hp:276010,intelligence:19245,physicalAttack:50,strength:3543,armor:12890,magicPenetration:23658,magicPower:80966.6,magicResist:12447.6,skin:0,favorPetId:6003,favorPower:11064},6003:{id:6003,color:10,star:6,xp:450551,level:130,slots:[25,50,50,25,50,50],skills:{6015:130,6016:130},power:181943,type:"pet",perks:[8],name:null,intelligence:11064,magicPenetration:47911,strength:12360}}},{id:7,args:{userId:8263335,heroes:[32,29,13,43,1],pet:6006,favor:{1:6004,13:6008,29:6006,32:6002,43:6007}},attackers:{1:{id:1,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{2:130,3:130,4:130,5:130,6022:130,8268:1,8269:1},power:198058,star:6,runes:[43750,43750,43750,43750,43750],skins:{1:60,54:60,95:60,154:60,250:60,325:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6004,type:"hero",perks:[4,1],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,9,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,9,10]},agility:3093,hp:419649,intelligence:3644,physicalAttack:11481.6,strength:17049,armor:12720,dodge:17232.28,magicPenetration:22780,magicPower:55816,magicResist:1580,modifiedSkillTier:5,skin:0,favorPetId:6004,favorPower:11064},13:{id:"13",xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{452:130,453:130,454:130,455:130,6038:130,8274:1,8275:1},power:194833,star:6,runes:[43750,43750,43750,43750,43750],skins:{13:60,38:60,148:60,199:60,240:60,335:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6008,type:"hero",perks:[7,2,21],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,9,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,9,10]},agility:2885,hp:344763,intelligence:17625,physicalAttack:50,strength:3020,armor:29017.6,magicPenetration:48181,magicPower:70100.6,magicResist:27227,modifiedSkillTier:4,skin:0,favorPetId:6008,favorPower:11064},29:{id:29,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{145:130,146:130,147:130,148:130,6032:130},power:189790,star:6,runes:[43750,43750,43750,43750,43750],skins:{29:60,72:60,88:60,147:60,242:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6006,type:"hero",perks:[9,5,2,22],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,10]},agility:2885,hp:491431,intelligence:18331,physicalAttack:106,strength:3020,armor:37716.6,magicPower:76792.6,magicResist:31377,skin:0,favorPetId:6006,favorPower:11064},32:{id:32,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{160:130,161:130,162:130,163:130,6012:130},power:189956,star:6,runes:[43750,43750,43750,43750,43750],skins:{45:60,73:60,81:60,135:60,212:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6002,type:"hero",perks:[7,5,2,22],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,10]},agility:2815,hp:551066,intelligence:18800,physicalAttack:50,strength:2810,armor:19040,magicPenetration:9957.6,magicPower:89495.6,magicResist:20805,skin:0,favorPetId:6002,favorPower:11064},43:{id:43,xp:3625195,level:130,color:18,slots:[0,0,0,0,0,0],skills:{215:130,216:130,217:130,218:130,6035:130},power:189593,star:6,runes:[43750,43750,43750,43750,43750],skins:{98:60,130:60,169:60,201:60,304:60},currentSkin:0,titanGiftLevel:30,titanCoinsSpent:null,artifacts:[{level:130,star:6},{level:130,star:6},{level:130,star:6}],scale:1,petId:6007,type:"hero",perks:[7,9,1,21],ascensions:{1:[0,1,2,3,4,5,6,7,8,9],2:[0,1,2,3,4,5,6,7,8,10],3:[0,1,2,3,4,5,6,7,8,9],4:[0,1,2,3,4,5,6,7,8,9],5:[0,1,2,3,4,5,6,7,8,10]},agility:2447,hp:265217,intelligence:18758,physicalAttack:50,strength:2842,armor:18637.6,magicPenetration:52439,magicPower:75465.6,magicResist:22695,skin:0,favorPetId:6007,favorPower:11064},6006:{id:6006,color:10,star:6,xp:450551,level:130,slots:[25,50,50,25,50,50],skills:{6030:130,6031:130},power:181943,type:"pet",perks:[5,9],name:null,intelligence:11064,magicPenetration:47911,strength:12360}}}];
  12520.  
  12521. const bestPack = {
  12522. pack: packs[0],
  12523. countWin: 0,
  12524. }
  12525.  
  12526. for (const pack of packs) {
  12527. const attackers = pack.attackers;
  12528. const battle = {
  12529. attackers,
  12530. defenders: [enemieHeroes],
  12531. type: 'brawl',
  12532. };
  12533.  
  12534. let countWinBattles = 0;
  12535. let countTestBattle = 10;
  12536. for (let i = 0; i < countTestBattle; i++) {
  12537. battle.seed = Math.floor(Date.now() / 1000) + Math.random() * 1000;
  12538. const result = await Calc(battle);
  12539. if (result.result.win) {
  12540. countWinBattles++;
  12541. }
  12542. if (countWinBattles > 7) {
  12543. console.log(pack)
  12544. return pack.args;
  12545. }
  12546. }
  12547. if (countWinBattles > bestPack.countWin) {
  12548. bestPack.countWin = countWinBattles;
  12549. bestPack.pack = pack.args;
  12550. }
  12551. }
  12552.  
  12553. console.log(bestPack);
  12554. return bestPack.pack;
  12555. }
  12556.  
  12557. async questFarm() {
  12558. const calls = [this.callBrawlQuestFarm];
  12559. const result = await Send(JSON.stringify({ calls }));
  12560. return result.results[0].result.response;
  12561. }
  12562.  
  12563. async getBrawlInfo() {
  12564. const data = await Send(JSON.stringify({
  12565. calls: [
  12566. this.callUserGetInfo,
  12567. this.callBrawlQuestGetInfo,
  12568. this.callBrawlFindEnemies,
  12569. this.callTeamGetMaxUpgrade,
  12570. this.callBrawlGetInfo,
  12571. ]
  12572. }));
  12573.  
  12574. let attempts = data.results[0].result.response.refillable.find(n => n.id == 48);
  12575.  
  12576. const maxUpgrade = data.results[3].result.response;
  12577. const maxHero = Object.values(maxUpgrade.hero);
  12578. const maxTitan = Object.values(maxUpgrade.titan);
  12579. const maxPet = Object.values(maxUpgrade.pet);
  12580. this.maxUpgrade = [...maxHero, ...maxPet, ...maxTitan];
  12581.  
  12582. this.info = data.results[4].result.response;
  12583. this.mandatoryId = lib.data.brawl.promoHero[this.info.id].promoHero;
  12584. return {
  12585. attempts: attempts.amount,
  12586. questInfo: data.results[1].result.response,
  12587. findEnemies: data.results[2].result.response,
  12588. }
  12589. }
  12590.  
  12591. /**
  12592. * Carrying out a fight
  12593. *
  12594. * Проведение боя
  12595. */
  12596. async battle(userId) {
  12597. this.stats.count++;
  12598. const battle = await this.startBattle(userId, this.args);
  12599. const result = await Calc(battle);
  12600. console.log(result.result);
  12601. if (result.result.win) {
  12602. this.stats.win++;
  12603. } else {
  12604. this.stats.loss++;
  12605. if (!this.info.boughtEndlessLivesToday) {
  12606. this.attempts--;
  12607. }
  12608. }
  12609. return await this.endBattle(result);
  12610. // return await this.cancelBattle(result);
  12611. }
  12612.  
  12613. /**
  12614. * Starts a fight
  12615. *
  12616. * Начинает бой
  12617. */
  12618. async startBattle(userId, args) {
  12619. const call = {
  12620. name: "brawl_startBattle",
  12621. args,
  12622. ident: "brawl_startBattle"
  12623. }
  12624. call.args.userId = userId;
  12625. const calls = [call];
  12626. const result = await Send(JSON.stringify({ calls }));
  12627. return result.results[0].result.response;
  12628. }
  12629.  
  12630. cancelBattle(battle) {
  12631. const fixBattle = function (heroes) {
  12632. for (const ids in heroes) {
  12633. const hero = heroes[ids];
  12634. hero.energy = random(1, 999);
  12635. if (hero.hp > 0) {
  12636. hero.hp = random(1, hero.hp);
  12637. }
  12638. }
  12639. }
  12640. fixBattle(battle.progress[0].attackers.heroes);
  12641. fixBattle(battle.progress[0].defenders.heroes);
  12642. return this.endBattle(battle);
  12643. }
  12644.  
  12645. /**
  12646. * Ends the fight
  12647. *
  12648. * Заканчивает бой
  12649. */
  12650. async endBattle(battle) {
  12651. battle.progress[0].attackers.input = ['auto', 0, 0, 'auto', 0, 0];
  12652. const calls = [{
  12653. name: "brawl_endBattle",
  12654. args: {
  12655. result: battle.result,
  12656. progress: battle.progress
  12657. },
  12658. ident: "brawl_endBattle"
  12659. },
  12660. this.callBrawlQuestGetInfo,
  12661. this.callBrawlFindEnemies,
  12662. ];
  12663. const result = await Send(JSON.stringify({ calls }));
  12664. return result.results;
  12665. }
  12666.  
  12667. end(endReason) {
  12668. setIsCancalBattle(true);
  12669. isBrawlsAutoStart = false;
  12670. setProgress(endReason, true);
  12671. console.log(endReason);
  12672. this.resolve();
  12673. }
  12674. }
  12675.  
  12676. this.HWHClasses.executeBrawls = executeBrawls;
  12677.  
  12678. })();
  12679.  
  12680. /**
  12681. * TODO:
  12682. * Получение всех уровней при сборе всех наград (квест на титанит и на энку) +-
  12683. * Добивание на арене титанов
  12684. * Закрытие окошек по Esc +-
  12685. * Починить работу скрипта на уровне команды ниже 10 +-
  12686. * Написать номальную синхронизацию
  12687. * Запрет сбора квестов и отправки экспеиций в промежуток между локальным обновлением и глобальным обновлением дня
  12688. * Улучшение боев
  12689. */