NEET Lib

NEET Bot Library

当前为 2019-07-23 提交的版本,查看 最新版本

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

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