NEET Lib

NEET Bot Library

当前为 2020-02-24 提交的版本,查看 最新版本

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

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