NEET Lib

NEET Bot Library

当前为 2019-10-22 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/383201/743039/NEET%20Lib.js

  1. // ==UserScript==
  2. // @name NEET Lib
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.5.0
  5. // @description NEET Bot Library
  6. // @author eterNEETy
  7. // @match http://game.granbluefantasy.jp/
  8. // @grant none
  9. // @namespace https://greasyfork.org/users/292830
  10. // ==/UserScript==
  11. // jshint esversion: 6
  12. // jshint -W138
  13.  
  14. /*
  15.  
  16. changelog:
  17.  
  18. 1.1.0:
  19. - added init()
  20. - changed `let main_path` to `path.main`
  21.  
  22. 1.2.0:
  23. - changed charMoveSet cid
  24.  
  25. 1.3.0:
  26. - added discord_mention
  27. 1.3.2:
  28. - missionComplete(cmd=[]);
  29.  
  30. 1.4.0:
  31. - lot of skill changes
  32. 1.4.1:
  33. - changed scrollTo to scroll_To
  34. 1.4.2:
  35. - changed getCoord, added auto scroll
  36.  
  37. 1.5.0:
  38. - replaced all references
  39. - changed 'message' from not defined to defined (let)
  40. - changed 'getMessage' to 'updateMessage'
  41. - changed 'battleLogic' from function to var
  42. - changed 'listenNetwork' from function to var
  43. */
  44.  
  45.  
  46. // environment info
  47. const xhr = new XMLHttpRequest(),
  48. server = 'http://localhost:2487',
  49. margin = {'top':91,'left':0},
  50. game_url = 'http://game.granbluefantasy.jp/';
  51.  
  52. let debug = true,
  53. reload_counter;
  54.  
  55. let zoom = 1;
  56.  
  57. let is_host = 'false';
  58. let battle;
  59. let is_wiped = true;
  60. let discord_mention = '';
  61. let abi_special_case = false;
  62.  
  63. let quests_id = [], monsters = [], monsters_name = [];
  64. const recovery_items = ['Elixir','Half Elixir','Soul Balm','Soul Berry'];
  65. let reloadable_skill = ['Four-Sky\'s Sorrow', 'Thunder Raid'];
  66. let tracker_reward_weapons = [];
  67. let tracker_reward_summons = [];
  68. let tracker_reward_items = [recovery_items[0], recovery_items[1], recovery_items[2], recovery_items[3],'Gold Brick','Damascus Grain','Silver Centrum'];
  69.  
  70.  
  71. const kaguya = {'name':'Kaguya', 'star':0},
  72. white_rabbit = {'name':'White Rabbit', 'star':3},
  73. black_rabbit = {'name':'Black Rabbit', 'star':3},
  74. huanglong = {'name':'Huanglong', 'star':3},
  75. shiva = {'name':'Shiva', 'star':3},
  76. shiva0 = {'name':'Shiva', 'star':0},
  77. varuna = {'name':'Varuna', 'star':3},
  78. bonito = {'name':'Bonito', 'star':4},
  79. yggdrasil = {'name':'Yggdrasil Omega', 'star':4},
  80. uriel = {'name':'Uriel', 'star':0},
  81. tiamat = {'name':'Tiamat Omega', 'star':4},
  82. bahamut = {'name':'Bahamut', 'star':5},
  83. lucifer = {'name':'Lucifer', 'star':5};
  84. const leech_summons = [kaguya,white_rabbit,black_rabbit];
  85.  
  86. // const game variable
  87. // const trials_id = ["990011","990021","990031","990041","990051","990061","990071"],
  88. // select_summon_path = "supporter/";
  89. const trial_id = '990011',
  90. select_summon_path = 'supporter/';
  91. // path
  92. let path = {
  93. 'main': '',
  94. 'item':'#item',
  95. 'quest':'#quest',
  96. 'support':'#quest/supporter/',
  97. 'assist':'#quest/assist',
  98. 'unclaimed':'#quest/assist/unclaimed',
  99. 'trial':'#quest/supporter/'+trial_id+'/17',
  100. };
  101.  
  102. // element dom query selector
  103. let skill_char = '#prt-command-top > div > div > div.lis-character';
  104. let skill_abi = '.btn-command-character > div.prt-ability-state > div.lis-ability-state.ability';
  105. let query = {
  106. 'battle_ui': {
  107. 'skill': {
  108. 'char1': {
  109. 'skill1': skill_char + '0' + skill_abi + '1',
  110. 'skill2': skill_char + '0' + skill_abi + '2',
  111. 'skill3': skill_char + '0' + skill_abi + '3',
  112. 'skill4': skill_char + '0' + skill_abi + '4',
  113. },
  114. 'char2': {
  115. 'skill1': skill_char + '1' + skill_abi + '1',
  116. 'skill2': skill_char + '1' + skill_abi + '2',
  117. 'skill3': skill_char + '1' + skill_abi + '3',
  118. 'skill4': skill_char + '1' + skill_abi + '4',
  119. },
  120. 'char3': {
  121. 'skill1': skill_char + '2' + skill_abi + '1',
  122. 'skill2': skill_char + '2' + skill_abi + '2',
  123. 'skill3': skill_char + '2' + skill_abi + '3',
  124. 'skill4': skill_char + '2' + skill_abi + '4',
  125. },
  126. 'char4': {
  127. 'skill1': skill_char + '3' + skill_abi + '1',
  128. 'skill2': skill_char + '3' + skill_abi + '2',
  129. 'skill3': skill_char + '3' + skill_abi + '3',
  130. 'skill4': skill_char + '3' + skill_abi + '4',
  131. },
  132. },
  133. 'skill_pop_up': {
  134. 'char1': 'div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character0.btn-command-character > img',
  135. 'char2': 'div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character1.btn-command-character > img',
  136. 'char3': 'div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character2.btn-command-character > img',
  137. 'char4': 'div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character3.btn-command-character > img',
  138. 'char5': 'div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character4.btn-command-character > img',
  139. 'char6': 'div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character5.btn-command-character > img',
  140. },
  141. 'ougi': '.btn-lock',
  142. 'toggle_ougi': {
  143. true: '.lock0',
  144. false: '.lock1',
  145. },
  146. 'char_ico': '.prt-party>.prt-member>.btn-command-character>img.img-chara-command',
  147. 'summon_panel': '.prt-summon-list>.prt-list-top.btn-command-summon',
  148. 'chat':'.btn-chat.comment.display-on',
  149. 'chat_pop_up': {
  150. 'dialog':'.txt-chat-pop',
  151. },
  152. 'heal':'#prt-sub-command-group>.btn-temporary',
  153. 'heal_pop_up': {
  154. 'green': '.lis-item.item-small',
  155. 'blue': '.lis-item.item-large',
  156. 'Green Potion': '.lis-item.item-small',
  157. 'Blue Potion': '.lis-item.item-large',
  158. 'Support Potion': '.lis-item.btn-event-item[item-id="1"]',
  159. 'Clarity Herb': '.lis-item.btn-event-item[item-id="2"]',
  160. 'Revival Potion': '.lis-item.btn-event-item[item-id="3"]',
  161. 'use': '.pop-usual.pop-raid-item.pop-show>.prt-popup-footer>.btn-usual-use',
  162. 'cancel': '.pop-usual.pop-raid-item.pop-show>.prt-popup-footer>.btn-usual-cancel',
  163. },
  164. 'trial_pop_up': {
  165. 'close': '.pop-usual.pop-trialbattle-notice.pop-show>.prt-popup-footer>.btn-usual-close',
  166. },
  167. 'backup_pop_up': {
  168. 'request': '.pop-usual.pop-start-assist.pop-show>.prt-popup-footer>.btn-usual-text',
  169. 'cancel': '.pop-usual.pop-start-assist.pop-show>.prt-popup-footer>.btn-usual-cancel',
  170. },
  171. 'button': {
  172. 'assist': '.prt-multi-buttons>.btn-assist',
  173. },
  174. },
  175. 'assist_ui': {
  176. 'tab_id': '#tab-id',
  177. 'tab_multi': '#tab-multi',
  178. 'tab_event': '#tab-event',
  179. 'unclaimed': '.btn-unclaimed',
  180. },
  181. 'poker': {
  182. 'canvas': '#canv',
  183. 'deal': '.prt-start',
  184. 'ok': '.prt-ok',
  185. 'yes': '.prt-yes',
  186. 'no': '.prt-no',
  187. 'low': '.prt-double-select>.prt-low-shine',
  188. 'high': '.prt-double-select>.prt-high-shine',
  189. },
  190. 'ok':'.btn-usual-ok',
  191. };
  192.  
  193. let my_profile = '';
  194. function updateMessage(pilot) {
  195. const message = {
  196. "raid" : {
  197. "panel" : {
  198. "open" : pilot+"Opening quest/raid panel",
  199. "pick" : pilot+"Picking quest/raid difficulties",
  200. },
  201. "select_party" : pilot+"Selecting party",
  202. "finish" : pilot+"Raid finished",
  203. "trial" : {
  204. "close_pop_up" : pilot+"In trial, closing pop up",
  205. "open_menu" : pilot+ "In trial, click menu",
  206. "retreat" : pilot+ "In trial, click retreat",
  207. "ok" : pilot+ "In trial, click ok",
  208. "end" : pilot+"Retreated from trial, back to main raid",
  209. }
  210. },
  211. "summon" : {
  212. "select" : pilot+"Selecting summon",
  213. "pick_tab" : pilot+"Clicking summon element tab",
  214. "not_found" : pilot+"Support summon not found, going to trial",
  215. },
  216. "replenish" : {
  217. "elixir" : {
  218. "half_elixir" : {
  219. "use" : pilot+"Not enough AP, using half elixir",
  220. "used" : pilot+"Half elixir used",
  221. }
  222. },
  223. "soul" : {
  224. "soul_berry" : {
  225. "use" : pilot+"Not enough EP, using soul berry",
  226. "used" : pilot+"soul berry used",
  227. }
  228. }
  229. },
  230. "ok" : pilot+"Clicking ok",
  231. };
  232. return message;
  233. }
  234. let message = updateMessage(my_profile);
  235.  
  236. // general item variable
  237. let tracked_item = false;
  238.  
  239.  
  240.  
  241. function reloadNow() {
  242. console.log(reloadNow.name);
  243. xhr.open('POST', server);
  244. xhr.send(JSON.stringify([{'cmd':'press','key':'f5'}]));
  245. window.location.reload();
  246. }
  247.  
  248. function reload(mod_value=1) {
  249. clearInterval(reload_counter);
  250. let current_path = window.location.hash;
  251. let count = 1;
  252. reload_counter = setInterval(function() {
  253. if(window.location.hash != current_path){
  254. clearInterval(reload_counter);
  255. }
  256. console.log('reloading in '+(mod_value-count).toString());
  257. if (count%mod_value===0){
  258. clearInterval(reload_counter);
  259. reloadNow();
  260. }
  261. count += 1;
  262. }, 1000);
  263. }
  264.  
  265. function setDebug() {
  266. if(!debug){
  267. console.log('DEBUG is turned OFF');
  268. if(!window.console) window.console = {};
  269. let methods = ['log', 'debug', 'warn', 'info'];
  270. for(let i=0;i<methods.length;i++){
  271. console[methods[i]] = function(){};
  272. }
  273. }
  274. }
  275.  
  276. function readBody(xhr) {
  277. let data;
  278. if (!xhr.responseType || xhr.responseType === 'text') {
  279. data = xhr.responseText;
  280. } else if (xhr.responseType === 'document') {
  281. data = xhr.responseXML;
  282. } else {
  283. data = xhr.response;
  284. }
  285. return data;
  286. }
  287.  
  288. function gotoHash(key){
  289. let hash_path;
  290. if (path[key] !== undefined) {
  291. hash_path = path[key];
  292. }else{
  293. if (key.indexOf('#')!==0) {
  294. hash_path = '#'+key;
  295. }
  296. }
  297. window.location.href = game_url + hash_path;
  298. }
  299.  
  300. function scroll_To(query,qid=0) {
  301. document.querySelectorAll(query)[qid].scrollIntoViewIfNeeded();
  302. }
  303.  
  304. function checkExist(query,qid=0) {
  305. let el_exist = false;
  306. if (document.querySelectorAll(query).length > qid){
  307. if (document.querySelectorAll(query)[qid].getBoundingClientRect().width > 0 && document.querySelectorAll(query)[qid].getBoundingClientRect().height > 0) {
  308. el_exist = true;
  309. }
  310. }
  311. return el_exist;
  312. }
  313.  
  314. function checkEl(query,qid=0,callback=false) {
  315. let old_top = -1;
  316. let old_left = -1;
  317. let loop_checkEl = setInterval(function() {
  318. console.log(checkEl.name + " " + query + "[" + qid + "]");
  319. if (checkExist(query,qid)) {
  320. if (old_top==document.querySelectorAll(query)[qid].getBoundingClientRect().top && old_left==document.querySelectorAll(query)[qid].getBoundingClientRect().left) {
  321. clearInterval(loop_checkEl);
  322. if (typeof callback == "function") {
  323. callback();
  324. }
  325. }else{
  326. old_top = document.querySelectorAll(query)[qid].getBoundingClientRect().top;
  327. old_left = document.querySelectorAll(query)[qid].getBoundingClientRect().left;
  328. }
  329. }
  330. }, 200);
  331. }
  332.  
  333. function checkEls(queries,callback=false) {
  334. let exist_result;
  335. let loop_checkEls = setInterval(function() {
  336. exist_result = [];
  337. for (let i in queries) {
  338. console.log(checkEls.name + " " + queries[i].query + "[" + queries[i].qid + "]");
  339. exist_result.push(checkExist(queries[i].query,queries[i].qid));
  340. }
  341. if (exist_result.indexOf(false)===-1) {
  342. clearInterval(loop_checkEls);
  343. if (typeof callback == "function") {
  344. callback();
  345. }
  346. }
  347. }, 300);
  348. }
  349.  
  350. function checkElsOR(queries,callback=false) {
  351. let exist_result;
  352. let loop_checkEls = setInterval(function() {
  353. exist_result = [];
  354. for (let i in queries) {
  355. console.log(checkElsOR.name + " " + queries[i].query + "[" + queries[i].qid + "]");
  356. exist_result.push(checkExist(queries[i].query,queries[i].qid));
  357. }
  358. if (exist_result.indexOf(true)>=0) {
  359. clearInterval(loop_checkEls);
  360. if (typeof callback == "function") {
  361. callback();
  362. }
  363. }
  364. }, 300);
  365. }
  366.  
  367. function checkError() {
  368. let q_cnt_error = ".cnt-error";
  369. let q_pop_up = ".pop-usual.common-pop-error.pop-show";
  370. let q_abi_pop_up = ".pop-usual.pop-raid-ability-error.pop-show";
  371. let check_error = setInterval(function() {
  372. console.log(checkError.name);
  373. if (checkExist(q_pop_up,0) || checkExist(q_cnt_error,0) || checkExist(q_abi_pop_up,0)) {
  374. let cmd = [];
  375. console.log("error_found");
  376. let do_reload = false;
  377. let level = "notif";
  378. let msg = "Uncatagorized error found";
  379. // let msg = "Connection error, refreshing disabled"
  380. if (checkExist(q_abi_pop_up,0)) {
  381. do_reload = true;
  382. msg = my_profile + document.querySelector(q_abi_pop_up+">.prt-popup-body>.txt-popup-body").innerHTML;
  383. level = "process";
  384. } else {
  385. if (checkExist(q_pop_up+">.prt-popup-header",0)) {
  386. if (document.querySelector(q_pop_up+">.prt-popup-header").innerHTML=="Access Verification") {
  387. clearInterval(reload_counter);
  388. clearInterval(check_error);
  389. msg = my_profile+"Captcha detected. " + discord_mention;
  390. console.log("Captcha detected");
  391. }else if (document.querySelector(q_pop_up+">.prt-popup-header").innerHTML=="エラー") {
  392. if (checkExist(q_pop_up+">.prt-popup-body>.txt-popup-body>div",0)) {
  393. if (typeof document.querySelector(q_pop_up+">.prt-popup-body>.txt-popup-body>div").innerHTML == "string") {
  394. if (document.querySelector(q_pop_up+">.prt-popup-body>.txt-popup-body>div").innerHTML.indexOf("Network Error")>=0) {
  395. clearInterval(reload_counter);
  396. console.log("Error connection");
  397. do_reload = true;
  398. msg = my_profile+"Error connection, reloading";
  399. level = "process";
  400. }
  401. }
  402. }
  403. }
  404. }
  405. if (checkExist(q_pop_up+">.prt-popup-body>.txt-popup-body",0)) {
  406. if (document.querySelector(q_pop_up+">.prt-popup-body>.txt-popup-body").innerHTML=="Check your pending battles.") {
  407. console.log("check raid");
  408. level = "process";
  409. msg = my_profile+"Check your pending battle";
  410. clickEl(".prt-popup-footer>.btn-usual-ok",0,my_profile+"Clicking ok pop up pending battles");
  411. }
  412. }
  413. }
  414. if (do_reload){
  415. cmd.push({"cmd":"press","key":"f5"});
  416. }
  417. cmd.push({"cmd":"log","level":level,"msg":msg});
  418. xhr.open('POST', server);
  419. xhr.send(JSON.stringify(cmd));
  420. if (do_reload){
  421. window.location.reload();
  422. }
  423. }
  424. }, 5000);
  425. }
  426.  
  427. function getCoord(el){
  428. zoom = parseInt(document.getElementById("mobage-game-container").style.zoom);
  429. let x, y, output;
  430. let pos_el = el.getBoundingClientRect();
  431. if (pos_el.top >= 0 && pos_el.bottom <= window.innerHeight) {
  432. if (pos_el.width>0 && pos_el.height>0) {
  433. x = (pos_el.width / 2) + pos_el.left;
  434. y = (pos_el.height / 2) + pos_el.top;
  435. if(pos_el.width>40){
  436. x += Math.floor(Math.random() * 41)-20;
  437. }else if(pos_el.width>20){
  438. x += Math.floor(Math.random() * 21)-10;
  439. }else if(pos_el.width>10){
  440. x += Math.floor(Math.random() * 11)-5;
  441. }
  442. if(pos_el.height>10){
  443. y += Math.floor(Math.random() * 11)-5;
  444. }
  445. output = [(x*zoom)+margin.left,(y*zoom)+margin.top];
  446. }else{
  447. output = 0;
  448. }
  449. return output;
  450. } else {
  451. el.scrollIntoViewIfNeeded();
  452. return getCoord(el);
  453. }
  454. }
  455.  
  456. function getMarginCoord(query,qid){
  457. let el = document.querySelectorAll(query)[qid].getBoundingClientRect();
  458. return {"top":el.top+margin.top,"left":el.left+margin.left};
  459. }
  460.  
  461. function clickNow(query,qid=0,msg=my_profile+"clickNow called",callback=false){
  462. let el = document.querySelectorAll(query)[qid];
  463. let output = false;
  464. if (checkExist(query,qid)) {
  465. output = true;
  466. let cmd = [];
  467. cmd.push({"cmd":"clickIt","param":getCoord(el)});
  468. cmd.push({"cmd":"log","level":"process","msg":msg});
  469. xhr.open("POST", server);
  470. xhr.send(JSON.stringify(cmd));
  471. if (typeof callback == "function") {
  472. callback();
  473. }
  474. }
  475. return output;
  476. }
  477.  
  478. function clickEl(query,qid=0,msg=my_profile+"clickEl called",callback=false){
  479. let init_clickEl = function() {
  480. clickNow(query,qid,msg,callback);
  481. };
  482. checkEl(query,qid,init_clickEl);
  483. }
  484.  
  485. function clickObject(obj){
  486. if (obj == "ok"){
  487. clickEl(".btn-usual-ok",0,message.ok);
  488. }
  489. }
  490.  
  491. function clickAndNegCheck(query,qid=0,msg="clickAndNegCheck called",callback=false,ticks=5){
  492. let old_href = window.location.href;
  493. let old_top = -1;
  494. let old_left = -1;
  495. let match = ticks-1;
  496. let str_clickAndNegCheck = clickAndNegCheck.name + ", el: " + query + "["+(qid.toString())+"] \n- match = ";
  497. let init_clickAndNegCheck = function() {
  498. let loop_clickAndNegCheck = setInterval(function() {
  499. console.log(str_clickAndNegCheck+(match.toString()));
  500. if (!(checkExist(query,qid))) {
  501. clearInterval(loop_clickAndNegCheck);
  502. if (typeof callback == "function") {
  503. callback();
  504. }
  505. }else if (old_href != window.location.href) {
  506. clearInterval(loop_clickAndNegCheck);
  507. }else{
  508. if (checkExist(query,qid)) {
  509. if (old_top==document.querySelectorAll(query)[qid].getBoundingClientRect().top && old_left==document.querySelectorAll(query)[qid].getBoundingClientRect().left) {
  510. if (match % ticks == 0) {
  511. clickNow(query,qid,msg);
  512. }
  513. match += 1;
  514. }else{
  515. old_top = document.querySelectorAll(query)[qid].getBoundingClientRect().top;
  516. old_left = document.querySelectorAll(query)[qid].getBoundingClientRect().left;
  517. }
  518. }
  519. }
  520. }, 100);
  521. };
  522. checkEl(query,qid,init_clickAndNegCheck);
  523. }
  524.  
  525. function clickAndCheck(query1,qid1=0,query2,qid2=0,msg="clickAndCheck called",callback=false,ticks=5){
  526. let old_href = window.location.href;
  527. let old_top = -1;
  528. let old_left = -1;
  529. let match = ticks-1;
  530. let str_clickAndCheck = clickAndCheck.name + ", check: " + query2 + "["+(qid2.toString())+"], click: " + query1 + "["+(qid1.toString())+"] \n- match = ";
  531. let loop_clickAndCheck = setInterval(function() {
  532. console.log(str_clickAndCheck+(match.toString()));
  533. if (checkExist(query2,qid2)) {
  534. clearInterval(loop_clickAndCheck);
  535. if (typeof callback == "function") {
  536. callback();
  537. }
  538. }else if (old_href != window.location.href) {
  539. clearInterval(loop_clickAndCheck);
  540. }else{
  541. if (checkExist(query1,qid1)) {
  542. if (old_top==document.querySelectorAll(query1)[qid1].getBoundingClientRect().top && old_left==document.querySelectorAll(query1)[qid1].getBoundingClientRect().left) {
  543. if (match % ticks == 0) {
  544. clickNow(query1,qid1,msg);
  545. }
  546. match += 1;
  547. }else{
  548. old_top = document.querySelectorAll(query1)[qid1].getBoundingClientRect().top;
  549. old_left = document.querySelectorAll(query1)[qid1].getBoundingClientRect().left;
  550. }
  551. }
  552. }
  553. }, 100);
  554. }
  555.  
  556. function popUpNotEnough(rep) {
  557. const query = ".btn-use-full.index-1",
  558. qid = 0,
  559. msg = message.replenish.elixir.half_elixir.use;
  560. let cmd = [], coordinate, consumable_data;
  561. consumable_data = my_profile+"Consumable Status:";
  562. for (let i = 0; i < rep.length; i++) {
  563. consumable_data += ("\n- "+rep[i].name+": "+rep[i].number);
  564. }
  565. let init_popUpNotEnough = function() {
  566. coordinate = getCoord(document.querySelectorAll(query)[qid]);
  567. if (coordinate!==0){
  568. cmd.push({"cmd":"clickIt","param":coordinate});
  569. cmd.push({"cmd":"log","level":"process","msg":msg});
  570. cmd.push({"cmd":"log","level":"summary","msg":consumable_data,"split":0});
  571. xhr.open('POST', server);
  572. xhr.send(JSON.stringify(cmd));
  573. }
  574. };
  575. checkEl(query,qid,init_popUpNotEnough);
  576.  
  577. }
  578.  
  579.  
  580. // function clickAndCheckSkill(query,qid=0,msg="clickAndCheckSkill called",callback=false,special_case=false){
  581. // console.log(clickAndCheckSkill.name);
  582. // console.log(callback);
  583. // console.log(query);
  584. // console.log(qid);
  585. // let old_class = document.querySelectorAll(query)[qid].parentNode.classList[0];
  586. // console.log(old_class);
  587. // let loop_clickAndCheckSkill = setInterval(function() {
  588. // console.log(loop_clickAndCheckSkill.name + " " + query + "[" + qid + "]");
  589. // if (Array.from(document.querySelectorAll(query)[qid].parentNode.parentNode.classList).indexOf("tmp-mask")>=0 || Array.from(document.querySelectorAll(query)[qid].parentNode.parentNode.classList).indexOf("btn-ability-unavailable")>=0){
  590. // clearInterval(loop_clickAndCheckSkill);
  591. // console.log(clickAndCheckSkill.name + " case normal");
  592. // if (typeof callback == "function") {
  593. // callback();
  594. // }
  595. // // Bea skill
  596. // }else if(special_case===1 && document.querySelectorAll(query)[qid].parentNode.classList[0] != old_class){
  597. // clearInterval(loop_clickAndCheckSkill);
  598. // console.log(clickAndCheckSkill.name + " case " + special_case.toString());
  599. // if (typeof callback == "function") {
  600. // callback();
  601. // }
  602. // // Out of sight & sage of eternity
  603. // }else if(special_case===2){
  604. // let do_click = true;
  605. // console.log(clickAndCheckSkill.name + " case " + special_case.toString());
  606. // let popup_query = "#wrapper > div.contents > div.pop-usual.pop-select-member > div.prt-popup-header";
  607. // if (checkExist(popup_query,0)) {
  608. // if (document.querySelector("#wrapper > div.contents > div.pop-usual.pop-select-member > div.prt-popup-header").innerHTML == "Use Skill"){
  609. // clearInterval(loop_clickAndCheckSkill);
  610. // do_click = false;
  611. // if (typeof callback == "function") {
  612. // callback();
  613. // }
  614. // }
  615. // }
  616. // if (do_click) {
  617. // if (checkExist(query,qid)) {
  618. // clickNow(query,qid,msg);
  619. // }
  620. // }
  621. // }else{
  622. // if (checkExist(query,qid)) {
  623. // clickNow(query,qid,msg);
  624. // }
  625. // }
  626.  
  627. // }, 500);
  628. // }
  629.  
  630. function clickSkill(cid,abi_id,callback=false){
  631. console.log(clickSkill.name+', cid: '+cid.toString()+', ability: '+abi_id.toString());
  632. let query = ".prt-command-chara.chara"+((cid+1).toString())+">div>div>div>.img-ability-icon";
  633. let qid = abi_id;
  634. let char = battle.player.param[cid].name;
  635. let msg = my_profile+"Clicking "+char+" skill"+((abi_id+1).toString());
  636. let old_class = document.querySelectorAll(query)[qid].parentNode.classList[0];
  637. let abi_obj = Object.values(battle.ability).find(x => x.pos === cid);
  638. let abi_name = abi_obj.list[abi_id+1][0]['ability-name'];
  639. let loop_clickSkill = setInterval(function() {
  640. console.log("loop_clickSkill " + query + "[" + qid + "]");
  641. if (Array.from(document.querySelectorAll(query)[qid].parentNode.parentNode.classList).indexOf("tmp-mask")>=0 || Array.from(document.querySelectorAll(query)[qid].parentNode.parentNode.classList).indexOf("btn-ability-unavailable")>=0){
  642. clearInterval(loop_clickSkill);
  643. console.log('case normal');
  644. if (typeof callback == "function") {
  645. callback();
  646. }
  647. } else if (abi_name === 'Runeweaving') {
  648. console.log('case Runeweaving');
  649. let do_click = true;
  650. let popup_query = '#wrapper > div.contents > div.pop-usual.pop-ability-mark > div.prt-popup-header';
  651. if (checkExist(popup_query,0)) {
  652. if (document.querySelector(popup_query).innerHTML == 'Use Skill'){
  653. clearInterval(loop_clickSkill);
  654. do_click = false;
  655. let error_special_case = true;
  656. let error_msg = 'Error skill: ';
  657. let q_invoke = '.lis-ability-mark';
  658. let q_rune = '>.lis-ability-frame';
  659.  
  660. const invoke = {'fire':'.mark1', 'water':'.mark2', 'earth':'.mark3', 'wind':'.mark4'};
  661.  
  662. if (abi_special_case === false){
  663. error_msg = 'abi_special_case is false.';
  664. } else {
  665. if (typeof abi_special_case === 'object') {
  666. if (abi_special_case.hasOwnProperty('invoke')) {
  667. if (typeof abi_special_case.invoke === 'object') {
  668. if (abi_special_case.invoke.length === 2) {
  669. if (invoke.hasOwnProperty(abi_special_case.invoke[0]) && invoke.hasOwnProperty(abi_special_case.invoke[1])) {
  670. error_special_case = false;
  671. } else {
  672. error_msg = 'abi_special_case.invoke value is invalid.';
  673. }
  674. } else {
  675. error_msg = 'abi_special_case.invoke length is invalid.';
  676. }
  677. } else {
  678. error_msg = 'abi_special_case.invoke type is invalid.';
  679. }
  680. }
  681. } else {
  682. error_msg = 'abi_special_case object \'invoke\' not found.';
  683. }
  684. }
  685. console.log('error_special_case: '+error_special_case);
  686. console.log(error_msg);
  687. if (error_special_case) {
  688. let cmd = [];
  689. cmd.push({"cmd":"log","level":"notif","msg":my_profile+error_msg+discord_mention});
  690. xhr.open('POST', server);
  691. xhr.send(JSON.stringify(cmd));
  692. } else {
  693. let q_next_rune;
  694. if (abi_special_case.invoke[0] === abi_special_case.invoke[1]) {
  695. q_next_rune = '.first.second';
  696. } else {
  697. q_next_rune = '.second:not(.first)';
  698. }
  699. let q_cast = '#wrapper > div.contents > div.pop-usual.pop-ability-mark > div.prt-popup-footer > div.btn-usual-text';
  700. let click_cast = function () {clickAndNegCheck(q_cast,0,my_profile+'Clicking cast',callback);};
  701. let next_rune = function () {clickAndCheck(q_invoke+invoke[abi_special_case.invoke[1]]+q_rune,0,q_invoke+invoke[abi_special_case.invoke[1]]+q_next_rune,0,my_profile+'Clicking second rune: '+abi_special_case.invoke[1],click_cast);};
  702. clickAndCheck(q_invoke+invoke[abi_special_case.invoke[0]]+q_rune,0,q_invoke+invoke[abi_special_case.invoke[0]]+'.first:not(.second)',0,my_profile+'Clicking first rune: '+abi_special_case.invoke[0],next_rune);
  703. }
  704.  
  705. // if (typeof callback == "function") {
  706. // callback();
  707. // }
  708. }
  709. }
  710. if (do_click) {
  711. if (checkExist(query,qid)) {
  712. clickNow(query,qid,msg);
  713. }
  714. }
  715. // // Bea skill
  716. // }else if(special_case===1 && document.querySelectorAll(query)[qid].parentNode.classList[0] != old_class){
  717. // clearInterval(loop_clickAndCheckSkill);
  718. // console.log(clickAndCheckSkill.name + " case " + special_case.toString());
  719. // if (typeof callback == "function") {
  720. // callback();
  721. // }
  722.  
  723. // // Out of sight & sage of eternity
  724. // }else if(special_case===2){
  725. // let do_click = true;
  726. // console.log(clickAndCheckSkill.name + " case " + special_case.toString());
  727. // let popup_query = "#wrapper > div.contents > div.pop-usual.pop-select-member > div.prt-popup-header";
  728. // if (checkExist(popup_query,0)) {
  729. // if (document.querySelector("#wrapper > div.contents > div.pop-usual.pop-select-member > div.prt-popup-header").innerHTML == "Use Skill"){
  730. // clearInterval(loop_clickAndCheckSkill);
  731. // do_click = false;
  732. // if (typeof callback == "function") {
  733. // callback();
  734. // }
  735. // }
  736. // }
  737. // if (do_click) {
  738. // if (checkExist(query,qid)) {
  739. // clickNow(query,qid,msg);
  740. // }
  741. // }
  742. } else {
  743. console.log('case normal');
  744. if (checkExist(query,qid)) {
  745. clickNow(query,qid,msg);
  746. }
  747. }
  748.  
  749. }, 500);
  750. }
  751.  
  752.  
  753.  
  754. function useSkills(cid, skill_list, callback=false) {
  755. let char_id = cid+1;
  756. console.log(useSkills.name);
  757. if (skill_list.length>0) {
  758. console.log(useSkills.name + ", cid: "+cid+", ability: " + (skill_list[0].toString()));
  759. let new_skill_list = Object.values(skill_list);
  760. new_skill_list.splice(0,1);
  761. let abi_id = parseInt(skill_list[0])-1;
  762. let next_skill = function(){useSkills(cid, new_skill_list, callback);};
  763. if (Array.from(document.querySelectorAll(".prt-command-chara.chara"+(char_id.toString())+">div>div.lis-ability")[abi_id].classList).indexOf("btn-ability-available")>=0 && document.querySelectorAll(".prt-command-chara.chara"+(char_id.toString())+">div>div.lis-ability")[abi_id].getBoundingClientRect().width>0){
  764. // clickAndCheckSkill(".prt-command-chara.chara"+(char_id.toString())+">div>div>div>.img-ability-icon",abi_id,my_profile+"Clicking "+char+" skill"+((abi_id+1).toString()),next_skill);
  765. clickSkill(cid,abi_id,next_skill);
  766. }else{
  767. if (typeof callback == "function") {
  768. next_skill();
  769. }
  770. }
  771. } else {
  772. if (typeof callback == "function") {
  773. callback();
  774. }
  775. }
  776. }
  777.  
  778. function usePot(pot_type, cid=false, callback=false) {
  779. console.log(usePot.name);
  780. console.log(cid);
  781. let do_click_heal = false;
  782. let front_cid = false;
  783. let player_stats = {
  784. 'need_heal': [],
  785. 'front_need_heal': [],
  786. 'need_clear': [],
  787. 'need_revive': [],
  788. };
  789. for (const i in battle.player.param) {
  790. if (battle.player.param.hasOwnProperty(i)) {
  791. const player_obj = battle.player.param[i];
  792. player_stats.need_revive.push(player_obj.alive === 1);
  793. let player_need_clear = false;
  794. if (player_obj.alive === 1) {
  795. player_stats.need_heal.push(player_obj.hpmax - player_obj.hp !== 0);
  796. if (player_obj.hasOwnProperty('condition')) {
  797. if (player_obj.condition.hasOwnProperty('debuff')) {
  798. if (player_obj.condition.debuff.length > 0) {
  799. player_need_clear = true;
  800. }
  801. }
  802. }
  803. } else {
  804. player_stats.need_heal.push(false);
  805. }
  806. player_stats.need_clear.push(player_need_clear);
  807. }
  808. }
  809.  
  810. for (const i in battle.formation) {
  811. if (battle.formation.hasOwnProperty(i)) {
  812. const front_id = parseInt(battle.formation[i]);
  813. if (cid===front_id) {
  814. front_cid = i;
  815. }
  816. player_stats.front_need_heal.push(battle.player.param[front_id].hpmax - battle.player.param[front_id].hp !== 0);
  817. }
  818. }
  819. console.log('front_cid: '+front_cid);
  820. console.log('player_stats: ');
  821. console.log(player_stats);
  822. if (pot_type==='Clarity Herb') {
  823. if (battle.hasOwnProperty('event')) {
  824. let item_obj = Object.values(battle.event.item).find(x => x.name === pot_type);
  825. if (item_obj !== undefined) {
  826. if (item_obj.number > 0 && front_cid !== false && player_stats.front_need_heal[front_cid]) {
  827. do_click_heal = true;
  828. }
  829. }
  830. }
  831. } else if (pot_type==='Green Potion') {
  832. if (battle.hasOwnProperty('temporary')) {
  833. if (battle.temporary.hasOwnProperty('small')) {
  834. let item_obj = parseInt(battle.temporary.small);
  835. console.log('item_obj');
  836. console.log(item_obj);
  837. if (item_obj !== undefined) {
  838. if (item_obj > 0 && front_cid !== false && player_stats.front_need_heal[front_cid]) {
  839. do_click_heal = true;
  840. }
  841. }
  842. }
  843. }
  844. } else if (pot_type==='Blue Potion') {
  845. if (battle.hasOwnProperty('temporary')) {
  846. if (battle.temporary.hasOwnProperty('large')) {
  847. let item_obj = parseInt(battle.temporary.large);
  848. console.log('item_obj');
  849. console.log(item_obj);
  850. if (item_obj !== undefined) {
  851. if (item_obj > 0 && player_stats.front_need_heal.indexOf(true)>=0) {
  852. do_click_heal = true;
  853. }
  854. }
  855. }
  856. }
  857. }
  858. console.log('do_click_heal:');
  859. console.log(do_click_heal);
  860.  
  861. let clickCancel = function() {
  862. clickAndNegCheck(query.battle_ui.heal_pop_up.cancel,0,my_profile+"Clicking cancel from pot pop up",callback);
  863. };
  864.  
  865. let clickUse = function() {
  866. clickAndNegCheck(query.battle_ui.heal_pop_up.use,0,my_profile+"Clicking use from pot pop up",callback);
  867. };
  868. let clickFront = function() {
  869. clickAndCheck(query.battle_ui.char_ico,front_cid,query.battle_ui.summon_panel+":not(.mask-black)",0,my_profile+"Clicking char_ico from pot pop up",callback);
  870. };
  871.  
  872. let clickPot = function() {
  873. console.log(clickPot.name);
  874. let query_qty = ">.txt-having>.having-num";
  875. let pot_available = false;
  876. let init_clickPot = function () {
  877. if (checkExist(query.battle_ui.heal_pop_up[pot_type]+query_qty)) {
  878. if ( parseInt(document.querySelector(query.battle_ui.heal_pop_up[pot_type]+query_qty).innerHTML) > 0 ) {
  879. pot_available = true;
  880. if (pot_type == 'Blue Potion') {
  881. clickAndNegCheck(query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking "+ pot_type +" pot",clickUse);
  882. }else if (pot_type == 'Green Potion') {
  883. clickAndNegCheck(query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking "+ pot_type +" pot",clickFront);
  884. }else if (pot_type == 'Clarity Herb') {
  885. clickAndNegCheck(query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking "+ pot_type +" pot",clickFront);
  886. }else{
  887. console.log("pot_type unknown");
  888. clickCancel();
  889. }
  890. }
  891. // console.log("pot qty not > 0");
  892. // clickCancel();
  893. // }
  894. // }else{
  895. // console.log("element not exist");
  896. // clickCancel();
  897. }
  898. if (!pot_available) {
  899. clickCancel();
  900. }
  901. };
  902. checkEl(query.battle_ui.heal_pop_up[pot_type]+">img",0,init_clickPot);
  903. };
  904. if (do_click_heal) {
  905. clickAndCheck(query.battle_ui.heal,0,query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking heal pop up",clickPot);
  906. } else {
  907. if (typeof callback == "function") {
  908. callback();
  909. }
  910. }
  911.  
  912. }
  913.  
  914. function usePots(pot_type,list_cid=[],callback=false) {
  915. console.log('usePots');
  916. console.log('pot_type');
  917. console.log(pot_type);
  918. console.log('list_cid');
  919. console.log(list_cid);
  920. if (list_cid > 0) {
  921. let new_list_cid = Object.values(list_cid);
  922. new_list_cid.splice(0,1);
  923. let next_clear = function(){usePots(pot_type,new_list_cid, callback);};
  924. usePot(pot_type,parseInt(list_cid[0]),next_clear);
  925. } else {
  926. if (typeof callback == "function") {
  927. callback();
  928. }
  929. }
  930. }
  931.  
  932. // function usePot (pot_type,char_id=false,callback=false) {
  933. // // console.log(usePot.name);
  934. // let is_front_healable = [];
  935. // let is_player_reviveable = [];
  936. // let is_player_healable = [];
  937. // for (const i in battle.player.param) {
  938. // if (battle.player.param.hasOwnProperty(i)) {
  939. // if (battle.player.param[i].alive === 1) {
  940. // is_player_reviveable.push(false);
  941. // is_player_healable.push(battle.player.param[i].hpmax - battle.player.param[i].hp !== 0);
  942. // }else{
  943. // is_player_reviveable.push(true);
  944. // is_player_healable.push(false);
  945. // }
  946. // }
  947. // }
  948. // for (const i in rep.formation) {
  949. // if (rep.formation.hasOwnProperty(i)) {
  950. // const alive_id = parseInt(rep.formation[i]);
  951. // is_front_healable.push(battle.player.param[alive_id].hpmax - battle.player.param[alive_id].hp !== 0);
  952. // }
  953. // }
  954. // let query_qty = ">.txt-having>.having-num";
  955. // let clickUse = function() {
  956. // clickAndNegCheck(query.battle_ui.heal_pop_up.use,0,my_profile+"Clicking use from pot pop up",callback);
  957. // };
  958. // let clickFront = function() {
  959. // clickAndCheck(query.battle_ui.char_ico,char_id,query.battle_ui.summon_panel+":not(.mask-black)",0,my_profile+"Clicking char_ico from pot pop up",callback);
  960. // };
  961. // let clickCancel = function() {
  962. // clickAndNegCheck(query.battle_ui.heal_pop_up.cancel,0,my_profile+"Clicking cancel from pot pop up",callback);
  963. // };
  964. // let clickPot = function() {
  965. // console.log(clickPot.name);
  966. // if (checkExist(query.battle_ui.heal_pop_up[pot_type]+query_qty)) {
  967. // if ( parseInt(document.querySelector(query.battle_ui.heal_pop_up[pot_type]+query_qty).innerHTML) > 0 ) {
  968. // if (pot_type == "blue") {
  969. // clickAndNegCheck(query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking "+ pot_type +" pot",clickUse);
  970. // }else if (pot_type == "green") {
  971. // clickAndNegCheck(query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking "+ pot_type +" pot",clickFront);
  972. // }else{
  973. // console.log("pot_type unknown");
  974. // clickCancel();
  975. // }
  976. // }else{
  977. // console.log("pot qty not > 0");
  978. // clickCancel();
  979. // }
  980. // }else{
  981. // console.log("element not exist");
  982. // clickCancel();
  983. // }
  984. // };
  985. // let clickHeal = function() {
  986. // console.log(clickHeal.name);
  987. // clickAndCheck(query.battle_ui.heal,0,query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking heal pop up",clickPot,20);
  988. // };
  989. // let do_heal = false;
  990. // if (pot_type=="blue" && is_front_healable.indexOf(true)>=0) {
  991. // do_heal = true;
  992. // }else if (pot_type=="green" && is_player_healable[char_id]) {
  993. // do_heal = true;
  994. // }else{
  995. // if (typeof callback == "function") {
  996. // callback();
  997. // }
  998. // }
  999. // if (do_heal) {
  1000. // checkEl(query.battle_ui.heal,0,clickHeal);
  1001. // }
  1002. // }
  1003.  
  1004. function clickBackup(callback=false) {
  1005. let check_backup = function() {
  1006. let el_btn, backup_msg;
  1007. if (Array.from(document.querySelector(query.battle_ui.backup_pop_up.request).classList).indexOf("disable") >= 0) {
  1008. el_btn = query.battle_ui.backup_pop_up.cancel;
  1009. backup_msg = "cancel";
  1010. } else {
  1011. el_btn = query.battle_ui.backup_pop_up.request;
  1012. backup_msg = "request";
  1013. }
  1014. clickAndNegCheck(el_btn,0,my_profile+"Clicking "+backup_msg,callback,10);
  1015. };
  1016. clickAndCheck(query.battle_ui.button.assist,0,query.battle_ui.backup_pop_up.request,0,my_profile+"Clicking backup",check_backup,10);
  1017. }
  1018.  
  1019. function clickBack(callback=false){
  1020. clickAndCheck(".btn-command-back.display-on",0,"div.prt-member",0,my_profile+"Clicking back",callback,10);
  1021. }
  1022.  
  1023. function clickSummonPanel(callback=false){
  1024. console.log(clickSummonPanel.name);
  1025. let query1 = ".prt-list-top.btn-command-summon.summon-on";
  1026. let query2 = ".prt-summon-list.opened";
  1027. let query3 = ".prt-list-top.btn-command-summon.summon-off";
  1028. let qid1 = 0, qid2 = 0, qid3 = 0;
  1029. let msg = my_profile+"Clicking summon panel";
  1030. let old_top = -1;
  1031. let old_left = -1;
  1032. let loop_clickAndCheck = setInterval(function() {
  1033. console.log(clickAndCheck.name + ", check: " + query2 + "["+(qid2.toString())+"], click: " + query1 + "["+(qid1.toString())+"]");
  1034. if (checkExist(query2,qid2) || checkExist(query3,qid3)) {
  1035. clearInterval(loop_clickAndCheck);
  1036. if (typeof callback == "function") {
  1037. callback();
  1038. }
  1039. }else{
  1040. if (checkExist(query1,qid1)) {
  1041. if (old_top==document.querySelectorAll(query1)[qid1].getBoundingClientRect().top && old_left==document.querySelectorAll(query1)[qid1].getBoundingClientRect().left) {
  1042. clickNow(query1,qid1,msg);
  1043. }else{
  1044. old_top = document.querySelectorAll(query1)[qid1].getBoundingClientRect().top;
  1045. old_left = document.querySelectorAll(query1)[qid1].getBoundingClientRect().left;
  1046. }
  1047. }
  1048. }
  1049. }, 200);
  1050. }
  1051.  
  1052. function clickSummon(summon_id,callback1=false,callback2=false){
  1053. console.log(clickSummon.name);
  1054. summon_id = summon_id-1;
  1055. if (Array.from(document.querySelectorAll(".lis-summon")[summon_id].classList).indexOf("btn-summon-available")>=0){
  1056. let loop_clickSummon = setInterval(function() {
  1057. if (document.querySelectorAll(".lis-summon>img")[summon_id].getBoundingClientRect().x === document.querySelectorAll(".lis-summon>img")[0].getBoundingClientRect().x + (summon_id * (document.querySelectorAll(".lis-summon>img")[0].getBoundingClientRect().width+2))){
  1058. clearInterval(loop_clickSummon);
  1059. clickAndCheck(".lis-summon>img",summon_id,".pop-usual.pop-summon-detail>div>.btn-usual-ok.btn-summon-use",0,my_profile+"Clicking summon "+((summon_id+1).toString()),callback1);
  1060. }
  1061. }, 300);
  1062. }else{
  1063. if (typeof callback2 == "function") {
  1064. callback2();
  1065. }
  1066. }
  1067. }
  1068.  
  1069. function clickOkSummon(callback=false){
  1070. console.log(clickOkSummon.name);
  1071. let el_ok = ".pop-usual.pop-summon-detail>div>.btn-usual-ok.btn-summon-use";
  1072. if (document.querySelector(el_ok) !== null){
  1073. clickAndCheck(el_ok,0,"div.prt-member",0,my_profile+"Clicking summon ok",callback);
  1074. }else{
  1075. if (typeof callback == "function") {
  1076. callback();
  1077. }
  1078. }
  1079. }
  1080. function clickOkSummon2(summon_id,callback=false){
  1081. let el_ok = ".pop-usual.pop-summon-detail>div>.btn-usual-ok.btn-summon-use";
  1082. let summon_el = '.lis-summon[pos="'+(summon_id.toString())+'"]';
  1083. if (document.querySelector(el_ok) !== null){
  1084. let loop_clickOkSummon2 = setInterval(function() {
  1085. console.log(clickOkSummon2.name + ", click: " + el_ok + "[0]");
  1086. if (Array.from(document.querySelector(summon_el).classList).indexOf("tmp-mask")>=0 || Array.from(document.querySelector(summon_el).classList).indexOf("btn-summon-unavailable")>=0) {
  1087. clearInterval(loop_clickOkSummon2);
  1088. if (typeof callback == "function") {
  1089. callback();
  1090. }
  1091. }else{
  1092. if (checkExist(el_ok,0)) {
  1093. clickNow(el_ok,0,my_profile+"Clicking summon ok2");
  1094. }
  1095. }
  1096. }, 1000);
  1097. }else{
  1098. if (typeof callback == "function") {
  1099. callback();
  1100. }
  1101. }
  1102. }
  1103.  
  1104. function selectSummon(preferred_summon,is_trial=false){
  1105. reload(20);
  1106.  
  1107. let init_selectSummon = function() {
  1108. console.log(init_selectSummon.name);
  1109. reload(10);
  1110. const attrib_list = [6,0,1,2,3,4,5];
  1111. let query_summon_list = ".btn-supporter.lis-supporter";
  1112. let el_summon_list = document.querySelectorAll(query_summon_list);
  1113. let preferred_summon_id = false;
  1114. let picked_attrib_id = false;
  1115. let picked_summon_id = false;
  1116. let picked_is_friend = false;
  1117. let is_friend;
  1118. let picked_summon_stars = false;
  1119. let picked_summon_level = false;
  1120. let picked_summon_plus = false;
  1121. let msg;
  1122. let cmd = [], summon_list = {};
  1123. if (el_summon_list.length>50 && document.querySelector(".prt-supporter-battle-announce")===null && document.querySelector(".txt-confirm-comment")===null && document.querySelector(".prt-check-auth")===null && document.querySelector(".btn-check-auth")===null){
  1124. msg = my_profile+"Verify not appear, summon list length is "+(el_summon_list.length.toString());
  1125. console.log(msg);
  1126.  
  1127. // check if raid is trial
  1128. if (!is_trial){
  1129. console.log("not trial");
  1130. for (let i = 0; i < el_summon_list.length; i++) {
  1131. let match_preferred = false, replace = false;
  1132. let temp_var, summon_detail, summon_name, summon_level, summon_stars, summon_plus;
  1133. temp_var = el_summon_list[i].querySelector(".prt-supporter-summon");
  1134. summon_detail = temp_var.innerHTML.trim();
  1135. temp_var = el_summon_list[i].querySelector(".prt-supporter-summon");
  1136. summon_detail = temp_var.innerHTML.trim();
  1137. summon_name = summon_detail.substring(summon_detail.indexOf("</span>")+8,summon_detail.length);
  1138. summon_level = parseInt(temp_var.children[0].innerHTML.replace("Lvl ",""));
  1139. temp_var = Array.from(el_summon_list[i].querySelector(".prt-summon-skill").classList);
  1140. if (temp_var.indexOf("bless-rank3-style")>=0){
  1141. summon_stars = 5;
  1142. }else if (temp_var.indexOf("bless-rank2-style")>=0){
  1143. summon_stars = 4;
  1144. }else if (temp_var.indexOf("bless-rank1-style")>=0){
  1145. summon_stars = 3;
  1146. }else{
  1147. summon_stars = 0;
  1148. }
  1149. temp_var = el_summon_list[i].querySelector(".prt-summon-quality");
  1150. if (temp_var !== null){
  1151. summon_plus = parseInt(temp_var.innerHTML.replace("+",""));
  1152. }else{
  1153. summon_plus = 0;
  1154. }
  1155. temp_var = false;
  1156. is_friend = Array.from(el_summon_list[i].querySelector(".prt-supporter-name").classList).indexOf("ico-friend")>=0;
  1157.  
  1158. // loop preferred summon list (specified in parameter)
  1159. for (let j = 0; j < preferred_summon.length; j++) {
  1160. if (preferred_summon[j].name==summon_name && preferred_summon[j].star<=summon_stars){
  1161. match_preferred = true;
  1162. temp_var = j;
  1163. }
  1164. }
  1165.  
  1166.  
  1167. if (match_preferred){
  1168. if (picked_attrib_id===false && picked_summon_id===false){
  1169. replace = true;
  1170. }else{
  1171. if (preferred_summon_id>temp_var){
  1172. replace = true;
  1173. }else if(preferred_summon_id==temp_var){
  1174. if (summon_stars>picked_summon_stars){
  1175. replace = true;
  1176. }else if(summon_stars==picked_summon_stars){
  1177. if (!picked_is_friend && is_friend){
  1178. replace = true;
  1179. }else if(picked_is_friend && is_friend){
  1180. if (summon_level>picked_summon_level){
  1181. replace = true;
  1182. }else if(summon_level==picked_summon_level){
  1183. if (summon_plus>picked_summon_plus){
  1184. replace = true;
  1185. }
  1186. }
  1187. }
  1188. }
  1189. }
  1190. }
  1191. }
  1192. if (replace){
  1193. picked_attrib_id = Array.from(document.querySelectorAll(".prt-supporter-attribute")).indexOf(el_summon_list[i].parentElement);
  1194. picked_summon_id = i;
  1195. preferred_summon_id = temp_var;
  1196. picked_summon_stars = summon_stars;
  1197. picked_is_friend = is_friend;
  1198. picked_summon_level = summon_level;
  1199. picked_summon_plus = summon_plus;
  1200. }
  1201. }
  1202. console.log([picked_attrib_id,picked_summon_id,preferred_summon_id]);
  1203. if (picked_summon_id===false){
  1204. console.log("go to trial");
  1205. cmd.push({"cmd":"log","level":"process","msg":message.summon.not_found});
  1206. xhr.open("POST", server);
  1207. xhr.send(JSON.stringify(cmd));
  1208. gotoHash("trial");
  1209. }else{
  1210. console.log("summon_found");
  1211. let pickSummon = function() {
  1212. scroll_To(query_summon_list,picked_summon_id);
  1213. clickEl(query_summon_list,picked_summon_id,message.summon.select);
  1214. };
  1215. let clickAndCheckSummon = function(callback=false){
  1216. let el_tab_ele_ico = ".prt-type-text";
  1217. let el_summon_container = ".prt-supporter-attribute";
  1218. let loop_clickAndCheckSummon = setInterval(function() {
  1219. console.log(clickAndCheckSummon.name + ", check: " + el_summon_container + "[" + picked_attrib_id + "], click: " + el_tab_ele_ico + "["+(attrib_list[picked_attrib_id].toString())+"]");
  1220. if (Array.from(document.querySelectorAll(el_summon_container)[picked_attrib_id].classList).indexOf("disableView") == -1) {
  1221. clearInterval(loop_clickAndCheckSummon);
  1222. if (typeof callback == "function") {
  1223. callback();
  1224. }
  1225. }else{
  1226. if (checkExist(el_tab_ele_ico, attrib_list[picked_attrib_id])) {
  1227. clickNow(el_tab_ele_ico, attrib_list[picked_attrib_id], message.summon.pick_tab);
  1228. }
  1229. }
  1230. }, 300);
  1231. };
  1232. clickAndCheckSummon(pickSummon);
  1233. }
  1234. }else{
  1235. console.log("is trial");
  1236. query_summon_list = ".prt-supporter-attribute:not(.disableView)>.btn-supporter.lis-supporter";
  1237. el_summon_list = document.querySelectorAll(query_summon_list);
  1238. for (let i = 0; i < el_summon_list.length; i++) {
  1239. is_friend = Array.from(el_summon_list[i].querySelector(".prt-supporter-name").classList).indexOf("ico-friend")>=0;
  1240. if (!is_friend){
  1241. if (picked_summon_id===false){
  1242. picked_summon_id = i;
  1243. }
  1244. }
  1245. }
  1246. if (picked_summon_id!==false){
  1247. scroll_To(".prt-supporter-attribute:not(.disableView)>.btn-supporter.lis-supporter",picked_summon_id);
  1248. clickEl(".prt-supporter-attribute:not(.disableView)>.btn-supporter.lis-supporter",picked_summon_id,message.summon.select);
  1249. }
  1250. }
  1251. }else{
  1252. msg = my_profile+"Verify might appear, summon list length is "+(el_summon_list.length.toString());
  1253. clearInterval(reload_counter);
  1254. console.log(msg);
  1255. cmd.push({"cmd":"log","level":"process","msg":msg});
  1256. cmd.push({"cmd":"log","level":"notif","msg":msg});
  1257. xhr.open("POST", server);
  1258. xhr.send(JSON.stringify(cmd));
  1259. }
  1260. };
  1261. checkEl(".prt-supporter-title",0,init_selectSummon);
  1262. }
  1263.  
  1264. function doChat(callback=false) {
  1265. console.log(doChat.name);
  1266. let clickDialog = function() {
  1267. console.log(clickDialog.name);
  1268. clickAndNegCheck(query.battle_ui.chat_pop_up.dialog,0,my_profile+"Clicking chat dialog",callback);
  1269. };
  1270. let clickChat = function() {
  1271. console.log(clickChat.name);
  1272. if (checkExist(query.battle_ui.chat+">.ico-attention",0)) {
  1273. clickAndCheck(query.battle_ui.chat,0,query.battle_ui.chat_pop_up.dialog,0,my_profile+"Clicking chat pop up",clickDialog,20);
  1274. }else{
  1275. if (typeof callback == "function") {
  1276. callback();
  1277. }
  1278. }
  1279. };
  1280. checkEl(query.battle_ui.chat,0,clickChat);
  1281. }
  1282.  
  1283. function backFromTrial(){
  1284. let cmd = [];
  1285. cmd.push({"cmd":"log","level":"process","msg":message.raid.trial.end});
  1286. xhr.open("POST", server);
  1287. xhr.send(JSON.stringify(cmd));
  1288. gotoHash("main");
  1289. }
  1290.  
  1291. function gotoResult() {
  1292. console.log(gotoResult.name);
  1293. console.log(is_host);
  1294. if (is_host || window.location.hash.indexOf("#raid/")>=0) {
  1295. gotoHash("quest");
  1296. }else if (window.location.hash.indexOf("#raid_multi")>=0) {
  1297. reloadNow();
  1298. }
  1299. }
  1300.  
  1301. function attack(rep){
  1302. console.log(attack.name);
  1303. let cmd = [];
  1304. let reps = rep.scenario;
  1305. let win = false;
  1306. let is_last_raid = false;
  1307. let ougi = 0;
  1308. let msg = "";
  1309. for (let i = 0; i < reps.length; i++) {
  1310. if (reps[i].cmd =="win"){
  1311. if (reps[i].is_last_raid){is_last_raid=true;}
  1312. win=true;
  1313. }else if (reps[i].cmd=="special" || reps[i].cmd=="special_npc"){
  1314. const char_name = battle.player.param[parseInt(battle.formation[reps[i].pos])].name;
  1315. msg += my_profile+char_name+" used ougi \""+reps[i].name+"\".\n";
  1316. if (reps[i].total){msg += my_profile+char_name+" dealt "+reps[i].total[0].split.join("")+" damage.\n";}
  1317. ougi++;
  1318. }else if (reps[i].cmd=="attack" && reps[i].from=="player"){
  1319. const char_name = battle.player.param[parseInt(battle.formation[reps[i].pos])].name;
  1320. if (reps[i].damage.length==3){
  1321. msg += my_profile+char_name+" made a triple attack.\n";
  1322. }else if (reps[i].damage.length==2){
  1323. msg += my_profile+char_name+" made a double attack.\n";
  1324. }
  1325. msg += my_profile+char_name+ " dealt ";
  1326. for (let ii=0; ii<reps[i].damage.length; ii++){
  1327. msg += reps[i].damage[ii][0].value.toString();
  1328. if (ii<reps[i].damage.length-1){
  1329. msg += ", ";
  1330. }else{
  1331. msg += " damage.\n";
  1332. }
  1333. }
  1334. }
  1335. }
  1336.  
  1337. if(win){
  1338. cmd.push({"cmd":"log","level":"process","msg":msg+my_profile+"Foe defeated."});
  1339. }else{
  1340. cmd.push({"cmd":"log","level":"process","msg":msg+my_profile+"Foe is still alive."});
  1341. cmd.push({"cmd":"press","key":"f5"});
  1342. }
  1343. xhr.open('POST', server);
  1344. xhr.send(JSON.stringify(cmd));
  1345. if(win && is_last_raid){
  1346. gotoResult();
  1347. }else if(win){
  1348. clickEl(".btn-result",0,my_profile+"Go to next round");
  1349. }
  1350. }
  1351.  
  1352. function skillUsed(rep){
  1353. console.log(skillUsed.name);
  1354. let do_reload = false;
  1355. let reps = rep.scenario;
  1356. let win = false, is_last_raid = false;
  1357. console.log(reps);
  1358. for (let i = 0; i < reps.length; i++) {
  1359. const scenario = reps[i];
  1360. if (scenario.cmd =="ability"){
  1361. if (reloadable_skill.indexOf(scenario.name)>= 0) {
  1362. do_reload = true;
  1363. }
  1364. }else if (scenario.cmd =="damage") {
  1365. if (scenario.to == "player") {
  1366. for (let j = 0; j < scenario.list.length; j++) {
  1367. const s = scenario.list[j];
  1368. if (s.hp !== undefined && s.pos !== undefined) {
  1369. battle.player.param[s.pos].hp = s.hp;
  1370. }
  1371. }
  1372. }
  1373. }else if (scenario.cmd =="finished"){
  1374. win=true;
  1375. is_last_raid=true;
  1376. }else if (scenario.cmd == "win"){
  1377. if (scenario.is_last_raid) {
  1378. is_last_raid=true;
  1379. }
  1380. win=true;
  1381. }
  1382. }
  1383. if(win && is_last_raid){
  1384. gotoResult();
  1385. }else if (win && !is_last_raid) {
  1386. clickEl(".btn-result",0,my_profile+"Go to next round");
  1387. }else if(do_reload){
  1388. reloadNow();
  1389. }
  1390. }
  1391.  
  1392. function summonUsed(rep){
  1393. console.log(summonUsed.name);
  1394. let do_reload = false;
  1395. let reps = rep.scenario;
  1396. let win = false,
  1397. is_last_raid = false;
  1398. for (let i = 0; i < reps.length; i++) {
  1399. const scenario = reps[i];
  1400. if (scenario.cmd == "finished"){
  1401. win=true;
  1402. is_last_raid=true;
  1403. }else if (scenario.cmd == "win"){
  1404. if (scenario.is_last_raid){
  1405. is_last_raid=true;
  1406. }
  1407. win=true;
  1408. }
  1409. }
  1410. if (battle.lyria_pos >= 0) {
  1411. do_reload = true;
  1412. }
  1413. if(win && is_last_raid){
  1414. gotoResult();
  1415. }else if(do_reload){
  1416. reloadNow();
  1417. }
  1418. }
  1419.  
  1420. function potUsed(rep) {
  1421. console.log(potUsed.name);
  1422. let reps = rep.scenario;
  1423. for (let i = 0; i < reps.length; i++) {
  1424. const scenario = reps[i];
  1425. if (scenario.cmd == "heal") {
  1426. for (let j = 0; j < scenario.list.length; j++) {
  1427. const s = scenario.list[j];
  1428. if (s.hp !== undefined && s.pos !== undefined) {
  1429. battle.player.param[s.pos].hp = s.hp;
  1430. }
  1431. }
  1432. }
  1433. }
  1434. }
  1435.  
  1436.  
  1437. function clickAttack(callback=false) {
  1438. let hp = ((parseInt(battle.boss.param[0].hp) / parseInt(battle.boss.param[0].hpmax)) * 100).toString();
  1439. if (hp.indexOf(".")>=0){
  1440. hp = hp.substring(0,hp.indexOf("."));
  1441. }
  1442. console.log(hp);
  1443. let attack_msg = my_profile+"Foe hp is "+hp+"% left, commencing attack";
  1444. clickAndCheck(".btn-attack-start.display-on",0,".btn-attack-cancel.btn-cancel.display-on",0,attack_msg,callback,20);
  1445. }
  1446.  
  1447. function charMoveSet(cid,skill_list,callback) {
  1448. if (!(Number.isInteger(cid))) {
  1449. cid = battle.player.param.findIndex(x => x.name === cid);
  1450. }
  1451. console.log(charMoveSet.name + ': ' + cid);
  1452. let char = battle.player.param[cid];
  1453. console.log(char.name);
  1454. if (char !== undefined) {
  1455. let can_use_skill = true;
  1456. if (skill_list.length>0) {
  1457. let new_skill_list = Object.values(skill_list);
  1458. for (let i = 0; i < skill_list.length; i++) {
  1459. const skill = skill_list[i];
  1460. if (document.querySelector(query.battle_ui.skill['char'+(cid+1).toString()]['skill'+(skill.toString())]).attributes.state.value != "2") {
  1461. new_skill_list.splice(new_skill_list.indexOf(skill),1);
  1462. }
  1463. }
  1464. skill_list = new_skill_list;
  1465. if ("debuff" in char.condition) {
  1466. for (let i = 0; i < char.condition.debuff.length; i++) {
  1467. const debuff = char.condition.debuff[i];
  1468. if (debuff.status == "1111" || debuff.status == "1102") {
  1469. can_use_skill = false;
  1470. }
  1471. // 1102
  1472. }
  1473. }
  1474. }
  1475. if (char.alive===1 && skill_list.length>0 && can_use_skill) {
  1476. let click_back = function(){clickBack(callback);};
  1477. let use_skills = function(){useSkills(cid,skill_list,click_back);};
  1478. let click_char = function(){clickChar(cid+1,use_skills);};
  1479. click_char();
  1480. } else {
  1481. if (typeof callback == "function") {
  1482. callback();
  1483. }
  1484. }
  1485. } else {
  1486. if (typeof callback == "function") {
  1487. callback();
  1488. }
  1489. }
  1490. }
  1491.  
  1492.  
  1493. function toggleOugi(ougi, callback=false) {
  1494. let init_toggleOugi = function() {
  1495. let current_ougi = "."+document.querySelector(query.battle_ui.ougi).classList[1];
  1496. if (query.battle_ui.toggle_ougi[ougi] != current_ougi){
  1497. clickAndCheck(query.battle_ui.ougi + current_ougi, 0, query.battle_ui.ougi + query.battle_ui.toggle_ougi[ougi], 0, my_profile+"Set toggle ougi to "+(ougi.toString()), callback);
  1498. }else{
  1499. if (typeof callback == "function") {
  1500. callback();
  1501. }
  1502. }
  1503. };
  1504. checkEl(query.battle_ui.ougi,0,init_toggleOugi);
  1505. }
  1506.  
  1507. function summoning(summon_id,callback=false) {
  1508. console.log(summoning.name);
  1509. let summon_cd;
  1510. console.log('test 1');
  1511. if (summon_id === 5) {
  1512. console.log('test 2');
  1513. summon_cd = battle.supporter.recast;
  1514. console.log('test 3');
  1515. } else if (battle.summon[summon_id] !== undefined) {
  1516. console.log('test 4');
  1517. summon_cd = battle.summon[summon_id].recast;
  1518. console.log('test 5');
  1519. }
  1520. console.log('test 6');
  1521. if (summon_cd === "0") {
  1522. console.log('test 7');
  1523. let summon_ok = function(){clickOkSummon(callback);};
  1524. let summon = function(){clickSummon(summon_id+1,summon_ok,callback);};
  1525. let summon_p = function(){clickSummonPanel(summon);};
  1526. summon_p();
  1527. } else {
  1528. console.log('test 8');
  1529. if (typeof callback == "function") {
  1530. callback();
  1531. }
  1532. }
  1533. }
  1534.  
  1535. function pickUnclaimedRaid(rep) {
  1536. if (rep.count > 0) {
  1537. let el_raid = ".prt-raid-info";
  1538. let init_pickUnlaimedRaid = function() {
  1539. gotoHash(rep.list[0].href);
  1540. };
  1541. checkEl(el_raid,0,init_pickUnlaimedRaid);
  1542. }else{
  1543. gotoHash('main');
  1544. }
  1545. }
  1546.  
  1547. let battleLogic = function(case_battle) {
  1548. console.log(battleLogic.name);
  1549. console.log('case_battle:');
  1550. console.log(case_battle);
  1551. clearInterval(reload_counter);
  1552. };
  1553.  
  1554. function startRaid(rep){
  1555. reload(15);
  1556. battle = rep;
  1557. is_host = rep.is_host;
  1558. for (let i = 0; i < battle.player.param.length; i++) {
  1559. const c = battle.player.param[i];
  1560. if (c.alive === 1) {
  1561. is_wiped = false;
  1562. }
  1563. }
  1564.  
  1565. let check_exist = setInterval(function() {
  1566. console.log("querying enemy name to appear");
  1567. if (document.querySelector("a.btn-targeting.enemy-1:not(.invisible)") !== null || document.querySelector("a.btn-targeting.enemy-2:not(.invisible)") !== null || document.querySelector("a.btn-targeting.enemy-3:not(.invisible)") !== null){
  1568. console.log("check width enemy name");
  1569. if (document.querySelector("a.btn-targeting.enemy-1:not(.invisible)").getBoundingClientRect().width>0 || document.querySelector("a.btn-targeting.enemy-2:not(.invisible)").getBoundingClientRect().width>0 || document.querySelector("a.btn-targeting.enemy-3:not(.invisible)").getBoundingClientRect().width>0){
  1570. console.log("found enemy name");
  1571. clearInterval(check_exist);
  1572. let is_quest_id_valid = false;
  1573. let is_twitter_valid = false;
  1574. try{
  1575. console.log(rep.quest_id);
  1576. if (rep.quest_id!==undefined) {
  1577. is_quest_id_valid = true;
  1578. }
  1579. }
  1580. catch(err){
  1581. console.log(err.message);
  1582. }
  1583. console.log("is_quest_id_valid:" +(is_quest_id_valid).toString());
  1584. try{
  1585. console.log(rep.twitter.monster);
  1586. if (rep.twitter.monster!==undefined) {
  1587. is_twitter_valid = true;
  1588. }
  1589. }
  1590. catch(err){
  1591. console.log(err.message);
  1592. }
  1593. console.log("is_twitter_valid:" +(is_twitter_valid).toString());
  1594. let case_battle = false;
  1595. if (is_quest_id_valid){
  1596. if (battle.is_trialbattle) {
  1597. case_battle = 99;
  1598. }else{
  1599. for (let i in quests_id) {
  1600. if (rep.quest_id == quests_id[i] && case_battle === false) {
  1601. case_battle = parseInt(i)+1;
  1602. }
  1603. }
  1604. }
  1605. }
  1606. if (case_battle === false && is_twitter_valid){
  1607. for (let i in monsters_name) {
  1608. if (rep.twitter.monster==monsters_name[i] && case_battle === false) {
  1609. case_battle = parseInt(i)+1;
  1610. }
  1611. }
  1612. }
  1613. console.log("case_battle:" + case_battle.toString());
  1614. let hp = ((parseInt(rep.boss.param[0].hp) / parseInt(rep.boss.param[0].hpmax)) * 100).toString();
  1615. if (hp.indexOf(".")>=0){
  1616. hp = hp.substring(0,hp.indexOf("."));
  1617. }
  1618. battleLogic(case_battle);
  1619. }
  1620. }
  1621. }, 300);
  1622. }
  1623.  
  1624. function clickChar(param,callback=false) {
  1625. clickAndCheck("div.prt-member>div.btn-command-character>img.img-chara-command",param-1,".prt-command-chara.chara"+(param.toString()),0,my_profile+"Clicking "+battle.player.param[param-1].name,callback);
  1626. }
  1627.  
  1628. function clickBoss(boss_id,callback=false) {
  1629. const boss_id_str = (boss_id+1).toString();
  1630. if (battle.boss.param[boss_id] !== undefined || battle.boss.param[boss_id].alive === 1) {
  1631. clickAndCheck('.enemy-info>.name',boss_id,'.btn-targeting.enemy-'+boss_id_str+'.lock-on',0,my_profile+'Clicking Boss '+boss_id_str,callback);
  1632. } else {
  1633. if (typeof callback == "function") {
  1634. callback();
  1635. }
  1636. }
  1637. }
  1638.  
  1639. function raidFinish(rep,send_all_loot=false){
  1640. console.log(raidFinish.name);
  1641. reload(10);
  1642. let cmd = [];
  1643. let tracked_loot = [];
  1644. let check_timer = true;
  1645. cmd.push({"cmd":"log","level":"process","msg":message.raid.finish});
  1646.  
  1647. let all_loot = {};
  1648. let important_loot = {};
  1649. for (const i in rep.rewards.reward_list) {
  1650. if (rep.rewards.reward_list.hasOwnProperty(i)) {
  1651. const loots = rep.rewards.reward_list[i];
  1652. for (const j in loots) {
  1653. if (loots.hasOwnProperty(j)) {
  1654. const loot = loots[j];
  1655. if ( ( ['weapon','summon'].indexOf(loot.type) >= 0 ) && loot.rarity=='4') {
  1656. if (tracked_loot.indexOf(loot.name)===-1) {
  1657. tracked_loot.push(loot.name);
  1658. }
  1659. } else if (tracker_reward_weapons.indexOf(loot.name) >= 0 || tracker_reward_summons.indexOf(loot.name) >= 0 || tracker_reward_items.indexOf(loot.name) >= 0) {
  1660. if (tracked_loot.indexOf(loot.name)===-1) {
  1661. tracked_loot.push(loot.name);
  1662. }
  1663. }
  1664. if (all_loot[loot.name]===undefined) {
  1665. all_loot[loot.name] = parseInt(loot.count);
  1666. } else {
  1667. all_loot[loot.name] += parseInt(loot.count);
  1668. }
  1669. }
  1670. }
  1671. }
  1672. }
  1673. if (send_all_loot) {
  1674. important_loot = all_loot;
  1675. } else {
  1676. for (const loot in all_loot) {
  1677. if (all_loot.hasOwnProperty(loot)) {
  1678. const qty = all_loot[loot];
  1679. if (tracked_loot.indexOf(loot)>=0) {
  1680. important_loot[loot] = qty;
  1681. }
  1682. }
  1683. }
  1684. }
  1685. console.log(important_loot);
  1686. if (Object.keys(important_loot).length > 0) {
  1687. cmd.push({"cmd":"reward","payload":important_loot});
  1688. cmd.push({"cmd":"log","level":"summary","msg":Object.keys(important_loot).length});
  1689. }
  1690.  
  1691. if (tracked_item !== false){
  1692. let data_track = my_profile+"Current Status:";
  1693. let temp_str;
  1694. for (let item in tracked_item){
  1695. if (tracked_item.hasOwnProperty(item)) {
  1696. let item_qty = parseInt(tracked_item[item].number);
  1697. let drop_qty = 0;
  1698. if (all_loot[tracked_item[item].name] !== undefined) {
  1699. drop_qty = all_loot[tracked_item[item].name];
  1700. }
  1701. temp_str = "\n- "+tracked_item[item].name+": "+(item_qty + drop_qty).toString();
  1702. if (all_loot[tracked_item[item].name] !== undefined) {
  1703. temp_str += ' ( +'+(drop_qty).toString()+' )';
  1704. }
  1705. data_track += temp_str;
  1706. }
  1707. }
  1708. cmd.push({"cmd":"log","level":"summary","msg":data_track,"split":0});
  1709. }
  1710. if (check_timer){
  1711. cmd.push({"cmd":"check_timer"});
  1712. }
  1713. xhr.open('POST', server);
  1714. xhr.send(JSON.stringify(cmd));
  1715. let gotoMain = function() {gotoHash("main");};
  1716. checkEl(".mask",0,gotoMain);
  1717. }
  1718.  
  1719. function quitTrial(){
  1720. let doit3 = function(){clickEl(".btn-usual-ok",0,message.raid.trial.ok);};
  1721. let doit2 = function(){clickEl(".btn-withdrow.btn-red-m",0,message.raid.trial.retreat,doit3);};
  1722. let doit1 = function(){clickEl(".btn-raid-menu.menu",0,message.raid.trial.open_menu,doit2);};
  1723. clickAndNegCheck(query.battle_ui.trial_pop_up.close,0,message.raid.trial.close_pop_up,doit1);
  1724. }
  1725.  
  1726. function missionComplete(cmd=[]) {
  1727. clearInterval(reload_counter);
  1728. // let cmd = [];
  1729. cmd.push({"cmd":"log","level":"notif","msg":my_profile+"Objective cleared. Mission complete. "+discord_mention});
  1730. cmd.push({"cmd":"log","level":"summary","msg":my_profile+"Objective cleared. Mission complete."});
  1731. cmd.push({"cmd":"hotkey","keys":["ctrl","w"]});
  1732. xhr.open('POST', server);
  1733. xhr.send(JSON.stringify(cmd));
  1734. }
  1735.  
  1736. let listenNetwork = function() {
  1737. console.log('listenNetwork');
  1738. clearInterval(reload_counter);
  1739. };
  1740.  
  1741. function init() {
  1742. "use strict";
  1743. console.log(init.name);
  1744. reload(5);
  1745. setDebug();
  1746. listenNetwork();
  1747. let checkBody = setInterval(function() {
  1748. console.log(checkBody.name);
  1749. if(document.body !== null){
  1750. clearInterval(checkBody);
  1751. if(document.body.children[0].tagName == "DIV"){
  1752. // reload(30);
  1753. checkError();
  1754. }else{
  1755. console.log("DOM Error");
  1756. reloadNow();
  1757. }
  1758. }
  1759. }, 300);
  1760. }