GBF Lib

GBF Bot Library

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

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

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

QingJ © 2025

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