Greasy Fork 还支持 简体中文。

NEET Lib

NEET Bot Library

目前為 2019-07-29 提交的版本,檢視 最新版本

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

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