-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhunt.js
133 lines (99 loc) · 3.45 KB
/
hunt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const { Builder, By, Key, until } = require('selenium-webdriver')
const logs = require('./logs')
const util = require('./util')
async function clickHuntButton() {
let driver = this.driver
try {
let form = await driver.findElement(By.id('form_cacada_tempo'))
let tds = await form.findElements(By.tagName('td'))
let td = tds[1]
let input = await td.findElement(By.tagName('input'))
input.click()
await driver.manage().setTimeouts({implicit: 3000})
} catch(e) {
clickHuntButton()
}
}
async function hunt() {
let driver = this.driver
let huntByTime = await driver.findElement(
By.xpath("//*[contains(text(), 'Caça p/ tempo')]"))
await huntByTime.click()
await util.solveCaptcha()
await clickHuntButton()
}
async function userStillHaveTimeToHunt() {
let driver = this.driver
await driver.get('http://www.narutoplayers.com.br/?p=cacadas')
await driver.manage().setTimeouts({implicit: 2000})
let huntByTime = await driver.findElement(
By.xpath("//*[contains(text(), 'Caça p/ tempo')]"))
await huntByTime.click()
let elementsFound = await driver.findElements(
By.xpath("//*[contains(text(), 'Você já usou todo seu tempo de caçada por hoje!')]"))
return elementsFound.length > 0 ? false : true
}
async function checkAndStartHunting() {
let secondsLeft = 300
let stillHaveTimeToHunt = await userStillHaveTimeToHunt()
if(stillHaveTimeToHunt) {
logs.save(`Ainda tem tempo pra caçar`)
let isClockOnTheScreen = await util.isClockOnDOM()
if(!isClockOnTheScreen) {
logs.save(`Não tem relógio`)
let playerAttacked = await util.playerWasAttacked()
if(!playerAttacked) {
await hunt()
logs.save(`Caçada realizada`)
return secondsLeft
}
logs.save(`O player foi atacado`)
let remainingSeconds = await util.getRemainingSeconds()
if(remainingSeconds > 0) {
logs.save(`Tempo restante da penalidade: ${remainingSeconds} segundos`)
secondsLeft = remainingSeconds
return secondsLeft
}
logs.save(`Apenas atualizar a página`)
await util.getReward('AtaqueExterno')
let afterGetRewardStillHaveTimeToHunt = await userStillHaveTimeToHunt()
if(afterGetRewardStillHaveTimeToHunt) {
await hunt()
logs.save(`Caçada realizada`)
return secondsLeft
}
logs.save(`Acabou o tempo da caçada`)
return secondsLeft
}
logs.save(`Tem relógio`)
let remainingSeconds = await util.getRemainingSeconds()
if(remainingSeconds > 0) {
logs.save(`Aguardar por ${remainingSeconds} segundos`)
secondsLeft = remainingSeconds
return secondsLeft
}
logs.save(`Apenas receber recompensa`)
await util.getReward('CaçadaPorTempo')
let afterGetRewardStillHaveTimeToHunt = await userStillHaveTimeToHunt()
if(afterGetRewardStillHaveTimeToHunt) {
await hunt()
logs.save(`Caçada realizada`)
return secondsLeft
}
logs.save(`Acabou o tempo da caçada`)
return secondsLeft
}
logs.save(`Acabou o tempo da caçada`)
this.timeToHuntIsUp = false
return secondsLeft
}
function init(timeToHuntIsUp, driver) {
this.timeToHuntIsUp = timeToHuntIsUp
this.driver = driver
}
exports.clickHuntButton = clickHuntButton
exports.checkAndStartHunting = checkAndStartHunting
exports.userStillHaveTimeToHunt = userStillHaveTimeToHunt
exports.hunt = hunt
exports.timeToHuntIsUp = this.timeToHuntIsUp
exports.init = init