NEET Lib

NEET Bot Library

目前為 2020-01-04 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/383201/763140/NEET%20Lib.js

  1. // ==UserScript==
  2. // @name NEET Lib
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.6.0
  5. // @description NEET Bot Library
  6. // @author eterNEETy
  7. // @match http://game.granbluefantasy.jp/
  8. // @grant none
  9. // @namespace https://greasyfork.org/users/292830
  10. // ==/UserScript==
  11. // jshint esversion: 6
  12. // jshint -W138
  13.  
  14. /*
  15.  
  16. changelog:
  17.  
  18. 1.1.0:
  19. - added init()
  20. - changed `let main_path` to `path.main`
  21.  
  22. 1.2.0:
  23. - changed charMoveSet cid
  24.  
  25. 1.3.0:
  26. - added discord_mention
  27. 1.3.2:
  28. - missionComplete(cmd=[]);
  29.  
  30. 1.4.0:
  31. - lot of skill changes
  32. 1.4.1:
  33. - changed scrollTo to scroll_To
  34. 1.4.2:
  35. - changed getCoord, added auto scroll
  36.  
  37. 1.5.0:
  38. - replaced all references
  39. - changed 'message' from not defined to defined (let)
  40. - changed 'getMessage' to 'updateMessage'
  41. - changed 'battleLogic' from function to var
  42. - changed 'listenNetwork' from function to var
  43. 1.5.1:
  44. - added a lot of support changes
  45. 1.5.2:
  46. - added cnt_error "An error has occurred. Return to the Home screen and try again. If this issue continues, please use the contact form."
  47. 1.5.3:
  48. - added skin summon support
  49. 1.5.4:
  50. - changed all cid+1 to battle.formation.indexOf(cid.toString())+1
  51. - added specialSkillBuffSingle and buff_single_skill_case
  52. 1.5.5 (754182):
  53. - added tryParseJSON
  54. 1.5.6 (759468):
  55. - added 'raids' object
  56.  
  57. 1.6.0:
  58. - changed 'raids' object to have key 'name' and 'tweet'
  59. - changed 'xhr', 'server', 'margin' and 'game_url' from const to let
  60. */
  61.  
  62.  
  63. // environment info
  64. let xhr = new XMLHttpRequest(),
  65. server = 'http://localhost:2487',
  66. margin = {'top':91,'left':0},
  67. // margin = {'top':104,'left':0},
  68. game_url = 'http://game.granbluefantasy.jp/';
  69.  
  70. let debug = true,
  71. reload_counter;
  72.  
  73. let zoom = 1;
  74.  
  75. let is_host = 'false';
  76. let battle;
  77. let is_wiped = true;
  78. let discord_mention = '';
  79. let abi_special_case = false;
  80. let buff_single_skill_case = {};
  81.  
  82. let quests_id = [], monsters = [], monsters_name = [];
  83. let reloadable_skill = ['Four-Sky\'s Sorrow', 'Thunder Raid'];
  84. let reloadable_summon = ['デス・サーティーン'];
  85. const recovery_items = ['Elixir','Half Elixir','Soul Balm','Soul Berry'];
  86. let tracker_reward_weapons = [];
  87. let tracker_reward_summons = [];
  88. let tracker_reward_items = [recovery_items[0], recovery_items[1], recovery_items[2], recovery_items[3],'Gold Brick','Damascus Grain','Silver Centrum'];
  89.  
  90.  
  91. const huanglong = {'name':'Huanglong', 'star':3},
  92. // providence
  93. lucifer = {'name':'Lucifer', 'star':5},
  94. bahamut = {'name':'Bahamut', 'star':5},
  95. // regallia
  96. shiva = {'name':'Shiva', 'star':3},
  97. shiva0 = {'name':'Shiva', 'star':0},
  98. europa = {'name':'Europa', 'star':3},
  99. europa0 = {'name':'Europa', 'star':0},
  100. alex = {'name':'Godsworn Alexiel', 'star':3},
  101. alex0 = {'name':'Godsworn Alexiel', 'star':0},
  102. grimnir = {'name':'Grimnir', 'star':3},
  103. grimnir0 = {'name':'Grimnir', 'star':0},
  104. // optimus
  105. agni = {'name':'Agni', 'star':4},
  106. agni3 = {'name':'Agni', 'star':3},
  107. agni0 = {'name':'Agni', 'star':0},
  108. varuna = {'name':'Varuna', 'star':4},
  109. varuna3 = {'name':'Varuna', 'star':3},
  110. varuna0 = {'name':'Varuna', 'star':0},
  111. titan = {'name':'Titan', 'star':4},
  112. titan3 = {'name':'Titan', 'star':3},
  113. titan0 = {'name':'Titan', 'star':0},
  114. zephyrus = {'name':'Zephyrus', 'star':4},
  115. zephyrus3 = {'name':'Zephyrus', 'star':3},
  116. zephyrus0 = {'name':'Zephyrus', 'star':0},
  117. zeus = {'name':'Zeus', 'star':4},
  118. zeus3 = {'name':'Zeus', 'star':3},
  119. zeus0 = {'name':'Zeus', 'star':0},
  120. hades = {'name':'Hades', 'star':4},
  121. hades3 = {'name':'Hades', 'star':3},
  122. hades0 = {'name':'Hades', 'star':0},
  123. // magna
  124. colossus = {'name':'Colossus Omega', 'star':4},
  125. leviathan = {'name':'Leviathan Omega', 'star':4},
  126. yggdrasil = {'name':'Yggdrasil Omega', 'star':4},
  127. tiamat = {'name':'Tiamat Omega', 'star':4},
  128. luminiera = {'name':'Luminiera Omega', 'star':4},
  129. celeste = {'name':'Celeste Omega', 'star':4},
  130. //
  131. raphael = {'name':'Raphael', 'star':3},
  132. raphael0 = {'name':'Raphael', 'star':0},
  133. gabriel = {'name':'Gabriel', 'star':3},
  134. gabriel0 = {'name':'Gabriel', 'star':0},
  135. uriel = {'name':'Uriel', 'star':3},
  136. // ele
  137. poseidon = {'name':'Poseidon', 'star':3},
  138. poseidon0 = {'name':'Poseidon', 'star':0},
  139. //
  140. bonito = {'name':'Bonito', 'star':4},
  141. // misc
  142. kaguya = {'name':'Kaguya', 'star':3},
  143. kaguya0 = {'name':'Kaguya', 'star':0},
  144. nobiyo = {'name':'Nobiyo', 'star':4},
  145. nobiyo3 = {'name':'Nobiyo', 'star':3},
  146. white_rabbit = {'name':'White Rabbit', 'star':3},
  147. black_rabbit = {'name':'Black Rabbit', 'star':3};
  148. const leech_summons = [kaguya,kaguya0,nobiyo,white_rabbit,black_rabbit,nobiyo3],
  149. ele_water_summons = [poseidon,europa,poseidon0,europa0,bonito,gabriel,gabriel0];
  150.  
  151. const raids = {
  152. 'regalia': {
  153. 'shiva': {'name': 'Shiva (Impossible)', 'tweet': 'Lvl 120 Shiva'},
  154. 'europa': {'name': 'Europa (Impossible)', 'tweet': 'Lvl 120 Europa'},
  155. 'alex': {'name': 'Godsworn Alexiel (Impossible)', 'tweet': 'Lvl 120 Godsworn Alexiel'},
  156. 'grimnir': {'name': 'Grimnir (Impossible)', 'tweet': 'Lvl 120 Grimnir'},
  157. 'metatron': {'name': 'Metatron (Impossible)', 'tweet': 'Lvl 120 Metatron'},
  158. 'avatar': {'name': 'Avatar (Impossible)', 'tweet': 'Lvl 120 Avatar'},
  159. },
  160. 'nightmare': {
  161. 'grande': {'name': 'The Peacemaker\'s Wings', 'tweet': 'Lvl 100 Grand Order'},
  162. 'proto_baha': {'name': 'Wings of Terror', 'tweet': 'Lvl 100 Proto Bahamut'},
  163. 'huang': {'name': 'The Dark Sunrise', 'tweet': 'Lvl 100 Huanglong'},
  164. 'qilin': {'name': 'Dusk of Nightfall', 'tweet': 'Lvl 100 Qilin'},
  165. 'hl': {
  166. 'grande': {'name': 'The Peacemaker\'s Wings (Impossible)', 'tweet': 'Lvl 200 Grand Order'},
  167. 'proto_baha': {'name': 'Wings of Terror (Impossible)', 'tweet': 'Lvl 150 Proto Bahamut'},
  168. 'akasha': {'name': 'Omen of the Broken Skies', 'tweet': 'Lvl 200 Akasha'},
  169. 'luci': {'name': 'Dark Rapture', 'tweet': 'Lvl 150 Lucilius'},
  170. 'qilin_huang': {'name': 'Huanglong & Qilin (Impossible)', 'tweet': 'Huanglong & Qilin (Impossible)'},
  171. 'hard': {
  172. 'luci': {'name': 'Dark Rapture (Hard)', 'tweet': 'Lvl 250 Lucilius'},
  173. },
  174. }
  175. },
  176. 'primach': {
  177. 'fire': {'name': 'Michael\'s Test', 'tweet': 'Lvl 100 Michael'},
  178. 'water': {'name': 'Gabriel\'s Test', 'tweet': 'Lvl 100 Gabriel'},
  179. 'earth': {'name': 'Uriel\'s Test', 'tweet': 'Lvl 100 Uriel'},
  180. 'wind': {'name': 'Raphael\'s Test', 'tweet': 'Lvl 100 Raphael'},
  181. 'hl': {'name': 'The Four Primarchs (Impossible)', 'tweet': 'The Four Primarchs'},
  182. },
  183. 't1': {
  184. 'fire': {'name': 'Twin Elements Showdown', 'tweet': 'Lvl 100 Twin Elements'},
  185. 'water': {'name': 'Macula Marius Showdown', 'tweet': 'Lvl 100 Macula Marius'},
  186. 'earth': {'name': 'Medusa Showdown', 'tweet': 'Lvl 100 Medusa'},
  187. 'wind': {'name': 'Nezha Showdown', 'tweet': 'Lvl 100 Nezha'},
  188. 'light': {'name': 'Apollo Showdown', 'tweet': 'Lvl 100 Apollo'},
  189. 'dark': {'name': 'Dark Angel Olivia Showdown', 'tweet': 'Lvl 100 Dark Angel Olivia'},
  190. 'hl': {
  191. 'fire': {'name': 'Twin Elements (Impossible)', 'tweet': 'Lvl 120 Twin Elements'},
  192. 'water': {'name': 'Macula Marius (Impossible)', 'tweet': 'Lvl 120 Macula Marius'},
  193. 'earth': {'name': 'Medusa (Impossible)', 'tweet': 'Lvl 120 Medusa'},
  194. 'wind': {'name': 'Nezha (Impossible)', 'tweet': 'Lvl 120 Nezha'},
  195. 'light': {'name': 'Apollo (Impossible)', 'tweet': 'Lvl 120 Apollo'},
  196. 'dark': {'name': 'Dark Angel Olivia (Impossible)', 'tweet': 'Lvl 120 Dark Angel Olivia'},
  197. }
  198. },
  199. 't2': {
  200. 'fire': {'name': 'Athena Showdown', 'tweet': 'Lvl 100 Athena'},
  201. 'water': {'name': 'Grani Showdown', 'tweet': 'Lvl 100 Grani'},
  202. 'earth': {'name': 'Baal Showdown', 'tweet': 'Lvl 100 Baal'},
  203. 'wind': {'name': 'Garuda Showdown', 'tweet': 'Lvl 100 Garuda'},
  204. 'light': {'name': 'Odin Showdown', 'tweet': 'Lvl 100 Odin'},
  205. 'dark': {'name': 'Lich Showdown', 'tweet': 'Lvl 100 Lich'},
  206. },
  207. 't3': {
  208. 'fire': {'name': 'Prometheus (Impossible)', 'tweet': 'Lvl 120 Prometheus'},
  209. 'water': {'name': 'Ca Ong (Impossible)', 'tweet': 'Lvl 120 Ca Ong'},
  210. 'earth': {'name': 'Gilgamesh (Impossible)', 'tweet': 'Lvl 120 Gilgamesh'},
  211. 'wind': {'name': 'Morrigna (Impossible)', 'tweet': 'Lvl 120 Morrigna'},
  212. 'light': {'name': 'Hector (Raid)', 'tweet': 'Lvl 120 Hector'},
  213. 'dark': {'name': 'Anubis (Impossible)', 'tweet': 'Lvl 120 Anubis'},
  214. },
  215. 'ultimate': {
  216. 'baha': {'name': 'Empyreal Ascension', 'tweet': 'Lvl 150 Ultimate Bahamut'},
  217. 'hl': {
  218. 'baha': {'name': 'Empyreal Ascension Impossible', 'tweet': 'Lvl 200 Ultimate Bahamut'},
  219. }
  220. },
  221. 'malice': {
  222. 'water': {'name': 'Leviathan Malice (Impossible)', 'tweet': 'Lvl 150 Leviathan Malice'},
  223. 'earth': {'name': 'Yggdrasil Malice (Impossible)', 'tweet': 'Lvl 150 Yggdrasil Malice'},
  224. 'wind': {'name': 'Tiamat Malice (Impossible)', 'tweet': 'Lvl 150 Tiamat Malice'},
  225. }
  226. };
  227.  
  228.  
  229. const trial_id = '990011',
  230. select_summon_path = 'supporter/';
  231. // path
  232. let path = {
  233. 'main': '',
  234. 'item':'#item',
  235. 'quest':'#quest',
  236. 'support':'#quest/supporter/',
  237. 'assist':'#quest/assist',
  238. 'unclaimed':'#quest/assist/unclaimed',
  239. 'trial':'#quest/supporter/'+trial_id+'/17',
  240. };
  241.  
  242. // element dom query selector
  243. let skill_char = '#prt-command-top > div > div > div.lis-character';
  244. let skill_abi = '.btn-command-character > div.prt-ability-state > div.lis-ability-state.ability';
  245. let query = {
  246. 'battle_ui': {
  247. 'skill': {
  248. 'char1': {
  249. 'skill1': skill_char + '0' + skill_abi + '1',
  250. 'skill2': skill_char + '0' + skill_abi + '2',
  251. 'skill3': skill_char + '0' + skill_abi + '3',
  252. 'skill4': skill_char + '0' + skill_abi + '4',
  253. },
  254. 'char2': {
  255. 'skill1': skill_char + '1' + skill_abi + '1',
  256. 'skill2': skill_char + '1' + skill_abi + '2',
  257. 'skill3': skill_char + '1' + skill_abi + '3',
  258. 'skill4': skill_char + '1' + skill_abi + '4',
  259. },
  260. 'char3': {
  261. 'skill1': skill_char + '2' + skill_abi + '1',
  262. 'skill2': skill_char + '2' + skill_abi + '2',
  263. 'skill3': skill_char + '2' + skill_abi + '3',
  264. 'skill4': skill_char + '2' + skill_abi + '4',
  265. },
  266. 'char4': {
  267. 'skill1': skill_char + '3' + skill_abi + '1',
  268. 'skill2': skill_char + '3' + skill_abi + '2',
  269. 'skill3': skill_char + '3' + skill_abi + '3',
  270. 'skill4': skill_char + '3' + skill_abi + '4',
  271. },
  272. },
  273. 'skill_pop_up': {
  274. 'char1': 'div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character0.btn-command-character > img',
  275. 'char2': 'div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character1.btn-command-character > img',
  276. 'char3': 'div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character2.btn-command-character > img',
  277. 'char4': 'div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character3.btn-command-character > img',
  278. 'char5': 'div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character4.btn-command-character > img',
  279. 'char6': 'div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character5.btn-command-character > img',
  280. },
  281. 'ougi': '.btn-lock',
  282. 'toggle_ougi': {
  283. true: '.lock0',
  284. false: '.lock1',
  285. },
  286. 'char_ico': '.prt-party>.prt-member>.btn-command-character>img.img-chara-command',
  287. 'summon_panel': '.prt-summon-list>.prt-list-top.btn-command-summon',
  288. 'chat':'.btn-chat.comment.display-on',
  289. 'chat_pop_up': {
  290. 'dialog':'.txt-chat-pop',
  291. },
  292. 'heal':'#prt-sub-command-group>.btn-temporary',
  293. 'heal_pop_up': {
  294. 'green': '.lis-item.item-small',
  295. 'blue': '.lis-item.item-large',
  296. 'Green Potion': '.lis-item.item-small',
  297. 'Blue Potion': '.lis-item.item-large',
  298. 'Support Potion': '.lis-item.btn-event-item[item-id="1"]',
  299. 'Clarity Herb': '.lis-item.btn-event-item[item-id="2"]',
  300. 'Revival Potion': '.lis-item.btn-event-item[item-id="3"]',
  301. 'use': '.pop-usual.pop-raid-item.pop-show>.prt-popup-footer>.btn-usual-use',
  302. 'cancel': '.pop-usual.pop-raid-item.pop-show>.prt-popup-footer>.btn-usual-cancel',
  303. },
  304. 'trial_pop_up': {
  305. 'close': '.pop-usual.pop-trialbattle-notice.pop-show>.prt-popup-footer>.btn-usual-close',
  306. },
  307. 'backup_pop_up': {
  308. 'request': '.pop-usual.pop-start-assist.pop-show>.prt-popup-footer>.btn-usual-text',
  309. 'cancel': '.pop-usual.pop-start-assist.pop-show>.prt-popup-footer>.btn-usual-cancel',
  310. },
  311. 'button': {
  312. 'assist': '.prt-multi-buttons>.btn-assist',
  313. },
  314. },
  315. 'assist_ui': {
  316. 'tab_id': '#tab-id',
  317. 'tab_multi': '#tab-multi',
  318. 'tab_event': '#tab-event',
  319. 'unclaimed': '.btn-unclaimed',
  320. },
  321. 'poker': {
  322. 'canvas': '#canv',
  323. 'deal': '.prt-start',
  324. 'ok': '.prt-ok',
  325. 'yes': '.prt-yes',
  326. 'no': '.prt-no',
  327. 'low': '.prt-double-select>.prt-low-shine',
  328. 'high': '.prt-double-select>.prt-high-shine',
  329. },
  330. 'ok':'.btn-usual-ok',
  331. };
  332.  
  333. let my_profile = '';
  334. function updateMessage(pilot) {
  335. const message = {
  336. "raid" : {
  337. "panel" : {
  338. "open" : pilot+"Opening quest/raid panel",
  339. "pick" : pilot+"Picking quest/raid difficulties",
  340. },
  341. "select_party" : pilot+"Selecting party",
  342. "finish" : pilot+"Raid finished",
  343. "trial" : {
  344. "close_pop_up" : pilot+"In trial, closing pop up",
  345. "open_menu" : pilot+ "In trial, click menu",
  346. "retreat" : pilot+ "In trial, click retreat",
  347. "ok" : pilot+ "In trial, click ok",
  348. "end" : pilot+"Retreated from trial, back to main raid",
  349. }
  350. },
  351. "summon" : {
  352. "select" : pilot+"Selecting summon",
  353. "pick_tab" : pilot+"Clicking summon element tab",
  354. "not_found" : pilot+"Support summon not found, going to trial",
  355. },
  356. "replenish" : {
  357. "elixir" : {
  358. "half_elixir" : {
  359. "use" : pilot+"Not enough AP, using half elixir",
  360. "used" : pilot+"Half elixir used",
  361. }
  362. },
  363. "soul" : {
  364. "soul_berry" : {
  365. "use" : pilot+"Not enough EP, using soul berry",
  366. "used" : pilot+"soul berry used",
  367. }
  368. }
  369. },
  370. "ok" : pilot+"Clicking ok",
  371. };
  372. return message;
  373. }
  374. let message = updateMessage(my_profile);
  375.  
  376. // general item variable
  377. let tracked_item = false;
  378.  
  379. function tryParseJSON (jsonString){
  380. try {
  381. var o = JSON.parse(jsonString);
  382.  
  383. // Handle non-exception-throwing cases:
  384. // Neither JSON.parse(false) or JSON.parse(1234) throw errors, hence the type-checking,
  385. // but... JSON.parse(null) returns null, and typeof null === "object",
  386. // so we must check for that, too. Thankfully, null is falsey, so this suffices:
  387. if (o && typeof o === "object") {
  388. return o;
  389. }
  390. }
  391. catch (e) { }
  392.  
  393. return false;
  394. }
  395.  
  396. function reloadNow() {
  397. console.log(reloadNow.name);
  398. xhr.open('POST', server);
  399. xhr.send(JSON.stringify([{'cmd':'press','key':'f5'}]));
  400. window.location.reload();
  401. }
  402.  
  403. function reload(mod_value=1) {
  404. clearInterval(reload_counter);
  405. let current_path = window.location.hash;
  406. let count = 1;
  407. reload_counter = setInterval(function() {
  408. if(window.location.hash != current_path){
  409. clearInterval(reload_counter);
  410. }
  411. console.log('reloading in '+(mod_value-count).toString());
  412. if (count%mod_value===0){
  413. clearInterval(reload_counter);
  414. reloadNow();
  415. }
  416. count += 1;
  417. }, 1000);
  418. }
  419.  
  420. function setDebug() {
  421. if(!debug){
  422. console.log('DEBUG is turned OFF');
  423. if(!window.console) window.console = {};
  424. let methods = ['log', 'debug', 'warn', 'info'];
  425. for(let i=0;i<methods.length;i++){
  426. console[methods[i]] = function(){};
  427. }
  428. }
  429. }
  430.  
  431. function readBody(xhr) {
  432. let data;
  433. if (!xhr.responseType || xhr.responseType === 'text') {
  434. data = xhr.responseText;
  435. } else if (xhr.responseType === 'document') {
  436. data = xhr.responseXML;
  437. } else {
  438. data = xhr.response;
  439. }
  440. return data;
  441. }
  442.  
  443. function gotoHash(key){
  444. let hash_path;
  445. if (path[key] !== undefined) {
  446. hash_path = path[key];
  447. }else{
  448. if (key.indexOf('#')!==0) {
  449. hash_path = '#'+key;
  450. }
  451. }
  452. window.location.href = game_url + hash_path;
  453. }
  454.  
  455. function scroll_To(query,qid=0) {
  456. document.querySelectorAll(query)[qid].scrollIntoViewIfNeeded();
  457. }
  458.  
  459. function checkExist(query,qid=0) {
  460. let el_exist = false;
  461. if (document.querySelectorAll(query).length > qid){
  462. if (document.querySelectorAll(query)[qid].getBoundingClientRect().width > 0 && document.querySelectorAll(query)[qid].getBoundingClientRect().height > 0) {
  463. el_exist = true;
  464. }
  465. }
  466. return el_exist;
  467. }
  468.  
  469. function checkEl(query,qid=0,callback=false) {
  470. let old_top = -1;
  471. let old_left = -1;
  472. let loop_checkEl = setInterval(function() {
  473. console.log(checkEl.name + " " + query + "[" + qid + "]");
  474. if (checkExist(query,qid)) {
  475. if (old_top==document.querySelectorAll(query)[qid].getBoundingClientRect().top && old_left==document.querySelectorAll(query)[qid].getBoundingClientRect().left) {
  476. clearInterval(loop_checkEl);
  477. if (typeof callback == "function") {
  478. callback();
  479. }
  480. }else{
  481. old_top = document.querySelectorAll(query)[qid].getBoundingClientRect().top;
  482. old_left = document.querySelectorAll(query)[qid].getBoundingClientRect().left;
  483. }
  484. }
  485. }, 200);
  486. }
  487.  
  488. function checkEls(queries,callback=false) {
  489. let exist_result;
  490. let loop_checkEls = setInterval(function() {
  491. exist_result = [];
  492. for (let i in queries) {
  493. console.log(checkEls.name + " " + queries[i].query + "[" + queries[i].qid + "]");
  494. exist_result.push(checkExist(queries[i].query,queries[i].qid));
  495. }
  496. if (exist_result.indexOf(false)===-1) {
  497. clearInterval(loop_checkEls);
  498. if (typeof callback == "function") {
  499. callback();
  500. }
  501. }
  502. }, 300);
  503. }
  504.  
  505. function checkElsOR(queries,callback=false) {
  506. let exist_result;
  507. let loop_checkEls = setInterval(function() {
  508. exist_result = [];
  509. for (let i in queries) {
  510. console.log(checkElsOR.name + " " + queries[i].query + "[" + queries[i].qid + "]");
  511. exist_result.push(checkExist(queries[i].query,queries[i].qid));
  512. }
  513. if (exist_result.indexOf(true)>=0) {
  514. clearInterval(loop_checkEls);
  515. if (typeof callback == "function") {
  516. callback();
  517. }
  518. }
  519. }, 300);
  520. }
  521.  
  522. function checkError() {
  523. let q_cnt_error = ".cnt-error";
  524. let q_pop_up = ".pop-usual.common-pop-error.pop-show";
  525. let q_abi_pop_up = ".pop-usual.pop-raid-ability-error.pop-show";
  526. let check_error = setInterval(function() {
  527. console.log(checkError.name);
  528. if (checkExist(q_pop_up,0) || checkExist(q_cnt_error,0) || checkExist(q_abi_pop_up,0)) {
  529. let cmd = [];
  530. console.log("error_found");
  531. let do_reload = false;
  532. let level = "notif";
  533. let msg = "Uncatagorized error found";
  534. // let msg = "Connection error, refreshing disabled"
  535. if (checkExist(q_cnt_error,0)) {
  536. if (checkExist('#wrapper > div.contents > div.cnt-error > div.prt-frame > div',0)) {
  537. if (checkExist('#wrapper > div.contents > div.cnt-error > div.prt-frame > div > p',0)) {
  538. do_reload = true;
  539. let msg_str = document.querySelector('#wrapper > div.contents > div.cnt-error > div.prt-frame > div > p').innerHTML;
  540. msg_str = msg_str.replace(/<br>/g,' ').replace(/<\/br>/g,' ').trim().replace(/\s{2,}/g, ' ').trim();
  541. msg = my_profile + msg_str +' Reloading.';
  542. level = "notif";
  543. }
  544. }
  545. } else if (checkExist(q_abi_pop_up,0)) {
  546. do_reload = true;
  547. msg = my_profile + document.querySelector(q_abi_pop_up+">.prt-popup-body>.txt-popup-body").innerHTML;
  548. level = "process";
  549. } else {
  550. if (checkExist(q_pop_up+">.prt-popup-header",0)) {
  551. if (document.querySelector(q_pop_up+">.prt-popup-header").innerHTML=="Access Verification") {
  552. clearInterval(reload_counter);
  553. clearInterval(check_error);
  554. msg = my_profile+"Captcha detected. " + discord_mention;
  555. console.log("Captcha detected");
  556. }else if (document.querySelector(q_pop_up+">.prt-popup-header").innerHTML=="エラー") {
  557. if (checkExist(q_pop_up+">.prt-popup-body>.txt-popup-body>div",0)) {
  558. if (typeof document.querySelector(q_pop_up+">.prt-popup-body>.txt-popup-body>div").innerHTML == "string") {
  559. if (document.querySelector(q_pop_up+">.prt-popup-body>.txt-popup-body>div").innerHTML.indexOf("Network Error")>=0) {
  560. clearInterval(reload_counter);
  561. console.log("Error connection");
  562. do_reload = true;
  563. msg = my_profile+"Error connection, reloading";
  564. level = "process";
  565. }
  566. }
  567. }
  568. }
  569. }
  570. if (checkExist(q_pop_up+">.prt-popup-body>.txt-popup-body",0)) {
  571. if (document.querySelector(q_pop_up+">.prt-popup-body>.txt-popup-body").innerHTML=="Check your pending battles.") {
  572. console.log("check raid");
  573. level = "process";
  574. msg = my_profile+"Check your pending battle";
  575. clickEl(".prt-popup-footer>.btn-usual-ok",0,my_profile+"Clicking ok pop up pending battles");
  576. }
  577. }
  578. }
  579. if (do_reload){
  580. cmd.push({"cmd":"press","key":"f5"});
  581. }
  582. cmd.push({"cmd":"log","level":level,"msg":msg});
  583. xhr.open('POST', server);
  584. xhr.send(JSON.stringify(cmd));
  585. if (do_reload){
  586. window.location.reload();
  587. }
  588. }
  589. }, 5000);
  590. }
  591.  
  592. function getCoord(el){
  593. zoom = parseInt(document.getElementById("mobage-game-container").style.zoom);
  594. let x, y, output;
  595. let pos_el = el.getBoundingClientRect();
  596. if (pos_el.top >= 0 && pos_el.bottom <= window.innerHeight) {
  597. if (pos_el.width>0 && pos_el.height>0) {
  598. x = (pos_el.width / 2) + pos_el.left;
  599. y = (pos_el.height / 2) + pos_el.top;
  600. if(pos_el.width>40){
  601. x += Math.floor(Math.random() * 41)-20;
  602. }else if(pos_el.width>20){
  603. x += Math.floor(Math.random() * 21)-10;
  604. }else if(pos_el.width>10){
  605. x += Math.floor(Math.random() * 11)-5;
  606. }
  607. if(pos_el.height>10){
  608. y += Math.floor(Math.random() * 11)-5;
  609. }
  610. output = [(x*zoom)+margin.left,(y*zoom)+margin.top];
  611. }else{
  612. output = 0;
  613. }
  614. return output;
  615. } else {
  616. el.scrollIntoViewIfNeeded();
  617. return getCoord(el);
  618. }
  619. }
  620.  
  621. function getMarginCoord(query,qid){
  622. let el = document.querySelectorAll(query)[qid].getBoundingClientRect();
  623. return {"top":el.top+margin.top,"left":el.left+margin.left};
  624. }
  625.  
  626. function clickNow(query,qid=0,msg=my_profile+"clickNow called",callback=false){
  627. let el = document.querySelectorAll(query)[qid];
  628. let output = false;
  629. if (checkExist(query,qid)) {
  630. output = true;
  631. let cmd = [];
  632. cmd.push({"cmd":"clickIt","param":getCoord(el)});
  633. cmd.push({"cmd":"log","level":"process","msg":msg});
  634. xhr.open("POST", server);
  635. xhr.send(JSON.stringify(cmd));
  636. if (typeof callback == "function") {
  637. callback();
  638. }
  639. }
  640. return output;
  641. }
  642.  
  643. function clickEl(query,qid=0,msg=my_profile+"clickEl called",callback=false){
  644. let init_clickEl = function() {
  645. clickNow(query,qid,msg,callback);
  646. };
  647. checkEl(query,qid,init_clickEl);
  648. }
  649.  
  650. function clickObject(obj){
  651. if (obj == "ok"){
  652. clickEl(".btn-usual-ok",0,message.ok);
  653. }
  654. }
  655.  
  656. function clickAndNegCheck(query,qid=0,msg="clickAndNegCheck called",callback=false,ticks=5){
  657. let old_href = window.location.href;
  658. let old_top = -1;
  659. let old_left = -1;
  660. let match = ticks-1;
  661. let str_clickAndNegCheck = clickAndNegCheck.name + ", el: " + query + "["+(qid.toString())+"] \n- match = ";
  662. let init_clickAndNegCheck = function() {
  663. let loop_clickAndNegCheck = setInterval(function() {
  664. console.log(str_clickAndNegCheck+(match.toString()));
  665. if (!(checkExist(query,qid))) {
  666. clearInterval(loop_clickAndNegCheck);
  667. if (typeof callback == "function") {
  668. callback();
  669. }
  670. }else if (old_href != window.location.href) {
  671. clearInterval(loop_clickAndNegCheck);
  672. }else{
  673. if (checkExist(query,qid)) {
  674. if (old_top==document.querySelectorAll(query)[qid].getBoundingClientRect().top && old_left==document.querySelectorAll(query)[qid].getBoundingClientRect().left) {
  675. if (match % ticks == 0) {
  676. clickNow(query,qid,msg);
  677. }
  678. match += 1;
  679. }else{
  680. old_top = document.querySelectorAll(query)[qid].getBoundingClientRect().top;
  681. old_left = document.querySelectorAll(query)[qid].getBoundingClientRect().left;
  682. }
  683. }
  684. }
  685. }, 100);
  686. };
  687. checkEl(query,qid,init_clickAndNegCheck);
  688. }
  689.  
  690. function clickAndCheck(query1,qid1=0,query2,qid2=0,msg="clickAndCheck called",callback=false,ticks=5){
  691. let old_href = window.location.href;
  692. let old_top = -1;
  693. let old_left = -1;
  694. let match = ticks-1;
  695. let str_clickAndCheck = clickAndCheck.name + ", check: " + query2 + "["+(qid2.toString())+"], click: " + query1 + "["+(qid1.toString())+"] \n- match = ";
  696. let loop_clickAndCheck = setInterval(function() {
  697. console.log(str_clickAndCheck+(match.toString()));
  698. if (checkExist(query2,qid2)) {
  699. clearInterval(loop_clickAndCheck);
  700. if (typeof callback == "function") {
  701. callback();
  702. }
  703. }else if (old_href != window.location.href) {
  704. clearInterval(loop_clickAndCheck);
  705. }else{
  706. if (checkExist(query1,qid1)) {
  707. if (old_top==document.querySelectorAll(query1)[qid1].getBoundingClientRect().top && old_left==document.querySelectorAll(query1)[qid1].getBoundingClientRect().left) {
  708. if (match % ticks == 0) {
  709. clickNow(query1,qid1,msg);
  710. }
  711. match += 1;
  712. }else{
  713. old_top = document.querySelectorAll(query1)[qid1].getBoundingClientRect().top;
  714. old_left = document.querySelectorAll(query1)[qid1].getBoundingClientRect().left;
  715. }
  716. }
  717. }
  718. }, 100);
  719. }
  720.  
  721. function popUpNotEnough(rep) {
  722. const query = ".btn-use-full.index-1",
  723. qid = 0,
  724. msg = message.replenish.elixir.half_elixir.use;
  725. let cmd = [], coordinate, consumable_data;
  726. consumable_data = my_profile+"Consumable Status:";
  727. for (let i = 0; i < rep.length; i++) {
  728. consumable_data += ("\n- "+rep[i].name+": "+rep[i].number);
  729. }
  730. let init_popUpNotEnough = function() {
  731. coordinate = getCoord(document.querySelectorAll(query)[qid]);
  732. if (coordinate!==0){
  733. cmd.push({"cmd":"clickIt","param":coordinate});
  734. cmd.push({"cmd":"log","level":"process","msg":msg});
  735. cmd.push({"cmd":"log","level":"summary","msg":consumable_data,"split":0});
  736. xhr.open('POST', server);
  737. xhr.send(JSON.stringify(cmd));
  738. }
  739. };
  740. checkEl(query,qid,init_popUpNotEnough);
  741.  
  742. }
  743.  
  744.  
  745. // function clickAndCheckSkill(query,qid=0,msg="clickAndCheckSkill called",callback=false,special_case=false){
  746. // console.log(clickAndCheckSkill.name);
  747. // console.log(callback);
  748. // console.log(query);
  749. // console.log(qid);
  750. // let old_class = document.querySelectorAll(query)[qid].parentNode.classList[0];
  751. // console.log(old_class);
  752. // let loop_clickAndCheckSkill = setInterval(function() {
  753. // console.log(loop_clickAndCheckSkill.name + " " + query + "[" + qid + "]");
  754. // 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){
  755. // clearInterval(loop_clickAndCheckSkill);
  756. // console.log(clickAndCheckSkill.name + " case normal");
  757. // if (typeof callback == "function") {
  758. // callback();
  759. // }
  760. // // Bea skill
  761. // }else if(special_case===1 && document.querySelectorAll(query)[qid].parentNode.classList[0] != old_class){
  762. // clearInterval(loop_clickAndCheckSkill);
  763. // console.log(clickAndCheckSkill.name + " case " + special_case.toString());
  764. // if (typeof callback == "function") {
  765. // callback();
  766. // }
  767. // // Out of sight & sage of eternity
  768. // }else if(special_case===2){
  769. // let do_click = true;
  770. // console.log(clickAndCheckSkill.name + " case " + special_case.toString());
  771. // let popup_query = "#wrapper > div.contents > div.pop-usual.pop-select-member > div.prt-popup-header";
  772. // if (checkExist(popup_query,0)) {
  773. // if (document.querySelector("#wrapper > div.contents > div.pop-usual.pop-select-member > div.prt-popup-header").innerHTML == "Use Skill"){
  774. // clearInterval(loop_clickAndCheckSkill);
  775. // do_click = false;
  776. // if (typeof callback == "function") {
  777. // callback();
  778. // }
  779. // }
  780. // }
  781. // if (do_click) {
  782. // if (checkExist(query,qid)) {
  783. // clickNow(query,qid,msg);
  784. // }
  785. // }
  786. // }else{
  787. // if (checkExist(query,qid)) {
  788. // clickNow(query,qid,msg);
  789. // }
  790. // }
  791.  
  792. // }, 500);
  793. // }
  794.  
  795.  
  796.  
  797. function clickSkill(cid,abi_id,callback=false){
  798. console.log(clickSkill.name+', cid: '+cid.toString()+', ability: '+abi_id.toString());
  799. let query = ".prt-command-chara.chara"+((battle.formation.indexOf(cid.toString())+1).toString())+">div>div>div>.img-ability-icon";
  800. let qid = abi_id;
  801. let char = battle.player.param[cid].name;
  802. let msg = my_profile+"Clicking "+char+" skill"+((abi_id+1).toString());
  803. let old_class = document.querySelectorAll(query)[qid].parentNode.classList[0];
  804. let abi_obj = Object.values(battle.ability).find(x => x.pos === cid);
  805. let abi_name = abi_obj.list[abi_id+1][0]['ability-name'];
  806. let specialSkillBuffSingle = function(BuffSingle) {
  807. console.log('case '+abi_name);
  808. console.log('buff_single_skill_case:');
  809. console.log(buff_single_skill_case);
  810. console.log('BuffSingle:');
  811. console.log(BuffSingle);
  812. clearInterval(reload_counter);
  813. let do_click = true;
  814. let popup_query = '#wrapper > div.contents > div.pop-usual.pop-select-member > div.prt-popup-header';
  815. let buff_single_cid = buff_single_skill_case[BuffSingle];
  816. let q_img_buff_single_cid = 'placeholder';
  817. if (checkExist(popup_query,0)) {
  818. if (document.querySelector(popup_query).innerHTML == 'Use Skill'){
  819. clearInterval(loop_clickSkill);
  820. do_click = false;
  821. let error_special_case = true;
  822. let error_msg = 'Error skill: ';
  823.  
  824. if (buff_single_skill_case === false){
  825. error_msg = 'buff_single_skill_case is false.';
  826. } else {
  827. console.log('typeof buff_single_skill_case');
  828. console.log(typeof buff_single_skill_case);
  829. console.log('BuffSingle');
  830. console.log(BuffSingle);
  831. error_msg = abi_name + ': buff_single_skill_case object not found.';
  832. if (typeof buff_single_skill_case === 'object') {
  833. if (buff_single_skill_case.hasOwnProperty(BuffSingle)) {
  834. error_msg = abi_name + ': buff_single_skill_case.'+BuffSingle+' type is invalid.';
  835. if (typeof buff_single_skill_case[BuffSingle] === 'string' || buff_single_skill_case[BuffSingle] === 0) {
  836. error_msg = abi_name + ': buff_single_cid is not a number.';
  837. buff_single_cid = buff_single_skill_case[BuffSingle];
  838. if (!(Number.isInteger(buff_single_cid))) {
  839. buff_single_cid = battle.player.param.findIndex(x => x.name === buff_single_skill_case[BuffSingle]);
  840. }
  841. if (Number.isInteger(buff_single_cid)) {
  842. error_msg = abi_name + ': q_img_buff_single_cid is not exist.';
  843. q_img_buff_single_cid = '#wrapper > div.contents > div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character'+buff_single_cid+'.btn-command-character:not(.mask-black) > img';
  844. if (checkExist(q_img_buff_single_cid,0)) {
  845. error_special_case = false;
  846. }
  847. }
  848. }
  849. }
  850. }
  851. }
  852. console.log('error_special_case: '+error_special_case);
  853. console.log(error_msg);
  854. if (error_special_case) {
  855. let cmd = [];
  856. cmd.push({"cmd":"log","level":"notif","msg":my_profile+error_msg+' '+discord_mention});
  857. xhr.open('POST', server);
  858. xhr.send(JSON.stringify(cmd));
  859. } else {
  860. clickAndNegCheck(q_img_buff_single_cid,0,my_profile+'Clicking '+abi_name +', target: '+(buff_single_skill_case[BuffSingle]).toString(),callback);
  861. }
  862.  
  863.  
  864.  
  865. }
  866. }
  867. if (do_click) {
  868. if (checkExist(query,qid)) {
  869. clickNow(query,qid,msg);
  870. }
  871. }
  872. };
  873. let loop_clickSkill = setInterval(function() {
  874. console.log("loop_clickSkill " + query + "[" + qid + "]");
  875. 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){
  876. clearInterval(loop_clickSkill);
  877. console.log('case normal cooldown');
  878. if (typeof callback == "function") {
  879. callback();
  880. }
  881. // } else if (buff_single_skill_list.indexOf(abi_name)>=0) {
  882. } else if (buff_single_skill_case.hasOwnProperty(abi_name)) {
  883. specialSkillBuffSingle(abi_name);
  884.  
  885.  
  886. } else if (abi_name === 'Runeweaving') {
  887. console.log('case Runeweaving');
  888. let do_click = true;
  889. let popup_query = '#wrapper > div.contents > div.pop-usual.pop-ability-mark > div.prt-popup-header';
  890. if (checkExist(popup_query,0)) {
  891. if (document.querySelector(popup_query).innerHTML == 'Use Skill'){
  892. clearInterval(loop_clickSkill);
  893. do_click = false;
  894. let error_special_case = true;
  895. let error_msg = 'Error skill: ';
  896. let q_invoke = '.lis-ability-mark';
  897. let q_rune = '>.lis-ability-frame';
  898.  
  899. const invoke = {'fire':'.mark1', 'water':'.mark2', 'earth':'.mark3', 'wind':'.mark4'};
  900.  
  901. if (abi_special_case === false){
  902. error_msg = 'abi_special_case is false.';
  903. } else {
  904. if (typeof abi_special_case === 'object') {
  905. if (abi_special_case.hasOwnProperty('invoke')) {
  906. if (typeof abi_special_case.invoke === 'object') {
  907. if (abi_special_case.invoke.length === 2) {
  908. if (invoke.hasOwnProperty(abi_special_case.invoke[0]) && invoke.hasOwnProperty(abi_special_case.invoke[1])) {
  909. error_special_case = false;
  910. } else {
  911. error_msg = 'abi_special_case.invoke value is invalid.';
  912. }
  913. } else {
  914. error_msg = 'abi_special_case.invoke length is invalid.';
  915. }
  916. } else {
  917. error_msg = 'abi_special_case.invoke type is invalid.';
  918. }
  919. }
  920. } else {
  921. error_msg = 'abi_special_case object \'invoke\' not found.';
  922. }
  923. }
  924. console.log('error_special_case: '+error_special_case);
  925. console.log(error_msg);
  926. if (error_special_case) {
  927. let cmd = [];
  928. cmd.push({"cmd":"log","level":"notif","msg":my_profile+error_msg+discord_mention});
  929. xhr.open('POST', server);
  930. xhr.send(JSON.stringify(cmd));
  931. } else {
  932. let q_next_rune;
  933. if (abi_special_case.invoke[0] === abi_special_case.invoke[1]) {
  934. q_next_rune = '.first.second';
  935. } else {
  936. q_next_rune = '.second:not(.first)';
  937. }
  938. let q_cast = '#wrapper > div.contents > div.pop-usual.pop-ability-mark > div.prt-popup-footer > div.btn-usual-text';
  939. let click_cast = function () {clickAndNegCheck(q_cast,0,my_profile+'Clicking cast',callback);};
  940. let next_rune = function () {clickAndCheck(q_invoke+invoke[abi_special_case.invoke[1]]+q_rune,0,q_invoke+invoke[abi_special_case.invoke[1]]+q_next_rune,0,my_profile+'Clicking second rune: '+abi_special_case.invoke[1],click_cast);};
  941. clickAndCheck(q_invoke+invoke[abi_special_case.invoke[0]]+q_rune,0,q_invoke+invoke[abi_special_case.invoke[0]]+'.first:not(.second)',0,my_profile+'Clicking first rune: '+abi_special_case.invoke[0],next_rune);
  942. }
  943. }
  944. }
  945. if (do_click) {
  946. if (checkExist(query,qid)) {
  947. clickNow(query,qid,msg);
  948. }
  949. }
  950. // // Bea skill
  951. // }else if(special_case===1 && document.querySelectorAll(query)[qid].parentNode.classList[0] != old_class){
  952. // clearInterval(loop_clickAndCheckSkill);
  953. // console.log(clickAndCheckSkill.name + " case " + special_case.toString());
  954. // if (typeof callback == "function") {
  955. // callback();
  956. // }
  957.  
  958. // // Out of sight & sage of eternity
  959. // }else if(special_case===2){
  960. // let do_click = true;
  961. // console.log(clickAndCheckSkill.name + " case " + special_case.toString());
  962. // let popup_query = "#wrapper > div.contents > div.pop-usual.pop-select-member > div.prt-popup-header";
  963. // if (checkExist(popup_query,0)) {
  964. // if (document.querySelector("#wrapper > div.contents > div.pop-usual.pop-select-member > div.prt-popup-header").innerHTML == "Use Skill"){
  965. // clearInterval(loop_clickAndCheckSkill);
  966. // do_click = false;
  967. // if (typeof callback == "function") {
  968. // callback();
  969. // }
  970. // }
  971. // }
  972. // if (do_click) {
  973. // if (checkExist(query,qid)) {
  974. // clickNow(query,qid,msg);
  975. // }
  976. // }
  977. } else {
  978. console.log('case normal not cooldown yet');
  979. if (checkExist(query,qid)) {
  980. clickNow(query,qid,msg);
  981. }
  982. }
  983.  
  984. }, 500);
  985. }
  986.  
  987.  
  988.  
  989. function useSkills(cid, skill_list, callback=false) {
  990. let char_id = battle.formation.indexOf(cid.toString())+1;
  991. console.log(useSkills.name);
  992. if (skill_list.length>0) {
  993. console.log(useSkills.name + ", cid: "+cid+", ability: " + (skill_list[0].toString()));
  994. let new_skill_list = Object.values(skill_list);
  995. new_skill_list.splice(0,1);
  996. let abi_id = parseInt(skill_list[0])-1;
  997. let next_skill = function(){useSkills(cid, new_skill_list, callback);};
  998. 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){
  999. // 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);
  1000. clickSkill(cid,abi_id,next_skill);
  1001. }else{
  1002. if (typeof callback == "function") {
  1003. next_skill();
  1004. }
  1005. }
  1006. } else {
  1007. if (typeof callback == "function") {
  1008. callback();
  1009. }
  1010. }
  1011. }
  1012.  
  1013. function usePot(pot_type, cid=false, callback=false) {
  1014. console.log(usePot.name);
  1015. console.log(cid);
  1016. let do_click_heal = false;
  1017. let front_cid = false;
  1018. let player_stats = {
  1019. 'need_heal': [],
  1020. 'front_need_heal': [],
  1021. 'need_clear': [],
  1022. 'need_revive': [],
  1023. };
  1024. for (const i in battle.player.param) {
  1025. if (battle.player.param.hasOwnProperty(i)) {
  1026. const player_obj = battle.player.param[i];
  1027. player_stats.need_revive.push(player_obj.alive === 1);
  1028. let player_need_clear = false;
  1029. if (player_obj.alive === 1) {
  1030. player_stats.need_heal.push(player_obj.hpmax - player_obj.hp !== 0);
  1031. if (player_obj.hasOwnProperty('condition')) {
  1032. if (player_obj.condition.hasOwnProperty('debuff')) {
  1033. if (player_obj.condition.debuff.length > 0) {
  1034. player_need_clear = true;
  1035. }
  1036. }
  1037. }
  1038. } else {
  1039. player_stats.need_heal.push(false);
  1040. }
  1041. player_stats.need_clear.push(player_need_clear);
  1042. }
  1043. }
  1044.  
  1045. for (const i in battle.formation) {
  1046. if (battle.formation.hasOwnProperty(i)) {
  1047. const front_id = parseInt(battle.formation[i]);
  1048. if (cid===front_id) {
  1049. front_cid = i;
  1050. }
  1051. player_stats.front_need_heal.push(battle.player.param[front_id].hpmax - battle.player.param[front_id].hp !== 0);
  1052. }
  1053. }
  1054. console.log('front_cid: '+front_cid);
  1055. console.log('player_stats: ');
  1056. console.log(player_stats);
  1057. if (pot_type==='Clarity Herb') {
  1058. if (battle.hasOwnProperty('event')) {
  1059. let item_obj = Object.values(battle.event.item).find(x => x.name === pot_type);
  1060. if (item_obj !== undefined) {
  1061. if (item_obj.number > 0 && front_cid !== false && player_stats.front_need_heal[front_cid]) {
  1062. do_click_heal = true;
  1063. }
  1064. }
  1065. }
  1066. } else if (pot_type==='Green Potion') {
  1067. if (battle.hasOwnProperty('temporary')) {
  1068. if (battle.temporary.hasOwnProperty('small')) {
  1069. let item_obj = parseInt(battle.temporary.small);
  1070. console.log('item_obj');
  1071. console.log(item_obj);
  1072. if (item_obj !== undefined) {
  1073. if (item_obj > 0 && front_cid !== false && player_stats.front_need_heal[front_cid]) {
  1074. do_click_heal = true;
  1075. }
  1076. }
  1077. }
  1078. }
  1079. } else if (pot_type==='Blue Potion') {
  1080. if (battle.hasOwnProperty('temporary')) {
  1081. if (battle.temporary.hasOwnProperty('large')) {
  1082. let item_obj = parseInt(battle.temporary.large);
  1083. console.log('item_obj');
  1084. console.log(item_obj);
  1085. if (item_obj !== undefined) {
  1086. if (item_obj > 0 && player_stats.front_need_heal.indexOf(true)>=0) {
  1087. do_click_heal = true;
  1088. }
  1089. }
  1090. }
  1091. }
  1092. }
  1093. console.log('do_click_heal:');
  1094. console.log(do_click_heal);
  1095.  
  1096. let clickCancel = function() {
  1097. clickAndNegCheck(query.battle_ui.heal_pop_up.cancel,0,my_profile+"Clicking cancel from pot pop up",callback);
  1098. };
  1099.  
  1100. let clickUse = function() {
  1101. clickAndNegCheck(query.battle_ui.heal_pop_up.use,0,my_profile+"Clicking use from pot pop up",callback);
  1102. };
  1103. let clickFront = function() {
  1104. clickAndCheck(query.battle_ui.char_ico,front_cid,query.battle_ui.summon_panel+":not(.mask-black)",0,my_profile+"Clicking char_ico from pot pop up",callback);
  1105. };
  1106.  
  1107. let clickPot = function() {
  1108. console.log(clickPot.name);
  1109. let query_qty = ">.txt-having>.having-num";
  1110. let pot_available = false;
  1111. let init_clickPot = function () {
  1112. if (checkExist(query.battle_ui.heal_pop_up[pot_type]+query_qty)) {
  1113. if ( parseInt(document.querySelector(query.battle_ui.heal_pop_up[pot_type]+query_qty).innerHTML) > 0 ) {
  1114. pot_available = true;
  1115. if (pot_type == 'Blue Potion') {
  1116. clickAndNegCheck(query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking "+ pot_type +" pot",clickUse);
  1117. }else if (pot_type == 'Green Potion') {
  1118. clickAndNegCheck(query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking "+ pot_type +" pot",clickFront);
  1119. }else if (pot_type == 'Clarity Herb') {
  1120. clickAndNegCheck(query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking "+ pot_type +" pot",clickFront);
  1121. }else{
  1122. console.log("pot_type unknown");
  1123. clickCancel();
  1124. }
  1125. }
  1126. // console.log("pot qty not > 0");
  1127. // clickCancel();
  1128. // }
  1129. // }else{
  1130. // console.log("element not exist");
  1131. // clickCancel();
  1132. }
  1133. if (!pot_available) {
  1134. clickCancel();
  1135. }
  1136. };
  1137. checkEl(query.battle_ui.heal_pop_up[pot_type]+">img",0,init_clickPot);
  1138. };
  1139. if (do_click_heal) {
  1140. clickAndCheck(query.battle_ui.heal,0,query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking heal pop up",clickPot);
  1141. } else {
  1142. if (typeof callback == "function") {
  1143. callback();
  1144. }
  1145. }
  1146.  
  1147. }
  1148.  
  1149. function usePots(pot_type,list_cid=[],callback=false) {
  1150. console.log('usePots');
  1151. console.log('pot_type');
  1152. console.log(pot_type);
  1153. console.log('list_cid');
  1154. console.log(list_cid);
  1155. if (list_cid > 0) {
  1156. let new_list_cid = Object.values(list_cid);
  1157. new_list_cid.splice(0,1);
  1158. let next_clear = function(){usePots(pot_type,new_list_cid, callback);};
  1159. usePot(pot_type,parseInt(list_cid[0]),next_clear);
  1160. } else {
  1161. if (typeof callback == "function") {
  1162. callback();
  1163. }
  1164. }
  1165. }
  1166.  
  1167. // function usePot (pot_type,char_id=false,callback=false) {
  1168. // // console.log(usePot.name);
  1169. // let is_front_healable = [];
  1170. // let is_player_reviveable = [];
  1171. // let is_player_healable = [];
  1172. // for (const i in battle.player.param) {
  1173. // if (battle.player.param.hasOwnProperty(i)) {
  1174. // if (battle.player.param[i].alive === 1) {
  1175. // is_player_reviveable.push(false);
  1176. // is_player_healable.push(battle.player.param[i].hpmax - battle.player.param[i].hp !== 0);
  1177. // }else{
  1178. // is_player_reviveable.push(true);
  1179. // is_player_healable.push(false);
  1180. // }
  1181. // }
  1182. // }
  1183. // for (const i in rep.formation) {
  1184. // if (rep.formation.hasOwnProperty(i)) {
  1185. // const alive_id = parseInt(rep.formation[i]);
  1186. // is_front_healable.push(battle.player.param[alive_id].hpmax - battle.player.param[alive_id].hp !== 0);
  1187. // }
  1188. // }
  1189. // let query_qty = ">.txt-having>.having-num";
  1190. // let clickUse = function() {
  1191. // clickAndNegCheck(query.battle_ui.heal_pop_up.use,0,my_profile+"Clicking use from pot pop up",callback);
  1192. // };
  1193. // let clickFront = function() {
  1194. // 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);
  1195. // };
  1196. // let clickCancel = function() {
  1197. // clickAndNegCheck(query.battle_ui.heal_pop_up.cancel,0,my_profile+"Clicking cancel from pot pop up",callback);
  1198. // };
  1199. // let clickPot = function() {
  1200. // console.log(clickPot.name);
  1201. // if (checkExist(query.battle_ui.heal_pop_up[pot_type]+query_qty)) {
  1202. // if ( parseInt(document.querySelector(query.battle_ui.heal_pop_up[pot_type]+query_qty).innerHTML) > 0 ) {
  1203. // if (pot_type == "blue") {
  1204. // clickAndNegCheck(query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking "+ pot_type +" pot",clickUse);
  1205. // }else if (pot_type == "green") {
  1206. // clickAndNegCheck(query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking "+ pot_type +" pot",clickFront);
  1207. // }else{
  1208. // console.log("pot_type unknown");
  1209. // clickCancel();
  1210. // }
  1211. // }else{
  1212. // console.log("pot qty not > 0");
  1213. // clickCancel();
  1214. // }
  1215. // }else{
  1216. // console.log("element not exist");
  1217. // clickCancel();
  1218. // }
  1219. // };
  1220. // let clickHeal = function() {
  1221. // console.log(clickHeal.name);
  1222. // clickAndCheck(query.battle_ui.heal,0,query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking heal pop up",clickPot,20);
  1223. // };
  1224. // let do_heal = false;
  1225. // if (pot_type=="blue" && is_front_healable.indexOf(true)>=0) {
  1226. // do_heal = true;
  1227. // }else if (pot_type=="green" && is_player_healable[char_id]) {
  1228. // do_heal = true;
  1229. // }else{
  1230. // if (typeof callback == "function") {
  1231. // callback();
  1232. // }
  1233. // }
  1234. // if (do_heal) {
  1235. // checkEl(query.battle_ui.heal,0,clickHeal);
  1236. // }
  1237. // }
  1238.  
  1239. function clickBackup(callback=false) {
  1240. let check_backup = function() {
  1241. let el_btn, backup_msg;
  1242. if (Array.from(document.querySelector(query.battle_ui.backup_pop_up.request).classList).indexOf("disable") >= 0) {
  1243. el_btn = query.battle_ui.backup_pop_up.cancel;
  1244. backup_msg = "cancel";
  1245. } else {
  1246. el_btn = query.battle_ui.backup_pop_up.request;
  1247. backup_msg = "request";
  1248. }
  1249. clickAndNegCheck(el_btn,0,my_profile+"Clicking "+backup_msg,callback,10);
  1250. };
  1251. clickAndCheck(query.battle_ui.button.assist,0,query.battle_ui.backup_pop_up.request,0,my_profile+"Clicking backup",check_backup,10);
  1252. }
  1253.  
  1254. function clickBack(callback=false){
  1255. clickAndCheck(".btn-command-back.display-on",0,"div.prt-member",0,my_profile+"Clicking back",callback,10);
  1256. }
  1257.  
  1258. function clickSummonPanel(callback=false){
  1259. console.log(clickSummonPanel.name);
  1260. let query1 = ".prt-list-top.btn-command-summon.summon-on";
  1261. let query2 = ".prt-summon-list.opened";
  1262. let query3 = ".prt-list-top.btn-command-summon.summon-off";
  1263. let qid1 = 0, qid2 = 0, qid3 = 0;
  1264. let msg = my_profile+"Clicking summon panel";
  1265. let old_top = -1;
  1266. let old_left = -1;
  1267. let loop_clickAndCheck = setInterval(function() {
  1268. console.log(clickAndCheck.name + ", check: " + query2 + "["+(qid2.toString())+"], click: " + query1 + "["+(qid1.toString())+"]");
  1269. if (checkExist(query2,qid2) || checkExist(query3,qid3)) {
  1270. clearInterval(loop_clickAndCheck);
  1271. if (typeof callback == "function") {
  1272. callback();
  1273. }
  1274. }else{
  1275. if (checkExist(query1,qid1)) {
  1276. if (old_top==document.querySelectorAll(query1)[qid1].getBoundingClientRect().top && old_left==document.querySelectorAll(query1)[qid1].getBoundingClientRect().left) {
  1277. clickNow(query1,qid1,msg);
  1278. }else{
  1279. old_top = document.querySelectorAll(query1)[qid1].getBoundingClientRect().top;
  1280. old_left = document.querySelectorAll(query1)[qid1].getBoundingClientRect().left;
  1281. }
  1282. }
  1283. }
  1284. }, 200);
  1285. }
  1286.  
  1287. function clickSummon(summon_id,callback1=false,callback2=false){
  1288. console.log(clickSummon.name);
  1289. summon_id = summon_id-1;
  1290. if (Array.from(document.querySelectorAll(".lis-summon")[summon_id].classList).indexOf("btn-summon-available")>=0){
  1291. let loop_clickSummon = setInterval(function() {
  1292. if (document.querySelectorAll(".lis-summon>img")[summon_id].getBoundingClientRect().x === document.querySelectorAll(".lis-summon>img")[0].getBoundingClientRect().x + (summon_id * (document.querySelectorAll(".lis-summon>img")[0].getBoundingClientRect().width+2))){
  1293. clearInterval(loop_clickSummon);
  1294. let q_img = '.lis-summon>img';
  1295. let q_skin = '#wrapper > div.contents > div.cnt-raid > div.prt-command > div.prt-command-summon.summon-show > div > div.lis-summon.is-skin.on.btn-summon-available > div.prt-summon-skin > img';
  1296. if (summon_id == 0) {
  1297. if (checkExist(q_skin,0)) {
  1298. q_img = q_skin;
  1299. }
  1300. }
  1301. clickAndCheck(q_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);
  1302. }
  1303. }, 300);
  1304. }else{
  1305. if (typeof callback2 == "function") {
  1306. callback2();
  1307. }
  1308. }
  1309. }
  1310.  
  1311. function clickOkSummon(callback=false){
  1312. console.log(clickOkSummon.name);
  1313. let el_ok = ".pop-usual.pop-summon-detail>div>.btn-usual-ok.btn-summon-use";
  1314. if (document.querySelector(el_ok) !== null){
  1315. clickAndCheck(el_ok,0,"div.prt-member",0,my_profile+"Clicking summon ok",callback);
  1316. }else{
  1317. if (typeof callback == "function") {
  1318. callback();
  1319. }
  1320. }
  1321. }
  1322. function clickOkSummon2(summon_id,callback=false){
  1323. let el_ok = ".pop-usual.pop-summon-detail>div>.btn-usual-ok.btn-summon-use";
  1324. let summon_el = '.lis-summon[pos="'+(summon_id.toString())+'"]';
  1325. if (document.querySelector(el_ok) !== null){
  1326. let loop_clickOkSummon2 = setInterval(function() {
  1327. console.log(clickOkSummon2.name + ", click: " + el_ok + "[0]");
  1328. if (Array.from(document.querySelector(summon_el).classList).indexOf("tmp-mask")>=0 || Array.from(document.querySelector(summon_el).classList).indexOf("btn-summon-unavailable")>=0) {
  1329. clearInterval(loop_clickOkSummon2);
  1330. if (typeof callback == "function") {
  1331. callback();
  1332. }
  1333. }else{
  1334. if (checkExist(el_ok,0)) {
  1335. clickNow(el_ok,0,my_profile+"Clicking summon ok2");
  1336. }
  1337. }
  1338. }, 1000);
  1339. }else{
  1340. if (typeof callback == "function") {
  1341. callback();
  1342. }
  1343. }
  1344. }
  1345.  
  1346. function selectSummon(preferred_summon,is_trial=false){
  1347. reload(20);
  1348.  
  1349. let init_selectSummon = function() {
  1350. console.log(init_selectSummon.name);
  1351. reload(10);
  1352. const attrib_list = [6,0,1,2,3,4,5];
  1353. let query_summon_list = ".btn-supporter.lis-supporter";
  1354. let el_summon_list = document.querySelectorAll(query_summon_list);
  1355. let preferred_summon_id = false;
  1356. let picked_attrib_id = false;
  1357. let picked_summon_id = false;
  1358. let picked_is_friend = false;
  1359. let is_friend;
  1360. let picked_summon_stars = false;
  1361. let picked_summon_level = false;
  1362. let picked_summon_plus = false;
  1363. let msg;
  1364. let cmd = [], summon_list = {};
  1365. 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){
  1366. msg = my_profile+"Verify not appear, summon list length is "+(el_summon_list.length.toString());
  1367. console.log(msg);
  1368.  
  1369. // check if raid is trial
  1370. if (!is_trial){
  1371. console.log("not trial");
  1372. for (let i = 0; i < el_summon_list.length; i++) {
  1373. let match_preferred = false, replace = false;
  1374. let temp_var, summon_detail, summon_name, summon_level, summon_stars, summon_plus;
  1375. temp_var = el_summon_list[i].querySelector(".prt-supporter-summon");
  1376. summon_detail = temp_var.innerHTML.trim();
  1377. temp_var = el_summon_list[i].querySelector(".prt-supporter-summon");
  1378. summon_detail = temp_var.innerHTML.trim();
  1379. summon_name = summon_detail.substring(summon_detail.indexOf("</span>")+8,summon_detail.length);
  1380. summon_level = parseInt(temp_var.children[0].innerHTML.replace("Lvl ",""));
  1381. temp_var = Array.from(el_summon_list[i].querySelector(".prt-summon-skill").classList);
  1382. if (temp_var.indexOf("bless-rank3-style")>=0){
  1383. summon_stars = 5;
  1384. }else if (temp_var.indexOf("bless-rank2-style")>=0){
  1385. summon_stars = 4;
  1386. }else if (temp_var.indexOf("bless-rank1-style")>=0){
  1387. summon_stars = 3;
  1388. }else{
  1389. summon_stars = 0;
  1390. }
  1391. temp_var = el_summon_list[i].querySelector(".prt-summon-quality");
  1392. if (temp_var !== null){
  1393. summon_plus = parseInt(temp_var.innerHTML.replace("+",""));
  1394. }else{
  1395. summon_plus = 0;
  1396. }
  1397. temp_var = false;
  1398. is_friend = Array.from(el_summon_list[i].querySelector(".prt-supporter-name").classList).indexOf("ico-friend")>=0;
  1399.  
  1400. // loop preferred summon list (specified in parameter)
  1401. for (let j = 0; j < preferred_summon.length; j++) {
  1402. if (preferred_summon[j].name==summon_name && preferred_summon[j].star<=summon_stars){
  1403. match_preferred = true;
  1404. temp_var = j;
  1405. }
  1406. }
  1407.  
  1408.  
  1409. if (match_preferred){
  1410. if (picked_attrib_id===false && picked_summon_id===false){
  1411. replace = true;
  1412. }else{
  1413. if (preferred_summon_id>temp_var){
  1414. replace = true;
  1415. }else if(preferred_summon_id==temp_var){
  1416. if (summon_stars>picked_summon_stars){
  1417. replace = true;
  1418. }else if(summon_stars==picked_summon_stars){
  1419. if (!picked_is_friend && is_friend){
  1420. replace = true;
  1421. }else if(picked_is_friend && is_friend){
  1422. if (summon_level>picked_summon_level){
  1423. replace = true;
  1424. }else if(summon_level==picked_summon_level){
  1425. if (summon_plus>picked_summon_plus){
  1426. replace = true;
  1427. }
  1428. }
  1429. }
  1430. }
  1431. }
  1432. }
  1433. }
  1434. if (replace){
  1435. picked_attrib_id = Array.from(document.querySelectorAll(".prt-supporter-attribute")).indexOf(el_summon_list[i].parentElement);
  1436. picked_summon_id = i;
  1437. preferred_summon_id = temp_var;
  1438. picked_summon_stars = summon_stars;
  1439. picked_is_friend = is_friend;
  1440. picked_summon_level = summon_level;
  1441. picked_summon_plus = summon_plus;
  1442. }
  1443. }
  1444. console.log([picked_attrib_id,picked_summon_id,preferred_summon_id]);
  1445. if (picked_summon_id===false){
  1446. console.log("go to trial");
  1447. cmd.push({"cmd":"log","level":"process","msg":message.summon.not_found});
  1448. xhr.open("POST", server);
  1449. xhr.send(JSON.stringify(cmd));
  1450. gotoHash("trial");
  1451. }else{
  1452. console.log("summon_found");
  1453. let pickSummon = function() {
  1454. scroll_To(query_summon_list,picked_summon_id);
  1455. clickEl(query_summon_list,picked_summon_id,message.summon.select);
  1456. };
  1457. let clickAndCheckSummon = function(callback=false){
  1458. let el_tab_ele_ico = ".prt-type-text";
  1459. let el_summon_container = ".prt-supporter-attribute";
  1460. let loop_clickAndCheckSummon = setInterval(function() {
  1461. console.log(clickAndCheckSummon.name + ", check: " + el_summon_container + "[" + picked_attrib_id + "], click: " + el_tab_ele_ico + "["+(attrib_list[picked_attrib_id].toString())+"]");
  1462. if (Array.from(document.querySelectorAll(el_summon_container)[picked_attrib_id].classList).indexOf("disableView") == -1) {
  1463. clearInterval(loop_clickAndCheckSummon);
  1464. if (typeof callback == "function") {
  1465. callback();
  1466. }
  1467. }else{
  1468. if (checkExist(el_tab_ele_ico, attrib_list[picked_attrib_id])) {
  1469. clickNow(el_tab_ele_ico, attrib_list[picked_attrib_id], message.summon.pick_tab);
  1470. }
  1471. }
  1472. }, 300);
  1473. };
  1474. clickAndCheckSummon(pickSummon);
  1475. }
  1476. }else{
  1477. console.log("is trial");
  1478. query_summon_list = ".prt-supporter-attribute:not(.disableView)>.btn-supporter.lis-supporter";
  1479. el_summon_list = document.querySelectorAll(query_summon_list);
  1480. for (let i = 0; i < el_summon_list.length; i++) {
  1481. is_friend = Array.from(el_summon_list[i].querySelector(".prt-supporter-name").classList).indexOf("ico-friend")>=0;
  1482. if (!is_friend){
  1483. if (picked_summon_id===false){
  1484. picked_summon_id = i;
  1485. }
  1486. }
  1487. }
  1488. if (picked_summon_id!==false){
  1489. scroll_To(".prt-supporter-attribute:not(.disableView)>.btn-supporter.lis-supporter",picked_summon_id);
  1490. clickEl(".prt-supporter-attribute:not(.disableView)>.btn-supporter.lis-supporter",picked_summon_id,message.summon.select);
  1491. }
  1492. }
  1493. }else{
  1494. msg = my_profile+"Verify might appear, summon list length is "+(el_summon_list.length.toString());
  1495. clearInterval(reload_counter);
  1496. console.log(msg);
  1497. cmd.push({"cmd":"log","level":"process","msg":msg});
  1498. cmd.push({"cmd":"log","level":"notif","msg":msg});
  1499. xhr.open("POST", server);
  1500. xhr.send(JSON.stringify(cmd));
  1501. }
  1502. };
  1503. checkEl(".prt-supporter-title",0,init_selectSummon);
  1504. }
  1505.  
  1506. function doChat(callback=false) {
  1507. console.log(doChat.name);
  1508. let clickDialog = function() {
  1509. console.log(clickDialog.name);
  1510. clickAndNegCheck(query.battle_ui.chat_pop_up.dialog,0,my_profile+"Clicking chat dialog",callback);
  1511. };
  1512. let clickChat = function() {
  1513. console.log(clickChat.name);
  1514. if (checkExist(query.battle_ui.chat+">.ico-attention",0)) {
  1515. clickAndCheck(query.battle_ui.chat,0,query.battle_ui.chat_pop_up.dialog,0,my_profile+"Clicking chat pop up",clickDialog,20);
  1516. }else{
  1517. if (typeof callback == "function") {
  1518. callback();
  1519. }
  1520. }
  1521. };
  1522. checkEl(query.battle_ui.chat,0,clickChat);
  1523. }
  1524.  
  1525. function backFromTrial(){
  1526. let cmd = [];
  1527. cmd.push({"cmd":"log","level":"process","msg":message.raid.trial.end});
  1528. xhr.open("POST", server);
  1529. xhr.send(JSON.stringify(cmd));
  1530. gotoHash("main");
  1531. }
  1532.  
  1533. function gotoResult() {
  1534. console.log(gotoResult.name);
  1535. console.log(is_host);
  1536. if (is_host || window.location.hash.indexOf("#raid/")>=0) {
  1537. gotoHash("quest");
  1538. }else if (window.location.hash.indexOf("#raid_multi")>=0) {
  1539. reloadNow();
  1540. }
  1541. }
  1542.  
  1543. function attack(rep){
  1544. console.log(attack.name);
  1545. let cmd = [];
  1546. let reps = rep.scenario;
  1547. let win = false;
  1548. let is_last_raid = false;
  1549. let ougi = 0;
  1550. let msg = "";
  1551. for (let i = 0; i < reps.length; i++) {
  1552. if (reps[i].cmd =="win"){
  1553. if (reps[i].is_last_raid){is_last_raid=true;}
  1554. win=true;
  1555. }else if (reps[i].cmd=="special" || reps[i].cmd=="special_npc"){
  1556. const char_name = battle.player.param[parseInt(battle.formation[reps[i].pos])].name;
  1557. msg += my_profile+char_name+" used ougi \""+reps[i].name+"\".\n";
  1558. if (reps[i].total){msg += my_profile+char_name+" dealt "+reps[i].total[0].split.join("")+" damage.\n";}
  1559. ougi++;
  1560. }else if (reps[i].cmd=="attack" && reps[i].from=="player"){
  1561. const char_name = battle.player.param[parseInt(battle.formation[reps[i].pos])].name;
  1562. if (reps[i].damage.length==3){
  1563. msg += my_profile+char_name+" made a triple attack.\n";
  1564. }else if (reps[i].damage.length==2){
  1565. msg += my_profile+char_name+" made a double attack.\n";
  1566. }
  1567. msg += my_profile+char_name+ " dealt ";
  1568. for (let ii=0; ii<reps[i].damage.length; ii++){
  1569. msg += reps[i].damage[ii][0].value.toString();
  1570. if (ii<reps[i].damage.length-1){
  1571. msg += ", ";
  1572. }else{
  1573. msg += " damage.\n";
  1574. }
  1575. }
  1576. }
  1577. }
  1578.  
  1579. if(win){
  1580. cmd.push({"cmd":"log","level":"process","msg":msg+my_profile+"Foe defeated."});
  1581. }else{
  1582. cmd.push({"cmd":"log","level":"process","msg":msg+my_profile+"Foe is still alive."});
  1583. cmd.push({"cmd":"press","key":"f5"});
  1584. }
  1585. xhr.open('POST', server);
  1586. xhr.send(JSON.stringify(cmd));
  1587. if(win && is_last_raid){
  1588. gotoResult();
  1589. }else if(win){
  1590. clickEl(".btn-result",0,my_profile+"Go to next round");
  1591. }
  1592. }
  1593.  
  1594. function skillUsed(rep){
  1595. console.log(skillUsed.name);
  1596. let do_reload = false;
  1597. let reps = rep.scenario;
  1598. let win = false, is_last_raid = false;
  1599. console.log(reps);
  1600. for (let i = 0; i < reps.length; i++) {
  1601. const scenario = reps[i];
  1602. if (scenario.cmd =="ability"){
  1603. if (scenario.hasOwnProperty('name')) {
  1604. if (reloadable_skill.indexOf(scenario.name)>= 0) {
  1605. do_reload = true;
  1606. }
  1607. }
  1608. } else if (scenario.cmd =="damage") {
  1609. if (scenario.to == "player") {
  1610. for (let j = 0; j < scenario.list.length; j++) {
  1611. const s = scenario.list[j];
  1612. if (s.hp !== undefined && s.pos !== undefined) {
  1613. battle.player.param[s.pos].hp = s.hp;
  1614. }
  1615. }
  1616. }
  1617. }else if (scenario.cmd =="finished"){
  1618. win=true;
  1619. is_last_raid=true;
  1620. }else if (scenario.cmd == "win"){
  1621. if (scenario.is_last_raid) {
  1622. is_last_raid=true;
  1623. }
  1624. win=true;
  1625. }
  1626. }
  1627. if(win && is_last_raid){
  1628. gotoResult();
  1629. }else if (win && !is_last_raid) {
  1630. clickEl(".btn-result",0,my_profile+"Go to next round");
  1631. }else if(do_reload){
  1632. reloadNow();
  1633. }
  1634. }
  1635.  
  1636. function summonUsed(rep){
  1637. console.log(summonUsed.name);
  1638. let do_reload = false;
  1639. let reps = rep.scenario;
  1640. let win = false,
  1641. is_last_raid = false;
  1642. for (let i = 0; i < reps.length; i++) {
  1643. const scenario = reps[i];
  1644. if (scenario.cmd == 'ability'){
  1645. if (scenario.hasOwnProperty('name')) {
  1646. if (reloadable_summon.indexOf(scenario.name)>= 0) {
  1647. do_reload = true;
  1648. }
  1649. }
  1650. } else if (scenario.cmd == "finished"){
  1651. win=true;
  1652. is_last_raid=true;
  1653. } else if (scenario.cmd == "win"){
  1654. if (scenario.is_last_raid){
  1655. is_last_raid=true;
  1656. }
  1657. win=true;
  1658. }
  1659. }
  1660. if (battle.lyria_pos >= 0) {
  1661. do_reload = true;
  1662. }
  1663. if(win && is_last_raid){
  1664. gotoResult();
  1665. }else if(do_reload){
  1666. reloadNow();
  1667. }
  1668. }
  1669.  
  1670. function potUsed(rep) {
  1671. console.log(potUsed.name);
  1672. let reps = rep.scenario;
  1673. for (let i = 0; i < reps.length; i++) {
  1674. const scenario = reps[i];
  1675. if (scenario.cmd == "heal") {
  1676. for (let j = 0; j < scenario.list.length; j++) {
  1677. const s = scenario.list[j];
  1678. if (s.hp !== undefined && s.pos !== undefined) {
  1679. battle.player.param[s.pos].hp = s.hp;
  1680. }
  1681. }
  1682. }
  1683. }
  1684. }
  1685.  
  1686.  
  1687. function clickAttack(callback=false) {
  1688. let hp = ((parseInt(battle.boss.param[0].hp) / parseInt(battle.boss.param[0].hpmax)) * 100).toString();
  1689. if (hp.indexOf(".")>=0){
  1690. hp = hp.substring(0,hp.indexOf("."));
  1691. }
  1692. console.log(hp);
  1693. let attack_msg = my_profile+"Foe hp is "+hp+"% left, commencing attack";
  1694. clickAndCheck(".btn-attack-start.display-on",0,".btn-attack-cancel.btn-cancel.display-on",0,attack_msg,callback,20);
  1695. }
  1696.  
  1697. function charMoveSet(cid,skill_list,callback) {
  1698. if (!(Number.isInteger(cid))) {
  1699. cid = battle.player.param.findIndex(x => x.name === cid);
  1700. }
  1701. console.log(charMoveSet.name + ': ' + cid);
  1702. let char = battle.player.param[cid];
  1703. console.log(char.name);
  1704. console.log('skill_list:');
  1705. console.log(skill_list);
  1706. if (char !== undefined) {
  1707. console.log(charMoveSet.name + ': ' + char.name + ', debug: 1');
  1708. let char_in_front = false;
  1709. let can_use_skill = true;
  1710. if (battle.formation.indexOf(cid.toString()) >= 0) {
  1711. console.log(charMoveSet.name + ': ' + char.name + ', debug: 2');
  1712. char_in_front = true;
  1713. }
  1714. console.log(charMoveSet.name + ': ' + char.name + ', debug: 3');
  1715. console.log(battle.formation);
  1716. if (char_in_front && char.alive === 1) {
  1717. console.log(charMoveSet.name + ': ' + char.name + ', debug: 4');
  1718. if (skill_list.length>0) {
  1719. console.log(charMoveSet.name + ': ' + char.name + ', debug: 5');
  1720. let new_skill_list = Object.values(skill_list);
  1721. for (let i = 0; i < skill_list.length; i++) {
  1722. const skill = skill_list[i];
  1723. if (document.querySelector(query.battle_ui.skill['char'+(battle.formation.indexOf(cid.toString())+1).toString()]['skill'+(skill.toString())]).attributes.state.value != "2") {
  1724. new_skill_list.splice(new_skill_list.indexOf(skill),1);
  1725. }
  1726. }
  1727. console.log(charMoveSet.name + ': ' + char.name + ', debug: 6');
  1728. skill_list = new_skill_list;
  1729. if ("debuff" in char.condition) {
  1730. console.log(charMoveSet.name + ': ' + char.name + ', debug: 7');
  1731. for (let i = 0; i < char.condition.debuff.length; i++) {
  1732. const debuff = char.condition.debuff[i];
  1733. if (debuff.status == "1111" || debuff.status == "1102") {
  1734. can_use_skill = false;
  1735. }
  1736. // 1102
  1737. }
  1738. }
  1739. }
  1740. }
  1741. console.log(charMoveSet.name + ': ' + char.name + ', debug: 8');
  1742. if (char_in_front && char.alive===1 && skill_list.length>0 && can_use_skill) {
  1743. console.log(charMoveSet.name + ': ' + char.name + ', debug: 9');
  1744. let click_back = function(){clickBack(callback);};
  1745. let use_skills = function(){useSkills(cid,skill_list,click_back);};
  1746. let click_char = function(){clickChar(cid,use_skills);};
  1747. click_char();
  1748. } else {
  1749. console.log(charMoveSet.name + ': ' + char.name + ', debug: 10');
  1750. if (typeof callback == "function") {
  1751. console.log(charMoveSet.name + ': ' + char.name + ', debug: 11');
  1752. callback();
  1753. }
  1754. }
  1755. } else {
  1756. console.log(charMoveSet.name + ': ' + char.name + ', debug: 12');
  1757. if (typeof callback == "function") {
  1758. console.log(charMoveSet.name + ': ' + char.name + ', debug: 13');
  1759. callback();
  1760. }
  1761. }
  1762. }
  1763.  
  1764.  
  1765. function toggleOugi(ougi, callback=false) {
  1766. let init_toggleOugi = function() {
  1767. let current_ougi = "."+document.querySelector(query.battle_ui.ougi).classList[1];
  1768. if (query.battle_ui.toggle_ougi[ougi] != current_ougi){
  1769. 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);
  1770. }else{
  1771. if (typeof callback == "function") {
  1772. callback();
  1773. }
  1774. }
  1775. };
  1776. checkEl(query.battle_ui.ougi,0,init_toggleOugi);
  1777. }
  1778.  
  1779. function summoning(summon_id,callback=false) {
  1780. console.log(summoning.name);
  1781. let summon_cd;
  1782. if (summon_id === 5) {
  1783. summon_cd = battle.supporter.recast;
  1784. } else if (battle.summon[summon_id] !== undefined) {
  1785. summon_cd = battle.summon[summon_id].recast;
  1786. }
  1787. if (summon_cd === "0") {
  1788. let summon_ok = function(){clickOkSummon(callback);};
  1789. let summon = function(){clickSummon(summon_id+1,summon_ok,callback);};
  1790. let summon_p = function(){clickSummonPanel(summon);};
  1791. summon_p();
  1792. } else {
  1793. if (typeof callback == "function") {
  1794. callback();
  1795. }
  1796. }
  1797. }
  1798.  
  1799. function pickUnclaimedRaid(rep) {
  1800. if (rep.count > 0) {
  1801. let el_raid = ".prt-raid-info";
  1802. let init_pickUnlaimedRaid = function() {
  1803. gotoHash(rep.list[0].href);
  1804. };
  1805. checkEl(el_raid,0,init_pickUnlaimedRaid);
  1806. }else{
  1807. gotoHash('main');
  1808. }
  1809. }
  1810.  
  1811. let battleLogic = function(case_battle) {
  1812. console.log(battleLogic.name);
  1813. console.log('case_battle:');
  1814. console.log(case_battle);
  1815. clearInterval(reload_counter);
  1816. };
  1817.  
  1818. function startRaid(rep){
  1819. reload(15);
  1820. battle = rep;
  1821. is_host = rep.is_host;
  1822. for (let i = 0; i < battle.player.param.length; i++) {
  1823. const c = battle.player.param[i];
  1824. if (c.alive === 1) {
  1825. is_wiped = false;
  1826. }
  1827. }
  1828.  
  1829. let check_exist = setInterval(function() {
  1830. console.log("querying enemy name to appear");
  1831. 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){
  1832. console.log("check width enemy name");
  1833. 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){
  1834. console.log("found enemy name");
  1835. clearInterval(check_exist);
  1836. let is_quest_id_valid = false;
  1837. let is_twitter_valid = false;
  1838. try{
  1839. console.log(rep.quest_id);
  1840. if (rep.quest_id!==undefined) {
  1841. is_quest_id_valid = true;
  1842. }
  1843. }
  1844. catch(err){
  1845. console.log(err.message);
  1846. }
  1847. console.log("is_quest_id_valid:" +(is_quest_id_valid).toString());
  1848. try{
  1849. console.log(rep.twitter.monster);
  1850. if (rep.twitter.monster!==undefined) {
  1851. is_twitter_valid = true;
  1852. }
  1853. }
  1854. catch(err){
  1855. console.log(err.message);
  1856. }
  1857. console.log("is_twitter_valid:" +(is_twitter_valid).toString());
  1858. let case_battle = false;
  1859. if (is_quest_id_valid){
  1860. if (battle.is_trialbattle) {
  1861. case_battle = 99;
  1862. }else{
  1863. for (let i in quests_id) {
  1864. if (rep.quest_id == quests_id[i] && case_battle === false) {
  1865. case_battle = parseInt(i)+1;
  1866. }
  1867. }
  1868. }
  1869. }
  1870. if (case_battle === false && is_twitter_valid){
  1871. for (let i in monsters_name) {
  1872. if (rep.twitter.monster==monsters_name[i] && case_battle === false) {
  1873. case_battle = parseInt(i)+1;
  1874. }
  1875. }
  1876. }
  1877. console.log("case_battle:" + case_battle.toString());
  1878. let hp = ((parseInt(rep.boss.param[0].hp) / parseInt(rep.boss.param[0].hpmax)) * 100).toString();
  1879. if (hp.indexOf(".")>=0){
  1880. hp = hp.substring(0,hp.indexOf("."));
  1881. }
  1882. battleLogic(case_battle);
  1883. }
  1884. }
  1885. }, 300);
  1886. }
  1887.  
  1888. function clickChar(cid,callback=false) {
  1889. let front_id = battle.formation.indexOf(cid.toString())+1;
  1890. clickAndCheck("div.prt-member>div.btn-command-character>img.img-chara-command",front_id-1,".prt-command-chara.chara"+(front_id.toString()),0,my_profile+"Clicking "+battle.player.param[cid].name,callback);
  1891. }
  1892.  
  1893. function clickBoss(boss_id,callback=false) {
  1894. const boss_id_str = (boss_id+1).toString();
  1895. if (battle.boss.param[boss_id] !== undefined || battle.boss.param[boss_id].alive === 1) {
  1896. clickAndCheck('.enemy-info>.name',boss_id,'.btn-targeting.enemy-'+boss_id_str+'.lock-on',0,my_profile+'Clicking Boss '+boss_id_str,callback);
  1897. } else {
  1898. if (typeof callback == "function") {
  1899. callback();
  1900. }
  1901. }
  1902. }
  1903.  
  1904. function raidFinish(rep,send_all_loot=false){
  1905. console.log(raidFinish.name);
  1906. reload(10);
  1907. let cmd = [];
  1908. let tracked_loot = [];
  1909. let check_timer = true;
  1910. cmd.push({"cmd":"log","level":"process","msg":message.raid.finish});
  1911.  
  1912. let all_loot = {};
  1913. let important_loot = {};
  1914. for (const i in rep.rewards.reward_list) {
  1915. if (rep.rewards.reward_list.hasOwnProperty(i)) {
  1916. const loots = rep.rewards.reward_list[i];
  1917. for (const j in loots) {
  1918. if (loots.hasOwnProperty(j)) {
  1919. const loot = loots[j];
  1920. if ( ( ['weapon','summon'].indexOf(loot.type) >= 0 ) && loot.rarity=='4') {
  1921. if (tracked_loot.indexOf(loot.name)===-1) {
  1922. tracked_loot.push(loot.name);
  1923. }
  1924. } else if (tracker_reward_weapons.indexOf(loot.name) >= 0 || tracker_reward_summons.indexOf(loot.name) >= 0 || tracker_reward_items.indexOf(loot.name) >= 0) {
  1925. if (tracked_loot.indexOf(loot.name)===-1) {
  1926. tracked_loot.push(loot.name);
  1927. }
  1928. }
  1929. if (all_loot[loot.name]===undefined) {
  1930. all_loot[loot.name] = parseInt(loot.count);
  1931. } else {
  1932. all_loot[loot.name] += parseInt(loot.count);
  1933. }
  1934. }
  1935. }
  1936. }
  1937. }
  1938. if (send_all_loot) {
  1939. important_loot = all_loot;
  1940. } else {
  1941. for (const loot in all_loot) {
  1942. if (all_loot.hasOwnProperty(loot)) {
  1943. const qty = all_loot[loot];
  1944. if (tracked_loot.indexOf(loot)>=0) {
  1945. important_loot[loot] = qty;
  1946. }
  1947. }
  1948. }
  1949. }
  1950. console.log(important_loot);
  1951. if (Object.keys(important_loot).length > 0) {
  1952. cmd.push({"cmd":"reward","payload":important_loot});
  1953. cmd.push({"cmd":"log","level":"summary","msg":Object.keys(important_loot).length});
  1954. }
  1955.  
  1956. if (tracked_item !== false){
  1957. let data_track = my_profile+"Current Status:";
  1958. let temp_str;
  1959. for (let item in tracked_item){
  1960. if (tracked_item.hasOwnProperty(item)) {
  1961. let item_qty = parseInt(tracked_item[item].number);
  1962. let drop_qty = 0;
  1963. if (all_loot[tracked_item[item].name] !== undefined) {
  1964. drop_qty = all_loot[tracked_item[item].name];
  1965. }
  1966. temp_str = "\n- "+tracked_item[item].name+": "+(item_qty + drop_qty).toString();
  1967. if (all_loot[tracked_item[item].name] !== undefined) {
  1968. temp_str += ' ( +'+(drop_qty).toString()+' )';
  1969. }
  1970. data_track += temp_str;
  1971. }
  1972. }
  1973. cmd.push({"cmd":"log","level":"summary","msg":data_track,"split":0});
  1974. }
  1975. if (check_timer){
  1976. cmd.push({"cmd":"check_timer"});
  1977. }
  1978. xhr.open('POST', server);
  1979. xhr.send(JSON.stringify(cmd));
  1980. let gotoMain = function() {gotoHash("main");};
  1981. checkEl(".mask",0,gotoMain);
  1982. }
  1983.  
  1984. function quitTrial(){
  1985. let doit3 = function(){clickEl(".btn-usual-ok",0,message.raid.trial.ok);};
  1986. let doit2 = function(){clickEl(".btn-withdrow.btn-red-m",0,message.raid.trial.retreat,doit3);};
  1987. let doit1 = function(){clickEl(".btn-raid-menu.menu",0,message.raid.trial.open_menu,doit2);};
  1988. clickAndNegCheck(query.battle_ui.trial_pop_up.close,0,message.raid.trial.close_pop_up,doit1);
  1989. }
  1990.  
  1991. function missionComplete(cmd=[]) {
  1992. clearInterval(reload_counter);
  1993. // let cmd = [];
  1994. cmd.push({"cmd":"log","level":"notif","msg":my_profile+"Objective cleared. Mission complete. "+discord_mention});
  1995. cmd.push({"cmd":"log","level":"summary","msg":my_profile+"Objective cleared. Mission complete."});
  1996. cmd.push({"cmd":"hotkey","keys":["ctrl","w"]});
  1997. xhr.open('POST', server);
  1998. xhr.send(JSON.stringify(cmd));
  1999. }
  2000.  
  2001. let listenNetwork = function() {
  2002. console.log('listenNetwork');
  2003. clearInterval(reload_counter);
  2004. };
  2005.  
  2006. function init() {
  2007. "use strict";
  2008. console.log(init.name);
  2009. reload(5);
  2010. setDebug();
  2011. listenNetwork();
  2012. let checkBody = setInterval(function() {
  2013. console.log(checkBody.name);
  2014. if(document.body !== null){
  2015. clearInterval(checkBody);
  2016. if(document.body.children[0].tagName == "DIV"){
  2017. // reload(30);
  2018. checkError();
  2019. }else{
  2020. console.log("DOM Error");
  2021. reloadNow();
  2022. }
  2023. }
  2024. }, 300);
  2025. }