Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //if the minutes until the refill are a high number probably there was a recent refill
- const LBPminutesToCheckAt = 8
- const LBPminutesToResetFight = 5
- const LBPminuteCheckRegex = /0\d:/g
- let LBPfought = true
- function battlePage() {
- //find minutes remaining until refill
- // let minutesText = $("#minutesLimit").text() // format should be: "0X:" where X is between 0-9
- // if (minutesText === '0-1' || minutesText === '0-2') refreshPage()
- //reset the regex
- LBPminuteCheckRegex.lastIndex = 0
- //finds matches and if everything is ok the index must be at 0, else refreshes the page
- // let isMatching = LBPminuteCheckRegex.exec(minutesText)
- /* try {
- if (isMatching.index !== 0) {
- refreshPage()
- console.log('xD')
- }
- }
- catch (e) {
- refreshPage()
- }*/
- let minutesTillRefill = Number($("#limit_timer_time_text").text().replace(/m \d*s/g, ''))
- //gets the HP and performs some calculations to take the right action
- let hpSpan = $('span:contains(\'Health:\')').next().text()
- //if the battle is over or the round is over takes action
- isRoundBattleActive()
- if (minutesTillRefill !== NaN && minutesTillRefill >= LBPminutesToCheckAt && hpSpan === '0.0' && !LBPfought) {
- refreshPage()
- }
- else performAction(hpSpan)
- if (minutesTillRefill <= LBPminutesToResetFight) LBPfought = false
- }
- function performAction(hpSpan) {
- if (hpSpan !== '0.0') {
- fight(1)
- setTimeout(battlePage, generateRandomBetween(3000, 7000))
- }
- else {
- //if nothing more to hit closes the window
- let closeHitData = $('div.pico-close:contains(\'×\')')
- if (closeHitData[0] !== undefined) closeHitData[0].click()
- }
- }
- //clicks the fight button takes 1 or 5 as an argument
- function fight(hits) {
- console.log('fights')
- LBPfought = true
- //gets the divs
- let berserk = $('#fightButtonBerserk1')
- let normalHit = $('#fightButton1')
- let fightAgain = $('#fightagainbutton')
- if (fightAgain[0] !== undefined) {
- fightAgain[0].click()
- }
- else if (hits == '5') {
- if (berserk[0] !== undefined) {
- //find 'i' finds the icon so it hits the button in the boundaries
- berserk.find('i')[0].click()
- }
- }
- else if (hits == '1') {
- if ($('#fightButton2')[0] !== undefined) {
- $('#fightButton2').find('i')[0].click()
- }
- else if (normalHit[0] !== undefined) {
- normalHit.find('i')[0].click()
- }
- }
- }
- //checks whether the current opened battle is valid, if not opens another one
- //checks if round is over. if yes refreshes the page
- function isRoundBattleActive() {
- let battleTime = $('#roundCountdown').find('span').text()
- let wrongLocation = $("div:contains('t fight in this battle from your current location.')")
- if (battleTime === '00:00:00' || wrongLocation[0] !== undefined) {
- //looks for button with battle drops text
- let battleDrops = $('input[value=\'Show battle drops\']')
- if (battleDrops[0] !== undefined || wrongLocation[0] !== undefined) {
- //navigates to another battle
- console.log('xD')
- buildSwitchBattleTask()
- }
- //if you are not browsing other pages
- else if (window.location.search.indexOf('round') === -1) {
- //automatically goes to the last page
- refreshPage()
- }
- else {
- let battleId = Number(window.location.search.replace("?id=", '').replace(/&round=\d/, ''))
- window.location.search = "?id=" + battleId
- }
- }
- }
- function buildSwitchBattleTask(Memory = new LongTermMemory('FindBattle')) {
- //first step
- let navigateHome = `()=>{
- window.location.pathname = '/index.html'
- }`
- Memory.createTask('navigate-home', navigateHome)
- gotoBattleTask(Memory)
- }
- function gotoBattleTask(Memory = new LongTermMemory('FindBattle')) {
- //secondStep
- //checks for available battles
- let findBattle = `()=>{
- $('#tabs-4').find('a')[0].click()
- }`
- Memory.createTask('click-battle', findBattle)
- fulfillTask(Memory)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement