NEET Lib

NEET Bot Library

当前为 2019-08-12 提交的版本,查看 最新版本

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

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