NEET Lib

NEET Bot Library

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

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

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