NEET Lib

NEET Bot Library

当前为 2019-09-18 提交的版本,查看 最新版本

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

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