NEET Lib

NEET Bot Library

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

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

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