NEET Lib

NEET Bot Library

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

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

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

QingJ © 2025

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