NEET Lib

NEET Bot Library

当前为 2019-11-06 提交的版本,查看 最新版本

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

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址