咕咕镇助手

气人页游 咕咕镇助手

目前为 2023-06-04 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name GuguTown Helper
  3. // @name:zh-CN 咕咕镇助手
  4. // @name:zh-TW 咕咕鎮助手
  5. // @name:ja 咕咕镇助手
  6. // @namespace https://github.com/GuguTown/GuguTownHelper
  7. // @homepage https://github.com/GuguTown/GuguTownHelper
  8. // @version 2.3.4
  9. // @description WebGame GuguTown Helper
  10. // @description:zh-CN 气人页游 咕咕镇助手
  11. // @description:zh-TW 氣人頁遊 咕咕鎮助手
  12. // @description:ja オンラインゲーム 咕咕镇助手
  13. // @author paraii & zyxboy
  14. // @match https://www.guguzhen.com/*
  15. // @match https://www.momozhen.com/*
  16. // @license MIT License
  17. // ==/UserScript==
  18. /* eslint-env jquery */
  19. function gudaq(){
  20. 'use strict'
  21.  
  22. const g_version = '2.3.4 (RP)';
  23. const g_modiTime = '2023-06-03 19:00:00';
  24.  
  25. ////////////////////////////////////////////////////////////////////////////////////////////////////
  26. //
  27. // common utilities
  28. //
  29. ////////////////////////////////////////////////////////////////////////////////////////////////////
  30.  
  31. const g_navigatorSelector = 'body > div > div.row > div.panel > div.panel-body > div';
  32. const g_kfUser = document.querySelector(g_navigatorSelector + ' > button.btn.btn-lg')?.innerText;
  33. if (!(g_kfUser?.length > 0)) {
  34. console.log('数据采集: 咕咕镇版本不匹配或正在测试');
  35. return;
  36. }
  37. console.log('数据采集: ' + g_kfUser);
  38.  
  39. const g_guguzhenHome = '/fyg_index.php';
  40. const g_guguzhenBeach = '/fyg_beach.php';
  41. const g_guguzhenPK = '/fyg_pk.php';
  42. const g_guguzhenEquip = '/fyg_equip.php';
  43. const g_guguzhenWish = '/fyg_wish.php';
  44. const g_guguzhenGem = '/fyg_gem.php';
  45. const g_guguzhenShop = '/fyg_shop.php';
  46.  
  47. const g_showSolutionPanelStorageKey = g_kfUser + '_showSolutionPanel';
  48. const g_indexRallyStorageKey = g_kfUser + '_indexRally';
  49. const g_keepPkRecordStorageKey = g_kfUser + '_keepPkRecord';
  50. const g_amuletGroupCollectionStorageKey = g_kfUser + '_amulet_Groups';
  51. const g_equipmentExpandStorageKey = g_kfUser + '_equipment_Expand';
  52. const g_equipmentStoreExpandStorageKey = g_kfUser + '_equipment_StoreExpand';
  53. const g_equipmentBGStorageKey = g_kfUser + '_equipment_BG';
  54. const g_beachForceExpandStorageKey = g_kfUser + '_beach_forceExpand';
  55. const g_beachBGStorageKey = g_kfUser + '_beach_BG';
  56. const g_gemConfigStorageKey = g_kfUser + '_gem_Config';
  57. const g_forgeHistoryStorageKey = g_kfUser + '_forgeHistory';
  58. const g_userDataStorageKeyConfig = [ g_kfUser, g_showSolutionPanelStorageKey, g_indexRallyStorageKey, g_keepPkRecordStorageKey,
  59. g_amuletGroupCollectionStorageKey, g_equipmentExpandStorageKey, g_equipmentStoreExpandStorageKey,
  60. g_equipmentBGStorageKey, g_beachForceExpandStorageKey, g_beachBGStorageKey, g_gemConfigStorageKey,
  61. g_forgeHistoryStorageKey ];
  62.  
  63. // deprecated
  64. const g_amuletGroupsStorageKey = g_kfUser + '_amulet_groups';
  65. const g_autoTaskEnabledStorageKey = g_kfUser + '_autoTaskEnabled';
  66. const g_autoTaskCheckStoneProgressStorageKey = g_kfUser + '_autoTaskCheckStoneProgress';
  67. const g_ignoreWishpoolExpirationStorageKey = g_kfUser + '_ignoreWishpoolExpiration';
  68. const g_stoneProgressEquipTipStorageKey = g_kfUser + '_stone_ProgressEquipTip';
  69. const g_stoneProgressCardTipStorageKey = g_kfUser + '_stone_ProgressCardTip';
  70. const g_stoneProgressHaloTipStorageKey = g_kfUser + '_stone_ProgressHaloTip';
  71. const g_stoneOperationStorageKey = g_kfUser + '_stoneOperation';
  72. const g_forgeBoxUsageStorageKey = g_kfUser + '_forgeBoxUsageStorageKey';
  73. const g_beachIgnoreStoreMysEquipStorageKey = g_kfUser + '_beach_ignoreStoreMysEquip';
  74. const g_userDataStorageKeyExtra = [ g_amuletGroupsStorageKey, g_autoTaskEnabledStorageKey, g_autoTaskCheckStoneProgressStorageKey,
  75. g_ignoreWishpoolExpirationStorageKey, g_stoneProgressEquipTipStorageKey,
  76. g_stoneProgressCardTipStorageKey, g_stoneProgressHaloTipStorageKey,
  77. g_stoneOperationStorageKey, g_forgeBoxUsageStorageKey, g_beachIgnoreStoreMysEquipStorageKey,
  78. 'attribute', 'cardName', 'title', 'over', 'halo_max', 'beachcheck', 'dataReward', 'keepcheck' ];
  79. // deprecated
  80.  
  81. const USER_STORAGE_RESERVED_SEPARATORS = /[:;,|=+*%!#$&?<>{}^`"\\\/\[\]\r\n\t\v\s]/;
  82. const USER_STORAGE_KEY_VALUE_SEPARATOR = ':';
  83.  
  84. const g_userMessageDivId = 'user-message-div';
  85. const g_userMessageBtnId = 'user-message-btn';
  86. var g_msgCount = 0;
  87. function addUserMessage(msgs, noNotification) {
  88. if (msgs?.length > 0) {
  89. let div = document.getElementById(g_userMessageDivId);
  90. if (div == null) {
  91. function clearNotification() {
  92. g_msgCount = 0;
  93. let btn = document.getElementById(g_userMessageBtnId);
  94. if (btn != null) {
  95. btn.style.display = 'none';
  96. }
  97. }
  98.  
  99. let div_row = document.createElement('div');
  100. div_row.className = 'row';
  101. document.querySelector('div.row.fyg_lh60.fyg_tr').parentNode.appendChild(div_row);
  102.  
  103. let div_pan = document.createElement('div');
  104. div_pan.className = 'panel panel-info';
  105. div_row.appendChild(div_pan);
  106.  
  107. let div_head = document.createElement('div');
  108. div_head.className = 'panel-heading';
  109. div_head.innerText = '页面消息';
  110. div_pan.appendChild(div_head);
  111.  
  112. let div_op = document.createElement('div');
  113. div_op.style.float = 'right';
  114. div_head.appendChild(div_op);
  115.  
  116. let link_mark = document.createElement('a');
  117. link_mark.style.marginRight = '20px';
  118. link_mark.innerText = '〇 已读';
  119. link_mark.href = '###';
  120. link_mark.onclick = (() => {
  121. clearNotification();
  122. let m = document.getElementById(g_userMessageDivId).children;
  123. for (let e of m) {
  124. let name = e.firstElementChild;
  125. if (name.getAttribute('item-readed') != 'true') {
  126. name.setAttribute('item-readed', 'true');
  127. name.style.color = 'grey';
  128. name.innerText = name.innerText.substring(1);
  129. }
  130. }
  131. });
  132. div_op.appendChild(link_mark);
  133.  
  134. let link_clear = document.createElement('a');
  135. link_clear.style.marginRight = '20px';
  136. link_clear.innerText = '〇 清空';
  137. link_clear.href = '###';
  138. link_clear.onclick = (() => {
  139. clearNotification();
  140. document.getElementById(g_userMessageDivId).innerHTML = '';
  141. });
  142. div_op.appendChild(link_clear);
  143.  
  144. let link_top = document.createElement('a');
  145. link_top.innerText = '〇 回到页首 ▲';
  146. link_top.href = '###';
  147. link_top.onclick = (() => { document.body.scrollIntoView(true); });
  148. div_op.appendChild(link_top);
  149.  
  150. div = document.createElement('div');
  151. div.className = 'panel-body';
  152. div.id = g_userMessageDivId;
  153. div_pan.appendChild(div);
  154. }
  155.  
  156. if (!noNotification) {
  157. let btn = document.getElementById(g_userMessageBtnId);
  158. if (btn == null) {
  159. let navBar = document.querySelector(g_navigatorSelector);
  160. btn = navBar.firstElementChild.cloneNode(true);
  161. btn.id = g_userMessageBtnId;
  162. btn.className += ' btn-danger';
  163. btn.setAttribute('onclick', `window.location.href='#${g_userMessageDivId}'`);
  164. navBar.appendChild(btn);
  165. }
  166. btn.innerText = `查看消息(${g_msgCount += msgs.length})`;
  167. btn.style.display = 'inline-block';
  168. }
  169.  
  170. let timeStamp = getTimeStamp();
  171. timeStamp = timeStamp.date + ' ' + timeStamp.time;
  172. let alt = (div.firstElementChild?.className?.length > 0);
  173. msgs.forEach((msg) => {
  174. let div_info = document.createElement('div');
  175. div_info.className = (alt = !alt ? 'alt' : '');
  176. div_info.style.backgroundColor = (alt ? '#f0f0f0' : '');
  177. div_info.style.padding = '5px';
  178. div_info.innerHTML =
  179. `<b style="color:purple;">★【${timeStamp}】${msg[0]}:</b>` +
  180. `<div style="padding:0px 0px 0px 15px;">${msg[1]}</div>`;
  181. div.insertBefore(div_info, div.firstElementChild);
  182. });
  183. }
  184. }
  185.  
  186. function addUserMessageSingle(title, msg, noNotification) {
  187. addUserMessage([[title, msg]], noNotification)
  188. }
  189.  
  190. function getTimeStamp(date, dateSeparator, timeSeparator) {
  191. date ??= new Date();
  192. dateSeparator ??= '-';
  193. timeSeparator ??= ':';
  194. return {
  195. date : `${('000' + date.getFullYear()).slice(-4)}${dateSeparator}${('0' + (date.getMonth() + 1))
  196. .slice(-2)}${dateSeparator}${('0' + date.getDate()).slice(-2)}`,
  197. time : `${('0' + date.getHours()).slice(-2)}${timeSeparator}${('0' + date.getMinutes())
  198. .slice(-2)}${timeSeparator}${('0' + date.getSeconds()).slice(-2)}`
  199. };
  200. }
  201.  
  202. function loadUserConfigData() {
  203. return JSON.parse(localStorage.getItem(g_kfUser));
  204. }
  205.  
  206. function saveUserConfigData(json) {
  207. localStorage.setItem(g_kfUser, JSON.stringify(json));
  208. }
  209.  
  210. // generic configuration items represented using checkboxes
  211. function setupConfigCheckbox(checkbox, configKey, fnPostProcess, fnParams) {
  212. checkbox.checked = (localStorage.getItem(configKey) == 'true');
  213. checkbox.onchange = ((e) => {
  214. localStorage.setItem(configKey, e.currentTarget.checked);
  215. if (fnPostProcess != null) {
  216. fnPostProcess(e.currentTarget.checked, fnParams);
  217. }
  218. });
  219. return checkbox.checked;
  220. }
  221.  
  222. // HTTP requests
  223. const GuGuZhenRequest = {
  224. read : { method : 'POST' , url : '/fyg_read.php' },
  225. update : { method : 'POST' , url : '/fyg_click.php' },
  226. user : { method : 'GET' , url : g_guguzhenHome },
  227. beach : { method : 'GET' , url : g_guguzhenBeach },
  228. pk : { method : 'GET' , url : g_guguzhenPK },
  229. equip : { method : 'GET' , url : g_guguzhenEquip },
  230. wish : { method : 'GET' , url : g_guguzhenWish },
  231. gem : { method : 'GET' , url : g_guguzhenGem },
  232. shop : { method : 'GET' , url : g_guguzhenShop }
  233. };
  234. const MoMoZhenRequest = GuGuZhenRequest;
  235. const g_postHeader = { 'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8' /*, 'Cookie' : document.cookie*/ };
  236. const g_networkTimeoutMS = 120 * 1000;
  237. var g_httpRequests = [];
  238. function httpRequestBegin(request, queryString, fnLoad, fnError, fnTimeout) {
  239. let requestObj;
  240. const g_readUrl = window.location.origin + '/fyg_read.php'
  241. const g_postUrl = window.location.origin + '/fyg_click.php'
  242. requestObj = new XMLHttpRequest();
  243. requestObj.onload = requestObj.onerror = requestObj.ontimeout = httpRequestEventHandler;
  244. requestObj.open(request.method, window.location.origin + request.url);
  245. for (let name in g_postHeader) {
  246. requestObj.setRequestHeader(name, g_postHeader[name]);
  247. }
  248. requestObj.send(queryString);
  249.  
  250. function httpRequestEventHandler(e) {
  251. switch (e.type) {
  252. case 'load':
  253. if (fnLoad != null) {
  254. fnLoad(e.currentTarget);
  255. }
  256. break;
  257. case 'error':
  258. if (fnError != null) {
  259. fnError(e.currentTarget);
  260. }
  261. break;
  262. case 'timeout':
  263. if (fnTimeout != null) {
  264. fnTimeout(e.currentTarget);
  265. }
  266. break;
  267. }
  268. }
  269. g_httpRequests.push(requestObj);
  270. return requestObj;
  271. }
  272.  
  273. function httpRequestAbortAll() {
  274. while (g_httpRequests.length > 0) {
  275. g_httpRequests.pop().abort();
  276. }
  277. g_httpRequests = [];
  278. }
  279.  
  280. function httpRequestClearAll() {
  281. g_httpRequests = [];
  282. }
  283.  
  284. // request data
  285. const g_httpRequestMap = new Map();
  286. function getRequestInfoAsync(name, location) {
  287. return new Promise((resolve) => {
  288. let r = g_httpRequestMap.get(name);
  289. if (r != null || !(name?.length > 0) || location == null) {
  290. resolve(r);
  291. }
  292. else {
  293. beginGetRequestMap(
  294. location,
  295. async () => {
  296. resolve(await getRequestInfoAsync(name, null));
  297. });
  298. }
  299. });
  300. }
  301.  
  302. function beginGetRequestMap(location, fnPostProcess, fnParams) {
  303. function searchScript(text) {
  304. let regex = /<script.+?<\/script>/gms;
  305. let script;
  306. while ((script = regex.exec(text))?.length > 0) {
  307. searchFunction(script[0]);
  308. }
  309. if (fnPostProcess != null) {
  310. fnPostProcess(fnParams);
  311. }
  312. }
  313. function searchFunction(text) {
  314. let regex = /^\s*function\s+(.+?)\s*\(.+?\{(.+?)((^\s*function)|(<\/script>))/gms;
  315. let func;
  316. while ((func = regex.exec(text))?.length == 6 && func[1]?.length > 0 && func[2]?.length > 0) {
  317. let request = searchRequest(func[2]);
  318. if (request != null) {
  319. g_httpRequestMap.set(func[1], request);
  320. }
  321. if (func[3] != '<\/script>') {
  322. regex.lastIndex -= func[3].length;
  323. }
  324. else {
  325. break;
  326. }
  327. }
  328. }
  329. function searchRequest(text) {
  330. let method = text.match(/^\s*type\s*:\s*"(.+)"\s*,\s*$/m);
  331. let url = text.match(/^\s*url\s*:\s*"(.+)"\s*,\s*$/m);
  332. let data = text.match(/^\s*data\s*:\s*"(.+),\s*$/m);
  333. if (method?.length > 1 && url?.length > 1 && data?.length > 1) {
  334. return {
  335. request : {
  336. method : method[1],
  337. url : (url[1].startsWith('/') ? '' : '/') + url[1]
  338. },
  339. data : data[1].endsWith('"') ? data[1].slice(0, -1) : data[1]
  340. };
  341. }
  342. return null;
  343. }
  344.  
  345. if (location == null) {
  346. searchScript(document.documentElement.innerHTML);
  347. }
  348. else {
  349. httpRequestBegin(location, '', (response) => { searchScript(response.responseText); });
  350. }
  351. }
  352. // beginGetRequestMap(null, () => { console.log(g_httpRequestMap); });
  353. beginGetRequestMap();
  354.  
  355. // read objects from bag and store with title filter
  356. function beginReadObjects(bag, store, fnPostProcess, fnParams) {
  357. if (bag != null || store != null) {
  358. httpRequestBegin(
  359. GuGuZhenRequest.read,
  360. 'f=7',
  361. (response) => {
  362. let div = document.createElement('div');
  363. div.innerHTML = response.responseText;
  364.  
  365. if (bag != null) {
  366. div.querySelectorAll('div.alert-danger > button.btn.fyg_mp3')?.forEach((e) => { bag.push(e); });
  367. }
  368. if (store != null) {
  369. div.querySelectorAll('div.alert-success > button.btn.fyg_mp3')?.forEach((e) => { store.push(e); });
  370. }
  371. if (fnPostProcess != null) {
  372. fnPostProcess(fnParams);
  373. }
  374. });
  375. }
  376. else if (fnPostProcess != null) {
  377. fnPostProcess(fnParams);
  378. }
  379. }
  380.  
  381. function beginReadObjectIds(bagIds, storeIds, key, ignoreEmptyCell, fnPostProcess, fnParams) {
  382. function parseObjectIds() {
  383. if (bagIds != null) {
  384. objectIdParseNodes(bag, bagIds, key, ignoreEmptyCell);
  385. }
  386. if (storeIds != null) {
  387. objectIdParseNodes(store, storeIds, key, ignoreEmptyCell);
  388. }
  389. if (fnPostProcess != null) {
  390. fnPostProcess(fnParams);
  391. }
  392. }
  393.  
  394. let bag = (bagIds != null ? [] : null);
  395. let store = (storeIds != null ? [] : null);
  396. if (bag != null || store != null) {
  397. beginReadObjects(bag, store, parseObjectIds, null);
  398. }
  399. else if (fnPostProcess != null) {
  400. fnPostProcess(fnParams);
  401. }
  402. }
  403.  
  404. function objectIdParseNodes(nodes, ids, key, ignoreEmptyCell) {
  405. for (let node of nodes) {
  406. if (node.className?.indexOf('fyg_mp3') >= 0) {
  407. let click = node.getAttribute('onclick');
  408. let id = click?.match(/\d+/g);
  409. if (id?.length > 0) {
  410. id = id[click?.match(/omenu/)?.length > 0 ? id.length - 1 : 0];
  411. if (id != null) {
  412. if (objectMatchTitle(node, key)) {
  413. ids.push(parseInt(id));
  414. continue;
  415. }
  416. }
  417. }
  418. if (!ignoreEmptyCell) {
  419. ids.push(-1);
  420. }
  421. }
  422. }
  423. }
  424.  
  425. function objectMatchTitle(node, key){
  426. return (!(key?.length > 0) || (node.getAttribute('data-original-title') ?? node.getAttribute('title'))?.indexOf(key) >= 0);
  427. }
  428.  
  429. // we wait the response(s) of the previous batch of request(s) to send another batch of request(s)
  430. // rather than simply send them all within an inside foreach - which could cause too many requests
  431. // to server simultaneously, that can be easily treated as D.D.O.S attack and therefor leads server
  432. // to returns http status 503: Service Temporarily Unavailable
  433. // * caution * the parameter 'objects' is required been sorted by their indices in ascending order
  434. const ConcurrentRequestCount = { min : 1 , max : 8 , default : 4 };
  435. const ObjectMovePath = { bag2store : 0 , store2bag : 1 , store2beach : 2 , beach2store : 3 };
  436. const ObjectMoveRequestLocation = [
  437. { location : GuGuZhenRequest.equip , name : 'puti' },
  438. { location : GuGuZhenRequest.equip , name : 'puto' },
  439. { location : GuGuZhenRequest.beach , name : 'stdel' },
  440. { location : GuGuZhenRequest.beach , name : 'stpick' }
  441. ];
  442. const ObjectMoveRequest = [ null, null, null, null ];
  443. var g_maxConcurrentRequests = ConcurrentRequestCount.default;
  444. var g_objectMoveRequestsCount = 0;
  445. var g_objectMoveTargetSiteFull = false;
  446. async function beginMoveObjects(objects, path, fnPostProcess, fnParams) {
  447. if (!g_objectMoveTargetSiteFull && objects?.length > 0) {
  448. ObjectMoveRequest[path] ??= await getRequestInfoAsync(ObjectMoveRequestLocation[path].name,
  449. ObjectMoveRequestLocation[path].location);
  450. if (ObjectMoveRequest[path] == null) {
  451. console.log('missing function:', ObjectMoveRequestLocation[path].name);
  452. return;
  453. }
  454. let ids = [];
  455. while (ids.length < g_maxConcurrentRequests && objects.length > 0) {
  456. let id = objects.pop();
  457. if (id >= 0) {
  458. ids.push(id);
  459. }
  460. }
  461. if ((g_objectMoveRequestsCount = ids.length) > 0) {
  462. while (ids.length > 0) {
  463. httpRequestBegin(
  464. ObjectMoveRequest[path].request,
  465. ObjectMoveRequest[path].data.replace('"+id+"', ids.shift()),
  466. (response) => {
  467. if (path != ObjectMovePath.store2beach && response.responseText != 'ok') {
  468. g_objectMoveTargetSiteFull = true;
  469. console.log(response.responseText);
  470. }
  471. if (--g_objectMoveRequestsCount == 0) {
  472. beginMoveObjects(objects, path, fnPostProcess, fnParams);
  473. }
  474. });
  475. }
  476. return;
  477. }
  478. }
  479. g_objectMoveTargetSiteFull = false;
  480. if (fnPostProcess != null) {
  481. fnPostProcess(fnParams);
  482. }
  483. }
  484.  
  485. const g_beach_pirl_verify_data = '85797';
  486. const g_store_pirl_verify_data = '124';
  487. const g_objectPirlRequest = g_httpRequestMap.get('pirl');
  488. var g_objectPirlRequestsCount = 0;
  489. function beginPirlObjects(storePirl, objects, fnPostProcess, fnParams) {
  490. if (objects?.length > 0) {
  491. let ids = [];
  492. while (ids.length < g_maxConcurrentRequests && objects.length > 0) {
  493. ids.push(objects.pop());
  494. }
  495. if ((g_objectPirlRequestsCount = ids.length) > 0) {
  496. while (ids.length > 0) {
  497. httpRequestBegin(
  498. g_objectPirlRequest.request,
  499. g_objectPirlRequest.data.replace('"+id+"', ids.shift()).replace(
  500. '"+pirlyz+"', storePirl ? g_store_pirl_verify_data : g_beach_pirl_verify_data),
  501. (response) => {
  502. if (!/\d+/.test(response.responseText.trim()) && response.responseText.indexOf('果核') < 0) {
  503. console.log(response.responseText);
  504. }
  505. if (--g_objectPirlRequestsCount == 0) {
  506. beginPirlObjects(storePirl, objects, fnPostProcess, fnParams);
  507. }
  508. });
  509. }
  510. return;
  511. }
  512. }
  513. if (fnPostProcess != null) {
  514. fnPostProcess(fnParams);
  515. }
  516. }
  517.  
  518. // roleInfo = [ roleId, roleName, [ equips ] ]
  519. function beginReadRoleInfo(roleInfo, fnPostProcess, fnParams) {
  520. function parseCarding(carding) {
  521. if (roleInfo != null) {
  522. let role = g_roleMap.get(carding.querySelector('div.text-info.fyg_f24.fyg_lh60')?.children[0]?.innerText);
  523. if (role != null) {
  524. roleInfo.push(role.id);
  525. roleInfo.push(role.name);
  526. roleInfo.push(carding.querySelectorAll('div.row > div.fyg_tc > button.btn.fyg_mp3'));
  527. }
  528. }
  529. }
  530. let div = document.getElementById('carding');
  531. if (div == null) {
  532. httpRequestBegin(
  533. GuGuZhenRequest.read,
  534. 'f=9',
  535. (response) => {
  536. div = document.createElement('div');
  537. div.innerHTML = response.responseText;
  538. parseCarding(div);
  539.  
  540. if (fnPostProcess != null) {
  541. fnPostProcess(fnParams);
  542. }
  543. });
  544. return;
  545. }
  546. parseCarding(div);
  547.  
  548. if (fnPostProcess != null) {
  549. fnPostProcess(fnParams);
  550. }
  551. }
  552.  
  553. // haloInfo = [ haloPoints, haloSlots, [ haloItem1, haloItem2, ... ] ]
  554. function beginReadHaloInfo(haloInfo, fnPostProcess, fnParams) {
  555. httpRequestBegin(
  556. GuGuZhenRequest.read,
  557. 'f=5',
  558. (response) => {
  559. if (haloInfo != null) {
  560. let haloPS = response.responseText.match(/<h3>.+?(\d+).+?(\d+).+?<\/h3>/);
  561. if (haloPS?.length == 3) {
  562. haloInfo.push(parseInt(haloPS[1]));
  563. haloInfo.push(parseInt(haloPS[2]));
  564. }
  565. else {
  566. haloInfo.push(0);
  567. haloInfo.push(0);
  568. }
  569. let halo = [];
  570. for (let item of response.responseText.matchAll(/halotfzt2\((\d+)\)/g)) {
  571. halo.push(item[1]);
  572. }
  573. haloInfo.push(halo);
  574. }
  575. if (fnPostProcess != null) {
  576. fnPostProcess(fnParams);
  577. }
  578. });
  579. }
  580.  
  581. function beginReadWishpool(points, misc, fnPostProcess, fnParams) {
  582. httpRequestBegin(
  583. GuGuZhenRequest.read,
  584. 'f=19',
  585. (response) => {
  586. let a = response.responseText.split('#');
  587. if (misc != null) {
  588. misc[0] = a[0];
  589. misc[1] = a[1];
  590. }
  591. if (points != null) {
  592. for (let i = a.length - 1; i >= 2; i--) {
  593. points[i - 2] = a[i];
  594. }
  595. }
  596. if (fnPostProcess != null) {
  597. fnPostProcess(fnParams);
  598. }
  599. });
  600. }
  601.  
  602. // userInfo = [ kfUser, grade, level, seashell, bvip, svip ]
  603. function beginReadUserInfo(userInfo, fnPostProcess, fnParams) {
  604. httpRequestBegin(
  605. GuGuZhenRequest.user,
  606. '',
  607. (response) => {
  608. if (userInfo != null) {
  609. userInfo.push(g_kfUser);
  610. userInfo.push(response.responseText.match(/<p.+?>\s*段位\s*<.+?>\s*(.+?)\s*<.+?<\/p>/)?.[1] ?? '');
  611. userInfo.push(response.responseText.match(/<p.+?>\s*等级\s*<.+?>\s*(\d+).*?<.+?<\/p>/)?.[1] ?? '');
  612. userInfo.push(response.responseText.match(/<p.+?>\s*贝壳\s*<.+?>\s*(\d+).*?<.+?<\/p>/)?.[1] ?? '');
  613. userInfo.push(response.responseText.match(/<p.+?>\s*BVIP\s*<.+?>\s*(.+?)\s*<.+?<\/p>/)?.[1] ?? '');
  614. userInfo.push(response.responseText.match(/<p.+?>\s*SVIP\s*<.+?>\s*(.+?)\s*<.+?<\/p>/)?.[1] ?? '');
  615. }
  616. if (fnPostProcess != null) {
  617. fnPostProcess(fnParams);
  618. }
  619. });
  620. }
  621.  
  622. ////////////////////////////////////////////////////////////////////////////////////////////////////
  623. //
  624. // amulet management
  625. //
  626. ////////////////////////////////////////////////////////////////////////////////////////////////////
  627.  
  628. const AMULET_STORAGE_GROUP_SEPARATOR = '|';
  629. const AMULET_STORAGE_GROUPNAME_SEPARATOR = '=';
  630. const AMULET_STORAGE_AMULET_SEPARATOR = ',';
  631. const AMULET_STORAGE_CODEC_SEPARATOR = '-';
  632. const AMULET_STORAGE_ITEM_SEPARATOR = ' ';
  633. const AMULET_STORAGE_ITEM_NV_SEPARATOR = '+';
  634.  
  635. // deprecated
  636. const AMULET_TYPE_ID_FACTOR = 100000000000000;
  637. const AMULET_LEVEL_ID_FACTOR = 10000000000000;
  638. const AMULET_ENHANCEMENT_FACTOR = 1000000000000;
  639. const AMULET_BUFF_MAX_FACTOR = AMULET_ENHANCEMENT_FACTOR;
  640. // deprecated
  641.  
  642. const g_amuletDefaultLevelIds = {
  643. start : 0,
  644. end : 2,
  645. 稀有 : 0,
  646. 史诗 : 1,
  647. 传奇 : 2
  648. };
  649. const g_amuletDefaultTypeIds = {
  650. start : 2,
  651. end : 6,
  652. 星铜苹果 : 0,
  653. 蓝银葡萄 : 1,
  654. 紫晶樱桃 : 2
  655. };
  656. const g_amuletDefaultLevelNames = [ '稀有', '史诗', '传奇' ];
  657. const g_amuletDefaultTypeNames = [ '星铜苹果', '蓝银葡萄', '紫晶樱桃' ];
  658. const g_amuletBuffs = [
  659. { index : -1 , name : '力量' , type : 0 , maxValue : 80 , unit : '点' , shortMark : 'STR' },
  660. { index : -1 , name : '敏捷' , type : 0 , maxValue : 80 , unit : '点' , shortMark : 'AGI' },
  661. { index : -1 , name : '智力' , type : 0 , maxValue : 80 , unit : '点' , shortMark : 'INT' },
  662. { index : -1 , name : '体魄' , type : 0 , maxValue : 80 , unit : '点' , shortMark : 'VIT' },
  663. { index : -1 , name : '精神' , type : 0 , maxValue : 80 , unit : '点' , shortMark : 'SPR' },
  664. { index : -1 , name : '意志' , type : 0 , maxValue : 80 , unit : '点' , shortMark : 'MND' },
  665. { index : -1 , name : '物理攻击' , type : 1 , maxValue : 10 , unit : '%' , shortMark : 'PATK' },
  666. { index : -1 , name : '魔法攻击' , type : 1 , maxValue : 10 , unit : '%' , shortMark : 'MATK' },
  667. { index : -1 , name : '速度' , type : 1 , maxValue : 10 , unit : '%' , shortMark : 'SPD' },
  668. { index : -1 , name : '生命护盾回复效果' , type : 1 , maxValue : 10 , unit : '%' , shortMark : 'REC' },
  669. { index : -1 , name : '最大生命值' , type : 1 , maxValue : 10 , unit : '%' , shortMark : 'HP' },
  670. { index : -1 , name : '最大护盾值' , type : 1 , maxValue : 10 , unit : '%' , shortMark : 'SLD' },
  671. { index : -1 , name : '固定生命偷取' , type : 2 , maxValue : 10 , unit : '%' , shortMark : 'LCH' },
  672. { index : -1 , name : '固定反伤' , type : 2 , maxValue : 10 , unit : '%' , shortMark : 'RFL' },
  673. { index : -1 , name : '固定暴击几率' , type : 2 , maxValue : 10 , unit : '%' , shortMark : 'CRT' },
  674. { index : -1 , name : '固定技能几率' , type : 2 , maxValue : 10 , unit : '%' , shortMark : 'SKL' },
  675. { index : -1 , name : '物理防御效果' , type : 2 , maxValue : 10 , unit : '%' , shortMark : 'PDEF' },
  676. { index : -1 , name : '魔法防御效果' , type : 2 , maxValue : 10 , unit : '%' , shortMark : 'MDEF' },
  677. { index : -1 , name : '全属性' , type : 2 , maxValue : 10 , unit : '点' , shortMark : 'AAA' },
  678. { index : -1 , name : '暴击抵抗' , type : 2 , maxValue : 5 , unit : '%' , shortMark : 'CRTR' },
  679. { index : -1 , name : '技能抵抗' , type : 2 , maxValue : 5 , unit : '%' , shortMark : 'SKLR' }
  680. ];
  681. const g_amuletBuffMap = new Map();
  682. g_amuletBuffs.forEach((item, index) => {
  683. item.index = index;
  684. g_amuletBuffMap.set(item.index, item);
  685. g_amuletBuffMap.set(item.index.toString(), item);
  686. g_amuletBuffMap.set(item.name, item);
  687. g_amuletBuffMap.set(item.shortMark, item);
  688. });
  689.  
  690. var g_amuletLevelIds = g_amuletDefaultLevelIds;
  691. var g_amuletTypeIds = g_amuletDefaultTypeIds;
  692. var g_amuletLevelNames = g_amuletDefaultLevelNames;
  693. var g_amuletTypeNames = g_amuletDefaultTypeNames;
  694.  
  695. function amuletLoadTheme(theme) {
  696. if (theme.dessertlevel?.length > 0 && theme.dessertname?.length > 0) {
  697. g_amuletLevelNames = theme.dessertlevel;
  698. g_amuletTypeNames = theme.dessertname;
  699. g_amuletLevelIds = {
  700. start : 0,
  701. end : theme.dessertlevel[0].length
  702. };
  703. g_amuletTypeIds = {
  704. start : theme.dessertlevel[0].length,
  705. end : theme.dessertlevel[0].length + theme.dessertname[0].length
  706. };
  707. for (let i = g_amuletLevelNames.length - 1; i >= 0; i--) {
  708. g_amuletLevelIds[g_amuletLevelNames[i].slice(0, g_amuletLevelIds.end - g_amuletLevelIds.start)] = i;
  709. }
  710. for (let i = g_amuletTypeNames.length - 1; i >= 0; i--) {
  711. g_amuletTypeIds[g_amuletTypeNames[i].slice(0, g_amuletTypeIds.end - g_amuletTypeIds.start)] = i;
  712. }
  713. }
  714. }
  715.  
  716. function Amulet() {
  717. this.isAmulet = true;
  718. this.id = -1;
  719. this.type = -1;
  720. this.level = 0;
  721. this.enhancement = 0;
  722. this.buffs = [];
  723. this.buffCode = null;
  724. this.text = null;
  725.  
  726. this.reset = (() => {
  727. this.id = -1;
  728. this.type = -1;
  729. this.level = 0;
  730. this.enhancement = 0;
  731. this.buffs = [];
  732. this.buffCode = null;
  733. this.text = null;
  734. });
  735.  
  736. this.isValid = (() => {
  737. return (this.type >= 0 && this.type < g_amuletDefaultTypeNames.length);
  738. });
  739.  
  740. this.addItem = ((item, buff) => {
  741. if (this.isValid()) {
  742. let meta = g_amuletBuffMap.get(item);
  743. if (meta?.type == this.type && (buff = parseInt(buff)) > 0) {
  744. this.buffs[meta.index] = (this.buffs[meta.index] ?? 0) + buff;
  745. this.buffCode = null;
  746. return true;
  747. }
  748. else {
  749. this.reset();
  750. }
  751. }
  752. return false;
  753. });
  754.  
  755. this.fromCode = ((code) => {
  756. this.reset();
  757. let e = code?.split(AMULET_STORAGE_CODEC_SEPARATOR);
  758. if (e?.length == 4) {
  759. this.type = parseInt(e[0]);
  760. this.level = parseInt(e[1]);
  761. this.enhancement = parseInt(e[2]);
  762. e[3].split(AMULET_STORAGE_ITEM_SEPARATOR).forEach((item) => {
  763. let nv = item.split(AMULET_STORAGE_ITEM_NV_SEPARATOR);
  764. this.addItem(nv[0], nv[1]);
  765. });
  766. this.getCode();
  767. }
  768. return (this.isValid() ? this : null);
  769. });
  770.  
  771. this.fromBuffText = ((text) => {
  772. this.reset();
  773. let nb = text?.split(' = ');
  774. if (nb?.length == 2) {
  775. this.type = (g_amuletTypeIds[nb[0].slice(g_amuletTypeIds.start, g_amuletTypeIds.end)] ??
  776. g_amuletDefaultTypeIds[nb[0].slice(g_amuletDefaultTypeIds.start, g_amuletDefaultTypeIds.end)]);
  777. this.level = (g_amuletLevelIds[nb[0].slice(g_amuletLevelIds.start, g_amuletLevelIds.end)] ??
  778. g_amuletDefaultLevelIds[nb[0].slice(g_amuletDefaultLevelIds.start, g_amuletDefaultLevelIds.end)]);
  779. this.enhancement = parseInt(nb[0].match(/\d+/)[0]);
  780. this.buffCode = 0;
  781. nb[1].replaceAll(/(\+)|( 点)|( %)/g, '').split(',').forEach((buff) => {
  782. let nv = buff.trim().split(' ');
  783. this.addItem(nv[0], nv[1]);
  784. });
  785. if (this.isValid()) {
  786. this.text = nb[1];
  787. this.getCode();
  788. return this;
  789. }
  790. }
  791. this.reset();
  792. return null;
  793. });
  794.  
  795. this.fromNode = ((node) => {
  796. if (node?.nodeType == Node.ELEMENT_NODE) {
  797. if (this.fromBuffText(node.getAttribute('amulate-string')) != null &&
  798. !isNaN(this.id = parseInt(node.getAttribute('onclick').match(/\d+/)?.[0]))) {
  799.  
  800. return this;
  801. }
  802. else if (node.className?.indexOf('fyg_mp3') >= 0) {
  803. this.reset();
  804. let typeName = (node.getAttribute('data-original-title') ?? node.getAttribute('title'));
  805. if (!/Lv.+?>\d+</.test(typeName)) {
  806. let id = node.getAttribute('onclick');
  807. let content = node.getAttribute('data-content');
  808. if (id?.length > 0 && content?.length > 0 &&
  809. !isNaN(this.type = (g_amuletTypeIds[typeName.slice(g_amuletTypeIds.start, g_amuletTypeIds.end)] ??
  810. g_amuletDefaultTypeIds[typeName.slice(g_amuletDefaultTypeIds.start,
  811. g_amuletDefaultTypeIds.end)])) &&
  812. !isNaN(this.level = (g_amuletLevelIds[typeName.slice(g_amuletLevelIds.start, g_amuletLevelIds.end)] ??
  813. g_amuletDefaultLevelIds[typeName.slice(g_amuletDefaultLevelIds.start,
  814. g_amuletDefaultLevelIds.end)])) &&
  815. !isNaN(this.id = parseInt(id.match(/\d+/)?.[0])) &&
  816. !isNaN(this.enhancement = parseInt(node.innerText))) {
  817.  
  818. this.text = '';
  819. let attr = null;
  820. let regex = /<p.*?>(.+?)<.*?>\+(\d+).*?<\/span><\/p>/g;
  821. while ((attr = regex.exec(content))?.length == 3) {
  822. let buffMeta = g_amuletBuffMap.get(attr[1]);
  823. if (buffMeta != null) {
  824. if (!this.addItem(attr[1], attr[2])) {
  825. break;
  826. }
  827. this.text += `${this.text.length > 0 ? ', ' : ''}${attr[1]} +${attr[2]} ${buffMeta.unit}`;
  828. }
  829. }
  830. if (this.isValid()) {
  831. node.setAttribute('amulet-string', this.formatBuffText());
  832. this.getCode();
  833. return this;
  834. }
  835. }
  836. }
  837. }
  838. }
  839. this.reset();
  840. return null;
  841. });
  842.  
  843. this.fromAmulet = ((amulet) => {
  844. this.reset();
  845. if (amulet?.isValid()) {
  846. this.id = amulet.id;
  847. this.type = amulet.type;
  848. this.level = amulet.level;
  849. this.enhancement = amulet.enhancement;
  850. this.buffs = amulet.buffs.slice();
  851. this.buffCode = amulet.buffCode;
  852. this.text = amulet.text;
  853. }
  854. return (this.isValid() ? this : null);
  855. });
  856.  
  857. this.getCode = (() => {
  858. if (this.isValid()) {
  859. if (!(this.buffCode?.length > 0)) {
  860. let bc = [];
  861. this.buffs.forEach((e, i) => {
  862. bc.push(i + AMULET_STORAGE_ITEM_NV_SEPARATOR + e);
  863. });
  864. this.buffCode = bc.join(AMULET_STORAGE_ITEM_SEPARATOR);
  865. }
  866. return (this.type + AMULET_STORAGE_CODEC_SEPARATOR +
  867. this.level + AMULET_STORAGE_CODEC_SEPARATOR +
  868. this.enhancement + AMULET_STORAGE_CODEC_SEPARATOR +
  869. this.buffCode);
  870. }
  871. return null;
  872. });
  873.  
  874. this.getBuff = (() => {
  875. return this.buffs;
  876. });
  877.  
  878. this.getTotalPoints = (() => {
  879. let points = 0;
  880. this.buffs?.forEach((e) => {
  881. points += e;
  882. });
  883. return points;
  884. });
  885.  
  886. this.formatName = (() => {
  887. if (this.isValid()) {
  888. return `${g_amuletLevelNames[this.level]}${g_amuletTypeNames[this.type]} (+${this.enhancement})`;
  889. }
  890. return null;
  891. });
  892.  
  893. this.formatBuff = (() => {
  894. if (this.isValid()) {
  895. if (this.text?.length > 0) {
  896. return this.text;
  897. }
  898. let bi = [];
  899. this.buffs.forEach((e, i) => {
  900. let meta = g_amuletBuffMap.get(i);
  901. bi.push(`${meta.name} +${e} ${meta.unit}`);
  902. });
  903. this.text = bi.join(', ');
  904. }
  905. return this.text;
  906. });
  907.  
  908. this.formatBuffText = (() => {
  909. if (this.isValid()) {
  910. return this.formatName() + ' = ' + this.formatBuff();
  911. }
  912. return null;
  913. });
  914.  
  915. this.formatShortMark = (() => {
  916. let text = this.formatBuff()?.replaceAll(/(\+)|( 点)|( %)/g, '');
  917. if (text?.length > 0) {
  918. this.buffs.forEach((e, i) => {
  919. let meta = g_amuletBuffMap.get(i);
  920. text = text.replaceAll(meta.name, meta.shortMark);
  921. });
  922. return this.formatName() + ' = ' + text;
  923. }
  924. return null;
  925. });
  926.  
  927. this.compareMatch = ((other, ascType) => {
  928. if (!this.isValid()) {
  929. return 1;
  930. }
  931. else if (!other?.isValid()) {
  932. return -1;
  933. }
  934.  
  935. let delta = other.type - this.type;
  936. if (delta != 0) {
  937. return (ascType ? -delta : delta);
  938. }
  939. return (other.buffCode > this.buffCode ? -1 : (other.buffCode < this.buffCode ? 1 : 0));
  940. });
  941.  
  942. this.compareTo = ((other, ascType) => {
  943. if (!this.isValid()) {
  944. return 1;
  945. }
  946. else if (!other?.isValid()) {
  947. return -1;
  948. }
  949.  
  950. let delta = other.type - this.type;
  951. if (delta != 0) {
  952. return (ascType ? -delta : delta);
  953. }
  954.  
  955. let tbuffs = this.formatBuffText().split(' = ')[1].replaceAll(/(\+)|( 点)|( %)/g, '').split(', ');
  956. let obuffs = other.formatBuffText().split(' = ')[1].replaceAll(/(\+)|( 点)|( %)/g, '').split(', ');
  957. let bl = Math.min(tbuffs.length, obuffs.length);
  958. for (let i = 0; i < bl; i++) {
  959. let tbuff = tbuffs[i].split(' ');
  960. let obuff = obuffs[i].split(' ');
  961. if ((delta = g_amuletBuffMap.get(tbuff[0]).index - g_amuletBuffMap.get(obuff[0]).index) != 0 ||
  962. (delta = parseInt(obuff[1]) - parseInt(tbuff[1])) != 0) {
  963. return delta;
  964. }
  965. }
  966. if ((delta = obuffs.length - tbuffs.length) != 0 ||
  967. (delta = other.level - this.level) != 0 ||
  968. (delta = other.enhancement - this.enhancement) != 0) {
  969. return delta;
  970. }
  971.  
  972. return 0;
  973. });
  974. }
  975.  
  976. function AmuletGroup(persistenceString) {
  977. this.isAmuletGroup = true;
  978. this.name = null;
  979. this.items = [];
  980. this.buffSummary = [];
  981.  
  982. this.isValid = (() => {
  983. return (this.items.length > 0 && amuletIsValidGroupName(this.name));
  984. });
  985.  
  986. this.count = (() => {
  987. return this.items.length;
  988. });
  989.  
  990. this.clear = (() => {
  991. this.items = [];
  992. this.buffSummary = [];
  993. });
  994.  
  995. this.add = ((amulet) => {
  996. if (amulet?.isValid()) {
  997. amulet.buffs.forEach((e, i) => {
  998. this.buffSummary[i] = (this.buffSummary[i] ?? 0) + e;
  999. });
  1000. return insertElement(this.items, amulet, (a, b) => a.compareTo(b, true));
  1001. }
  1002. return -1;
  1003. });
  1004.  
  1005. this.remove = ((amulet) => {
  1006. if (this.isValid() && amulet?.isValid()) {
  1007. let i = searchElement(this.items, amulet, (a, b) => a.compareTo(b, true));
  1008. if (i >= 0) {
  1009. amulet.buffs.forEach((e, i) => {
  1010. this.buffSummary[i] -= e;
  1011. if (this.buffSummary[i] <= 0) {
  1012. delete this.buffSummary[i];
  1013. }
  1014. });
  1015. this.items.splice(i, 1);
  1016. return true;
  1017. }
  1018. }
  1019. return false;
  1020. });
  1021.  
  1022. this.removeId = ((id) => {
  1023. if (this.isValid()) {
  1024. let i = this.items.findIndex((a) => a.id == id);
  1025. if (i >= 0) {
  1026. let amulet = this.items[i];
  1027. amulet.buffs.forEach((e, i) => {
  1028. this.buffSummary[i] -= e;
  1029. if (this.buffSummary[i] <= 0) {
  1030. delete this.buffSummary[i];
  1031. }
  1032. });
  1033. this.items.splice(i, 1);
  1034. return amulet;
  1035. }
  1036. }
  1037. return null;
  1038. });
  1039.  
  1040. this.merge = ((group) => {
  1041. group?.items?.forEach((am) => { this.add(am); });
  1042. return this;
  1043. });
  1044.  
  1045. this.validate = ((amulets) => {
  1046. if (this.isValid()) {
  1047. let mismatch = 0;
  1048. let al = this.items.length;
  1049. let i = 0;
  1050. if (amulets?.length > 0) {
  1051. amulets = amulets.slice().sort((a, b) => a.compareMatch(b));
  1052. for ( ; amulets.length > 0 && i < al; i++) {
  1053. let mi = searchElement(amulets, this.items[i], (a, b) => a.compareMatch(b));
  1054. if (mi >= 0) {
  1055. // remove a matched amulet from the amulet pool can avoid one single amulet matches all
  1056. // the equivalent objects in the group.
  1057. // let's say two (or even more) AGI +5 apples in one group is fairly normal, if we just
  1058. // have only one equivalent apple in the amulet pool and we don't remove it when the
  1059. // first match happens, then the 2nd apple will get matched later, the consequence would
  1060. // be we can never find the mismatch which should be encountered at the 2nd apple
  1061. this.items[i].fromAmulet(amulets[mi]);
  1062. amulets.splice(mi, 1);
  1063. }
  1064. else {
  1065. mismatch++;
  1066. }
  1067. }
  1068. }
  1069. if (i > mismatch) {
  1070. this.items.sort((a, b) => a.compareTo(b, true));
  1071. }
  1072. if (i < al) {
  1073. mismatch += (al - i);
  1074. }
  1075. return (mismatch == 0);
  1076. }
  1077. return false;
  1078. });
  1079.  
  1080. this.findIndices = ((amulets) => {
  1081. let indices = [];
  1082. let al;
  1083. if (this.isValid() && (al = amulets?.length) > 0) {
  1084. let items = this.items.slice().sort((a, b) => a.compareMatch(b));
  1085. for (let i = 0; items.length > 0 && i < al; i++) {
  1086. let mi;
  1087. if (amulets[i]?.id >= 0 && (mi = searchElement(items, amulets[i], (a, b) => a.compareMatch(b))) >= 0) {
  1088. // similar to the 'validate', remove the amulet from the search list when we found
  1089. // a match item in first time to avoid the duplicate founding, e.g. say we need only
  1090. // one AGI +5 apple in current group and we actually have 10 of AGI +5 apples in store,
  1091. // if we found the first matched itme in store and record it's index but not remove it
  1092. // from the temporary searching list, then we will continuously reach this kind of
  1093. // founding and recording until all those 10 AGI +5 apples are matched and processed,
  1094. // this obviously ain't the result what we expected
  1095. indices.push(i);
  1096. items.splice(mi, 1);
  1097. }
  1098. }
  1099. }
  1100. return indices;
  1101. });
  1102.  
  1103. this.parse = ((persistenceString) => {
  1104. this.clear();
  1105. if (persistenceString?.length > 0) {
  1106. let elements = persistenceString.split(AMULET_STORAGE_GROUPNAME_SEPARATOR);
  1107. if (elements.length == 2) {
  1108. let name = elements[0].trim();
  1109. if (amuletIsValidGroupName(name)) {
  1110. let items = elements[1].split(AMULET_STORAGE_AMULET_SEPARATOR);
  1111. let il = items.length;
  1112. for (let i = 0; i < il; i++) {
  1113. if (this.add((new Amulet()).fromCode(items[i])) < 0) {
  1114. this.clear();
  1115. break;
  1116. }
  1117. }
  1118. if (this.count() > 0) {
  1119. this.name = name;
  1120. }
  1121. }
  1122. }
  1123. }
  1124. return (this.count() > 0);
  1125. });
  1126.  
  1127. this.formatBuffSummary = ((linePrefix, lineSuffix, lineSeparator, ignoreMaxValue) => {
  1128. if (this.isValid()) {
  1129. let str = '';
  1130. let nl = '';
  1131. g_amuletBuffs.forEach((buff) => {
  1132. let v = this.buffSummary[buff.index];
  1133. if (v > 0) {
  1134. str += `${nl}${linePrefix}${buff.name} +${ignoreMaxValue ? v : Math.min(v, buff.maxValue)} ${buff.unit}${lineSuffix}`;
  1135. nl = lineSeparator;
  1136. }
  1137. });
  1138. return str;
  1139. }
  1140. return '';
  1141. });
  1142.  
  1143. this.formatBuffShortMark = ((keyValueSeparator, itemSeparator, ignoreMaxValue) => {
  1144. if (this.isValid()) {
  1145. let str = '';
  1146. let sp = '';
  1147. g_amuletBuffs.forEach((buff) => {
  1148. let v = this.buffSummary[buff.index];
  1149. if (v > 0) {
  1150. str += `${sp}${buff.shortMark}${keyValueSeparator}${ignoreMaxValue ? v : Math.min(v, buff.maxValue)}`;
  1151. sp = itemSeparator;
  1152. }
  1153. });
  1154. return str;
  1155. }
  1156. return '';
  1157. });
  1158.  
  1159. this.formatItems = ((linePrefix, erroeLinePrefix, lineSuffix, errorLineSuffix, lineSeparator) => {
  1160. if (this.isValid()) {
  1161. let str = '';
  1162. let nl = '';
  1163. this.items.forEach((amulet) => {
  1164. str += `${nl}${amulet.id < 0 ? erroeLinePrefix : linePrefix}${amulet.formatBuffText()}` +
  1165. `${amulet.id < 0 ? errorLineSuffix : lineSuffix}`;
  1166. nl = lineSeparator;
  1167. });
  1168. return str;
  1169. }
  1170. return '';
  1171. });
  1172.  
  1173. this.getDisplayStringLineCount = (() => {
  1174. if (this.isValid()) {
  1175. let lines = 0;
  1176. g_amuletBuffs.forEach((buff) => {
  1177. if (this.buffSummary[buff.index] > 0) {
  1178. lines++;
  1179. }
  1180. });
  1181. return lines + this.items.length;
  1182. }
  1183. return 0;
  1184. });
  1185.  
  1186. this.formatPersistenceString = (() => {
  1187. if (this.isValid()) {
  1188. let codes = [];
  1189. this.items.forEach((amulet) => {
  1190. codes.push(amulet.getCode());
  1191. });
  1192. return `${this.name}${AMULET_STORAGE_GROUPNAME_SEPARATOR}${codes.join(AMULET_STORAGE_AMULET_SEPARATOR)}`;
  1193. }
  1194. return '';
  1195. });
  1196.  
  1197. this.parse(persistenceString);
  1198. }
  1199.  
  1200. function AmuletGroupCollection(persistenceString) {
  1201. this.isAmuletGroupCollection = true;
  1202. this.items = {};
  1203. this.itemCount = 0;
  1204.  
  1205. this.count = (() => {
  1206. return this.itemCount;
  1207. });
  1208.  
  1209. this.contains = ((name) => {
  1210. return (this.items[name] != null);
  1211. });
  1212.  
  1213. this.add = ((item) => {
  1214. if (item?.isValid()) {
  1215. if (!this.contains(item.name)) {
  1216. this.itemCount++;
  1217. }
  1218. this.items[item.name] = item;
  1219. return true;
  1220. }
  1221. return false;
  1222. });
  1223.  
  1224. this.remove = ((name) => {
  1225. if (this.contains(name)) {
  1226. delete this.items[name];
  1227. this.itemCount--;
  1228. return true;
  1229. }
  1230. return false;
  1231. });
  1232.  
  1233. this.clear = (() => {
  1234. for (let name in this.items) {
  1235. delete this.items[name];
  1236. }
  1237. this.itemCount = 0;
  1238. });
  1239.  
  1240. this.get = ((name) => {
  1241. return this.items[name];
  1242. });
  1243.  
  1244. this.rename = ((oldName, newName) => {
  1245. if (amuletIsValidGroupName(newName)) {
  1246. let group = this.items[oldName];
  1247. if (this.remove(oldName)) {
  1248. group.name = newName;
  1249. return this.add(group);
  1250. }
  1251. }
  1252. return false;
  1253. });
  1254.  
  1255. this.toArray = (() => {
  1256. let groups = [];
  1257. for (let name in this.items) {
  1258. groups.push(this.items[name]);
  1259. }
  1260. return groups;
  1261. });
  1262.  
  1263. this.parse = ((persistenceString) => {
  1264. this.clear();
  1265. if (persistenceString?.length > 0) {
  1266. let groupStrings = persistenceString.split(AMULET_STORAGE_GROUP_SEPARATOR);
  1267. let gl = groupStrings.length;
  1268. for (let i = 0; i < gl; i++) {
  1269. if (!this.add(new AmuletGroup(groupStrings[i]))) {
  1270. this.clear();
  1271. break;
  1272. }
  1273. }
  1274. }
  1275. return (this.count() > 0);
  1276. });
  1277.  
  1278. this.formatPersistenceString = (() => {
  1279. let str = '';
  1280. let ns = '';
  1281. for (let name in this.items) {
  1282. str += (ns + this.items[name].formatPersistenceString());
  1283. ns = AMULET_STORAGE_GROUP_SEPARATOR;
  1284. }
  1285. return str;
  1286. });
  1287.  
  1288. this.parse(persistenceString);
  1289. }
  1290.  
  1291. // deprecated
  1292. // 2023-05-04: new amulet items added
  1293. function AmuletOld() {
  1294. this.id = -1;
  1295. this.type = -1;
  1296. this.level = 0;
  1297. this.enhancement = 0;
  1298. this.buffCode = 0;
  1299. this.text = null;
  1300.  
  1301. this.reset = (() => {
  1302. this.id = -1;
  1303. this.type = -1;
  1304. this.level = 0;
  1305. this.enhancement = 0;
  1306. this.buffCode = 0;
  1307. this.text = null;
  1308. });
  1309.  
  1310. this.isValid = (() => {
  1311. return (this.type >= 0 && this.type < g_amuletDefaultTypeNames.length && this.buffCode > 0);
  1312. });
  1313.  
  1314. this.fromCode = ((code) => {
  1315. if (!isNaN(code)) {
  1316. this.type = Math.trunc(code / AMULET_TYPE_ID_FACTOR) % 10;
  1317. this.level = Math.trunc(code / AMULET_LEVEL_ID_FACTOR) % 10;
  1318. this.enhancement = Math.trunc(code / AMULET_ENHANCEMENT_FACTOR) % 10;
  1319. this.buffCode = code % AMULET_BUFF_MAX_FACTOR;
  1320. }
  1321. else {
  1322. this.reset();
  1323. }
  1324. return (this.isValid() ? this : null);
  1325. });
  1326.  
  1327. this.fromBuffText = ((text) => {
  1328. if (text?.length > 0) {
  1329. let nb = text.split(' = ');
  1330. if (nb.length == 2) {
  1331. this.id = -1;
  1332. this.type = (g_amuletTypeIds[nb[0].slice(g_amuletTypeIds.start, g_amuletTypeIds.end)] ??
  1333. g_amuletDefaultTypeIds[nb[0].slice(g_amuletDefaultTypeIds.start, g_amuletDefaultTypeIds.end)]);
  1334. this.level = (g_amuletLevelIds[nb[0].slice(g_amuletLevelIds.start, g_amuletLevelIds.end)] ??
  1335. g_amuletDefaultLevelIds[nb[0].slice(g_amuletDefaultLevelIds.start, g_amuletDefaultLevelIds.end)]);
  1336. this.enhancement = parseInt(nb[0].match(/\d+/)[0]);
  1337. this.buffCode = 0;
  1338. nb[1].replaceAll(/(\+)|( 点)|( %)/g, '').split(',').forEach((buff) => {
  1339. let nv = buff.trim().split(' ');
  1340. this.buffCode += ((100 ** (g_amuletBuffMap.get(nv[0]).index % 6)) * parseInt(nv[1]));
  1341. });
  1342. if (this.isValid()) {
  1343. this.text = nb[1];
  1344. return this;
  1345. }
  1346. }
  1347. }
  1348. this.reset();
  1349. return null;
  1350. });
  1351.  
  1352. this.fromNode = ((node) => {
  1353. if (node?.nodeType == Node.ELEMENT_NODE) {
  1354. if (this.fromBuffText(node.getAttribute('amulate-string'))?.isValid() &&
  1355. !isNaN(this.id = parseInt(node.getAttribute('onclick').match(/\d+/)?.[0]))) {
  1356.  
  1357. return this;
  1358. }
  1359. else if (node.className?.indexOf('fyg_mp3') >= 0) {
  1360. let typeName = (node.getAttribute('data-original-title') ?? node.getAttribute('title'));
  1361. if (!/Lv.+?>\d+</.test(typeName)) {
  1362. let id = node.getAttribute('onclick');
  1363. let content = node.getAttribute('data-content');
  1364. if (id?.length > 0 && content?.length > 0 &&
  1365. !isNaN(this.type = (g_amuletTypeIds[typeName.slice(g_amuletTypeIds.start, g_amuletTypeIds.end)] ??
  1366. g_amuletDefaultTypeIds[typeName.slice(g_amuletDefaultTypeIds.start,
  1367. g_amuletDefaultTypeIds.end)])) &&
  1368. !isNaN(this.level = (g_amuletLevelIds[typeName.slice(g_amuletLevelIds.start, g_amuletLevelIds.end)] ??
  1369. g_amuletDefaultLevelIds[typeName.slice(g_amuletDefaultLevelIds.start,
  1370. g_amuletDefaultLevelIds.end)])) &&
  1371. !isNaN(this.id = parseInt(id.match(/\d+/)?.[0])) &&
  1372. !isNaN(this.enhancement = parseInt(node.innerText))) {
  1373.  
  1374. this.buffCode = 0;
  1375. this.text = '';
  1376. let attr = null;
  1377. let regex = /<p.*?>(.+?)<.*?>\+(\d+).*?<\/span><\/p>/g;
  1378. while ((attr = regex.exec(content))?.length == 3) {
  1379. let buffMeta = g_amuletBuffMap.get(attr[1]);
  1380. if (buffMeta != null) {
  1381. this.buffCode += ((100 ** (buffMeta.index % 6)) * attr[2]);
  1382. this.text += `${this.text.length > 0 ? ', ' : ''}${attr[1]} +${attr[2]} ${buffMeta.unit}`;
  1383. }
  1384. }
  1385. if (this.isValid()) {
  1386. node.setAttribute('amulate-string', this.formatBuffText());
  1387. return this;
  1388. }
  1389. }
  1390. }
  1391. }
  1392. }
  1393. this.reset();
  1394. return null;
  1395. });
  1396.  
  1397. this.fromAmulet = ((amulet) => {
  1398. if (amulet?.isValid()) {
  1399. this.id = amulet.id;
  1400. this.type = amulet.type;
  1401. this.level = amulet.level;
  1402. this.enhancement = amulet.enhancement;
  1403. this.buffCode = amulet.buffCode;
  1404. this.text = amulet.text;
  1405. }
  1406. else {
  1407. this.reset();
  1408. }
  1409. return (this.isValid() ? this : null);
  1410. });
  1411.  
  1412. this.getCode = (() => {
  1413. if (this.isValid()) {
  1414. return (this.type * AMULET_TYPE_ID_FACTOR +
  1415. this.level * AMULET_LEVEL_ID_FACTOR +
  1416. this.enhancement * AMULET_ENHANCEMENT_FACTOR +
  1417. this.buffCode);
  1418. }
  1419. return -1;
  1420. });
  1421.  
  1422. this.getBuff = (() => {
  1423. let buffs = {};
  1424. if (this.isValid()) {
  1425. let code = this.buffCode;
  1426. let type = this.type * 6;
  1427. g_amuletBuffs.slice(type, type + 6).forEach((buff) => {
  1428. let v = (code % 100);
  1429. if (v > 0) {
  1430. buffs[buff.name] = v;
  1431. }
  1432. code = Math.trunc(code / 100);
  1433. });
  1434. }
  1435. return buffs;
  1436. });
  1437.  
  1438. this.getTotalPoints = (() => {
  1439. let points = 0;
  1440. if (this.isValid()) {
  1441. let code = this.buffCode;
  1442. for(let i = 0; i < 6; i++) {
  1443. points += (code % 100);
  1444. code = Math.trunc(code / 100);
  1445. }
  1446. }
  1447. return points;
  1448. });
  1449.  
  1450. this.formatName = (() => {
  1451. if (this.isValid()) {
  1452. return `${g_amuletLevelNames[this.level]}${g_amuletTypeNames[this.type]} (+${this.enhancement})`;
  1453. }
  1454. return null;
  1455. });
  1456.  
  1457. this.formatBuff = (() => {
  1458. if (this.isValid()) {
  1459. if (this.text?.length > 0) {
  1460. return this.text;
  1461. }
  1462. this.text = '';
  1463. let buffs = this.getBuff();
  1464. for (let buff in buffs) {
  1465. this.text += `${this.text.length > 0 ? ', ' : ''}${buff} +${buffs[buff]} ${g_amuletBuffMap.get(buff).unit}`;
  1466. }
  1467. }
  1468. return this.text;
  1469. });
  1470.  
  1471. this.formatBuffText = (() => {
  1472. if (this.isValid()) {
  1473. return this.formatName() + ' = ' + this.formatBuff();
  1474. }
  1475. return null;
  1476. });
  1477.  
  1478. this.formatShortMark = (() => {
  1479. let text = this.formatBuff()?.replaceAll(/(\+)|( 点)|( %)/g, '');
  1480. if (text?.length > 0) {
  1481. for (let buff in this.getBuff()) {
  1482. text = text.replaceAll(buff, g_amuletBuffMap.get(buff).shortMark);
  1483. }
  1484. return this.formatName() + ' = ' + text;
  1485. }
  1486. return null;
  1487. });
  1488.  
  1489. this.compareMatch = ((other, ascType) => {
  1490. if (!this.isValid()) {
  1491. return 1;
  1492. }
  1493. else if (!other?.isValid()) {
  1494. return -1;
  1495. }
  1496.  
  1497. let delta = other.type - this.type;
  1498. if (delta != 0) {
  1499. return (ascType ? -delta : delta);
  1500. }
  1501. return (other.buffCode - this.buffCode);
  1502. });
  1503.  
  1504. this.compareTo = ((other, ascType) => {
  1505. if (!this.isValid()) {
  1506. return 1;
  1507. }
  1508. else if (!other?.isValid()) {
  1509. return -1;
  1510. }
  1511.  
  1512. let delta = other.type - this.type;
  1513. if (delta != 0) {
  1514. return (ascType ? -delta : delta);
  1515. }
  1516.  
  1517. let tbuffs = this.formatBuffText().split(' = ')[1].replaceAll(/(\+)|( 点)|( %)/g, '').split(', ');
  1518. let obuffs = other.formatBuffText().split(' = ')[1].replaceAll(/(\+)|( 点)|( %)/g, '').split(', ');
  1519. let bl = Math.min(tbuffs.length, obuffs.length);
  1520. for (let i = 0; i < bl; i++) {
  1521. let tbuff = tbuffs[i].split(' ');
  1522. let obuff = obuffs[i].split(' ');
  1523. if ((delta = g_amuletBuffMap.get(tbuff[0]).index - g_amuletBuffMap.get(obuff[0]).index) != 0 ||
  1524. (delta = parseInt(obuff[1]) - parseInt(tbuff[1])) != 0) {
  1525. return delta;
  1526. }
  1527. }
  1528. if ((delta = obuffs.length - tbuffs.length) != 0 ||
  1529. (delta = other.level - this.level) != 0 ||
  1530. (delta = other.enhancement - this.enhancement) != 0) {
  1531. return delta;
  1532. }
  1533.  
  1534. return 0;
  1535. });
  1536. }
  1537.  
  1538. function AmuletGroupOld(persistenceString) {
  1539. this.name = null;
  1540. this.items = [];
  1541. this.buffSummary = [];
  1542.  
  1543. this.isValid = (() => {
  1544. return (this.items.length > 0 && amuletIsValidGroupName(this.name));
  1545. });
  1546.  
  1547. this.count = (() => {
  1548. return this.items.length;
  1549. });
  1550.  
  1551. this.clear = (() => {
  1552. this.items = [];
  1553. this.buffSummary = [];
  1554. });
  1555.  
  1556. this.add = ((amulet) => {
  1557. if (amulet?.isValid()) {
  1558. let buffs = amulet.getBuff();
  1559. for (let buff in buffs) {
  1560. this.buffSummary[buff] = (this.buffSummary[buff] ?? 0) + buffs[buff];
  1561. }
  1562. return insertElement(this.items, amulet, (a, b) => a.compareTo(b, true));
  1563. }
  1564. return -1;
  1565. });
  1566.  
  1567. this.remove = ((amulet) => {
  1568. if (this.isValid() && amulet?.isValid()) {
  1569. let i = searchElement(this.items, amulet, (a, b) => a.compareTo(b, true));
  1570. if (i >= 0) {
  1571. let buffs = amulet.getBuff();
  1572. for (let buff in buffs) {
  1573. this.buffSummary[buff] = (this.buffSummary[buff] ?? 0) - buffs[buff];
  1574. if (this.buffSummary[buff] <= 0) {
  1575. delete this.buffSummary[buff];
  1576. }
  1577. }
  1578. this.items.splice(i, 1);
  1579. return true;
  1580. }
  1581. }
  1582. return false;
  1583. });
  1584.  
  1585. this.removeId = ((id) => {
  1586. if (this.isValid()) {
  1587. let i = this.items.findIndex((a) => a.id == id);
  1588. if (i >= 0) {
  1589. let amulet = this.items[i];
  1590. let buffs = amulet.getBuff();
  1591. for (let buff in buffs) {
  1592. this.buffSummary[buff] = (this.buffSummary[buff] ?? 0) - buffs[buff];
  1593. if (this.buffSummary[buff] <= 0) {
  1594. delete this.buffSummary[buff];
  1595. }
  1596. }
  1597. this.items.splice(i, 1);
  1598. return amulet;
  1599. }
  1600. }
  1601. return null;
  1602. });
  1603.  
  1604. this.merge = ((group) => {
  1605. group?.items?.forEach((am) => { this.add(am); });
  1606. return this;
  1607. });
  1608.  
  1609. this.validate = ((amulets) => {
  1610. if (this.isValid()) {
  1611. let mismatch = 0;
  1612. let al = this.items.length;
  1613. let i = 0;
  1614. if (amulets?.length > 0) {
  1615. amulets = amulets.slice().sort((a, b) => a.compareMatch(b));
  1616. for ( ; amulets.length > 0 && i < al; i++) {
  1617. let mi = searchElement(amulets, this.items[i], (a, b) => a.compareMatch(b));
  1618. if (mi >= 0) {
  1619. // remove a matched amulet from the amulet pool can avoid one single amulet matches all
  1620. // the equivalent objects in the group.
  1621. // let's say two (or even more) AGI +5 apples in one group is fairly normal, if we just
  1622. // have only one equivalent apple in the amulet pool and we don't remove it when the
  1623. // first match happens, then the 2nd apple will get matched later, the consequence would
  1624. // be we can never find the mismatch which should be encountered at the 2nd apple
  1625. this.items[i].fromAmulet(amulets[mi]);
  1626. amulets.splice(mi, 1);
  1627. }
  1628. else {
  1629. mismatch++;
  1630. }
  1631. }
  1632. }
  1633. if (i > mismatch) {
  1634. this.items.sort((a, b) => a.compareTo(b, true));
  1635. }
  1636. if (i < al) {
  1637. mismatch += (al - i);
  1638. }
  1639. return (mismatch == 0);
  1640. }
  1641. return false;
  1642. });
  1643.  
  1644. this.findIndices = ((amulets) => {
  1645. let indices = [];
  1646. let al;
  1647. if (this.isValid() && (al = amulets?.length) > 0) {
  1648. let items = this.items.slice().sort((a, b) => a.compareMatch(b));
  1649. for (let i = 0; items.length > 0 && i < al; i++) {
  1650. let mi;
  1651. if (amulets[i]?.id >= 0 && (mi = searchElement(items, amulets[i], (a, b) => a.compareMatch(b))) >= 0) {
  1652. // similar to the 'validate', remove the amulet from the search list when we found
  1653. // a match item in first time to avoid the duplicate founding, e.g. say we need only
  1654. // one AGI +5 apple in current group and we actually have 10 of AGI +5 apples in store,
  1655. // if we found the first matched itme in store and record it's index but not remove it
  1656. // from the temporary searching list, then we will continuously reach this kind of
  1657. // founding and recording until all those 10 AGI +5 apples are matched and processed,
  1658. // this obviously ain't the result what we expected
  1659. indices.push(i);
  1660. items.splice(mi, 1);
  1661. }
  1662. }
  1663. }
  1664. return indices;
  1665. });
  1666.  
  1667. this.parse = ((persistenceString) => {
  1668. this.clear();
  1669. if (persistenceString?.length > 0) {
  1670. let elements = persistenceString.split(AMULET_STORAGE_GROUPNAME_SEPARATOR);
  1671. if (elements.length == 2) {
  1672. let name = elements[0].trim();
  1673. if (amuletIsValidGroupName(name)) {
  1674. let items = elements[1].split(AMULET_STORAGE_AMULET_SEPARATOR);
  1675. let il = items.length;
  1676. for (let i = 0; i < il; i++) {
  1677. if (this.add((new AmuletOld()).fromCode(parseInt(items[i]))) < 0) {
  1678. this.clear();
  1679. break;
  1680. }
  1681. }
  1682. if (this.count() > 0) {
  1683. this.name = name;
  1684. }
  1685. }
  1686. }
  1687. }
  1688. return (this.count() > 0);
  1689. });
  1690.  
  1691. this.formatBuffSummary = ((linePrefix, lineSuffix, lineSeparator, ignoreMaxValue) => {
  1692. if (this.isValid()) {
  1693. let str = '';
  1694. let nl = '';
  1695. g_amuletBuffs.forEach((buff) => {
  1696. let v = this.buffSummary[buff.name];
  1697. if (v > 0) {
  1698. str += `${nl}${linePrefix}${buff.name} +${ignoreMaxValue ? v : Math.min(v, buff.maxValue)} ${buff.unit}${lineSuffix}`;
  1699. nl = lineSeparator;
  1700. }
  1701. });
  1702. return str;
  1703. }
  1704. return '';
  1705. });
  1706.  
  1707. this.formatBuffShortMark = ((keyValueSeparator, itemSeparator, ignoreMaxValue) => {
  1708. if (this.isValid()) {
  1709. let str = '';
  1710. let sp = '';
  1711. g_amuletBuffs.forEach((buff) => {
  1712. let v = this.buffSummary[buff.name];
  1713. if (v > 0) {
  1714. str += `${sp}${buff.shortMark}${keyValueSeparator}${ignoreMaxValue ? v : Math.min(v, buff.maxValue)}`;
  1715. sp = itemSeparator;
  1716. }
  1717. });
  1718. return str;
  1719. }
  1720. return '';
  1721. });
  1722.  
  1723. this.formatItems = ((linePrefix, erroeLinePrefix, lineSuffix, errorLineSuffix, lineSeparator) => {
  1724. if (this.isValid()) {
  1725. let str = '';
  1726. let nl = '';
  1727. this.items.forEach((amulet) => {
  1728. str += `${nl}${amulet.id < 0 ? erroeLinePrefix : linePrefix}${amulet.formatBuffText()}` +
  1729. `${amulet.id < 0 ? errorLineSuffix : lineSuffix}`;
  1730. nl = lineSeparator;
  1731. });
  1732. return str;
  1733. }
  1734. return '';
  1735. });
  1736.  
  1737. this.getDisplayStringLineCount = (() => {
  1738. if (this.isValid()) {
  1739. let lines = 0;
  1740. g_amuletBuffs.forEach((buff) => {
  1741. if (this.buffSummary[buff.name] > 0) {
  1742. lines++;
  1743. }
  1744. });
  1745. return lines + this.items.length;
  1746. }
  1747. return 0;
  1748. });
  1749.  
  1750. this.formatPersistenceString = (() => {
  1751. if (this.isValid()) {
  1752. let codes = [];
  1753. this.items.forEach((amulet) => {
  1754. codes.push(amulet.getCode());
  1755. });
  1756. return `${this.name}${AMULET_STORAGE_GROUPNAME_SEPARATOR}${codes.join(AMULET_STORAGE_AMULET_SEPARATOR)}`;
  1757. }
  1758. return '';
  1759. });
  1760.  
  1761. this.parse(persistenceString);
  1762. }
  1763.  
  1764. function AmuletGroupCollectionOld(persistenceString) {
  1765. this.items = {};
  1766. this.itemCount = 0;
  1767.  
  1768. this.count = (() => {
  1769. return this.itemCount;
  1770. });
  1771.  
  1772. this.contains = ((name) => {
  1773. return (this.items[name] != null);
  1774. });
  1775.  
  1776. this.add = ((item) => {
  1777. if (item?.isValid()) {
  1778. if (!this.contains(item.name)) {
  1779. this.itemCount++;
  1780. }
  1781. this.items[item.name] = item;
  1782. return true;
  1783. }
  1784. return false;
  1785. });
  1786.  
  1787. this.remove = ((name) => {
  1788. if (this.contains(name)) {
  1789. delete this.items[name];
  1790. this.itemCount--;
  1791. return true;
  1792. }
  1793. return false;
  1794. });
  1795.  
  1796. this.clear = (() => {
  1797. for (let name in this.items) {
  1798. delete this.items[name];
  1799. }
  1800. this.itemCount = 0;
  1801. });
  1802.  
  1803. this.get = ((name) => {
  1804. return this.items[name];
  1805. });
  1806.  
  1807. this.rename = ((oldName, newName) => {
  1808. if (amuletIsValidGroupName(newName)) {
  1809. let group = this.items[oldName];
  1810. if (this.remove(oldName)) {
  1811. group.name = newName;
  1812. return this.add(group);
  1813. }
  1814. }
  1815. return false;
  1816. });
  1817.  
  1818. this.toArray = (() => {
  1819. let groups = [];
  1820. for (let name in this.items) {
  1821. groups.push(this.items[name]);
  1822. }
  1823. return groups;
  1824. });
  1825.  
  1826. this.parse = ((persistenceString) => {
  1827. this.clear();
  1828. if (persistenceString?.length > 0) {
  1829. let groupStrings = persistenceString.split(AMULET_STORAGE_GROUP_SEPARATOR);
  1830. let gl = groupStrings.length;
  1831. for (let i = 0; i < gl; i++) {
  1832. if (!this.add(new AmuletGroupOld(groupStrings[i]))) {
  1833. this.clear();
  1834. break;
  1835. }
  1836. }
  1837. }
  1838. return (this.count() > 0);
  1839. });
  1840.  
  1841. this.formatPersistenceString = (() => {
  1842. let str = '';
  1843. let ns = '';
  1844. for (let name in this.items) {
  1845. str += (ns + this.items[name].formatPersistenceString());
  1846. ns = AMULET_STORAGE_GROUP_SEPARATOR;
  1847. }
  1848. return str;
  1849. });
  1850.  
  1851. this.parse(persistenceString);
  1852. }
  1853.  
  1854. function amuletGroupStorageConvert() {
  1855. if (localStorage.getItem(g_amuletGroupCollectionStorageKey) == null) {
  1856. console.log('Begin convert amulet groups ...');
  1857. let groups = (new AmuletGroupCollectionOld(localStorage.getItem(g_amuletGroupsStorageKey))).toArray();
  1858. if (groups?.length > 0) {
  1859. console.log(groups.length + ' amulet groups loaded');
  1860. let ngs = new AmuletGroupCollection();
  1861. groups.forEach((g, i) => {
  1862. console.log('amulet group #' + i + ' - ' + g.name + ' : ' + g.count() + ' amulets included');
  1863. let ng = new AmuletGroup();
  1864. ng.name = g.name;
  1865. g.items.forEach((a, j) => {
  1866. let na = (new Amulet()).fromBuffText(a.formatBuffText());
  1867. if (ng.add(na) < 0) {
  1868. console.log('amulet group #' + i + ' - ' + ng.name + ' : add amulet #' + j + ' failed');
  1869. console.log(na);
  1870. }
  1871. });
  1872. console.log('amulet group #' + i + ' - ' + ng.name + ' : ' + ng.count() + ' amulets converted');
  1873. if (!ngs.add(ng)) {
  1874. console.log('amulet group #' + i + ' - ' + ng.name + ' : add group failed');
  1875. }
  1876. });
  1877. console.log(ngs.count() + ' amulet groups converted');
  1878. amuletSaveGroups(ngs);
  1879. }
  1880. }
  1881. }
  1882. amuletGroupStorageConvert();
  1883. // deprecated
  1884.  
  1885. function amuletIsValidGroupName(groupName) {
  1886. return (groupName?.length > 0 && groupName.length < 32 && groupName.search(USER_STORAGE_RESERVED_SEPARATORS) < 0);
  1887. }
  1888.  
  1889. function amuletSaveGroups(groups) {
  1890. if (groups?.count() > 0) {
  1891. localStorage.setItem(g_amuletGroupCollectionStorageKey, groups.formatPersistenceString());
  1892. }
  1893. else {
  1894. localStorage.removeItem(g_amuletGroupCollectionStorageKey);
  1895. }
  1896. }
  1897.  
  1898. function amuletLoadGroups() {
  1899. return new AmuletGroupCollection(localStorage.getItem(g_amuletGroupCollectionStorageKey));
  1900. }
  1901.  
  1902. function amuletClearGroups() {
  1903. localStorage.removeItem(g_amuletGroupCollectionStorageKey);
  1904. }
  1905.  
  1906. function amuletSaveGroup(group) {
  1907. if (group?.isValid()) {
  1908. let groups = amuletLoadGroups();
  1909. if (groups.add(group)) {
  1910. amuletSaveGroups(groups);
  1911. }
  1912. }
  1913. }
  1914.  
  1915. function amuletLoadGroup(groupName) {
  1916. return amuletLoadGroups().get(groupName);
  1917. }
  1918.  
  1919. function amuletDeleteGroup(groupName) {
  1920. let groups = amuletLoadGroups();
  1921. if (groups.remove(groupName)) {
  1922. amuletSaveGroups(groups);
  1923. }
  1924. }
  1925.  
  1926. function amuletCreateGroupFromArray(groupName, amulets) {
  1927. if (amulets?.length > 0 && amuletIsValidGroupName(groupName)) {
  1928. let group = new AmuletGroup(null);
  1929. for (let amulet of amulets) {
  1930. if (group.add(amulet) < 0) {
  1931. group.clear();
  1932. break;
  1933. }
  1934. }
  1935. if (group.count() > 0) {
  1936. group.name = groupName;
  1937. return group;
  1938. }
  1939. }
  1940. return null;
  1941. }
  1942.  
  1943. function amuletNodesToArray(nodes, array, key) {
  1944. array ??= [];
  1945. let amulet;
  1946. for (let node of nodes) {
  1947. if (objectMatchTitle(node, key) && (amulet ??= new Amulet()).fromNode(node)?.isValid()) {
  1948. array.push(amulet);
  1949. amulet = null;
  1950. }
  1951. }
  1952. return array;
  1953. }
  1954.  
  1955. function beginReadAmulets(bagAmulets, storeAmulets, key, fnPostProcess, fnParams) {
  1956. function parseAmulets() {
  1957. if (bagAmulets != null) {
  1958. amuletNodesToArray(bag, bagAmulets, key);
  1959. }
  1960. if (storeAmulets != null) {
  1961. amuletNodesToArray(store, storeAmulets, key);
  1962. }
  1963. if (fnPostProcess != null) {
  1964. fnPostProcess(fnParams);
  1965. }
  1966. }
  1967.  
  1968. let bag = (bagAmulets != null ? [] : null);
  1969. let store = (storeAmulets != null ? [] : null);
  1970. if (bag != null || store != null) {
  1971. beginReadObjects(bag, store, parseAmulets, null);
  1972. }
  1973. else if (fnPostProcess != null) {
  1974. fnPostProcess(fnParams);
  1975. }
  1976. }
  1977.  
  1978. function beginLoadAmuletGroupsDiff(groupNames, fnProgress, fnPostProcess, fnParams) {
  1979. let bag, store, loading;
  1980. if (groupNames?.length > 0) {
  1981. loading = [];
  1982. groupNames.forEach((gn) => {
  1983. let g = amuletLoadGroup(gn);
  1984. if (g?.isValid()) {
  1985. loading = loading.concat(g.items);
  1986. }
  1987. });
  1988.  
  1989. if (loading.length > 0) {
  1990. if (fnProgress != null) {
  1991. fnProgress(4, 1, loading.length);
  1992. }
  1993. beginReadAmulets(bag = [], store = [], null, beginUnload);
  1994. return;
  1995. }
  1996. }
  1997. if (fnPostProcess != null) {
  1998. fnPostProcess(fnParams);
  1999. }
  2000.  
  2001. function beginUnload() {
  2002. let ids = [];
  2003. if (bag.length > 0) {
  2004. let indices = findNewObjects(bag, loading.sort((a, b) => a.compareMatch(b)), true, true,
  2005. (a, b) => a.compareMatch(b)).sort((a, b) => b - a);
  2006. while (indices?.length > 0) {
  2007. ids.push(bag[indices.pop()].id);
  2008. }
  2009. }
  2010. if (fnProgress != null) {
  2011. fnProgress(4, 2, ids.length);
  2012. }
  2013. beginMoveObjects(ids, ObjectMovePath.bag2store, beginLoad, ids.length);
  2014. }
  2015.  
  2016. function beginLoad(unloadedCount) {
  2017. if (loading.length > 0 && store.length > 0) {
  2018. if (unloadedCount == 0) {
  2019. let indices = amuletCreateGroupFromArray('_', loading)?.findIndices(store)?.sort((a, b) => b - a);
  2020. let ids = [];
  2021. while (indices?.length > 0) {
  2022. ids.push(store[indices.pop()].id);
  2023. }
  2024. if (fnProgress != null) {
  2025. fnProgress(4, 4, ids.length);
  2026. }
  2027. beginMoveObjects(ids, ObjectMovePath.store2bag, fnPostProcess, fnParams);
  2028. }
  2029. else {
  2030. if (fnProgress != null) {
  2031. fnProgress(4, 3, loading.length);
  2032. }
  2033. beginReadAmulets(null, store = [], null, beginLoad, 0);
  2034. }
  2035. }
  2036. else if (fnPostProcess != null) {
  2037. fnPostProcess(fnParams);
  2038. }
  2039. }
  2040. }
  2041.  
  2042. function beginMoveAmulets({ groupName, amulets, path, proc, params }) {
  2043. let indices = amuletLoadGroup(groupName)?.findIndices(amulets)?.sort((a, b) => b - a);
  2044. let ids = [];
  2045. while (indices?.length > 0) {
  2046. ids.push(amulets[indices.pop()].id);
  2047. }
  2048. beginMoveObjects(ids, path, proc, params);
  2049. }
  2050.  
  2051. function beginLoadAmuletGroupFromStore(amulets, groupName, fnPostProcess, fnParams) {
  2052. if (amulets?.length > 0) {
  2053. let store = amuletNodesToArray(amulets);
  2054. beginMoveAmulets({ groupName : groupName, amulets : store, path : ObjectMovePath.store2bag,
  2055. proc : fnPostProcess, params : fnParams });
  2056. }
  2057. else {
  2058. beginReadAmulets(null, amulets = [], null, beginMoveAmulets,
  2059. { groupName : groupName, amulets : amulets, path : ObjectMovePath.store2bag,
  2060. proc : fnPostProcess, params : fnParams });
  2061. }
  2062. }
  2063.  
  2064. function beginUnloadAmuletGroupFromBag(amulets, groupName, fnPostProcess, fnParams) {
  2065. if (amulets?.length > 0) {
  2066. let bag = amuletNodesToArray(amulets);
  2067. beginMoveAmulets({ groupName : groupName, amulets : bag, path : ObjectMovePath.bag2store,
  2068. proc : fnPostProcess, params : fnParams });
  2069. }
  2070. else {
  2071. beginReadAmulets(amulets, null, null, beginMoveAmulets,
  2072. { groupName : groupName, amulets : amulets, path : ObjectMovePath.bag2store,
  2073. proc : fnPostProcess, params : fnParams });
  2074. }
  2075. }
  2076.  
  2077. ////////////////////////////////////////////////////////////////////////////////////////////////////
  2078. //
  2079. // property utilities
  2080. //
  2081. ////////////////////////////////////////////////////////////////////////////////////////////////////
  2082.  
  2083. const g_equipmentDefaultLevelName = [ '普通', '幸运', '稀有', '史诗', '传奇' ];
  2084. const g_equipmentLevelStyleClass = [ 'primary', 'info', 'success', 'warning', 'danger' ];
  2085. const g_equipmentLevelPoints = [ 200, 321, 419, 516, 585 ];
  2086. const g_equipmentLevelBGColor = [ '#e0e8e8', '#c0e0ff', '#c0ffc0', '#ffffc0', '#ffd0d0' ];
  2087. function propertyInfoParseNode(node) {
  2088. function formatPropertyString(p) {
  2089. return `${p.metaIndex},${p.level},${p.amount}`;
  2090. }
  2091.  
  2092. function parsePropertyString(s) {
  2093. let a = s.split(',');
  2094. console.log(s);
  2095. return {
  2096. isProperty : true,
  2097. metaIndex : parseInt(a[0]),
  2098. level : parseInt(a[1]),
  2099. amount : parseInt(a[2])
  2100. };
  2101. }
  2102.  
  2103. if (node?.nodeType == Node.ELEMENT_NODE) {
  2104. let s = node.getAttribute('property-string');
  2105. if (s?.length > 0) {
  2106. return parsePropertyString(s);
  2107. }
  2108. else if (node.className?.split(' ').length >= 2 && node.className.indexOf('fyg_mp3') >= 0) {
  2109. let title = (node.getAttribute('data-original-title') ?? node.getAttribute('title'))?.split(' ');
  2110. let meta = g_propertyMap.get(title?.[0]?.trim());
  2111. if (meta != null) {
  2112. let text = node.getAttribute('data-content');
  2113. let lv = node.getAttribute('data-tip-class');
  2114. if (text?.length > 0 && lv?.length > 0) {
  2115. if (meta.discription == null) {
  2116. meta.discription = text;
  2117. }
  2118. let p = {
  2119. isProperty : true,
  2120. metaIndex : meta.index,
  2121. level : g_equipmentLevelStyleClass.indexOf(lv.substring(lv.indexOf('-') + 1)),
  2122. amount : parseInt(title?.[1]?.match(/\d+/)?.[0] ?? 0)
  2123. };
  2124. node.setAttribute('property-string', formatPropertyString(p));
  2125. return p;
  2126. }
  2127. }
  2128. }
  2129. }
  2130. return null;
  2131. }
  2132.  
  2133. function propertyNodesToInfoArray(nodes, array, key) {
  2134. array ??= [];
  2135. let e;
  2136. for (let i = nodes?.length - 1; i >= 0; i--) {
  2137. if (objectMatchTitle(nodes[i], key) && (e = propertyInfoParseNode(nodes[i])) != null) {
  2138. array.unshift(e);
  2139. }
  2140. }
  2141. return array;
  2142. }
  2143.  
  2144. function propertyInfoComparer(p1, p2) {
  2145. return p1.metaIndex - p2.metaIndex;
  2146. }
  2147.  
  2148. function beginReadProperties(properties, key, fnPostProcess, fnParams) {
  2149. if (properties != null) {
  2150. let store = [];
  2151. beginReadObjects(
  2152. null,
  2153. store,
  2154. () => {
  2155. propertyNodesToInfoArray(store, properties, key);
  2156.  
  2157. if (fnPostProcess != null) {
  2158. fnPostProcess(fnParams);
  2159. }
  2160. },
  2161. store);
  2162. }
  2163. else if (fnPostProcess != null) {
  2164. fnPostProcess(fnParams);
  2165. }
  2166. }
  2167.  
  2168. ////////////////////////////////////////////////////////////////////////////////////////////////////
  2169. //
  2170. // equipment utilities
  2171. //
  2172. ////////////////////////////////////////////////////////////////////////////////////////////////////
  2173.  
  2174. var g_equipmentLevelName = g_equipmentDefaultLevelName;
  2175. function equipmentInfoParseNode(node, ignoreIllegalAttributes) {
  2176. if (node?.nodeType == Node.ELEMENT_NODE) {
  2177. let eq = node.getAttribute('equip-string')?.split(',');
  2178. if (eq?.length >= 8 && g_equipMap.has(eq[0])) {
  2179. return eq;
  2180. }
  2181. else if (node.className?.split(' ').length >= 2 && node.className.indexOf('fyg_mp3') >= 0) {
  2182. let attrTitle = node.hasAttribute('data-original-title') ? 'data-original-title' : 'title';
  2183. let title = node.getAttribute(attrTitle);
  2184. let eqInfo = title?.match(/Lv.+?>\s*(\d+)\s*<.+?\/i>\s*(\d+)\s*<.+?<br>(.+)/);
  2185. if (eqInfo?.length == 4) {
  2186. let name = eqInfo[3].trim();
  2187. let meta = (g_equipMap.get(name) ?? g_equipMap.get(name.substring(g_equipmentLevelName[0].length)));
  2188. if(meta==undefined){
  2189. let tempEqName,tempEqNameC;
  2190. let tempEqType=node.innerHTML;
  2191. if(tempEqType.indexOf('z21')>-1){tempEqType=1;tempEqName='NEWEQA';tempEqNameC='待更新的未知新武器'}
  2192. else if(tempEqType.indexOf('z22')>-1){tempEqType=2;tempEqName='NEWEQB';;tempEqNameC='待更新的未知新手饰'}
  2193. else if(tempEqType.indexOf('z23')>-1){tempEqType=3;tempEqName='NEWEQC';;tempEqNameC='待更新的未知新防具'}
  2194. else if(tempEqType.indexOf('z24')>-1){tempEqType=4;tempEqName='NEWEQD';;tempEqNameC='待更新的未知新耳饰'};
  2195. meta={
  2196. "index": tempEqType-1,
  2197. "name": tempEqNameC,
  2198. "type": tempEqType,
  2199. "attributes": [
  2200. {
  2201. "attribute": {
  2202. "index": 33,
  2203. "type": 0,
  2204. "name": "未知属性"
  2205. },
  2206. "factor": 0,
  2207. "additive": 42
  2208. },
  2209. {
  2210. "attribute": {
  2211. "index": 33,
  2212. "type": 0,
  2213. "name": "未知属性"
  2214. },
  2215. "factor": 0,
  2216. "additive": 42
  2217. },
  2218. {
  2219. "attribute": {
  2220. "index": 15,
  2221. "type": 0,
  2222. "name": "未知属性"
  2223. },
  2224. "factor": 0,
  2225. "additive": 42
  2226. },
  2227. {
  2228. "attribute": {
  2229. "index": 33,
  2230. "type": 0,
  2231. "name": "未知属性"
  2232. },
  2233. "factor": 0,
  2234. "additive": 42
  2235. }
  2236. ],
  2237. "shortMark": tempEqName,
  2238. "alias": tempEqNameC
  2239. };
  2240. };
  2241. name = meta?.shortMark;
  2242. if (name?.length > 0) {
  2243. let attr = node.getAttribute('data-content')?.match(/>\s*\d+\s?%\s*</g);
  2244. let lv = eqInfo[1];
  2245. let lvEx = eqInfo[2];
  2246. if ((ignoreIllegalAttributes || attr?.length > 0) && lv?.length > 0 && lvEx?.length > 0) {
  2247. let e = [ name, lv, meta.type < 2 ? lvEx : '0', meta.type < 2 ? '0' : lvEx,
  2248. (attr?.[0]?.match(/\d+/)?.[0] ?? '0'),
  2249. (attr?.[1]?.match(/\d+/)?.[0] ?? '0'),
  2250. (attr?.[2]?.match(/\d+/)?.[0] ?? '0'),
  2251. (attr?.[3]?.match(/\d+/)?.[0] ?? '0'),
  2252. (/\[神秘属性\]/.test(node.getAttribute('data-content')) ? '1' : '0'),
  2253. (node.getAttribute('onclick')?.match(/\d+/)?.[0] ?? '-1') ];
  2254. node.setAttribute(attrTitle, title.replace(/(Lv.+?>\s*\d+\s*)(<)/,
  2255. `$1<span style="font-size:15px;">(${equipmentQuality(e)}%)</span>$2`));
  2256. node.setAttribute('equip-string', e.join(','));
  2257. return e;
  2258. }
  2259. }
  2260. }
  2261. }
  2262. }
  2263. return null;
  2264. }
  2265.  
  2266. function equipmentQuality(e) {
  2267. let eq = (Array.isArray(e) ? e : equipmentInfoParseNode(e, true));
  2268. if (eq?.length >= 9) {
  2269. return parseInt(eq[4]) + parseInt(eq[5]) + parseInt(eq[6]) + parseInt(eq[7]) + (parseInt(eq[8]) * 100);
  2270. }
  2271. return -1;
  2272. }
  2273.  
  2274. function equipmentNodesToInfoArray(nodes, array, ignoreIllegalAttributes) {
  2275. array ??= [];
  2276. for (let i = nodes?.length - 1; i >= 0; i--) {
  2277. let e = equipmentInfoParseNode(nodes[i], ignoreIllegalAttributes);
  2278. if (e != null) {
  2279. array.unshift(e);
  2280. }
  2281. }
  2282. return array;
  2283. }
  2284.  
  2285. function equipmentInfoComparer(e1, e2) {
  2286. let delta = g_equipMap.get(e1[0]).index - g_equipMap.get(e2[0]).index;
  2287. for (let i = 1; i < 9 && delta == 0; delta = parseInt(e1[i]) - parseInt(e2[i++]));
  2288. return delta;
  2289. }
  2290.  
  2291. ////////////////////////////////////////////////////////////////////////////////////////////////////
  2292. //
  2293. // object utilities
  2294. //
  2295. ////////////////////////////////////////////////////////////////////////////////////////////////////
  2296.  
  2297. function objectGetLevel(e) {
  2298. let eq = equipmentQuality(e);
  2299. if (eq >= 0) {
  2300. for (var i = g_equipmentLevelPoints.length - 1; i > 0 && eq < g_equipmentLevelPoints[i]; i--);
  2301. return i;
  2302. }
  2303. else if((eq = e.isProperty ? e : propertyInfoParseNode(e))?.isProperty){
  2304. return eq.level;
  2305. }
  2306. else if ((eq = (e.isAmulet ? e : (new Amulet()).fromNode(e)))?.isValid()) {
  2307. return (eq.level + 2)
  2308. }
  2309. try {
  2310. let theme = JSON.parse(sessionStorage.getItem('ThemePack') ?? '{}');
  2311. if (theme?.url != null) {
  2312. amuletLoadTheme(theme);
  2313. propertyLoadTheme(theme);
  2314. equipLoadTheme(theme);
  2315. }
  2316. }
  2317. catch (ex) {
  2318. console.log('THEME:');
  2319. console.log(ex);
  2320. }
  2321. return -1;
  2322. }
  2323.  
  2324. function objectNodeComparer(e1, e2) {
  2325. let eq1 = equipmentInfoParseNode(e1, true);
  2326. let eq2 = equipmentInfoParseNode(e2, true);
  2327.  
  2328. if (eq1 == null && eq2 == null) {
  2329. return ((new Amulet()).fromNode(e1)?.compareTo((new Amulet()).fromNode(e2)) ?? 1);
  2330. }
  2331. else if (eq1 == null) {
  2332. return 1;
  2333. }
  2334. else if (eq2 == null) {
  2335. return -1;
  2336. }
  2337. return equipmentInfoComparer(eq1, eq2);
  2338. }
  2339.  
  2340. function objectIsEmptyNode(node) {
  2341. return (/空/.test(node?.innerText) || !(node?.getAttribute('data-content')?.length > 0));
  2342. }
  2343.  
  2344. ////////////////////////////////////////////////////////////////////////////////////////////////////
  2345. //
  2346. // bag & store utilities
  2347. //
  2348. ////////////////////////////////////////////////////////////////////////////////////////////////////
  2349.  
  2350. function findAmuletIds(container, amulets, ids, maxCount) {
  2351. ids ??= [];
  2352. let cl = container?.length;
  2353. if (cl > 0 && amulets?.length > 0) {
  2354. maxCount ??= cl;
  2355. let ams = amuletNodesToArray(container);
  2356. for (let i = ams.length - 1; i >= 0 && amulets.length > 0 && ids.length < maxCount; i--) {
  2357. for (let j = amulets.length - 1; j >= 0; j--) {
  2358. if (ams[i].compareTo(amulets[j]) == 0) {
  2359. amulets.splice(j, 1);
  2360. ids.unshift(ams[i].id);
  2361. break;
  2362. }
  2363. }
  2364. }
  2365. }
  2366. return ids;
  2367. }
  2368.  
  2369. function findEquipmentIds(container, equips, ids, maxCount) {
  2370. ids ??= [];
  2371. let cl = container?.length;
  2372. if (cl > 0 && equips?.length > 0) {
  2373. maxCount ??= cl;
  2374. let eqs = equipmentNodesToInfoArray(container);
  2375. for (let i = eqs.length - 1; i >= 0 && equips.length > 0 && ids.length < maxCount; i--) {
  2376. for (let j = equips.length - 1; j >= 0; j--) {
  2377. if (equipmentInfoComparer(eqs[i], equips[j]) == 0) {
  2378. equips.splice(j, 1);
  2379. ids.unshift(parseInt(eqs[i][9]));
  2380. break;
  2381. }
  2382. }
  2383. }
  2384. }
  2385. return ids;
  2386. }
  2387.  
  2388. function beginClearBag(bag, key, fnPostProcess, fnParams) {
  2389. function beginClearBagObjects(objects) {
  2390. beginMoveObjects(objects, ObjectMovePath.bag2store, fnPostProcess, fnParams);
  2391. }
  2392.  
  2393. let objects = [];
  2394. if (bag?.length > 0) {
  2395. objectIdParseNodes(bag, objects, key, true);
  2396. beginClearBagObjects(objects);
  2397. }
  2398. else {
  2399. beginReadObjectIds(objects, null, key, true, beginClearBagObjects, objects);
  2400. }
  2401. }
  2402.  
  2403. ////////////////////////////////////////////////////////////////////////////////////////////////////
  2404. //
  2405. // generic popups
  2406. //
  2407. ////////////////////////////////////////////////////////////////////////////////////////////////////
  2408.  
  2409. const g_genericPopupContainerId = 'generic-popup-container';
  2410. const g_genericPopupClass = 'generic-popup';
  2411. const g_genericPopupId = g_genericPopupClass;
  2412. const g_genericPopupWindowClass = 'generic-popup-window';
  2413. const g_genericPopupContentContainerId = 'generic-popup-content-container';
  2414. const g_genericPopupContentClass = 'generic-popup-content';
  2415. const g_genericPopupContentId = g_genericPopupContentClass;
  2416. const g_genericPopupFixedContentId = 'generic-popup-content-fixed';
  2417. const g_genericPopupInformationTipsId = 'generic-popup-information-tips';
  2418. const g_genericPopupProgressClass = g_genericPopupClass;
  2419. const g_genericPopupProgressId = 'generic-popup-progress';
  2420. const g_genericPopupProgressContentClass = 'generic-popup-content-progress';
  2421. const g_genericPopupProgressContentId = g_genericPopupProgressContentClass;
  2422. const g_genericPopupTopLineDivClass = 'generic-popup-top-line-container';
  2423. const g_genericPopupTitleTextClass = 'generic-popup-title-text';
  2424. const g_genericPopupTitleTextId = g_genericPopupTitleTextClass;
  2425. const g_genericPopupTitleButtonContainerId = 'generic-popup-title-button-container';
  2426. const g_genericPopupFootButtonContainerId = 'generic-popup-foot-button-container';
  2427. const g_genericPopupBackgroundColor = '#ebf2f9';
  2428. const g_genericPopupBackgroundColorAlt = '#dbe2e9';
  2429. const g_genericPopupBorderColor = '#3280fc';
  2430. const g_genericPopupTitleTextColor = '#ffffff';
  2431.  
  2432. const g_genericPopupStyle =
  2433. `<style>
  2434. .${g_genericPopupClass} {
  2435. width: 100vw;
  2436. height: 100vh;
  2437. background-color: rgba(0, 0, 0, 0.4);
  2438. position: fixed;
  2439. left: 0;
  2440. top: 0;
  2441. bottom: 0;
  2442. right: 0;
  2443. z-index: 99;
  2444. display: none;
  2445. justify-content: center;
  2446. align-items: center;
  2447. }
  2448. .${g_genericPopupWindowClass} {
  2449. border: 2px solid ${g_genericPopupBorderColor};
  2450. border-radius: 5px;
  2451. box-shadow: 4px 4px 16px 8px rgba(0, 0, 0, 0.4);
  2452. }
  2453. .${g_genericPopupContentClass} {
  2454. width: 100%;
  2455. background-color: ${g_genericPopupBackgroundColor};
  2456. box-sizing: border-box;
  2457. padding: 0px 30px;
  2458. color: black;
  2459. }
  2460. .${g_genericPopupProgressContentClass} {
  2461. width: 400px;
  2462. height: 200px;
  2463. background-color: ${g_genericPopupBackgroundColor};
  2464. box-sizing: border-box;
  2465. box-shadow: 4px 4px 16px 8px rgba(0, 0, 0, 0.4);
  2466. border: 2px solid ${g_genericPopupBorderColor};
  2467. border-radius: 5px;
  2468. display: table;
  2469. }
  2470. #${g_genericPopupProgressContentId} {
  2471. height: 100%;
  2472. width: 100%;
  2473. color: #0000c0;
  2474. font-size: 24px;
  2475. font-weight: bold;
  2476. display: table-cell;
  2477. text-align: center;
  2478. vertical-align: middle;
  2479. }
  2480. .${g_genericPopupTopLineDivClass} {
  2481. width: 100%;
  2482. padding: 20px 0px;
  2483. border-top: 2px groove #d0d0d0;
  2484. }
  2485. .generic-popup-title-foot-container {
  2486. width: 100%;
  2487. height: 40px;
  2488. background-color: ${g_genericPopupBorderColor};
  2489. padding: 0px 30px;
  2490. display: table;
  2491. }
  2492. .${g_genericPopupTitleTextClass} {
  2493. height: 100%;
  2494. color: ${g_genericPopupTitleTextColor};
  2495. font-size: 18px;
  2496. display: table-cell;
  2497. text-align: left;
  2498. vertical-align: middle;
  2499. }
  2500. </style>`;
  2501.  
  2502. const g_genericPopupHTML =
  2503. `${g_genericPopupStyle}
  2504. <div class="${g_genericPopupClass}" id="${g_genericPopupId}">
  2505. <div class="${g_genericPopupWindowClass}">
  2506. <div class="generic-popup-title-foot-container">
  2507. <span class="${g_genericPopupTitleTextClass}" id="${g_genericPopupTitleTextId}"></span>
  2508. <div id="${g_genericPopupTitleButtonContainerId}" style="float:right;margin-top:6px;"></div>
  2509. </div>
  2510. <div id="${g_genericPopupContentContainerId}">
  2511. <div class="${g_genericPopupContentClass}" id="${g_genericPopupFixedContentId}" style="display:none;"></div>
  2512. <div class="${g_genericPopupContentClass}" id="${g_genericPopupContentId}"></div>
  2513. </div>
  2514. <div class="generic-popup-title-foot-container">
  2515. <div id="${g_genericPopupFootButtonContainerId}" style="float:right;margin-top:8px;"></div>
  2516. </div>
  2517. </div>
  2518. </div>
  2519. <div class="${g_genericPopupProgressClass}" id="${g_genericPopupProgressId}">
  2520. <div class="${g_genericPopupProgressContentClass}"><span id="${g_genericPopupProgressContentId}"></span></div>
  2521. </div>`;
  2522.  
  2523. var g_genericPopupContainer = null;
  2524. function genericPopupInitialize() {
  2525. if (g_genericPopupContainer == null && (g_genericPopupContainer = document.getElementById(g_genericPopupContainerId)) == null) {
  2526. g_genericPopupContainer = document.createElement('div');
  2527. g_genericPopupContainer.id = g_genericPopupContainerId;
  2528. document.body.appendChild(g_genericPopupContainer);
  2529. }
  2530. g_genericPopupContainer.innerHTML = g_genericPopupHTML;
  2531. }
  2532.  
  2533. function genericPopupReset(initialize) {
  2534. if (initialize) {
  2535. g_genericPopupContainer.innerHTML = g_genericPopupHTML;
  2536. }
  2537. else {
  2538. let fixedContent = g_genericPopupContainer.querySelector('#' + g_genericPopupFixedContentId);
  2539. fixedContent.style.display = 'none';
  2540. fixedContent.innerHTML = '';
  2541.  
  2542. g_genericPopupContainer.querySelector('#' + g_genericPopupTitleTextId).innerText = '';
  2543. g_genericPopupContainer.querySelector('#' + g_genericPopupContentId).innerHTML = '';
  2544. g_genericPopupContainer.querySelector('#' + g_genericPopupTitleButtonContainerId).innerHTML = '';
  2545. g_genericPopupContainer.querySelector('#' + g_genericPopupFootButtonContainerId).innerHTML = '';
  2546. }
  2547. }
  2548.  
  2549. function genericPopupSetContent(title, content) {
  2550. g_genericPopupContainer.querySelector('#' + g_genericPopupTitleTextId).innerText = title;
  2551. g_genericPopupContainer.querySelector('#' + g_genericPopupContentId).innerHTML = content;
  2552. }
  2553.  
  2554. function genericPopupSetFixedContent(content) {
  2555. let fixedContent = g_genericPopupContainer.querySelector('#' + g_genericPopupFixedContentId);
  2556. fixedContent.style.display = 'block';
  2557. fixedContent.innerHTML = content;
  2558. }
  2559.  
  2560. function genericPopupAddButton(text, width, clickProc, addToTitle) {
  2561. let btn = document.createElement('button');
  2562. btn.innerText = text;
  2563. btn.onclick = clickProc;
  2564. if (width != null && width > 0) {
  2565. width = width.toString();
  2566. btn.style.width = width + (width.endsWith('px') || width.endsWith('%') ? '' : 'px');
  2567. }
  2568. else {
  2569. btn.style.width = 'auto';
  2570. }
  2571.  
  2572. g_genericPopupContainer.querySelector('#' + (addToTitle
  2573. ? g_genericPopupTitleButtonContainerId
  2574. : g_genericPopupFootButtonContainerId)).appendChild(btn);
  2575. return btn;
  2576. }
  2577.  
  2578. function genericPopupAddCloseButton(width, text, addToTitle) {
  2579. return genericPopupAddButton(text?.length > 0 ? text : '关闭', width, (() => { genericPopupClose(true); }), addToTitle);
  2580. }
  2581.  
  2582. function genericPopupSetContentSize(height, width, scrollable) {
  2583. height = (height?.toString() ?? '100%');
  2584. width = (width?.toString() ?? '100%');
  2585.  
  2586. g_genericPopupContainer.querySelector('#' + g_genericPopupContentContainerId).style.width
  2587. = width + (width.endsWith('px') || width.endsWith('%') ? '' : 'px');
  2588.  
  2589. let content = g_genericPopupContainer.querySelector('#' + g_genericPopupContentId);
  2590. content.style.height = height + (height.endsWith('px') || height.endsWith('%') ? '' : 'px');
  2591. content.style.overflow = (scrollable ? 'auto' : 'hidden');
  2592. }
  2593.  
  2594. function genericPopupShowModal(clickOutsideToClose) {
  2595. genericPopupClose(false);
  2596.  
  2597. let popup = g_genericPopupContainer.querySelector('#' + g_genericPopupId);
  2598.  
  2599. if (clickOutsideToClose) {
  2600. popup.onclick = ((event) => {
  2601. if (event.target == popup) {
  2602. genericPopupClose(true);
  2603. }
  2604. });
  2605. }
  2606. else {
  2607. popup.onclick = null;
  2608. }
  2609.  
  2610. popup.style.display = "flex";
  2611. }
  2612.  
  2613. function genericPopupClose(reset, initialize) {
  2614. genericPopupCloseProgressMessage();
  2615.  
  2616. let popup = g_genericPopupContainer.querySelector('#' + g_genericPopupId);
  2617. popup.style.display = "none";
  2618.  
  2619. if (reset) {
  2620. genericPopupReset(initialize);
  2621. }
  2622.  
  2623. httpRequestClearAll();
  2624. }
  2625.  
  2626. function genericPopupOnClickOutside(fnProcess, fnParams) {
  2627. let popup = g_genericPopupContainer.querySelector('#' + g_genericPopupId);
  2628.  
  2629. if (fnProcess != null) {
  2630. popup.onclick = ((event) => {
  2631. if (event.target == popup) {
  2632. fnProcess(fnParams);
  2633. }
  2634. });
  2635. }
  2636. else {
  2637. popup.onclick = null;
  2638. }
  2639. }
  2640.  
  2641. function genericPopupQuerySelector(selectString) {
  2642. return g_genericPopupContainer.querySelector(selectString);
  2643. }
  2644.  
  2645. function genericPopupQuerySelectorAll(selectString) {
  2646. return g_genericPopupContainer.querySelectorAll(selectString);
  2647. }
  2648.  
  2649. let g_genericPopupInformationTipsTimer = null;
  2650. function genericPopupShowInformationTips(msg, time) {
  2651. if (g_genericPopupInformationTipsTimer != null) {
  2652. clearTimeout(g_genericPopupInformationTipsTimer);
  2653. g_genericPopupInformationTipsTimer = null;
  2654. }
  2655. let msgContainer = g_genericPopupContainer.querySelector('#' + g_genericPopupInformationTipsId);
  2656. if (msgContainer != null) {
  2657. msgContainer.innerText = (msg?.length > 0 ? `[ ${msg} ]` : '');
  2658. if ((time = parseInt(time)) > 0) {
  2659. g_genericPopupInformationTipsTimer = setTimeout(() => {
  2660. g_genericPopupInformationTipsTimer = null;
  2661. msgContainer.innerText = '';
  2662. }, time);
  2663. }
  2664. }
  2665. }
  2666.  
  2667. function genericPopupShowProgressMessage(progressMessage) {
  2668. genericPopupClose(false);
  2669.  
  2670. g_genericPopupContainer.querySelector('#' + g_genericPopupProgressContentId).innerText
  2671. = (progressMessage?.length > 0 ? progressMessage : '请稍候...');
  2672. g_genericPopupContainer.querySelector('#' + g_genericPopupProgressId).style.display = "flex";
  2673. }
  2674.  
  2675. function genericPopupUpdateProgressMessage(progressMessage) {
  2676. g_genericPopupContainer.querySelector('#' + g_genericPopupProgressContentId).innerText
  2677. = (progressMessage?.length > 0 ? progressMessage : '请稍候...');
  2678. }
  2679.  
  2680. function genericPopupCloseProgressMessage() {
  2681. g_genericPopupContainer.querySelector('#' + g_genericPopupProgressId).style.display = "none";
  2682. }
  2683.  
  2684. //
  2685. // generic task-list based progress popup
  2686. //
  2687. const g_genericPopupTaskListId = 'generic-popup-task-list';
  2688. const g_genericPopupTaskItemId = 'generic-popup-task-item-';
  2689. const g_genericPopupTaskWaiting = '×';
  2690. const g_genericPopupTaskCompleted = '√';
  2691. const g_genericPopupTaskCompletedWithError = '!';
  2692. const g_genericPopupColorTaskIncompleted = '#c00000';
  2693. const g_genericPopupColorTaskCompleted = '#0000c0';
  2694. const g_genericPopupColorTaskCompletedWithError = 'red';
  2695.  
  2696. var g_genericPopupIncompletedTaskCount = 0;
  2697. function genericPopupTaskListPopupSetup(title, popupWidth, tasks, fnCancelRoutine, cancelButtonText, cancelButtonWidth) {
  2698. g_genericPopupIncompletedTaskCount = tasks.length;
  2699.  
  2700. genericPopupSetContent(title, `<div style="padding:15px 0px 15px 0px;"><ul id="${g_genericPopupTaskListId}"></ul></div>`);
  2701. let indicatorList = g_genericPopupContainer.querySelector('#' + g_genericPopupTaskListId);
  2702. for (let i = 0; i < g_genericPopupIncompletedTaskCount; i++) {
  2703. let li = document.createElement('li');
  2704. li.id = g_genericPopupTaskItemId + i;
  2705. li.style.color = g_genericPopupColorTaskIncompleted;
  2706. li.innerHTML = `<span>${g_genericPopupTaskWaiting}</span><span>&nbsp;${tasks[i]}&nbsp;</span><span></span>`;
  2707. indicatorList.appendChild(li);
  2708. }
  2709.  
  2710. if (fnCancelRoutine != null) {
  2711. genericPopupAddButton(cancelButtonText?.length > 0 ? cancelButtonText : '取消', cancelButtonWidth, fnCancelRoutine, false);
  2712. }
  2713.  
  2714. genericPopupSetContentSize(Math.min(g_genericPopupIncompletedTaskCount * 20 + 30, window.innerHeight - 400), popupWidth, true);
  2715. }
  2716.  
  2717. function genericPopupTaskSetState(index, state) {
  2718. let item = g_genericPopupContainer.querySelector('#' + g_genericPopupTaskItemId + index)?.lastChild;
  2719. if (item != null) {
  2720. item.innerText = (state ?? '');
  2721. }
  2722. }
  2723.  
  2724. function genericPopupTaskComplete(index, error) {
  2725. let li = g_genericPopupContainer.querySelector('#' + g_genericPopupTaskItemId + index);
  2726. if (li?.firstChild?.innerText == g_genericPopupTaskWaiting) {
  2727. li.firstChild.innerText = (error ? g_genericPopupTaskCompletedWithError : g_genericPopupTaskCompleted);
  2728. li.style.color = (error ? g_genericPopupColorTaskCompletedWithError : g_genericPopupColorTaskCompleted);
  2729. g_genericPopupIncompletedTaskCount--;
  2730. }
  2731. }
  2732.  
  2733. function genericPopupTaskCheckCompletion() {
  2734. return (g_genericPopupIncompletedTaskCount == 0);
  2735. }
  2736.  
  2737. ////////////////////////////////////////////////////////////////////////////////////////////////////
  2738. //
  2739. // switch solution
  2740. //
  2741. ////////////////////////////////////////////////////////////////////////////////////////////////////
  2742.  
  2743. const BINDING_SEPARATOR = ';';
  2744. const BINDING_NAME_SEPARATOR = '=';
  2745. const BINDING_ELEMENT_SEPARATOR = '|';
  2746.  
  2747. const g_switchSolutionRequests = {};
  2748. async function switchBindingSolution(bindingString, fnPostProcess, fnParams) {
  2749. if ((g_switchSolutionRequests.card ??= await getRequestInfoAsync('upcard', GuGuZhenRequest.equip)) != null) {
  2750. g_switchSolutionRequests.halo ??= await getRequestInfoAsync('halosave', GuGuZhenRequest.equip);
  2751. g_switchSolutionRequests.equip ??= await getRequestInfoAsync('puton', GuGuZhenRequest.equip);
  2752. }
  2753. if (g_switchSolutionRequests.card == null ||
  2754. g_switchSolutionRequests.halo == null ||
  2755. g_switchSolutionRequests.equip == null) {
  2756.  
  2757. console.log('missing function:', g_switchSolutionRequests);
  2758. alert('无法获取服务请求格式,可能的原因是咕咕镇版本不匹配或正在测试。');
  2759. window.location.reload();
  2760. return;
  2761. }
  2762.  
  2763. let binding = bindingString?.split(BINDING_NAME_SEPARATOR);
  2764. let roleId = g_roleMap.get(binding?.[0]?.trim())?.id;
  2765. let bindInfo = binding?.[1]?.split(BINDING_ELEMENT_SEPARATOR)
  2766. if (roleId == null || bindInfo?.length != 6) {
  2767. console.log('missins format:', bindingString);
  2768. alert('无效的绑定信息,无法执行切换。');
  2769. window.location.reload();
  2770. return;
  2771. }
  2772.  
  2773. let bindingEquipments = bindInfo.slice(0, 4);
  2774. let bindingHalos = bindInfo[4].split(',');
  2775. let amuletGroups = bindInfo[5].split(',');
  2776.  
  2777. function roleSetupCompletion() {
  2778. httpRequestClearAll();
  2779. genericPopupClose(true, true);
  2780.  
  2781. if (fnPostProcess != null) {
  2782. fnPostProcess(fnParams);
  2783. }
  2784. }
  2785.  
  2786. function checkForRoleSetupCompletion() {
  2787. if (genericPopupTaskCheckCompletion()) {
  2788. // delay for the final state can be seen
  2789. genericPopupTaskSetState(0);
  2790. genericPopupTaskSetState(1);
  2791. genericPopupTaskSetState(2);
  2792. genericPopupTaskSetState(3);
  2793. setTimeout(roleSetupCompletion, 200);
  2794. }
  2795. }
  2796.  
  2797. function amuletLoadCompletion() {
  2798. genericPopupTaskComplete(3);
  2799. checkForRoleSetupCompletion();
  2800. }
  2801.  
  2802. let switchMethod = g_configMap.get('solutionSwitchMethod')?.value;
  2803. function beginAmuletLoadGroups() {
  2804. if (amuletGroups?.length > 0) {
  2805. if (switchMethod == 0) {
  2806. genericPopupTaskSetState(3, `- 加载护符...(${amuletGroups?.length})`);
  2807. beginLoadAmuletGroupFromStore(null, amuletGroups.shift(), beginAmuletLoadGroups, null);
  2808. }
  2809. else {
  2810. genericPopupTaskSetState(3, `- 加载护符...`);
  2811. beginLoadAmuletGroupsDiff(amuletGroups, amuletLoadProgress, amuletLoadCompletion, null);
  2812. }
  2813. }
  2814. else {
  2815. amuletLoadCompletion();
  2816. }
  2817.  
  2818. function amuletLoadProgress(total, current, amuletCount) {
  2819. genericPopupTaskSetState(3, `- 加载护符...(${amuletCount} - ${Math.trunc(current * 100 / total)}%)`);
  2820. }
  2821. }
  2822.  
  2823. function beginLoadAmulets() {
  2824. genericPopupTaskSetState(2);
  2825. genericPopupTaskComplete(2, equipmentOperationError > 0);
  2826.  
  2827. if (amuletGroups?.length > 0) {
  2828. if (switchMethod == 0) {
  2829. genericPopupTaskSetState(3, '- 清理饰品...');
  2830. beginClearBag(null, null, beginAmuletLoadGroups, null);
  2831. }
  2832. else {
  2833. beginAmuletLoadGroups();
  2834. }
  2835. }
  2836. else {
  2837. amuletLoadCompletion();
  2838. }
  2839. }
  2840.  
  2841. let equipmentOperationError = 0;
  2842. let putonRequestsCount;
  2843. function putonEquipments(objects, fnPostProcess, fnParams) {
  2844. if (objects?.length > 0) {
  2845. let ids = [];
  2846. while (ids.length < g_maxConcurrentRequests && objects.length > 0) {
  2847. ids.push(objects.pop());
  2848. }
  2849. if ((putonRequestsCount = ids.length) > 0) {
  2850. while (ids.length > 0) {
  2851. httpRequestBegin(
  2852. g_switchSolutionRequests.equip.request,
  2853. g_switchSolutionRequests.equip.data.replace('"+id+"', ids.shift()),
  2854. (response) => {
  2855. if (response.responseText.indexOf('已装备') < 0) {
  2856. equipmentOperationError++;
  2857. console.log(response.responseText);
  2858. }
  2859. if (--putonRequestsCount == 0) {
  2860. putonEquipments(objects, fnPostProcess, fnParams);
  2861. }
  2862. });
  2863. }
  2864. return;
  2865. }
  2866. }
  2867. if (fnPostProcess != null) {
  2868. fnPostProcess(fnParams);
  2869. }
  2870. }
  2871.  
  2872. let currentEquipments = null;
  2873. function beginPutonEquipments() {
  2874. genericPopupTaskSetState(2, '- 检查装备...');
  2875. let equipsToPuton = [];
  2876. for (let i = 0; i < 4; i++) {
  2877. let equipInfo = bindingEquipments[i].split(',');
  2878. equipInfo.push(-1);
  2879. if (equipmentInfoComparer(equipInfo, currentEquipments[i]) != 0) {
  2880. equipsToPuton.push(equipInfo);
  2881. }
  2882. }
  2883. if (equipsToPuton.length == 0) {
  2884. beginLoadAmulets();
  2885. }
  2886. else {
  2887. let store = [];
  2888. beginReadObjects(null, store, scheduleEquipments, null);
  2889.  
  2890. function scheduleEquipments() {
  2891. let eqIds = findEquipmentIds(store, equipsToPuton);
  2892. if (equipsToPuton.length == 0) {
  2893. genericPopupTaskSetState(2, `- 穿戴装备...(${eqIds.length})`);
  2894. putonEquipments(eqIds, beginLoadAmulets, null);
  2895. }
  2896. else {
  2897. console.log(equipsToPuton);
  2898. alert('有装备不存在,请重新检查绑定!');
  2899.  
  2900. httpRequestAbortAll();
  2901. roleSetupCompletion();
  2902. }
  2903. }
  2904. }
  2905. }
  2906.  
  2907. function beginSetupHalo() {
  2908. if (bindingHalos?.length > 0) {
  2909. let halo = [];
  2910. bindingHalos.forEach((h) => {
  2911. let hid = g_haloMap.get(h.trim())?.id;
  2912. if (hid > 0) {
  2913. halo.push(hid);
  2914. }
  2915. });
  2916. if ((halo = halo.join(','))?.length > 0) {
  2917. genericPopupTaskSetState(1, '- 设置光环...');
  2918. httpRequestBegin(
  2919. g_switchSolutionRequests.halo.request,
  2920. g_switchSolutionRequests.halo.data.replace('"+savearr+"', halo),
  2921. (response) => {
  2922. genericPopupTaskSetState(1);
  2923. genericPopupTaskComplete(1, response.responseText != 'ok');
  2924. checkForRoleSetupCompletion();
  2925. });
  2926. return;
  2927. }
  2928. }
  2929. genericPopupTaskComplete(1);
  2930. checkForRoleSetupCompletion();
  2931. }
  2932.  
  2933. function beginRoleSetup() {
  2934. beginSetupHalo();
  2935. beginPutonEquipments();
  2936. }
  2937.  
  2938. function beginSwitch(roleInfo) {
  2939. function cancelSwitching() {
  2940. httpRequestAbortAll();
  2941. roleSetupCompletion();
  2942. }
  2943.  
  2944. if (!(roleInfo?.length > 0)) {
  2945. alert('获取当前角色信息失败,无法执行切换。');
  2946. window.location.reload();
  2947. return;
  2948. }
  2949.  
  2950. currentEquipments = equipmentNodesToInfoArray(roleInfo[2]);
  2951.  
  2952. genericPopupInitialize();
  2953. genericPopupTaskListPopupSetup('切换中...', 300, [ '卡片', '光环', '装备', '饰品' ], cancelSwitching);
  2954. genericPopupShowModal(false);
  2955.  
  2956. if (roleId == roleInfo[0]) {
  2957. genericPopupTaskComplete(0);
  2958. beginRoleSetup();
  2959. }
  2960. else {
  2961. genericPopupTaskSetState(0, '- 装备中...');
  2962. httpRequestBegin(
  2963. g_switchSolutionRequests.card.request,
  2964. g_switchSolutionRequests.card.data.replace('"+id+"', roleId),
  2965. (response) => {
  2966. genericPopupTaskSetState(0);
  2967. if (response.responseText == 'ok' || response.responseText == '你没有这张卡片或已经装备中') {
  2968. genericPopupTaskComplete(0);
  2969. beginRoleSetup();
  2970. }
  2971. else {
  2972. genericPopupTaskComplete(0, true);
  2973. alert('卡片装备失败!');
  2974. cancelSwitching();
  2975. }
  2976. });
  2977. }
  2978. }
  2979.  
  2980. let roleInfo = [];
  2981. beginReadRoleInfo(roleInfo, beginSwitch, roleInfo);
  2982. }
  2983.  
  2984. ////////////////////////////////////////////////////////////////////////////////////////////////////
  2985. //
  2986. // constants
  2987. //
  2988. ////////////////////////////////////////////////////////////////////////////////////////////////////
  2989.  
  2990. const g_roles = [
  2991. { index : -1 , id : 3000 , name : '舞' , hasG : true , shortMark : 'WU' },
  2992. { index : -1 , id : 3001 , name : '默' , hasG : false , shortMark : 'MO' },
  2993. { index : -1 , id : 3002 , name : '琳' , hasG : false , shortMark : 'LIN' },
  2994. { index : -1 , id : 3003 , name : '艾' , hasG : false , shortMark : 'AI' },
  2995. { index : -1 , id : 3004 , name : '梦' , hasG : false , shortMark : 'MENG' },
  2996. { index : -1 , id : 3005 , name : '薇' , hasG : false , shortMark : 'WEI' },
  2997. { index : -1 , id : 3006 , name : '伊' , hasG : false , shortMark : 'YI' },
  2998. { index : -1 , id : 3007 , name : '冥' , hasG : false , shortMark : 'MING' },
  2999. { index : -1 , id : 3008 , name : '命' , hasG : false , shortMark : 'MIN' },
  3000. { index : -1 , id : 3009 , name : '希' , hasG : true , shortMark : 'XI' },
  3001. { index : -1 , id : 3010 , name : '霞' , hasG : true , shortMark : 'XIA' },
  3002. { index : -1 , id : 3011 , name : '雅' , hasG : true , shortMark : 'YA' }
  3003. ];
  3004.  
  3005. const g_roleMap = new Map();
  3006. g_roles.forEach((item, index) => {
  3007. item.index = index;
  3008. g_roleMap.set(item.id, item);
  3009. g_roleMap.set(item.id.toString(), item);
  3010. g_roleMap.set(item.name, item);
  3011. g_roleMap.set(item.shortMark, item);
  3012. });
  3013.  
  3014. const g_properties = [
  3015. { index : -1 , id : 3001 , name : '体能刺激药水' },
  3016. { index : -1 , id : 3002 , name : '锻造材料箱' },
  3017. { index : -1 , id : 3003 , name : '灵魂药水' },
  3018. { index : -1 , id : 3004 , name : '随机装备箱' },
  3019. { index : -1 , id : 3005 , name : '宝石原石' },
  3020. { index : -1 , id : 3301 , name : '蓝锻造石' },
  3021. { index : -1 , id : 3302 , name : '绿锻造石' },
  3022. { index : -1 , id : 3303 , name : '金锻造石' },
  3023. { index : -1 , id : 3309 , name : '苹果核' },
  3024. { index : -1 , id : 3310 , name : '光环天赋石' }
  3025. ];
  3026.  
  3027. const g_propertyMap = new Map();
  3028. g_properties.forEach((item, index) => {
  3029. item.index = index;
  3030. item.alias = item.name;
  3031. g_propertyMap.set(item.id, item);
  3032. g_propertyMap.set(item.id.toString(), item);
  3033. g_propertyMap.set(item.name, item);
  3034. });
  3035.  
  3036. function propertyLoadTheme(theme) {
  3037. if (theme.itemsname?.length > 0) {
  3038. theme.itemsname.forEach((item, index) => {
  3039. if (!g_propertyMap.has(item) && index < g_properties.length) {
  3040. g_properties[index].alias = item;
  3041. g_propertyMap.set(item, g_properties[index]);
  3042. }
  3043. });
  3044. }
  3045. }
  3046.  
  3047. const g_gemWorks = [
  3048. {
  3049. index : -1,
  3050. name : '赶海',
  3051. nameRegex : { line : 1 , regex : /^\d+贝壳$/ },
  3052. progressRegex : { line : 1 , regex : /(\d+)/ },
  3053. completionProgress : 1000000,
  3054. unitRegex : { line : 4 , regex : /(\d+)/ },
  3055. unitSymbol : '贝壳'
  3056. },
  3057. {
  3058. index : -1,
  3059. name : '随机装备箱',
  3060. nameRegex : { line : 1 , regex : /^随机装备箱$/ },
  3061. progressRegex : { line : 0 , regex : /(\d+\.?\d*)%?/ },
  3062. completionProgress : 100,
  3063. unitRegex : { line : 4 , regex : /(\d+\.?\d*)%?/ },
  3064. unitSymbol : '%'
  3065. },
  3066. {
  3067. index : -1,
  3068. name : '灵魂药水',
  3069. nameRegex : { line : 1 , regex : /^灵魂药水$/ },
  3070. progressRegex : { line : 0 , regex : /(\d+\.?\d*)%?/ },
  3071. completionProgress : 100,
  3072. unitRegex : { line : 4 , regex : /(\d+\.?\d*)%?/ },
  3073. unitSymbol : '%'
  3074. },
  3075. {
  3076. index : -1,
  3077. name : '宝石原石',
  3078. nameRegex : { line : 1 , regex : /^宝石原石/ },
  3079. progressRegex : { line : 0 , regex : /(\d+\.?\d*)%?/ },
  3080. completionProgress : 100,
  3081. unitRegex : { line : 4 , regex : /(\d+\.?\d*)%?/ },
  3082. unitSymbol : '%'
  3083. },
  3084. {
  3085. index : -1,
  3086. name : '星沙',
  3087. nameRegex : { line : 1 , regex : /^\d+星沙\(\d+\.?\d*\)/ },
  3088. progressRegex : { line : 1 , regex : /\((\d+\.?\d*)\)/ },
  3089. completionProgress : 10,
  3090. precision : 0,
  3091. unitRegex : { line : 4 , regex : /(\d+\.?\d*)/ },
  3092. unitSymbol : ''
  3093. },
  3094. {
  3095. index : -1,
  3096. name : '幻影经验',
  3097. nameRegex : { line : 1 , regex : /^\d+幻影经验$/ },
  3098. progressRegex : { line : 1 , regex : /(\d+)/ },
  3099. completionProgress : 200,
  3100. precision : 0,
  3101. unitRegex : { line : 4 , regex : /(\d+\.?\d*)/ },
  3102. unitSymbol : ''
  3103. }
  3104. ];
  3105.  
  3106. const g_gemMinWorktimeMinute = 8 * 60;
  3107. const g_gemPollPeriodMinute = { min : 1 , max : 8 * 60 , default : 60 };
  3108. const g_gemFailurePollPeriodSecond = 30;
  3109. const g_gemWorkMap = new Map();
  3110. g_gemWorks.forEach((item, index) => {
  3111. item.index = index;
  3112. item.alias = item.name;
  3113. g_gemWorkMap.set(item.name, item);
  3114. });
  3115.  
  3116. function readGemWorkCompletionCondition() {
  3117. let cond = g_configMap.get('gemWorkCompletionCondition');
  3118. let conds = cond.value.split(',');
  3119. let len = Math.min(conds.length, g_gemWorks.length);
  3120. let error = 0;
  3121. for (let i = len - 1; i >= 0; i--) {
  3122. if ((conds[i] = conds[i].trim()).length > 0) {
  3123. let comp = conds[i].match(new RegExp(`^${g_gemWorks[i].unitRegex.regex.source}$`))?.[1];
  3124. if (!isNaN(comp = Number.parseFloat(comp))) {
  3125. g_gemWorks[i].completionProgress = comp;
  3126. }
  3127. else {
  3128. error++;
  3129. }
  3130. }
  3131. }
  3132. return error;
  3133. }
  3134.  
  3135. const g_equipAttributes = [
  3136. { index : 0 , type : 0 , name : '物理攻击' },
  3137. { index : 1 , type : 0 , name : '魔法攻击' },
  3138. { index : 2 , type : 0 , name : '攻击速度' },
  3139. { index : 3 , type : 0 , name : '最大生命' },
  3140. { index : 4 , type : 0 , name : '最大护盾' },
  3141. { index : 5 , type : 1 , name : '附加物伤' },
  3142. { index : 6 , type : 1 , name : '附加魔伤' },
  3143. { index : 7 , type : 1 , name : '附加攻速' },
  3144. { index : 8 , type : 1 , name : '附加生命' },
  3145. { index : 9 , type : 1 , name : '附加护盾' },
  3146. { index : 10 , type : 1 , name : '附加回血' },
  3147. { index : 11 , type : 1 , name : '附加回盾' },
  3148. { index : 12 , type : 0 , name : '护盾回复' },
  3149. { index : 13 , type : 0 , name : '物理穿透' },
  3150. { index : 14 , type : 0 , name : '魔法穿透' },
  3151. { index : 15 , type : 0 , name : '暴击穿透' },
  3152. { index : 16 , type : 1 , name : '附加物穿' },
  3153. { index : 17 , type : 1 , name : '附加物防' },
  3154. { index : 18 , type : 1 , name : '附加魔防' },
  3155. { index : 19 , type : 1 , name : '物理减伤' },
  3156. { index : 20 , type : 1 , name : '魔法减伤' },
  3157. { index : 21 , type : 0 , name : '生命偷取' },
  3158. { index : 22 , type : 0 , name : '伤害反弹' },
  3159. { index : 23 , type : 1 , name : '附加魔穿' },
  3160. { index : 24 , type : 1 , name : '技能概率' },
  3161. { index : 25 , type : 1 , name : '暴击概率' },
  3162. { index : 26 , type : 1 , name : '力量生命' },
  3163. { index : 27 , type : 1 , name : '体魄生命' },
  3164. { index : 28 , type : 1 , name : '意志生命' },
  3165. { index : 29 , type : 1 , name : '体魄物减' },
  3166. { index : 30 , type : 1 , name : '意志魔减' },
  3167. { index : 31 , type : 1 , name : '敏捷绝伤' },
  3168. { index : 32 , type : 1 , name : '敏捷生命' },
  3169. { index : 33 , type : 0 , name : '未知属性' }
  3170. ];
  3171.  
  3172. const g_equipments = [
  3173. {
  3174. index : -1,
  3175. name : '待更新的未知新武器',
  3176. type : 0,
  3177. attributes : [ { attribute : g_equipAttributes[33] , factor : 1 , additive : 0 },
  3178. { attribute : g_equipAttributes[33] , factor : 1 , additive : 0 },
  3179. { attribute : g_equipAttributes[33] , factor : 1 , additive : 0 },
  3180. { attribute : g_equipAttributes[33] , factor : 1 , additive : 0 } ],
  3181. shortMark : 'NEWEQA'
  3182. },
  3183. {
  3184. index : -1,
  3185. name : '待更新的未知新手饰',
  3186. type : 1,
  3187. attributes : [ { attribute : g_equipAttributes[33] , factor : 1 , additive : 0 },
  3188. { attribute : g_equipAttributes[33] , factor : 1 , additive : 0 },
  3189. { attribute : g_equipAttributes[33] , factor : 1 , additive : 0 },
  3190. { attribute : g_equipAttributes[33] , factor : 1 , additive : 0 } ],
  3191. shortMark : 'NEWEQB'
  3192. },
  3193. {
  3194. index : -1,
  3195. name : '待更新的未知新防具',
  3196. type : 2,
  3197. attributes : [ { attribute : g_equipAttributes[33] , factor : 1 , additive : 0 },
  3198. { attribute : g_equipAttributes[33] , factor : 1 , additive : 0 },
  3199. { attribute : g_equipAttributes[33] , factor : 1 , additive : 0 },
  3200. { attribute : g_equipAttributes[33] , factor : 1 , additive : 0 } ],
  3201. shortMark : 'NEWEQC'
  3202. },
  3203. {
  3204. index : -1,
  3205. name : '待更新的未知新耳饰',
  3206. type : 3,
  3207. attributes : [ { attribute : g_equipAttributes[33] , factor : 1 , additive : 0 },
  3208. { attribute : g_equipAttributes[33] , factor : 1 , additive : 0 },
  3209. { attribute : g_equipAttributes[33] , factor : 1 , additive : 0 },
  3210. { attribute : g_equipAttributes[33] , factor : 1 , additive : 0 } ],
  3211. shortMark : 'NEWEQD'
  3212. },
  3213. {
  3214. index : -1,
  3215. name : '反叛者的刺杀弓',
  3216. type : 0,
  3217. attributes : [ { attribute : g_equipAttributes[0] , factor : 1 / 5 , additive : 30 },
  3218. { attribute : g_equipAttributes[15] , factor : 1 / 20 , additive : 10 },
  3219. { attribute : g_equipAttributes[13] , factor : 1 / 20 , additive : 10 },
  3220. { attribute : g_equipAttributes[16] , factor : 1 , additive : 0 } ],
  3221. shortMark : 'ASSBOW'
  3222. },
  3223. {
  3224. index : -1,
  3225. name : '狂信者的荣誉之刃',
  3226. type : 0,
  3227. attributes : [ { attribute : g_equipAttributes[0] , factor : 1 / 5 , additive : 20 },
  3228. { attribute : g_equipAttributes[2] , factor : 1 / 5 , additive : 20 },
  3229. { attribute : g_equipAttributes[15] , factor : 1 / 20 , additive : 10 },
  3230. { attribute : g_equipAttributes[13] , factor : 1 / 20 , additive : 10 } ],
  3231. shortMark : 'BLADE'
  3232. },
  3233. {
  3234. index : -1,
  3235. name : '陨铁重剑',
  3236. type : 0,
  3237. attributes : [ { attribute : g_equipAttributes[5] , factor : 20 , additive : 0 },
  3238. { attribute : g_equipAttributes[5] , factor : 20 , additive : 0 },
  3239. { attribute : g_equipAttributes[0] , factor : 1 / 5 , additive : 30 },
  3240. { attribute : g_equipAttributes[15] , factor : 1 / 20 , additive : 1 } ],
  3241. merge : [ [ 0, 1 ], [ 2 ], [ 3 ] ],
  3242. shortMark : 'CLAYMORE'
  3243. },
  3244. {
  3245. index : -1,
  3246. name : '幽梦匕首',
  3247. type : 0,
  3248. attributes : [ { attribute : g_equipAttributes[0] , factor : 1 / 5 , additive : 0 },
  3249. { attribute : g_equipAttributes[1] , factor : 1 / 5 , additive : 0 },
  3250. { attribute : g_equipAttributes[7] , factor : 4 , additive : 0 },
  3251. { attribute : g_equipAttributes[2] , factor : 1 / 5 , additive : 25 } ],
  3252. shortMark : 'DAGGER'
  3253. },
  3254. {
  3255. index : -1,
  3256. name : '荆棘盾剑',
  3257. type : 0,
  3258. attributes : [ { attribute : g_equipAttributes[21] , factor : 1 / 15 , additive : 10 },
  3259. { attribute : g_equipAttributes[22] , factor : 1 / 15 , additive : 0 },
  3260. { attribute : g_equipAttributes[17] , factor : 1 , additive : 0 },
  3261. { attribute : g_equipAttributes[18] , factor : 1 , additive : 0 } ],
  3262. shortMark : 'SHIELD'
  3263. },
  3264. {
  3265. index : -1,
  3266. name : '饮血魔剑',
  3267. type : 0,
  3268. attributes : [ { attribute : g_equipAttributes[0] , factor : 1 / 5 , additive : 50 },
  3269. { attribute : g_equipAttributes[13] , factor : 1 / 20 , additive : 10 },
  3270. { attribute : g_equipAttributes[23] , factor : 2 , additive : 0 },
  3271. { attribute : g_equipAttributes[21] , factor : 1 / 15, additive : 10 } ],
  3272. shortMark : 'SPEAR'
  3273. },
  3274. {
  3275. index : -1,
  3276. name : '彩金长剑',
  3277. type : 0,
  3278. attributes : [ { attribute : g_equipAttributes[0] , factor : 1 / 5 , additive : 10 },
  3279. { attribute : g_equipAttributes[1] , factor : 1 / 5 , additive : 10 },
  3280. { attribute : g_equipAttributes[2] , factor : 1 / 5 , additive : 20 },
  3281. { attribute : g_equipAttributes[31] , factor : 1 / 20 , additive : 0 } ],
  3282. shortMark : 'COLORFUL'
  3283. },
  3284. {
  3285. index : -1,
  3286. name : '光辉法杖',
  3287. type : 0,
  3288. attributes : [ { attribute : g_equipAttributes[1] , factor : 1 / 5 , additive : 0 },
  3289. { attribute : g_equipAttributes[1] , factor : 1 / 5 , additive : 0 },
  3290. { attribute : g_equipAttributes[1] , factor : 1 / 5 , additive : 0 },
  3291. { attribute : g_equipAttributes[14] , factor : 1 / 20 , additive : 0 } ],
  3292. merge : [ [ 0, 1, 2 ], [ 3 ] ],
  3293. shortMark : 'WAND'
  3294. },
  3295. {
  3296. index : -1,
  3297. name : '探险者短弓',
  3298. type : 0,
  3299. attributes : [ { attribute : g_equipAttributes[5] , factor : 10 , additive : 0 },
  3300. { attribute : g_equipAttributes[6] , factor : 10 , additive : 0 },
  3301. { attribute : g_equipAttributes[7] , factor : 2 , additive : 0 },
  3302. { attribute : g_equipAttributes[21] , factor : 1 / 15 , additive : 10 } ],
  3303. shortMark : 'BOW'
  3304. },
  3305. {
  3306. index : -1,
  3307. name : '探险者短杖',
  3308. type : 0,
  3309. attributes : [ { attribute : g_equipAttributes[5] , factor : 10 , additive : 0 },
  3310. { attribute : g_equipAttributes[6] , factor : 10 , additive : 0 },
  3311. { attribute : g_equipAttributes[14] , factor : 1 / 20 , additive : 5 },
  3312. { attribute : g_equipAttributes[21] , factor : 1 / 15 , additive : 10 } ],
  3313. shortMark : 'STAFF'
  3314. },
  3315. {
  3316. index : -1,
  3317. name : '探险者之剑',
  3318. type : 0,
  3319. attributes : [ { attribute : g_equipAttributes[5] , factor : 10 , additive : 0 },
  3320. { attribute : g_equipAttributes[6] , factor : 10 , additive : 0 },
  3321. { attribute : g_equipAttributes[16] , factor : 1 , additive : 0 },
  3322. { attribute : g_equipAttributes[21] , factor : 1 / 15 , additive : 10 } ],
  3323. shortMark : 'SWORD'
  3324. },
  3325. {
  3326. index : -1,
  3327. name : '命师的传承手环',
  3328. type : 1,
  3329. attributes : [ { attribute : g_equipAttributes[1] , factor : 1 / 5 , additive : 1 },
  3330. { attribute : g_equipAttributes[14] , factor : 1 / 20 , additive : 1 },
  3331. { attribute : g_equipAttributes[9] , factor : 20 , additive : 0 },
  3332. { attribute : g_equipAttributes[18] , factor : 1 , additive : 0 } ],
  3333. shortMark : 'BRACELET'
  3334. },
  3335. {
  3336. index : -1,
  3337. name : '秃鹫手环',
  3338. type : 1,
  3339. attributes : [ { attribute : g_equipAttributes[21] , factor : 1 / 15 , additive : 1 },
  3340. { attribute : g_equipAttributes[21] , factor : 1 / 15 , additive : 1 },
  3341. { attribute : g_equipAttributes[21] , factor : 1 / 15 , additive : 1 },
  3342. { attribute : g_equipAttributes[7] , factor : 2 , additive : 0 } ],
  3343. merge : [ [ 0, 1, 2 ], [ 3 ] ],
  3344. shortMark : 'VULTURE'
  3345. },
  3346. {
  3347. index : -1,
  3348. name : '海星戒指',
  3349. type : 1,
  3350. attributes : [ { attribute : g_equipAttributes[16] , factor : 1 / 2 , additive : 0 },
  3351. { attribute : g_equipAttributes[23] , factor : 1 / 2 , additive : 0 },
  3352. { attribute : g_equipAttributes[25] , factor : 4 / 5 , additive : 0 },
  3353. { attribute : g_equipAttributes[24] , factor : 4 / 5 , additive : 0 } ],
  3354. shortMark : 'RING'
  3355. },
  3356. {
  3357. index : -1,
  3358. name : '噬魔戒指',
  3359. type : 1,
  3360. attributes : [ { attribute : g_equipAttributes[23] , factor : 1 / 2 , additive : 0 },
  3361. { attribute : g_equipAttributes[24] , factor : 4 / 5 , additive : 0 },
  3362. { attribute : g_equipAttributes[26] , factor : 20 / 25 , additive : 0,
  3363. calculate : (a, l, p) => Math.trunc(l * p / 100 * a.factor + p / 100 * a.additive) / 10 },
  3364. { attribute : g_equipAttributes[3] , factor : 70 / 100 , additive : 0,
  3365. calculate : (a, l, p) => Math.trunc(l * p / 100 * a.factor + p / 100 * a.additive) / 10 } ],
  3366. shortMark : 'DEVOUR'
  3367. },
  3368. {
  3369. index : -1,
  3370. name : '探险者手环',
  3371. type : 1,
  3372. attributes : [ { attribute : g_equipAttributes[5] , factor : 10 , additive : 0 },
  3373. { attribute : g_equipAttributes[6] , factor : 10 , additive : 0 },
  3374. { attribute : g_equipAttributes[7] , factor : 2 , additive : 0 },
  3375. { attribute : g_equipAttributes[8] , factor : 10 , additive : 0 } ],
  3376. shortMark : 'GLOVES'
  3377. },
  3378. {
  3379. index : -1,
  3380. name : '旅法师的灵光袍',
  3381. type : 2,
  3382. attributes : [ { attribute : g_equipAttributes[8] , factor : 10 , additive : 0 },
  3383. { attribute : g_equipAttributes[11] , factor : 60 , additive : 0 },
  3384. { attribute : g_equipAttributes[4] , factor : 1 / 5 , additive : 25 },
  3385. { attribute : g_equipAttributes[9] , factor : 50 , additive : 0 } ],
  3386. shortMark : 'CLOAK'
  3387. },
  3388. {
  3389. index : -1,
  3390. name : '挑战斗篷',
  3391. type : 2,
  3392. attributes : [ { attribute : g_equipAttributes[4] , factor : 1 / 5 , additive : 50 },
  3393. { attribute : g_equipAttributes[9] , factor : 100 , additive : 0 },
  3394. { attribute : g_equipAttributes[18] , factor : 1 , additive : 0 },
  3395. { attribute : g_equipAttributes[20] , factor : 5 , additive : 0 } ],
  3396. shortMark : 'CAPE'
  3397. },
  3398. {
  3399. index : -1,
  3400. name : '战线支撑者的荆棘重甲',
  3401. type : 2,
  3402. attributes : [ { attribute : g_equipAttributes[3] , factor : 1 / 5 , additive : 20 },
  3403. { attribute : g_equipAttributes[17] , factor : 1 , additive : 0 },
  3404. { attribute : g_equipAttributes[18] , factor : 1 , additive : 0 },
  3405. { attribute : g_equipAttributes[22] , factor : 1 / 15 , additive : 10 } ],
  3406. shortMark : 'THORN'
  3407. },
  3408. {
  3409. index : -1,
  3410. name : '复苏战衣',
  3411. type : 2,
  3412. attributes : [ { attribute : g_equipAttributes[3] , factor : 1 / 5 , additive : 50 },
  3413. { attribute : g_equipAttributes[19] , factor : 5 , additive : 0 },
  3414. { attribute : g_equipAttributes[20] , factor : 5 , additive : 0 },
  3415. { attribute : g_equipAttributes[10] , factor : 20 , additive : 0 } ],
  3416. shortMark : 'WOOD'
  3417. },
  3418. {
  3419. index : -1,
  3420. name : '探险者铁甲',
  3421. type : 2,
  3422. attributes : [ { attribute : g_equipAttributes[8] , factor : 20 , additive : 0 },
  3423. { attribute : g_equipAttributes[17] , factor : 1 , additive : 0 },
  3424. { attribute : g_equipAttributes[18] , factor : 1 , additive : 0 },
  3425. { attribute : g_equipAttributes[10] , factor : 10 , additive : 0 } ],
  3426. shortMark : 'PLATE'
  3427. },
  3428. {
  3429. index : -1,
  3430. name : '探险者皮甲',
  3431. type : 2,
  3432. attributes : [ { attribute : g_equipAttributes[8] , factor : 25 , additive : 0 },
  3433. { attribute : g_equipAttributes[19] , factor : 2 , additive : 0 },
  3434. { attribute : g_equipAttributes[20] , factor : 2 , additive : 0 },
  3435. { attribute : g_equipAttributes[10] , factor : 6 , additive : 0 } ],
  3436. shortMark : 'LEATHER'
  3437. },
  3438. {
  3439. index : -1,
  3440. name : '探险者布甲',
  3441. type : 2,
  3442. attributes : [ { attribute : g_equipAttributes[8] , factor : 25 , additive : 0 },
  3443. { attribute : g_equipAttributes[19] , factor : 2 , additive : 0 },
  3444. { attribute : g_equipAttributes[20] , factor : 2 , additive : 0 },
  3445. { attribute : g_equipAttributes[10] , factor : 6 , additive : 0 } ],
  3446. shortMark : 'CLOTH'
  3447. },
  3448. {
  3449. index : -1,
  3450. name : '萌爪耳钉',
  3451. type : 3,
  3452. attributes : [ { attribute : g_equipAttributes[29] , factor : 17 / 2000 , additive : 0 },
  3453. { attribute : g_equipAttributes[30] , factor : 17 / 2000 , additive : 0 },
  3454. { attribute : g_equipAttributes[27] , factor : 1 / 30 , additive : 0 },
  3455. { attribute : g_equipAttributes[28] , factor : 1 / 30 , additive : 0 } ],
  3456. shortMark : 'RIBBON'
  3457. },
  3458. {
  3459. index : -1,
  3460. name : '占星师的耳饰',
  3461. type : 3,
  3462. attributes : [ { attribute : g_equipAttributes[8] , factor : 5 , additive : 0 },
  3463. { attribute : g_equipAttributes[4] , factor : 1 / 5 , additive : 0 },
  3464. { attribute : g_equipAttributes[9] , factor : 20 , additive : 0 },
  3465. { attribute : g_equipAttributes[19] , factor : 2 , additive : 0 } ],
  3466. shortMark : 'TIARA'
  3467. },
  3468. {
  3469. index : -1,
  3470. name : '猎魔耳环',
  3471. type : 3,
  3472. attributes : [ { attribute : g_equipAttributes[24] , factor : 2 / 5 , additive : 0 },
  3473. { attribute : g_equipAttributes[26] , factor : 2 / 25 , additive : 0 },
  3474. { attribute : g_equipAttributes[32] , factor : 2 / 25 , additive : 0 },
  3475. { attribute : g_equipAttributes[3] , factor : 3 / 50 , additive : 0 } ],
  3476. shortMark : 'HUNT'
  3477. },
  3478. {
  3479. index : -1,
  3480. name : '探险者耳环',
  3481. type : 3,
  3482. attributes : [ { attribute : g_equipAttributes[8] , factor : 10 , additive : 0 },
  3483. { attribute : g_equipAttributes[19] , factor : 2 , additive : 0 },
  3484. { attribute : g_equipAttributes[20] , factor : 2 , additive : 0 },
  3485. { attribute : g_equipAttributes[10] , factor : 4 , additive : 0 } ],
  3486. shortMark : 'SCARF'
  3487. }
  3488. ];
  3489.  
  3490. const g_equipMap = new Map();
  3491. g_equipments.forEach((item, index) => {
  3492. item.index = index;
  3493. item.alias = item.name;
  3494. g_equipMap.set(item.name, item);
  3495. g_equipMap.set(item.shortMark, item);
  3496. });
  3497.  
  3498. const g_oldEquipNames = [
  3499. [ '荆棘盾剑', '荆棘剑盾' ],
  3500. [ '饮血魔剑', '饮血长枪' ],
  3501. [ '探险者手环', '探险者手套' ],
  3502. [ '秃鹫手环', '秃鹫手套' ],
  3503. [ '复苏战衣', '复苏木甲' ],
  3504. [ '萌爪耳钉', '天使缎带' ],
  3505. [ '占星师的耳饰', '占星师的发饰' ],
  3506. [ '探险者耳环', '探险者头巾' ]
  3507. ];
  3508.  
  3509. const g_defaultEquipAttributeMerge = [ [0], [1], [2], [3] ];
  3510. const defaultEquipAttributeCalculate = ((a, l, p) => Math.trunc((l * a.factor + a.additive) * (p / 10)) / 10);
  3511. function defaultEquipmentNodeComparer(setting, eqKey, eq1, eq2) {
  3512. let eqMeta = g_equipMap.get(eqKey);
  3513. let delta = [];
  3514. let quality = eq1[2] + eq1[3] + eq1[4] + eq1[5] - eq2[2] - eq2[3] - eq2[4] - eq2[5];
  3515. let majorAdv = 0;
  3516. let majorEq = 0;
  3517. let majorDis = 0;
  3518. let minorAdv = 0;
  3519.  
  3520. eqMeta.attributes.forEach((attr, index) => {
  3521. let calculator = (attr.calculate ?? defaultEquipAttributeCalculate);
  3522. let d = calculator(attr, eq1[0], eq1[index + 1]) - calculator(attr, eq2[0], eq2[index + 1]);
  3523. if (setting[index + 1]) {
  3524. delta.push(0);
  3525. if (d > 0) {
  3526. minorAdv++;
  3527. }
  3528. }
  3529. else {
  3530. delta.push(d);
  3531. }
  3532. });
  3533.  
  3534. let merge = (eqMeta.merge?.length > 1 ? eqMeta.merge : g_defaultEquipAttributeMerge);
  3535. for (let indices of merge) {
  3536. let sum = 0;
  3537. indices.forEach((index) => { sum += delta[index]; });
  3538. if (sum > 0) {
  3539. majorAdv++;
  3540. }
  3541. else if (sum < 0) {
  3542. majorDis++;
  3543. }
  3544. else {
  3545. majorEq++;
  3546. }
  3547. };
  3548.  
  3549. return { quality : quality, majorAdv : majorAdv, majorEq : majorEq, majorDis : majorDis, minorAdv : minorAdv };
  3550. }
  3551.  
  3552. function formatEquipmentAttributes(e, itemSeparator) {
  3553. let text = '';
  3554. if (e?.length > 7) {
  3555. itemSeparator ??= ', ';
  3556. let sp = '';
  3557. console.log(e[0]);
  3558. g_equipMap.get(e[0])?.attributes.forEach((attr, index) => {
  3559. text += `${sp}${attr.attribute.name} +${(attr.calculate ?? defaultEquipAttributeCalculate)
  3560. (attr, e[1], e[index + 4])}${attr.attribute.type == 0 ? '%' : ''}`;
  3561. sp = itemSeparator;
  3562. });
  3563. }
  3564. return text;
  3565. }
  3566.  
  3567. function equipmentVerify(node, e) {
  3568. if ((e ??= equipmentInfoParseNode(node, false)) != null) {
  3569. let error = 0;
  3570. let attrs = node.getAttribute('data-content')?.match(/'>.+\+\d+\.?\d*%?.*?<span/g);
  3571. if (attrs?.length == 4) {
  3572. g_equipMap.get(e[0])?.attributes.forEach((attr, index) => {
  3573. let eBase = (attr.calculate ?? defaultEquipAttributeCalculate)(attr, parseInt(e[1]), parseInt(e[index + 4]));
  3574. let disp = attrs[index].match(/\d+\.?\d*/)?.[0];
  3575. if (eBase.toString() != disp) {
  3576. console.log(`${e[0]} Lv.${e[1]} #${index}: ${attrs[index].slice(2, -5)} ---> ${eBase}`);
  3577. error++;
  3578. }
  3579. });
  3580. return error;
  3581. }
  3582. }
  3583. console.log(`BUG equip: ${node}`);
  3584. return -1;
  3585. }
  3586.  
  3587. function equipmentVerifyManual(name, level, attrs, displays) {
  3588. let eqMeta = g_equipMap.get(name);
  3589. if (eqMeta != null && attrs?.length == 4 && displays?.length == 4) {
  3590. console.log(`${name} Lv.${level}`);
  3591. eqMeta.attributes.forEach((a, i) => {
  3592. let eBase = (a.calculate ?? defaultEquipAttributeCalculate)(a, level, attrs[i]);
  3593. console.log(`${i}: ${displays[i]} ---> ${eBase}`);
  3594. });
  3595. }
  3596. }
  3597. // equipmentVerifyManual('噬魔戒指', 200, [90, 82, 99, 90], ['90', '131.2', '15.8', '12.6']);
  3598.  
  3599. var g_useOldEquipName = false;
  3600. var g_useThemeEquipName = false;
  3601. function equipLoadTheme(theme) {
  3602. if (theme.level?.length > 0) {
  3603. g_equipmentLevelName = theme.level;
  3604. }
  3605. if (g_useOldEquipName) {
  3606. g_oldEquipNames.forEach((item) => {
  3607. if (!g_equipMap.has(item[1])) {
  3608. let eqMeta = g_equipMap.get(item[0]);
  3609. if (eqMeta != null) {
  3610. eqMeta.alias = item[1];
  3611. g_equipMap.set(eqMeta.alias, eqMeta);
  3612. }
  3613. }
  3614. });
  3615. }
  3616. if (g_useThemeEquipName) {
  3617. for(let item in theme) {
  3618. if (/^[a-z]+\d+$/.test(item) && theme[item].length >= 5 && theme[item][3]?.length > 0 && !g_equipMap.has(theme[item][3])) {
  3619. let eqMeta = g_equipMap.get(theme[item][2]);
  3620. if (eqMeta != null) {
  3621. eqMeta.alias = theme[item][3];
  3622. g_equipMap.set(eqMeta.alias, eqMeta);
  3623. }
  3624. }
  3625. }
  3626. }
  3627. }
  3628.  
  3629. const g_halos = [
  3630. { index : -1 , id : 101 , name : '启程之誓' , points : 0 , shortMark : 'SHI' },
  3631. { index : -1 , id : 102 , name : '启程之心' , points : 0 , shortMark : 'XIN' },
  3632. { index : -1 , id : 103 , name : '启程之风' , points : 0 , shortMark : 'FENG' },
  3633. { index : -1 , id : 104 , name : '等级挑战' , points : 0 , shortMark : 'TIAO' },
  3634. { index : -1 , id : 105 , name : '等级压制' , points : 0 , shortMark : 'YA' },
  3635. { index : -1 , id : 201 , name : '破壁之心' , points : 20 , shortMark : 'BI' },
  3636. { index : -1 , id : 202 , name : '破魔之心' , points : 20 , shortMark : 'MO' },
  3637. { index : -1 , id : 203 , name : '复合护盾' , points : 20 , shortMark : 'DUN' },
  3638. { index : -1 , id : 204 , name : '鲜血渴望' , points : 20 , shortMark : 'XUE' },
  3639. { index : -1 , id : 205 , name : '削骨之痛' , points : 20 , shortMark : 'XIAO' },
  3640. { index : -1 , id : 206 , name : '圣盾祝福' , points : 20 , shortMark : 'SHENG' },
  3641. { index : -1 , id : 207 , name : '恶意抽奖' , points : 20 , shortMark : 'E' },
  3642. { index : -1 , id : 301 , name : '伤口恶化' , points : 30 , shortMark : 'SHANG' },
  3643. { index : -1 , id : 302 , name : '精神创伤' , points : 30 , shortMark : 'SHEN' },
  3644. { index : -1 , id : 303 , name : '铁甲尖刺' , points : 30 , shortMark : 'CI' },
  3645. { index : -1 , id : 304 , name : '忍无可忍' , points : 30 , shortMark : 'REN' },
  3646. { index : -1 , id : 305 , name : '热血战魂' , points : 30 , shortMark : 'RE' },
  3647. { index : -1 , id : 306 , name : '点到为止' , points : 30 , shortMark : 'DIAN' },
  3648. { index : -1 , id : 307 , name : '午时已到' , points : 30 , shortMark : 'WU' },
  3649. { index : -1 , id : 308 , name : '纸薄命硬' , points : 30 , shortMark : 'ZHI' },
  3650. { index : -1 , id : 309 , name : '不动如山' , points : 30 , shortMark : 'SHAN' },
  3651. { index : -1 , id : 401 , name : '沸血之志' , points : 100 , shortMark : 'FEI' },
  3652. { index : -1 , id : 402 , name : '波澜不惊' , points : 100 , shortMark : 'BO' },
  3653. { index : -1 , id : 403 , name : '飓风之力' , points : 100 , shortMark : 'JU' },
  3654. { index : -1 , id : 404 , name : '红蓝双刺' , points : 100 , shortMark : 'HONG' },
  3655. { index : -1 , id : 405 , name : '荧光护盾' , points : 100 , shortMark : 'JUE' },
  3656. { index : -1 , id : 406 , name : '后发制人' , points : 100 , shortMark : 'HOU' },
  3657. { index : -1 , id : 407 , name : '钝化锋芒' , points : 100 , shortMark : 'DUNH' },
  3658. { index : -1 , id : 408 , name : '自信回头' , points : 100 , shortMark : 'ZI' }
  3659. ];
  3660.  
  3661. const g_haloMap = new Map();
  3662. g_halos.forEach((item, index) => {
  3663. item.index = index;
  3664. g_haloMap.set(item.id, item);
  3665. g_haloMap.set(item.id.toString(), item);
  3666. g_haloMap.set(item.name, item);
  3667. g_haloMap.set(item.shortMark, item);
  3668. });
  3669.  
  3670. const g_configs = [
  3671. {
  3672. index : -1,
  3673. id : 'maxConcurrentRequests',
  3674. name : `最大并发网络请求(${ConcurrentRequestCount.min} - ${ConcurrentRequestCount.max})`,
  3675. defaultValue : ConcurrentRequestCount.default,
  3676. value : ConcurrentRequestCount.default,
  3677. tips : '同时向服务器提交的请求的最大数量。过高的设置容易引起服务阻塞或被认定为DDOS攻击从而导致服务器停止服务(HTTP 503)。',
  3678. validate : ((value) => {
  3679. return (!isNaN(value = parseInt(value)) && value >= ConcurrentRequestCount.min && value <= ConcurrentRequestCount.max);
  3680. }),
  3681. onchange : ((value) => {
  3682. if (!isNaN(value = parseInt(value)) && value >= ConcurrentRequestCount.min && value <= ConcurrentRequestCount.max) {
  3683. return (g_maxConcurrentRequests = value);
  3684. }
  3685. return (g_maxConcurrentRequests = ConcurrentRequestCount.default);
  3686. })
  3687. },
  3688. {
  3689. index : -1,
  3690. id : 'solutionSwitchMethod',
  3691. name : '绑定方案切换方式(0:完全,1:差分)',
  3692. defaultValue : 1,
  3693. value : 1,
  3694. tips : '执行绑定方案切换时所要使用的方法。“完全切换”和“差分切换”的主要区别在于护符组的加载方式,完全切换方式总是首先清空饰品栏然后按照绑定' +
  3695. '定义中指定的加载顺序逐项加载护符组,优点是优先级较高的组会先行加载,当饰品栏空间不足时不完全加载的组一般为优先级较低的组,而缺点则' +
  3696. '是加载效率较低;差分切换方式会忽略护符组的优先级,首先卸载已经在饰品栏中但并不在方案中的护符而留下重叠部分,然后加载缺失的护符,但' +
  3697. '加载顺序随机,这意味着当饰品栏空间不足时可能出现重要护符未能加载的情况,但这种加载方式效率较高(尤其是在护符重叠较多的方案间切换时)。' +
  3698. '正常情况下由于当前版本的饰品栏空间较为固定,所以绑定方案不应使用多于饰品栏空间的护符数量,而在这种情况下差分加载方式具有明显的优势。',
  3699. validate : ((value) => {
  3700. return /^[01]$/.test(value);
  3701. }),
  3702. onchange : ((value) => {
  3703. if (/^[01]$/.test(value)) {
  3704. return parseInt(value);
  3705. }
  3706. return 0;
  3707. })
  3708. },
  3709. {
  3710. index : -1,
  3711. id : 'singlePotRecovery',
  3712. name : '以单瓶方式使用体能刺激药水(0:禁止,1:允许)',
  3713. defaultValue : 1,
  3714. value : 1,
  3715. tips : '以单瓶方式使用体能刺激药水可再一次获得翻牌的贝壳和经验奖励(仅基础奖励,无道具),无需重新出击和翻牌。此方式对于药水充足且出击胜率高' +
  3716. '的玩家并非最佳选择,将此选项设为0可防止点错。',
  3717. validate : ((value) => {
  3718. return /^[01]$/.test(value);
  3719. }),
  3720. onchange : ((value) => {
  3721. if (/^[01]$/.test(value)) {
  3722. return parseInt(value);
  3723. }
  3724. return 0;
  3725. })
  3726. },
  3727. {
  3728. index : -1,
  3729. id : 'openCardSequence',
  3730. name : `一键翻牌次序(整数 ±(1 - 12) 组成的无重复序列或留空)`,
  3731. defaultValue : '',
  3732. value : '',
  3733. tips : '一键翻牌时的开牌次序,此设置留空时(不可留有空格字符,空格不会被判定为空而会判定为随机元素)将不显示一键翻牌相关面板。序列中禁止出现绝对值' +
  3734. '重复的元素,负数表示排除某张牌,可出现在任意位置且不占位,排除个数须不大于3。由于最多只需翻开9张牌必定会出现三同色,所以正数及随机元素个数' +
  3735. '须不大于9,不足9时程序将在开牌时按需随机补足。单个元素也可设置为随机,只需将该元素设置为无内容、仅含空格和/或单个“?”即可。' +
  3736. '例:“?”=“ ? ”=“,”=“ , ”=“ ”=全随机;“-12”=排除绮,其余全随机;“-1,12,,6,-2, , ? ,+5”=排除舞和默,依次翻开:绮、随机、薇、随机、' +
  3737. '随机、梦、随机到底。开牌过程中任意时刻出现三同色或错误即终止。',
  3738. validate : ((value) => {
  3739. let seq = value.split(',');
  3740. let abs;
  3741. let inc = 0;
  3742. let exc = 0;
  3743. let dup = [];
  3744. for (let e of seq) {
  3745. if ((e = e.trim()).length == 0 || e == '?') {
  3746. if (++inc > 9) {
  3747. return false;
  3748. }
  3749. continue;
  3750. }
  3751. else if ((!/^(\+|-)?\d+$/.test(e) || (abs = Math.abs(e = parseInt(e))) < 1 || abs > 12 || dup[abs] != null) ||
  3752. (e < 0 && ++exc > 3) || (e > 0 && ++inc > 9)) {
  3753. return false;
  3754. }
  3755. dup[abs] = true;
  3756. }
  3757. return true;
  3758. }),
  3759. onchange : ((value) => {
  3760. let seq = value.split(',');
  3761. let abs;
  3762. let inc = 0;
  3763. let exc = 0;
  3764. let dup = [];
  3765. for (let e of seq) {
  3766. if ((e = e.trim()).length == 0 || e == '?') {
  3767. if (++inc > 9) {
  3768. return '';
  3769. }
  3770. continue;
  3771. }
  3772. else if ((!/^(\+|-)?\d+$/.test(e) || (abs = Math.abs(e = parseInt(e))) < 1 || abs > 12 || dup[abs] != null) ||
  3773. (e < 0 && ++exc > 3) || (e > 0 && ++inc > 9)) {
  3774. return '';
  3775. }
  3776. dup[abs] = true;
  3777. }
  3778. return value;
  3779. })
  3780. },
  3781. {
  3782. index : -1,
  3783. id : 'maxEquipForgeHistoryList',
  3784. name : `锻造历史记录数限制(0 - 100)`,
  3785. defaultValue : 15,
  3786. value : 15,
  3787. tips : '锻造历史记录的条目数限制,0为不保存。当记录数超出限制时将按照锻造顺序移除较早的记录。除非您有特殊需求,否则此项设置不宜过大,15 ~ 30' +
  3788. '可能是较为平衡的选择',
  3789. validate : ((value) => {
  3790. return (!isNaN(value = parseInt(value)) && value >= 0 && value <= 100);
  3791. }),
  3792. onchange : ((value) => {
  3793. if (!isNaN(value = parseInt(value)) && value >= 0 && value <= 100) {
  3794. return value;
  3795. }
  3796. return 15;
  3797. })
  3798. },
  3799. {
  3800. index : -1,
  3801. id : 'minBeachEquipLevelToAmulet',
  3802. name : `沙滩装备转护符最小等级(绿,黄,红)`,
  3803. defaultValue : '1,1,1',
  3804. value : '1,1,1',
  3805. tips : '沙滩装备批量转换护符时各色装备所需达到的最小等级,小于对应等级的装备不会被转换,但玩家依然可以选择手动熔炼。',
  3806. validate : ((value) => {
  3807. return /^\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*$/.test(value);
  3808. }),
  3809. onchange : ((value) => {
  3810. if (/^\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*$/.test(value)) {
  3811. return value;
  3812. }
  3813. return '1,1,1';
  3814. })
  3815. },
  3816. {
  3817. index : -1,
  3818. id : 'minBeachAmuletPointsToStore',
  3819. name : `沙滩转护符默认入仓最小加成(苹果,葡萄,樱桃)`,
  3820. defaultValue : '1,1%,1%',
  3821. value : '1,1%,1%',
  3822. tips : '沙滩装备批量转换护符时默认处于入仓列表的最小加成,“%”可省略。此设置仅为程序产生分类列表时作为参考,玩家可通过双击或以上下文菜单键单击' +
  3823. '特定护符移动它的位置。',
  3824. validate : ((value) => {
  3825. return /^\s*\d+\s*,\s*\d+\s*%?\s*,\s*\d+\s*%?\s*$/.test(value);
  3826. }),
  3827. onchange : ((value) => {
  3828. if (/^\s*\d+\s*,\s*\d+\s*%?\s*,\s*\d+\s*%?\s*$/.test(value)) {
  3829. return value;
  3830. }
  3831. return '1,1%,1%';
  3832. })
  3833. },
  3834. {
  3835. index : -1,
  3836. id : 'clearBeachAfterBatchToAmulet',
  3837. name : `批量转护符完成后自动清理沙滩(0:否,1:是)`,
  3838. defaultValue : 0,
  3839. value : 0,
  3840. tips : '沙滩装备批量转换护符完成后自动清理沙滩上残存的装备。装备一但被清理将转换为各种锻造石且不可恢复,当此选项开启时请务必确保在使用批量转护符' +
  3841. '功能之前拾取所有欲保留的装备。',
  3842. validate : ((value) => {
  3843. return /^[01]$/.test(value);
  3844. }),
  3845. onchange : ((value) => {
  3846. if (/^[01]$/.test(value)) {
  3847. return parseInt(value);
  3848. }
  3849. return 0;
  3850. })
  3851. },
  3852. {
  3853. index : -1,
  3854. id : 'gemPollPeriod',
  3855. name : `宝石工坊挂机轮询周期(1 - ${Math.min(g_gemPollPeriodMinute.max, g_gemMinWorktimeMinute)}分钟,0:禁用挂机)`,
  3856. defaultValue : g_gemPollPeriodMinute.default,
  3857. value : g_gemPollPeriodMinute.default,
  3858. tips : '宝石工坊挂机程序向服务器发出进度轮询请求的间隔时间,以分钟为单位。0表示禁用挂机程序,同时各工作台完工剩余时间和工会面板也将不会显示。此项设置越' +
  3859. '小对服务器造成的压力越大,除非您一直盯着宝石工坊的页面(这种情况建议手动按需刷新),否则您不会因较小的设置值获得任何额外优势,因为挂机程序会根据' +
  3860. '工作进度动态调整轮询时间间隔以便及时收工重开。所以如果您的需求只是单纯的自动收工重开则建议设置为最大值。唯一例外是当您的设备时钟走时明显偏慢,小' +
  3861. '时误差达到分钟级别时可根据情况适当调小设置,推荐公式为“期望时间 - 期望时间内可能产生的最大正误差”。如果您的设备时钟偏快则在设为最大值的情况下无' +
  3862. '需进行任何额外调整。',
  3863. validate : ((value) => {
  3864. return (!isNaN(value = parseInt(value)) && value <= g_gemPollPeriodMinute.max);
  3865. }),
  3866. onchange : ((value) => {
  3867. if (!isNaN(value = parseInt(value)) && value <= g_gemPollPeriodMinute.max) {
  3868. return value;
  3869. }
  3870. return g_gemPollPeriodMinute.default;
  3871. })
  3872. },
  3873. {
  3874. index : -1,
  3875. id : 'gemWorkCompletionCondition',
  3876. name : `宝石工坊完工条件(按工作台顺序以“,”分隔或留空)`,
  3877. defaultValue : '',
  3878. value : '',
  3879. tips : '宝石工坊运作过程中挂机程序对各工作台进行完工判定的条件,按照工作台次序以“,”分隔,“%”可省略。也可以单项或全部留空表示使用默认值(目前贝壳1000000,' +
  3880. '星沙10,幻影经验200,其它100%)。在满足基本收工条件后(目前为开工满8小时),此设置将被挂机程序直接用于自动收工判定。请注意,设置程序只进行格式检' +
  3881. '查,并不会对有效值范围作出任何假设,所以一个错误的设置可能会令完工判定逻辑失效从而影响自动收工功能的正确运行。',
  3882. validate : ((value) => {
  3883. let conds = value.split(',');
  3884. if (conds.length > g_gemWorks.length) {
  3885. return false;
  3886. }
  3887. for (let i = conds.length - 1; i >= 0; i--) {
  3888. if ((conds[i] = conds[i].trim()).length > 0 && !(new RegExp(`^${g_gemWorks[i].unitRegex.regex.source}$`)).test(conds[i])) {
  3889. return false;
  3890. }
  3891. }
  3892. return true;
  3893. }),
  3894. onchange : ((value) => {
  3895. let conds = value.split(',');
  3896. if (conds.length > g_gemWorks.length) {
  3897. return '';
  3898. }
  3899. for (let i = conds.length - 1; i >= 0; i--) {
  3900. if ((conds[i] = conds[i].trim()).length > 0 && !(new RegExp(`^${g_gemWorks[i].unitRegex.regex.source}$`)).test(conds[i])) {
  3901. return '';
  3902. }
  3903. }
  3904. return value;
  3905. })
  3906. }
  3907. ];
  3908.  
  3909. const g_configMap = new Map();
  3910. g_configs.forEach((item, index) => {
  3911. item.index = index;
  3912. g_configMap.set(item.id, item);
  3913. });
  3914.  
  3915. function readConfig() {
  3916. let udata = loadUserConfigData();
  3917. g_configs.forEach((item) => {
  3918. item.value = (item.onchange?.call(null, udata.config[item.id] ?? item.defaultValue));
  3919. });
  3920. return udata;
  3921. }
  3922.  
  3923. function modifyConfig(configIds, title, reload) {
  3924. title ??= '插件设置';
  3925. let udata = readConfig();
  3926. let configs = (configIds?.length > 0 ? [] : g_configs);
  3927. if (configIds?.length > 0) {
  3928. for (let id of configIds) {
  3929. let cfg = g_configMap.get(id);
  3930. if (cfg != null) {
  3931. configs.push(cfg);
  3932. }
  3933. }
  3934. }
  3935.  
  3936. genericPopupInitialize();
  3937.  
  3938. let fixedContent =
  3939. '<div style="padding:20px 10px 10px 0px;color:blue;font-size:16px;"><b>请勿随意修改配置项,' +
  3940. `除非您知道它的准确用途并且设置为正确的值,否则可能导致插件工作异常<span id="${g_genericPopupInformationTipsId}" ` +
  3941. 'style="float:right;color:red;"></span></b></div>';
  3942. let mainContent =
  3943. `<style> #config-table { width:100%; }
  3944. #config-table th { width:25%; line-height:240%; }
  3945. #config-table th.config-th-name { width:60%; }
  3946. #config-table th.config-th-button { width:15%; }
  3947. #config-table button.config-restore-value { width:48%; float:right; margin-left:1px; }
  3948. table tr.alt { background-color:${g_genericPopupBackgroundColorAlt}; } </style>
  3949. <div class="${g_genericPopupTopLineDivClass}"><table id="config-table">
  3950. <tr class="alt"><th class="config-th-name">配置项 (在项名称或值输入框上悬停查看说明)</th><th>值</th>
  3951. <th class="config-th-button"></th></tr></table><div>`;
  3952.  
  3953. genericPopupSetFixedContent(fixedContent);
  3954. genericPopupSetContent(title, mainContent);
  3955.  
  3956. let configTable = genericPopupQuerySelector('#config-table');
  3957. configs.forEach((item, index) => {
  3958. let tr = document.createElement('tr');
  3959. tr.className = ('config-tr' + ((index & 1) == 0 ? '' : ' alt'));
  3960. tr.setAttribute('config-item', item.id);
  3961. tr.innerHTML =
  3962. `<td><div data-toggle="popover" data-placement="bottom" data-trigger="hover" data-content="${item.tips}">${item.name}<div></td>
  3963. <td><div data-toggle="popover" data-placement="bottom" data-trigger="hover" data-content="${item.tips}">
  3964. <input type="text" style="display:inline-block;width:100%;" value="${item.value}" /><div></td>
  3965. <td><button type="button" class="config-restore-value" title="重置为当前配置" value="${item.value}">当前</button>` +
  3966. `<button type="button" class="config-restore-value" title="重置为默认配置" value="${item.defaultValue}">默认</button></td>`;
  3967. tr.children[1].children[0].children[0].oninput = tr.children[1].children[0].children[0].onchange = validateInput;
  3968. configTable.appendChild(tr);
  3969. });
  3970. function validateInput(e) {
  3971. let tr = e.target.parentNode.parentNode.parentNode;
  3972. let cfg = g_configMap.get(tr.getAttribute('config-item'));
  3973. tr.style.color = ((cfg.validate?.call(null, e.target.value) ?? true) ? 'black' : 'red');
  3974. }
  3975.  
  3976. configTable.querySelectorAll('button.config-restore-value').forEach((btn) => { btn.onclick = restoreValue; });
  3977. function restoreValue(e) {
  3978. let input = e.target.parentNode.parentNode.children[1].children[0].children[0];
  3979. input.value = e.target.value;
  3980. input.oninput({ target : input });
  3981. genericPopupShowInformationTips('配置项已' + e.target.title, 5000);
  3982. }
  3983.  
  3984. $('#config-table div[data-toggle="popover"]').popover();
  3985.  
  3986. genericPopupAddButton('重置为当前配置', 0, restoreValueAll, true).setAttribute('config-restore-default-all', 0);
  3987. genericPopupAddButton('重置为默认配置', 0, restoreValueAll, true).setAttribute('config-restore-default-all', 1);
  3988. function restoreValueAll(e) {
  3989. let defaultValue = (e.target.getAttribute('config-restore-default-all') == '1');
  3990. configTable.querySelectorAll('tr.config-tr').forEach((row) => {
  3991. let id = row.getAttribute('config-item');
  3992. let cfg = g_configMap.get(id);
  3993. let input = row.children[1].children[0].children[0];
  3994. input.value = (defaultValue ? cfg.defaultValue : (cfg.value ?? cfg.defaultValue));
  3995. input.oninput({ target : input });
  3996. });
  3997. genericPopupShowInformationTips('全部配置项已' + e.target.innerText, 5000);
  3998. }
  3999.  
  4000. genericPopupAddButton('保存', 80, saveConfig, false).setAttribute('config-save-config', 1);
  4001. genericPopupAddButton('确认', 80, saveConfig, false).setAttribute('config-save-config', 0);
  4002. function saveConfig(e) {
  4003. let close = (e.target.getAttribute('config-save-config') == '0');
  4004. let config = (udata?.config ?? {});
  4005. let error = [];
  4006. configTable.querySelectorAll('tr.config-tr').forEach((row) => {
  4007. let id = row.getAttribute('config-item');
  4008. let cfg = g_configMap.get(id);
  4009. let value = row.children[1].children[0].children[0].value;
  4010. if (cfg.validate?.call(null, value) ?? true) {
  4011. config[id] = cfg.value = row.children[2].children[0].value = (cfg.onchange?.call(null, value) ?? value);
  4012. }
  4013. else {
  4014. error.push(cfg.name);
  4015. }
  4016. });
  4017.  
  4018. udata.config = config;
  4019. saveUserConfigData(udata);
  4020.  
  4021. if (error.length > 0) {
  4022. alert('以下配置项输入内容有误,如有必要请重新设置:\n\n [ ' + error.join(' ]\n [ ') + ' ]');
  4023. }
  4024. else if (close) {
  4025. if (reload) {
  4026. window.location.reload();
  4027. }
  4028. else {
  4029. genericPopupClose(true, true);
  4030. }
  4031. }
  4032. else {
  4033. genericPopupShowInformationTips('配置已保存', 5000);
  4034. }
  4035. }
  4036. genericPopupAddCloseButton(80);
  4037.  
  4038. genericPopupSetContentSize(Math.min(configs.length * 28 + 70, Math.max(window.innerHeight - 200, 400)),
  4039. Math.min(720, Math.max(window.innerWidth - 100, 680)),
  4040. true);
  4041. genericPopupShowModal(true);
  4042. }
  4043.  
  4044. function initiatizeConfig() {
  4045. let udata = loadUserConfigData();
  4046. if (udata == null) {
  4047. udata = {
  4048. dataIndex : { battleInfoNow : '' , battleInfoBefore : '' , battleInfoBack : '' },
  4049. dataBeachSift : {},
  4050. dataBind : {},
  4051. dataBindDefault : {},
  4052. config : {},
  4053. calculatorTemplatePVE : {}
  4054. };
  4055. }
  4056. else {
  4057. if (udata.dataIndex == null) {
  4058. udata.dataIndex = { battleInfoNow : '' , battleInfoBefore : '' , battleInfoBack : '' };
  4059. }
  4060. if (udata.dataBeachSift == null) {
  4061. udata.dataBeachSift = {};
  4062. }
  4063. if (udata.dataBind == null) {
  4064. udata.dataBind = {};
  4065. }
  4066. if (udata.dataBindDefault == null) {
  4067. udata.dataBindDefault = {};
  4068. }
  4069. if (udata.config == null) {
  4070. udata.config = {};
  4071. }
  4072. if (udata.calculatorTemplatePVE == null) {
  4073. udata.calculatorTemplatePVE = {};
  4074. }
  4075. for (let key in udata.dataBeachSift) {
  4076. if (!g_equipMap.has(key) && key != 'ignoreEquipQuality' &&
  4077. key != 'ignoreMysEquip' && key != 'ignoreEquipLevel') {
  4078.  
  4079. delete udata.dataBeachSift[key];
  4080. }
  4081. }
  4082. for (let key in udata.dataBind) {
  4083. if (!g_roleMap.has(key)) {
  4084. delete udata.dataBind[key];
  4085. }
  4086. }
  4087. for (let key in udata.dataBindDefault) {
  4088. if (!g_roleMap.has(key) || udata.dataBind[key] == null) {
  4089. delete udata.dataBindDefault[key];
  4090. }
  4091. }
  4092. for (let key in udata.config) {
  4093. if (!g_configMap.has(key)) {
  4094. delete udata.config[key];
  4095. }
  4096. }
  4097. for (let key in udata.calculatorTemplatePVE) {
  4098. if (!g_roleMap.has(key)) {
  4099. delete udata.calculatorTemplatePVE[key];
  4100. }
  4101. }
  4102. }
  4103.  
  4104. saveUserConfigData(udata);
  4105. readConfig();
  4106. }
  4107.  
  4108. var g_themeLoaded = false;
  4109. function loadTheme() {
  4110. if (!g_themeLoaded) {
  4111. g_themeLoaded = true;
  4112. let cb = document.querySelector('input.iconpack-switch');
  4113. if (cb != null) {
  4114. g_useOldEquipName = cb.checked;
  4115. g_useThemeEquipName = (document.querySelector('input.themepack-equip')?.checked ?? false);
  4116. try {
  4117. let theme = JSON.parse(sessionStorage.getItem('ThemePack') ?? '{}');
  4118. if (theme?.url != null) {
  4119. amuletLoadTheme(theme);
  4120. propertyLoadTheme(theme);
  4121. equipLoadTheme(theme);
  4122. }
  4123. }
  4124. catch (ex) {
  4125. console.log('THEME:');
  4126. console.log(ex);
  4127. }
  4128. }
  4129. }
  4130. }
  4131.  
  4132. initiatizeConfig();
  4133.  
  4134. let g_messageBoxObserver = new MutationObserver((mList) => {
  4135. g_messageBoxObserver.disconnect();
  4136. readConfig();
  4137.  
  4138. let btns = mList?.[0]?.target?.querySelectorAll('button.btn.btn-primary');
  4139. btns?.forEach((btn) => {
  4140. if (btn.getAttribute('onclick')?.indexOf('oclick(\'13\',\'1\')') >= 0) {
  4141. if (g_configMap.get('singlePotRecovery')?.value == 0) {
  4142. btn.disabled = 'disabled';
  4143. btn.parentNode.innerHTML = btn.outerHTML + '<b style="margin-left:10px;color:red;">(已禁止)</b>';
  4144. }
  4145. }
  4146. });
  4147. g_messageBoxObserver.observe(document.getElementById('mymessage'), { subtree : true , childList : true });
  4148. });
  4149. g_messageBoxObserver.observe(document.getElementById('mymessage'), { subtree : true , childList : true });
  4150.  
  4151. ////////////////////////////////////////////////////////////////////////////////////////////////////
  4152. //
  4153. // page add-ins
  4154. //
  4155. ////////////////////////////////////////////////////////////////////////////////////////////////////
  4156.  
  4157. if (window.location.pathname == g_guguzhenHome) {
  4158. const USER_DATA_xPORT_GM_KEY = g_kfUser + '_export_string';
  4159. const USER_DATA_xPORT_SEPARATOR = '\n';
  4160.  
  4161. function importUserConfigData() {
  4162. genericPopupSetContent(
  4163. '导入内容',
  4164. `<b><div id="user_data_import_tip" style="color:#0000c0;padding:15px 0px 10px;">
  4165. 请将从其它系统中使用同一帐号导出的内容填入文本框中并执行导入操作</div></b>
  4166. <div style="height:330px;"><textarea id="user_data_persistence_string"
  4167. style="height:100%;width:100%;resize:none;"></textarea></div>`);
  4168.  
  4169. let btnRead = genericPopupAddButton(
  4170. '从全局存储中读取',
  4171. 0,
  4172. ((e) => {
  4173. btnRead.disabled = btnImport.disabled = 'disabled';
  4174. genericPopupQuerySelector('#user_data_persistence_string').value = null;//GM_getValue(USER_DATA_xPORT_GM_KEY, '');
  4175. let tipContainer = genericPopupQuerySelector('#user_data_import_tip');
  4176. let tipColor = tipContainer.style.color;
  4177. let tipString = tipContainer.innerText;
  4178. tipContainer.style.color = '#ff0000';
  4179. tipContainer.innerText = (genericPopupQuerySelector('#user_data_persistence_string').value.length > g_kfUser.length ?
  4180. '已从全局存储中读取成功' : '未能读取导出数据,请确保已在“数据导出”功能中写入全局存储');
  4181. setTimeout((() => {
  4182. tipContainer.style.color = tipColor;
  4183. tipContainer.innerText = tipString;
  4184. btnRead.disabled = btnImport.disabled = '';
  4185. }), 3000);
  4186. }),
  4187. true);
  4188. btnRead.disabled = 'disabled';
  4189.  
  4190. let btnImport = genericPopupAddButton(
  4191. '执行导入',
  4192. 0,
  4193. (() => {
  4194. btnRead.disabled = btnImport.disabled = 'disabled';
  4195. let userData = genericPopupQuerySelector('#user_data_persistence_string').value.split(USER_DATA_xPORT_SEPARATOR);
  4196. if (userData.length > 0) {
  4197. if (confirm('导入操作会覆盖已有的用户配置(护符组定义、卡片装备光环护符绑定、沙滩装备筛选配置等等),要继续吗?')) {
  4198. let backup = [];
  4199. let importedItems = [];
  4200. let illegalItems = [];
  4201. g_userDataStorageKeyConfig.forEach((item, index) => {
  4202. backup[index] = localStorage.getItem(item);
  4203. });
  4204. userData.forEach((item) => {
  4205. if ((item = item.trim()).length > 0) {
  4206. let key = item.slice(0, item.indexOf(USER_STORAGE_KEY_VALUE_SEPARATOR));
  4207. if (g_userDataStorageKeyConfig.indexOf(key) >= 0) {
  4208. if (illegalItems.length == 0) {
  4209. localStorage.setItem(key, item.substring(key.length + 1));
  4210. importedItems.push(key);
  4211. }
  4212. }
  4213. else {
  4214. illegalItems.push(key);
  4215. }
  4216. }
  4217. });
  4218. if (illegalItems.length > 0) {
  4219. importedItems.forEach((item) => {
  4220. let index = g_userDataStorageKeyConfig.indexOf(item);
  4221. if (index >= 0 && backup[index] != null) {
  4222. localStorage.setItem(item, backup[index]);
  4223. }
  4224. else {
  4225. localStorage.removeItem(item);
  4226. }
  4227. });
  4228. alert('输入内容格式有误,有非法项目导致导入失败,请检查:\n\n [ ' + illegalItems.join(' ]\n [ ') + ' ]');
  4229. }
  4230. else if (importedItems.length > 0) {
  4231. alert('导入已完成:\n\n [ ' + importedItems.join(' ]\n [ ') + ' ]');
  4232. window.location.reload();
  4233. return;
  4234. }
  4235. else {
  4236. alert('输入内容格式有误,导入失败,请检查!');
  4237. }
  4238. }
  4239. }
  4240. else {
  4241. alert('输入内容格式有误,导入失败,请检查!');
  4242. }
  4243. btnRead.disabled = 'disabled';
  4244. btnImport.disabled = '';
  4245. }),
  4246. true);
  4247. genericPopupAddCloseButton(80);
  4248.  
  4249. genericPopupSetContentSize(400, 600, false);
  4250. genericPopupShowModal(true);
  4251. }
  4252.  
  4253. function exportUserConfigData() {
  4254. genericPopupSetContent(
  4255. '导出内容',
  4256. `<b><div id="user_data_export_tip" style="color:#0000c0;padding:15px 0px 10px;">
  4257. 请勿修改任何导出内容,将其保存为纯文本在其它系统中使用相同的帐号执行导入操作</div></b>
  4258. <div style="height:330px;"><textarea id="user_data_persistence_string" readonly="true"
  4259. style="height:100%;width:100%;resize:none;"></textarea></div>`);
  4260.  
  4261. let btnWrite = genericPopupAddButton(
  4262. '写入全局存储',
  4263. 0,
  4264. (() => {
  4265. btnWrite.disabled = btnCopy.disabled = 'disabled';
  4266. //GM_setValue(USER_DATA_xPORT_GM_KEY, genericPopupQuerySelector('#user_data_persistence_string').value);
  4267. let tipContainer = genericPopupQuerySelector('#user_data_export_tip');
  4268. let tipColor = tipContainer.style.color;
  4269. let tipString = tipContainer.innerText;
  4270. tipContainer.style.color = '#ff0000';
  4271. tipContainer.innerText = '导出内容已写入全局存储';
  4272. setTimeout((() => {
  4273. tipContainer.style.color = tipColor;
  4274. tipContainer.innerText = tipString;
  4275. btnWrite.disabled = btnCopy.disabled = '';
  4276. }), 3000);
  4277. }),
  4278. true);
  4279. btnWrite.disabled = 'disabled';
  4280.  
  4281. let btnCopy = genericPopupAddButton(
  4282. '复制导出内容至剪贴板',
  4283. 0,
  4284. (() => {
  4285. btnWrite.disabled = btnCopy.disabled = 'disabled';
  4286. let tipContainer = genericPopupQuerySelector('#user_data_export_tip');
  4287. let tipColor = tipContainer.style.color;
  4288. let tipString = tipContainer.innerText;
  4289. tipContainer.style.color = '#ff0000';
  4290. genericPopupQuerySelector('#user_data_persistence_string').select();
  4291. if (document.execCommand('copy')) {
  4292. tipContainer.innerText = '导出内容已复制到剪贴板';
  4293. }
  4294. else {
  4295. tipContainer.innerText = '复制失败,这可能是因为浏览器没有剪贴板访问权限,请进行手工复制(CTRL+A, CTRL+C)';
  4296. }
  4297. setTimeout((() => {
  4298. tipContainer.style.color = tipColor;
  4299. tipContainer.innerText = tipString;
  4300. btnWrite.disabled = 'disabled';
  4301. btnCopy.disabled = '';
  4302. }), 3000);
  4303. }),
  4304. true);
  4305. genericPopupAddCloseButton(80);
  4306.  
  4307. let userData = [];
  4308. g_userDataStorageKeyConfig.forEach((item) => {
  4309. let value = localStorage.getItem(item);
  4310. if (value != null) {
  4311. userData.push(`${item}${USER_STORAGE_KEY_VALUE_SEPARATOR}${value}`);
  4312. }
  4313. });
  4314. genericPopupQuerySelector('#user_data_persistence_string').value = userData.join(USER_DATA_xPORT_SEPARATOR);
  4315.  
  4316. genericPopupSetContentSize(400, 600, false);
  4317. genericPopupShowModal(true);
  4318. }
  4319.  
  4320. function clearUserData() {
  4321. if (confirm('这将清除所有用户配置(护符组定义、卡片装备光环护符绑定、沙滩装备筛选配置等等)和数据,要继续吗?')) {
  4322. g_userDataStorageKeyConfig.concat(g_userDataStorageKeyExtra).forEach((item) => {
  4323. localStorage.removeItem(item);
  4324. });
  4325. alert('用户配置和数据已全部清除!');
  4326. window.location.reload();
  4327. }
  4328. }
  4329.  
  4330. function onekeyOpenCard() {
  4331. readConfig();
  4332.  
  4333. let seq = g_configMap.get('openCardSequence')?.value;
  4334. if (!(seq?.length > 0)) {
  4335. return;
  4336. }
  4337.  
  4338. seq = seq.split(',');
  4339. let abs;
  4340. let inc = 0;
  4341. let exc = 0;
  4342. let rnd = [];
  4343. let dup = [];
  4344. let openSeq = [];
  4345. for (let e of seq) {
  4346. if ((e = e.trim()).length == 0 || e == '?') {
  4347. if (++inc > 9) {
  4348. alert('一键翻牌配置错误,请检查。');
  4349. return;
  4350. }
  4351. rnd.push(openSeq.length);
  4352. openSeq.push(0);
  4353. continue;
  4354. }
  4355. else if ((!/^(\+|-)?\d+$/.test(e) || (abs = Math.abs(e = parseInt(e))) < 1 || abs > 12 || dup[abs] != null) ||
  4356. (e < 0 && ++exc > 3) || (e > 0 && ++inc > 9)) {
  4357. alert('一键翻牌配置错误,请检查。');
  4358. return;
  4359. }
  4360. else if (e > 0) {
  4361. openSeq.push(e);
  4362. }
  4363. dup[abs] = true;
  4364. }
  4365. if (rnd.length > 0 || openSeq.length < 9) {
  4366. let outstanding = [];
  4367. for (let i = 1; i <= 12; i++) {
  4368. if (!dup[i]) {
  4369. outstanding.push(i);
  4370. }
  4371. }
  4372. for (let i = rnd.length - 1; i >= 0; i--) {
  4373. let ri = Math.trunc(Math.random() * outstanding.length);
  4374. openSeq[rnd[i]] = outstanding[ri];
  4375. outstanding.splice(ri, 1);
  4376. }
  4377. while (openSeq.length < 9) {
  4378. let ri = Math.trunc(Math.random() * outstanding.length);
  4379. openSeq.push(outstanding[ri]);
  4380. outstanding.splice(ri, 1);
  4381. }
  4382. }
  4383.  
  4384. const openCardRequest = g_httpRequestMap.get('giftop');
  4385. function beginOpenCard(sequence, fnPostProcess, fnParams) {
  4386. if (sequence?.length > 0) {
  4387. let id = sequence.shift();
  4388. genericPopupUpdateProgressMessage(g_roles[id - 1].name + '...');
  4389. httpRequestBegin(
  4390. openCardRequest.request,
  4391. openCardRequest.data.replace('"+id+"', id),
  4392. (response) => {
  4393. if (response.responseText?.length > 0) {
  4394. sequence = null;
  4395. addUserMessageSingle('一键翻牌', response.responseText);
  4396. }
  4397. beginOpenCard(sequence, fnPostProcess, fnParams);
  4398. });
  4399. }
  4400. else if (fnPostProcess != null) {
  4401. fnPostProcess(fnParams);
  4402. }
  4403. }
  4404.  
  4405. function closeProcess(fnPostProcess) {
  4406. let asyncObserver = new MutationObserver(() => {
  4407. asyncObserver.disconnect();
  4408. if (fnPostProcess != null) {
  4409. fnPostProcess();
  4410. }
  4411. });
  4412. asyncObserver.observe(document.getElementById('gifsall'), { childList : true , subtree : true });
  4413.  
  4414. // refresh card state
  4415. indre(10, 'gifsall');
  4416. }
  4417.  
  4418. genericPopupShowProgressMessage();
  4419. beginOpenCard(openSeq, closeProcess, genericPopupCloseProgressMessage);
  4420. }
  4421.  
  4422. function addForgeHistory(attrs) {
  4423. readConfig();
  4424.  
  4425. let maxList = (g_configMap.get('maxEquipForgeHistoryList')?.value ?? 0);
  4426. if (maxList <= 0) {
  4427. return;
  4428. }
  4429. let ts = getTimeStamp();
  4430. let lv = 1, name = '', quality = 0, eqLv;
  4431. let div = document.createElement('div');
  4432. attrs.forEach((p, i) => {
  4433. if (i == 1) {
  4434. let m = p.innerText.match(/\s*Lv\.(\d+)\s*-\s*(.+)/);
  4435. if (m?.length == 3) {
  4436. lv = m[1];
  4437. name = m[2].trim();
  4438. }
  4439. }
  4440. else if (i > 1) {
  4441. let m = p.innerText.match(/\s(\d+)\s*%\s/);
  4442. if (m?.length == 2) {
  4443. quality += parseInt(m[1]);
  4444. }
  4445. else if(p.innerText.startsWith('[神秘属性]')) {
  4446. quality += 100;
  4447. }
  4448. div.appendChild(p.cloneNode(true));
  4449. }
  4450. });
  4451. for (eqLv = g_equipmentLevelPoints.length - 1; eqLv > 0 && quality < g_equipmentLevelPoints[eqLv]; eqLv--);
  4452. let title =
  4453. `Lv.<span class="fyg_f18">${lv}<span style="font-size:15px;">(${quality}%)</span></span>
  4454. <span class="fyg_f18 pull-right"><i class="icon icon-star"></i> 0</span><br>${name}`;
  4455.  
  4456. let btn = document.createElement('button');
  4457. btn.className = `btn btn-light btn-equipment popover-${g_equipmentLevelStyleClass[eqLv]}`;
  4458. btn.style.minWidth = '240px';
  4459. btn.style.padding = '0px';
  4460. btn.style.marginRight = '5px';
  4461. btn.style.marginBottom = '5px';
  4462. btn.style.textAlign = 'left';
  4463. btn.style.boxShadow = 'none';
  4464. btn.style.lineHeight = '150%';
  4465. btn.innerHTML =
  4466. `<h3 class="popover-title" style="color:white;background-color:black;text-align:center;padding:3px;">${ts.date} ${ts.time}</h3>
  4467. <h3 class="popover-title bg-${g_equipmentLevelStyleClass[eqLv]}">${title}</h3>
  4468. <div class="popover-content-show" style="padding:10px 10px 0px 10px;">${div.innerHTML}</div>`;
  4469.  
  4470. let history = (localStorage.getItem(g_forgeHistoryStorageKey) ?? '');
  4471. div.innerHTML = history;
  4472. div.insertBefore(btn, div.firstElementChild);
  4473. while (div.children.length > maxList) {
  4474. div.lastElementChild.remove();
  4475. }
  4476. localStorage.setItem(g_forgeHistoryStorageKey, div.innerHTML);
  4477. }
  4478.  
  4479. function showForgeHistory() {
  4480. readConfig();
  4481.  
  4482. let maxList = (g_configMap.get('maxEquipForgeHistoryList')?.value ?? 0);
  4483. let history = (localStorage.getItem(g_forgeHistoryStorageKey) ?? '');
  4484. let div = document.createElement('div');
  4485. div.style.padding = '10px';
  4486. div.style.backgroundColor = '#ddf4df';
  4487. div.innerHTML = history;
  4488. while (div.children.length > maxList) {
  4489. div.lastElementChild.remove();
  4490. }
  4491. localStorage.setItem(g_forgeHistoryStorageKey, div.innerHTML);
  4492.  
  4493. let fixedContent =
  4494. '<div style="padding:20px 10px 10px 0px;color:blue;font-size:15px;"><b><ul>' +
  4495. '<li>历史记录仅包含在本机上使用本浏览器本帐号以常规方式(即:使用“锻造指定绿色以上装备”按钮)锻造的装备</li>' +
  4496. '<li>如果您使用多种锻造方式(包括但不限于常规、插件脚本、不同设备、不同浏览器等),此列表参考价值极为有限</li>' +
  4497. '<li>日期信息取自您锻造时的本机时间,如果您的本机时间不准确则装备锻造时间亦不准确</li></ul></b></div>';
  4498. const mainContent = `<div class="${g_genericPopupTopLineDivClass}" id="historyDiv"></div>`;
  4499.  
  4500. genericPopupInitialize();
  4501. genericPopupSetFixedContent(fixedContent);
  4502. genericPopupSetContent('装备锻造历史记录', mainContent);
  4503.  
  4504. let historyDiv = genericPopupQuerySelector('#historyDiv');
  4505. historyDiv.appendChild(div);
  4506. fitMystSection(historyDiv);
  4507.  
  4508. genericPopupAddButton(
  4509. '清理记录',
  4510. 0,
  4511. (() => {
  4512. let keep = prompt('请输入欲保留的记录条目数(0 - 100)', maxList);
  4513. if (/^\s*\d+\s*$/.test(keep) && (keep = parseInt(keep)) >= 0) {
  4514. if (keep < div.children.length && confirm(`这将删除 ${div.children.length - keep} 条历史记录,继续吗?`)) {
  4515. while (div.children.length > keep) {
  4516. div.lastElementChild.remove();
  4517. }
  4518. localStorage.setItem(g_forgeHistoryStorageKey, div.innerHTML);
  4519. }
  4520. }
  4521. else if (keep != null) {
  4522. alert('非法的输入值,请检查后重新输入。');
  4523. }
  4524. }),
  4525. true);
  4526. genericPopupAddCloseButton(80);
  4527. genericPopupSetContentSize(Math.min(window.innerHeight - 300, Math.max(window.innerHeight - 300, 400)),
  4528. Math.min(840, Math.max(window.innerWidth - 200, 600)),
  4529. true);
  4530. genericPopupShowModal(true);
  4531.  
  4532. function fitMystSection(container) {
  4533. $(`#${container.id} .btn-equipment .bg-danger.with-padding`).css({
  4534. 'max-width': '220px',
  4535. 'padding': '5px 5px 5px 5px',
  4536. 'white-space': 'pre-line',
  4537. 'word-break': 'break-all'
  4538. });
  4539. }
  4540. }
  4541.  
  4542. (new MutationObserver((mList) => {
  4543. if (mList?.[0]?.target?.style.display != 'none' &&
  4544. mList?.[0]?.target?.innerHTML?.indexOf('锻造出了新装备') >= 0) {
  4545.  
  4546. let eq = mList?.[0]?.target?.querySelectorAll('p');
  4547. if (eq?.length > 5) {
  4548. addForgeHistory(eq);
  4549. }
  4550. }
  4551. })).observe(document.getElementById('mymessage'), { subtree : true, childList : true });
  4552.  
  4553. let timer = setInterval(() => {
  4554. let panels = document.querySelectorAll('div.col-md-3 > div.panel > div.panel-body');
  4555. if (panels?.length >= 2) {
  4556. clearInterval(timer);
  4557. genericPopupInitialize();
  4558.  
  4559. let panel = panels[1];
  4560. let userData = loadUserConfigData();
  4561. let dataIndex = userData.dataIndex;
  4562.  
  4563. for (var px = panel.firstElementChild; px != null && !px.innerText.startsWith('对玩家战斗'); px = px.nextElementSibling);
  4564. if (px != null) {
  4565. let p0 = px.cloneNode(true);
  4566. let sp = p0.firstElementChild;
  4567. p0.firstChild.textContent = '对玩家战斗(上次查看)';
  4568.  
  4569. dataIndex.battleInfoNow = px.firstElementChild.innerText;
  4570. if (dataIndex.battleInfoNow == dataIndex.battleInfoBefore) {
  4571. sp.innerText = dataIndex.battleInfoBack;
  4572. }
  4573. else {
  4574. sp.innerText = dataIndex.battleInfoBefore;
  4575. dataIndex.battleInfoBack = dataIndex.battleInfoBefore;
  4576. dataIndex.battleInfoBefore = dataIndex.battleInfoNow
  4577. saveUserConfigData(userData);
  4578. }
  4579. px.parentNode.insertBefore(p0, px.nextElementSibling);
  4580. }
  4581. else {
  4582. px = panel.firstElementChild;
  4583. }
  4584.  
  4585. let globalDataBtnContainer = document.createElement('div');
  4586. globalDataBtnContainer.style.borderTop = '1px solid #d0d0d0';
  4587. globalDataBtnContainer.style.padding = '10px 0px 0px';
  4588.  
  4589. let versionLabel = px.cloneNode(true);
  4590. let versionText = versionLabel.firstElementChild;
  4591. versionLabel.firstChild.textContent = '插件版本:';
  4592. versionText.innerHTML = `<i class="icon icon-info-sign" data-toggle="tooltip" data-placement="left"
  4593. data-original-title="${g_modiTime}"> ${g_version}</i>`;
  4594. globalDataBtnContainer.appendChild(versionLabel);
  4595.  
  4596. let configBtn = document.createElement('button');
  4597. configBtn.innerHTML = '设置';
  4598. configBtn.style.height = '30px';
  4599. configBtn.style.width = '100%';
  4600. configBtn.style.marginBottom = '1px';
  4601. configBtn.onclick = (() => { modifyConfig(); });
  4602. globalDataBtnContainer.appendChild(configBtn);
  4603.  
  4604. let importBtn = configBtn.cloneNode(true);
  4605. importBtn.innerHTML = '导入用户配置数据';
  4606. importBtn.onclick = (() => { importUserConfigData(); });
  4607. globalDataBtnContainer.appendChild(importBtn);
  4608.  
  4609. let exportBtn = configBtn.cloneNode(true);
  4610. exportBtn.innerHTML = '导出用户配置数据';
  4611. exportBtn.onclick = (() => { exportUserConfigData(); });
  4612. globalDataBtnContainer.appendChild(exportBtn);
  4613.  
  4614. let eraseBtn = configBtn.cloneNode(true);
  4615. eraseBtn.innerHTML = '清除用户数据';
  4616. eraseBtn.onclick = (() => { clearUserData(); });
  4617. globalDataBtnContainer.appendChild(eraseBtn);
  4618. px.parentNode.appendChild(globalDataBtnContainer);
  4619.  
  4620. if (g_configMap.get('openCardSequence')?.value?.trim().length > 0) {
  4621. let openCardBtnContainer = document.createElement('div')
  4622. openCardBtnContainer.style.textAlign = 'right';
  4623. openCardBtnContainer.innerHTML =
  4624. '<span style="color:blue;font-size:16px;">★ 如果您选择使用一键翻牌功能,表明您完全接受最终结果,否则请选择手动翻牌</span>';
  4625.  
  4626. let openCardConfigBtn = document.createElement('button');
  4627. openCardConfigBtn.className = 'btn btn-lg';
  4628. openCardConfigBtn.innerHTML = '一键翻牌设置';
  4629. openCardConfigBtn.style.marginLeft = '15px';
  4630. openCardConfigBtn.style.marginRight = '3px';
  4631. openCardConfigBtn.onclick = (() => { modifyConfig(['openCardSequence'], '一键翻牌设置'); });
  4632. openCardBtnContainer.appendChild(openCardConfigBtn);
  4633.  
  4634. let openCardBtn = document.createElement('button');
  4635. openCardBtn.className = 'btn btn-lg';
  4636. openCardBtn.innerHTML = '一键翻牌';
  4637. openCardBtn.onclick = (() => { onekeyOpenCard(); });
  4638. openCardBtnContainer.appendChild(openCardBtn);
  4639. let cardDiv = document.querySelector('#gifsall');
  4640. cardDiv.parentNode.insertBefore(openCardBtnContainer, cardDiv.nextSibling.nextSibling);
  4641. }
  4642.  
  4643. let btns = document.querySelectorAll('button.btn.btn-lg');
  4644. for (let btn of btns) {
  4645. if (btn.innerText.indexOf('锻造') >= 0) {
  4646. let forgeHistoryBtn = document.createElement('button');
  4647. forgeHistoryBtn.className = 'btn btn-lg';
  4648. forgeHistoryBtn.innerHTML = '查看锻造历史记录';
  4649. forgeHistoryBtn.style.width = getComputedStyle(btn).getPropertyValue('width');
  4650. forgeHistoryBtn.style.marginTop = '1px';
  4651. forgeHistoryBtn.onclick = (() => { showForgeHistory(); });
  4652. btn.parentNode.appendChild(forgeHistoryBtn);
  4653. break;
  4654. }
  4655. }
  4656.  
  4657. $('[data-toggle="tooltip"]').tooltip();
  4658. }
  4659. }, 200);
  4660. }
  4661. else if (window.location.pathname == g_guguzhenEquip) {
  4662. genericPopupInitialize();
  4663.  
  4664. let timer = setInterval(() => {
  4665. let cardingDiv = document.getElementById('carding');
  4666. let backpacksDiv = document.getElementById('backpacks');
  4667. if (cardingDiv?.firstElementChild != null && backpacksDiv?.firstElementChild != null) {
  4668. clearInterval(timer);
  4669. loadTheme();
  4670.  
  4671. let panel = document.getElementsByClassName('panel panel-primary')[1];
  4672. let calcBtn = document.createElement('button');
  4673. let calcDiv = document.createElement('div');
  4674.  
  4675. calcBtn.innerText = '导出计算器';
  4676. calcBtn.style.marginLeft = '3px';
  4677. calcBtn.disabled = 'disabled';
  4678. calcBtn.onclick = (() => {});
  4679.  
  4680. panel.insertBefore(calcBtn, panel.children[0]);
  4681. panel.insertBefore(calcDiv, calcBtn);
  4682.  
  4683. const bagQueryString = 'div.alert-danger';
  4684. const storeQueryString = 'div.alert-success';
  4685. const cardingObjectsQueryString = 'div.row > div.fyg_tc > button.btn.fyg_mp3';
  4686. const bagObjectsQueryString = 'div.alert-danger > button.btn.fyg_mp3';
  4687. const storeObjectsQueryString = 'div.alert-success > button.btn.fyg_mp3';
  4688. const storeButtonId = 'collapse-backpacks-store';
  4689.  
  4690. let equipmentDiv = document.createElement('div');
  4691. equipmentDiv.id = 'equipmentDiv';
  4692. equipmentDiv.style.width = '100%';
  4693. equipmentDiv.innerHTML =
  4694. `<p class="alert alert-danger" id="equip-ctrl-container" style="text-align:right;">
  4695. <input type="checkbox" id="equipment_StoreExpand" style="margin-right:5px;" />
  4696. <label for="equipment_StoreExpand" style="margin-right:15px;cursor:pointer;">仅显示饰品栏和仓库</label>
  4697. <input type="checkbox" id="equipment_Expand" style="margin-right:5px;" />
  4698. <label for="equipment_Expand" style="margin-right:15px;cursor:pointer;">全部展开</label>
  4699. <input type="checkbox" id="equipment_BG" style="margin-right:5px;" />
  4700. <label for="equipment_BG" style="margin-right:15px;cursor:pointer;">使用深色背景</label>
  4701. <button type="button" id="objects_Cleanup">清理库存</button></p>
  4702. <div id="equipment_ObjectContainer" style="display:block;height:0px;">
  4703. <p><button type="button" class="btn btn-block collapsed" data-toggle="collapse" data-target="#eq5">道具 ▼</button></p>
  4704. <div class="in" id="eq5"></div>
  4705. <p><button type="button" class="btn btn-block collapsed" data-toggle="collapse" data-target="#eq4">护符 ▼</button></p>
  4706. <div class="in" id="eq4"></div>
  4707. <p><button type="button" class="btn btn-block collapsed" data-toggle="collapse" data-target="#eq0">武器装备 ▼</button></p>
  4708. <div class="in" id="eq0"></div>
  4709. <p><button type="button" class="btn btn-block collapsed" data-toggle="collapse" data-target="#eq1">手臂装备 ▼</button></p>
  4710. <div class="in" id="eq1"></div>
  4711. <p><button type="button" class="btn btn-block collapsed" data-toggle="collapse" data-target="#eq2">身体装备 ▼</button></p>
  4712. <div class="in" id="eq2"></div>
  4713. <p><button type="button" class="btn btn-block collapsed" data-toggle="collapse" data-target="#eq3">头部装备 ▼</button></p>
  4714. <div class="in" id="eq3"></div>
  4715. <p><button type="button" class="btn btn-block collapsed" id="${storeButtonId}">仓库 ▼</button></p></div>`;
  4716.  
  4717. function refreshEquipmentPage(fnPostProcess) {
  4718. let asyncOperations = 2;
  4719. let asyncObserver = new MutationObserver(() => {
  4720. if (--asyncOperations == 0) {
  4721. asyncObserver.disconnect();
  4722. if (fnPostProcess != null) {
  4723. fnPostProcess();
  4724. }
  4725. }
  4726. });
  4727. asyncObserver.observe(backpacksDiv, { childList : true , subtree : true });
  4728.  
  4729. // refresh #carding & #backpacks
  4730. cding();
  4731. eqbp(1);
  4732. }
  4733.  
  4734. equipmentDiv.querySelector('#objects_Cleanup').onclick = objectsCleanup;
  4735. function objectsCleanup() {
  4736. genericPopupInitialize();
  4737.  
  4738. let cancelled = false;
  4739. function cancelProcess() {
  4740. if (timer != null) {
  4741. clearInterval(timer);
  4742. timer = null;
  4743. }
  4744. if (!cancelled) {
  4745. cancelled = true;
  4746. httpRequestAbortAll();
  4747. refreshEquipmentPage(() => { genericPopupClose(true); });
  4748. }
  4749. }
  4750.  
  4751. let timer = null;
  4752. function postProcess(closeCountDown) {
  4753. if (closeCountDown > 0) {
  4754. genericPopupOnClickOutside(cancelProcess);
  4755. timer = setInterval(() => {
  4756. if (cancelled || --closeCountDown == 0) {
  4757. cancelProcess();
  4758. }
  4759. else {
  4760. genericPopupShowInformationTips(`所有操作已完成,窗口将在 ${closeCountDown} 秒后关闭`, 0);
  4761. }
  4762. }, 1000);
  4763. }
  4764. else {
  4765. cancelProcess();
  4766. }
  4767. }
  4768.  
  4769. let bagObjects = backpacksDiv.querySelectorAll(bagObjectsQueryString);
  4770. let storeObjects = backpacksDiv.querySelectorAll(storeObjectsQueryString);
  4771. function refreshContainer(fnPostProcess) {
  4772. function queryObjects() {
  4773. bagObjects = backpacksDiv.querySelectorAll(bagObjectsQueryString);
  4774. storeObjects = backpacksDiv.querySelectorAll(storeObjectsQueryString);
  4775. if (fnPostProcess != null) {
  4776. fnPostProcess();
  4777. }
  4778. }
  4779.  
  4780. refreshEquipmentPage(queryObjects);
  4781. }
  4782.  
  4783. function processEquips() {
  4784. let equips = [];
  4785. genericPopupQuerySelectorAll('table.equip-list input.equip-checkbox.equip-item').forEach((e) => {
  4786. if (e.checked) {
  4787. equips.push(e.getAttribute('original-item').split(','));
  4788. }
  4789. });
  4790.  
  4791. if (equips.length > 0) {
  4792. genericPopupShowInformationTips(`丢弃装备...(${equips.length})`, 0);
  4793. let ids = findEquipmentIds(storeObjects, equips);
  4794. if (ids.length > 0) {
  4795. beginMoveObjects(ids, ObjectMovePath.store2beach, refreshContainer, processAmulets);
  4796. return;
  4797. }
  4798. else {
  4799. alert('有装备不存在,请在清理结束后检查!');
  4800. console.log(equips);
  4801. }
  4802. }
  4803. processAmulets();
  4804. }
  4805.  
  4806. function processAmulets() {
  4807. let amulets = [];
  4808. let groupItem = 0;
  4809. genericPopupQuerySelectorAll('table.amulet-list input.equip-checkbox.amulet-item').forEach((e) => {
  4810. if (e.checked) {
  4811. if (e.hasAttribute('group-item')) {
  4812. groupItem++;
  4813. }
  4814. amulets.push((new Amulet()).fromBuffText(e.getAttribute('original-item')));
  4815. }
  4816. });
  4817. if (!(groupItem == 0 || confirm(`选中的护符中有 ${groupItem} 个可能已加入护符组,继续销毁吗?`))) {
  4818. cancelProcess();
  4819. return;
  4820. }
  4821.  
  4822. let bag = 0;
  4823. pirlAmulets();
  4824.  
  4825. function pirlAmulets() {
  4826. if (amulets.length > 0) {
  4827. genericPopupShowInformationTips(`转换果核...(${amulets.length})`, 0);
  4828. if ((bag & 1) == 0) {
  4829. bag++;
  4830. let ids = findAmuletIds(storeObjects, amulets);
  4831. if (ids.length > 0) {
  4832. beginPirlObjects(true, ids, refreshContainer, pirlAmulets);
  4833. return;
  4834. }
  4835. }
  4836. if (bag == 1) {
  4837. bag++;
  4838. let ids = findAmuletIds(bagObjects, amulets.slice());
  4839. if (ids.length > 0) {
  4840. let emptyCells = parseInt(backpacksDiv.querySelector(storeQueryString + ' > p.fyg_lh40.fyg_tc.text-gray')
  4841. ?.innerText?.match(/\d+/)[0]);
  4842. if (emptyCells >= ids.length) {
  4843. beginMoveObjects(ids, ObjectMovePath.bag2store, refreshContainer, pirlAmulets);
  4844. }
  4845. else {
  4846. alert('仓库空间不足,清理无法继续,请检查!');
  4847. cancelProcess();
  4848. }
  4849. return;
  4850. }
  4851. else {
  4852. alert('有护符不存在,请在清理结束后检查!');
  4853. console.log(amulets);
  4854. }
  4855. }
  4856. else {
  4857. alert('有护符不存在,请在清理结束后检查!');
  4858. console.log(amulets);
  4859. }
  4860. }
  4861. postProcess(15);
  4862. }
  4863. }
  4864.  
  4865. let fixedContent =
  4866. '<div style="padding:20px 10px 10px 0px;color:blue;font-size:16px;"><b><ul>' +
  4867. '<li>护符表中被选中的护符会被销毁并转换为果核,此操作不可逆,请谨慎使用</li>' +
  4868. '<li>如果饰品栏有您欲销毁的护符,请确保仓库中届时有足够的空间容纳它们(饰品栏护符会在最后一个步骤销毁)</li>' +
  4869. '<li>装备表中被选中的装备会被丢弃,丢弃后的装备将出现在沙滩上,并在24小时后消失,在它消失前您可随时捡回</li>' +
  4870. '<li>正在使用的装备不会出现在装备表中,如果您想要丢弃正在使用的装备,请首先将它替换下来</li>' +
  4871. `<li id="${g_genericPopupInformationTipsId}" style="color:red;">` +
  4872. `<input type="checkbox" id="disclaimer-check" />` +
  4873. `<label for="disclaimer-check" style="margin-left:5px;cursor:pointer;">` +
  4874. `本人已仔细阅读并完全理解以上全部注意事项,愿意独立承担所有因此操作而引起的一切后果及损失</label></li></ul></b></div>`;
  4875. const mainStyle =
  4876. '<style> .group-menu { position:relative;' +
  4877. 'display:inline-block;' +
  4878. 'color:blue;' +
  4879. 'font-size:20px;' +
  4880. 'cursor:pointer; } ' +
  4881. '.group-menu-items { display:none;' +
  4882. 'position:absolute;' +
  4883. 'font-size:15px;' +
  4884. 'word-break:keep-all;' +
  4885. 'white-space:nowrap;' +
  4886. 'margin:0 auto;' +
  4887. 'width:fit-content;' +
  4888. 'z-index:999;' +
  4889. 'background-color:white;' +
  4890. 'box-shadow:0px 2px 16px 4px rgba(0, 0, 0, 0.4);' +
  4891. 'padding:15px 30px; } '+
  4892. '.group-menu-item { } ' +
  4893. '.group-menu:hover .group-menu-items { display:block; } ' +
  4894. '.group-menu-items .group-menu-item:hover { background-color:#bbddff; } ' +
  4895. 'b > span { color:purple; } ' +
  4896. 'button.btn-group-selection { width:80px; float:right; } ' +
  4897. 'table.amulet-list { width:100%; } ' +
  4898. 'table.amulet-list th.object-name { width:20%; text-align:left; } ' +
  4899. 'table.amulet-list th.object-property { width:80%; text-align:left; } ' +
  4900. 'table.equip-list { width:100%; } ' +
  4901. 'table.equip-list th.object-name { width:44%; text-align:left; } ' +
  4902. 'table.equip-list th.object-property { width:14%; text-align:left; } ' +
  4903. 'table tr.alt { background-color:' + g_genericPopupBackgroundColorAlt + '; } ' +
  4904. '</style>';
  4905. const menuItems =
  4906. '<div class="group-menu-items"><ul>' +
  4907. '<li class="group-menu-item"><a href="#amulets-div">护符</a></li>' +
  4908. '<li class="group-menu-item"><a href="#equips1-div">武器装备</a></li>' +
  4909. '<li class="group-menu-item"><a href="#equips2-div">手臂装备</a></li>' +
  4910. '<li class="group-menu-item"><a href="#equips3-div">身体装备</a></li>' +
  4911. '<li class="group-menu-item"><a href="#equips4-div">头部装备</a></li>' +
  4912. '</ul></div>';
  4913. const amuletTable =
  4914. '<table class="amulet-list"><tr class="alt"><th class="object-name">护符</th>' +
  4915. '<th class="object-property">属性</th></tr></table>';
  4916. const equipTable =
  4917. '<table class="equip-list"><tr class="alt"><th class="object-name">装备</th><th class="object-property">属性</th>' +
  4918. '<th class="object-property"></th><th class="object-property"></th><th class="object-property"></th></tr></table>';
  4919. const btnGroup =
  4920. '<button type="button" class="btn-group-selection" select-type="2">反选</button>' +
  4921. '<button type="button" class="btn-group-selection" select-type="1">全不选</button>' +
  4922. '<button type="button" class="btn-group-selection" select-type="0">全选</button>';
  4923. const mainContent =
  4924. `${mainStyle}
  4925. <div class="${g_genericPopupTopLineDivClass}" id="amulets-div">
  4926. <b class="group-menu">护符 (选中 <span>0</span>)(★:已加入护符组) ▼${menuItems}</b>${btnGroup}<p />${amuletTable}</div>
  4927. <div class="${g_genericPopupTopLineDivClass}" id="equips1-div">
  4928. <b class="group-menu">武器装备 (选中 <span>0</span>) ▼${menuItems}</b>${btnGroup}<p />${equipTable}</div>
  4929. <div class="${g_genericPopupTopLineDivClass}" id="equips2-div">
  4930. <b class="group-menu">手臂装备 (选中 <span>0</span>) ▼${menuItems}</b>${btnGroup}<p />${equipTable}</div>
  4931. <div class="${g_genericPopupTopLineDivClass}" id="equips3-div">
  4932. <b class="group-menu">身体装备 (选中 <span>0</span>) ▼${menuItems}</b>${btnGroup}<p />${equipTable}</div>
  4933. <div class="${g_genericPopupTopLineDivClass}" id="equips4-div">
  4934. <b class="group-menu">头部装备 (选中 <span>0</span>) ▼${menuItems}</b>${btnGroup}<p />${equipTable}</div>`;
  4935.  
  4936. genericPopupSetFixedContent(fixedContent);
  4937. genericPopupSetContent('清理库存', mainContent);
  4938.  
  4939. genericPopupQuerySelectorAll('button.btn-group-selection').forEach((btn) => { btn.onclick = batchSelection; });
  4940. function batchSelection(e) {
  4941. let selType = parseInt(e.target.getAttribute('select-type'));
  4942. let selCount = 0;
  4943. e.target.parentNode.querySelectorAll('input.equip-checkbox').forEach((chk) => {
  4944. if (chk.checked = (selType == 2 ? !chk.checked : selType == 0)) {
  4945. selCount++;
  4946. }
  4947. });
  4948. e.target.parentNode.firstElementChild.firstElementChild.innerText = selCount;
  4949. }
  4950.  
  4951. const objectTypeColor = [ '#e0fff0', '#ffe0ff', '#fff0e0', '#d0f0ff' ];
  4952. let bagAmulets = amuletNodesToArray(backpacksDiv.querySelectorAll(bagObjectsQueryString));
  4953. let groupAmulets = [];
  4954. amuletLoadGroups().toArray().forEach((group) => { groupAmulets.push(group.items); });
  4955. groupAmulets = groupAmulets.flat().sort((a , b) => a.compareMatch(b));
  4956. let amulet_selector = genericPopupQuerySelector('table.amulet-list');
  4957. let storeAmulets = amuletNodesToArray(backpacksDiv.querySelectorAll(storeObjectsQueryString));
  4958. storeAmulets.concat(bagAmulets).sort((a , b) => a.compareTo(b)).forEach((item) => {
  4959. let gi = searchElement(groupAmulets, item, (a , b) => a.compareMatch(b));
  4960. if (gi >= 0) {
  4961. groupAmulets.splice(gi, 1);
  4962. }
  4963. let tr = document.createElement('tr');
  4964. tr.style.color = (gi >= 0 ? 'blue' : '');
  4965. tr.style.backgroundColor = objectTypeColor[item.type];
  4966. tr.innerHTML =
  4967. `<td><input type="checkbox" class="equip-checkbox amulet-item" id="amulet-${item.id}"
  4968. original-item="${item.formatBuffText()}"${gi >= 0 ? ' group-item' : ''} />
  4969. <label for="amulet-${item.id}" style="margin-left:5px;cursor:pointer;">
  4970. ${gi >= 0 ? '★ ' : ''}${item.formatName()}</label></td>
  4971. <td>${item.formatBuff()}</td>`;
  4972. amulet_selector.appendChild(tr);
  4973. });
  4974.  
  4975. let eqIndex = 0;
  4976. let eq_selectors = genericPopupQuerySelectorAll('table.equip-list');
  4977. let storeEquips = equipmentNodesToInfoArray(backpacksDiv.querySelectorAll(storeObjectsQueryString));
  4978. storeEquips.sort((e1, e2) => {
  4979. if (e1[0] != e2[0]) {
  4980. return (g_equipMap.get(e1[0]).index - g_equipMap.get(e2[0]).index);
  4981. }
  4982. return -equipmentInfoComparer(e1, e2);
  4983. }).forEach((item) => {
  4984. let eqMeta = g_equipMap.get(item[0]);
  4985. let lv = objectGetLevel(item);
  4986. let tr = document.createElement('tr');
  4987. tr.style.backgroundColor = g_equipmentLevelBGColor[lv];
  4988. tr.innerHTML =
  4989. `<td><input type="checkbox" class="equip-checkbox equip-item" id="equip-${++eqIndex}"
  4990. original-item="${item.join(',')}" />
  4991. <label for="equip-${eqIndex}" style="margin-left:5px;cursor:pointer;">` +
  4992. `${eqMeta.alias} - Lv.${item[1]} (攻.${item[2]} 防.${item[3]}) ` +
  4993. `${item[8] == 1 ? ' - [ 神秘 ]' : ''}</label></td>
  4994. <td>${formatEquipmentAttributes(item, '</td><td>')}</td>`;
  4995. eq_selectors[eqMeta.type].appendChild(tr);
  4996. });
  4997.  
  4998. genericPopupQuerySelectorAll('input.equip-checkbox').forEach((e) => { e.onchange = equipCheckboxStateChange; });
  4999. function equipCheckboxStateChange(e) {
  5000. let countSpan = e.target.parentNode.parentNode.parentNode.parentNode.firstElementChild.firstElementChild;
  5001. countSpan.innerText = parseInt(countSpan.innerText) + (e.target.checked ? 1 : -1);
  5002. }
  5003.  
  5004. let btnGo = genericPopupAddButton('开始', 80, (() => {
  5005. genericPopupOnClickOutside(null);
  5006. operationEnabler(false);
  5007. genericPopupQuerySelector('#disclaimer-check').disabled = 'disabled';
  5008. processEquips();
  5009. }), false);
  5010. let btnCancel = genericPopupAddButton('取消', 80, () => {
  5011. operationEnabler(false);
  5012. btnCancel.disabled = 'disabled';
  5013. cancelProcess();
  5014. }, false);
  5015.  
  5016. function operationEnabler(enabled) {
  5017. let v = enabled ? '' : 'disabled';
  5018. genericPopupQuerySelectorAll('button.btn-group-selection').forEach((e) => { e.disabled = v; });
  5019. genericPopupQuerySelectorAll('input.equip-checkbox').forEach((e) => { e.disabled = v; });
  5020. btnGo.disabled = v;
  5021. }
  5022. operationEnabler(false);
  5023. genericPopupQuerySelector('#disclaimer-check').onchange = ((e) => { operationEnabler(e.target.checked); });
  5024.  
  5025. let objectsCount = bagAmulets.length + storeEquips.length + storeAmulets.length;
  5026. genericPopupSetContentSize(Math.min((objectsCount * 31) + (6 * 104), Math.max(window.innerHeight - 400, 400)),
  5027. Math.min(1000, Math.max(window.innerWidth - 200, 600)),
  5028. true);
  5029. genericPopupShowModal(true);
  5030. }
  5031.  
  5032. ////////////////////////////////////////////////////////////////////////////////
  5033. //
  5034. // collapse container
  5035. //
  5036. ////////////////////////////////////////////////////////////////////////////////
  5037.  
  5038. let forceEquipDivOperation = true;
  5039. let equipDivExpanded = {};
  5040.  
  5041. equipmentDiv.querySelectorAll('button.btn.btn-block.collapsed').forEach((btn) => { btn.onclick = backupEquipmentDivState; });
  5042. function backupEquipmentDivState(e) {
  5043. let targetDiv = equipmentDiv.querySelector(e.target.getAttribute('data-target'));
  5044. if (targetDiv != null) {
  5045. equipDivExpanded[targetDiv.id] = !equipDivExpanded[targetDiv.id];
  5046. }
  5047. else {
  5048. equipDivExpanded[e.target.id] = !equipDivExpanded[e.target.id];
  5049. }
  5050. };
  5051.  
  5052. function collapseEquipmentDiv(expand, force) {
  5053. let targetDiv;
  5054. equipmentDiv.querySelectorAll('button.btn.btn-block').forEach((btn) => {
  5055. if (btn.getAttribute('data-toggle') == 'collapse' &&
  5056. (targetDiv = equipmentDiv.querySelector(btn.getAttribute('data-target'))) != null) {
  5057.  
  5058. let exp = expand;
  5059. if (equipDivExpanded[targetDiv.id] == null || force) {
  5060. equipDivExpanded[targetDiv.id] = exp;
  5061. }
  5062. else {
  5063. exp = equipDivExpanded[targetDiv.id];
  5064. }
  5065.  
  5066. targetDiv.className = (exp ? 'in' : 'collapse');
  5067. targetDiv.style.height = (exp ? 'auto' : '0px');
  5068. }
  5069. });
  5070. if (equipDivExpanded[storeButtonId] == null || force) {
  5071. equipDivExpanded[storeButtonId] = expand;
  5072. }
  5073. if (equipDivExpanded[storeButtonId]) {
  5074. $('#backpacks > ' + storeQueryString).show();
  5075. }
  5076. else {
  5077. $('#backpacks > ' + storeQueryString).hide();
  5078. }
  5079. }
  5080.  
  5081. let objectContainer = equipmentDiv.querySelector('#equipment_ObjectContainer');
  5082. function switchObjectContainerStatus(show) {
  5083. if (show) {
  5084. objectContainer.style.display = 'block';
  5085. objectContainer.style.height = 'auto';
  5086. if (equipDivExpanded[storeButtonId]) {
  5087. $('#backpacks > ' + storeQueryString).show();
  5088. }
  5089. else {
  5090. $('#backpacks > ' + storeQueryString).hide();
  5091. }
  5092. }
  5093. else {
  5094. objectContainer.style.height = '0px';
  5095. objectContainer.style.display = 'none';
  5096. $('#backpacks > ' + storeQueryString).show();
  5097. }
  5098.  
  5099. equipmentDiv.querySelector('#equipment_Expand').disabled =
  5100. equipmentDiv.querySelector('#equipment_BG').disabled = (show ? '' : 'disabled');
  5101. }
  5102.  
  5103. function changeEquipmentDivStyle(bg) {
  5104. $('#equipmentDiv .backpackDiv').css({
  5105. 'background-color': bg ? 'black' : '#ffe5e0'
  5106. });
  5107. $('#equipmentDiv .storeDiv').css({
  5108. 'background-color': bg ? 'black' : '#ddf4df'
  5109. });
  5110. $('#equipmentDiv .btn-light').css({
  5111. 'background-color': bg ? 'black' : 'white'
  5112. });
  5113. $('#equipmentDiv .popover-content-show').css({
  5114. 'background-color': bg ? 'black' : 'white',
  5115. 'color': bg ? 'white' : 'black'
  5116. });
  5117. $('#equipmentDiv .popover-title').css({
  5118. 'color': bg ? 'black' : 'white'
  5119. });
  5120. $('#equipmentDiv .bg-special').css({
  5121. 'background-color': bg ? 'black' : '#8666b8',
  5122. 'color': bg ? '#c0c0c0' : 'white',
  5123. 'border-bottom': bg ? '1px solid grey' : 'none'
  5124. });
  5125. $('#equipmentDiv .btn-equipment .pull-right').css({
  5126. 'color': bg ? 'black' : 'white'
  5127. });
  5128. $('#equipmentDiv .btn-equipment .bg-danger.with-padding').css({
  5129. 'color': bg ? 'black' : 'white'
  5130. });
  5131. }
  5132.  
  5133. let equipmentStoreExpand = setupConfigCheckbox(
  5134. equipmentDiv.querySelector('#equipment_StoreExpand'),
  5135. g_equipmentStoreExpandStorageKey,
  5136. (checked) => { switchObjectContainerStatus(!(equipmentStoreExpand = checked)); },
  5137. null);
  5138. let equipmentExpand = setupConfigCheckbox(
  5139. equipmentDiv.querySelector('#equipment_Expand'),
  5140. g_equipmentExpandStorageKey,
  5141. (checked) => { collapseEquipmentDiv(equipmentExpand = checked, true); },
  5142. null);
  5143. let equipmentBG = setupConfigCheckbox(
  5144. equipmentDiv.querySelector('#equipment_BG'),
  5145. g_equipmentBGStorageKey,
  5146. (checked) => { changeEquipmentDivStyle(equipmentBG = checked); },
  5147. null);
  5148.  
  5149. let wishpool = [];
  5150. let userInfo = [];
  5151. function restructEquipUI(fnPostProcess, fnParams) {
  5152. let asyncOperations = 2;
  5153. if (wishpool.length == 0) {
  5154. beginReadWishpool(wishpool, null, () => { asyncOperations--; });
  5155. }
  5156. else {
  5157. asyncOperations--;
  5158. }
  5159. if (userInfo.length == 0) {
  5160. beginReadUserInfo(userInfo, () => { asyncOperations--; });
  5161. }
  5162. else {
  5163. asyncOperations--;
  5164. }
  5165. let timer = setInterval(() => {
  5166. if (asyncOperations == 0) {
  5167. clearInterval(timer);
  5168. addCollapse(fnPostProcess, fnParams);
  5169. }
  5170. }, 200);
  5171. }
  5172.  
  5173. function addCollapse(fnPostProcess, fnParams) {
  5174. let waitForBtn = setInterval(() => {
  5175. if (cardingDiv?.firstElementChild != null && backpacksDiv?.firstElementChild != null) {
  5176. let eqbtns = cardingDiv.querySelectorAll(cardingObjectsQueryString);
  5177. let eqstore = backpacksDiv.querySelectorAll(storeObjectsQueryString);
  5178. if (eqbtns?.length > 0 || eqstore?.length > 0) {
  5179. clearInterval(waitForBtn);
  5180.  
  5181. eqstore.forEach((item) => { item.dataset.instore = 1; });
  5182. eqbtns =
  5183. Array.from(eqbtns).concat(
  5184. Array.from(backpacksDiv.querySelectorAll(bagObjectsQueryString))).concat(
  5185. Array.from(eqstore)).sort(objectNodeComparer);
  5186.  
  5187. if (!(document.getElementsByClassName('collapsed')?.length > 0)) {
  5188. backpacksDiv.insertBefore(equipmentDiv, backpacksDiv.firstElementChild);
  5189. }
  5190. for (let i = eqbtns.length - 1; i >= 0; i--) {
  5191. if (objectIsEmptyNode(eqbtns[i]) || eqbtns[i].className?.indexOf('popover') >= 0) {
  5192. eqbtns.splice(i, 1);
  5193. }
  5194. }
  5195.  
  5196. let ineqBackpackDiv =
  5197. '<div class="backpackDiv" style="padding:10px;margin-bottom:10px;"></div>' +
  5198. '<div class="storeDiv" style="padding:10px;margin-bottom:10px;"></div>';
  5199. let eqDivs = [ equipmentDiv.querySelector('#eq0'),
  5200. equipmentDiv.querySelector('#eq1'),
  5201. equipmentDiv.querySelector('#eq2'),
  5202. equipmentDiv.querySelector('#eq3'),
  5203. equipmentDiv.querySelector('#eq4'),
  5204. equipmentDiv.querySelector('#eq5') ];
  5205. eqDivs.forEach((item) => { item.innerHTML = ineqBackpackDiv; });
  5206.  
  5207. const store = [ '', '【仓】'];
  5208. eqbtns.forEach((btn) => {
  5209. let tempEQThis=btn.style.backgroundImage;
  5210. let equipInfo = equipmentInfoParseNode(btn, true);
  5211. let amulet = (new Amulet()).fromNode(btn);
  5212. let propInfo = propertyInfoParseNode(btn);
  5213. if(equipInfo==null&&tempEQThis.indexOf('/z2')>-1){
  5214. let tempEQType,num1,num2,num3,num4,smcheck='0';
  5215. let numtemp = btn.getAttribute("data-content").match(/\d+(\.\d)?/g).map(o => +o);
  5216. let tempEqLv = btn.innerHTML.match(/\d+(\.\d)?/g).map(o => +o);
  5217. let eqid = btn.getAttribute("onclick").match(/\d+(\.\d)?/g).map(o => +o);
  5218. if(btn.getAttribute("data-content").indexOf('神秘')>-1){smcheck='1'};
  5219. if(tempEQThis.indexOf('/z21')>-1){tempEQType='NEWEQA'}
  5220. else if(tempEQThis.indexOf('/z22')>-1){tempEQType='NEWEQB'}
  5221. else if(tempEQThis.indexOf('/z23')>-1){tempEQType='NEWEQC'}
  5222. else if(tempEQThis.indexOf('/z24')>-1){tempEQType='NEWEQD'}
  5223. equipInfo=[tempEQType, tempEqLv[3].toString() , '0' , '0' ,numtemp[1].toString() , numtemp[3].toString() , numtemp[5].toString() , numtemp[7].toString() , smcheck, eqid[0].toString()];
  5224. };
  5225. let styleClass = g_equipmentLevelStyleClass[objectGetLevel(equipInfo ?? amulet ?? propInfo)];
  5226. let btn0 = document.createElement('button');
  5227. btn0.className = `btn btn-light popover-${styleClass}`;
  5228. btn0.style.minWidth = '200px';
  5229. btn0.style.marginRight = '5px';
  5230. btn0.style.marginBottom = '5px';
  5231. btn0.style.padding = '0px';
  5232. btn0.style.textAlign = 'left';
  5233. btn0.style.boxShadow = 'none';
  5234. btn0.style.lineHeight = '150%';
  5235. btn0.setAttribute('onclick', btn.getAttribute('onclick'));
  5236. let enhancements = (amulet != null ? ' +' + btn.innerText.trim() : '');
  5237. let storeText = store[btn.dataset.instore ?? 0];
  5238. btn0.innerHTML =
  5239. `<h3 class="popover-title bg-${styleClass}">${storeText}${btn.dataset.originalTitle}${enhancements}</h3>
  5240. <div class="popover-content-show" style="padding:10px 10px 0px 10px;">${btn.dataset.content}</div>`;
  5241.  
  5242. if (equipInfo != null && btn0.lastChild.lastChild?.nodeType != Node.ELEMENT_NODE) {
  5243. btn0.lastChild.lastChild?.remove();
  5244. }
  5245.  
  5246. let ineq;
  5247. if (amulet != null) {
  5248. ineq = 4;
  5249. }
  5250. else if (equipInfo != null) {
  5251. ineq = g_equipMap.get(equipInfo[0]).type;
  5252. btn0.style.minWidth = '240px';
  5253. btn0.className += ' btn-equipment';
  5254.  
  5255. // debug only
  5256. if (equipmentVerify(btn, equipInfo) != 0) {
  5257. btn.style.border = '3px solid #ff00ff';
  5258. btn0.style.border = '5px solid #ff00ff';
  5259. }
  5260. }
  5261. else {
  5262. ineq = 5;
  5263. btn0.lastChild.style.cssText =
  5264. 'max-width:180px;padding:10px;text-align:center;white-space:pre-line;word-break:break-all;';
  5265. }
  5266.  
  5267. (storeText == '' ? eqDivs[ineq].firstChild : eqDivs[ineq].firstChild.nextSibling).appendChild(btn0);
  5268. });
  5269.  
  5270. eqDivs.forEach((div) => {
  5271. for (let area of div.children) {
  5272. if (area.children.length == 0) {
  5273. area.style.display = 'none';
  5274. }
  5275. }
  5276. });
  5277.  
  5278. function inputAmuletGroupName(defaultGroupName) {
  5279. let groupName = prompt('请输入护符组名称(不超过31个字符,请仅使用大、小写英文字母、数字、连字符、下划线及中文字符)',
  5280. defaultGroupName);
  5281. if (amuletIsValidGroupName(groupName)) {
  5282. return groupName;
  5283. }
  5284. else if (groupName != null) {
  5285. alert('名称不符合命名规则,信息未保存。');
  5286. }
  5287. return null;
  5288. }
  5289.  
  5290. function queryAmulets(bag, store, key) {
  5291. let count = 0;
  5292. if (bag != null) {
  5293. amuletNodesToArray(backpacksDiv.querySelectorAll(bagObjectsQueryString), bag, key);
  5294. count += bag.length;
  5295. }
  5296. if (store != null) {
  5297. amuletNodesToArray(backpacksDiv.querySelectorAll(storeObjectsQueryString), store, key);
  5298. count += store.length;
  5299. }
  5300. return count;
  5301. }
  5302.  
  5303. function showAmuletGroupsPopup() {
  5304. function beginSaveBagAsGroup(groupName, update) {
  5305. let amulets = [];
  5306. queryAmulets(amulets, null);
  5307. createAmuletGroup(groupName, amulets, update);
  5308. showAmuletGroupsPopup();
  5309. }
  5310.  
  5311. genericPopupClose(true);
  5312.  
  5313. let bag = [];
  5314. let store = [];
  5315. if (queryAmulets(bag, store) == 0) {
  5316. alert('护符信息加载异常,请检查!');
  5317. refreshEquipmentPage(null);
  5318. return;
  5319. }
  5320.  
  5321. let amulets = bag.concat(store);
  5322. let bagGroup = amuletCreateGroupFromArray('当前饰品栏', bag);
  5323. let groups = amuletLoadGroups();
  5324. if (bagGroup == null && groups.count() == 0) {
  5325. alert('饰品栏为空,且未找到预保存的护符组信息!');
  5326. return;
  5327. }
  5328.  
  5329. let bagCells = 8 + parseInt(wishpool[0] ?? 0);
  5330. if (userInfo?.[4]?.length > 0) {
  5331. bagCells += 2;
  5332. }
  5333. if (userInfo?.[5]?.length > 0) {
  5334. bagCells += 5;
  5335. }
  5336.  
  5337. genericPopupSetContent(
  5338. '护符组管理',
  5339. '<style> .group-menu { position:relative;' +
  5340. 'display:inline-block;' +
  5341. 'color:blue;' +
  5342. 'font-size:20px;' +
  5343. 'cursor:pointer; } ' +
  5344. '.group-menu-items { display:none;' +
  5345. 'position:absolute;' +
  5346. 'font-size:15px;' +
  5347. 'word-break:keep-all;' +
  5348. 'white-space:nowrap;' +
  5349. 'margin:0 auto;' +
  5350. 'width:fit-content;' +
  5351. 'z-index:999;' +
  5352. 'background-color:white;' +
  5353. 'box-shadow:0px 2px 16px 4px rgba(0, 0, 0, 0.4);' +
  5354. 'padding:15px 30px; } ' +
  5355. '.group-menu-item { } ' +
  5356. '.group-menu:hover .group-menu-items { display:block; } ' +
  5357. '.group-menu-items .group-menu-item:hover { background-color:#bbddff; } ' +
  5358. '</style>' +
  5359. '<div id="popup_amulet_groups" style="margin-top:15px;"></div>');
  5360. let amuletContainer = genericPopupQuerySelector('#popup_amulet_groups');
  5361. let groupMenuDiv = document.createElement('div');
  5362. groupMenuDiv.className = 'group-menu-items';
  5363. groupMenuDiv.innerHTML = '<ul></ul>';
  5364. let groupMenu = groupMenuDiv.firstChild;
  5365.  
  5366. if (bagGroup != null) {
  5367. let groupDiv = document.createElement('div');
  5368. groupDiv.className = g_genericPopupTopLineDivClass;
  5369. groupDiv.id = 'popup_amulet_group_bag';
  5370. groupDiv.setAttribute('group-name', '当前饰品栏内容');
  5371. groupDiv.innerHTML =
  5372. `<b class="group-menu" style="color:${bagGroup.count() > bagCells ? 'red' : 'blue'};">` +
  5373. `当前饰品栏内容 [${bagGroup.count()} / ${bagCells}] ▼</b>`;
  5374.  
  5375. let mitem = document.createElement('li');
  5376. mitem.className = 'group-menu-item';
  5377. mitem.innerHTML =
  5378. `<a href="#popup_amulet_group_bag">当前饰品栏内容 [${bagGroup.count()} / ${bagCells}]</a>`;
  5379. groupMenu.appendChild(mitem);
  5380.  
  5381. g_amuletTypeNames.slice().reverse().forEach((item) => {
  5382. let btn = document.createElement('button');
  5383. btn.innerText = '清空' + item;
  5384. btn.style.float = 'right';
  5385. btn.setAttribute('amulet-key', item);
  5386. btn.onclick = clearSpecAmulet;
  5387. groupDiv.appendChild(btn);
  5388. });
  5389.  
  5390. function clearSpecAmulet(e) {
  5391. genericPopupShowProgressMessage('处理中,请稍候...');
  5392. beginClearBag(backpacksDiv.querySelectorAll(bagObjectsQueryString),
  5393. e.target.getAttribute('amulet-key'),
  5394. refreshEquipmentPage,
  5395. showAmuletGroupsPopup);
  5396. }
  5397.  
  5398. let saveBagGroupBtn = document.createElement('button');
  5399. saveBagGroupBtn.innerText = '保存为护符组';
  5400. saveBagGroupBtn.style.float = 'right';
  5401. saveBagGroupBtn.onclick = (() => {
  5402. let groupName = inputAmuletGroupName('');
  5403. if (groupName != null) {
  5404. beginSaveBagAsGroup(groupName, false);
  5405. }
  5406. });
  5407. groupDiv.appendChild(saveBagGroupBtn);
  5408.  
  5409. let groupInfoDiv = document.createElement('div');
  5410. groupInfoDiv.innerHTML =
  5411. `<hr><ul style="color:#000080;">${bagGroup.formatBuffSummary('<li>', '</li>', '', true)}</ul>
  5412. <hr><ul>${bagGroup.formatItems('<li>', '<li style="color:red;">', '</li>', '</li>', '')}</ul>
  5413. <hr><ul><li>AMULET ${bagGroup.formatBuffShortMark(' ', ' ', false)} ENDAMULET</li></ul>`;
  5414. groupDiv.appendChild(groupInfoDiv);
  5415.  
  5416. amuletContainer.appendChild(groupDiv);
  5417. }
  5418.  
  5419. let li = 0
  5420. let groupArray = groups.toArray();
  5421. let gl = (groupArray?.length ?? 0);
  5422. if (gl > 0) {
  5423. groupArray = groupArray.sort((a, b) => a.name < b.name ? -1 : 1);
  5424. for (let i = 0; i < gl; i++) {
  5425. let err = !groupArray[i].validate(amulets);
  5426.  
  5427. let groupDiv = document.createElement('div');
  5428. groupDiv.className = g_genericPopupTopLineDivClass;
  5429. groupDiv.id = 'popup_amulet_group_' + i;
  5430. groupDiv.setAttribute('group-name', groupArray[i].name);
  5431. groupDiv.innerHTML =
  5432. `<b class="group-menu" style="color:${err ? "red" : "blue"};">` +
  5433. `${groupArray[i].name} [${groupArray[i].count()}] ▼</b>`;
  5434.  
  5435. let mitem = document.createElement('li');
  5436. mitem.className = 'group-menu-item';
  5437. mitem.innerHTML =
  5438. `<a href="#popup_amulet_group_${i}">${groupArray[i].name} [${groupArray[i].count()}]</a>`;
  5439. groupMenu.appendChild(mitem);
  5440.  
  5441. let amuletDeleteGroupBtn = document.createElement('button');
  5442. amuletDeleteGroupBtn.innerText = '删除';
  5443. amuletDeleteGroupBtn.style.float = 'right';
  5444. amuletDeleteGroupBtn.onclick = ((e) => {
  5445. let groupName = e.target.parentNode.getAttribute('group-name');
  5446. if (confirm(`删除护符组 "${groupName}" 吗?`)) {
  5447. amuletDeleteGroup(groupName);
  5448. showAmuletGroupsPopup();
  5449. }
  5450. });
  5451. groupDiv.appendChild(amuletDeleteGroupBtn);
  5452.  
  5453. let amuletModifyGroupBtn = document.createElement('button');
  5454. amuletModifyGroupBtn.innerText = '编辑';
  5455. amuletModifyGroupBtn.style.float = 'right';
  5456. amuletModifyGroupBtn.onclick = ((e) => {
  5457. let groupName = e.target.parentNode.getAttribute('group-name');
  5458. modifyAmuletGroup(groupName);
  5459. });
  5460. groupDiv.appendChild(amuletModifyGroupBtn);
  5461.  
  5462. let importAmuletGroupBtn = document.createElement('button');
  5463. importAmuletGroupBtn.innerText = '导入';
  5464. importAmuletGroupBtn.style.float = 'right';
  5465. importAmuletGroupBtn.onclick = ((e) => {
  5466. let groupName = e.target.parentNode.getAttribute('group-name');
  5467. let persistenceString = prompt('请输入护符组编码(工具软件生成的特殊格式序列)');
  5468. if (persistenceString != null) {
  5469. let group = new AmuletGroup(`${groupName}${AMULET_STORAGE_GROUPNAME_SEPARATOR}${persistenceString}`);
  5470. if (group.isValid()) {
  5471. let groups = amuletLoadGroups();
  5472. if (groups.add(group)) {
  5473. amuletSaveGroups(groups);
  5474. showAmuletGroupsPopup();
  5475. }
  5476. else {
  5477. alert('保存失败!');
  5478. }
  5479. }
  5480. else {
  5481. alert('输入的护符组编码无效,请检查!');
  5482. }
  5483. }
  5484. });
  5485. groupDiv.appendChild(importAmuletGroupBtn);
  5486.  
  5487. let renameAmuletGroupBtn = document.createElement('button');
  5488. renameAmuletGroupBtn.innerText = '更名';
  5489. renameAmuletGroupBtn.style.float = 'right';
  5490. renameAmuletGroupBtn.onclick = ((e) => {
  5491. let oldName = e.target.parentNode.getAttribute('group-name');
  5492. let groupName = inputAmuletGroupName(oldName);
  5493. if (groupName != null && groupName != oldName) {
  5494. let groups = amuletLoadGroups();
  5495. if (!groups.contains(groupName) || confirm(`护符组 "${groupName}" 已存在,要覆盖吗?`)) {
  5496. if (groups.rename(oldName, groupName)) {
  5497. amuletSaveGroups(groups);
  5498. showAmuletGroupsPopup();
  5499. }
  5500. else {
  5501. alert('更名失败!');
  5502. }
  5503. }
  5504. }
  5505. });
  5506. groupDiv.appendChild(renameAmuletGroupBtn);
  5507.  
  5508. let updateAmuletGroupBtn = document.createElement('button');
  5509. updateAmuletGroupBtn.innerText = '更新';
  5510. updateAmuletGroupBtn.style.float = 'right';
  5511. updateAmuletGroupBtn.onclick = ((e) => {
  5512. let groupName = e.target.parentNode.getAttribute('group-name');
  5513. if (confirm(`用当前饰品栏内容替换 "${groupName}" 护符组预定内容吗?`)) {
  5514. beginSaveBagAsGroup(groupName, true);
  5515. }
  5516. });
  5517. groupDiv.appendChild(updateAmuletGroupBtn);
  5518.  
  5519. let unamuletLoadGroupBtn = document.createElement('button');
  5520. unamuletLoadGroupBtn.innerText = '入仓';
  5521. unamuletLoadGroupBtn.style.float = 'right';
  5522. unamuletLoadGroupBtn.onclick = ((e) => {
  5523. let groupName = e.target.parentNode.getAttribute('group-name');
  5524. genericPopupShowProgressMessage('卸载中,请稍候...');
  5525. beginUnloadAmuletGroupFromBag(
  5526. backpacksDiv.querySelectorAll(bagObjectsQueryString),
  5527. groupName, refreshEquipmentPage, showAmuletGroupsPopup);
  5528. });
  5529. groupDiv.appendChild(unamuletLoadGroupBtn);
  5530.  
  5531. let amuletLoadGroupBtn = document.createElement('button');
  5532. amuletLoadGroupBtn.innerText = '装备';
  5533. amuletLoadGroupBtn.style.float = 'right';
  5534. amuletLoadGroupBtn.onclick = ((e) => {
  5535. let groupName = e.target.parentNode.getAttribute('group-name');
  5536. genericPopupShowProgressMessage('加载中,请稍候...');
  5537. beginLoadAmuletGroupFromStore(
  5538. backpacksDiv.querySelectorAll(storeObjectsQueryString),
  5539. groupName, refreshEquipmentPage, showAmuletGroupsPopup);
  5540. });
  5541. groupDiv.appendChild(amuletLoadGroupBtn);
  5542.  
  5543. let groupInfoDiv = document.createElement('div');
  5544. groupInfoDiv.innerHTML =
  5545. `<hr><ul style="color:#000080;">${groupArray[i].formatBuffSummary('<li>', '</li>', '', true)}</ul>
  5546. <hr><ul>${groupArray[i].formatItems('<li>', '<li style="color:red;">', '</li>', '</li>', '')}</ul>
  5547. <hr><ul><li>AMULET ${groupArray[i].formatBuffShortMark(' ', ' ', false)} ENDAMULET</li></ul>`;
  5548. groupDiv.appendChild(groupInfoDiv);
  5549.  
  5550. amuletContainer.appendChild(groupDiv);
  5551. li += groupArray[i].getDisplayStringLineCount();
  5552. }
  5553. }
  5554.  
  5555. genericPopupQuerySelectorAll('.group-menu')?.forEach((e) => {
  5556. e.appendChild(groupMenuDiv.cloneNode(true));
  5557. });
  5558.  
  5559. if (bagGroup != null) {
  5560. gl++;
  5561. li += bagGroup.getDisplayStringLineCount();
  5562. }
  5563.  
  5564. genericPopupAddButton('新建护符组', 0, modifyAmuletGroup, true);
  5565. genericPopupAddButton(
  5566. '导入新护符组',
  5567. 0,
  5568. (() => {
  5569. let groupName = inputAmuletGroupName('');
  5570. if (groupName != null) {
  5571. let persistenceString = prompt('请输入护符组编码(工具软件生成的特殊格式序列)');
  5572. if (persistenceString != null) {
  5573. let group = new AmuletGroup(`${groupName}${AMULET_STORAGE_GROUPNAME_SEPARATOR}${persistenceString}`);
  5574. if (group.isValid()) {
  5575. let groups = amuletLoadGroups();
  5576. if (!groups.contains(groupName) || confirm(`护符组 "${groupName}" 已存在,要覆盖吗?`)) {
  5577. if (groups.add(group)) {
  5578. amuletSaveGroups(groups);
  5579. showAmuletGroupsPopup();
  5580. }
  5581. else {
  5582. alert('保存失败!');
  5583. }
  5584. }
  5585. }
  5586. else {
  5587. alert('输入的护符组编码无效,请检查!');
  5588. }
  5589. }
  5590. }
  5591. }),
  5592. true);
  5593. genericPopupAddButton(
  5594. '清空饰品栏',
  5595. 0,
  5596. (() => {
  5597. genericPopupShowProgressMessage('处理中,请稍候...');
  5598. beginClearBag(backpacksDiv.querySelectorAll(bagObjectsQueryString),
  5599. null, refreshEquipmentPage, showAmuletGroupsPopup);
  5600. }),
  5601. true);
  5602. genericPopupAddCloseButton(80);
  5603.  
  5604. genericPopupSetContentSize(Math.min((li * 20) + (gl * 160) + 60, Math.max(window.innerHeight - 200, 400)),
  5605. Math.min(1000, Math.max(window.innerWidth - 100, 600)),
  5606. true);
  5607. genericPopupShowModal(true);
  5608.  
  5609. if (window.getSelection) {
  5610. window.getSelection().removeAllRanges();
  5611. }
  5612. else if (document.getSelection) {
  5613. document.getSelection().removeAllRanges();
  5614. }
  5615. }
  5616.  
  5617. function modifyAmuletGroup(groupName) {
  5618. function divHeightAdjustment(div) {
  5619. div.style.height = (div.parentNode.offsetHeight - div.offsetTop - 3) + 'px';
  5620. }
  5621.  
  5622. function refreshAmuletList() {
  5623. amuletList.innerHTML = '';
  5624. amulets.forEach((am) => {
  5625. if (amuletFilter == -1 || am.type == amuletFilter) {
  5626. let item = document.createElement('li');
  5627. item.setAttribute('original-id', am.id);
  5628. item.innerText = am.formatBuffText();
  5629. amuletList.appendChild(item);
  5630. }
  5631. });
  5632. }
  5633.  
  5634. function refreshGroupAmuletSummary() {
  5635. let count = group.count();
  5636. if (count > 0) {
  5637. groupSummary.innerHTML = group.formatBuffSummary('<li>', '</li>', '', true);
  5638. groupSummary.style.display = 'block';
  5639. }
  5640. else {
  5641. groupSummary.style.display = 'none';
  5642. groupSummary.innerHTML = '';
  5643. }
  5644. divHeightAdjustment(groupAmuletList.parentNode);
  5645. amuletCount.innerText = count;
  5646. }
  5647.  
  5648. function refreshGroupAmuletList() {
  5649. groupAmuletList.innerHTML = '';
  5650. group.items.forEach((am) => {
  5651. if (am.id >= 0) {
  5652. let item = document.createElement('li');
  5653. item.setAttribute('original-id', am.id);
  5654. item.innerText = am.formatBuffText();
  5655. groupAmuletList.appendChild(item);
  5656. }
  5657. });
  5658. }
  5659.  
  5660. function refreshGroupAmuletDiv() {
  5661. refreshGroupAmuletSummary();
  5662. refreshGroupAmuletList();
  5663. }
  5664.  
  5665. function moveAmuletItem(e) {
  5666. let li = e.target;
  5667. if (li.tagName == 'LI') {
  5668. let from = li.parentNode;
  5669. let id = li.getAttribute('original-id');
  5670. from.removeChild(li);
  5671. if (from == amuletList) {
  5672. let i = searchElement(amulets, id, (a, b) => a - b.id);
  5673. let am = amulets[i];
  5674. amulets.splice(i, 1);
  5675. groupAmuletList.insertBefore(li, groupAmuletList.children.item(group.add(am)));
  5676. }
  5677. else {
  5678. let am = group.removeId(id);
  5679. insertElement(amulets, am, (a, b) => a.id - b.id);
  5680. if (amuletFilter == -1 || am.type == amuletFilter) {
  5681. for (var item = amuletList.firstChild;
  5682. parseInt(item?.getAttribute('original-id')) <= am.id;
  5683. item = item.nextSibling);
  5684. amuletList.insertBefore(li, item);
  5685. }
  5686. }
  5687. refreshGroupAmuletSummary();
  5688. groupChanged = true;
  5689. }
  5690. }
  5691.  
  5692. let bag = [];
  5693. let store = [];
  5694. if (queryAmulets(bag, store) == 0) {
  5695. alert('获取护符信息失败,请检查!');
  5696. return;
  5697. }
  5698. let amulets = bag.concat(store).sort((a, b) => a.compareTo(b));
  5699. amulets.forEach((item, index) => { item.id = index; });
  5700.  
  5701. let displayName = groupName;
  5702. if (!amuletIsValidGroupName(displayName)) {
  5703. displayName = '(未命名)';
  5704. groupName = null;
  5705. }
  5706. else if (displayName.length > 20) {
  5707. displayName = displayName.slice(0, 19) + '...';
  5708. }
  5709.  
  5710. let groupChanged = false;
  5711. let group = amuletLoadGroup(groupName);
  5712. if (!group?.isValid()) {
  5713. group = new AmuletGroup(null);
  5714. group.name = '(未命名)';
  5715. groupName = null;
  5716. }
  5717. else {
  5718. group.validate(amulets);
  5719. while (group.removeId(-1) != null) {
  5720. groupChanged = true;
  5721. }
  5722. group.items.forEach((am) => {
  5723. let i = searchElement(amulets, am, (a, b) => a.id - b.id);
  5724. if (i >= 0) {
  5725. amulets.splice(i, 1);
  5726. }
  5727. });
  5728. }
  5729.  
  5730. genericPopupClose(true);
  5731.  
  5732. let fixedContent =
  5733. '<div style="padding:20px 0px 5px 0px;font-size:18px;color:blue;"><b>' +
  5734. '<span>左键双击或上下文菜单键单击护符条目以进行添加或移除操作</span><span style="float:right;">共 ' +
  5735. '<span id="amulet_count" style="color:#800020;">0</span> 个护符</span></b></div>';
  5736. let mainContent =
  5737. '<style> ul > li:hover { background-color:#bbddff; } </style>' +
  5738. '<div style="display:block;height:100%;width:100%;">' +
  5739. '<div style="position:relative;display:block;float:left;height:96%;width:49%;' +
  5740. 'margin-top:10px;border:1px solid #000000;">' +
  5741. '<div id="amulet_filter" style="display:inline-block;width:100%;padding:5px;color:#0000c0;' +
  5742. 'font-size:14px;text-align:center;border-bottom:2px groove #d0d0d0;margin-bottom:10px;">' +
  5743. '</div>' +
  5744. '<div style="position:absolute;display:block;height:1px;width:100%;overflow:scroll;">' +
  5745. '<ul id="amulet_list" style="cursor:pointer;"></ul>' +
  5746. '</div>' +
  5747. '</div>' +
  5748. '<div style="position:relative;display:block;float:right;height:96%;width:49%;' +
  5749. 'margin-top:10px;border:1px solid #000000;">' +
  5750. '<div id="group_summary" style="display:block;width:100%;padding:10px 5px;' +
  5751. 'border-bottom:2px groove #d0d0d0;color:#000080;margin-bottom:10px;"></div>' +
  5752. '<div style="position:absolute;display:block;height:1px;width:100%;overflow:scroll;">' +
  5753. '<ul id="group_amulet_list" style="cursor:pointer;"></ul>' +
  5754. '</div>' +
  5755. '</div>' +
  5756. '</div>';
  5757.  
  5758. genericPopupSetFixedContent(fixedContent);
  5759. genericPopupSetContent('编辑护符组 - ' + displayName, mainContent);
  5760.  
  5761. let amuletCount = genericPopupQuerySelector('#amulet_count');
  5762. let amuletFilter = -1;
  5763. let amuletFilterList = genericPopupQuerySelector('#amulet_filter');
  5764. let amuletList = genericPopupQuerySelector('#amulet_list');
  5765. let groupSummary = genericPopupQuerySelector('#group_summary');
  5766. let groupAmuletList = genericPopupQuerySelector('#group_amulet_list');
  5767.  
  5768. function addAmuletFilterItem(text, amuletTypesId, checked) {
  5769. let check = document.createElement('input');
  5770. check.type = 'radio';
  5771. check.name = 'amulet-filter';
  5772. check.id = 'amulet-type-' + amuletTypesId.toString();
  5773. check.setAttribute('amulet-type-id', amuletTypesId);
  5774. check.checked = checked;
  5775. if (amuletFilterList.firstChild != null) {
  5776. check.style.marginLeft = '30px';
  5777. }
  5778. check.onchange = ((e) => {
  5779. if (e.target.checked) {
  5780. amuletFilter = e.target.getAttribute('amulet-type-id');
  5781. refreshAmuletList();
  5782. }
  5783. });
  5784.  
  5785. let label = document.createElement('label');
  5786. label.innerText = text;
  5787. label.setAttribute('for', check.id);
  5788. label.style.cursor = 'pointer';
  5789. label.style.marginLeft = '5px';
  5790.  
  5791. amuletFilterList.appendChild(check);
  5792. amuletFilterList.appendChild(label);
  5793. }
  5794.  
  5795. for (let amuletType of g_amuletTypeNames) {
  5796. addAmuletFilterItem(amuletType,
  5797. g_amuletTypeIds[amuletType.slice(0, g_amuletTypeIds.end - g_amuletTypeIds.start)],
  5798. false);
  5799. }
  5800. addAmuletFilterItem('全部', -1, true);
  5801.  
  5802. refreshAmuletList();
  5803. refreshGroupAmuletDiv();
  5804.  
  5805. amuletList.parentNode.oncontextmenu = groupAmuletList.parentNode.oncontextmenu = (() => false);
  5806. amuletList.oncontextmenu = groupAmuletList.oncontextmenu = moveAmuletItem;
  5807. amuletList.ondblclick = groupAmuletList.ondblclick = moveAmuletItem;
  5808.  
  5809. genericPopupAddButton(
  5810. '清空护符组',
  5811. 0,
  5812. (() => {
  5813. if (group.count() > 0) {
  5814. group.items.forEach((am) => { insertElement(amulets, am, (a, b) => a.id - b.id); });
  5815. group.clear();
  5816.  
  5817. refreshAmuletList();
  5818. refreshGroupAmuletDiv();
  5819.  
  5820. groupChanged = true;
  5821. }
  5822. }),
  5823. true);
  5824.  
  5825. if (amuletIsValidGroupName(groupName)) {
  5826. genericPopupAddButton(
  5827. '另存为',
  5828. 80,
  5829. (() => {
  5830. if (!group.isValid()) {
  5831. alert('护符组内容存在错误,请检查!');
  5832. return;
  5833. }
  5834.  
  5835. let gn = inputAmuletGroupName(groupName);
  5836. if (gn == null) {
  5837. return;
  5838. }
  5839.  
  5840. let groups = amuletLoadGroups();
  5841. if (groups.contains(gn) && !confirm(`护符组 "${gn}" 已存在,要覆盖吗?`)) {
  5842. return;
  5843. }
  5844.  
  5845. group.name = gn;
  5846. if (groups.add(group)) {
  5847. amuletSaveGroups(groups);
  5848. showAmuletGroupsPopup();
  5849. }
  5850. else {
  5851. alert('保存失败!');
  5852. }
  5853. }),
  5854. false);
  5855. }
  5856.  
  5857. genericPopupAddButton(
  5858. '确认',
  5859. 80,
  5860. (() => {
  5861. if (!groupChanged && group.isValid()) {
  5862. showAmuletGroupsPopup();
  5863. return;
  5864. }
  5865. else if (!group.isValid()) {
  5866. alert('护符组内容存在错误,请检查!');
  5867. return;
  5868. }
  5869.  
  5870. let groups = amuletLoadGroups();
  5871. if (!amuletIsValidGroupName(groupName)) {
  5872. let gn = inputAmuletGroupName(displayName);
  5873. if (gn == null || (groups.contains(gn) && !confirm(`护符组 "${gn}" 已存在,要覆盖吗?`))) {
  5874. return;
  5875. }
  5876. group.name = gn;
  5877. }
  5878.  
  5879. if (groups.add(group)) {
  5880. amuletSaveGroups(groups);
  5881. showAmuletGroupsPopup();
  5882. }
  5883. else {
  5884. alert('保存失败!');
  5885. }
  5886. }),
  5887. false);
  5888.  
  5889. let btnCancel = genericPopupAddButton(
  5890. '取消',
  5891. 80,
  5892. (() => {
  5893. if (!groupChanged || confirm('护符组内容已修改,不保存吗?')) {
  5894. showAmuletGroupsPopup();
  5895. }
  5896. }),
  5897. false);
  5898.  
  5899. genericPopupSetContentSize(Math.min(800, Math.max(window.innerHeight - 200, 500)),
  5900. Math.min(1000, Math.max(window.innerWidth - 100, 600)),
  5901. false);
  5902. genericPopupShowModal(false);
  5903. genericPopupOnClickOutside(btnCancel.onclick);
  5904.  
  5905. divHeightAdjustment(amuletList.parentNode);
  5906. divHeightAdjustment(groupAmuletList.parentNode);
  5907. }
  5908.  
  5909. function createAmuletGroup(groupName, amulets, update) {
  5910. let group = amuletCreateGroupFromArray(groupName, amulets);
  5911. if (group != null) {
  5912. let groups = amuletLoadGroups();
  5913. if (update || !groups.contains(groupName) || confirm(`护符组 "${groupName}" 已存在,要覆盖吗?`)) {
  5914. if (groups.add(group)) {
  5915. amuletSaveGroups(groups);
  5916. genericPopupClose(true);
  5917. return true;
  5918. }
  5919. else {
  5920. alert('保存失败!');
  5921. }
  5922. }
  5923. }
  5924. else {
  5925. alert('保存异常,请检查!');
  5926. }
  5927. genericPopupClose(true);
  5928. return false;
  5929. }
  5930.  
  5931. function formatAmuletsString() {
  5932. let bag = [];
  5933. let store = [];
  5934. let exportLines = [];
  5935. if (queryAmulets(bag, store) > 0) {
  5936. let amulets = bag.concat(store).sort((a, b) => a.compareTo(b));
  5937. let amuletIndex = 1;
  5938. amulets.forEach((am) => {
  5939. exportLines.push(`${('00' + amuletIndex).slice(-3)} - ${am.formatShortMark()}`);
  5940. amuletIndex++;
  5941. });
  5942. }
  5943. return (exportLines.length > 0 ? exportLines.join('\n') : '');
  5944. }
  5945.  
  5946. function exportAmulets() {
  5947. genericPopupSetContent(
  5948. '护符导出',
  5949. `<b><div id="amulet_export_tip" style="color:#0000c0;padding:15px 0px 10px;">
  5950. 请勿修改任何导出内容,将其保存为纯文本在其它相应工具中使用</div></b>
  5951. <div style="height:330px;"><textarea id="amulet_persistence_string" readonly="true"
  5952. style="height:100%;width:100%;resize:none;"></textarea></div>`);
  5953.  
  5954. genericPopupAddButton(
  5955. '复制导出内容至剪贴板',
  5956. 0,
  5957. ((e) => {
  5958. e.target.disabled = 'disabled';
  5959. let tipContainer = genericPopupQuerySelector('#amulet_export_tip');
  5960. let tipColor = tipContainer.style.color;
  5961. let tipString = tipContainer.innerText;
  5962. tipContainer.style.color = '#ff0000';
  5963. genericPopupQuerySelector('#amulet_persistence_string').select();
  5964. if (document.execCommand('copy')) {
  5965. tipContainer.innerText = '导出内容已复制到剪贴板';
  5966. }
  5967. else {
  5968. tipContainer.innerText = '复制失败,这可能是因为浏览器没有剪贴板访问权限,请进行手工复制(CTRL+A, CTRL+C)';
  5969. }
  5970. setTimeout((() => {
  5971. tipContainer.style.color = tipColor;
  5972. tipContainer.innerText = tipString;
  5973. e.target.disabled = '';
  5974. }), 3000);
  5975. }),
  5976. true);
  5977. genericPopupAddCloseButton(80);
  5978.  
  5979. genericPopupQuerySelector('#amulet_persistence_string').value = formatAmuletsString();
  5980.  
  5981. genericPopupSetContentSize(400, 600, false);
  5982. genericPopupShowModal(true);
  5983. }
  5984.  
  5985. let amuletButtonsGroupContainer = document.getElementById('amulet_management_btn_group');
  5986. if (amuletButtonsGroupContainer == null) {
  5987. let equipCtrlContainer = document.querySelector('#equip-ctrl-container');
  5988. amuletButtonsGroupContainer = document.createElement('p');
  5989. amuletButtonsGroupContainer.id = 'amulet_management_btn_group';
  5990. amuletButtonsGroupContainer.style.display = 'inline-block';
  5991. amuletButtonsGroupContainer.style.float = 'left';
  5992. equipCtrlContainer.insertBefore(amuletButtonsGroupContainer, equipCtrlContainer.firstElementChild);
  5993.  
  5994. let exportAmuletsBtn = document.createElement('button');
  5995. exportAmuletsBtn.innerText = '导出护符';
  5996. exportAmuletsBtn.style.width = '100px';
  5997. exportAmuletsBtn.style.marginRight = '1px';
  5998. exportAmuletsBtn.onclick = (() => {
  5999. exportAmulets();
  6000. });
  6001. amuletButtonsGroupContainer.appendChild(exportAmuletsBtn);
  6002.  
  6003. let clearAmuletGroupBtn = document.createElement('button');
  6004. clearAmuletGroupBtn.innerText = '清除护符组';
  6005. clearAmuletGroupBtn.style.width = '100px';
  6006. clearAmuletGroupBtn.style.marginRight = '1px';
  6007. clearAmuletGroupBtn.onclick = (() => {
  6008. if (confirm('要删除全部已保存的护符组信息吗?')) {
  6009. amuletClearGroups();
  6010. alert('已删除全部预定义护符组信息。');
  6011. }
  6012. });
  6013. amuletButtonsGroupContainer.appendChild(clearAmuletGroupBtn);
  6014.  
  6015. let manageAmuletGroupBtn = document.createElement('button');
  6016. manageAmuletGroupBtn.innerText = '管理护符组';
  6017. manageAmuletGroupBtn.style.width = '100px';
  6018. manageAmuletGroupBtn.onclick = (() => {
  6019. genericPopupInitialize();
  6020. showAmuletGroupsPopup();
  6021. });
  6022. amuletButtonsGroupContainer.appendChild(manageAmuletGroupBtn);
  6023.  
  6024. document.getElementById(storeButtonId).onclick = (() => {
  6025. if ($('#backpacks > ' + storeQueryString).css('display') == 'none') {
  6026. $('#backpacks > ' + storeQueryString).show();
  6027. } else {
  6028. $('#backpacks > ' + storeQueryString).hide();
  6029. }
  6030. backupEquipmentDivState({ target : document.getElementById(storeButtonId) });
  6031. });
  6032. }
  6033.  
  6034. let bagButtonsGroupContainer = document.getElementById('bag_management_btn_group');
  6035. if (bagButtonsGroupContainer == null) {
  6036. let bagTitle = backpacksDiv.querySelector(bagQueryString + ' > p.fyg_tr');
  6037. let bagButtonsGroupContainer = document.createElement('p');
  6038. bagButtonsGroupContainer.id = 'bag_management_btn_group';
  6039. bagButtonsGroupContainer.style.display = 'inline-block';
  6040. bagButtonsGroupContainer.style.float = 'left';
  6041. bagButtonsGroupContainer.style.marginTop = '6px';
  6042. bagTitle.insertBefore(bagButtonsGroupContainer, bagTitle.firstElementChild);
  6043.  
  6044. let beginClearBagBtn = document.createElement('button');
  6045. beginClearBagBtn.innerText = '清空饰品栏';
  6046. beginClearBagBtn.style.width = '100px';
  6047. beginClearBagBtn.style.marginRight = '1px';
  6048. beginClearBagBtn.onclick = (() => {
  6049. genericPopupShowProgressMessage('处理中,请稍候...');
  6050. beginClearBag(
  6051. backpacksDiv.querySelectorAll(bagObjectsQueryString),
  6052. null, refreshEquipmentPage, () => { genericPopupClose(true, true); });
  6053. });
  6054. bagButtonsGroupContainer.appendChild(beginClearBagBtn);
  6055.  
  6056. let amuletSaveGroupBtn = document.createElement('button');
  6057. amuletSaveGroupBtn.innerText = '存为护符组';
  6058. amuletSaveGroupBtn.style.width = '100px';
  6059. amuletSaveGroupBtn.onclick = (() => {
  6060. let groupName = inputAmuletGroupName('');
  6061. if (groupName != null) {
  6062. let amulets = [];
  6063. if (queryAmulets(amulets, null) == 0) {
  6064. alert('保存失败,请检查饰品栏内容!');
  6065. }
  6066. else if (createAmuletGroup(groupName, amulets, false)) {
  6067. alert('保存成功。');
  6068. }
  6069. }
  6070. });
  6071. bagButtonsGroupContainer.appendChild(amuletSaveGroupBtn);
  6072. }
  6073.  
  6074. $('#equipmentDiv .btn-equipment .bg-danger.with-padding').css({
  6075. 'max-width': '220px',
  6076. 'padding': '5px 5px 5px 5px',
  6077. 'white-space': 'pre-line',
  6078. 'word-break': 'break-all'
  6079. });
  6080.  
  6081. collapseEquipmentDiv(equipmentExpand, forceEquipDivOperation);
  6082. changeEquipmentDivStyle(equipmentBG);
  6083. switchObjectContainerStatus(!equipmentStoreExpand);
  6084.  
  6085. forceEquipDivOperation = false;
  6086. }
  6087. if (fnPostProcess != null) {
  6088. fnPostProcess(fnParams);
  6089. }
  6090. }
  6091. }, 200);
  6092. }
  6093.  
  6094. const g_genCalcCfgPopupLinkId = 'gen_calc_cfg_popup_link';
  6095. const g_bindingPopupLinkId = 'binding_popup_link';
  6096. const g_bindingSolutionId = 'binding_solution_div';
  6097. const g_bindingListSelectorId = 'binding_list_selector';
  6098. const g_equipOnekeyLinkId = 'equip_one_key_link';
  6099. function equipOnekey() {
  6100. let solutionSelector = document.getElementById(g_bindingListSelectorId);
  6101. let bindingElements = solutionSelector?.value?.split(BINDING_NAME_SEPARATOR);
  6102. if (bindingElements?.length == 2) {
  6103. let solution = solutionSelector.options?.[solutionSelector.selectedIndex]?.innerText?.trim();
  6104. if (solution?.length > 0) {
  6105. let roleId = g_roleMap.get(bindingElements[0].trim()).id;
  6106. let udata = loadUserConfigData();
  6107. if (udata.dataBindDefault[roleId] != solution) {
  6108. udata.dataBindDefault[roleId] = solution;
  6109. saveUserConfigData(udata);
  6110. }
  6111. genericPopupInitialize();
  6112. genericPopupShowProgressMessage('读取中,请稍候...');
  6113. switchBindingSolution(solutionSelector.value, cding);
  6114. return;
  6115. }
  6116. }
  6117. alert('绑定信息读取失败,无法装备!');
  6118. }
  6119.  
  6120. const BINDING_NAME_DEFAULT = '(未命名)';
  6121. function showBindingPopup() {
  6122. let role = g_roleMap.get(backpacksDiv.querySelector('div.row > div.col-md-3 > span.text-info.fyg_f24')?.innerText);
  6123. let cardInfos = backpacksDiv.querySelectorAll('.icon.icon-angle-down.text-primary');
  6124. let roleLv = cardInfos[0].innerText.match(/\d+/)[0];
  6125. let roleQl = cardInfos[1].innerText.match(/\d+/)[0];
  6126. let roleHs = cardInfos[2].innerText.match(/\d+/)[0];
  6127. let roleGv = (cardInfos[3]?.innerText.match(/\d+/)[0] ?? '0');
  6128. let rolePt = [];
  6129. for (let i = 1; i <= 6; i++) {
  6130. rolePt.push(document.getElementById('sjj' + i).innerText);
  6131. }
  6132. if (role == null || roleLv == null || roleQl == null || roleHs == null) {
  6133. alert('读取卡片信息失败,无法执行绑定操作!');
  6134. return;
  6135. }
  6136.  
  6137. let bind_info = null;
  6138. let udata = loadUserConfigData();
  6139. if (udata.dataBind[role.id] != null) {
  6140. bind_info = udata.dataBind[role.id];
  6141. }
  6142.  
  6143. genericPopupInitialize();
  6144. genericPopupShowProgressMessage('读取中,请稍候...');
  6145.  
  6146. const highlightBackgroundColor = '#80c0f0';
  6147. const fixedContent =
  6148. '<style> .binding-list { position:relative; width:100%; display:inline-block; } ' +
  6149. '.binding-names { display:none;' +
  6150. 'position:absolute;' +
  6151. 'word-break:keep-all;' +
  6152. 'white-space:nowrap;' +
  6153. 'margin:0 auto;' +
  6154. 'width:100%;' +
  6155. 'z-index:999;' +
  6156. 'background-color:white;' +
  6157. 'box-shadow:0px 2px 16px 4px rgba(0, 0, 0, 0.4);' +
  6158. 'padding:10px 20px; } '+
  6159. '.binding-name { cursor:pointer; } ' +
  6160. '.binding-list:hover .binding-names { display:block; } ' +
  6161. '.binding-list:focus-within .binding-names { display:block; } ' +
  6162. '.binding-names .binding-name:hover { background-color:#bbddff; } </style>' +
  6163. `<div style="width:100%;color:#0000ff;padding:20px 10px 5px 0px;"><b style="font-size:15px;">绑定方案名称` +
  6164. `(不超过31个字符,请仅使用大、小写英文字母、数字、连字符、下划线及中文字符):` +
  6165. `<span id="${g_genericPopupInformationTipsId}" style="float:right;color:red;"></span></b></div>
  6166. <div style="width:100%;padding:0px 10px 20px 0px;"><div class="binding-list">
  6167. <input type="text" id="binding_name" style="display:inline-block;width:100%;" maxlength="31" />
  6168. <div class="binding-names" id="binding_list"><ul></ul></div></div></div>`;
  6169. const mainContent =
  6170. `<style> .equipment_label { display:inline-block; width:15%; }
  6171. .equipment_selector { display:inline-block; width:84%; color:#145ccd; float:right; }
  6172. ul > li { cursor:pointer; } </style>
  6173. <div class="${g_genericPopupTopLineDivClass}" id="role_export_div" style="display:none;">
  6174. <div style="height:200px;">
  6175. <textarea id="role_export_string" readonly="true" style="height:100%;width:100%;resize:none;"></textarea></div>
  6176. <div style="padding:10px 0px 20px 0px;">
  6177. <button type="button" style="float:right;margin-left:1px;" id="hide_export_div">隐藏</button>
  6178. <button type="button" style="float:right;" id="copy_export_string">复制导出内容至剪贴板</button></div></div>
  6179. <div class="${g_genericPopupTopLineDivClass}">
  6180. <span class="equipment_label">武器装备:</span><select class="equipment_selector"></select><br><br>
  6181. <span class="equipment_label">手臂装备:</span><select class="equipment_selector"></select><br><br>
  6182. <span class="equipment_label">身体装备:</span><select class="equipment_selector"></select><br><br>
  6183. <span class="equipment_label">头部装备:</span><select class="equipment_selector"></select><br></div>
  6184. <div class="${g_genericPopupTopLineDivClass}"><div id="halo_selector"></div></div>
  6185. <div class="${g_genericPopupTopLineDivClass}" id="amulet_selector" style="display:block;"><div></div></div>`;
  6186.  
  6187. genericPopupSetFixedContent(fixedContent);
  6188. genericPopupSetContent(`${role.name} - ${roleLv} 级`, mainContent);
  6189.  
  6190. let eq_selectors = genericPopupQuerySelectorAll('select.equipment_selector');
  6191. let asyncOperations = 4;
  6192. let haloMax = 0;
  6193. let haloGroupItemMax = 0;
  6194.  
  6195. let store = [];
  6196. beginReadObjects(
  6197. null,
  6198. store,
  6199. () => {
  6200. let equipment = equipmentNodesToInfoArray(store);
  6201. equipmentNodesToInfoArray(cardingDiv.querySelectorAll(cardingObjectsQueryString), equipment);
  6202.  
  6203. equipment.sort((e1, e2) => {
  6204. if (e1[0] != e2[0]) {
  6205. return (g_equipMap.get(e1[0]).index - g_equipMap.get(e2[0]).index);
  6206. }
  6207. return -equipmentInfoComparer(e1, e2);
  6208. });
  6209.  
  6210. equipment.forEach((item) => {
  6211. let eqMeta = g_equipMap.get(item[0]);
  6212. let lv = objectGetLevel(item);
  6213. let op = document.createElement('option');
  6214. op.style.backgroundColor = g_equipmentLevelBGColor[lv];
  6215. op.innerText =
  6216. `${eqMeta.alias} Lv.${item[1]} (攻.${item[2]} 防.${item[3]}) - ${item[4]}% ${item[5]}% ` +
  6217. `${item[6]}% ${item[7]}% ${item[8] == 1 ? ' - [ 神秘 ]' : ''}`;
  6218. op.title =
  6219. `Lv.${item[1]} - ${item[8] == 1 ? '神秘' : ''}${g_equipmentLevelName[lv]}装备\n` +
  6220. `${formatEquipmentAttributes(item, '\n')}`;
  6221. op.value = item.slice(0, -1).join(',');
  6222. eq_selectors[eqMeta.type].appendChild(op);
  6223. });
  6224.  
  6225. eq_selectors.forEach((eqs) => {
  6226. eqs.onchange = equipSelectionChange;
  6227. equipSelectionChange({ target : eqs });
  6228. });
  6229. function equipSelectionChange(e) {
  6230. for (var op = e.target.firstChild; op != null && op.value != e.target.value; op = op.nextSibling);
  6231. e.target.title = (op?.title ?? '');
  6232. e.target.style.backgroundColor = (op?.style.backgroundColor ?? 'white');
  6233. }
  6234. asyncOperations--;
  6235. },
  6236. null);
  6237.  
  6238. let currentHalo;
  6239. beginReadHaloInfo(
  6240. currentHalo = [],
  6241. () => {
  6242. haloMax = currentHalo[0];
  6243. let haloInfo =
  6244. `天赋点:<span style="color:#0000c0;"><span id="halo_points">0</span> / ${haloMax}</span>,
  6245. 技能位:<span style="color:#0000c0;"><span id="halo_slots">0</span> / ${roleHs}</span>
  6246. <b id="halo_errors" style="display:none;color:red;margin-left:15px;">(光环天赋点数 / 角色卡片技能位不足)</b>`;
  6247. let haloSelector = genericPopupQuerySelector('#halo_selector');
  6248. haloSelector.innerHTML =
  6249. `<style> .halo_group { display:block; width:25%; float:left; text-align:center; border-left:1px solid grey; }
  6250. div > a { display:inline-block; width:90px; } </style>
  6251. <div>${haloInfo}</div>
  6252. <p></p>
  6253. <div style="display:table;">
  6254. <div class="halo_group"></div>
  6255. <div class="halo_group"></div>
  6256. <div class="halo_group"></div>
  6257. <div class="halo_group" style="border-right:1px solid grey;"></div></div>`;
  6258. let haloGroups = haloSelector.querySelectorAll('.halo_group');
  6259. let group = -1;
  6260. let points = -1;
  6261. g_halos.forEach((item) => {
  6262. if (item.points != points) {
  6263. points = item.points;
  6264. group++;
  6265. }
  6266. let a = document.createElement('a');
  6267. a.href = '###';
  6268. a.className = 'halo_item';
  6269. a.innerText = item.name + ' ' + item.points;
  6270. haloGroups[group].appendChild(a);
  6271. if (haloGroups[group].children.length > haloGroupItemMax) {
  6272. haloGroupItemMax = haloGroups[group].children.length;
  6273. }
  6274. });
  6275.  
  6276. function selector_halo() {
  6277. let hp = parseInt(haloPoints.innerText);
  6278. let hs = parseInt(haloSlots.innerText);
  6279. if ($(this).attr('item-selected') != 1) {
  6280. $(this).attr('item-selected', 1);
  6281. $(this).css('background-color', highlightBackgroundColor);
  6282. hp += parseInt($(this).text().split(' ')[1]);
  6283. hs++;
  6284. }
  6285. else {
  6286. $(this).attr('item-selected', 0);
  6287. $(this).css('background-color', g_genericPopupBackgroundColor);
  6288. hp -= parseInt($(this).text().split(' ')[1]);
  6289. hs--;
  6290. }
  6291. haloPoints.innerText = hp;
  6292. haloSlots.innerText = hs;
  6293. haloPoints.style.color = (hp <= haloMax ? '#0000c0' : 'red');
  6294. haloSlots.style.color = (hs <= roleHs ? '#0000c0' : 'red');
  6295. haloErrors.style.display = (hp <= haloMax && hs <= roleHs ? 'none' : 'inline-block');
  6296. }
  6297.  
  6298. haloPoints = genericPopupQuerySelector('#halo_points');
  6299. haloSlots = genericPopupQuerySelector('#halo_slots');
  6300. haloErrors = genericPopupQuerySelector('#halo_errors');
  6301. $('.halo_item').each(function(i, e) {
  6302. $(e).on('click', selector_halo);
  6303. $(e).attr('original-item', $(e).text().split(' ')[0]);
  6304. });
  6305. asyncOperations--;
  6306. },
  6307. null);
  6308.  
  6309. if (wishpool.length == 0) {
  6310. beginReadWishpool(wishpool, null, () => { asyncOperations--; }, null);
  6311. }
  6312. else {
  6313. asyncOperations--;
  6314. }
  6315. if (userInfo.length == 0) {
  6316. beginReadUserInfo(userInfo, () => { asyncOperations--; });
  6317. }
  6318. else {
  6319. asyncOperations--;
  6320. }
  6321.  
  6322. function collectBindingInfo() {
  6323. let halo = [];
  6324. let sum = 0;
  6325. $('.halo_item').each(function(i, e) {
  6326. if ($(e).attr('item-selected') == 1) {
  6327. let ee = e.innerText.split(' ');
  6328. sum += parseInt(ee[1]);
  6329. halo.push($(e).attr('original-item'));
  6330. }
  6331. });
  6332. let h = parseInt(haloMax);
  6333. if (sum <= h && halo.length <= parseInt(roleHs)) {
  6334. let roleInfo = [ role.shortMark, roleLv, userInfo[2], roleHs, roleQl ];
  6335. if (role.hasG) {
  6336. roleInfo.splice(1, 0, 'G=' + roleGv);
  6337. }
  6338.  
  6339. let amuletArray = [];
  6340. $('.amulet_item').each(function(i, e) {
  6341. if ($(e).attr('item-selected') == 1) {
  6342. amuletArray[parseInt(e.lastChild.innerText) - 1] = ($(e).attr('original-item'));
  6343. }
  6344. });
  6345.  
  6346. let eqs = [];
  6347. eq_selectors.forEach((eq) => { eqs.push(eq.value); });
  6348.  
  6349. return [ roleInfo, wishpool.slice(-14), amuletArray, rolePt, eqs, halo ];
  6350. }
  6351. return null;
  6352. }
  6353.  
  6354. function generateExportString() {
  6355. let info = collectBindingInfo();
  6356. if (info?.length > 0) {
  6357. let exp = [ info[0].join(' '), 'WISH ' + info[1].join(' ') ];
  6358.  
  6359. let ag = new AmuletGroup();
  6360. ag.name = 'export-temp';
  6361. info[2].forEach((gn) => {
  6362. ag.merge(amuletGroups.get(gn));
  6363. });
  6364. if (ag.isValid()) {
  6365. exp.push(`AMULET ${ag.formatBuffShortMark(' ', ' ', false)} ENDAMULET`);
  6366. }
  6367.  
  6368. exp.push(info[3].join(' '));
  6369.  
  6370. info[4].forEach((eq) => {
  6371. let a = eq.split(',');
  6372. a.splice(2, 2);
  6373. exp.push(a.join(' '));
  6374. });
  6375.  
  6376. let halo = [ info[5].length ];
  6377. info[5].forEach((h) => {
  6378. halo.push(g_haloMap.get(h).shortMark);
  6379. });
  6380. exp.push(halo.join(' '));
  6381.  
  6382. return exp.join('\n') + '\n';
  6383. }
  6384. else {
  6385. alert('有装备未选或光环天赋选择错误!');
  6386. }
  6387. return null;
  6388. }
  6389.  
  6390. function unbindAll() {
  6391. if (confirm('这将清除本卡片全部绑定方案,继续吗?')) {
  6392. let udata = loadUserConfigData();
  6393. if (udata.dataBind[role.id] != null) {
  6394. delete udata.dataBind[role.id];
  6395. }
  6396. saveUserConfigData(udata);
  6397. bindingName.value = BINDING_NAME_DEFAULT;
  6398. bindingList.innerHTML = '';
  6399. refreshBindingSelector(role.id);
  6400. genericPopupShowInformationTips('解除全部绑定成功', 5000);
  6401. }
  6402. };
  6403.  
  6404. function deleteBinding() {
  6405. if (validateBindingName()) {
  6406. bindings = [];
  6407. let found = false;
  6408. $('.binding-name').each((index, item) => {
  6409. if (item.innerText == bindingName.value) {
  6410. bindingList.removeChild(item);
  6411. found = true;
  6412. }
  6413. else {
  6414. bindings.push(`${item.innerText}${BINDING_NAME_SEPARATOR}${item.getAttribute('original-item')}`);
  6415. }
  6416. });
  6417. if (found) {
  6418. let bn = bindingName.value;
  6419. let bi = null;
  6420. let udata = loadUserConfigData();
  6421. if (bindings.length > 0) {
  6422. udata.dataBind[role.id] = bindings.join(BINDING_SEPARATOR);
  6423. bindingName.value = bindingList.children[0].innerText;
  6424. bi = bindingList.children[0].getAttribute('original-item');
  6425. }
  6426. else if(udata.dataBind[role.id] != null) {
  6427. delete udata.dataBind[role.id];
  6428. bindingName.value = BINDING_NAME_DEFAULT;
  6429. }
  6430. saveUserConfigData(udata);
  6431. refreshBindingSelector(role.id);
  6432. representBinding(bi);
  6433. genericPopupShowInformationTips(bn + ':解绑成功', 5000);
  6434. }
  6435. else {
  6436. alert('方案名称未找到!');
  6437. }
  6438. }
  6439. };
  6440.  
  6441. function saveBinding() {
  6442. if (validateBindingName()) {
  6443. let info = collectBindingInfo();
  6444. if (info?.length > 0) {
  6445. let bind_info = [ info[4][0], info[4][1], info[4][2], info[4][3],
  6446. info[5].join(','), info[2].join(',') ].join(BINDING_ELEMENT_SEPARATOR);
  6447. let newBinding = true;
  6448. bindings = [];
  6449. $('.binding-name').each((index, item) => {
  6450. if (item.innerText == bindingName.value) {
  6451. item.setAttribute('original-item', bind_info);
  6452. newBinding = false;
  6453. }
  6454. bindings.push(`${item.innerText}${BINDING_NAME_SEPARATOR}${item.getAttribute('original-item')}`);
  6455. });
  6456. if (newBinding) {
  6457. let li = document.createElement('li');
  6458. li.className = 'binding-name';
  6459. li.innerText = bindingName.value;
  6460. li.setAttribute('original-item', bind_info);
  6461. for (var li0 = bindingList.firstChild; li0?.innerText < li.innerText; li0 = li0.nextSibling);
  6462. bindingList.insertBefore(li, li0);
  6463. bindings.push(`${bindingName.value}${BINDING_NAME_SEPARATOR}${bind_info}`);
  6464. }
  6465.  
  6466. let udata = loadUserConfigData();
  6467. udata.dataBind[role.id] = bindings.join(BINDING_SEPARATOR);
  6468. saveUserConfigData(udata);
  6469. refreshBindingSelector(role.id);
  6470. genericPopupShowInformationTips(bindingName.value + ':绑定成功', 5000);
  6471. }
  6472. else {
  6473. alert('有装备未选或光环天赋选择错误!');
  6474. }
  6475. }
  6476. }
  6477.  
  6478. function isValidBindingName(bindingName) {
  6479. return (bindingName?.length > 0 && bindingName.length < 32 && bindingName.search(USER_STORAGE_RESERVED_SEPARATORS) < 0);
  6480. }
  6481.  
  6482. function validateBindingName() {
  6483. let valid = isValidBindingName(bindingName.value);
  6484. genericPopupShowInformationTips(valid ? null : '方案名称不符合规则,请检查');
  6485. return valid;
  6486. }
  6487.  
  6488. function validateBinding() {
  6489. if (validateBindingName) {
  6490. let ol = bindingList.children.length;
  6491. for (let i = 0; i < ol; i++) {
  6492. if (bindingName.value == bindingList.children[i].innerText) {
  6493. representBinding(bindingList.children[i].getAttribute('original-item'));
  6494. break;
  6495. }
  6496. }
  6497. }
  6498. }
  6499.  
  6500. function representBinding(items) {
  6501. if (items?.length > 0) {
  6502. let elements = items.split(BINDING_ELEMENT_SEPARATOR);
  6503. if (elements.length > 3) {
  6504. let v = elements.slice(0, 4);
  6505. eq_selectors.forEach((eqs) => {
  6506. for (let op of eqs.childNodes) {
  6507. if (v.indexOf(op.value) >= 0) {
  6508. eqs.value = op.value;
  6509. break;
  6510. }
  6511. }
  6512. eqs.onchange({ target : eqs });
  6513. });
  6514. }
  6515. if (elements.length > 4) {
  6516. let hp = 0;
  6517. let hs = 0;
  6518. let v = elements[4].split(',');
  6519. $('.halo_item').each((index, item) => {
  6520. let s = (v.indexOf($(item).attr('original-item')) < 0 ? 0 : 1);
  6521. $(item).attr('item-selected', s);
  6522. $(item).css('background-color', s == 0 ? g_genericPopupBackgroundColor : highlightBackgroundColor);
  6523. hp += (s == 0 ? 0 : parseInt($(item).text().split(' ')[1]));
  6524. hs += s;
  6525. });
  6526. haloPoints.innerText = hp;
  6527. haloSlots.innerText = hs;
  6528. haloPoints.style.color = (hp <= haloMax ? '#0000c0' : 'red');
  6529. haloSlots.style.color = (hs <= roleHs ? '#0000c0' : 'red');
  6530. haloErrors.style.display = (hp <= haloMax && hs <= roleHs ? 'none' : 'inline-block');
  6531. }
  6532. selectedAmuletGroupCount = 0;
  6533. if (elements.length > 5 && amuletCount != null) {
  6534. let ac = 0;
  6535. let v = elements[5].split(',');
  6536. $('.amulet_item').each((index, item) => {
  6537. let j = v.indexOf($(item).attr('original-item'));
  6538. let s = (j < 0 ? 0 : 1);
  6539. $(item).attr('item-selected', s);
  6540. $(item).css('background-color', s == 0 ? g_genericPopupBackgroundColor : highlightBackgroundColor);
  6541. item.lastChild.innerText = (j < 0 ? '' : j + 1);
  6542. selectedAmuletGroupCount += s;
  6543. ac += (s == 0 ? 0 : parseInt($(item).text().match(/\[(\d+)\]/)[1]));
  6544. });
  6545. amuletCount.innerText = ac + ' / ' + bagCells;
  6546. amuletCount.style.color = (ac <= bagCells ? 'blue' : 'red');
  6547. }
  6548. }
  6549. }
  6550.  
  6551. function selector_amulet() {
  6552. let ac = parseInt(amuletCount.innerText);
  6553. let tc = parseInt($(this).text().match(/\[(\d+)\]/)[1]);
  6554. if ($(this).attr('item-selected') != 1) {
  6555. $(this).attr('item-selected', 1);
  6556. $(this).css('background-color', highlightBackgroundColor);
  6557. this.lastChild.innerText = ++selectedAmuletGroupCount;
  6558. ac += tc;
  6559. }
  6560. else {
  6561. $(this).attr('item-selected', 0);
  6562. $(this).css('background-color', g_genericPopupBackgroundColor);
  6563. let i = parseInt(this.lastChild.innerText);
  6564. this.lastChild.innerText = '';
  6565. ac -= tc;
  6566. if (i < selectedAmuletGroupCount) {
  6567. $('.amulet_item').each((index, item) => {
  6568. var j;
  6569. if ($(item).attr('item-selected') == 1 && (j = parseInt(item.lastChild.innerText)) > i) {
  6570. item.lastChild.innerText = j - 1;
  6571. }
  6572. });
  6573. }
  6574. selectedAmuletGroupCount--;
  6575. }
  6576. amuletCount.innerText = ac + ' / ' + bagCells;
  6577. amuletCount.style.color = (ac <= bagCells ? 'blue' : 'red');
  6578. }
  6579.  
  6580. let bindingList = genericPopupQuerySelector('#binding_list').firstChild;
  6581. let bindingName = genericPopupQuerySelector('#binding_name');
  6582. let haloPoints = null;
  6583. let haloSlots = null;
  6584. let haloErrors = null;
  6585. let amuletContainer = genericPopupQuerySelector('#amulet_selector').firstChild;
  6586. let amuletCount = null;
  6587. let amuletGroups = amuletLoadGroups();
  6588. let selectedAmuletGroupCount = 0;
  6589. let bagCells = 8;
  6590.  
  6591. let amuletGroupCount = (amuletGroups?.count() ?? 0);
  6592. if (amuletGroupCount > 0) {
  6593. amuletContainer.innerHTML =
  6594. '护符组:已选定 <span id="amulet_count">0 / 0</span> 个护符' +
  6595. '<span style="float:right;margin-right:5px;">加载顺序</span><p /><ul></ul>';
  6596. amuletCount = genericPopupQuerySelector('#amulet_count');
  6597. amuletCount.style.color = 'blue';
  6598. let amuletArray = amuletGroups.toArray().sort((a, b) => a.name < b.name ? -1 : 1);
  6599. let amuletGroupContainer = amuletContainer.lastChild;
  6600. for (let i = 0; i < amuletGroupCount; i++) {
  6601. let li = document.createElement('li');
  6602. li.className = 'amulet_item';
  6603. li.setAttribute('original-item', amuletArray[i].name);
  6604. li.title = amuletArray[i].formatBuffSummary('', '', '\n', false);
  6605. li.innerHTML =
  6606. `<a href="###">${amuletArray[i].name} [${amuletArray[i].count()}]</a>` +
  6607. `<span style="color:#0000c0;width:40;float:right;margin-right:5px;"></span>`;
  6608. li.onclick = selector_amulet;
  6609. amuletGroupContainer.appendChild(li);
  6610. }
  6611. }
  6612. else {
  6613. amuletContainer.innerHTML =
  6614. '<ul><li>未能读取护符组定义信息,这可能是因为您没有预先完成护符组定义。</li><p />' +
  6615. '<li>将护符与角色卡片进行绑定并不是必须的,但如果您希望使用此功能,' +
  6616. '则必须先定义护符组然后才能将它们与角色卡片进行绑定。</li><p />' +
  6617. '<li>要定义护符组,您需要前往 [ <b style="color:#0000c0;">我的角色 → 武器装备</b> ] 页面,' +
  6618. '并在其中使用将饰品栏内容 [ <b style="color:#0000c0;">存为护符组</b> ] 功能,' +
  6619. '或在 [ <b style="color:#0000c0;">管理护符组</b> ] 相应功能中进行定义。</li></ul>';
  6620. }
  6621.  
  6622. let bindings = null;
  6623. if (bind_info != null) {
  6624. bindings = bind_info.split(BINDING_SEPARATOR).sort((a, b) => {
  6625. a = a.split(BINDING_NAME_SEPARATOR);
  6626. b = b.split(BINDING_NAME_SEPARATOR);
  6627. a = a.length > 1 ? a[0] : BINDING_NAME_DEFAULT;
  6628. b = b.length > 1 ? b[0] : BINDING_NAME_DEFAULT;
  6629. return a < b ? -1 : 1;
  6630. });
  6631. }
  6632. else {
  6633. bindings = [];
  6634. }
  6635.  
  6636. bindings.forEach((item) => {
  6637. let elements = item.split(BINDING_NAME_SEPARATOR);
  6638. let binding = elements[elements.length - 1].split(BINDING_ELEMENT_SEPARATOR);
  6639. if (binding.length > 5) {
  6640. let amuletGroupNames = binding[5].split(',');
  6641. let ag = '';
  6642. let sp = '';
  6643. let al = amuletGroupNames.length;
  6644. for (let i = 0; i < al; i++) {
  6645. if (amuletGroups.contains(amuletGroupNames[i])) {
  6646. ag += (sp + amuletGroupNames[i]);
  6647. sp = ',';
  6648. }
  6649. }
  6650. binding[5] = ag;
  6651. elements[elements.length - 1] = binding.join(BINDING_ELEMENT_SEPARATOR);
  6652. }
  6653.  
  6654. let op = document.createElement('li');
  6655. op.className = 'binding-name';
  6656. op.innerText = (elements.length > 1 ? elements[0] : BINDING_NAME_DEFAULT);
  6657. op.setAttribute('original-item', elements[elements.length - 1]);
  6658. bindingList.appendChild(op);
  6659. });
  6660.  
  6661. let timer = setInterval(() => {
  6662. if (asyncOperations == 0) {
  6663. clearInterval(timer);
  6664. httpRequestClearAll();
  6665.  
  6666. bagCells += parseInt(wishpool[0] ?? 0);
  6667. if (userInfo?.[4]?.length > 0) {
  6668. bagCells += 2;
  6669. }
  6670. if (userInfo?.[5]?.length > 0) {
  6671. bagCells += 5;
  6672. }
  6673. if (amuletCount != null) {
  6674. amuletCount.innerText = '0 / ' + bagCells;
  6675. amuletCount.style.color = 'blue';
  6676. }
  6677.  
  6678. let solutionSelector = document.getElementById(g_bindingListSelectorId);
  6679. let selectedOption = solutionSelector?.options?.[solutionSelector.selectedIndex];
  6680. if (selectedOption != null) {
  6681. bindingName.value = selectedOption.innerText;
  6682. representBinding(selectedOption.value?.split(BINDING_NAME_SEPARATOR)?.[1]);
  6683. }
  6684. else if (bindingList.children.length > 0) {
  6685. bindingName.value = bindingList.children[0].innerText;
  6686. representBinding(bindingList.children[0].getAttribute('original-item'));
  6687. }
  6688. else {
  6689. bindingName.value = BINDING_NAME_DEFAULT;
  6690. }
  6691.  
  6692. bindingName.oninput = validateBindingName;
  6693. bindingName.onchange = validateBinding;
  6694. bindingList.onclick = ((e) => {
  6695. let li = e.target;
  6696. if (li.tagName == 'LI') {
  6697. bindingName.value = li.innerText;
  6698. representBinding(li.getAttribute('original-item'));
  6699. }
  6700. });
  6701.  
  6702. genericPopupQuerySelector('#copy_export_string').onclick = (() => {
  6703. genericPopupQuerySelector('#role_export_string').select();
  6704. if (document.execCommand('copy')) {
  6705. genericPopupShowInformationTips('导出内容已复制到剪贴板', 5000);
  6706. }
  6707. else {
  6708. genericPopupShowInformationTips('复制失败,请进行手工复制(CTRL+A, CTRL+C)');
  6709. }
  6710. });
  6711.  
  6712. genericPopupQuerySelector('#hide_export_div').onclick = (() => {
  6713. genericPopupQuerySelector('#role_export_div').style.display = 'none';
  6714. });
  6715.  
  6716. genericPopupSetContentSize(Math.min((haloGroupItemMax + amuletGroupCount) * 20
  6717. + (amuletGroupCount > 0 ? 60 : 160) + 260,
  6718. window.innerHeight - 200),
  6719. 680, true);
  6720.  
  6721. genericPopupAddButton('解除绑定', 0, deleteBinding, true);
  6722. genericPopupAddButton('全部解绑', 0, unbindAll, true);
  6723. genericPopupAddButton('绑定', 80, saveBinding, false);
  6724. genericPopupAddButton(
  6725. '导出计算器',
  6726. 0,
  6727. () => {
  6728. let string = generateExportString();
  6729. if (string?.length > 0) {
  6730. genericPopupQuerySelector('#role_export_string').value = string;
  6731. genericPopupQuerySelector('#role_export_div').style.display = 'block';
  6732. }
  6733. },
  6734. false);
  6735. genericPopupAddCloseButton(80);
  6736.  
  6737. genericPopupCloseProgressMessage();
  6738. genericPopupShowModal(true);
  6739. }
  6740. }, 200);
  6741. }
  6742.  
  6743. function showCalcConfigGenPopup() {
  6744. let role = g_roleMap.get(backpacksDiv.querySelector('div.row > div.col-md-3 > span.text-info.fyg_f24')?.innerText);
  6745. let cardInfos = backpacksDiv.querySelectorAll('.icon.icon-angle-down.text-primary');
  6746. let roleLv = cardInfos[0].innerText.match(/\d+/)[0];
  6747. let roleQl = cardInfos[1].innerText.match(/\d+/)[0];
  6748. let roleHs = cardInfos[2].innerText.match(/\d+/)[0];
  6749. let roleGv = (cardInfos[3]?.innerText.match(/\d+/)[0] ?? '0');
  6750. let roleTotalPt = Math.trunc((roleLv * 3 + 6) * (1 + roleQl / 100));
  6751. let rolePt = [];
  6752. for (let i = 1; i <= 6; i++) {
  6753. rolePt.push(document.getElementById('sjj' + i).innerText);
  6754. }
  6755. if (role == null || roleLv == null || roleQl == null || roleHs == null) {
  6756. alert('读取卡片信息失败,无法执行配置生成操作!');
  6757. return;
  6758. }
  6759.  
  6760. genericPopupInitialize();
  6761. genericPopupShowProgressMessage('读取中,请稍候...');
  6762.  
  6763. const monsters = [
  6764. {
  6765. name : '六边形战士',
  6766. shortMark : 'LIU'
  6767. },
  6768. {
  6769. name : '铁皮木人',
  6770. shortMark : 'MU2'
  6771. },
  6772. {
  6773. name : '迅捷魔蛛',
  6774. shortMark : 'ZHU2'
  6775. },
  6776. {
  6777. name : '魔灯之灵',
  6778. shortMark : 'DENG2'
  6779. },
  6780. {
  6781. name : '食铁兽',
  6782. shortMark : 'SHOU2'
  6783. },
  6784. {
  6785. name : '六眼飞鱼',
  6786. shortMark : 'YU2'
  6787. },
  6788. {
  6789. name : '晶刺豪猪',
  6790. shortMark : 'HAO2'
  6791. }
  6792. ];
  6793.  
  6794. let fixedContent =
  6795. '<div style="padding:20px 10px 10px 0px;color:blue;font-size:16px;"><b><ul>' +
  6796. '<li>初次使用本功能时请先仔细阅读咕咕镇计算器相关资料及此后各部分设置说明以便对其中涉及到的概念及元素建立基本认识</li>' +
  6797. '<li>此功能只生成指定角色的PVE配置,若需供其他角色使用请在相应角色页面使用此功能或自行正确修改配置</li>' +
  6798. '<li>此功能只生成计算器可用的基础PVE配置,若需使用计算器提供的其它高级功能请自行正确修改配置</li>' +
  6799. '<li>此功能并未进行完整的数据合法性检查,并不保证生成的配置100%正确,所以请仔细阅读说明并正确使用各项设置</li>' +
  6800. `<li id="${g_genericPopupInformationTipsId}" style="color:red;">` +
  6801. '保存模板可保存当前设置,每次保存均会覆盖前一次保存的设置,保存模板后再次进入此功能时将自动加载最后一次保存的设置</li></ul></b></div>';
  6802. const mainStyle =
  6803. '<style> .group-menu { position:relative;' +
  6804. 'display:inline-block;' +
  6805. 'color:blue;' +
  6806. 'font-size:20px;' +
  6807. 'cursor:pointer; } ' +
  6808. '.group-menu-items { display:none;' +
  6809. 'position:absolute;' +
  6810. 'font-size:15px;' +
  6811. 'word-break:keep-all;' +
  6812. 'white-space:nowrap;' +
  6813. 'margin:0 auto;' +
  6814. 'width:fit-content;' +
  6815. 'z-index:999;' +
  6816. 'background-color:white;' +
  6817. 'box-shadow:0px 2px 16px 4px rgba(0, 0, 0, 0.4);' +
  6818. 'padding:15px 30px; } ' +
  6819. '.group-menu-item { } ' +
  6820. '.group-menu:hover .group-menu-items { display:block; } ' +
  6821. '.group-menu-items .group-menu-item:hover { background-color:#bbddff; } ' +
  6822. '.section-help-text { font-size:15px; color:navy; } ' +
  6823. 'b > span { color:purple; } ' +
  6824. 'button.btn-group-selection { width:80px; float:right; } ' +
  6825. 'table.mon-list { width:100%; } ' +
  6826. 'table.mon-list th.mon-name { width:25%; text-align:left; } ' +
  6827. 'table.mon-list th.mon-progress { width:25%; text-align:left; } ' +
  6828. 'table.mon-list th.mon-level { width:25%; text-align:left; } ' +
  6829. 'table.mon-list th.mon-baselevel { width:25%; text-align:left; } ' +
  6830. 'table.role-info { width:100%; } ' +
  6831. 'table.role-info th.role-item { width:30%; text-align:left; } ' +
  6832. 'table.role-info th.role-points { width:10%; text-align:left; } ' +
  6833. 'table.role-info th.role-operation { width:10%; text-align:center; } ' +
  6834. 'table.equip-list { width:100%; } ' +
  6835. 'table.equip-list th.equip-name { width:44%; text-align:left; } ' +
  6836. 'table.equip-list th.equip-property { width:14%; text-align:left; } ' +
  6837. 'table.misc-config { width:100%; } ' +
  6838. 'table.misc-config th { width:20%; text-align:center; } ' +
  6839. 'table.misc-config td { text-align:center; } ' +
  6840. 'table tr.alt { background-color:' + g_genericPopupBackgroundColorAlt + '; } ' +
  6841. '</style>';
  6842. const menuItems =
  6843. '<div class="group-menu-items"><ul>' +
  6844. '<li class="group-menu-item"><a href="#mon-div">野怪</a></li>' +
  6845. '<li class="group-menu-item"><a href="#role-div">角色</a></li>' +
  6846. '<li class="group-menu-item"><a href="#equips1-div">武器装备</a></li>' +
  6847. '<li class="group-menu-item"><a href="#equips2-div">手臂装备</a></li>' +
  6848. '<li class="group-menu-item"><a href="#equips3-div">身体装备</a></li>' +
  6849. '<li class="group-menu-item"><a href="#equips4-div">头部装备</a></li>' +
  6850. '<li class="group-menu-item"><a href="#halo-div">光环</a></li>' +
  6851. '<li class="group-menu-item"><a href="#amulet-div">护符</a></li>' +
  6852. '<li class="group-menu-item"><a href="#misc-div">其它</a></li><hr>' +
  6853. '<li class="group-menu-item"><a href="#result-div">生成结果</a></li>' +
  6854. '</ul></div>';
  6855. const monTable =
  6856. '<table class="mon-list"><tr class="alt"><th class="mon-name">名称</th><th class="mon-progress">段位进度(0% - 100%)</th>' +
  6857. '<th class="mon-level">进度等级</th><th class="mon-baselevel">基础等级(0%进度)</th></tr></table>';
  6858. const roleTable =
  6859. '<table class="role-info" id="role-info"><tr class="alt"><th class="role-item">设置</th>' +
  6860. '<th class="role-points">力量</th><th class="role-points">敏捷</th><th class="role-points">智力</th>' +
  6861. '<th class="role-points">体魄</th><th class="role-points">精神</th><th class="role-points">意志</th>' +
  6862. '<th class="role-operation">操作</th></tr><tr>' +
  6863. '<td>属性点下限(须大于0)<span id ="role-points-summary" style="float:right;margin-right:5px;"></span></td>' +
  6864. '<td><input type="text" style="width:90%;" value="1" oninput="value=value.replace(/[^\\d]/g,\'\');" /></td>' +
  6865. '<td><input type="text" style="width:90%;" value="1" oninput="value=value.replace(/[^\\d]/g,\'\');" /></td>' +
  6866. '<td><input type="text" style="width:90%;" value="1" oninput="value=value.replace(/[^\\d]/g,\'\');" /></td>' +
  6867. '<td><input type="text" style="width:90%;" value="1" oninput="value=value.replace(/[^\\d]/g,\'\');" /></td>' +
  6868. '<td><input type="text" style="width:90%;" value="1" oninput="value=value.replace(/[^\\d]/g,\'\');" /></td>' +
  6869. '<td><input type="text" style="width:90%;" value="1" oninput="value=value.replace(/[^\\d]/g,\'\');" /></td>' +
  6870. '<td><button type="button" class="role-points-text-reset" style="width:100%;" value="1">重置</td></tr><tr class="alt">' +
  6871. '<td>属性点上限(0为无限制)</td>' +
  6872. '<td><input type="text" style="width:90%;" value="0" oninput="value=value.replace(/[^\\d]/g,\'\');" /></td>' +
  6873. '<td><input type="text" style="width:90%;" value="0" oninput="value=value.replace(/[^\\d]/g,\'\');" /></td>' +
  6874. '<td><input type="text" style="width:90%;" value="0" oninput="value=value.replace(/[^\\d]/g,\'\');" /></td>' +
  6875. '<td><input type="text" style="width:90%;" value="0" oninput="value=value.replace(/[^\\d]/g,\'\');" /></td>' +
  6876. '<td><input type="text" style="width:90%;" value="0" oninput="value=value.replace(/[^\\d]/g,\'\');" /></td>' +
  6877. '<td><input type="text" style="width:90%;" value="0" oninput="value=value.replace(/[^\\d]/g,\'\');" /></td>' +
  6878. '<td><button type="button" class="role-points-text-reset" style="width:100%;" value="0">重置</td>' +
  6879. '</tr></table>';
  6880. const equipTable =
  6881. '<table class="equip-list"><tr class="alt"><th class="equip-name">装备</th><th class="equip-property">属性</th>' +
  6882. '<th class="equip-property"></th><th class="equip-property"></th><th class="equip-property"></th></tr></table>';
  6883. const miscTable =
  6884. '<table class="misc-config"><tr class="alt">' +
  6885. '<th>计算线程数</th><th>最大组合数</th><th>单组测试次数</th><th>置信区间测试阈值(%)</th><th>输出计算进度</th></tr><tr>' +
  6886. '<td><input type="text" style="width:90%;" original-item="THREADS" value="4" oninput="value=value.replace(/[^\\d]/g,\'\');" /></td>' +
  6887. '<td><input type="text" style="width:90%;" original-item="SEEDMAX" value="1000000" oninput="value=value.replace(/[^\\d]/g,\'\');" /></td>' +
  6888. '<td><input type="text" style="width:90%;" original-item="TESTS" value="1000" oninput="value=value.replace(/[^\\d]/g,\'\');" /></td>' +
  6889. '<td><input type="text" style="width:90%;" original-item="CITEST" value="1.0" oninput="value=value.replace(/[^\\d.]/g,\'\');" /></td>' +
  6890. '<td><input type="text" style="width:90%;" original-item="VERBOSE" value="1" oninput="value=value.replace(/[^\\d]/g,\'\');" /></td></tr></table>';
  6891. const btnGroup =
  6892. '<button type="button" class="btn-group-selection" select-type="2">反选</button>' +
  6893. '<button type="button" class="btn-group-selection" select-type="1">全不选</button>' +
  6894. '<button type="button" class="btn-group-selection" select-type="0">全选</button>';
  6895. const mainContent =
  6896. `${mainStyle}
  6897. <div class="${g_genericPopupTopLineDivClass}" id="mon-div">
  6898. <b class="group-menu">野怪设置 (选中 <span>0</span>) ▼${menuItems}</b>${btnGroup}<hr>
  6899. <span class="section-help-text">` +
  6900. `只有勾选行的野怪信息才会被写入配置,且这些信息与选定角色相关。段位进度和等级必须对应,例如选定卡片当前段位60%进度迅捷魔蛛` +
  6901. `的等级为200级,则在迅捷魔蛛一行的段位进度栏填60,等级栏填200,程序将自动计算得到0%进度迅捷魔蛛的估计基础等级为167。</span>
  6902. <hr>${monTable}<hr><b style="display:inline-block;width:100%;text-align:center;">起始进度 ` +
  6903. `<input type="text" class="mon-batch-data" style="width:40px;" maxlength="3" value="0"
  6904. oninput="value=value.replace(/[^\\d]/g,'');" /> %,以 ` +
  6905. `<input type="text" class="mon-batch-data" style="width:40px;" maxlength="2" value="0"
  6906. oninput="value=value.replace(/[^\\d]/g,'');" /> % 进度差或以 ` +
  6907. `<input type="text" class="mon-batch-data" style="width:40px;" maxlength="3" value="0"
  6908. oninput="value=value.replace(/[^\\d]/g,'');" /> 级差为间隔额外生成 ` +
  6909. `<input type="text" class="mon-batch-data" style="width:40px;" maxlength="1" value="0"
  6910. oninput="value=value.replace(/[^\\d]/g,'');" /> 批野怪数据</b><hr>
  6911. <span class="section-help-text"">此功能可以生成多批阶梯等级的野怪配置,计算器可根据这些信息计算当野怪等级` +
  6912. `在一定范围内浮动时的近似最优策略。野怪的等级由其基础等级及进度加成共同决定(进度等级=基础等级×(1+(进度÷300))),` +
  6913. `多批之间的级差可由进度差或绝对级差指定,当进度差和绝对级差同时被指定(均大于0)且需生成多批数据(额外生成大于0)时默认使用` +
  6914. `进度差进行计算,当进度差和绝对级差同时为0或额外生成为0时将不会生成额外批次数据。需要注意的是(起始进度+(进度差×批次数))` +
  6915. `允许大于100,因为大于100的进度仍然可以计算得到有效的野怪等级。</span></div>
  6916. <div class="${g_genericPopupTopLineDivClass}" id="role-div">
  6917. <b class="group-menu">角色基础设置 ${role.name},${roleLv}级,${roleQl}%品质,${role.hasG ? `${roleGv}成长值,` : ''}` +
  6918. `${roleTotalPt}属性点) ${menuItems}</b><hr><span class="section-help-text">` +
  6919. `属性点下限初始值为指定角色当前点数分配方案,直接使用这些值主要用于胜率验证、装备及光环技能选择等情况,全部置1表示由计算器从` +
  6920. `头开始计算近似最佳点数分配(该行末的重置按钮将属性点下限全部置1)。也可为各点数设置合理的下限值(必须大于0且总和小于等于总` +
  6921. `可用属性点数)并由计算器分配剩余点数,这一般用于角色升级后可用点数增加、指定加点方案大致方向并进行装备、光环选择等情况,在` +
  6922. `其它条件相同的情况下,越少的剩余点数将节约越多的计算时间。属性点上限用于指定特定属性点数分配的上限,设为0表示无限制。合理地` +
  6923. `设置上限可以节约计算时间,典型的应用场景为将某些明确无需加点的属性上限设为1(例如3速角色的敏捷、血量系的精神等,以及通常情况` +
  6924. `下梦、默仅敏捷、智力、精神为0,其它皆为1,当然特殊加点除外),而将其它设为0(该行末的重置按钮将属性点上限全部置0)。除非上限` +
  6925. `值设为0(无限制),否则请务必保证相应的下限值不超过上限值,非法设置将导致计算器运行错误。</span><hr>
  6926. <input type="checkbox" id="role-useWishpool" checked /><label for="role-useWishpool"
  6927. style="margin-left:5px;cursor:pointer;">使用许愿池数据</label><hr>${roleTable}</div>
  6928. <div class="${g_genericPopupTopLineDivClass}" id ="equips1-div">
  6929. <b class="group-menu">武器装备 (选中 <span>0</span>) ▼${menuItems}</b>${btnGroup}<hr>
  6930. <span class="section-help-text">` +
  6931. `某类装备中如果只选中其中一件则意味着固定使用此装备;选中多件表示由计算器从选中的装备中选择一件合适(不保证最优)的装备;` +
  6932. `不选等同于全选,即由计算器在全部同类装备中进行选择。一般原则是尽可能多地固定使用装备,留给计算器的选择越多意味着计算所花` +
  6933. `的时间将越长(根据其它设置及硬件算力,可能长至数天)。</span><hr>${equipTable}</div>
  6934. <div class="${g_genericPopupTopLineDivClass}" id="equips2-div">
  6935. <b class="group-menu">手臂装备 (选中 <span>0</span>) ▼${menuItems}</b>${btnGroup}<p />${equipTable}</div>
  6936. <div class="${g_genericPopupTopLineDivClass}" id="equips3-div">
  6937. <b class="group-menu">身体装备 (选中 <span>0</span>) ▼${menuItems}</b>${btnGroup}<p />${equipTable}</div>
  6938. <div class="${g_genericPopupTopLineDivClass}" id="equips4-div">
  6939. <b class="group-menu">头部装备 (选中 <span>0</span>) ▼${menuItems}</b>${btnGroup}<p />${equipTable}</div>
  6940. <div class="${g_genericPopupTopLineDivClass}" id="halo-div">
  6941. <b class="group-menu">光环技能 ${menuItems}</b><hr><span class="section-help-text">` +
  6942. `在选用的光环技能栏选择基本可以确定使用的的光环技能(例如血量重剑系几乎肯定会带沸血之志而护盾法系及某些反伤系带波澜不惊的` +
  6943. `可能性非常大),如果设置正确(光环点数未超范围)则计算器只需补齐空闲的技能位,所以这里指定的光环越多则计算所需时间越少。` +
  6944. `排除的光环用于指定几乎不可能出现在计算结果中的光环(例如护盾系可以排除沸血之志而法系基本可排除破壁之心,在技能位不足的情` +
  6945. `况下启程系列可以考虑全部排除),计算器在寻找优势方案时不会使用这些光环技能进行尝试,所以在有空闲技能位和光环点数充足的情况` +
  6946. `下,排除的光环技能越多则所需计算时间越少。选用与排除的技能允许重复,如果发生这种情况将强制选用。</span><hr>
  6947. <div style="width:100%;font-size:15px;"><div id="halo_selector"></div></div></div>
  6948. <div class="${g_genericPopupTopLineDivClass}" id ="amulet-div">
  6949. <b class="group-menu">护符 ${menuItems}</b><hr><span class="section-help-text">` +
  6950. `护符配置可以省略,或由当前饰品栏内容决定,如果有预先定义的护符组也可以使用护符组的组合。使用第二及第三种方式时需考虑饰品栏容` +
  6951. `量(包括许愿池的饰品栏加成及时限)。</span><hr><div style="font-size:15px;">
  6952. <input type="radio" class="amulet-config" name="amulet-config" id="amulet-config-none" />
  6953. <label for="amulet-config-none" style="cursor:pointer;margin-left:5px;">无</label><br>
  6954. <input type="radio" class="amulet-config" name="amulet-config" id="amulet-config-bag" checked />
  6955. <label for="amulet-config-bag" style="cursor:pointer;margin-left:5px;">当前饰品栏内容(悬停查看)</label><br>
  6956. <input type="radio" class="amulet-config" name="amulet-config" id="amulet-config-groups" />
  6957. <label for="amulet-config-groups" style="cursor:pointer;margin-left:5px;">护符组(在组名称上悬停查看)</label>
  6958. <div id="amulet_selector" style="display:block;padding:0px 20px 0px 20px;"></div></div></div>
  6959. <div class="${g_genericPopupTopLineDivClass}" id ="misc-div">
  6960. <b class="group-menu">其它 ${menuItems}</b><hr><span class="section-help-text">` +
  6961. `除非清楚修改以下配置项将会造成的影响,否则如无特殊需要请保持默认值。</span><ul class="section-help-text">` +
  6962. `<li>计算线程数:计算所允许使用的最大线程数,较大的值可以提高并行度从而减少计算用时,但超出处理器物理限制将适得其反,` +
  6963. `合理的值应小于处理器支持的物理线程数(推荐值:处理器物理线程数-1或-2)</li>` +
  6964. `<li>最大组合数:如果给定配置所产生的组合数超过此值将会造成精度下降,但过大的值可能会造成内存不足,且过大的组合数需求` +
  6965. `通常意味着待定项目过多,计算将异常耗时,请尝试多固定一些装备及光环技能项,多排除一些无用的光环技能项</li>` +
  6966. `<li>单组测试次数:特定的点数分配、装备、光环等组合与目标战斗过程的模拟次数,较高的值一般会产生可信度较高的结果,但会` +
  6967. `消耗较长的计算时间(此设置仅在置信区间测试阈值设为0时生效)</li>` +
  6968. `<li>置信区间测试阈值:不使用固定的测试次数而以置信区间阈值代替,可有小数部份。当测试结果的置信区间达到此值时计算终止,` +
  6969. `此设置生效(不为0)时单组测试次数设置将被忽略</li>` +
  6970. `<li>输出计算进度:1为计算过程中在命令行窗口中显示计算时间、进度等信息,0为无显示</li></ul><hr>${miscTable}</div>
  6971. <div class="${g_genericPopupTopLineDivClass}" id="result-div">
  6972. <b class="group-menu">生成配置 ${menuItems}</b><hr><span class="section-help-text">` +
  6973. `生成配置文本后一种方式是将其内容复制至计算器目录中的“newkf.in”文件替换其内容并保存(使用文本编辑器),然后运行计算器` +
  6974. `执行文件(32位系统:newkf.batnewkf.exe64位系统:newkf_64.batnewkf_64.exe)在其中输入anpc(小写)命令并` +
  6975. `回车然后等待计算完成。另一种使用方式是将生成的配置文本另存为一个ansi编码(重要)的文本文件,名称自定,然后将此文件用` +
  6976. `鼠标拖放至前述的计算器执行文件上,待程序启动后同样使用anpc命令开始计算。</span><hr><div style="height:200px;">
  6977. <textarea id="export-result" style="height:100%;width:100%;resize:none;"></textarea></div>
  6978. <div style="padding:10px 0px 20px 0px;">
  6979. <button type="button" style="float:right;" id="copy-to-clipboard">复制导出内容至剪贴板</button>
  6980. <button type="button" style="float:right;" id="save-template-do-export">保存模板并生成配置</button>
  6981. <button type="button" style="float:right;" id="do-export">生成配置</button></div></div>`;
  6982.  
  6983. genericPopupSetFixedContent(fixedContent);
  6984. genericPopupSetContent('咕咕镇计算器配置生成(PVE)', mainContent);
  6985.  
  6986. genericPopupQuerySelectorAll('button.btn-group-selection').forEach((btn) => { btn.onclick = batchSelection; });
  6987. function batchSelection(e) {
  6988. let selType = parseInt(e.target.getAttribute('select-type'));
  6989. let selCount = 0;
  6990. e.target.parentNode.querySelectorAll('input.generic-checkbox').forEach((chk) => {
  6991. if (chk.checked = (selType == 2 ? !chk.checked : selType == 0)) {
  6992. selCount++;
  6993. }
  6994. });
  6995. e.target.parentNode.firstElementChild.firstElementChild.innerText = selCount;
  6996. }
  6997.  
  6998. function countGenericCheckbox(div) {
  6999. let selsum = 0;
  7000. genericPopupQuerySelectorAll(`${div} input.generic-checkbox`).forEach((e) => {
  7001. if (e.checked) {
  7002. selsum++;
  7003. }
  7004. });
  7005. genericPopupQuerySelector(`${div} b span`).innerText = selsum;
  7006. }
  7007.  
  7008. let asyncOperations = 4;
  7009. let equipItemCount = 0;
  7010. let bag = [];
  7011. let store = [];
  7012. beginReadObjects(
  7013. bag,
  7014. store,
  7015. () => {
  7016. let equipment = equipmentNodesToInfoArray(store);
  7017. equipmentNodesToInfoArray(cardingDiv.querySelectorAll(cardingObjectsQueryString), equipment);
  7018.  
  7019. let eqIndex = 0;
  7020. let eq_selectors = genericPopupQuerySelectorAll('table.equip-list');
  7021. equipment.sort((e1, e2) => {
  7022. if (e1[0] != e2[0]) {
  7023. return (g_equipMap.get(e1[0]).index - g_equipMap.get(e2[0]).index);
  7024. }
  7025. return -equipmentInfoComparer(e1, e2);
  7026. }).forEach((item) => {
  7027. let eqMeta = g_equipMap.get(item[0]);
  7028. let lv = objectGetLevel(item);
  7029. let tr = document.createElement('tr');
  7030. tr.style.backgroundColor = g_equipmentLevelBGColor[lv];
  7031. tr.innerHTML =
  7032. `<td><input type="checkbox" class="generic-checkbox equip-checkbox equip-item" id="equip-${++eqIndex}"
  7033. original-item="${item.slice(0, -1).join(' ')}" />
  7034. <label for="equip-${eqIndex}" style="margin-left:5px;cursor:pointer;">
  7035. ${eqMeta.alias} - Lv.${item[1]} (攻.${item[2]} 防.${item[3]}) ` +
  7036. `${item[8] == 1 ? ' - [ 神秘 ]' : ''}</label></td>
  7037. <td>${formatEquipmentAttributes(item, '</td><td>')}</td>`;
  7038. eq_selectors[eqMeta.type].appendChild(tr);
  7039. });
  7040. equipItemCount = equipment.length;
  7041.  
  7042. let bagGroup = amuletCreateGroupFromArray('temp', amuletNodesToArray(bag));
  7043. if (bagGroup?.isValid()) {
  7044. let radio = genericPopupQuerySelector('#amulet-config-bag');
  7045. radio.setAttribute('original-item', `AMULET ${bagGroup.formatBuffShortMark(' ', ' ', false)} ENDAMULET`);
  7046. radio.nextElementSibling.title = radio.title = bagGroup.formatBuffSummary('', '', '\n', false);
  7047. }
  7048. asyncOperations--;
  7049. },
  7050. null);
  7051.  
  7052. const highlightBackgroundColor = '#80c0f0';
  7053. let haloMax = 0;
  7054. let haloPoints = null;
  7055. let haloSlots = null;
  7056. let haloErrors = null;
  7057. let currentHalo;
  7058. beginReadHaloInfo(
  7059. currentHalo = [],
  7060. () => {
  7061. haloMax = currentHalo[0];
  7062. let haloInfo =
  7063. `天赋点:<span style="color:#0000c0;"><span id="halo_points">0</span> / ${haloMax}</span>,` +
  7064. `技能位:<span style="color:#0000c0;"><span id="halo_slots">0</span> / ${roleHs}</span>` +
  7065. `<b id="halo_errors" style="display:none;color:red;margin-left:15px;">(光环天赋点数 / 角色卡片技能位不足)</b>`;
  7066. let haloSelector = genericPopupQuerySelector('#halo_selector');
  7067. haloSelector.innerHTML =
  7068. `<style>
  7069. .halo_group { display:block; width:25%; float:left; text-align:center; border-left:1px solid grey; }
  7070. .halo_group_exclude { display:block; width:25%; float:left; text-align:center; border-left:1px solid grey; }
  7071. div > a { display:inline-block; width:90%; } </style>
  7072. <b style="margin-right:15px;">选用的光环技能:</b>${haloInfo}
  7073. <p />
  7074. <div style="display:table;">
  7075. <div class="halo_group"></div>
  7076. <div class="halo_group"></div>
  7077. <div class="halo_group"></div>
  7078. <div class="halo_group" style="border-right:1px solid grey;"></div></div>
  7079. <div style="display:table;width:100%;margin-top:15px;padding-top:10px;border-top:1px solid lightgrey;">
  7080. <b>排除的光环技能:</b>
  7081. <p />
  7082. </div>
  7083. <div style="display:table;">
  7084. <div class="halo_group_exclude"></div>
  7085. <div class="halo_group_exclude"></div>
  7086. <div class="halo_group_exclude"></div>
  7087. <div class="halo_group_exclude" style="border-right:1px solid grey;"></div></div>`;
  7088. let haloGroups = haloSelector.querySelectorAll('.halo_group');
  7089. let haloExGroups = haloSelector.querySelectorAll('.halo_group_exclude');
  7090. let group = -1;
  7091. let points = -1;
  7092. g_halos.forEach((item) => {
  7093. if (item.points != points) {
  7094. points = item.points;
  7095. group++;
  7096. }
  7097. let a = document.createElement('a');
  7098. a.href = '###';
  7099. a.className = 'halo_item';
  7100. a.innerText = item.name + ' ' + item.points;
  7101. haloGroups[group].appendChild(a.cloneNode(true));
  7102. a.className = 'halo_item_exclude';
  7103. haloExGroups[group].appendChild(a);
  7104. });
  7105.  
  7106. function selector_halo() {
  7107. let hp = parseInt(haloPoints.innerText);
  7108. let hs = parseInt(haloSlots.innerText);
  7109. if ($(this).attr('item-selected') != 1) {
  7110. $(this).attr('item-selected', 1);
  7111. $(this).css('background-color', highlightBackgroundColor);
  7112. hp += parseInt($(this).text().split(' ')[1]);
  7113. hs++;
  7114. }
  7115. else {
  7116. $(this).attr('item-selected', 0);
  7117. $(this).css('background-color', g_genericPopupBackgroundColor);
  7118. hp -= parseInt($(this).text().split(' ')[1]);
  7119. hs--;
  7120. }
  7121. haloPoints.innerText = hp;
  7122. haloSlots.innerText = hs;
  7123. haloPoints.style.color = (hp <= haloMax ? '#0000c0' : 'red');
  7124. haloSlots.style.color = (hs <= roleHs ? '#0000c0' : 'red');
  7125. haloErrors.style.display = (hp <= haloMax && hs <= roleHs ? 'none' : 'inline-block');
  7126. }
  7127.  
  7128. haloPoints = genericPopupQuerySelector('#halo_points');
  7129. haloSlots = genericPopupQuerySelector('#halo_slots');
  7130. haloErrors = genericPopupQuerySelector('#halo_errors');
  7131. $('.halo_item').each(function(i, e) {
  7132. $(e).on('click', selector_halo);
  7133. $(e).attr('original-item', $(e).text().split(' ')[0]);
  7134. });
  7135.  
  7136. function selector_halo_exclude() {
  7137. if ($(this).attr('item-selected') != 1) {
  7138. $(this).attr('item-selected', 1);
  7139. $(this).css('background-color', highlightBackgroundColor);
  7140. }
  7141. else {
  7142. $(this).attr('item-selected', 0);
  7143. $(this).css('background-color', g_genericPopupBackgroundColor);
  7144. }
  7145. }
  7146.  
  7147. $('.halo_item_exclude').each(function(i, e) {
  7148. $(e).on('click', selector_halo_exclude);
  7149. $(e).attr('original-item', $(e).text().split(' ')[0]);
  7150. });
  7151. asyncOperations--;
  7152. },
  7153. null);
  7154.  
  7155. if (wishpool.length == 0) {
  7156. beginReadWishpool(wishpool, null, () => { asyncOperations--; }, null);
  7157. }
  7158. else {
  7159. asyncOperations--;
  7160. }
  7161. if (userInfo.length == 0) {
  7162. beginReadUserInfo(userInfo, () => { asyncOperations--; });
  7163. }
  7164. else {
  7165. asyncOperations--;
  7166. }
  7167.  
  7168. let mon_selector = genericPopupQuerySelector('table.mon-list');
  7169. monsters.forEach((e, i) => {
  7170. let tr = document.createElement('tr');
  7171. tr.className = 'mon-row' + ((i & 1) == 0 ? '' : ' alt');
  7172. tr.setAttribute('original-item', e.shortMark);
  7173. tr.innerHTML =
  7174. `<td><input type="checkbox" class="generic-checkbox mon-checkbox mon-item" id="mon-item-${i}"${i == 0 ? ' checked' : ''} />
  7175. <label for="mon-item-${i}" style="margin-left:5px;cursor:pointer;">${e.name}</label></td>
  7176. <td><input type="text" class="mon-textbox" style="width:80%;" maxlength="3" value="0"
  7177. oninput="value=value.replace(/[^\\d]/g,'');" /> %</td>
  7178. <td><input type="text" class="mon-textbox" style="width:80%;" value="1"
  7179. oninput="value=value.replace(/[^\\d]/g,'');" /></td>
  7180. <td>1</td>`;
  7181. mon_selector.appendChild(tr);
  7182. });
  7183. mon_selector.querySelectorAll('input.mon-textbox').forEach((e) => { e.onchange = monDataChange; });
  7184. function monDataChange(e) {
  7185. let tr = e.target.parentNode.parentNode;
  7186. let p = parseInt(tr.children[1].firstChild.value);
  7187. let l = parseInt(tr.children[2].firstChild.value);
  7188. if (!isNaN(p) && !isNaN(l) && p >= 0 && p <= 100 && l > 0) {
  7189. tr.children[3].innerText = Math.ceil(l / (1 + (p / 300)));
  7190. }
  7191. else {
  7192. tr.children[3].innerHTML = '<b style="color:red;">输入不合法</b>';
  7193. }
  7194. }
  7195. countGenericCheckbox('#mon-div');
  7196.  
  7197. let roleInfo = genericPopupQuerySelector('#role-info');
  7198. let rolePtsSum = roleInfo.querySelector('#role-points-summary');
  7199. let textPts = roleInfo.querySelectorAll('input');
  7200. for (let i = 0; i < 6; i++) {
  7201. textPts[i].value = rolePt[i];
  7202. textPts[i].onchange = rolePtsChanged;
  7203. }
  7204. rolePtsChanged();
  7205. function rolePtsChanged() {
  7206. let ptsSum = 0;
  7207. for (let i = 0; i < 6; i++) {
  7208. let pt = parseInt(textPts[i].value);
  7209. if (isNaN(pt) || pt < 1) {
  7210. textPts[i].value = '1';
  7211. pt = 1;
  7212. }
  7213. ptsSum += pt;
  7214. }
  7215. rolePtsSum.innerText = `(${ptsSum} / ${roleTotalPt})`;
  7216. rolePtsSum.style.color = (ptsSum > roleTotalPt ? 'red' : 'blue');
  7217. }
  7218. roleInfo.querySelectorAll('button.role-points-text-reset').forEach((item) => {
  7219. item.onclick = ((e) => {
  7220. e.target.parentNode.parentNode.querySelectorAll('input[type="text"]').forEach((item) => {
  7221. item.value = e.target.value;
  7222. });
  7223. if (e.target.value == '1') {
  7224. rolePtsChanged();
  7225. }
  7226. });
  7227. });
  7228.  
  7229. let amuletRadioGroup = genericPopupQuerySelectorAll('#amulet-div input.amulet-config');
  7230. let bagCells = 8;
  7231. let amuletContainer = genericPopupQuerySelector('#amulet_selector');
  7232. amuletContainer.innerHTML = '护符组:已选定 <span id="amulet_count">0 / 0</span> 个护符<p /><ul></ul>';
  7233. let amuletCount = genericPopupQuerySelector('#amulet_count');
  7234. amuletCount.style.color = 'blue';
  7235. let amuletGroups = amuletLoadGroups();
  7236. let amuletGroupCount = (amuletGroups?.count() ?? 0);
  7237. if (amuletGroupCount > 0) {
  7238. let amuletArray = amuletGroups.toArray().sort((a, b) => a.name < b.name ? -1 : 1);
  7239. let amuletGroupContainer = amuletContainer.lastChild;
  7240. for (let i = 0; i < amuletGroupCount; i++) {
  7241. let li = document.createElement('li');
  7242. li.className = 'amulet_item';
  7243. li.setAttribute('original-item', amuletArray[i].name);
  7244. li.title = amuletArray[i].formatBuffSummary('', '', '\n', false);
  7245. li.innerHTML = `<a href="###">${amuletArray[i].name} [${amuletArray[i].count()}]</a>`;
  7246. li.onclick = selector_amulet;
  7247. amuletGroupContainer.appendChild(li);
  7248. }
  7249. }
  7250. function selector_amulet() {
  7251. if (!amuletRadioGroup[2].checked) {
  7252. amuletRadioGroup[0].checked = false;
  7253. amuletRadioGroup[1].checked = false;
  7254. amuletRadioGroup[2].checked = true;
  7255. }
  7256. let ac = parseInt(amuletCount.innerText);
  7257. let tc = parseInt($(this).text().match(/\[(\d+)\]/)[1]);
  7258. if ($(this).attr('item-selected') != 1) {
  7259. $(this).attr('item-selected', 1);
  7260. $(this).css('background-color', highlightBackgroundColor);
  7261. ac += tc;
  7262. }
  7263. else {
  7264. $(this).attr('item-selected', 0);
  7265. $(this).css('background-color', g_genericPopupBackgroundColor);
  7266. ac -= tc;
  7267. }
  7268. amuletCount.innerText = ac + ' / ' + bagCells;
  7269. amuletCount.style.color = (ac <= bagCells ? 'blue' : 'red');
  7270. }
  7271.  
  7272. function generateTemplate() {
  7273. let template = {
  7274. monster : { batchData : [] },
  7275. role : { useWishpool : true , points : [] },
  7276. equipment : { selected : [] },
  7277. halo : { selected : [] , excluded : [] },
  7278. amulet : { selected : -1 , selectedGroups : [] },
  7279. miscellaneous : {}
  7280. };
  7281. mon_selector.querySelectorAll('.mon-row').forEach((tr) => {
  7282. let row = tr.children;
  7283. template.monster[tr.getAttribute('original-item')] = {
  7284. selected : row[0].firstElementChild.checked,
  7285. progress : row[1].firstElementChild.value,
  7286. level : row[2].firstElementChild.value
  7287. };
  7288. });
  7289. genericPopupQuerySelectorAll('#mon-div input.mon-batch-data').forEach((e) => {
  7290. template.monster.batchData.push(e.value);
  7291. });
  7292.  
  7293. template.role.useWishpool = genericPopupQuerySelector('#role-useWishpool').checked;
  7294. genericPopupQuerySelectorAll('#role-info input').forEach((e, i) => {
  7295. template.role.points.push(e.value);
  7296. });
  7297.  
  7298. genericPopupQuerySelectorAll('table.equip-list input.equip-checkbox.equip-item').forEach((e) => {
  7299. if (e.checked) {
  7300. template.equipment.selected.push(e.getAttribute('original-item'));
  7301. }
  7302. });
  7303.  
  7304. genericPopupQuerySelectorAll('#halo_selector a.halo_item').forEach((e) => {
  7305. if (e.getAttribute('item-selected') == 1) {
  7306. template.halo.selected.push(e.getAttribute('original-item'));
  7307. }
  7308. });
  7309. genericPopupQuerySelectorAll('#halo_selector a.halo_item_exclude').forEach((e) => {
  7310. if (e.getAttribute('item-selected') == 1) {
  7311. template.halo.excluded.push(e.getAttribute('original-item'));
  7312. }
  7313. });
  7314.  
  7315. let amchk = genericPopupQuerySelectorAll('#amulet-div input.amulet-config');
  7316. for (var amStyle = amchk.length - 1; amStyle >= 0 && !amchk[amStyle].checked; amStyle--);
  7317. template.amulet.selected = amStyle;
  7318. genericPopupQuerySelectorAll('#amulet_selector .amulet_item').forEach((e) => {
  7319. if (e.getAttribute('item-selected') == 1) {
  7320. template.amulet.selectedGroups.push(e.getAttribute('original-item'));
  7321. }
  7322. });
  7323.  
  7324. genericPopupQuerySelectorAll('#misc-div table.misc-config input').forEach((e) => {
  7325. template.miscellaneous[e.getAttribute('original-item')] = e.value;
  7326. });
  7327.  
  7328. return template;
  7329. }
  7330.  
  7331. function applyTemplate(template) {
  7332. mon_selector.querySelectorAll('.mon-row').forEach((tr) => {
  7333. let mon = template.monster[tr.getAttribute('original-item')];
  7334. if (mon != null) {
  7335. let row = tr.children;
  7336. row[0].firstElementChild.checked = mon.selected;
  7337. row[1].firstElementChild.value = mon.progress;
  7338. row[2].firstElementChild.value = mon.level;
  7339. monDataChange({ target : row[1].firstElementChild });
  7340. }
  7341. });
  7342. genericPopupQuerySelectorAll('#mon-div input.mon-batch-data').forEach((e, i) => {
  7343. e.value = template.monster.batchData[i];
  7344. });
  7345. countGenericCheckbox('#mon-div');
  7346.  
  7347. genericPopupQuerySelector('#role-useWishpool').checked = template.role.useWishpool;
  7348. genericPopupQuerySelectorAll('#role-info input').forEach((e, i) => {
  7349. e.value = template.role.points[i];
  7350. });
  7351. rolePtsChanged();
  7352.  
  7353. let eqs = template.equipment.selected.slice();
  7354. genericPopupQuerySelectorAll('table.equip-list input.equip-checkbox.equip-item').forEach((e) => {
  7355. let i = eqs.indexOf(e.getAttribute('original-item'));
  7356. if (e.checked = (i >= 0)) {
  7357. eqs.splice(i, 1);
  7358. }
  7359. });
  7360. countGenericCheckbox('#equips1-div');
  7361. countGenericCheckbox('#equips2-div');
  7362. countGenericCheckbox('#equips3-div');
  7363. countGenericCheckbox('#equips4-div');
  7364.  
  7365. let hp = 0;
  7366. let hs = 0;
  7367. genericPopupQuerySelectorAll('#halo_selector a.halo_item').forEach((e) => {
  7368. if (template.halo.selected.indexOf(e.getAttribute('original-item')) >= 0) {
  7369. e.setAttribute('item-selected', 1);
  7370. e.style.backgroundColor = highlightBackgroundColor;
  7371. hp += parseInt(e.innerText.split(' ')[1]);
  7372. hs++;
  7373. }
  7374. else {
  7375. e.setAttribute('item-selected', 0);
  7376. e.style.backgroundColor = g_genericPopupBackgroundColor;
  7377. }
  7378. });
  7379. haloPoints.innerText = hp;
  7380. haloSlots.innerText = hs;
  7381. haloPoints.style.color = (hp <= haloMax ? '#0000c0' : 'red');
  7382. haloSlots.style.color = (hs <= roleHs ? '#0000c0' : 'red');
  7383.  
  7384. genericPopupQuerySelectorAll('#halo_selector a.halo_item_exclude').forEach((e) => {
  7385. if (template.halo.excluded.indexOf(e.getAttribute('original-item')) >= 0) {
  7386. e.setAttribute('item-selected', 1);
  7387. e.style.backgroundColor = highlightBackgroundColor;
  7388. }
  7389. else {
  7390. e.setAttribute('item-selected', 0);
  7391. e.style.backgroundColor = g_genericPopupBackgroundColor;
  7392. }
  7393. });
  7394.  
  7395. genericPopupQuerySelectorAll('#amulet-div input.amulet-config').forEach((e, i) => {
  7396. e.checked = (template.amulet.selected == i);
  7397. });
  7398. let ac = 0;
  7399. genericPopupQuerySelectorAll('#amulet_selector .amulet_item').forEach((e) => {
  7400. if (template.amulet.selectedGroups.indexOf(e.getAttribute('original-item')) >= 0) {
  7401. e.setAttribute('item-selected', 1);
  7402. e.style.backgroundColor = highlightBackgroundColor;
  7403. ac += parseInt(e.innerHTML.match(/\[(\d+)\]/)[1]);
  7404. }
  7405. else {
  7406. e.setAttribute('item-selected', 0);
  7407. e.style.backgroundColor = g_genericPopupBackgroundColor;
  7408. }
  7409. });
  7410. amuletCount.innerText = ac + ' / ' + bagCells;
  7411. amuletCount.style.color = (ac <= bagCells ? 'blue' : 'red');
  7412.  
  7413. genericPopupQuerySelectorAll('#misc-div table.misc-config input').forEach((e) => {
  7414. e.value = template.miscellaneous[e.getAttribute('original-item')];
  7415. });
  7416. }
  7417.  
  7418. function collectConfigData() {
  7419. let cfg = [ haloMax,
  7420. '',
  7421. `${role.shortMark}${role.hasG ? ' G=' + roleGv : ''} ${roleLv} ${userInfo[2]} ${roleHs} ${roleQl}` ];
  7422. if (genericPopupQuerySelector('#role-useWishpool').checked) {
  7423. cfg.push('WISH ' + wishpool.slice(-14).join(' '));
  7424. }
  7425.  
  7426. let amchk = genericPopupQuerySelectorAll('#amulet-div input.amulet-config');
  7427. if (amchk[1].checked) {
  7428. let am = amchk[1].getAttribute('original-item');
  7429. if (am?.length > 0) {
  7430. cfg.push(am);
  7431. }
  7432. }
  7433. else if (amchk[2].checked) {
  7434. let ag = new AmuletGroup();
  7435. ag.name = 'temp';
  7436. $('.amulet_item').each(function(i, e) {
  7437. if ($(e).attr('item-selected') == 1) {
  7438. ag.merge(amuletGroups.get($(e).attr('original-item')));
  7439. }
  7440. });
  7441. if (ag.isValid()) {
  7442. cfg.push(`AMULET ${ag.formatBuffShortMark(' ', ' ', false)} ENDAMULET`);
  7443. }
  7444. }
  7445.  
  7446. let pts = [];
  7447. let ptsMax = [ 'MAXATTR' ];
  7448. genericPopupQuerySelectorAll('#role-info input').forEach((e, i) => {
  7449. (i < 6 ? pts : ptsMax).push(e.value);
  7450. });
  7451. cfg.push(pts.join(' '));
  7452.  
  7453. let eq = [ [], [], [], [] ];
  7454. genericPopupQuerySelectorAll('table.equip-list').forEach((t, ti) => {
  7455. let equ = t.querySelectorAll('input.equip-checkbox.equip-item');
  7456. let equnsel = [];
  7457. equ.forEach((e) => {
  7458. let eqstr = e.getAttribute('original-item');
  7459. let a = eqstr.split(' ');
  7460. a.splice(2, 2);
  7461. eqstr = a.join(' ');
  7462. if (e.checked) {
  7463. eq[ti].push(eqstr);
  7464. }
  7465. else if (eq[ti].length == 0) {
  7466. equnsel.push(eqstr);
  7467. }
  7468. });
  7469. if (eq[ti].length == 0) {
  7470. eq[ti] = equnsel;
  7471. }
  7472. });
  7473. let eqsel = [];
  7474. eq.forEach((e) => {
  7475. if (e.length == 1) {
  7476. cfg.push(e[0]);
  7477. }
  7478. else {
  7479. cfg.push('NONE');
  7480. eqsel.push(e);
  7481. }
  7482. });
  7483.  
  7484. let halo = [];
  7485. $('.halo_item').each(function(i, e) {
  7486. if ($(e).attr('item-selected') == 1) {
  7487. halo.push(g_haloMap.get($(e).attr('original-item')).shortMark);
  7488. }
  7489. });
  7490. cfg.push(halo.length > 0 ? halo.length + ' ' + halo.join(' ') : '0');
  7491. cfg.push('');
  7492.  
  7493. if (eqsel.length > 0) {
  7494. cfg.push('GEAR\n ' + eqsel.flat().join('\n ') + '\nENDGEAR');
  7495. cfg.push('');
  7496. }
  7497.  
  7498. let monText = genericPopupQuerySelectorAll('#mon-div input.mon-batch-data');
  7499. let startProg = parseInt(monText[0].value);
  7500. let progStep = parseInt(monText[1].value);
  7501. let lvlstep = parseInt(monText[2].value);
  7502. let batCount = parseInt(monText[3].value);
  7503. let mon = [];
  7504. mon_selector.querySelectorAll('input.mon-checkbox.mon-item').forEach((e) => {
  7505. if (e.checked) {
  7506. let tr = e.parentNode.parentNode;
  7507. let baseLvl = parseInt(tr.children[3].innerText);
  7508. if (!isNaN(baseLvl)) {
  7509. mon.push({ mon : tr.getAttribute('original-item'), level : baseLvl });
  7510. }
  7511. }
  7512. });
  7513. if (mon.length > 0) {
  7514. cfg.push('NPC');
  7515. const sp = ' ';
  7516. mon.forEach((e) => {
  7517. let bl = Math.trunc(e.level * (1 + startProg / 300));
  7518. cfg.push(' ' + (e.mon + sp).substring(0, 8) + (bl + sp).substring(0, 8) + '0');
  7519. if (batCount > 0 && progStep == 0 && lvlstep > 0) {
  7520. e.level = bl;
  7521. }
  7522. });
  7523. while (batCount > 0) {
  7524. cfg.push('');
  7525. if (progStep > 0) {
  7526. startProg += progStep;
  7527. mon.forEach((e) => {
  7528. cfg.push(' ' + (e.mon + sp).substring(0, 8) +
  7529. (Math.trunc(e.level * (1 + startProg / 300)) + sp).substring(0, 8) + '0');
  7530. });
  7531. }
  7532. else if (lvlstep > 0) {
  7533. mon.forEach((e) => {
  7534. cfg.push(' ' + (e.mon + sp).substring(0, 8) +
  7535. ((e.level += lvlstep) + sp).substring(0, 8) + '0');
  7536. });
  7537. }
  7538. else {
  7539. cfg.pop();
  7540. break;
  7541. }
  7542. batCount--;
  7543. }
  7544. cfg.push('ENDNPC');
  7545. cfg.push('');
  7546. }
  7547.  
  7548. genericPopupQuerySelectorAll('#misc-div table.misc-config input').forEach((e) => {
  7549. cfg.push(e.getAttribute('original-item') + ' ' + e.value);
  7550. });
  7551. cfg.push('REDUCERATE 3 10');
  7552. cfg.push('PCWEIGHT 1 1');
  7553. cfg.push('DEFENDER 0');
  7554. cfg.push('');
  7555.  
  7556. cfg.push(ptsMax.join(' '));
  7557. halo = [];
  7558. $('.halo_item_exclude').each(function(i, e) {
  7559. if ($(e).attr('item-selected') == 1) {
  7560. halo.push(g_haloMap.get($(e).attr('original-item')).shortMark);
  7561. }
  7562. });
  7563. if (halo.length > 0) {
  7564. cfg.push('AURAFILTER ' + halo.join('_'));
  7565. }
  7566.  
  7567. return cfg;
  7568. }
  7569.  
  7570. let timer = setInterval(() => {
  7571. if (asyncOperations == 0) {
  7572. clearInterval(timer);
  7573. httpRequestClearAll();
  7574.  
  7575. bagCells += parseInt(wishpool[0] ?? 0);
  7576. if (userInfo?.[4]?.length > 0) {
  7577. bagCells += 2;
  7578. }
  7579. if (userInfo?.[5]?.length > 0) {
  7580. bagCells += 5;
  7581. }
  7582. amuletCount.innerText = '0 / ' + bagCells;
  7583. amuletCount.style.color = 'blue';
  7584.  
  7585. let udata = loadUserConfigData();
  7586. let template = udata.calculatorTemplatePVE?.[role.id];
  7587.  
  7588. function loadTemplate(hideTips) {
  7589. if (template != null) {
  7590. applyTemplate(template);
  7591.  
  7592. btnLoadTemplate.disabled = '';
  7593. btnDeleteTemplate.disabled = '';
  7594. }
  7595. else {
  7596. btnLoadTemplate.disabled = 'disabled';
  7597. btnDeleteTemplate.disabled = 'disabled';
  7598. }
  7599. if (hideTips != true) {
  7600. genericPopupShowInformationTips(template != null ? '模板已加载' : '模板加载失败');
  7601. }
  7602. }
  7603.  
  7604. function saveTemplate() {
  7605. udata.calculatorTemplatePVE ??= {};
  7606. udata.calculatorTemplatePVE[role.id] = template = generateTemplate();
  7607. saveUserConfigData(udata);
  7608.  
  7609. btnLoadTemplate.disabled = '';
  7610. btnDeleteTemplate.disabled = '';
  7611. genericPopupShowInformationTips('模板已保存');
  7612. }
  7613.  
  7614. function deleteTemplate() {
  7615. delete udata.calculatorTemplatePVE[role.id];
  7616. saveUserConfigData(udata);
  7617.  
  7618. template = null;
  7619. btnLoadTemplate.disabled = 'disabled';
  7620. btnDeleteTemplate.disabled = 'disabled';
  7621. genericPopupShowInformationTips('模板已删除');
  7622. }
  7623.  
  7624. genericPopupQuerySelectorAll('input.generic-checkbox').forEach((e) => { e.onchange = genericCheckboxStateChange; });
  7625. function genericCheckboxStateChange(e) {
  7626. let countSpan = e.target.parentNode.parentNode.parentNode.parentNode.firstElementChild.firstElementChild;
  7627. countSpan.innerText = parseInt(countSpan.innerText) + (e.target.checked ? 1 : -1);
  7628. }
  7629.  
  7630. genericPopupQuerySelector('#copy-to-clipboard').onclick = (() => {
  7631. genericPopupQuerySelector('#export-result').select();
  7632. if (document.execCommand('copy')) {
  7633. genericPopupShowInformationTips('导出内容已复制到剪贴板');
  7634. }
  7635. else {
  7636. genericPopupShowInformationTips('复制失败,请进行手工复制(CTRL+A, CTRL+C)');
  7637. }
  7638. });
  7639.  
  7640. genericPopupQuerySelector('#do-export').onclick =
  7641. genericPopupQuerySelector('#save-template-do-export').onclick = (
  7642. (e) => {
  7643. let textbox = genericPopupQuerySelector('#export-result');
  7644. textbox.value = '';
  7645. let string = collectConfigData().join('\n') + '\n';
  7646. if (string?.length > 0) {
  7647. textbox.value = string;
  7648. if (e.target.id.startsWith('save-template')) {
  7649. saveTemplate();
  7650. }
  7651. }
  7652. });
  7653.  
  7654. genericPopupSetContentSize(Math.min(4000, Math.max(window.innerHeight - 400, 400)),
  7655. Math.min(1000, Math.max(window.innerWidth - 200, 600)),
  7656. true);
  7657.  
  7658. genericPopupAddButton('保存模板', 0, saveTemplate, true);
  7659. let btnLoadTemplate = genericPopupAddButton('加载模板', 0, loadTemplate, true);
  7660. let btnDeleteTemplate = genericPopupAddButton('删除模板', 0, deleteTemplate, true);
  7661. genericPopupAddCloseButton(80);
  7662.  
  7663. loadTemplate(true);
  7664.  
  7665. genericPopupCloseProgressMessage();
  7666. genericPopupShowModal(true);
  7667. }
  7668. }, 200);
  7669. }
  7670.  
  7671. function refreshBindingSelector(roleId) {
  7672. let bindingsolutionDiv = document.getElementById(g_bindingSolutionId);
  7673. let bindingList = document.getElementById(g_bindingListSelectorId);
  7674.  
  7675. let udata = loadUserConfigData();
  7676. let defaultSolution = false;
  7677. let bindings = null;
  7678. let bind_info = udata.dataBind[roleId];
  7679. if (bind_info != null) {
  7680. bindings = bind_info.split(BINDING_SEPARATOR).sort((a, b) => {
  7681. a = a.split(BINDING_NAME_SEPARATOR);
  7682. b = b.split(BINDING_NAME_SEPARATOR);
  7683. a = a.length > 1 ? a[0] : BINDING_NAME_DEFAULT;
  7684. b = b.length > 1 ? b[0] : BINDING_NAME_DEFAULT;
  7685. return a < b ? -1 : 1;
  7686. });
  7687. }
  7688. bindingList.innerHTML = '';
  7689. if (bindings?.length > 0) {
  7690. bindings.forEach((item) => {
  7691. let elements = item.split(BINDING_NAME_SEPARATOR);
  7692. let op = document.createElement('option');
  7693. op.value = roleId + BINDING_NAME_SEPARATOR + elements[elements.length - 1];
  7694. op.innerText = (elements.length > 1 ? elements[0] : BINDING_NAME_DEFAULT);
  7695. bindingList.appendChild(op);
  7696. if (udata.dataBindDefault[roleId] == op.innerText) {
  7697. bindingList.value = op.value;
  7698. defaultSolution = true;
  7699. }
  7700. });
  7701. bindingsolutionDiv.style.display = 'inline-block';
  7702. }
  7703. else {
  7704. bindingsolutionDiv.style.display = 'none';
  7705. }
  7706. if (!defaultSolution && udata.dataBindDefault[roleId] != null) {
  7707. delete udata.dataBindDefault[roleId];
  7708. saveUserConfigData(udata);
  7709. }
  7710. }
  7711.  
  7712. function addRoleOperationBtn() {
  7713. let roleId = g_roleMap.get(backpacksDiv.querySelector('div.row > div.col-md-3 > span.text-info.fyg_f24')?.innerText)?.id;
  7714.  
  7715. function toolsLinks(e) {
  7716. if (e.target.id == g_genCalcCfgPopupLinkId) {
  7717. showCalcConfigGenPopup();
  7718. }
  7719. else if (e.target.id == g_bindingPopupLinkId) {
  7720. showBindingPopup();
  7721. }
  7722. else if (e.target.id == g_equipOnekeyLinkId) {
  7723. equipOnekey();
  7724. }
  7725. }
  7726.  
  7727. let bindingAnchor = backpacksDiv.querySelector('div.row > div.col-md-12').parentNode.nextSibling;
  7728. let toolsContainer = document.createElement('div');
  7729. toolsContainer.className = 'btn-group';
  7730. toolsContainer.style.display = 'block';
  7731. toolsContainer.style.width = '100%';
  7732. toolsContainer.style.marginTop = '15px';
  7733. toolsContainer.style.fontSize = '18px';
  7734. toolsContainer.style.padding = '10px';
  7735. toolsContainer.style.borderRadius = '5px';
  7736. toolsContainer.style.color = '#0000c0';
  7737. toolsContainer.style.backgroundColor = '#ebf2f9';
  7738. bindingAnchor.parentNode.insertBefore(toolsContainer, bindingAnchor);
  7739.  
  7740. let genCalcCfgLink = document.createElement('span');
  7741. genCalcCfgLink.setAttribute('class', 'fyg_lh30');
  7742. genCalcCfgLink.style.width = '25%';
  7743. genCalcCfgLink.style.textAlign = 'left';
  7744. genCalcCfgLink.style.display = 'inline-block';
  7745. genCalcCfgLink.innerHTML =
  7746. `<a href="###" style="text-decoration:underline;" id="${g_genCalcCfgPopupLinkId}">生成计算器配置(PVE)</a>`;
  7747. genCalcCfgLink.querySelector('#' + g_genCalcCfgPopupLinkId).onclick = toolsLinks;
  7748. toolsContainer.appendChild(genCalcCfgLink);
  7749.  
  7750. let bindingLink = document.createElement('span');
  7751. bindingLink.setAttribute('class', 'fyg_lh30');
  7752. bindingLink.style.width = '25%';
  7753. bindingLink.style.textAlign = 'left';
  7754. bindingLink.style.display = 'inline-block';
  7755. bindingLink.innerHTML =
  7756. `<a href="###" style="text-decoration:underline;" id="${g_bindingPopupLinkId}">绑定(装备 光环 护符)</a>`;
  7757. bindingLink.querySelector('#' + g_bindingPopupLinkId).onclick = toolsLinks;
  7758. toolsContainer.appendChild(bindingLink);
  7759.  
  7760. let bindingsolutionDiv = document.createElement('div');
  7761. bindingsolutionDiv.id = g_bindingSolutionId;
  7762. bindingsolutionDiv.style.display = 'none';
  7763. bindingsolutionDiv.style.width = '50%';
  7764.  
  7765. let bindingList = document.createElement('select');
  7766. bindingList.id = g_bindingListSelectorId;
  7767. bindingList.style.width = '80%';
  7768. bindingList.style.color = '#0000c0';
  7769. bindingList.style.textAlign = 'center';
  7770. bindingList.style.display = 'inline-block';
  7771. bindingsolutionDiv.appendChild(bindingList);
  7772.  
  7773. let applyLink = document.createElement('span');
  7774. applyLink.setAttribute('class', 'fyg_lh30');
  7775. applyLink.style.width = '20%';
  7776. applyLink.style.textAlign = 'right';
  7777. applyLink.style.display = 'inline-block';
  7778. applyLink.innerHTML = `<a href="###" style="text-decoration:underline;" id="${g_equipOnekeyLinkId}">应用方案</a>`;
  7779. applyLink.querySelector('#' + g_equipOnekeyLinkId).onclick = toolsLinks;
  7780. bindingsolutionDiv.appendChild(applyLink);
  7781. toolsContainer.appendChild(bindingsolutionDiv);
  7782.  
  7783. refreshBindingSelector(roleId);
  7784. }
  7785.  
  7786. function switchEquipSubtabs() {
  7787. function enableSwitchEquipSubtabs(enabled) {
  7788. const maskDivId = 'equip-tab-div';
  7789. let maskDiv = document.getElementById(maskDivId);
  7790. if (maskDiv == null) {
  7791. maskDiv = document.createElement('div');
  7792. maskDiv.id = maskDivId;
  7793. maskDiv.style.position = 'absolute';
  7794. maskDiv.style.zIndex = '999';
  7795. maskDiv.style.height = '100%';
  7796. maskDiv.style.width = '100%';
  7797. maskDiv.style.top = '0';
  7798. maskDiv.style.left = '0';
  7799. maskDiv.style.backgroundColor = 'rgb(0, 0, 0, 0.02)';
  7800. let container = document.querySelector('ul.nav.nav-secondary.nav-justified').parentNode;
  7801. container.insertBefore(maskDiv, container.firstElementChild);
  7802. }
  7803. maskDiv.style.display = (enabled ? 'none' : 'block');
  7804. }
  7805. enableSwitchEquipSubtabs(false);
  7806.  
  7807. $('.pop_main').hide();
  7808. calcBtn.disabled = 'disabled';
  7809. calcBtn.onclick = (() => {});
  7810.  
  7811. let index = -1;
  7812. document.querySelectorAll('ul.nav.nav-secondary.nav-justified > li').forEach((e, i) => {
  7813. if (e.className == 'active') {
  7814. index = i;
  7815. }
  7816. });
  7817. switch (index) {
  7818. case 0: {
  7819. calcBtn.disabled = '';
  7820. calcBtn.onclick = (() => {
  7821. let eqon = equipmentNodesToInfoArray(cardingDiv.querySelectorAll(cardingObjectsQueryString));
  7822. let eqall = equipmentNodesToInfoArray(backpacksDiv.querySelectorAll(storeObjectsQueryString));
  7823. eqall = eqall.concat(eqon).sort(equipmentInfoComparer);
  7824. let el = eqall.length;
  7825. calcDiv.innerHTML =
  7826. `<div class="pop_main" style="padding:0px 10px;"><a href="###" 折叠 ×</a>
  7827. <div class="pop_con">
  7828. <div style="width:200px;padding:5px;margin-top:10px;margin-bottom:10px;
  7829. color:purple;border:1px solid grey;">护符:</div>
  7830. <div class="pop_text"></div>
  7831. <div style="width:200px;padding:5px;margin-top:10px;margin-bottom:10px;
  7832. color:purple;border:1px solid grey">已装备:</div>
  7833. <div class="pop_text"></div>
  7834. <div class="pop_text"></div>
  7835. <div class="pop_text"></div>
  7836. <div class="pop_text"></div>
  7837. <div style="width:200px;padding:5px;margin-top:10px;margin-bottom:10px;
  7838. color:purple;border:1px solid grey;">全部装备:</div>
  7839. ${new Array(el).fill('<div class="pop_text"></div>').join('')}<hr></div>
  7840. <a href="###" 折叠 ×</a></div>`;
  7841.  
  7842. $('.pop_main a').click(() => {
  7843. $('.pop_main').hide()
  7844. })
  7845. let text = $('.pop_text');
  7846. let bagAmulets = [];
  7847. amuletNodesToArray(backpacksDiv.querySelectorAll(bagObjectsQueryString), bagAmulets);
  7848. let bagGroup = amuletCreateGroupFromArray('temp', bagAmulets);
  7849. if (bagGroup?.isValid()) {
  7850. text[0].innerText = `AMULET ${bagGroup.formatBuffShortMark(' ', ' ', false)} ENDAMULET`;
  7851. }
  7852. eqon.forEach((e, i) => {
  7853. let a = e.slice(0, -1);
  7854. a.splice(2, 2);
  7855. text[i + 1].innerText = a.join(' ');
  7856. });
  7857. for (let i = 0; i < el; i++) {
  7858. let a = eqall[i].slice(0, -1);
  7859. a.splice(2, 2);
  7860. text[5 + i].innerText = a.join(' ');
  7861. }
  7862. $('.pop_main').show();
  7863. });
  7864. if (document.getElementById('equipmentDiv') == null) {
  7865. restructEquipUI(enableSwitchEquipSubtabs, true);
  7866. return;
  7867. }
  7868. else {
  7869. switchObjectContainerStatus(!equipmentStoreExpand);
  7870. }
  7871. break;
  7872. }
  7873. case 1: {
  7874. if (g_roleMap.has(backpacksDiv.querySelector('div.row > div.col-md-3 > span.text-info.fyg_f24')?.innerText)) {
  7875. addRoleOperationBtn();
  7876. }
  7877. break;
  7878. }
  7879. default: {
  7880. break;
  7881. }
  7882. }
  7883. enableSwitchEquipSubtabs(true);
  7884. }
  7885.  
  7886. let backpacksObserver = new MutationObserver(() => {
  7887. backpacksObserver.disconnect();
  7888. switchEquipSubtabs();
  7889. backpacksObserver.observe(backpacksDiv, { childList : true , characterData : true });
  7890. });
  7891.  
  7892. switchEquipSubtabs();
  7893. backpacksObserver.observe(backpacksDiv, { childList : true , characterData : true });
  7894.  
  7895. equipmentNodesToInfoArray(cardingDiv.querySelectorAll(cardingObjectsQueryString));
  7896. new MutationObserver(() => {
  7897. equipmentNodesToInfoArray(cardingDiv.querySelectorAll(cardingObjectsQueryString));
  7898. }).observe(cardingDiv, { subtree : true, childList : true });
  7899. }
  7900. }, 200);
  7901. }
  7902. else if (window.location.pathname == g_guguzhenBeach) {
  7903. genericPopupInitialize();
  7904.  
  7905. let beachConfigDiv = document.createElement('div');
  7906. beachConfigDiv.style.padding = '5px 15px';
  7907. beachConfigDiv.style.borderBottom = '1px solid #d0d0d0';
  7908. beachConfigDiv.innerHTML =
  7909. `<button type="button" style="width:160px;" id="analyze-indicator" disabled>分析中...(0)</button>
  7910. <div style="float:right;">
  7911. <button type="button" style="width:120px;" id="siftSettings">筛选展开设置</button>
  7912. <button type="button" style="width:120px;" id="toAmuletSettings">批量转护符设置</button>
  7913. <input type="checkbox" id="forceExpand" style="margin-left:15px;margin-right:5px;" />
  7914. <label for="forceExpand" style="margin-right:15px;cursor:pointer;">强制展开所有装备</label>
  7915. <input type="checkbox" id="beach_BG" style="margin-right:5px;"/>
  7916. <label for="beach_BG" style="cursor:pointer;">使用深色背景</label>
  7917. </div></div>`;
  7918.  
  7919. let equipRefreshRequired = true;
  7920. let btnAnalyze = beachConfigDiv.querySelector('#analyze-indicator');
  7921. btnAnalyze.onclick = (() => {
  7922. if (document.getElementById('beach_copy') != null) {
  7923. btnAnalyze.disabled = 'disabled';
  7924. equipRefreshRequired = true;
  7925. analyzeBeachEquips();
  7926. }
  7927. });
  7928.  
  7929. let forceExpand = setupConfigCheckbox(
  7930. beachConfigDiv.querySelector('#forceExpand'),
  7931. g_beachForceExpandStorageKey,
  7932. (checked) => {
  7933. forceExpand = checked;
  7934. if (document.getElementById('beach_copy') != null) {
  7935. analyzeBeachEquips();
  7936. }
  7937. },
  7938. null);
  7939.  
  7940. let beach_BG = setupConfigCheckbox(
  7941. beachConfigDiv.querySelector('#beach_BG'),
  7942. g_beachBGStorageKey,
  7943. (checked) => { changeBeachStyle('beach_copy', beach_BG = checked); },
  7944. null);
  7945.  
  7946. beachConfigDiv.querySelector('#toAmuletSettings').onclick = (() => {
  7947. modifyConfig(['minBeachEquipLevelToAmulet', 'minBeachAmuletPointsToStore', 'clearBeachAfterBatchToAmulet'], '批量转护符设置');
  7948. });
  7949.  
  7950. beachConfigDiv.querySelector('#siftSettings').onclick = (() => {
  7951. loadTheme();
  7952.  
  7953. let fixedContent =
  7954. '<div style="font-size:15px;color:#0000c0;padding:20px 0px 10px;"><b><ul>' +
  7955. '<li>被勾选的装备不会被展开,不会产生与已有装备的对比列表,传奇、史诗及有神秘属性的装备例外</li>' +
  7956. '<li>未勾选的属性被视为主要属性,沙滩装备的任一主要属性值大于已有装备的相应值时即有可能被展开,除非已有装备中至少有一件其各项属性值均不低于沙滩装备</li>' +
  7957. '<li>被勾选的属性被视为次要属性,当且仅当沙滩装备和已有装备的主要属性值完全相等时才会被对比</li>' +
  7958. '<li>不作为筛选依据的已有装备或指定特性不会与沙滩装备直接进行比较,这些装备不会影响沙滩装备的展开与否</li></ul></b></div>';
  7959. let mainContent =
  7960. `<style> #equip-table { width:100%; }
  7961. #equip-table th { width:17%; text-align:right; }
  7962. #equip-table th.equip-th-equip { width:32%; text-align:left; }
  7963. #equip-table td { display:table-cell; text-align:right; }
  7964. #equip-table td.equip-td-equip { display:table-cell; text-align:left; }
  7965. #equip-table label.equip-checkbox-label { margin-left:5px; cursor:pointer; }
  7966. table tr.alt { background-color:${g_genericPopupBackgroundColorAlt}; } </style>
  7967. <div class="${g_genericPopupTopLineDivClass}" style="color:#800080;">
  7968. <b style="display:inline-block;width:30%;">不作为筛选依据的特性及装备:</b>
  7969. <span style="display:inline-block;width:22%;;text-align:center;">
  7970. <input type="checkbox" id="ignoreEquipQuality" style="margin-right:5px;" />
  7971. <label for="ignoreEquipQuality" style="cursor:pointer;">装备品质</label></span>
  7972. <span style="display:inline-block;width:22%;;text-align:center;">
  7973. <input type="checkbox" id="ignoreMysEquip" style="margin-right:5px;" />
  7974. <label for="ignoreMysEquip" style="cursor:pointer;">神秘装备</label></span>
  7975. <b style="display:inline-block;width:22%;text-align:right;">低于 ` +
  7976. `<input type="text" id="ignoreEquipLevel" style="width:40px;" maxlength="3" value="0"
  7977. oninput="value=value.replace(/[^\\d]/g,'');" /> 级的装备</b></div>
  7978. <div class="${g_genericPopupTopLineDivClass}"><table id="equip-table">
  7979. <tr class="alt"><th class="equip-th-equip"><input type="checkbox" id="equip-name-check" />
  7980. <label class= "equip-checkbox-label" for="equip-name-check">装备名称</label></th>
  7981. <th>装备属性</th><th /><th /><th /></tr></table><div>`;
  7982.  
  7983. genericPopupSetFixedContent(fixedContent);
  7984. genericPopupSetContent('沙滩装备筛选设置', mainContent);
  7985.  
  7986. genericPopupQuerySelector('#equip-name-check').onchange = ((e) => {
  7987. let eqchecks = equipTable.querySelectorAll('input.sift-settings-checkbox');
  7988. for (let i = 0; i < eqchecks.length; i += 5) {
  7989. eqchecks[i].checked = e.target.checked;
  7990. }
  7991. });
  7992.  
  7993. let udata = loadUserConfigData();
  7994. if (udata.dataBeachSift == null) {
  7995. udata.dataBeachSift = {};
  7996. saveUserConfigData(udata);
  7997. }
  7998.  
  7999. let ignoreEquipQuality = genericPopupQuerySelector('#ignoreEquipQuality');
  8000. let ignoreMysEquip = genericPopupQuerySelector('#ignoreMysEquip');
  8001. let ignoreEquipLevel = genericPopupQuerySelector('#ignoreEquipLevel');
  8002.  
  8003. ignoreEquipQuality.checked = (udata.dataBeachSift.ignoreEquipQuality ?? false);
  8004. ignoreMysEquip.checked = (udata.dataBeachSift.ignoreMysEquip ?? false);
  8005. ignoreEquipLevel.value = (udata.dataBeachSift.ignoreEquipLevel ?? "0");
  8006.  
  8007. let equipTable = genericPopupQuerySelector('#equip-table');
  8008. let equipTypeColor = [ '#000080', '#008000', '#800080', '#008080' ];
  8009. g_equipments.forEach((equip) => {
  8010. let tr = document.createElement('tr');
  8011. tr.id = `equip-index-${equip.index}`;
  8012. tr.className = ('equip-tr' + ((equip.index & 1) == 0 ? '' : ' alt'));
  8013. tr.setAttribute('equip-abbr', equip.shortMark);
  8014. tr.style.color = equipTypeColor[equip.type];
  8015. let attrHTML = '';
  8016. equip.attributes.forEach((item, index) => {
  8017. let attrId = `${tr.id}-attr-${index}`;
  8018. attrHTML +=
  8019. `<td><input type="checkbox" class="sift-settings-checkbox" id="${attrId}" />
  8020. <label class="equip-checkbox-label" for="${attrId}">${item.attribute.name}</label></td>`;
  8021. });
  8022. let equipId = `equip-${equip.index}`;
  8023. tr.innerHTML =
  8024. `<td class="equip-td-equip"><input type="checkbox" class="sift-settings-checkbox" id="${equipId}" />
  8025. <label class="equip-checkbox-label" for="${equipId}">${equip.alias}</label></td>${attrHTML}`;
  8026. equipTable.appendChild(tr);
  8027. });
  8028.  
  8029. let eqchecks = equipTable.querySelectorAll('input.sift-settings-checkbox');
  8030. for (let i = 0; i < eqchecks.length; i += 5) {
  8031. let abbr = eqchecks[i].parentNode.parentNode.getAttribute('equip-abbr');
  8032. if (udata.dataBeachSift[abbr] != null) {
  8033. let es = udata.dataBeachSift[abbr].split(',');
  8034. for (let j = 0; j < es.length; j++) {
  8035. eqchecks[i + j].checked = (es[j] == 'true');
  8036. }
  8037. }
  8038. }
  8039.  
  8040. genericPopupAddButton(
  8041. '确认',
  8042. 80,
  8043. (() => {
  8044. let settings = {
  8045. ignoreEquipQuality : ignoreEquipQuality.checked,
  8046. ignoreMysEquip : ignoreMysEquip.checked,
  8047. ignoreEquipLevel : ignoreEquipLevel.value
  8048. };
  8049. equipTable.querySelectorAll('tr.equip-tr').forEach((row) => {
  8050. let checks = [];
  8051. row.querySelectorAll('input.sift-settings-checkbox').forEach((col) => { checks.push(col.checked); });
  8052. settings[row.getAttribute('equip-abbr')] = checks.join(',');
  8053. });
  8054.  
  8055. let udata = loadUserConfigData();
  8056. udata.dataBeachSift = settings;
  8057. saveUserConfigData(udata);
  8058.  
  8059. window.location.reload();
  8060. }),
  8061. false);
  8062. genericPopupAddCloseButton(80);
  8063.  
  8064. genericPopupSetContentSize(Math.min(g_equipments.length * 31 + 130, Math.max(window.innerHeight - 400, 600)),
  8065. Math.min(750, Math.max(window.innerWidth - 100, 600)),
  8066. true);
  8067. genericPopupShowModal(true);
  8068. });
  8069.  
  8070. let beach = document.getElementById('beachall');
  8071. beach.parentNode.insertBefore(beachConfigDiv, beach);
  8072.  
  8073. let batbtns = document.querySelector('div.col-md-12 > div.panel > div.panel-heading > div.btn-group > button.btn.btn-danger');
  8074. let toAmuletBtn = document.createElement('button');
  8075. toAmuletBtn.className = batbtns.className;
  8076. toAmuletBtn.innerText = '批量沙滩装备转护符';
  8077. toAmuletBtn.style.marginLeft = '1px';
  8078. toAmuletBtn.onclick = equipToAmulet;
  8079. toAmuletBtn.disabled = 'disabled';
  8080. batbtns.parentNode.appendChild(toAmuletBtn);
  8081.  
  8082. function equipToAmulet() {
  8083. loadTheme();
  8084. readConfig();
  8085.  
  8086. function divHeightAdjustment(div) {
  8087. div.style.height = (div.parentNode.offsetHeight - div.offsetTop - 3) + 'px';
  8088. }
  8089.  
  8090. function moveAmuletItem(e) {
  8091. let li = e.target;
  8092. if (li.tagName == 'LI') {
  8093. let container = (li.parentNode == amuletToStoreList ? amuletToDestroyList : amuletToStoreList);
  8094. let liIndex = parseInt(li.getAttribute('li-index'));
  8095. for (var li0 = container.firstChild; parseInt(li0?.getAttribute('li-index')) < liIndex; li0 = li0.nextSibling);
  8096. container.insertBefore(li, li0);
  8097. }
  8098. }
  8099.  
  8100. function refreshStore(fnPostProcess) {
  8101. // read store
  8102. stbp();
  8103.  
  8104. let timer = setInterval(() => {
  8105. if (asyncOperations == 0) {
  8106. clearInterval(timer);
  8107. if (fnPostProcess != null) {
  8108. fnPostProcess();
  8109. }
  8110. }
  8111. }, 200);
  8112. }
  8113.  
  8114. function queryObjects(storeAmulets, beach, beachEquipLevel) {
  8115. freeCell = parseInt(document.querySelector('#wares > p.fyg_lh40.fyg_tc.text-gray')?.innerText?.match(/\d+/)?.[0]);
  8116. if (isNaN(freeCell)) {
  8117. freeCell = 0;
  8118. }
  8119. if (storeAmulets != null) {
  8120. amuletNodesToArray(document.querySelectorAll('#wares > button.btn.fyg_mp3'), storeAmulets);
  8121. }
  8122. if (beach != null) {
  8123. let nodes = document.getElementById('beachall').children;
  8124. for (let node of nodes) {
  8125. let lv = objectGetLevel(node);
  8126. if (lv > 1) {
  8127. lv -= 2;
  8128. let e = equipmentInfoParseNode(node);
  8129. if (e != null && parseInt(e[1]) >= beachEquipLevel[lv]) {
  8130. beach.push(parseInt(e[9]));
  8131. }
  8132. }
  8133. }
  8134. }
  8135. }
  8136.  
  8137. function pirlEquip() {
  8138. genericPopupShowInformationTips('熔炼装备...', 0);
  8139. let ids = [];
  8140. while (originalBeachEquips.length > 0 && ids.length < freeCell) {
  8141. ids.unshift(originalBeachEquips.pop());
  8142. }
  8143. pirlCount = ids.length;
  8144. beginPirlObjects(false, ids, refreshStore, prepareNewAmulets);
  8145. }
  8146.  
  8147. function prepareNewAmulets() {
  8148. let amulets = [];
  8149. queryObjects(amulets);
  8150. newAmulets = findNewObjects(amulets, originalStoreAmulets, false, false, (a, b) => a.compareTo(b));
  8151. if (newAmulets.length != pirlCount) {
  8152. alert('熔炼装备出错无法继续,请手动处理!');
  8153. window.location.reload();
  8154. return;
  8155. }
  8156. let liAm = [];
  8157. newAmulets.forEach((am, index) => {
  8158. let li = document.createElement('li');
  8159. li.innerText = (am.type == 2 || am.level == 2 ? '★ ' : '') + am.formatBuffText();
  8160. li.style.backgroundColor = g_equipmentLevelBGColor[am.level + 2];
  8161. li.setAttribute('item-index', index);
  8162. liAm.push(li);
  8163. });
  8164. liAm.sort((a, b) => newAmulets[parseInt(a.getAttribute('item-index'))].compareTo(
  8165. newAmulets[parseInt(b.getAttribute('item-index'))])).forEach((li, index) => {
  8166. li.setAttribute('li-index', index);
  8167. let am = newAmulets[parseInt(li.getAttribute('item-index'))];
  8168. (am.getTotalPoints() < minBeachAmuletPointsToStore[am.type] ? amuletToDestroyList : amuletToStoreList).appendChild(li);
  8169. });
  8170. if (window.getSelection) {
  8171. window.getSelection().removeAllRanges();
  8172. }
  8173. else if (document.getSelection) {
  8174. document.getSelection().removeAllRanges();
  8175. }
  8176. genericPopupShowInformationTips((originalBeachEquips.length > 0 ? '本批' : '全部') + '装备熔炼完成,请分类后继续', 0);
  8177. btnContinue.innerText = `继续 (剩余 ${originalBeachEquips.length} 件装备 / ${freeCell} 个空位)`;
  8178. btnContinue.disabled = '';
  8179. btnCloseOnBatch.disabled = (originalBeachEquips.length > 0 ? '' : 'disabled');
  8180. }
  8181.  
  8182. function processNewAmulets() {
  8183. btnContinue.disabled = 'disabled';
  8184. btnCloseOnBatch.disabled = 'disabled';
  8185.  
  8186. if (pirlCount > 0) {
  8187. let indices = [];
  8188. for (let li of amuletToDestroyList.children) {
  8189. indices.push(parseInt(li.getAttribute('item-index')));
  8190. }
  8191. if (indices.length > 0) {
  8192. let ids = [];
  8193. let warning = 0;
  8194. indices.sort((a, b) => a - b).forEach((i) => {
  8195. let am = newAmulets[i];
  8196. if (am.type == 2 || am.level == 2) {
  8197. warning++;
  8198. }
  8199. ids.push(am.id);
  8200. });
  8201. if (warning > 0 && !confirm(`这将把 ${warning} 个“樱桃/传奇”护符转换成果核,要继续吗?`)) {
  8202. btnContinue.disabled = '';
  8203. btnCloseOnBatch.disabled = (originalBeachEquips.length > 0 ? '' : 'disabled');
  8204. return;
  8205. }
  8206. amuletToDestroyList.innerHTML = '';
  8207. coresCollected += indices.length;
  8208. pirlCount -= indices.length;
  8209. genericPopupShowInformationTips('转换果核...', 0);
  8210. beginPirlObjects(true, ids, refreshStore, processNewAmulets);
  8211. }
  8212. else {
  8213. amuletToStoreList.innerHTML = '';
  8214. amuletsCollected += pirlCount;
  8215. pirlCount = 0;
  8216. processNewAmulets();
  8217. }
  8218. }
  8219. else if (originalBeachEquips.length > 0) {
  8220. queryObjects(originalStoreAmulets);
  8221. originalStoreAmulets.sort((a, b) => a.compareTo(b));
  8222. pirlEquip();
  8223. }
  8224. else {
  8225. postProcess(15);
  8226. }
  8227. }
  8228.  
  8229. function postProcess(closeCountDown) {
  8230. let closed = false;
  8231. function closeProcess() {
  8232. if (timer != null) {
  8233. clearInterval(timer);
  8234. timer = null;
  8235. }
  8236. if (!closed) {
  8237. closed = true;
  8238. genericPopupClose(true, true);
  8239. if (clearBeachAfterBatchToAmulet != 0) {
  8240. // clear beach
  8241. sttz();
  8242. }
  8243. let msgBox = document.getElementById('mymessage');
  8244. timer = setInterval(() => {
  8245. if (asyncOperations == 0 && (!(msgBox?.style?.display?.length > 0) || msgBox.style.display == 'none')) {
  8246. clearInterval(timer);
  8247. timer = null;
  8248. window.location.reload();
  8249. }
  8250. }, 200);
  8251. }
  8252. }
  8253.  
  8254. let timer = null;
  8255. if (closeCountDown > 0) {
  8256. genericPopupQuerySelector('#fixed-tips').innerText = `操作完成,共获得 ${amuletsCollected} 个护符, ${coresCollected} 个果核`;
  8257. genericPopupOnClickOutside(closeProcess);
  8258. timer = setInterval(() => {
  8259. if (--closeCountDown == 0) {
  8260. closeProcess();
  8261. }
  8262. else {
  8263. genericPopupShowInformationTips(`窗口将在 ${closeCountDown} 秒后关闭,` +
  8264. `点击窗口外区域立即关闭${clearBeachAfterBatchToAmulet != 0 ? '并清理沙滩' : ''}`, 0);
  8265. }
  8266. }, 1000);
  8267. }
  8268. else {
  8269. closeProcess();
  8270. }
  8271. }
  8272.  
  8273. const objectTypeColor = [ '#e0fff0', '#ffe0ff', '#fff0e0', '#d0f0ff' ];
  8274. let minBeachAmuletPointsToStore = [ 1, 1, 1 ];
  8275. let cfg = g_configMap.get('minBeachAmuletPointsToStore')?.value?.split(',');
  8276. if (cfg?.length == 3) {
  8277. cfg.forEach((item, index) => {
  8278. if (isNaN(minBeachAmuletPointsToStore[index] = parseInt(item))) {
  8279. minBeachAmuletPointsToStore[index] = 1;
  8280. }
  8281. });
  8282. }
  8283.  
  8284. let originalBeachEquips = [];
  8285. let originalStoreAmulets = [];
  8286. let freeCell = 0;
  8287. let pirlCount = 0;
  8288. let amuletsCollected = 0;
  8289. let coresCollected = 0;
  8290. let newAmulets = null;
  8291.  
  8292. let clearBeachAfterBatchToAmulet = (g_configMap.get('clearBeachAfterBatchToAmulet')?.value ?? 0);
  8293. let minBeachEquipLevelToAmulet = (g_configMap.get('minBeachEquipLevelToAmulet')?.value ?? '1,1,1').split(',');
  8294. for (let i = 0; i < 3; i++) {
  8295. minBeachEquipLevelToAmulet[i] = parseInt(minBeachEquipLevelToAmulet[i] ?? 0);
  8296. if (isNaN(minBeachEquipLevelToAmulet[i])) {
  8297. minBeachEquipLevelToAmulet[i] = 1;
  8298. }
  8299. }
  8300. queryObjects(null, originalBeachEquips, minBeachEquipLevelToAmulet);
  8301. if (originalBeachEquips.length == 0) {
  8302. alert('沙滩无可熔炼装备!');
  8303. return;
  8304. }
  8305. else if (freeCell == 0) {
  8306. alert('仓库已满!');
  8307. return;
  8308. }
  8309.  
  8310. let fixedContent =
  8311. `<div style="width:100%;padding:10px 0px 0px 0px;font-size:16px;color:blue;"><b>
  8312. <span id="fixed-tips">左键双击或上下文菜单键单击条目以进行分类间移动</span><br>
  8313. <div id="${g_genericPopupInformationTipsId}" style="width:100%;color:red;text-align:right;"></div></b></div>`;
  8314. let mainContent =
  8315. '<div style="display:block;height:96%;width:100%;">' +
  8316. '<div style="position:relative;display:block;float:left;height:96%;width:48%;' +
  8317. 'margin-top:10px;border:1px solid #000000;">' +
  8318. '<div style="display:block;width:100%;padding:5px;border-bottom:2px groove #d0d0d0;margin-bottom:10px;">放入仓库</div>' +
  8319. '<div style="position:absolute;display:block;height:1px;width:100%;overflow:scroll;">' +
  8320. '<ul id="amulet_to_store_list" style="cursor:pointer;"></ul></div></div>' +
  8321. '<div style="position:relative;display:block;float:right;height:96%;width:48%;' +
  8322. 'margin-top:10px;border:1px solid #000000;">' +
  8323. '<div style="display:block;width:100%;padding:5px;border-bottom:2px groove #d0d0d0;margin-bottom:10px;">转换果核</div>' +
  8324. '<div style="position:absolute;display:block;height:1px;width:100%;overflow:scroll;">' +
  8325. '<ul id="amulet_to_destroy_list" style="cursor:pointer;"></ul></div></div></div>';
  8326.  
  8327. genericPopupSetFixedContent(fixedContent);
  8328. genericPopupSetContent('批量护符转换', mainContent);
  8329.  
  8330. let amuletToStoreList = genericPopupQuerySelector('#amulet_to_store_list');
  8331. let amuletToDestroyList = genericPopupQuerySelector('#amulet_to_destroy_list');
  8332. amuletToStoreList.parentNode.oncontextmenu = amuletToDestroyList.parentNode.oncontextmenu = (() => false);
  8333. amuletToStoreList.oncontextmenu = amuletToDestroyList.oncontextmenu = moveAmuletItem;
  8334. amuletToStoreList.ondblclick = amuletToDestroyList.ondblclick = moveAmuletItem;
  8335.  
  8336. genericPopupShowInformationTips('这会分批将沙滩可熔炼装备转化为护符,请点击“继续”开始', 0);
  8337. let btnContinue = genericPopupAddButton(`继续 (剩余 ${originalBeachEquips.length} 件装备 / ${freeCell} 个空位)`,
  8338. 0, processNewAmulets, true);
  8339. let btnCloseOnBatch = genericPopupAddButton('本批完成后关闭(不清理沙滩)', 0, (() => {
  8340. clearBeachAfterBatchToAmulet = 0;
  8341. originalBeachEquips = [];
  8342. processNewAmulets();
  8343. }), false);
  8344. btnCloseOnBatch.disabled = 'disabled';
  8345.  
  8346. genericPopupAddButton('关闭(不清理沙滩)', 0, (() => { window.location.reload(); }), false);
  8347.  
  8348. genericPopupSetContentSize(400, 700, false);
  8349.  
  8350. analyzingEquipment = true;
  8351. genericPopupShowModal(false);
  8352.  
  8353. divHeightAdjustment(amuletToStoreList.parentNode);
  8354. divHeightAdjustment(amuletToDestroyList.parentNode);
  8355. }
  8356.  
  8357. let asyncOperations = 1;
  8358. let equipExchanged = false;
  8359. let cardingNodes, equipNodes, equipInfos = [];
  8360. let roleInfo;
  8361. beginReadRoleInfo(
  8362. roleInfo = [],
  8363. () => {
  8364. $(document).ajaxSend(() => { asyncOperations++; });
  8365. $(document).ajaxComplete((e, r) => {
  8366. if (r.responseText?.indexOf('已装备') >= 0) {
  8367. equipExchanged = true;
  8368. }
  8369. if (--asyncOperations < 0) {
  8370. asyncOperations = 0;
  8371. }
  8372. });
  8373.  
  8374. cardingNodes = Array.from(roleInfo[2]).sort(objectNodeComparer);
  8375. if (--asyncOperations < 0) {
  8376. asyncOperations = 0;
  8377. }
  8378. });
  8379.  
  8380. (new MutationObserver((mlist) => {
  8381. if (!(mlist[0].addedNodes[0]?.className?.indexOf('popover') >= 0 ||
  8382. mlist[0].removedNodes[0]?.className?.indexOf('popover') >= 0)) {
  8383. let oldNodes = Array.from(mlist[0].removedNodes).sort(objectNodeComparer);
  8384. let newNodes = Array.from(mlist[0].addedNodes).sort(objectNodeComparer);
  8385. let oldInfos = equipmentNodesToInfoArray(oldNodes);
  8386. let newInfos = equipmentNodesToInfoArray(newNodes);
  8387. if (equipExchanged) {
  8388. equipExchanged = false;
  8389. let puton = findNewObjects(oldInfos, newInfos, true, false, equipmentInfoComparer);
  8390. if (puton.length == 1) {
  8391. let takeoff = findNewObjects(newInfos, oldInfos, true, false, equipmentInfoComparer);
  8392. if (takeoff.length == 1) {
  8393. let exi = searchElement(cardingNodes, newNodes[takeoff[0]], objectNodeComparer);
  8394. if (exi >= 0) {
  8395. cardingNodes.splice(exi, 1);
  8396. }
  8397. }
  8398. if (cardingNodes.length < 4) {
  8399. insertElement(cardingNodes, oldNodes[puton[0]], objectNodeComparer);
  8400. }
  8401. }
  8402. return;
  8403. }
  8404.  
  8405. equipRefreshRequired = (oldInfos.length != newInfos.length);
  8406.  
  8407. if (oldNodes.length == newNodes.length) {
  8408. analyzeBeachEquips();
  8409. }
  8410. }
  8411. })).observe(document.getElementById('wares'), { childList : true });
  8412.  
  8413. let beachTimer = setInterval(() => {
  8414. if (asyncOperations == 0 &&
  8415. (document.getElementById('beachall')?.firstChild?.nodeType ?? Node.ELEMENT_NODE) == Node.ELEMENT_NODE &&
  8416. (document.getElementById('wares')?.firstChild?.nodeType ?? Node.ELEMENT_NODE) == Node.ELEMENT_NODE) {
  8417.  
  8418. clearInterval(beachTimer);
  8419. loadTheme();
  8420.  
  8421. analyzeBeachEquips();
  8422. (new MutationObserver(() => { analyzeBeachEquips(); })).observe(document.getElementById('beachall'), { childList : true });
  8423.  
  8424. toAmuletBtn.disabled = '';
  8425. }
  8426. }, 200);
  8427.  
  8428. var analyzingEquipment = false;
  8429. function analyzeBeachEquips() {
  8430. if (!analyzingEquipment) {
  8431. analyzingEquipment = true;
  8432. let count = (document.getElementById('beachall')?.children?.length ?? 0);
  8433. btnAnalyze.innerText = `分析中...(${count})`;
  8434.  
  8435. let equipTimer = setInterval(() => {
  8436. if (asyncOperations == 0) {
  8437. clearInterval(equipTimer);
  8438.  
  8439. if (equipRefreshRequired) {
  8440. equipNodes = cardingNodes.concat(Array.from(document.querySelectorAll('#wares button.btn.fyg_mp3')))
  8441. .sort(objectNodeComparer);
  8442. equipInfos = equipmentNodesToInfoArray(equipNodes);
  8443. equipRefreshRequired = false;
  8444.  
  8445. // debug only
  8446. equipInfos.forEach((e, i) => {
  8447. if (equipmentVerify(equipNodes[i], e) != 0) {
  8448. equipNodes[i].style.border = '3px solid #ff00ff';
  8449. }
  8450. });
  8451. }
  8452.  
  8453. expandEquipment();
  8454.  
  8455. btnAnalyze.innerText = `重新分析(${count})`;
  8456. btnAnalyze.disabled = (document.getElementById('beachall')?.children?.length > 0 ? '' : 'disabled');
  8457.  
  8458. analyzingEquipment = false;
  8459. }
  8460. }, 200);
  8461. }
  8462. }
  8463.  
  8464. function expandEquipment() {
  8465. let beach_copy = document.getElementById('beach_copy');
  8466. if (beach_copy == null) {
  8467. let beachall = document.getElementById('beachall');
  8468. beach_copy = beachall.cloneNode();
  8469. beachall.style.display = 'none';
  8470. beach_copy.id = 'beach_copy';
  8471. beach_copy.style.backgroundColor = beach_BG ? 'black' : 'white';
  8472. beachall.parentNode.insertBefore(beach_copy, beachall);
  8473.  
  8474. (new MutationObserver((mList) => {
  8475. if (!analyzingEquipment && mList?.length == 1 && mList[0].type == 'childList' &&
  8476. mList[0].addedNodes?.length == 1 && !(mList[0].removedNodes?.length > 0)) {
  8477.  
  8478. let node = mList[0].addedNodes[0];
  8479. if (node.hasAttribute('role')) {
  8480. node.remove();
  8481. }
  8482. else if (node.className?.indexOf('popover') >= 0) {
  8483. node.setAttribute('id', 'id_temp_apply_beach_BG');
  8484. changeBeachStyle('id_temp_apply_beach_BG', beach_BG);
  8485. node.removeAttribute('id');
  8486. if (node.className?.indexOf('popover-') < 0) {
  8487. let content = node.querySelector('.popover-content');
  8488. content.style.borderRadius = '5px';
  8489. content.style.border = '4px double ' + (beach_BG ? 'white' : 'black');
  8490. }
  8491. }
  8492. }
  8493. })).observe(beach_copy, { childList : true });
  8494. }
  8495. copyBeach(beach_copy);
  8496.  
  8497. let udata = loadUserConfigData();
  8498. if (udata.dataBeachSift == null) {
  8499. udata.dataBeachSift = {};
  8500. saveUserConfigData(udata);
  8501. }
  8502.  
  8503. let ignoreEquipQuality = (udata.dataBeachSift.ignoreEquipQuality ?? false);
  8504. let ignoreMysEquip = (udata.dataBeachSift.ignoreMysEquip ?? false);
  8505. let ignoreEquipLevel = parseInt(udata.dataBeachSift.ignoreEquipLevel ?? '0');
  8506. if (isNaN(ignoreEquipLevel)) {
  8507. ignoreEquipLevel = 0;
  8508. }
  8509.  
  8510. let settings = {};
  8511. for (let abbr in udata.dataBeachSift) {
  8512. if (g_equipMap.has(abbr)) {
  8513. let checks = udata.dataBeachSift[abbr].split(',');
  8514. if (checks?.length == 5) {
  8515. let setting = [];
  8516. checks.forEach((checked) => { setting.push(checked.trim().toLowerCase() == 'true'); });
  8517. settings[abbr] = setting;
  8518. }
  8519. }
  8520. }
  8521.  
  8522. const defaultSetting = [ false, false, false, false, false ];
  8523. beach_copy.querySelectorAll('button.btn.fyg_mp3').forEach((btn) => {
  8524. let e = equipmentInfoParseNode(btn);
  8525. if (e != null) {
  8526. let isExpanding = false;
  8527. let eqLv = objectGetLevel(e);
  8528. if (forceExpand || eqLv > 2 || e[8] > 0) {
  8529. isExpanding = true;
  8530. }
  8531. else {
  8532. let setting = (settings[e[0]] ?? defaultSetting);
  8533. if (!setting[0]) {
  8534. let isFind = false;
  8535. let stLv;
  8536. for (let j = equipInfos.length - 1; j >= 0; j--) {
  8537. if (equipInfos[j][0] == e[0] &&
  8538. !(ignoreMysEquip && equipInfos[j][8] == 1) &&
  8539. (stLv = parseInt(equipInfos[j][1])) >= ignoreEquipLevel) {
  8540.  
  8541. isFind = true;
  8542. let e1 = [ parseInt(e[1]), parseInt(e[4]), parseInt(e[5]), parseInt(e[6]), parseInt(e[7]) ];
  8543. let e2 = [ stLv, parseInt(equipInfos[j][4]), parseInt(equipInfos[j][5]),
  8544. parseInt(equipInfos[j][6]), parseInt(equipInfos[j][7]) ];
  8545. let res = defaultEquipmentNodeComparer(setting, e[0], e1, e2);
  8546. if (!ignoreEquipQuality && (res.quality > 0 || (res.quality == 0 && e1[0] > e2[0]))) {
  8547. isExpanding = true;
  8548. break;
  8549. }
  8550. else if (res.majorAdv == 0) {
  8551. if (res.minorAdv == 0) {
  8552. isExpanding = false;
  8553. break;
  8554. }
  8555. else if (!isExpanding) {
  8556. isExpanding = (res.majorDis == 0);
  8557. }
  8558. }
  8559. else {
  8560. isExpanding = true;
  8561. }
  8562. }
  8563. }
  8564. if (!isFind) {
  8565. isExpanding = true;
  8566. }
  8567. }
  8568. }
  8569. let btn0 = null;
  8570. if (isExpanding) {
  8571. btn0 = document.createElement('button');
  8572. btn0.className = `btn btn-light popover-${g_equipmentLevelStyleClass[eqLv]}`;
  8573. btn0.style.minWidth = '240px';
  8574. btn0.style.padding = '0px';
  8575. btn0.style.marginBottom = '5px';
  8576. btn0.style.textAlign = 'left';
  8577. btn0.style.boxShadow = 'none';
  8578. btn0.style.lineHeight = '150%';
  8579. btn0.setAttribute('data-toggle', 'popover');
  8580. btn0.setAttribute('data-trigger', 'hover');
  8581. btn0.setAttribute('data-placement', 'bottom');
  8582. btn0.setAttribute('data-html', 'true');
  8583. btn0.setAttribute('onclick', btn.getAttribute('onclick'));
  8584.  
  8585. let popover = document.createElement('div');
  8586. popover.innerHTML =
  8587. `<style> .popover { max-width:100%; }
  8588. .compare-equip-title { margin-bottom:0px; text-align:center; }
  8589. .compare-equip-content { padding:10px 5px 0px 5px; text-align:left; line-height:120%;}
  8590. </style>`;
  8591. equipInfos.forEach((eq, i) => {
  8592. if (e[0] == eq[0]) {
  8593. let btn1 = document.createElement('button');
  8594. let styleClass = g_equipmentLevelStyleClass[objectGetLevel(eq)];
  8595. btn1.className = `btn btn-light popover-${styleClass}`;
  8596. btn1.style.cssText = 'min-width:220px;padding:0px;box-shadow:none;margin-right:5px;margin-bottom:5px;';
  8597. btn1.innerHTML =
  8598. `<p class="compare-equip-title bg-${styleClass}">Lv.<b>${eq[1]}` +
  8599. `(${equipmentQuality(eq)}%, 攻.${eq[2]} 防.${eq[3]})</b></p>
  8600. <div class="compare-equip-content">${equipNodes[i].dataset.content}</div>`;
  8601. if (btn1.lastChild.lastChild?.nodeType != Node.ELEMENT_NODE) {
  8602. btn1.lastChild.lastChild?.remove();
  8603. }
  8604. if (btn1.lastChild.lastChild?.className?.indexOf('bg-danger') >= 0) {
  8605. btn1.lastChild.lastChild.style.cssText =
  8606. 'max-width:210px;padding:3px;white-space:pre-line;word-break:break-all;';
  8607. }
  8608. popover.insertBefore(btn1, popover.firstElementChild);
  8609.  
  8610. // debug only
  8611. if (equipmentVerify(equipNodes[i], eq) != 0) {
  8612. btn1.style.border = '5px solid #ff00ff';
  8613. }
  8614. }
  8615. });
  8616. btn0.setAttribute('data-content', popover.innerHTML);
  8617. btn0.innerHTML =
  8618. `<h3 class="popover-title bg-${g_equipmentLevelStyleClass[objectGetLevel(e)]}">${btn.dataset.originalTitle}</h3>
  8619. <div class="popover-content-show" style="padding:10px 10px 0px 10px;">${btn.dataset.content}</div>`;
  8620. beach_copy.insertBefore(btn0, btn.nextSibling);
  8621. }
  8622. // debug only
  8623. if (equipmentVerify(btn, e) != 0) {
  8624. btn.style.border = '3px solid #ff00ff';
  8625. if (btn0 != null) {
  8626. btn0.style.border = '5px solid #ff00ff';
  8627. }
  8628. }
  8629. }
  8630. });
  8631.  
  8632. $(function() {
  8633. $('#beach_copy .btn[data-toggle="popover"]').popover();
  8634. });
  8635. $('#beach_copy .bg-danger.with-padding').css({
  8636. 'max-width': '220px',
  8637. 'padding': '5px',
  8638. 'white-space': 'pre-line',
  8639. 'word-break': 'break-all'
  8640. });
  8641.  
  8642. changeBeachStyle('beach_copy', beach_BG);
  8643.  
  8644. function copyBeach(beach_copy) {
  8645. beach_copy.innerHTML = '';
  8646. Array.from(document.getElementById('beachall').children).sort(sortBeach).forEach((node) => {
  8647. beach_copy.appendChild(node.cloneNode(true));
  8648. });
  8649.  
  8650. function sortBeach(a, b) {
  8651. let delta = objectGetLevel(a) - objectGetLevel(b);
  8652. if (delta == 0) {
  8653. if ((delta = parseInt(a.innerText.match(/\d+/)[0]) - parseInt(b.innerText.match(/\d+/)[0])) == 0) {
  8654. delta = (a.getAttribute('data-original-title') < b.getAttribute('data-original-title') ? -1 : 1);
  8655. }
  8656. }
  8657. return -delta;
  8658. }
  8659. }
  8660. }
  8661.  
  8662. function changeBeachStyle(container, bg) {
  8663. $(`#${container}`).css({
  8664. 'background-color': bg ? 'black' : 'white'
  8665. });
  8666. $(`#${container} .popover-content-show`).css({
  8667. 'background-color': bg ? 'black' : 'white'
  8668. });
  8669. $(`#${container} .btn-light`).css({
  8670. 'background-color': bg ? 'black' : 'white'
  8671. });
  8672. $(`#${container} .popover-title`).css({
  8673. 'color': bg ? 'black' : 'white'
  8674. });
  8675. $(`#${container} .compare-equip-title`).css({
  8676. 'color': bg ? 'black' : 'white'
  8677. });
  8678. $(`#${container} .pull-right`).css({
  8679. 'color': bg ? 'black' : 'white'
  8680. });
  8681. $(`#${container} .bg-danger.with-padding`).css({
  8682. 'color': bg ? 'black' : 'white'
  8683. });
  8684. }
  8685.  
  8686. document.body.style.paddingBottom = '1000px';
  8687. }
  8688. else if (window.location.pathname == g_guguzhenPK) {
  8689. let timer = setInterval(() => {
  8690. if (document.querySelector('#pklist')?.firstElementChild != null) {
  8691. clearInterval(timer);
  8692.  
  8693. let pkConfigDiv = document.createElement('div');
  8694. pkConfigDiv.className = 'row';
  8695. pkConfigDiv.innerHTML =
  8696. `<div class="panel panel-info" style="width:100%;">
  8697. <div class="panel-heading" id="pk-addin-panel" style="width:100%;display:table;border:none;">
  8698. <div id="solutionPanel" style="display:none;margin-top:3px;float:left;"
  8699. data-toggle="tooltip" data-placement="top"
  8700. data-original-title="如果在其它页面增加、删除或修改了任何绑定方案,请重新刷新本页面或点击“更新列表”链接以获取更新后的方案内容"><b>
  8701. <a href="###" id="refreshSolutionList"
  8702. style="margin-top:2px;font-size:15px;text-decoration:underline;float:left;">更新列表</a>
  8703. <div style="padding-top:1px;margin-left:10px;margin-right:10px;float:left;">
  8704. <select id="bindingSolutions" style="width:180px;font-size:15px;padding:2px 0px;text-align:center;"></select></div>
  8705. <a href="###" id="switchSolution"
  8706. style="display:none;margin-top:2px;font-size:15px;text-decoration:underline;float:left;">应用方案</a></b></div>
  8707. <div style="margin-top:3px;text-align:right;float:right;">
  8708. <input type="checkbox" id="showSolutionPanelCheckbox" />
  8709. <label for="showSolutionPanelCheckbox" style="margin-left:5px;cursor:pointer;">显示方案切换面板</label>
  8710. <input type="checkbox" id="indexRallyCheckbox" style="margin-left:15px;" />
  8711. <label for="indexRallyCheckbox" style="margin-left:5px;cursor:pointer;">为攻击回合加注索引</label>
  8712. <input type="checkbox" id="keepPkRecordCheckbox" style="margin-left:15px;" />
  8713. <label for="keepPkRecordCheckbox" style="margin-left:5px;cursor:pointer;">暂时保持战斗记录</label>
  8714. </div></div></div>`;
  8715. let pkAddinPanel = pkConfigDiv.querySelector('#pk-addin-panel');
  8716.  
  8717. let refreshSolutionList = pkConfigDiv.querySelector('#refreshSolutionList');
  8718. refreshSolutionList.onclick = (() => { refreshBindingSolutionList(); });
  8719.  
  8720. let bindingSolutions = pkConfigDiv.querySelector('#bindingSolutions');
  8721. function refreshBindingSolutionList() {
  8722. bindingSolutions.innerHTML = '';
  8723. let udata = loadUserConfigData();
  8724. for (let role in udata.dataBind) {
  8725. udata.dataBind[role].split(BINDING_SEPARATOR).forEach((s) => {
  8726. let e = s.split(BINDING_NAME_SEPARATOR);
  8727. if (e.length == 2) {
  8728. let op = document.createElement('option');
  8729. op.value = role + BINDING_NAME_SEPARATOR + e[1];
  8730. op.innerText = g_roleMap.get(role).name + ' : ' + e[0];
  8731. bindingSolutions.appendChild(op);
  8732. }
  8733. });
  8734. }
  8735. switchSolution.style.display = (bindingSolutions.options.length > 0 ? 'inline-block' : 'none');
  8736. }
  8737.  
  8738. let switchSolution = pkConfigDiv.querySelector('#switchSolution');
  8739. switchSolution.onclick = (() => {
  8740. genericPopupInitialize();
  8741. genericPopupShowProgressMessage('读取中,请稍候...');
  8742. switchBindingSolution(bindingSolutions.value);
  8743. });
  8744. refreshBindingSolutionList();
  8745.  
  8746. let showSolutionPanel = setupConfigCheckbox(
  8747. pkConfigDiv.querySelector('#showSolutionPanelCheckbox'),
  8748. g_showSolutionPanelStorageKey,
  8749. (checked) => { solutionPanel.style.display = ((showSolutionPanel = checked) ? 'block' : 'none'); },
  8750. null);
  8751.  
  8752. let solutionPanel = pkConfigDiv.querySelector('#solutionPanel');
  8753. solutionPanel.style.display = (showSolutionPanel ? 'block' : 'none');
  8754.  
  8755. let indexRally = setupConfigCheckbox(
  8756. pkConfigDiv.querySelector('#indexRallyCheckbox'),
  8757. g_indexRallyStorageKey,
  8758. (checked) => { indexRally = checked; },
  8759. null);
  8760.  
  8761. let keepPkRecord = setupConfigCheckbox(
  8762. pkConfigDiv.querySelector('#keepPkRecordCheckbox'),
  8763. g_keepPkRecordStorageKey,
  8764. (checked) => { pkRecordDiv.style.display = ((keepPkRecord = checked) ? 'block' : 'none'); },
  8765. null);
  8766.  
  8767. let pkDiv = document.querySelector('#pk_text');
  8768. pkDiv.parentNode.insertBefore(pkConfigDiv, pkDiv);
  8769. $('#solutionPanel').tooltip();
  8770.  
  8771. let pkRecordDiv = document.createElement('div');
  8772. pkRecordDiv.id = 'pk_record';
  8773. pkRecordDiv.style.marginTop = '5px';
  8774. pkRecordDiv.style.display = (keepPkRecord ? 'block' : 'none');
  8775. pkDiv.parentNode.insertBefore(pkRecordDiv, pkDiv.nextSibling);
  8776.  
  8777. let pkCount = 0;
  8778. let lastPk = null;
  8779. let lastPkTime = null;
  8780. let pkObserver = new MutationObserver(() => {
  8781. pkObserver.disconnect();
  8782. if (indexRally) {
  8783. let turn_l = 0;
  8784. let turn_r = 0;
  8785. pkDiv.querySelectorAll('p.bg-default').forEach((e, i) => {
  8786. let myTurn = (e.parentNode.className.indexOf('fyg_tr') >= 0);
  8787. let rally = document.createElement('b');
  8788. rally.className = 'bg-default';
  8789. rally.innerText = (myTurn ? `${i + 1} ${++turn_l})` : `(${++turn_r}) ${i + 1}`);
  8790. rally.style.float = (myTurn ? 'left' : 'right');
  8791. rally.style.paddingLeft = rally.style.paddingRight = '5px';
  8792. e.nextElementSibling.appendChild(rally);
  8793. });
  8794. }
  8795. if (keepPkRecord) {
  8796. let pkTime = getTimeStamp();
  8797. if (lastPk != null) {
  8798. let player = (lastPk.querySelector('div.col-md-7.fyg_tr > p > span.fyg_f18')?.innerText ?? '(Lv.∞×0 玩家)' + g_kfUser);
  8799. let opponent = (lastPk.querySelector('div.col-md-7.fyg_tl > p > span.fyg_f18')?.innerText ?? '独孤求败(神仙 Lv.1÷0)');
  8800. let pkLabel = lastPk.querySelector('div.with-icon.fyg_tc').cloneNode();
  8801. pkLabel.className = (pkLabel.className?.match(/ (alert-.+?) /)?.[1] ?? '');
  8802. pkLabel.style.padding = '8px';
  8803. pkLabel.style.marginBottom = '2px';
  8804. pkLabel.style.cursor = 'pointer';
  8805. pkLabel.style.fontSize = '18px';
  8806. pkLabel.style.fontWeight = 'bold';
  8807. pkLabel.innerHTML =
  8808. `<div style="float:left;width:45%;text-align:right;">${player}</div>
  8809. <div style="float:left;width:10%;text-align:center;color:#0000c0;">${lastPkTime.time}</div>
  8810. <div style="text-align:left;">${opponent}</div>`;
  8811. pkLabel.onclick = ((e) => {
  8812. let pkhis = e.currentTarget.nextSibling;
  8813. pkhis.style.display = (pkhis.style.display == 'none' ? 'block' : 'none');
  8814. });
  8815.  
  8816. let pkRec = document.createElement('div');
  8817. pkRec.style.marginTop = '2px';
  8818. pkRec.appendChild(pkLabel);
  8819. pkRec.appendChild(lastPk);
  8820. pkRecordDiv.insertBefore(pkRec, pkRecordDiv.firstElementChild);
  8821.  
  8822. $(`#${lastPk.id} .btn[data-toggle="tooltip"]`).tooltip();
  8823. lastPk = null;
  8824. }
  8825. if (lastPkTime != null) {
  8826. if (lastPkTime.date != pkTime.date) {
  8827. let dateLabel = document.createElement('h3');
  8828. dateLabel.innerText = lastPkTime.date;
  8829. dateLabel.style.padding = '5px';
  8830. dateLabel.style.marginTop = '2px';
  8831. dateLabel.style.marginBottom = '2px';
  8832. dateLabel.style.color = '#c0c0c0';
  8833. dateLabel.style.backgroundColor = '#202020';
  8834. dateLabel.style.textAlign = 'center';
  8835. pkRecordDiv.insertBefore(dateLabel, pkRecordDiv.firstElementChild);
  8836. lastPkTime = null;
  8837. }
  8838. }
  8839. if (pkDiv.querySelector('div.with-icon.fyg_tc') != null) {
  8840. lastPk = pkDiv.cloneNode(true);
  8841. lastPk.id = 'pk_history_' + pkCount++;
  8842. lastPk.style.display = 'none';
  8843. lastPkTime = pkTime;
  8844. }
  8845. }
  8846. pkObserver.observe(pkDiv, { characterData : true , childList : true });
  8847. });
  8848. pkObserver.observe(pkDiv, { characterData : true , childList : true });
  8849.  
  8850. pkAddinPanel.setAttribute('pk-text-hooked', 'true');
  8851. }
  8852. }, 200);
  8853. }
  8854. else if (window.location.pathname == g_guguzhenWish) {
  8855. //
  8856. // temporary solution
  8857. //
  8858.  
  8859. function getWishPoints() {
  8860. let text = 'WISH';
  8861. for (let i = 2; i <= 15; i++) {
  8862. text += (' ' + (document.getElementById('xyx_' + ('0' + i).slice(-2))?.innerText ?? '0'));
  8863. console.log(text)
  8864. }
  8865. return text;
  8866. }
  8867.  
  8868. let div = document.createElement('div');
  8869. div.className = 'row';
  8870. div.innerHTML =
  8871. '<div class="panel panel-info"><div class="panel-heading">计算器许愿点设置 (' +
  8872. '<a href="###" id="copyWishPoints">点击这里复制到剪贴板</a>)</div>' +
  8873. '<input type="text" class="panel-body" id="calcWishPoints" readonly="true" ' +
  8874. 'style="width:100%;border:none;outline:none;" value="" /></div>';
  8875.  
  8876. let calcWishPoints = div.querySelector('#calcWishPoints');
  8877. calcWishPoints.value = getWishPoints();
  8878.  
  8879. let xydiv = document.getElementById('xydiv');
  8880. xydiv.parentNode.parentNode.insertBefore(div, xydiv.parentNode.nextSibling);
  8881.  
  8882. div.querySelector('#copyWishPoints').onclick = ((e) => {
  8883. calcWishPoints.select();
  8884. if (document.execCommand('copy')) {
  8885. e.target.innerText = '许愿点设置已复制到剪贴板';
  8886. }
  8887. else {
  8888. e.target.innerText = '复制失败,这可能是因为浏览器没有剪贴板访问权限,请进行手工复制';
  8889. }
  8890. setTimeout(() => { e.target.innerText = '点击这里复制到剪贴板'; }, 3000);
  8891. });
  8892.  
  8893. (new MutationObserver(() => {
  8894. //
  8895. // temporary solution
  8896. //
  8897. calcWishPoints.value = getWishPoints();
  8898. })).observe(xydiv, { subtree : true , childList : true , characterData : true });
  8899. }
  8900. else if (window.location.pathname == g_guguzhenGem) {
  8901. let gemPollPeriod = (g_configMap.get('gemPollPeriod')?.value ?? 0);
  8902. if (gemPollPeriod == 0) {
  8903. return;
  8904. }
  8905. let timer = setInterval(() => {
  8906. let gemdDiv = document.querySelector('#gemd');
  8907. if (gemdDiv?.firstElementChild != null) {
  8908. clearInterval(timer);
  8909.  
  8910. let error = readGemWorkCompletionCondition();
  8911. if (error > 0) {
  8912. addUserMessageSingle('宝石工坊完成条件设置', `在完成条件设置中发现 <b style="color:red;">${error}</b> 个错误,将使用默认值替换。`);
  8913. }
  8914.  
  8915. let unionDiv = document.createElement('div');
  8916. unionDiv.className = 'row';
  8917. unionDiv.innerHTML =
  8918. `<div class="panel panel-info"><div class="panel-heading" style="padding-bottom:10px;">
  8919. <div style="display:inline-block;margin-top:5px;"><b>咕咕镇工会(伪)</b></div>
  8920. <div style="float:right;">上次刷新:<span id="last-refresh-time" style="color:blue;margin-right:15px;"></span>` +
  8921. `距离下次刷新:<a href="###" id="refresh-count-down" style="text-decoration:underline;margin-right:15px;"
  8922. title="立即刷新">00:00:00</a>定时器最大延迟:` +
  8923. `<a href="###" id="refresh-longest-delay" style="text-decoration:underline;margin-right:15px;"
  8924. title="重新开始测量">00:00:00</a>` +
  8925. `<button type="button" id="btn-setup" style="width:60px;">设置</button></div></div>
  8926. <div class="panel-body"><div style="padding:10px;color:#00a0b0;font-size:15px;">
  8927. <b>★ 这是一个浏览器挂机功能,对运行环境要求比较苛刻,在很多情形下都不能正常工作,这些情形包括但不限于浏览器窗口最小化、` +
  8928. `浏览器窗口被其它程序遮挡、本页签为非活动页签及屏幕保护程序运行、屏幕休眠、锁屏等等,不同浏览器的表现可能会有所不同。` +
  8929. `如果您不能接受这些常见情形所导致的运行问题,请谨慎使用本功能或经常检查网页运行状态以确保不会蒙受意外损失` +
  8930. `(刚刚是谁说的WebWorker?我闲但我没那么闲)。<hr>` +
  8931. `★ 根据初步测试,已知新版本的firefox111)、chromium内核(chrome109)、edge109),需关闭页签休眠模式)浏览器` +
  8932. `在窗口最小化、被其它程序遮挡、本页签为非活动页签等情况下可能会产生最长1分钟的延迟,但并不排除发生更长时间延迟的可能性,` +
  8933. `在对较早浏览器版本的测试中曾出现长达6小时以上的延迟。其它浏览器尤其是移动端浏览器的行为尚待测试补充。</b><hr>` +
  8934. `<button type="button" id="btn-apply" style="width:60px;margin-right:5px;" disabled>实施</button>` +
  8935. `<button type="button" id="btn-restore" style="width:60px;" disabled>否决</button></div>
  8936. <div style="padding:10px;">
  8937. <input type="radio" class="condition-config" name="condition-config" id="condition-config-none" checked />
  8938. <label for="condition-config-none" style="cursor:pointer;margin-left:5px;"
  8939. title="手动控制开工及收工时机">BOSS至尊,工会退散</label><br>
  8940. <input type="radio" class="condition-config" name="condition-config" id="condition-config-program" />
  8941. <label for="condition-config-program" style="cursor:pointer;margin-left:5px;"
  8942. title="由挂机程序自动判定收工重开时机">HR强势,KPI考核(不考核任何KPI则强制最短工时轮班)</label></div>
  8943. <div style="padding-left:33px;">
  8944. <div style="display:block;border:1px solid lightgrey;border-radius:5px;margin-left:40;">
  8945. <div style="display:block;padding:5px 15px;border-bottom:1px solid lightgrey;margin-bottom:10px;">
  8946. <input type="radio" class="program-config" name="program-config" id="program-config-or" checked />
  8947. <label for="program-config-or" style="cursor:pointer;margin-left:5px;margin-right:15px;"
  8948. title="工作时长达到目标的前提下,任一选定项目达到预设进度即可收工重开">完成任一选定KPI项</label>
  8949. <input type="radio" class="program-config" name="program-config" id="program-config-and" />
  8950. <label for="program-config-and" style="cursor:pointer;margin-left:5px;margin-right:15px;"
  8951. title="工作时长达到目标的前提下,选定项目全部达到各自预设进度才可收工重开">完成全部选定KPI项</label>
  8952. <b>(已选定 <span id="kpi-count" style="color:#0000c0">0</span> 项)</b>
  8953. </div><div style="padding:5px 15px;"><ul id="kpi-list" style="cursor:pointer;"></ul></div>
  8954. </div></div></div></div>`;
  8955.  
  8956. let lastRefTime = unionDiv.querySelector('#last-refresh-time');
  8957. let refCountDown = unionDiv.querySelector('#refresh-count-down');
  8958. let refLongestDelay = unionDiv.querySelector('#refresh-longest-delay');
  8959. let btnApply = unionDiv.querySelector('#btn-apply');
  8960. let btnRestore = unionDiv.querySelector('#btn-restore');
  8961. let btnSetup = unionDiv.querySelector('#btn-setup');
  8962. let conditionConfig = unionDiv.querySelectorAll('input.condition-config');
  8963. let programConfig = unionDiv.querySelectorAll('input.program-config');
  8964. let kpiList = unionDiv.querySelector('#kpi-list');
  8965. let kpiCount = unionDiv.querySelector('#kpi-count');
  8966.  
  8967. function refreshTime() {
  8968. let ts = getTimeStamp();
  8969. lastRefTime.innerText = ts.date + ' ' + ts.time;
  8970. }
  8971.  
  8972. conditionConfig.forEach((op) => {
  8973. op.onchange = (() => { btnApply.disabled = btnRestore.disabled = ''; });
  8974. });
  8975.  
  8976. programConfig.forEach((op) => {
  8977. op.onchange = (() => { btnApply.disabled = btnRestore.disabled = ''; });
  8978. });
  8979.  
  8980. const highlightBackgroundColor = '#80c0f0';
  8981. g_gemWorks.forEach((item) => {
  8982. let li = document.createElement('li');
  8983. li.setAttribute('original-item', item.name);
  8984. li.innerHTML = `<a href="###">${item.name} ${item.completionProgress.toString() + item.unitSymbol}】</a>`;
  8985. li.onclick = selectGemWork;
  8986. kpiList.appendChild(li);
  8987. });
  8988. function selectGemWork(e) {
  8989. let count = parseInt(kpiCount.innerText);
  8990. if ($(this).attr('item-selected') != 1) {
  8991. $(this).attr('item-selected', 1);
  8992. $(this).css('background-color', highlightBackgroundColor);
  8993. count++;
  8994. }
  8995. else {
  8996. $(this).attr('item-selected', 0);
  8997. $(this).css('background-color', '');
  8998. count--;
  8999. }
  9000. kpiCount.innerText = count;
  9001. btnApply.disabled = btnRestore.disabled = '';
  9002. }
  9003.  
  9004. let currentGemConfig;
  9005. function saveGemConfig(gemConfig) {
  9006. localStorage.setItem(g_gemConfigStorageKey, collectConfig(gemConfig));
  9007. btnApply.disabled = btnRestore.disabled = 'disabled';
  9008.  
  9009. function collectConfig(gemConfig) {
  9010. if (gemConfig == null) {
  9011. gemConfig = {
  9012. gemConfig : conditionConfig[0].checked ? 0 : 1,
  9013. programConfig : programConfig[0].checked ? 0 : 1,
  9014. kpiList : []
  9015. };
  9016. for (let i = kpiList.children?.length - 1; i >= 0; i--) {
  9017. if (kpiList.children[i].getAttribute('item-selected') == 1) {
  9018. gemConfig.kpiList.push(kpiList.children[i].getAttribute('original-item'));
  9019. }
  9020. }
  9021. }
  9022. currentGemConfig = gemConfig;
  9023. return `${gemConfig.gemConfig}|${gemConfig.programConfig}` +
  9024. `${gemConfig.kpiList.length > 0 ? '|' + gemConfig.kpiList.join(',') : ''}`;
  9025. }
  9026. }
  9027.  
  9028. function loadGemConfig() {
  9029. let gemConfig = parseConfig();
  9030. let error = (gemConfig == null);
  9031. if (error) {
  9032. gemConfig = { gemConfig : 0 , programConfig : 0 , kpiList : [] };
  9033. }
  9034. else {
  9035. for (let i = gemConfig.kpiList.length - 1; i >= 0; i--) {
  9036. if (!g_gemWorkMap.has(gemConfig.kpiList[i])) {
  9037. gemConfig.kpiList.splice(i, 1);
  9038. error = true;
  9039. }
  9040. }
  9041. }
  9042. if (error) {
  9043. saveGemConfig(gemConfig);
  9044. }
  9045. representConfig(gemConfig);
  9046. btnApply.disabled = btnRestore.disabled = 'disabled';
  9047. return (currentGemConfig = gemConfig);
  9048.  
  9049. function parseConfig() {
  9050. let config = localStorage.getItem(g_gemConfigStorageKey)?.split('|');
  9051. if (config?.length >= 2 && config?.length <= 3) {
  9052. let gemConfig = {
  9053. gemConfig : parseInt(config[0]),
  9054. programConfig : parseInt(config[1]),
  9055. kpiList : config[2]?.split(',') ?? []
  9056. };
  9057. if (gemConfig.gemConfig >= 0 && gemConfig.gemConfig <= 1 &&
  9058. gemConfig.programConfig >= 0 && gemConfig.programConfig <= 1) {
  9059.  
  9060. return gemConfig;
  9061. }
  9062. }
  9063. return null;
  9064. }
  9065.  
  9066. function representConfig(gemConfig) {
  9067. conditionConfig[0].checked = !(conditionConfig[1].checked = (gemConfig.gemConfig == 1));
  9068. programConfig[0].checked = !(programConfig[1].checked = (gemConfig.programConfig == 1));
  9069. let count = 0;
  9070. for (let i = kpiList.children?.length - 1; i >= 0; i--) {
  9071. if (gemConfig.kpiList.indexOf(kpiList.children[i].getAttribute('original-item')) >= 0) {
  9072. kpiList.children[i].setAttribute('item-selected', 1);
  9073. kpiList.children[i].style.backgroundColor = highlightBackgroundColor;
  9074. count++;
  9075. }
  9076. else {
  9077. kpiList.children[i].setAttribute('item-selected', 0);
  9078. kpiList.children[i].style.backgroundColor = '';
  9079. }
  9080. kpiCount.innerText = count;
  9081. }
  9082. }
  9083. }
  9084.  
  9085. refCountDown.onclick = (() => { queueRefresh(0); });
  9086. refLongestDelay.onclick = (() => { longestDelay = 0; refLongestDelay.innerText = '00:00:00'; });
  9087. btnApply.onclick = (() => { saveGemConfig(null); shiftConfirm = true; queueRefresh(0); });
  9088. btnRestore.onclick = (() => { loadGemConfig(); });
  9089. btnSetup.onclick = (() => { modifyConfig(['gemPollPeriod', 'gemWorkCompletionCondition'], '宝石工坊挂机设置', true); });
  9090.  
  9091. let div = gemdDiv.parentNode.parentNode;
  9092. div.parentNode.insertBefore(unionDiv, div.nextSibling);
  9093.  
  9094. loadGemConfig();
  9095.  
  9096. let longestDelay = 0;
  9097. let countDownTimer = null;
  9098. function queueRefresh(timeSecond) {
  9099. if (countDownTimer != null) {
  9100. clearTimeout(countDownTimer);
  9101. countDownTimer = null;
  9102. refCountDown.innerText = '00:00:00';
  9103. }
  9104. if (timeSecond == 0) {
  9105. rgamd();
  9106. }
  9107. else if (timeSecond > 0) {
  9108. let lastTick = Date.now();
  9109. let fireTime = lastTick + (timeSecond * 1000);
  9110. let interval = fireTime;
  9111. timerRoutine(false);
  9112.  
  9113. function timerRoutine(setOnly) {
  9114. let now = Date.now();
  9115. let delay = (now - lastTick) - interval;
  9116. if (delay > longestDelay) {
  9117. longestDelay = delay;
  9118. refLongestDelay.innerText = formatTimeSpan(longestDelay - 999);
  9119. }
  9120.  
  9121. let etr = fireTime - now;
  9122. if (etr <= 0) {
  9123. countDownTimer = null;
  9124. rgamd();
  9125. }
  9126. else if (setOnly) {
  9127. lastTick = now;
  9128. countDownTimer = setTimeout(timerRoutine, interval = Math.min(etr, 1000), false);
  9129. }
  9130. else {
  9131. refCountDown.innerText = formatTimeSpan(etr);
  9132. timerRoutine(true);
  9133. }
  9134. }
  9135.  
  9136. function formatTimeSpan(milliseconds) {
  9137. return `${('0' + Math.trunc((milliseconds += 999) / 3600000)).slice(-2)}:${
  9138. ('0' + Math.trunc(milliseconds / 60000) % 60).slice(-2)}:${
  9139. ('0' + Math.trunc(milliseconds / 1000) % 60).slice(-2)}`;
  9140. }
  9141. }
  9142. }
  9143.  
  9144. const defaultShiftDelay = 50;
  9145. let shiftDelay = defaultShiftDelay;
  9146. const changeShiftRequest = g_httpRequestMap.get('cgamd');
  9147. function changeShift() {
  9148. function beginChangeShift() {
  9149. httpRequestBegin(
  9150. changeShiftRequest.request,
  9151. changeShiftRequest.data,
  9152. (response) => {
  9153. addUserMessageSingle('宝石工坊', response.responseText);
  9154. rgamd();
  9155. },
  9156. () => { queueRefresh(g_gemFailurePollPeriodSecond); },
  9157. () => { queueRefresh(g_gemFailurePollPeriodSecond); });
  9158. }
  9159.  
  9160. if (shiftDelay > 0) {
  9161. let timer = setInterval(() => {
  9162. if (shiftDelay <= 0) {
  9163. clearInterval(timer);
  9164. shiftDelay = defaultShiftDelay;
  9165. beginChangeShift();
  9166. }
  9167. }, shiftDelay);
  9168. }
  9169. else {
  9170. shiftDelay = defaultShiftDelay;
  9171. beginChangeShift();
  9172. }
  9173. }
  9174.  
  9175. function collectGemWorkStatus(workDivs) {
  9176. let status = [];
  9177. g_gemWorks.forEach((template, i) => {
  9178. let lines = workDivs[i].innerHTML.replace('\r', '').replace('\n', '').split('<br>');
  9179. if (lines?.length >= 5 && template.nameRegex.regex.test(lines[template.nameRegex.line])) {
  9180. status.push(`${template.name}:${lines[template.progressRegex.line]
  9181. .match(template.progressRegex.regex)?.[1]}${template.unitSymbol}`);
  9182. }
  9183. });
  9184. return (status.length > 0 ? status.join(',') : '休息日');
  9185. }
  9186.  
  9187. function calculateGemWork(template, workDiv, timeElapsed) {
  9188. let etc = [-1, 0];
  9189. let lines = workDiv.innerHTML.replace('\r', '').replace('\n', '').split('<br>');
  9190. if (lines?.length < 5 || !template.nameRegex.regex.test(lines[template.nameRegex.line])) {
  9191. return etc;
  9192. }
  9193. let progress = Number.parseFloat(lines[template.progressRegex.line].match(template.progressRegex.regex)?.[1]);
  9194. let unit = Number.parseFloat(lines[template.unitRegex.line].match(template.unitRegex.regex)?.[1]);
  9195. if (isNaN(progress) || isNaN(unit) || unit == 0) {
  9196. return etc;
  9197. }
  9198. if (template.precision == 0) {
  9199. etc[1] = Math.ceil(Math.trunc(progress + 1) / unit) - timeElapsed;
  9200. }
  9201. else if (Math.ceil(progress / unit) < timeElapsed) {
  9202. etc[1] = -1;
  9203. }
  9204. etc[0] = Math.ceil(template.completionProgress / unit) - timeElapsed;
  9205. if (etc[0] < 0) {
  9206. etc[0] = 0;
  9207. }
  9208. return etc;
  9209. }
  9210.  
  9211. let shiftConfirm = true;
  9212. function updateGemWorks() {
  9213. refreshTime();
  9214. queueRefresh(-1);
  9215.  
  9216. let btn = gemdDiv.querySelector('div.col-sm-12 > button.btn.btn-block.btn-lg');
  9217. if (btn == null) {
  9218. queueRefresh(g_gemFailurePollPeriodSecond);
  9219. return;
  9220. }
  9221.  
  9222. let workTime = btn.innerText?.match(/^已开工(\d+)小时(\d+)分钟/);
  9223. let timeElapsed = parseInt(workTime?.[1]) * 60 + parseInt(workTime?.[2]);
  9224. let etr = g_gemMinWorktimeMinute - timeElapsed;
  9225.  
  9226. let checkList = null;
  9227. let checkCount = 0;
  9228. if (currentGemConfig.gemConfig == 1) {
  9229. if (isNaN(etr)) {
  9230. if (!shiftConfirm || confirm('宝石工坊尚未开工,是否开工?')) {
  9231. shiftConfirm = false;
  9232. changeShift();
  9233. return;
  9234. }
  9235. else {
  9236. conditionConfig[0].checked = !(conditionConfig[1].checked = false)
  9237. currentGemConfig.gemConfig = 0;
  9238. }
  9239. }
  9240. else if (etr <= 0) {
  9241. checkList = currentGemConfig.kpiList;
  9242. checkCount = (currentGemConfig.programConfig == 0 ? Math.min(1, checkList.length) : checkList.length);
  9243. }
  9244. }
  9245.  
  9246. let pollTime = (etr > 0 ? Math.min(etr, gemPollPeriod) : gemPollPeriod);
  9247. let shift = (checkList != null && checkCount == 0);
  9248.  
  9249. let workDivs = gemdDiv.querySelectorAll('div.col-sm-2 > div.fyg_f14.fyg_lh30');
  9250. for (let i = workDivs?.length - 1; i >= 0; i--) {
  9251. let result = '未开工';
  9252. if (i < g_gemWorks.length) {
  9253. let etc = calculateGemWork(g_gemWorks[i], workDivs[i], timeElapsed);
  9254. if (etc[0] > 0) {
  9255. if (etc[0] < pollTime) {
  9256. pollTime = etc[0];
  9257. }
  9258. let h = Math.trunc(etc[0] / 60);
  9259. let m = etc[0] % 60;
  9260. result = `剩余 ${h == 0 ? '' : `${h} 小时 `}${m == 0 ? '' : `${m} 分`}`.trim();
  9261. }
  9262. else if (etc[0] == 0) {
  9263. if (!shift && checkList?.indexOf(g_gemWorks[i].name) >= 0) {
  9264. shift = (--checkCount == 0);
  9265. }
  9266. result = `已完成`;
  9267. workDivs[i].className = workDivs[i].className.replace('info', 'danger');
  9268. }
  9269. result += '<br>';
  9270. if (etc[1] > 0) {
  9271. let h = Math.trunc(etc[1] / 60);
  9272. let m = etc[1] % 60;
  9273. result += `距下一整数 ${h == 0 ? '' : `${h} 小时 `}${m == 0 ? '' : `${m} 分`}`.trim();
  9274. }
  9275. else if (etc[1] < 0 || g_gemWorks[i].precision == 0) {
  9276. result += '进度已达上限';
  9277. }
  9278. else {
  9279. result += '&nbsp;';
  9280. }
  9281. }
  9282. workDivs[i].innerHTML += ('<br>' + result);
  9283. }
  9284. if (shift) {
  9285. if (!shiftConfirm || confirm('宝石工坊已达换班条件,是否换班?')) {
  9286. shiftConfirm = false;
  9287. addUserMessageSingle('宝石工坊', `准备换班,${workTime[0].substring(1)},工作进度(${collectGemWorkStatus(workDivs)})。`);
  9288. changeShift();
  9289. return;
  9290. }
  9291. else {
  9292. conditionConfig[0].checked = !(conditionConfig[1].checked = false)
  9293. currentGemConfig.gemConfig = 0;
  9294. }
  9295. }
  9296. shiftConfirm = false;
  9297. queueRefresh(pollTime * 60);
  9298. }
  9299.  
  9300. $(document).ajaxComplete((e, r) => {
  9301. if (r.status != 200) {
  9302. queueRefresh(g_gemFailurePollPeriodSecond);
  9303. }
  9304. });
  9305.  
  9306. let gemWorksObserver = new MutationObserver(() => {
  9307. gemWorksObserver.disconnect();
  9308. updateGemWorks();
  9309. gemWorksObserver.observe(gemdDiv, { subtree : true , childList : true , characterData : true });
  9310. shiftDelay = 0;
  9311. });
  9312.  
  9313. updateGemWorks();
  9314. gemWorksObserver.observe(gemdDiv, { subtree : true , childList : true , characterData : true });
  9315. shiftDelay = 0;
  9316. }
  9317. }, 200);
  9318. }
  9319. }
  9320.  
  9321. ////////////////////////////////////////////////////////////////////////////////////////////////////
  9322. //
  9323. // array utilities
  9324. //
  9325. ////////////////////////////////////////////////////////////////////////////////////////////////////
  9326.  
  9327. // perform a binary search. array must be sorted, but no matter in ascending or descending order.
  9328. // in this manner, you must pass in a proper comparer function for it works properly, aka, if the
  9329. // array was sorted in ascending order, then the comparer(a, b) should return a negative value
  9330. // while a < b or a positive value while a > b; otherwise, if the array was sorted in descending
  9331. // order, then the comparer(a, b) should return a positive value while a < b or a negative value
  9332. // while a > b, and in both, if a equals b, the comparer(a, b) should return 0. if you pass nothing
  9333. // or null / null value as comparer, then you must make sure about that the array was sorted
  9334. // in ascending order.
  9335. //
  9336. // in this particular case, we just want to check whether the array contains the value or not, we
  9337. // don't even need to point out the first place where the value appears (if the array actually
  9338. // contains the value), so we perform a simplest binary search and return an index (may not the
  9339. // first place where the value appears) or a negative value (means value not found) to indicate
  9340. // the search result.
  9341. function searchElement(array, value, fnComparer) {
  9342. if (array?.length > 0) {
  9343. fnComparer ??= ((a, b) => a < b ? -1 : (a > b ? 1 : 0));
  9344. let li = 0;
  9345. let hi = array.length - 1;
  9346. while (li <= hi) {
  9347. let mi = ((li + hi) >> 1);
  9348. let cr = fnComparer(value, array[mi]);
  9349. if (cr == 0) {
  9350. return mi;
  9351. }
  9352. else if (cr > 0) {
  9353. li = mi + 1;
  9354. }
  9355. else {
  9356. hi = mi - 1;
  9357. }
  9358. }
  9359. }
  9360. return -1;
  9361. }
  9362.  
  9363. // perform a binary insertion. the array and comparer must exactly satisfy as it in the searchElement
  9364. // function. this operation behaves sort-stable, aka, the newer inserting element will be inserted
  9365. // into the position after any existed equivalent elements.
  9366. function insertElement(array, value, fnComparer) {
  9367. if (array != null) {
  9368. fnComparer ??= ((a, b) => a < b ? -1 : (a > b ? 1 : 0));
  9369. let li = 0;
  9370. let hi = array.length - 1;
  9371. while (li <= hi) {
  9372. let mi = ((li + hi) >> 1);
  9373. let cr = fnComparer(value, array[mi]);
  9374. if (cr >= 0) {
  9375. li = mi + 1;
  9376. }
  9377. else {
  9378. hi = mi - 1;
  9379. }
  9380. }
  9381. array.splice(li, 0, value);
  9382. return li;
  9383. }
  9384. return -1;
  9385. }
  9386.  
  9387. // it's not necessary to have newArray been sorted, but the oldArray must be sorted since we are calling
  9388. // searchElement. if there are some values should be ignored in newArray, the comparer(a, b) should be
  9389. // implemented as return 0 whenever parameter a equals any of values that should be ignored.
  9390. function findNewObjects(newArray, oldArray, findIndices, removeDupFromOldArray, fnComparer) {
  9391. if (!removeDupFromOldArray) {
  9392. oldArray = oldArray?.slice();
  9393. }
  9394. let newObjects = [];
  9395. for (let i = newArray?.length - 1; i >= 0; i--) {
  9396. let index = searchElement(oldArray, newArray[i], fnComparer);
  9397. if (index < 0) {
  9398. newObjects.unshift(findIndices ? i : newArray[i]);
  9399. }
  9400. else {
  9401. oldArray.splice(index, 1);
  9402. }
  9403. }
  9404. return newObjects;
  9405. };
  9406. $(document).ready(function(e) { gudaq();});