NEET Lib

NEET Bot Library

目前為 2019-08-12 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/383201/724225/NEET%20Lib.js

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