Guest User

HH auto

a guest
Oct 3rd, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 39.51 KB | None | 0 0
  1. // ==UserScript==
  2. // @name HaremHeroes Automatic
  3. // @namespace JDscripts
  4. // @version 3.24
  5. // @description Open the menu in HaremHeroes(topright) to toggle AutoControlls. Supports AutoSalary, AutoContest, AutoMission, AutoQuest, AutoTrollBattle, AutoArenaBattle and AutoPachinko(Free). Messages are printed in local console.
  6. // @author JD
  7. // @match http*://nutaku.haremheroes.com/*
  8. // @match http*://*.hentaiheroes.com/*
  9. // @require https://cdn.jsdelivr.net/js-cookie/2.2.0/js.cookie.js
  10. // @grant GM_addStyle
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. GM_addStyle('/* The switch - the box around the slider */ .switch { position: relative; display: inline-block; width: 60px; height: 34px; } /* Hide default HTML checkbox */ .switch input {display:none;} /* The slider */ .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; -webkit-transition: .4s; transition: .4s; } .slider:before { position: absolute; content: ""; height: 26px; width: 26px; left: 4px; bottom: 4px; background-color: white; -webkit-transition: .4s; transition: .4s; } input:checked + .slider { background-color: #2196F3; } input:focus + .slider { box-shadow: 0 0 1px #2196F3; } input:checked + .slider:before { -webkit-transform: translateX(26px); -ms-transform: translateX(26px); transform: translateX(26px); } /* Rounded sliders */ .slider.round { border-radius: 34px; } .slider.round:before { border-radius: 50%; }');
  15.  
  16. var globalWorldMap;
  17.  
  18. function getHero()
  19. {
  20. if(unsafeWindow.Hero === undefined)
  21. {
  22. setTimeout(autoLoop, Number(sessionStorage.autoLoopTimeMili))
  23. //console.log(window.wrappedJSObject)
  24. }
  25. return unsafeWindow.Hero;
  26. }
  27.  
  28. function getGirlsMap()
  29. {
  30. return unsafeWindow.GirlSalaryManager.girlsMap;
  31. }
  32.  
  33. function getPage()
  34. {
  35. try{
  36. var ob = document.getElementById("hh_nutaku");
  37. if(ob===undefined || ob === null)
  38. {
  39. ob = document.getElementById("hh_hentai");
  40. }
  41. return ob.className.match(/.*page-(.*) .*/i)[1];
  42. }
  43. catch(err)
  44. {
  45. return ""
  46. }
  47. }
  48.  
  49. // Retruns true if on correct page.
  50. function gotoPage(page)
  51. {
  52. if(getPage() === page)
  53. {
  54. return true;
  55. }
  56. else
  57. {
  58. console.log("Navigating to page: "+page);
  59. var togoto = undefined;
  60. // get page path
  61. switch(page)
  62. {
  63. case "missions":
  64. case "activities":
  65. togoto = $("nav div[rel='content'] a:has(.activities)").attr("href");
  66. break;
  67. case "harem":
  68. togoto = $("nav div[rel='content'] a:has(.harem)").attr("href");
  69. break;
  70. case "map":
  71. togoto = $("nav div[rel='content'] a:has(.map)").attr("href");
  72. break;
  73. case "arena":
  74. togoto = $("nav div[rel='content'] a:has(.battle)").attr("href");
  75. break;
  76. case "pachinko":
  77. togoto = $("nav div[rel='content'] a:has(.pachinko)").attr("href");
  78. break;
  79. case "quest":
  80. togoto = getHero().infos.questing.current_url;
  81. console.log("Current quest page: "+togoto);
  82. break;
  83. default:
  84. console.log("Unknown goto page request. No page \'"+page+"\' defined.");
  85. }
  86. if(togoto != undefined)
  87. {
  88. sessionStorage.autoLoop = "false";
  89. window.location = window.location.origin + togoto;
  90. }
  91. else console.log("Couldn't find page path. Page was undefined...");
  92. return false;
  93. }
  94. }
  95.  
  96. var proceedQuest = function () {
  97. //console.log("Starting auto quest.");
  98. // Check if at correct page.
  99. if (!gotoPage("quest")) {
  100. // Click on current quest to naviagte to it.
  101. console.log("Navigating to current quest.");
  102. return;
  103. }
  104.  
  105. // Get the proceed button type
  106. var proceedButtonMatch = $("#controls button:not([style='display: none;'])");
  107. var proceedCostEnergy = Number($("#controls .cost span[cur='*']").text());
  108. var proceedCostMoney = Number($("#controls .cost span[cur='$']").text().trim().replace(',', ''));
  109. var proceedType = proceedButtonMatch.attr("act");
  110.  
  111. if (proceedButtonMatch.length === 0) console.log("Could not find resume button.");
  112. else if (proceedType === "free") {
  113. console.log("Proceeding for free.");
  114. proceedButtonMatch.click();
  115. }
  116. else if (proceedType === "pay") {
  117. var energyCurrent = getHero().infos.energy_quest;
  118. var moneyCurrent = getHero().infos.soft_currency;
  119. if(proceedCostEnergy <= energyCurrent)
  120. {
  121. // We have energy.
  122. console.log("Spending "+proceedCostEnergy+" Energy to proceed.");
  123. }
  124. else
  125. {
  126. console.log("Quest requires "+proceedCostEnergy+" Energy to proceed.");
  127. sessionStorage.questRequirement = "*"+proceedCostEnergy;
  128. return;
  129. }
  130. if(proceedCostMoney <= moneyCurrent)
  131. {
  132. // We have money.
  133. console.log("Spending "+proceedCostMoney+" Money to proceed.");
  134. }
  135. else
  136. {
  137. console.log("Spending "+proceedCostEnergy+" Money to proceed.");
  138. sessionStorage.questRequirement = "$"+proceedCostMoney;
  139. return;
  140. }
  141. proceedButtonMatch.click();
  142. sessionStorage.autoLoop = "false";
  143. location.reload();
  144. }
  145. else if (proceedType === "use_item") {
  146. console.log("Proceeding by using X" + Number($("#controls .item span").text()) + " of the required item.");
  147. proceedButtonMatch.click();
  148. }
  149. else if (proceedType === "battle") {
  150. console.log("Proceeding to battle troll...");
  151. sessionStorage.questRequirement = "battle";
  152. // Proceed to battle troll.
  153. proceedButtonMatch.click();
  154. sessionStorage.autoLoop = "false";
  155. location.reload();
  156. }
  157. else if (proceedType === "end_archive") {
  158. console.log("Reached end of current archive. Proceeding to next archive.");
  159. sessionStorage.autoLoop = "false";
  160. proceedButtonMatch.click();
  161. }
  162. else if (proceedType === "end_play") {
  163. console.log("Reached end of current play. Proceeding to next play.");
  164. sessionStorage.autoLoop = "false";
  165. proceedButtonMatch.click();
  166. }
  167. else {
  168. console.log("Could not identify given resume button.");
  169. sessionStorage.questRequirement = "unknownQuestButton";
  170. }
  171. };
  172.  
  173. /**
  174. * Recieves a list of mission objects and returns the mission object to use.
  175. * A mission object looks similar to this :-
  176. * Eg 1: {"id_member_mission":"256160093","id_mission":"23","duration":"53","cost":"1","remaining_time":"-83057","rewards":[{"classList":{"0":"slot","1":"slot_xp"},"type":"xp","data":28},{"classList":{"0":"slot","1":"slot_SC"},"type":"money","data":277}]}
  177. * Eg 2: {"id_member_mission":"256160095","id_mission":"10","duration":"53","cost":"1","remaining_time":"-81330","rewards":[{"classList":{"0":"slot","1":"slot_xp"},"type":"xp","data":28},{"classList":{"0":"slot","1":"rare"},"type":"item","data":{"id_item":"23","type":"gift","subtype":"0","identifier":"K3","rarity":"rare","value":"80","carac1":0,"carac2":0,"carac3":0,"endurance":0,"chance":0,"ego":0,"damage":0,"duration":0,"level_mini":"1","name":"Bracelet","Name":"Bracelet","ico":"https://content.haremheroes.com/pictures/items/K3.png","price_sell":5561,"count":1,"id_m_i":[]}}]}
  178. * Eg 3: {"id_member_mission":"256822795","id_mission":"337","duration":"17172","cost":"144","remaining_time":null,"remaining_cost":"144","rewards":[{"classList":{"0":"slot","1":"slot_HC"},"type":"koban","data":11}]}
  179. * Eg 1 has mission rewards of xp and money.
  180. * Eg 2 has mission rewards of xp and item.
  181. * Eg 3 has mission rewards of koban/hard_currency.
  182. * cost is the koban price for instant complete.
  183. */
  184. function getSuitableMission(missionsList)
  185. {
  186. var msn = missionsList[0];
  187. for(var m in missionsList)
  188. {
  189. if(Number(msn.duration) > Number(missionsList[m].duration))
  190. {
  191. msn = missionsList[m];
  192. }
  193. }
  194. return msn;
  195. }
  196.  
  197. // retruns a map of WorldName->fullLink/href
  198. // else returns false if navigating there
  199. function getUnlockedWorlds()
  200. {
  201. if(gotoPage("map"))
  202. {
  203. var map = new Map();
  204. // fill the map
  205. document.querySelectorAll("a.link-world").forEach(
  206. function(elem)
  207. {
  208. var name = elem.nextElementSibling.textContent.trim();
  209. map.set(name, elem.href);
  210. }
  211. );
  212. // set global latest map
  213. sessionStorage.globalWorldMap = JSON.stringify([...map]);
  214. globalWorldMap = map;
  215. //return not busy
  216. return map;
  217. }
  218. else
  219. {
  220. console.log("Navigating to worldmap.");
  221. // not done
  222. return false;
  223. }
  224. }
  225.  
  226. // returns boolean to set busy
  227. function doMissionStuff()
  228. {
  229. if(!gotoPage("missions"))
  230. {
  231. console.log("Navigating to activities page.");
  232. // return busy
  233. return true;
  234. }
  235. else
  236. {
  237. console.log("On activities page.");
  238. console.log("Collecting finished mission's reward.");
  239. $(".mission_button button:visible[rel='claim']").click();
  240. // TODO: select new missions and parse reward data from HTML, it's there in data attributes of tags
  241. var missions = [];
  242. var allGood = true;
  243. // parse missions
  244. $(".mission_object").each(function(idx,missionObject){
  245. var data = $.data(missionObject).d;
  246. // Do not list completed missions
  247. if(data.remaining_time !== null){
  248. // This is not a fresh mission
  249. if(data.remaining_time > 0)
  250. {
  251. console.log("Unfinished mission detected...("+data.remaining_time+"sec. remaining)");
  252. Cookies.set('nextMissionTime',data.remaining_time,{expires:new Date(new Date().getTime() + data.remaining_time * 1000)});
  253. }
  254. else{
  255. console.log("Unclaimed mission detected...");
  256. }
  257. allGood = false;
  258. return;
  259. }
  260. data.missionObject = missionObject;
  261. var rewards = [];
  262. // set rewards
  263. {
  264. // get Reward slots
  265. var slots = missionObject.querySelectorAll(".slot");
  266. // traverse slots
  267. $.each(slots,function(idx,slotDiv){
  268. var reward = {};
  269. // get slot class list
  270. reward.classList = slotDiv.classList;
  271. // set reward type
  272. if(reward.classList.contains("slot_xp"))reward.type = "xp";
  273. else if(reward.classList.contains("slot_SC"))reward.type = "money";
  274. else if(reward.classList.contains("slot_HC"))reward.type = "koban";
  275. else reward.type = "item";
  276. // set value if xp
  277. if(reward.type === "xp" || reward.type === "money" || reward.type === "koban")
  278. {
  279. // remove all non numbers and HTML tags
  280. try{
  281. reward.data = Number(slotDiv.innerHTML.replace(/<.*?>/g,'').replace(/\D/g,''));
  282. }
  283. catch(e){
  284. console.log("Couldn't parse xp/money data.");
  285. console.log(slotDiv);
  286. }
  287. }
  288. // set item details if item
  289. else if(reward.type === "item")
  290. {
  291. try{
  292. reward.data = $.data(slotDiv).d;
  293. }
  294. catch(e){
  295. console.log("Couldn't parse item reward slot details.");
  296. console.log(slotDiv);
  297. reward.type = "unknown";
  298. }
  299. }
  300. rewards.push(reward);
  301. });
  302. }
  303. data.rewards = rewards;
  304. missions.push(data);
  305. });
  306. if(!allGood){
  307. console.log("Something went wrong, need to retry later...");
  308. // busy
  309. return true;
  310. }
  311. console.log("Missions parsed, mission list is:-");
  312. console.log(missions);
  313. if(missions.length > 0)
  314. {
  315. console.log("Selecting mission from list.");
  316. var mission = getSuitableMission(missions);
  317. console.log("Selected mission:-");
  318. console.log(mission);
  319. console.log("Selected mission duration: "+mission.duration+"sec.");
  320. var missionButton = $(mission.missionObject).find("button:visible").first();
  321. console.log("Mission button of type: "+missionButton.attr("rel"));
  322. console.log("Clicking mission button.");
  323. missionButton.click();
  324. Cookies.set('nextMissionTime',mission.duration,{expires:new Date(new Date().getTime() + mission.duration * 1000)});
  325. }
  326. else{
  327. console.log("No missions detected...!");
  328. // get gift
  329. var ck = Cookies.get('nextMissionTime');
  330. var isAfterGift = document.querySelector("#missions .after_gift").style.display === 'block';
  331. if(!isAfterGift){
  332. if(ck === undefined || ck === 'giftleft')
  333. {
  334. console.log("Collecting gift.");
  335. // click button
  336. document.querySelector(".end_gift button").click();
  337. }
  338. else{
  339. console.log("Refreshing to collect gift...");
  340. Cookies.set('nextMissionTime','giftleft');
  341. window.reload();
  342. // is busy
  343. return true;
  344. }
  345. }
  346. var time = 0;
  347. for(var e in unsafeWindow.HHTimers.timers){
  348. try{if(unsafeWindow.HHTimers.timers[e].$elm.selector.includes("#missions_counter"))
  349. time=unsafeWindow.HHTimers.timers[e];
  350. }
  351. catch(e){}
  352. }
  353. time = time.remainingTime;
  354. if(time === undefined)
  355. {
  356. //try again with different selector
  357. for(e in unsafeWindow.HHTimers.timers){
  358. try{if(unsafeWindow.HHTimers.timers[e].$elm.selector.includes(".after_gift"))
  359. time=unsafeWindow.HHTimers.timers[e];
  360. }
  361. catch(e){}
  362. }
  363. time = time.remainingTime;
  364. }
  365. if(time === undefined){
  366. console.log("New mission time was undefined... Setting it manually to 10min.");
  367. time = 10*60;
  368. }
  369. console.log("New missions in: "+time+"sec.");
  370. Cookies.set('nextMissionTime',time,{expires:new Date(new Date().getTime() + time * 1000)});
  371. }
  372. // not busy
  373. return false;
  374. }
  375. }
  376.  
  377. // returns boolean to set busy
  378. function doContestStuff()
  379. {
  380. if(!gotoPage("missions"))
  381. {
  382. console.log("Navigating to activities page.");
  383. // return busy
  384. return true;
  385. }
  386. else
  387. {
  388. console.log("On activities page.");
  389. console.log("Collecting finished contests's reward.");
  390. $(".contest .ended button[rel='claim']").click();
  391. // need to get next contest timer data
  392. var time = 0;
  393. for(var e in unsafeWindow.HHTimers.timers){
  394. try{if(unsafeWindow.HHTimers.timers[e].$elm.selector.includes(".contest_timer"))
  395. time=unsafeWindow.HHTimers.timers[e];
  396. }
  397. catch(e){}
  398. }
  399. time = time.remainingTime;
  400. try{if(time === undefined)
  401. {
  402. //try again with different selector
  403. time = undefined;
  404. for(e in unsafeWindow.HHTimers.timers){
  405. if(unsafeWindow.HHTimers.timers[e].$elm[0].className.includes("contest_timer"))
  406. // get closest time
  407. if(!(unsafeWindow.HHTimers.timers[e].remainingTime>time))
  408. time=unsafeWindow.HHTimers.timers[e].remainingTime;
  409. }
  410. }}catch(e){}
  411. if(time === undefined){
  412. console.log("New contest time was undefined... Setting it manually to 10min.");
  413. time = 10*60;
  414. }
  415. Cookies.set('nextContestTime',time,{expires:new Date(new Date().getTime() + time * 1000)});
  416. console.log("Next contest time stored in nextContestTime cookie.(+" + time + " sec.)");
  417. // Not busy
  418. return false;
  419. }
  420. }
  421.  
  422. var getSalary = function () {
  423. try {
  424. if(!gotoPage("harem"))
  425. {
  426. // Not at Harem screen then goto the Harem screen.
  427. console.log("Navigating to Harem window.");
  428. // return busy
  429. return true;
  430. }
  431. else {
  432. console.log("Detected Harem Screen. Fetching Salary");
  433. is_cheat_click=function(e) { return false; };
  434. $("#harem_whole #harem_left .salary:not('.loads') button").each(function (index) {
  435. $(this).click();
  436. });
  437. console.log("Salary fetched. Getting next fetch time");
  438. // In seconds
  439. var closestTime = undefined;
  440. var gMap = getGirlsMap();
  441. if(gMap === undefined)
  442. {
  443. // error
  444. console.log("Girls Map was undefined...! Error, manually setting salary time to 2 min.");
  445. closestTime = 2*60;
  446. }
  447. else
  448. {
  449. try{
  450. // Calc. closest time
  451. for(var key in gMap)
  452. {
  453. // undefined comparision is always false so first iteration is false, hence the not(!)
  454. if(!(closestTime<gMap[key].gData.pay_in))
  455. {
  456. closestTime = gMap[key].gData.pay_in;
  457. }
  458. }
  459. }
  460. catch(exp){
  461. // error
  462. console.log("Girls Map had undefined property...! Error, manually setting salary time to 2 min.");
  463. closestTime = 2*60;
  464. }
  465. }
  466. if(closestTime === undefined)
  467. {
  468. console.log("closestTime was undefined...! Error, manually setting salary time to 2 min.");
  469. closestTime = 2*60;
  470. }
  471. if(closestTime <= 2)
  472. {
  473. console.log("closestTime is less than/equal to 2 sec. Staying on this page.");
  474. // return busy
  475. return true;
  476. }
  477. Cookies.set('nextSalaryTime',closestTime,{expires:new Date(new Date().getTime() + closestTime * 1000)});
  478. console.log("New fetch time stored in nextSalaryTime cookie.(+" + closestTime + " sec.)");
  479. // return not busy
  480. return false;
  481. }
  482. }
  483. catch (ex) {
  484. console.log("Could not collect salary... " + ex);
  485. // return not busy
  486. return false;
  487. }
  488. };
  489.  
  490. var doBossBattle = function()
  491. {
  492. var currentPower = getHero().infos.energy_fight;
  493. if(currentPower < 1)
  494. {
  495. //console.log("No power for battle.");
  496. return;
  497. }
  498. // Battles the latest boss.
  499. // Navigate to latest boss.
  500. if(window.location.pathname.startsWith("/battle.html"))
  501. {
  502. // On the battle screen.
  503. doBattle();
  504. }
  505. else if(window.location.pathname.startsWith("/world"))
  506. {
  507. // On some world screen.
  508. // Click on the local Boss's battle button.
  509. console.log("Entering battle with this troll.");
  510. sessionStorage.autoLoop = "false";
  511. window.location = window.location.origin + $("#worldmap a[class='troll_world']").attr("href");
  512. return;
  513. }
  514. else if(sessionStorage.trollToFight !== undefined && sessionStorage.trollToFight !== "latest")
  515. {
  516. console.log("Custom troll fight.");
  517. console.log("Fighting troll at: "+sessionStorage.trollToFight);
  518. var worldMap = getUnlockedWorlds();
  519. if(worldMap === false)
  520. {
  521. console.log("Finding unlocked worlds...");
  522. return;
  523. }
  524. var worldPage = worldMap.get(sessionStorage.trollToFight);
  525. if(worldPage == undefined)
  526. {
  527. console.log("ERROR! worldPage undefined for troll at: "+sessionStorage.trollToFight);
  528. return;
  529. }
  530. console.log("Troll world at: "+worldPage);
  531. window.location = worldPage;
  532. sessionStorage.autoLoop = "false";
  533. }
  534. else if(window.location.pathname.startsWith("/quest"))
  535. {
  536. // On some quest screen.
  537. // Goto this area's screen.
  538. console.log("Navigating to latest Troll.");
  539. sessionStorage.autoLoop = "false";
  540. window.location = window.location.origin + $("#breadcrumbs a[class='back']").last().attr("href");
  541. return;
  542. }
  543. else{
  544. console.log("Navigating to latest Troll.");
  545. sessionStorage.autoLoop = "false";
  546. window.location = window.location.origin + $("nav div[rel='content'] a:has(.continue_quest)").attr("href");
  547. return;
  548. }
  549. };
  550.  
  551. var doBattle = function () {
  552. //console.log("Performing auto battle.");
  553. // Confirm if on correct screen.
  554. var page = getPage();
  555. if(page === "arena")
  556. {
  557. if ($("#arena[class='canvas']").length === 1) {
  558. // Oponent choose screen
  559. console.log("On opponent choose screen.");
  560. if(document.getElementById("popups").style.display === "block")
  561. {
  562. console.log("Popup detetcted. Refresh page.");
  563. unsafeWindow.reload();
  564. return;
  565. }
  566. else{
  567. console.log("No popups.");
  568. }
  569. // Fight the first opponent in list.
  570. var selbutton = $(".opponents_arena .sub_block button:contains('Select')");
  571. if(selbutton.length<1)
  572. {
  573. console.log("No arena opponents found, storing nextArenaTime...")
  574. var arenatime = 0;
  575. for(var e in unsafeWindow.HHTimers.timers){
  576. try{
  577. if(unsafeWindow.HHTimers.timers[e].$elm.selector.startsWith(".arena_refresh_counter"))
  578. arenatime=unsafeWindow.HHTimers.timers[e];
  579. }
  580. catch(e){}
  581. }
  582. arenatime = arenatime.remainingTime;
  583. Cookies.set('nextArenaTime',arenatime,{expires:new Date(new Date().getTime() + arenatime * 1000)});
  584. console.log("New arena time stored in nextArenaTime cookie.(+" + arenatime + " sec.)");
  585. return;
  586. }
  587. selbutton[0].click();
  588. sessionStorage.autoLoop = "false";
  589. }
  590. }
  591. else if (page === "battle") {
  592. // On battle page.
  593. //console.log("On Battle Page.");
  594. if ($("#battle[class='canvas']").length === 1) {
  595. // Battle screen
  596. console.log("On battle screen.");
  597. // get button with no autofight, i.e. no koban
  598. var battleButton = $("#battle_middle button[rel='launch']:not(.autofight)");
  599. var currentPower = getHero().infos.energy_fight;
  600. if(battleButton === undefined){
  601. console.log("Battle Button was undefined. Disabling all auto-battle.");
  602. document.getElementById("autoBattleCheckbox").checked = false;
  603. document.getElementById("autoArenaCheckbox").checked = false;
  604. if (sessionStorage.questRequirement === "battle")
  605. {
  606. document.getElementById("autoQuestCheckbox").checked = false;
  607. console.log("Auto-quest disabled since it requires battle and auto-battle has errors.");
  608. }
  609. return;
  610. }
  611. var battle_price = battleButton.attr("price_fe");
  612. if(battle_price === undefined){
  613. console.log("Could not detect battle button price. Error.");
  614. console.log("Disabling all auto-battle.");
  615. document.getElementById("autoBattleCheckbox").checked = false;
  616. document.getElementById("autoArenaCheckbox").checked = false;
  617. if (sessionStorage.questRequirement === "battle")
  618. {
  619. document.getElementById("autoQuestCheckbox").checked = false;
  620. console.log("Auto-quest disabled since it requires battle and auto-battle has errors.");
  621. }
  622. return;
  623. }
  624. console.log("battle price: "+battle_price+"P")
  625. if(currentPower >= 0)
  626. {
  627. // We have the power.
  628. is_cheat_click=function(e) { return false; };
  629. battleButton.click();
  630. // Skip
  631. setTimeout(function(){$("#battle_middle button[rel='skip']").click();},1000);
  632. setTimeout(function(){$("#battle_end div[style*='display: block;'] .blue_text_button").click();},2500);
  633.  
  634. if (sessionStorage.questRequirement === "battle") {
  635. // Battle Done.
  636. sessionStorage.questRequirement = "none";
  637. }
  638. }
  639. else
  640. {
  641. // We need more power.
  642. console.log("Battle requires "+battle_price+" power.");
  643. sessionStorage.battlePowerRequired = battle_price;
  644. if(sessionStorage.questRequirement === "battle")sessionStorage.questRequirement = "P"+battle_price;
  645. }
  646. }
  647. else {
  648. console.log("Could not identify battle screen.");
  649. if (sessionStorage.questRequirement === "battle") sessionStorage.questRequirement = "errorInAutoBattle";
  650. return;
  651. }
  652. }
  653. else
  654. {
  655. // Switch to the correct screen
  656. console.log("Switching to battle screen.");
  657. gotoPage("arena");
  658. return;
  659. }
  660. };
  661.  
  662. var updateData = function () {
  663. //console.log("updating UI");
  664. var trollOptions = document.getElementById("autoTrollSelector");
  665. sessionStorage.autoTrollSelectedIndex = trollOptions.selectedIndex;
  666. sessionStorage.trollToFight = trollOptions.value;
  667. sessionStorage.autoSalary = document.getElementById("autoSalaryCheckbox").checked;
  668. sessionStorage.autoContest = document.getElementById("autoContestCheckbox").checked;
  669. sessionStorage.autoMission = document.getElementById("autoMissionCheckbox").checked;
  670. sessionStorage.autoQuest = document.getElementById("autoQuestCheckbox").checked;
  671. sessionStorage.autoTrollBattle = document.getElementById("autoBattleCheckbox").checked;
  672. sessionStorage.autoArenaBattle = document.getElementById("autoArenaCheckbox").checked;
  673. sessionStorage.autoFreePachinko = document.getElementById("autoFreePachinko").checked;
  674. };
  675.  
  676. var getPachinko = function(){
  677. try {
  678. if(!gotoPage("pachinko"))
  679. {
  680. // Not at Pachinko screen then goto the Pachinko screen.
  681. console.log("Navigating to Pachinko window.");
  682. return;
  683. }
  684. else {
  685. console.log("Detected Pachinko Screen. Fetching Pachinko");
  686. $("#pachinko button[free=1]")[0].click();
  687. var npach;
  688. for(var e in unsafeWindow.HHTimers.timersListMin){
  689. if(unsafeWindow.HHTimers.timersListMin[e].$elm.selector.startsWith(".pachinko_change"))
  690. npach=unsafeWindow.HHTimers.timersListMin[e].remainingTime;
  691. }
  692. if(npach !== undefined || npach !== 0)
  693. {
  694. Cookies.set('nextPachinkoTime',npach,{expires:new Date(new Date().getTime() + npach * 1000)});
  695. }
  696. else
  697. {
  698. Cookies.remove('nextPachinkoTime');
  699. }
  700. }
  701. }
  702. catch (ex) {
  703. console.log("Could not collect pachinko... " + ex);
  704. }
  705. };
  706.  
  707. var autoLoop = function () {
  708. updateData();
  709. var busy = false;
  710. var page = window.location.href;
  711. var currentPower = getHero().infos.energy_fight;
  712. //console.log("sal="+sessionStorage.autoSalary);
  713. if(sessionStorage.autoFreePachinko === "true" && busy === false){
  714. // Navigate to pachinko
  715. if (Cookies.get("nextPachinkoTime") === undefined) {
  716. console.log("Time to fetch Pachinko.");
  717. getPachinko();
  718. busy = true;
  719. }
  720. }
  721. if(sessionStorage.autoContest === "true" && busy === false){
  722. if (Cookies.get("nextContestTime") === undefined){
  723. console.log("Time to get contest rewards.");
  724. busy = doContestStuff();
  725. }
  726. }
  727. if(sessionStorage.autoMission === "true" && busy === false){
  728. if (Cookies.get("nextMissionTime") === undefined){
  729. console.log("Time to do missions.");
  730. busy = doMissionStuff();
  731. }
  732. }
  733. if (sessionStorage.autoSalary === "true" && busy === false) {
  734. if (Cookies.get("nextSalaryTime") === undefined) {
  735. console.log("Time to fetch salary.");
  736. busy = getSalary();
  737. }
  738. }
  739. if (sessionStorage.autoQuest === "true" && busy === false) {
  740. if (sessionStorage.questRequirement === "battle") {
  741. console.log("Quest requires battle.");
  742. doBossBattle();
  743. busy = true;
  744. }
  745. else if (sessionStorage.questRequirement[0] === '$') {
  746. if (Number(sessionStorage.questRequirement.substr(1)) < getHero().infos.soft_currency) {
  747. // We have enough money... requirement fulfilled.
  748. console.log("Continuing quest, required money obtained.");
  749. sessionStorage.questRequirement = "none";
  750. proceedQuest();
  751. busy = true;
  752. }
  753. else {
  754. if(isNaN(sessionStorage.questRequirement.substr(1)))
  755. {
  756. sessionStorage.questRequirement = "none";
  757. console.log("Invalid money in session storage quest requirement !");
  758. }
  759. else{
  760. // Else we need more money.
  761. //console.log("Need money for quest, cannot continue. Turning ON AutoSalary.");
  762. sessionStorage.autoQuest = "true";
  763. }
  764. busy = false;
  765. }
  766. }
  767. else if (sessionStorage.questRequirement[0] === '*') {
  768. var energyNeeded = Number(sessionStorage.questRequirement.substr(1));
  769. var energyCurrent = getHero().infos.energy_quest;
  770. if (energyNeeded <= energyCurrent) {
  771. // We have enough energy... requirement fulfilled.
  772. console.log("Continuing quest, required energy obtained.");
  773. sessionStorage.questRequirement = "none";
  774. proceedQuest();
  775. busy = true;
  776. }
  777. // Else we need energy, just wait.
  778. else {
  779. busy = false;
  780. //console.log("Replenishing energy for quest.(" + energyNeeded + " needed)");
  781. }
  782. }
  783. else if (sessionStorage.questRequirement[0] === 'P')
  784. {
  785. // Battle power required.
  786. var neededPower = Number(sessionStorage.questRequirement.substr(1));
  787. if(currentPower < neededPower)
  788. {
  789. console.log("Quest requires "+neededPower+" Battle Power for advancement. Waiting...");
  790. busy = false;
  791. }
  792. else
  793. {
  794. console.log("Battle Power obtained, resuming quest...");
  795. sessionStorage.questRequirement = "none";
  796. proceedQuest();
  797. busy = true;
  798. }
  799. }
  800. else if (sessionStorage.questRequirement === "unknownQuestButton") {
  801. console.log("AutoQuest disabled.AutoQuest cannot be performed due to unknown quest button. Please manually proceed the current quest screen.");
  802. document.getElementById("autoQuestCheckbox").checked = false;
  803. sessionStorage.autoQuest = "false";
  804. sessionStorage.questRequirement = "none";
  805. busy = false;
  806. }
  807. else if (sessionStorage.questRequirement === "errorInAutoBattle") {
  808. console.log("AutoQuest disabled.AutoQuest cannot be performed due errors in AutoBattle. Please manually proceed the current quest screen.");
  809. document.getElementById("autoQuestCheckbox").checked = false;
  810. sessionStorage.autoQuest = "false";
  811. sessionStorage.questRequirement = "none";
  812. busy = false;
  813. }
  814. else if(sessionStorage.questRequirement === "none")
  815. {
  816. //console.log("NONE req.");
  817. busy = true;
  818. proceedQuest();
  819. }
  820. else
  821. {
  822. console.log("Invalid quest requirement : "+sessionStorage.questRequirement);
  823. busy=false;
  824. }
  825. }
  826. else if(sessionStorage.autoQuest === "false"){sessionStorage.questRequirement = "none";}
  827.  
  828. if(sessionStorage.autoArenaBattle === "true" && busy === false)
  829. {
  830. if(Cookies.get("nextArenaTime") === undefined)
  831. {
  832. console.log("Time to fight in arena.");
  833. doBattle();
  834. busy = true;
  835. }
  836. }
  837.  
  838. if(sessionStorage.autoTrollBattle === "true")
  839. {
  840. if(busy === false && currentPower >= Number(sessionStorage.battlePowerRequired) && currentPower > 0)
  841. {
  842. sessionStorage.battlePowerRequired = "0";
  843. busy = true;
  844. if(sessionStorage.autoQuest === "true")
  845. {
  846. if(sessionStorage.questRequirement[0] === 'P')
  847. {
  848. console.log("AutoBattle disabled for power collection for AutoQuest.");
  849. document.getElementById("autoBattleCheckbox").checked = false;
  850. sessionStorage.autoTrollBattle = "false";
  851. busy = false;
  852. }
  853. else
  854. {
  855. doBossBattle();
  856. }
  857. }
  858. else
  859. {
  860. doBossBattle();
  861. }
  862. }
  863. }
  864. else{sessionStorage.battlePowerRequired = "0";}
  865.  
  866. if(busy === true && sessionStorage.userLink==="none" && !window.location.pathname.startsWith("/quest"))
  867. {
  868. sessionStorage.userLink = page;
  869. }
  870. else if(sessionStorage.userLink !=="none" && busy === false)
  871. {
  872. console.log("Restoring page "+sessionStorage.userLink);
  873. window.location = sessionStorage.userLink;
  874. sessionStorage.userLink = "none";
  875. }
  876.  
  877. if(isNaN(sessionStorage.autoLoopTimeMili)){
  878. console.log("AutoLoopTimeMili is not a number.");
  879. setDefaults();
  880. }
  881. else{
  882. if (sessionStorage.autoLoop === "true") setTimeout(autoLoop, Number(sessionStorage.autoLoopTimeMili));
  883. else console.log("autoLoop Disabled");
  884. }
  885. };
  886.  
  887. var setDefaults = function () {
  888. console.log("Setting Defaults.");
  889. sessionStorage.autoSalary = "false";
  890. sessionStorage.autoContest = "false";
  891. sessionStorage.autoMission = "false";
  892. sessionStorage.autoFreePachinko = "false";
  893. sessionStorage.autoLoop = "true";
  894. sessionStorage.userLink = "none";
  895. sessionStorage.autoLoopTimeMili = "200";
  896. sessionStorage.autoQuest = "false";
  897. sessionStorage.autoTrollBattle = "false";
  898. sessionStorage.autoArenaBattle = "false";
  899. sessionStorage.battlePowerRequired = "0";
  900. sessionStorage.questRequirement = "none";
  901. sessionStorage.freshStart = "no";
  902. };
  903.  
  904. var start = function () {
  905. //console.log("script started");
  906. // get world map
  907. try{
  908. globalWorldMap = new Map(JSON.parse(sessionStorage.globalWorldMap));
  909. if(!(globalWorldMap instanceof Map) || globalWorldMap.size<1)throw false;
  910. }
  911. catch(e)
  912. {
  913. console.log("Need world map NOW...");
  914. if(!getUnlockedWorlds())
  915. {
  916. sessionStorage.userLink = window.location.href;
  917. return;
  918. }
  919. }
  920. // Add UI buttons.
  921. var UIcontainer = $("#contains_all nav div[rel='content']");
  922. UIcontainer.html('<div style="position: absolute;right: 18.66%; padding: 10px;width: inherit;text-align: center;display:flex;flex-direction:column;">'
  923. + '<span>AutoSal.</span><div><label class=\"switch\"><input id=\"autoSalaryCheckbox\" type=\"checkbox\"><span class=\"slider round\"></span></label></div>'
  924. + '<span>AutoContest</span><div><label class=\"switch\"><input id=\"autoContestCheckbox\" type=\"checkbox\"><span class=\"slider round\"></span></label></div>'
  925. + '<span>AutoMission</span><div><label class=\"switch\"><input id=\"autoMissionCheckbox\" type=\"checkbox\"><span class=\"slider round\"></span></label></div>'
  926. +'<span>AutoQuest</span><div><label class=\"switch\"><input id=\"autoQuestCheckbox\" type=\"checkbox\"><span class=\"slider round\"></span></label></div>'
  927. +'<span>AutoTrollBattle</span><div>\
  928. <label class=\"switch\"><input id=\"autoBattleCheckbox\" type=\"checkbox\"><span class=\"slider round\"></span></label>\
  929. <select id=\"autoTrollSelector\"><option value=\"latest\">Latest</option></select>\
  930. </div>'
  931. +'<span>AutoArenaBattle</span><div><label class=\"switch\"><input id=\"autoArenaCheckbox\" type=\"checkbox\"><span class=\"slider round\"></span></label></div>'
  932. +'<span>AutoPachinko(Free)</span><div><label class=\"switch\"><input id=\"autoFreePachinko\" type=\"checkbox\"><span class=\"slider round\"></span></label></div>'
  933. +'</div>'+UIcontainer.html());
  934. // Add auto troll options
  935. var trollOptions = document.getElementById("autoTrollSelector");
  936. globalWorldMap.forEach(function(val,key){
  937. var option = document.createElement("option");
  938. option.text = key;
  939. trollOptions.add(option);
  940. });
  941. trollOptions.selectedIndex = sessionStorage.autoTrollSelectedIndex;
  942. document.getElementById("autoSalaryCheckbox").checked = sessionStorage.autoSalary === "true";
  943. document.getElementById("autoContestCheckbox").checked = sessionStorage.autoContest === "true";
  944. document.getElementById("autoMissionCheckbox").checked = sessionStorage.autoMission === "true";
  945. document.getElementById("autoQuestCheckbox").checked = sessionStorage.autoQuest === "true";
  946. document.getElementById("autoBattleCheckbox").checked = sessionStorage.autoTrollBattle === "true";
  947. document.getElementById("autoArenaCheckbox").checked = sessionStorage.autoArenaBattle === "true";
  948. document.getElementById("autoFreePachinko").checked = sessionStorage.autoFreePachinko === "true";
  949. sessionStorage.autoLoop = "true";
  950. if (typeof sessionStorage.freshStart == "undefined" || isNaN(Number(sessionStorage.autoLoopTimeMili))) {
  951. setDefaults();
  952. }
  953. autoLoop();
  954. };
  955. $("document").ready(start);
Add Comment
Please, Sign In to add comment