NEET Lib

NEET Bot Library

当前为 2019-06-15 提交的版本,查看 最新版本

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

  1. // ==UserScript==
  2. // @name NEET Lib
  3. // @namespace http://tampermonkey.net/
  4. // @version 5.8
  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 my_profile = "Main: ";
  24. let is_host = "false";
  25. let battle_status;
  26.  
  27. let quests_id = [], monsters = [], monsters_name = [];
  28.  
  29. // const game variable
  30. const trial_id = "990011",
  31. select_summon_path = "supporter/",
  32. message = {
  33. "raid" : {
  34. "panel" : {
  35. "open" : my_profile+"Opening quest/raid panel",
  36. "pick" : my_profile+"Picking quest/raid difficulties",
  37. },
  38. "select_party" : my_profile+"Selecting party",
  39. "finish" : my_profile+"Raid finished",
  40. "trial" : {
  41. "close_pop_up" : my_profile+"In trial, closing pop up",
  42. "open_menu" : my_profile+ "In trial, click menu",
  43. "retreat" : my_profile+ "In trial, click retreat",
  44. "ok" : my_profile+ "In trial, click ok",
  45. "end" : my_profile+"Retreated from trial, back to main raid",
  46. }
  47. },
  48. "summon" : {
  49. "select" : my_profile+"Selecting summon",
  50. "pick_tab" : my_profile+"Clicking summon element tab",
  51. "not_found" : my_profile+"Support summon not found, going to trial",
  52. },
  53. "replenish" : {
  54. "elixir" : {
  55. "half_elixir" : {
  56. "use" : my_profile+"Not enough AP, using half elixir",
  57. "used" : my_profile+"Half elixir used",
  58. }
  59. },
  60. "soul" : {
  61. "soul_berry" : {
  62. "use" : my_profile+"Not enough EP, using soul berry",
  63. "used" : my_profile+"soul berry used",
  64. }
  65. }
  66. },
  67. "ok" : my_profile+"Clicking ok",
  68. };
  69.  
  70. // path
  71. let path = {
  72. "item":"#item",
  73. "quest":"#quest",
  74. "support":"#quest/supporter/",
  75. "assist":"#quest/assist",
  76. "unclaimed":"#quest/assist/unclaimed",
  77. "trial":"#quest/supporter/"+trial_id+"/17",
  78. };
  79.  
  80. // element dom query selector
  81. let skill_char = "#prt-command-top > div > div > div.lis-character";
  82. let skill_abi = ".btn-command-character > div.prt-ability-state > div.lis-ability-state.ability";
  83. let query = {
  84. "battle_ui": {
  85. "skill": {
  86. "char1": {
  87. "skill1": skill_char + "0" + skill_abi + "1",
  88. "skill2": skill_char + "0" + skill_abi + "2",
  89. "skill3": skill_char + "0" + skill_abi + "3",
  90. "skill4": skill_char + "0" + skill_abi + "4",
  91. },
  92. "char2": {
  93. "skill1": skill_char + "1" + skill_abi + "1",
  94. "skill2": skill_char + "1" + skill_abi + "2",
  95. "skill3": skill_char + "1" + skill_abi + "3",
  96. "skill4": skill_char + "1" + skill_abi + "4",
  97. },
  98. "char3": {
  99. "skill1": skill_char + "2" + skill_abi + "1",
  100. "skill2": skill_char + "2" + skill_abi + "2",
  101. "skill3": skill_char + "2" + skill_abi + "3",
  102. "skill4": skill_char + "2" + skill_abi + "4",
  103. },
  104. "char4": {
  105. "skill1": skill_char + "3" + skill_abi + "1",
  106. "skill2": skill_char + "3" + skill_abi + "2",
  107. "skill3": skill_char + "3" + skill_abi + "3",
  108. "skill4": skill_char + "3" + skill_abi + "4",
  109. },
  110. },
  111. "skill_pop_up": {
  112. "char1": "div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character0.btn-command-character > img",
  113. "char2": "div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character1.btn-command-character > img",
  114. "char3": "div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character2.btn-command-character > img",
  115. "char4": "div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character3.btn-command-character > img",
  116. "char5": "div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character4.btn-command-character > img",
  117. "char6": "div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character5.btn-command-character > img",
  118. },
  119. // "#prt-command-top > div > div > div.lis-character3.btn-command-character > div.prt-ability-state > div.lis-ability-state.ability3",
  120. "ougi": ".btn-lock",
  121. "toggle_ougi": {
  122. true: ".lock0",
  123. false: ".lock1",
  124. },
  125. "char_ico": ".prt-party>.prt-member>.btn-command-character>img.img-chara-command",
  126. "summon_panel": ".prt-summon-list>.prt-list-top.btn-command-summon",
  127. "chat":".btn-chat.comment.display-on",
  128. "chat_pop_up": {
  129. "dialog":".txt-chat-pop",
  130. },
  131. "heal":"#prt-sub-command-group>.btn-temporary",
  132. "heal_pop_up": {
  133. "green": ".lis-item.item-small",
  134. "blue": ".lis-item.item-large",
  135. "use": ".pop-usual.pop-raid-item.pop-show>.prt-popup-footer>.btn-usual-use",
  136. "cancel": ".pop-usual.pop-raid-item.pop-show>.prt-popup-footer>.btn-usual-cancel",
  137. },
  138. "trial_pop_up": {
  139. "close": ".pop-usual.pop-trialbattle-notice.pop-show>.prt-popup-footer>.btn-usual-close"
  140. },
  141. },
  142. "assist_ui": {
  143. "tab_id": "#tab-id",
  144. "tab_multi": "#tab-multi",
  145. "tab_event": "#tab-event",
  146. "unclaimed": ".btn-unclaimed",
  147. },
  148. "poker": {
  149. "canvas": "#canv",
  150. "deal": ".prt-start",
  151. "ok": ".prt-ok",
  152. "yes": ".prt-yes",
  153. "no": ".prt-no",
  154. "low": ".prt-double-select>.prt-low-shine",
  155. "high": ".prt-double-select>.prt-high-shine",
  156. },
  157. "ok":".btn-usual-ok",
  158. };
  159.  
  160. // general item variable
  161. let tracked_item = false;
  162.  
  163. function reloadNow() {
  164. console.log(reloadNow.name);
  165. xhr.open('POST', server);
  166. xhr.send(JSON.stringify([{"cmd":"press","key":"f5"}]));
  167. window.location.reload();
  168. }
  169.  
  170. function reload(mod_value=1) {
  171. clearInterval(reload_counter);
  172. let current_path = window.location.hash;
  173. let count = 1;
  174. reload_counter = setInterval(function() {
  175. if(window.location.hash != current_path){
  176. clearInterval(reload_counter);
  177. }
  178. console.log("reloading in "+(mod_value-count).toString());
  179. if (count%mod_value===0){
  180. clearInterval(reload_counter);
  181. reloadNow();
  182. }
  183. count += 1;
  184. }, 1000);
  185. }
  186.  
  187. function setDebug() {
  188. if(!debug){
  189. console.log("DEBUG is turned OFF");
  190. if(!window.console) window.console = {};
  191. let methods = ["log", "debug", "warn", "info"];
  192. for(let i=0;i<methods.length;i++){
  193. console[methods[i]] = function(){};
  194. }
  195. }
  196. }
  197.  
  198. function readBody(xhr) {
  199. let data;
  200. if (!xhr.responseType || xhr.responseType === "text") {
  201. data = xhr.responseText;
  202. } else if (xhr.responseType === "document") {
  203. data = xhr.responseXML;
  204. } else {
  205. data = xhr.response;
  206. }
  207. return data;
  208. }
  209.  
  210. function gotoHash(key){
  211. let hash_path;
  212. if (path[key] !== undefined) {
  213. hash_path = path[key];
  214. }else{
  215. if (key.indexOf("#")!==0) {
  216. hash_path = "#"+key;
  217. }
  218. }
  219. window.location.href = game_url + hash_path;
  220. }
  221.  
  222. function scrollTo(query,qid=0) {
  223. document.querySelectorAll(query)[qid].scrollIntoViewIfNeeded();
  224. }
  225.  
  226. function checkExist(query,qid=0) {
  227. let el_exist = false;
  228. if (document.querySelectorAll(query).length > qid){
  229. if (document.querySelectorAll(query)[qid].getBoundingClientRect().width > 0 && document.querySelectorAll(query)[qid].getBoundingClientRect().height > 0) {
  230. el_exist = true;
  231. }
  232. }
  233. return el_exist;
  234. }
  235.  
  236. function checkEl(query,qid=0,callback=false) {
  237. let old_top = -1;
  238. let old_left = -1;
  239. let loop_checkEl = setInterval(function() {
  240. console.log(checkEl.name + " " + query + "[" + qid + "]");
  241. if (checkExist(query,qid)) {
  242. if (old_top==document.querySelectorAll(query)[qid].getBoundingClientRect().top && old_left==document.querySelectorAll(query)[qid].getBoundingClientRect().left) {
  243. clearInterval(loop_checkEl);
  244. if (typeof callback == "function") {
  245. callback();
  246. }
  247. }else{
  248. old_top = document.querySelectorAll(query)[qid].getBoundingClientRect().top;
  249. old_left = document.querySelectorAll(query)[qid].getBoundingClientRect().left;
  250. }
  251. }
  252. }, 200);
  253. }
  254.  
  255. function checkEls(queries,callback=false) {
  256. let exist_result;
  257. let loop_checkEls = setInterval(function() {
  258. exist_result = [];
  259. for (let i in queries) {
  260. console.log(checkEls.name + " " + queries[i].query + "[" + queries[i].qid + "]");
  261. exist_result.push(checkExist(queries[i].query,queries[i].qid));
  262. }
  263. if (exist_result.indexOf(false)===-1) {
  264. clearInterval(loop_checkEls);
  265. if (typeof callback == "function") {
  266. callback();
  267. }
  268. }
  269. }, 300);
  270. }
  271.  
  272. function checkError() {
  273. let q_cnt_error = ".cnt-error";
  274. let q_pop_up = ".pop-usual.common-pop-error.pop-show";
  275. let check_error = setInterval(function() {
  276. let func_name = checkError.name;
  277. if (checkExist(q_pop_up,0) || checkExist(q_cnt_error,0)) {
  278. let cmd = [];
  279. console.log("error_found");
  280. let do_reload = false;
  281. let level = "notif";
  282. let msg = "Uncatagorized error found";
  283. // let msg = "Connection error, refreshing disabled"
  284. if (checkExist(q_pop_up+">.prt-popup-header",0)) {
  285. if (document.querySelector(q_pop_up+">.prt-popup-header").innerHTML=="Access Verification") {
  286. clearInterval(reload_counter);
  287. msg = my_profile+"Captcha detected";
  288. console.log("Captcha detected");
  289. }else if (document.querySelector(q_pop_up+">.prt-popup-header").innerHTML=="エラー") {
  290. if (checkExist(q_pop_up+">.prt-popup-body>.txt-popup-body>div",0)) {
  291. if (typeof document.querySelector(q_pop_up+">.prt-popup-body>.txt-popup-body>div").innerHTML == "string") {
  292. if (document.querySelector(q_pop_up+">.prt-popup-body>.txt-popup-body>div").innerHTML.indexOf("Network Error")>=0) {
  293. clearInterval(reload_counter);
  294. console.log("Error connection");
  295. do_reload = true;
  296. msg = my_profile+"Error connection, reloading";
  297. level = "process";
  298. }
  299. }
  300. }
  301. }
  302. }
  303. if (checkExist(q_pop_up+">.prt-popup-body>.txt-popup-body",0)) {
  304. if (document.querySelector(q_pop_up+">.prt-popup-body>.txt-popup-body").innerHTML=="Check your pending battles.") {
  305. console.log("check raid");
  306. level = "process";
  307. msg = my_profile+"Check your pending battle";
  308. clickEl(".prt-popup-footer>.btn-usual-ok",0,my_profile+"Clicking ok pop up pending battles");
  309. }
  310. }
  311. if (do_reload){
  312. cmd.push({"cmd":"press","key":"f5"});
  313. }
  314. cmd.push({"cmd":"log","level":level,"msg":msg});
  315. xhr.open('POST', server);
  316. xhr.send(JSON.stringify(cmd));
  317. if (do_reload){
  318. window.location.reload();
  319. }
  320. }
  321. }, 5000);
  322. }
  323.  
  324. function getCoord(el){
  325. let x, y, output;
  326. el = el.getBoundingClientRect();
  327. if (el.width>0 && el.height>0) {
  328. x = (el.width / 2) + el.left;
  329. y = (el.height / 2) + el.top;
  330. if(el.width>40){
  331. x += Math.floor(Math.random() * 41)-20;
  332. }else if(el.width>20){
  333. x += Math.floor(Math.random() * 21)-10;
  334. }else if(el.width>10){
  335. x += Math.floor(Math.random() * 11)-5;
  336. }
  337. if(el.height>10){
  338. y += Math.floor(Math.random() * 11)-5;
  339. }
  340. output = [x+margin.left,y+margin.top];
  341. }else{
  342. output = 0;
  343. }
  344. return output;
  345. }
  346.  
  347. function getMarginCoord(query,qid){
  348. let el = document.querySelectorAll(query)[qid].getBoundingClientRect();
  349. return {"top":el.top+margin.top,"left":el.left+margin.left};
  350. }
  351.  
  352. function clickNow(query,qid=0,msg=my_profile+"clickNow called",callback=false){
  353. let el = document.querySelectorAll(query)[qid];
  354. let output = false;
  355. if (checkExist(query,qid)) {
  356. output = true;
  357. let cmd = [];
  358. cmd.push({"cmd":"clickIt","param":getCoord(el)});
  359. cmd.push({"cmd":"log","level":"process","msg":msg});
  360. xhr.open("POST", server);
  361. xhr.send(JSON.stringify(cmd));
  362. if (typeof callback == "function") {
  363. callback();
  364. }
  365. }
  366. return output;
  367. }
  368.  
  369. function clickEl(query,qid=0,msg=my_profile+"clickEl called",callback=false){
  370. let init_clickEl = function() {
  371. clickNow(query,qid,msg,callback);
  372. };
  373. checkEl(query,qid,init_clickEl);
  374. }
  375.  
  376. function clickObject(obj){
  377. if (obj == "ok"){
  378. clickEl(".btn-usual-ok",0,message.ok);
  379. }
  380. }
  381.  
  382. function clickAndNegCheck(query,qid=0,msg="clickAndNegCheck called",callback=false,ticks=5){
  383. let old_top = -1;
  384. let old_left = -1;
  385. let match = ticks-1;
  386. let str_clickAndNegCheck = clickAndNegCheck.name + ", el: " + query + "["+(qid.toString())+"] \n- match = ";
  387. let init_clickAndNegCheck = function() {
  388. let loop_clickAndNegCheck = setInterval(function() {
  389. console.log(str_clickAndNegCheck+(match.toString()));
  390. if (!(checkExist(query,qid))) {
  391. clearInterval(loop_clickAndNegCheck);
  392. if (typeof callback == "function") {
  393. callback();
  394. }
  395. }else{
  396. if (checkExist(query,qid)) {
  397. if (old_top==document.querySelectorAll(query)[qid].getBoundingClientRect().top && old_left==document.querySelectorAll(query)[qid].getBoundingClientRect().left) {
  398. if (match % ticks == 0) {
  399. clickNow(query,qid,msg);
  400. }
  401. match += 1;
  402. }else{
  403. old_top = document.querySelectorAll(query)[qid].getBoundingClientRect().top;
  404. old_left = document.querySelectorAll(query)[qid].getBoundingClientRect().left;
  405. }
  406. }
  407. }
  408. }, 100);
  409. };
  410. checkEl(query,qid,init_clickAndNegCheck);
  411. }
  412.  
  413. function clickAndCheck(query1,qid1=0,query2,qid2=0,msg="clickAndCheck called",callback=false,ticks=5){
  414. let old_href = window.location.href;
  415. let old_top = -1;
  416. let old_left = -1;
  417. let match = ticks-1;
  418. let str_clickAndCheck = clickAndCheck.name + ", check: " + query2 + "["+(qid2.toString())+"], click: " + query1 + "["+(qid1.toString())+"] \n- match = ";
  419. let loop_clickAndCheck = setInterval(function() {
  420. console.log(str_clickAndCheck+(match.toString()));
  421. if (checkExist(query2,qid2)) {
  422. clearInterval(loop_clickAndCheck);
  423. if (typeof callback == "function") {
  424. callback();
  425. }
  426. }else if (old_href != window.location.href) {
  427. clearInterval(loop_clickAndCheck);
  428. }else{
  429. if (checkExist(query1,qid1)) {
  430. if (old_top==document.querySelectorAll(query1)[qid1].getBoundingClientRect().top && old_left==document.querySelectorAll(query1)[qid1].getBoundingClientRect().left) {
  431. if (match % ticks == 0) {
  432. clickNow(query1,qid1,msg);
  433. }
  434. match += 1;
  435. }else{
  436. old_top = document.querySelectorAll(query1)[qid1].getBoundingClientRect().top;
  437. old_left = document.querySelectorAll(query1)[qid1].getBoundingClientRect().left;
  438. }
  439. }
  440. }
  441. }, 100);
  442. }
  443.  
  444. function popUpNotEnough(rep) {
  445. const query = ".btn-use-full.index-1",
  446. qid = 0,
  447. msg = message.replenish.elixir.half_elixir.use;
  448. let cmd = [], coordinate, consumable_data;
  449. consumable_data = my_profile+"Consumable Status:";
  450. for (let i = 0; i < rep.length; i++) {
  451. consumable_data += ("\n- "+rep[i].name+": "+rep[i].number);
  452. }
  453. let init_popUpNotEnough = function() {
  454. coordinate = getCoord(document.querySelectorAll(query)[qid]);
  455. if (coordinate!==0){
  456. cmd.push({"cmd":"clickIt","param":coordinate});
  457. cmd.push({"cmd":"log","level":"process","msg":msg});
  458. cmd.push({"cmd":"log","level":"summary","msg":consumable_data,"split":0});
  459. xhr.open('POST', server);
  460. xhr.send(JSON.stringify(cmd));
  461. }
  462. };
  463. checkEl(query,qid,init_popUpNotEnough);
  464.  
  465. }
  466.  
  467. function clickAndCheckSkill(query,qid=0,msg="clickAndCheckSkill called",callback=false,special_case=false){
  468. let old_class = document.querySelectorAll(query)[qid].parentNode.classList[0];
  469. let loop_clickAndCheckSkill = setInterval(function() {
  470. console.log(checkEl.name + " " + query + "[" + qid + "]");
  471. 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){
  472. clearInterval(loop_clickAndCheckSkill);
  473. console.log(clickAndCheckSkill.name + " case normal");
  474. if (typeof callback == "function") {
  475. callback();
  476. }
  477. // Bea skill
  478. }else if(special_case===1 && document.querySelectorAll(query)[qid].parentNode.classList[0] != old_class){
  479. clearInterval(loop_clickAndCheckSkill);
  480. console.log(clickAndCheckSkill.name + " case " + special_case.toString());
  481. if (typeof callback == "function") {
  482. callback();
  483. }
  484. // Out of sight & sage of eternity
  485. }else if(special_case===2){
  486. let do_click = true;
  487. console.log(clickAndCheckSkill.name + " case " + special_case.toString());
  488. let popup_query = "#wrapper > div.contents > div.pop-usual.pop-select-member > div.prt-popup-header";
  489. if (checkExist(popup_query,0)) {
  490. if (document.querySelector("#wrapper > div.contents > div.pop-usual.pop-select-member > div.prt-popup-header").innerHTML == "Use Skill"){
  491. clearInterval(loop_clickAndCheckSkill);
  492. do_click = false;
  493. if (typeof callback == "function") {
  494. callback();
  495. }
  496. }
  497. }
  498. if (do_click) {
  499. if (checkExist(query,qid)) {
  500. clickNow(query,qid,msg);
  501. }
  502. }
  503. }else{
  504. if (checkExist(query,qid)) {
  505. clickNow(query,qid,msg);
  506. }
  507. }
  508.  
  509. }, 500);
  510. }
  511.  
  512. function getCharStr(char_id){
  513. let char;
  514. if (char_id==1){
  515. char = "MC";
  516. }else{
  517. char = "NPC"+((char_id-1).toString());
  518. }
  519. return char;
  520. }
  521.  
  522. function useSkill(char_id,abi_id,callback=false,special_case=false){
  523. console.log(useSkill.name + ", char: "+char_id+", ability: " + (abi_id.toString()) + ", case: "+special_case);
  524. let char = getCharStr(char_id);
  525. abi_id = parseInt(abi_id)-1;
  526. // console.log("lol");
  527. console.log(".prt-command-chara.chara"+(char_id.toString())+">div>div.lis-ability");
  528. 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){
  529. 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);
  530. }else{
  531. if (typeof callback == "function") {
  532. callback();
  533. }
  534. }
  535. }
  536.  
  537. function clickBack(callback=false){
  538. clickAndCheck(".btn-command-back.display-on",0,"div.prt-member",0,my_profile+"Clicking back",callback,10);
  539. }
  540.  
  541. function clickSummonPanel(callback=false){
  542. let query1 = ".prt-list-top.btn-command-summon.summon-on";
  543. let query2 = ".prt-summon-list.opened";
  544. let query3 = ".prt-list-top.btn-command-summon.summon-off";
  545. let qid1 = 0, qid2 = 0, qid3 = 0;
  546. let msg = my_profile+"Clicking summon panel";
  547. let old_top = -1;
  548. let old_left = -1;
  549. let loop_clickAndCheck = setInterval(function() {
  550. console.log(clickAndCheck.name + ", check: " + query2 + "["+(qid2.toString())+"], click: " + query1 + "["+(qid1.toString())+"]");
  551. if (checkExist(query2,qid2) || checkExist(query3,qid3)) {
  552. clearInterval(loop_clickAndCheck);
  553. if (typeof callback == "function") {
  554. callback();
  555. }
  556. }else{
  557. if (checkExist(query1,qid1)) {
  558. if (old_top==document.querySelectorAll(query1)[qid1].getBoundingClientRect().top && old_left==document.querySelectorAll(query1)[qid1].getBoundingClientRect().left) {
  559. clickNow(query1,qid1,msg);
  560. }else{
  561. old_top = document.querySelectorAll(query1)[qid1].getBoundingClientRect().top;
  562. old_left = document.querySelectorAll(query1)[qid1].getBoundingClientRect().left;
  563. }
  564. }
  565. }
  566. }, 200);
  567. // clickAndCheck(,0,,0,);
  568. }
  569.  
  570. function clickSummon(summon_id,callback1=false,callback2=false){
  571. summon_id = summon_id-1;
  572. if (Array.from(document.querySelectorAll(".lis-summon")[summon_id].classList).indexOf("btn-summon-available")>=0){
  573. let loop_clickSummon = setInterval(function() {
  574. if (document.querySelectorAll(".lis-summon>img")[summon_id].getBoundingClientRect().x=== 72 + (summon_id * 51)){
  575. clearInterval(loop_clickSummon);
  576. 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);
  577. }
  578. }, 300);
  579. }else{
  580. if (typeof callback2 == "function") {
  581. callback2();
  582. }
  583. }
  584. }
  585.  
  586. function clickOkSummon(callback=false){
  587. let el_ok = ".pop-usual.pop-summon-detail>div>.btn-usual-ok.btn-summon-use";
  588. if (document.querySelector(el_ok) !== null){
  589. clickAndCheck(el_ok,0,"div.prt-member",0,my_profile+"Clicking summon ok",callback);
  590. }else{
  591. if (typeof callback == "function") {
  592. callback();
  593. }
  594. }
  595. }
  596. function clickOkSummon2(summon_id,callback=false){
  597. let el_ok = ".pop-usual.pop-summon-detail>div>.btn-usual-ok.btn-summon-use";
  598. let summon_el = '.lis-summon[pos="'+(summon_id.toString())+'"]';
  599. if (document.querySelector(el_ok) !== null){
  600. let loop_clickOkSummon2 = setInterval(function() {
  601. console.log(clickOkSummon2.name + ", click: " + el_ok + "[0]");
  602. if (Array.from(document.querySelector(summon_el).classList).indexOf("tmp-mask")>=0 || Array.from(document.querySelector(summon_el).classList).indexOf("btn-summon-unavailable")>=0) {
  603. clearInterval(loop_clickOkSummon2);
  604. if (typeof callback == "function") {
  605. callback();
  606. }
  607. }else{
  608. if (checkExist(el_ok,0)) {
  609. clickNow(el_ok,0,my_profile+"Clicking summon ok2");
  610. }
  611. }
  612. }, 1000);
  613. }else{
  614. if (typeof callback == "function") {
  615. callback();
  616. }
  617. }
  618. }
  619.  
  620. function selectSummon(preferred_summon,is_trial=false){
  621. reload(20);
  622.  
  623. let init_selectSummon = function() {
  624. console.log(init_selectSummon.name);
  625. reload(10);
  626. const attrib_list = [6,0,1,2,3,4,5];
  627. let query_summon_list = ".btn-supporter.lis-supporter";
  628. let el_summon_list = document.querySelectorAll(query_summon_list);
  629. let preferred_summon_id = false;
  630. let picked_attrib_id = false;
  631. let picked_summon_id = false;
  632. let picked_is_friend = false;
  633. let is_friend;
  634. let picked_summon_stars = false;
  635. let picked_summon_level = false;
  636. let picked_summon_plus = false;
  637. let msg;
  638. let cmd = [], summon_list = {};
  639. 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){
  640. msg = my_profile+"Verify not appear, summon list length is "+(el_summon_list.length.toString());
  641. console.log(msg);
  642.  
  643. // check if raid is trial
  644. if (!is_trial){
  645. console.log("not trial");
  646. for (let i = 0; i < el_summon_list.length; i++) {
  647. let match_preferred = false, replace = false;
  648. let temp_var, summon_detail, summon_name, summon_level, summon_stars, summon_plus;
  649. temp_var = el_summon_list[i].querySelector(".prt-supporter-summon");
  650. summon_detail = temp_var.innerHTML.trim();
  651. temp_var = el_summon_list[i].querySelector(".prt-supporter-summon");
  652. summon_detail = temp_var.innerHTML.trim();
  653. summon_name = summon_detail.substring(summon_detail.indexOf("</span>")+8,summon_detail.length);
  654. summon_level = parseInt(temp_var.children[0].innerHTML.replace("Lvl ",""));
  655. temp_var = Array.from(el_summon_list[i].querySelector(".prt-summon-skill").classList);
  656. if (temp_var.indexOf("bless-rank2-style")>=0){
  657. summon_stars = 4;
  658. }else if (temp_var.indexOf("bless-rank1-style")>=0){
  659. summon_stars = 3;
  660. }else{
  661. summon_stars = 0;
  662. }
  663. temp_var = el_summon_list[i].querySelector(".prt-summon-quality");
  664. if (temp_var !== null){
  665. summon_plus = parseInt(temp_var.innerHTML.replace("+",""));
  666. }else{
  667. summon_plus = 0;
  668. }
  669. temp_var = false;
  670. is_friend = Array.from(el_summon_list[i].querySelector(".prt-supporter-name").classList).indexOf("ico-friend")>=0;
  671.  
  672. // console.log([summon_name,summon_level,summon_stars,summon_plus,is_friend]);
  673.  
  674. // loop preferred summon list (specified in parameter)
  675. for (let j = 0; j < preferred_summon.length; j++) {
  676. if (preferred_summon[j][0]==summon_name && preferred_summon[j][1]<=summon_stars){
  677. match_preferred = true;
  678. temp_var = j;
  679. }
  680. }
  681.  
  682.  
  683. if (match_preferred){
  684. if (picked_attrib_id===false && picked_summon_id===false){
  685. replace = true;
  686. }else{
  687. if (preferred_summon_id>temp_var){
  688. replace = true;
  689. }else if(preferred_summon_id==temp_var){
  690. if (summon_stars>picked_summon_stars){
  691. replace = true;
  692. }else if(summon_stars==picked_summon_stars){
  693. if (!picked_is_friend && is_friend){
  694. replace = true;
  695. }else if(picked_is_friend && is_friend){
  696. if (summon_level>picked_summon_level){
  697. replace = true;
  698. }else if(summon_level==picked_summon_level){
  699. if (summon_plus>picked_summon_plus){
  700. replace = true;
  701. }
  702. }
  703. }
  704. }
  705. }
  706. }
  707. }
  708. if (replace){
  709. picked_attrib_id = Array.from(document.querySelectorAll(".prt-supporter-attribute")).indexOf(el_summon_list[i].parentElement);
  710. picked_summon_id = i;
  711. preferred_summon_id = temp_var;
  712. picked_summon_stars = summon_stars;
  713. picked_is_friend = is_friend;
  714. picked_summon_level = summon_level;
  715. picked_summon_plus = summon_plus;
  716. }
  717. }
  718. console.log([picked_attrib_id,picked_summon_id,preferred_summon_id]);
  719. if (picked_summon_id===false){
  720. console.log("go to trial");
  721. cmd.push({"cmd":"log","level":"process","msg":message.summon.not_found});
  722. xhr.open("POST", server);
  723. xhr.send(JSON.stringify(cmd));
  724. gotoHash("trial");
  725. }else{
  726. console.log("summon_found");
  727. let pickSummon = function() {
  728. scrollTo(query_summon_list,picked_summon_id);
  729. clickEl(query_summon_list,picked_summon_id,message.summon.select);
  730. };
  731. let clickAndCheckSummon = function(callback=false){
  732. let el_tab_ele_ico = ".prt-type-text";
  733. let el_summon_container = ".prt-supporter-attribute";
  734. let loop_clickAndCheckSummon = setInterval(function() {
  735. console.log(clickAndCheckSummon.name + ", check: " + el_summon_container + "[" + picked_attrib_id + "], click: " + el_tab_ele_ico + "["+(attrib_list[picked_attrib_id].toString())+"]");
  736. if (Array.from(document.querySelectorAll(el_summon_container)[picked_attrib_id].classList).indexOf("disableView") == -1) {
  737. clearInterval(loop_clickAndCheckSummon);
  738. if (typeof callback == "function") {
  739. callback();
  740. }
  741. }else{
  742. if (checkExist(el_tab_ele_ico, attrib_list[picked_attrib_id])) {
  743. clickNow(el_tab_ele_ico, attrib_list[picked_attrib_id], message.summon.pick_tab);
  744. }
  745. }
  746. }, 300);
  747. };
  748. clickAndCheckSummon(pickSummon);
  749. }
  750. }else{
  751. console.log("is trial");
  752. query_summon_list = ".prt-supporter-attribute:not(.disableView)>.btn-supporter.lis-supporter";
  753. // clearInterval(reload_counter);
  754. el_summon_list = document.querySelectorAll(query_summon_list);
  755. // console.log(el_summon_list);
  756. for (let i = 0; i < el_summon_list.length; i++) {
  757. is_friend = Array.from(el_summon_list[i].querySelector(".prt-supporter-name").classList).indexOf("ico-friend")>=0;
  758. if (!is_friend){
  759. if (picked_summon_id===false){
  760. picked_summon_id = i;
  761. }
  762. }
  763. }
  764. // console.log(picked_summon_id);
  765. if (picked_summon_id!==false){
  766. scrollTo(".prt-supporter-attribute:not(.disableView)>.btn-supporter.lis-supporter",picked_summon_id);
  767. clickEl(".prt-supporter-attribute:not(.disableView)>.btn-supporter.lis-supporter",picked_summon_id,message.summon.select);
  768. }
  769. }
  770. }else{
  771. msg = my_profile+"Verify might appear, summon list length is "+(el_summon_list.length.toString());
  772. clearInterval(reload_counter);
  773. console.log(msg);
  774. cmd.push({"cmd":"log","level":"process","msg":msg});
  775. cmd.push({"cmd":"log","level":"notif","msg":msg});
  776. xhr.open("POST", server);
  777. xhr.send(JSON.stringify(cmd));
  778. }
  779. };
  780. checkEl(".prt-supporter-title",0,init_selectSummon);
  781. }
  782.  
  783. function doChat(callback=false) {
  784. console.log(doChat.name);
  785. let clickDialog = function() {
  786. console.log(clickDialog.name);
  787. clickAndNegCheck(query.battle_ui.chat_pop_up.dialog,0,my_profile+"Clicking chat dialog",callback);
  788. };
  789. let clickChat = function() {
  790. console.log(clickChat.name);
  791. if (checkExist(query.battle_ui.chat+">.ico-attention",0)) {
  792. clickAndCheck(query.battle_ui.chat,0,query.battle_ui.chat_pop_up.dialog,0,my_profile+"Clicking chat pop up",clickDialog,20);
  793. }else{
  794. if (typeof callback == "function") {
  795. callback();
  796. }
  797. }
  798. };
  799. checkEl(query.battle_ui.chat,0,clickChat);
  800. }
  801.  
  802. function backFromTrial(){
  803. let cmd = [];
  804. cmd.push({"cmd":"log","level":"process","msg":message.raid.trial.end});
  805. xhr.open("POST", server);
  806. xhr.send(JSON.stringify(cmd));
  807. gotoHash("main");
  808. }
  809.  
  810. function gotoResult() {
  811. console.log(gotoResult.name);
  812. console.log(is_host);
  813. if (is_host || window.location.hash.indexOf("#raid/")>=0) {
  814. gotoHash("quest");
  815. }else if (window.location.hash.indexOf("#raid_multi")>=0) {
  816. reloadNow();
  817. }
  818. }
  819.  
  820. function attack(rep){
  821. console.log(attack.name);
  822. let cmd = [];
  823. let reps = rep.scenario;
  824. let win = false;
  825. let is_last_raid = false;
  826. let ougi = 0;
  827. let msg = "";
  828. let pos_player = ["MC","NPC1","NPC2","NPC3","NPC4","NPC5"];
  829. for (let i = 0; i < reps.length; i++) {
  830. if (reps[i].cmd =="win"){
  831. if (reps[i].is_last_raid){is_last_raid=true;}
  832. win=true;
  833. }else if (reps[i].cmd=="special" || reps[i].cmd=="special_npc"){
  834. msg += my_profile+pos_player[reps[i].pos]+" used ougi \""+reps[i].name+"\".\n";
  835. if (reps[i].total){msg += my_profile+pos_player[reps[i].pos]+" dealt "+reps[i].total[0].split.join("")+" damage.\n";}
  836. ougi++;
  837. }else if (reps[i].cmd=="attack" && reps[i].from=="player"){
  838. if (reps[i].damage.length==3){
  839. msg += my_profile+pos_player[reps[i].pos]+" made a triple attack.\n";
  840. }else if (reps[i].damage.length==2){
  841. msg += my_profile+pos_player[reps[i].pos]+" made a double attack.\n";
  842. }
  843. msg += my_profile+pos_player[reps[i].pos]+ " dealt ";
  844. for (let ii=0; ii<reps[i].damage.length; ii++){
  845. msg += reps[i].damage[ii][0].value.toString();
  846. if (ii<reps[i].damage.length-1){
  847. msg += ", ";
  848. }else{
  849. msg += " damage.\n";
  850. }
  851. }
  852. }
  853. }
  854.  
  855. if(win){
  856. cmd.push({"cmd":"log","level":"process","msg":msg+my_profile+"Foe defeated."});
  857. }else{
  858. cmd.push({"cmd":"log","level":"process","msg":msg+my_profile+"Foe is still alive."});
  859. cmd.push({"cmd":"press","key":"f5"});
  860. }
  861. xhr.open('POST', server);
  862. xhr.send(JSON.stringify(cmd));
  863. if(win && is_last_raid){
  864. gotoResult();
  865. }else if(win){
  866. clickEl(".btn-result",0,my_profile+"Go to next round");
  867. }
  868. }
  869.  
  870. function skillUsed(rep){
  871. console.log(skillUsed.name);
  872. let do_reload = false;
  873. let reps = rep.scenario;
  874. let win = false, is_last_raid = false;
  875. // win = false;
  876. // is_last_raid = false;
  877. console.log(reps);
  878. for (let i = 0; i < reps.length; i++) {
  879. const scenario = reps[i];
  880. if (scenario.cmd =="ability"){
  881. if (scenario.name == "Thunder Raid") {
  882. do_reload = true;
  883. }
  884. }else if (scenario.cmd =="damage") {
  885. if (scenario.to == "player") {
  886. for (let j = 0; j < scenario.list.length; j++) {
  887. const element = scenario.list[j];
  888. if (element.hp !== undefined && element.pos !== undefined) {
  889. battle_status.player.param[element.pos].hp = element.hp;
  890. }
  891. }
  892. }
  893. }else if (scenario.cmd =="finished"){
  894. win=true;
  895. is_last_raid=true;
  896. }else if (scenario.cmd == "win"){
  897. if (scenario.is_last_raid){is_last_raid=true;}
  898. win=true;
  899. }
  900. }
  901.  
  902. if(win && is_last_raid){
  903. gotoResult();
  904. }else if(do_reload){
  905. reloadNow();
  906. }
  907. }
  908.  
  909. function potUsed(rep) {
  910. console.log(potUsed.name);
  911. let reps = rep.scenario;
  912. for (let i = 0; i < reps.length; i++) {
  913. const scenario = reps[i];
  914. if (scenario.cmd == "heal") {
  915. for (let j = 0; j < scenario.list.length; j++) {
  916. const element = scenario.list[j];
  917. if (element.hp !== undefined && element.pos !== undefined) {
  918. battle_status.player.param[element.pos].hp = element.hp;
  919. }
  920. }
  921. }
  922. }
  923. }
  924.  
  925. function raidFinish(rep){
  926. console.log(raidFinish.name);
  927. reload(10);
  928. let cmd = [];
  929. let check_timer = true;
  930. cmd.push({"cmd":"log","level":"process","msg":message.raid.finish});
  931. let reward_list = {};
  932. let loop_list = [1,2,3,4,11];
  933.  
  934. for (let l in loop_list){
  935. if (Object.keys(rep.rewards.reward_list[loop_list[l]]).length){
  936. let keys = [];
  937. for(let k in rep.rewards.reward_list[loop_list[l]]) keys.push(k);
  938. for(let i in keys){
  939. if(reward_list[rep.rewards.reward_list[loop_list[l]][keys[i]].name]){
  940. reward_list[rep.rewards.reward_list[loop_list[l]][keys[i]].name] += parseInt(rep.rewards.reward_list[loop_list[l]][keys[i]].count);
  941. }else{
  942. reward_list[rep.rewards.reward_list[loop_list[l]][keys[i]].name] = parseInt(rep.rewards.reward_list[loop_list[l]][keys[i]].count);
  943. }
  944. }
  945. }
  946. }
  947. if (tracked_item !== false){
  948. let track_item = my_profile+"Current Status:";
  949. let temp_str;
  950. for (let item in tracked_item){
  951. if (tracked_item.hasOwnProperty(item)) {
  952. temp_str = "\n- "+tracked_item[item].name+": "+(tracked_item[item].number).toString();
  953. track_item += temp_str;
  954. }
  955. }
  956. cmd.push({"cmd":"log","level":"summary","msg":track_item,"split":0});
  957. }
  958. cmd.push({"cmd":"reward","payload":reward_list});
  959. if (check_timer){
  960. cmd.push({"cmd":"check_timer"});
  961. }
  962. xhr.open('POST', server);
  963. xhr.send(JSON.stringify(cmd));
  964. let gotoMain = function() {gotoHash("main");};
  965. checkEl(".mask",0,gotoMain);
  966. }