NEET Lib

NEET Bot Library

目前為 2020-02-20 提交的版本,檢視 最新版本

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

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