GBF Lib

GBF Bot Library

当前为 2019-05-20 提交的版本,查看 最新版本

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

  1. // ==UserScript==
  2. // @name GBF Lib
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.4
  5. // @description GBF Bot Library
  6. // @author eterNEETy
  7. // @match http://game.granbluefantasy.jp/
  8. // @grant none
  9. // @namespace https://gf.qytechs.cn/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.  
  25. let is_host = "false";
  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" : "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 query = {
  82. "battle_ui": {
  83. "ougi": ".btn-lock",
  84. "toggle_ougi": {
  85. true: ".lock0",
  86. false: ".lock1",
  87. },
  88. },
  89. "assist_ui": {
  90. "tab_id": "#tab-id",
  91. "tab_multi": "#tab-multi",
  92. "tab_event": "#tab-event",
  93. "unclaimed": ".btn-unclaimed",
  94. },
  95. "poker": {
  96. "canvas": "#canv",
  97. "deal": ".prt-start",
  98. "ok": ".prt-ok",
  99. "yes": ".prt-yes",
  100. "no": ".prt-no",
  101. "low": ".prt-double-select>.prt-low-shine",
  102. "high": ".prt-double-select>.prt-high-shine",
  103. },
  104. "ok":".btn-usual-ok",
  105. };
  106.  
  107. // general item variable
  108. let tracked_item = false;
  109.  
  110. function reloadNow() {
  111. console.log(reloadNow.name);
  112. xhr.open('POST', server);
  113. xhr.send(JSON.stringify([{"cmd":"press","key":"f5"}]));
  114. window.location.reload();
  115. }
  116.  
  117. function reload(mod_value=1) {
  118. clearInterval(reload_counter);
  119. let current_path = window.location.hash;
  120. let count = 1;
  121. reload_counter = setInterval(function() {
  122. if(window.location.hash != current_path){
  123. clearInterval(reload_counter);
  124. }
  125. console.log("reloading in "+(mod_value-count).toString());
  126. if (count%mod_value===0){
  127. clearInterval(reload_counter);
  128. reloadNow();
  129. }
  130. count += 1;
  131. }, 1000);
  132. }
  133.  
  134. function setDebug() {
  135. if(!debug){
  136. console.log("DEBUG is turned OFF");
  137. if(!window.console) window.console = {};
  138. let methods = ["log", "debug", "warn", "info"];
  139. for(let i=0;i<methods.length;i++){
  140. console[methods[i]] = function(){};
  141. }
  142. }
  143. }
  144.  
  145. function readBody(xhr) {
  146. let data;
  147. if (!xhr.responseType || xhr.responseType === "text") {
  148. data = xhr.responseText;
  149. } else if (xhr.responseType === "document") {
  150. data = xhr.responseXML;
  151. } else {
  152. data = xhr.response;
  153. }
  154. return data;
  155. }
  156.  
  157. function gotoHash(key){
  158. let hash_path;
  159. if (path[key] !== undefined) {
  160. hash_path = path[key];
  161. }else{
  162. if (key.indexOf("#")!==0) {
  163. hash_path = "#"+key;
  164. }
  165. }
  166. window.location.href = game_url + hash_path;
  167. }
  168.  
  169. function scrollTo(query,qid=0) {
  170. document.querySelectorAll(query)[qid].scrollIntoViewIfNeeded();
  171. }
  172.  
  173. function checkExist(query,qid) {
  174. let el_exist = false;
  175. if (document.querySelectorAll(query).length > qid){
  176. if (document.querySelectorAll(query)[qid].getBoundingClientRect().width > 0 && document.querySelectorAll(query)[qid].getBoundingClientRect().height > 0) {
  177. el_exist = true;
  178. }
  179. }
  180. return el_exist;
  181. }
  182.  
  183. function checkEl(query,qid,callback=false) {
  184. let loop_checkEl = setInterval(function() {
  185. console.log(checkEl.name + " " + query + "[" + qid + "]");
  186. if (checkExist(query,qid)) {
  187. clearInterval(loop_checkEl);
  188. if (typeof callback == "function") {
  189. callback();
  190. }
  191. }
  192. }, 300);
  193. }
  194.  
  195. function checkEls(queries,callback=false) {
  196. let exist_result;
  197. let loop_checkEls = setInterval(function() {
  198. exist_result = [];
  199. for (let i in queries) {
  200. console.log(checkEls.name + " " + queries[i].query + "[" + queries[i].qid + "]");
  201. exist_result.push(checkExist(queries[i].query,queries[i].qid));
  202. }
  203. if (exist_result.indexOf(false)===-1) {
  204. clearInterval(loop_checkEls);
  205. if (typeof callback == "function") {
  206. callback();
  207. }
  208. }
  209. }, 300);
  210. }
  211.  
  212. function checkError() {
  213. let func_name = checkError.name;
  214. let check_error = setInterval(function() {
  215. console.log("check_error");
  216. if (document.getElementsByClassName("pop-usual common-pop-error pop-show")[0] || document.getElementsByClassName("cnt-error")[0]) {
  217. let cmd = [];
  218. console.log("error_found");
  219. let do_reload = false;
  220. let level = "notif";
  221. let msg = "Uncatagorized error found";
  222. // let msg = "Connection error, refreshing disabled"
  223. if (document.getElementsByClassName("pop-usual common-pop-error pop-show")[0]){
  224. if (document.getElementsByClassName("pop-usual common-pop-error pop-show")[0].children.length>0){
  225. if (document.getElementsByClassName("pop-usual common-pop-error pop-show")[0].children[0].className=="prt-popup-header" || document.getElementsByClassName("pop-usual common-pop-error pop-show")[0].children[1].className=="prt-popup-body"){
  226. if (document.getElementsByClassName("pop-usual common-pop-error pop-show")[0].children[0].innerHTML=="Processing"){
  227. do_reload = true;
  228. msg = my_profile+"Waiting for last turn, reloading";
  229. level = "process";
  230. }else if (document.getElementsByClassName("pop-usual common-pop-error pop-show")[0].children[0].innerHTML=="Access Verification"){
  231. msg = my_profile+"Captcha detected";
  232. clearInterval(reload_counter);
  233. }else if (document.getElementsByClassName("pop-usual common-pop-error pop-show")[0].children[1].children[0].children[0].innerHTML.indexOf("Network Error")>=0){
  234. do_reload = true;
  235. msg = my_profile+"Error connection, reloading";
  236. level = "process";
  237. }
  238. }
  239. }
  240. }
  241. if (do_reload){
  242. cmd.push({"cmd":"press","key":"f5"});
  243. }
  244. cmd.push({"cmd":"log","level":level,"msg":msg});
  245. xhr.open('POST', server);
  246. xhr.send(JSON.stringify(cmd));
  247. if (do_reload){
  248. window.location.reload();
  249. }
  250. }
  251. }, 5000);
  252. }
  253.  
  254. function getCoord(el){
  255. let x, y, output;
  256. el = el.getBoundingClientRect();
  257. if (el.width>0 && el.height>0) {
  258. x = (el.width / 2) + el.left;
  259. y = (el.height / 2) + el.top;
  260. if(el.width>40){
  261. x += Math.floor(Math.random() * 41)-20;
  262. }else if(el.width>20){
  263. x += Math.floor(Math.random() * 21)-10;
  264. }else if(el.width>10){
  265. x += Math.floor(Math.random() * 11)-5;
  266. }
  267. if(el.height>10){
  268. y += Math.floor(Math.random() * 11)-5;
  269. }
  270. output = [x+margin.left,y+margin.top];
  271. }else{
  272. output = 0;
  273. }
  274. return output;
  275. }
  276.  
  277. function getMarginCoord(query,qid){
  278. let el = document.querySelectorAll(query)[qid].getBoundingClientRect();
  279. return {"top":el.top+margin.top,"left":el.left+margin.left};
  280. }
  281.  
  282. function clickNow(query,qid=0,msg=my_profile+"clickNow called",callback=false){
  283. let el = document.querySelectorAll(query)[qid];
  284. let output = false;
  285. if (checkExist(query,qid)) {
  286. output = true;
  287. let cmd = [];
  288. cmd.push({"cmd":"clickIt","param":getCoord(el)});
  289. cmd.push({"cmd":"log","level":"process","msg":msg});
  290. xhr.open("POST", server);
  291. xhr.send(JSON.stringify(cmd));
  292. if (typeof callback == "function") {
  293. callback();
  294. }
  295. }
  296. return output;
  297. }
  298.  
  299. function clickEl(query,qid=0,msg=my_profile+"clickEl called",callback=false){
  300. let init_clickEl = function() {
  301. clickNow(query,qid,msg,callback);
  302. };
  303. checkEl(query,qid,init_clickEl);
  304. }
  305.  
  306. function clickObject(obj){
  307. if (obj == "ok"){
  308. clickEl(".btn-usual-ok",0,message.ok);
  309. }
  310. }
  311.  
  312. function clickAndCheck(query1,qid1=0,query2,qid2=0,msg="clickAndCheck called",callback=false){
  313. let old_top = 0;
  314. let old_left = 0;
  315. let loop_clickAndCheck = setInterval(function() {
  316. console.log(clickAndCheck.name + ", check: " + query2 + "["+(qid2.toString())+"], click: " + query1 + "["+(qid1.toString())+"]");
  317. if (checkExist(query2,qid2)) {
  318. clearInterval(loop_clickAndCheck);
  319. if (typeof callback == "function") {
  320. callback();
  321. }
  322. }else{
  323. if (checkExist(query1,qid1)) {
  324. if (old_top==document.querySelectorAll(query1)[qid1].getBoundingClientRect().top && old_left==document.querySelectorAll(query1)[qid1].getBoundingClientRect().left) {
  325. clickNow(query1,qid1,msg);
  326. }else{
  327. old_top = document.querySelectorAll(query1)[qid1].getBoundingClientRect().top;
  328. old_left = document.querySelectorAll(query1)[qid1].getBoundingClientRect().left;
  329. }
  330. }
  331. }
  332. }, 300);
  333. }
  334.  
  335. function popUpNotEnough(rep) {
  336. const query = ".btn-use-full.index-1",
  337. qid = 0,
  338. msg = message.replenish.elixir.half_elixir.use;
  339. let cmd = [], coordinate, consumable_data;
  340. consumable_data = my_profile+"Consumable Status:";
  341. for (let i = 0; i < rep.length; i++) {
  342. consumable_data += ("\n- "+rep[i].name+": "+rep[i].number);
  343. }
  344. let init_popUpNotEnough = function() {
  345. coordinate = getCoord(document.querySelectorAll(query)[qid]);
  346. if (coordinate!==0){
  347. cmd.push({"cmd":"clickIt","param":coordinate});
  348. cmd.push({"cmd":"log","level":"process","msg":msg});
  349. cmd.push({"cmd":"log","level":"summary","msg":consumable_data,"split":0});
  350. xhr.open('POST', server);
  351. xhr.send(JSON.stringify(cmd));
  352. }
  353. };
  354. checkEl(query,qid,init_popUpNotEnough);
  355.  
  356. }
  357.  
  358. function clickAndCheckSkill(query,qid=0,msg="clickAndCheckSkill called",callback=false,special_case=false){
  359. let old_class = document.querySelectorAll(query)[qid].parentNode.classList[0];
  360. let loop_clickAndCheckSkill = setInterval(function() {
  361. console.log(checkEl.name + " " + query + "[" + qid + "]");
  362. 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){
  363. clearInterval(loop_clickAndCheckSkill);
  364. console.log(clickAndCheckSkill.name + " case normal");
  365. if (typeof callback == "function") {
  366. callback();
  367. }
  368. // Bea skill
  369. }else if(special_case===1 && document.querySelectorAll(query)[qid].parentNode.classList[0] != old_class){
  370. clearInterval(loop_clickAndCheckSkill);
  371. console.log(clickAndCheckSkill.name + " case " + special_case.toString());
  372. if (typeof callback == "function") {
  373. callback();
  374. }
  375. // Out of sight
  376. }else if(special_case===2){
  377. console.log(clickAndCheckSkill.name + " case " + special_case.toString());
  378. let popup_query = "#wrapper > div.contents > div.pop-usual.pop-select-member > div.prt-popup-header";
  379. if (checkExist(popup_query,0)) {
  380. if (document.querySelector("#wrapper > div.contents > div.pop-usual.pop-select-member > div.prt-popup-header").innerHTML == "Use Skill"){
  381. clearInterval(loop_clickAndCheckSkill);
  382. if (typeof callback == "function") {
  383. callback();
  384. }
  385. }
  386. }
  387. }else{
  388. if (checkExist(query,qid)) {
  389. clickNow(query,qid,msg);
  390. }
  391. }
  392.  
  393. }, 500);
  394. }
  395.  
  396. function getCharStr(char_id){
  397. let char;
  398. if (char_id==1){
  399. char = "MC";
  400. }else{
  401. char = "NPC"+((char_id-1).toString());
  402. }
  403. return char;
  404. }
  405.  
  406. function useSkill(char_id,abi_id,callback=false,special_case=false){
  407. console.log(useSkill.name + ", char: "+char_id+", ability: " + (abi_id.toString()) + ", case: "+special_case);
  408. let char = getCharStr(char_id);
  409. abi_id = parseInt(abi_id)-1;
  410. // console.log("lol");
  411. console.log(".prt-command-chara.chara"+(char_id.toString())+">div>div.lis-ability");
  412. 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){
  413. 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);
  414. }else{
  415. if (typeof callback == "function") {
  416. callback();
  417. }
  418. }
  419. }
  420.  
  421. function clickBack(callback=false){
  422. clickAndCheck(".btn-command-back.display-on",0,"div.prt-member",0,my_profile+"Clicking back",callback);
  423. }
  424.  
  425. function clickSummonPanel(callback=false){
  426. let query1 = ".prt-list-top.btn-command-summon.summon-on";
  427. let query2 = ".prt-summon-list.opened";
  428. let query3 = ".prt-list-top.btn-command-summon.summon-off";
  429. let qid1 = 0, qid2 = 0, qid3 = 0;
  430. let msg = my_profile+"Clicking summon panel";
  431. let old_top = 0;
  432. let old_left = 0;
  433. let loop_clickAndCheck = setInterval(function() {
  434. console.log(clickAndCheck.name + ", check: " + query2 + "["+(qid2.toString())+"], click: " + query1 + "["+(qid1.toString())+"]");
  435. if (checkExist(query2,qid2) || checkExist(query3,qid3)) {
  436. clearInterval(loop_clickAndCheck);
  437. if (typeof callback == "function") {
  438. callback();
  439. }
  440. }else{
  441. if (checkExist(query1,qid1)) {
  442. if (old_top==document.querySelectorAll(query1)[qid1].getBoundingClientRect().top && old_left==document.querySelectorAll(query1)[qid1].getBoundingClientRect().left) {
  443. clickNow(query1,qid1,msg);
  444. }else{
  445. old_top = document.querySelectorAll(query1)[qid1].getBoundingClientRect().top;
  446. old_left = document.querySelectorAll(query1)[qid1].getBoundingClientRect().left;
  447. }
  448. }
  449. }
  450. }, 200);
  451. // clickAndCheck(,0,,0,);
  452. }
  453.  
  454. function clickSummon(summon_id,callback1=false,callback2=false){
  455. summon_id = summon_id-1;
  456. if (Array.from(document.querySelectorAll(".lis-summon")[summon_id].classList).indexOf("btn-summon-available")>=0){
  457. let loop_clickSummon = setInterval(function() {
  458. if (document.querySelectorAll(".lis-summon>img")[summon_id].getBoundingClientRect().x=== 72 + (summon_id * 51)){
  459. clearInterval(loop_clickSummon);
  460. 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);
  461. }
  462. }, 300);
  463. }else{
  464. if (typeof callback2 == "function") {
  465. callback2();
  466. }
  467. }
  468. }
  469.  
  470. function clickOkSummon(callback=false){
  471. let el_ok = ".pop-usual.pop-summon-detail>div>.btn-usual-ok.btn-summon-use";
  472. if (document.querySelector(el_ok) !== null){
  473. clickAndCheck(el_ok,0,"div.prt-member",0,my_profile+"Clicking summon ok",callback);
  474. }else{
  475. if (typeof callback == "function") {
  476. callback();
  477. }
  478. }
  479. }
  480. function clickOkSummon2(summon_id,callback=false){
  481. let el_ok = ".pop-usual.pop-summon-detail>div>.btn-usual-ok.btn-summon-use";
  482. let summon_el = '.lis-summon[pos="'+(summon_id.toString())+'"]';
  483. if (document.querySelector(el_ok) !== null){
  484. let loop_clickOkSummon2 = setInterval(function() {
  485. console.log(clickOkSummon2.name + ", click: " + el_ok + "[0]");
  486. if (Array.from(document.querySelector(summon_el).classList).indexOf("tmp-mask")>=0 || Array.from(document.querySelector(summon_el).classList).indexOf("btn-summon-unavailable")>=0) {
  487. clearInterval(loop_clickOkSummon2);
  488. if (typeof callback == "function") {
  489. callback();
  490. }
  491. }else{
  492. if (checkExist(el_ok,0)) {
  493. clickNow(el_ok,0,my_profile+"Clicking summon ok2");
  494. }
  495. }
  496. }, 1000);
  497. }else{
  498. if (typeof callback == "function") {
  499. callback();
  500. }
  501. }
  502. }
  503.  
  504. function selectSummon(preferred_summon,is_trial=false){
  505. reload(20);
  506.  
  507. let init_selectSummon = function() {
  508. console.log(init_selectSummon.name);
  509. reload(10);
  510. const attrib_list = [6,0,1,2,3,4,5];
  511. let query_summon_list = ".btn-supporter.lis-supporter";
  512. let el_summon_list = document.querySelectorAll(query_summon_list);
  513. let preferred_summon_id = false;
  514. let picked_attrib_id = false;
  515. let picked_summon_id = false;
  516. let picked_is_friend = false;
  517. let is_friend;
  518. let picked_summon_stars = false;
  519. let picked_summon_level = false;
  520. let picked_summon_plus = false;
  521. let msg;
  522. let cmd = [], summon_list = {};
  523. 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){
  524. msg = my_profile+"Verify not appear, summon list length is "+(el_summon_list.length.toString());
  525. console.log(msg);
  526.  
  527. // check if raid is trial
  528. if (!is_trial){
  529. console.log("not trial");
  530. for (let i = 0; i < el_summon_list.length; i++) {
  531. let match_preferred = false, replace = false;
  532. let temp_var, summon_detail, summon_name, summon_level, summon_stars, summon_plus;
  533. temp_var = el_summon_list[i].querySelector(".prt-supporter-summon");
  534. summon_detail = temp_var.innerHTML.trim();
  535. temp_var = el_summon_list[i].querySelector(".prt-supporter-summon");
  536. summon_detail = temp_var.innerHTML.trim();
  537. summon_name = summon_detail.substring(summon_detail.indexOf("</span>")+8,summon_detail.length);
  538. summon_level = parseInt(temp_var.children[0].innerHTML.replace("Lvl ",""));
  539. temp_var = Array.from(el_summon_list[i].querySelector(".prt-summon-skill").classList);
  540. if (temp_var.indexOf("bless-rank2-style")>=0){
  541. summon_stars = 4;
  542. }else if (temp_var.indexOf("bless-rank1-style")>=0){
  543. summon_stars = 3;
  544. }else{
  545. summon_stars = 0;
  546. }
  547. temp_var = el_summon_list[i].querySelector(".prt-summon-quality");
  548. if (temp_var !== null){
  549. summon_plus = parseInt(temp_var.innerHTML.replace("+",""));
  550. }else{
  551. summon_plus = 0;
  552. }
  553. temp_var = false;
  554. is_friend = Array.from(el_summon_list[i].querySelector(".prt-supporter-name").classList).indexOf("ico-friend")>=0;
  555.  
  556. // console.log([summon_name,summon_level,summon_stars,summon_plus,is_friend]);
  557.  
  558. // loop preferred summon list (specified in parameter)
  559. for (let j = 0; j < preferred_summon.length; j++) {
  560. if (preferred_summon[j][0]==summon_name && preferred_summon[j][1]<=summon_stars){
  561. match_preferred = true;
  562. temp_var = j;
  563. }
  564. }
  565.  
  566.  
  567. if (match_preferred){
  568. if (picked_attrib_id===false && picked_summon_id===false){
  569. replace = true;
  570. }else{
  571. if (preferred_summon_id>temp_var){
  572. replace = true;
  573. }else if(preferred_summon_id==temp_var){
  574. if (summon_stars>picked_summon_stars){
  575. replace = true;
  576. }else if(summon_stars==picked_summon_stars){
  577. if (picked_is_friend && !is_friend){
  578. replace = true;
  579. }else if(!picked_is_friend && !is_friend){
  580. if (summon_level>picked_summon_level){
  581. replace = true;
  582. }else if(summon_level==picked_summon_level){
  583. if (summon_plus>picked_summon_plus){
  584. replace = true;
  585. }
  586. }
  587. }
  588. }
  589. }
  590. }
  591. }
  592. if (replace){
  593. picked_attrib_id = Array.from(document.querySelectorAll(".prt-supporter-attribute")).indexOf(el_summon_list[i].parentElement);
  594. picked_summon_id = i;
  595. preferred_summon_id = temp_var;
  596. picked_summon_stars = summon_stars;
  597. picked_is_friend = is_friend;
  598. picked_summon_level = summon_level;
  599. picked_summon_plus = summon_plus;
  600. }
  601. }
  602. console.log([picked_attrib_id,picked_summon_id,preferred_summon_id]);
  603. if (picked_summon_id===false){
  604. console.log("go to trial");
  605. cmd.push({"cmd":"log","level":"process","msg":message.summon.not_found});
  606. xhr.open("POST", server);
  607. xhr.send(JSON.stringify(cmd));
  608. gotoHash("trial");
  609. }else{
  610. console.log("summon_found");
  611. let pickSummon = function() {
  612. scrollTo(query_summon_list,picked_summon_id);
  613. clickEl(query_summon_list,picked_summon_id,message.summon.select);
  614. };
  615. let clickAndCheckSummon = function(callback=false){
  616. let el_tab_ele_ico = ".prt-type-text";
  617. let el_summon_container = ".prt-supporter-attribute";
  618. let loop_clickAndCheckSummon = setInterval(function() {
  619. console.log(clickAndCheckSummon.name + ", check: " + el_summon_container + "[" + picked_attrib_id + "], click: " + el_tab_ele_ico + "["+(attrib_list[picked_attrib_id].toString())+"]");
  620. if (Array.from(document.querySelectorAll(el_summon_container)[picked_attrib_id].classList).indexOf("disableView") == -1) {
  621. clearInterval(loop_clickAndCheckSummon);
  622. if (typeof callback == "function") {
  623. callback();
  624. }
  625. }else{
  626. if (checkExist(el_tab_ele_ico, attrib_list[picked_attrib_id])) {
  627. clickNow(el_tab_ele_ico, attrib_list[picked_attrib_id], message.summon.pick_tab);
  628. }
  629. }
  630. }, 300);
  631. };
  632. clickAndCheckSummon(pickSummon);
  633. }
  634. }else{
  635. console.log("is trial");
  636. query_summon_list = ".prt-supporter-attribute:not(.disableView)>.btn-supporter.lis-supporter";
  637. // clearInterval(reload_counter);
  638. el_summon_list = document.querySelectorAll(query_summon_list);
  639. // console.log(el_summon_list);
  640. for (let i = 0; i < el_summon_list.length; i++) {
  641. is_friend = Array.from(el_summon_list[i].querySelector(".prt-supporter-name").classList).indexOf("ico-friend")>=0;
  642. if (!is_friend){
  643. if (picked_summon_id===false){
  644. picked_summon_id = i;
  645. }
  646. }
  647. }
  648. // console.log(picked_summon_id);
  649. if (picked_summon_id!==false){
  650. scrollTo(".prt-supporter-attribute:not(.disableView)>.btn-supporter.lis-supporter",picked_summon_id);
  651. clickEl(".prt-supporter-attribute:not(.disableView)>.btn-supporter.lis-supporter",picked_summon_id,message.summon.select);
  652. }
  653. }
  654. }else{
  655. msg = my_profile+"Verify might appear, summon list length is "+(el_summon_list.length.toString());
  656. clearInterval(reload_counter);
  657. console.log(msg);
  658. cmd.push({"cmd":"log","level":"process","msg":msg});
  659. cmd.push({"cmd":"log","level":"notif","msg":msg});
  660. xhr.open("POST", server);
  661. xhr.send(JSON.stringify(cmd));
  662. }
  663. };
  664. checkEl(".prt-supporter-title",0,init_selectSummon);
  665. }
  666.  
  667. function backFromTrial(){
  668. var cmd = [];
  669. cmd.push({"cmd":"log","level":"process","msg":message.raid.trial.end});
  670. xhr.open("POST", server);
  671. xhr.send(JSON.stringify(cmd));
  672. gotoHash("main");
  673. }
  674.  
  675. function gotoResult() {
  676. console.log(gotoResult.name);
  677. console.log(is_host);
  678. if (is_host) {
  679. gotoHash("quest");
  680. }else if (window.location.hash.indexOf("#raid_multi")>=0) {
  681. window.location.reload();
  682. }
  683. }
  684.  
  685. function attack(rep){
  686. console.log(attack.name);
  687. let cmd = [];
  688. let reps = rep.scenario;
  689. let win = false;
  690. let is_last_raid = false;
  691. let ougi = 0;
  692. let msg = "";
  693. let pos_player = ["MC","NPC1","NPC2","NPC3","NPC4","NPC5"];
  694. for (let i = 0; i < reps.length; i++) {
  695. if (reps[i].cmd =="win"){
  696. if (reps[i].is_last_raid){is_last_raid=true;}
  697. win=true;
  698. }else if (reps[i].cmd=="special" || reps[i].cmd=="special_npc"){
  699. msg += my_profile+pos_player[reps[i].pos]+" used ougi \""+reps[i].name+"\".\n";
  700. if (reps[i].total){msg += my_profile+pos_player[reps[i].pos]+" dealt "+reps[i].total[0].split.join("")+" damage.\n";}
  701. ougi++;
  702. }else if (reps[i].cmd=="attack" && reps[i].from=="player"){
  703. if (reps[i].damage.length==3){
  704. msg += my_profile+pos_player[reps[i].pos]+" made a triple attack.\n";
  705. }else if (reps[i].damage.length==2){
  706. msg += my_profile+pos_player[reps[i].pos]+" made a double attack.\n";
  707. }
  708. msg += my_profile+pos_player[reps[i].pos]+ " dealt ";
  709. for (let ii=0; ii<reps[i].damage.length; ii++){
  710. msg += reps[i].damage[ii][0].value.toString();
  711. if (ii<reps[i].damage.length-1){
  712. msg += ", ";
  713. }else{
  714. msg += " damage.\n";
  715. }
  716. }
  717. }
  718. }
  719.  
  720. if(win){
  721. cmd.push({"cmd":"log","level":"process","msg":msg+my_profile+"Foe defeated."});
  722. }else{
  723. cmd.push({"cmd":"log","level":"process","msg":msg+my_profile+"Foe is still alive."});
  724. cmd.push({"cmd":"press","key":"f5"});
  725. }
  726. xhr.open('POST', server);
  727. xhr.send(JSON.stringify(cmd));
  728. if(win && is_last_raid){
  729. gotoResult();
  730. }else if(win){
  731. clickEl(".btn-result",0,my_profile+"Go to next round");
  732. }
  733. }
  734.  
  735. function skillUsed(rep){
  736. console.log(skillUsed.name);
  737. let do_reload = false;
  738. let reps = rep.scenario;
  739. let win = false, is_last_raid = false;
  740. console.log(reps);
  741. // var cmd = [];
  742. for (let i = 0; i < reps.length; i++) {
  743. if (reps[i].cmd =="win"){
  744. if (reps[i].is_last_raid){is_last_raid=true;}
  745. win=true;
  746. }else if(reps[i].cmd =="finished"){
  747. win=true;
  748. is_last_raid=true;
  749. }
  750. if (reps[i].cmd == "ability" && reps[i].name == "Thunder Raid"){
  751. do_reload = true;
  752. }
  753. }
  754.  
  755. if(win && is_last_raid){
  756. gotoResult();
  757. }else if(do_reload){
  758. window.location.reload();
  759. }
  760. }
  761.  
  762. function raidFinish(rep){
  763. console.log(raidFinish.name);
  764. reload(10);
  765. let cmd = [];
  766. let check_timer = true;
  767. cmd.push({"cmd":"log","level":"process","msg":message.raid.finish});
  768. let reward_list = {};
  769. let loop_list = [1,2,3,4,11];
  770.  
  771. for (let l in loop_list){
  772. if (Object.keys(rep.rewards.reward_list[loop_list[l]]).length){
  773. let keys = [];
  774. for(let k in rep.rewards.reward_list[loop_list[l]]) keys.push(k);
  775. for(let i in keys){
  776. if(reward_list[rep.rewards.reward_list[loop_list[l]][keys[i]].name]){
  777. reward_list[rep.rewards.reward_list[loop_list[l]][keys[i]].name] += parseInt(rep.rewards.reward_list[loop_list[l]][keys[i]].count);
  778. }else{
  779. reward_list[rep.rewards.reward_list[loop_list[l]][keys[i]].name] = parseInt(rep.rewards.reward_list[loop_list[l]][keys[i]].count);
  780. }
  781. }
  782. }
  783. }
  784. if (tracked_item !== false){
  785. let track_item = my_profile+"Current Status:";
  786. let temp_str;
  787. for (let item in tracked_item){
  788. if (tracked_item.hasOwnProperty(item)) {
  789. temp_str = "\n- "+tracked_item[item].name+": "+(tracked_item[item].number).toString();
  790. track_item += temp_str;
  791. }
  792. }
  793. cmd.push({"cmd":"log","level":"summary","msg":track_item,"split":0});
  794. }
  795. cmd.push({"cmd":"reward","payload":reward_list});
  796. if (check_timer){
  797. cmd.push({"cmd":"check_timer"});
  798. }
  799. xhr.open('POST', server);
  800. xhr.send(JSON.stringify(cmd));
  801. let checkExist = setInterval(function() {
  802. console.log("raid_finish");
  803. if (document.getElementsByClassName("mask")[0].getBoundingClientRect().width>0){
  804. clearInterval(checkExist);
  805. gotoHash("main");
  806. }
  807. }, 300);
  808. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址