NEET Lib

NEET Bot Library

当前为 2019-07-21 提交的版本,查看 最新版本

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

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