forked from ephymew/Pokeclicker-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautobattlefrontier.user.js
More file actions
207 lines (187 loc) · 8.73 KB
/
autobattlefrontier.user.js
File metadata and controls
207 lines (187 loc) · 8.73 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// ==UserScript==
// @name [Pokeclicker] Auto Battle Frontier
// @namespace Pokeclicker Scripts
// @author Ephenia (Credit: andrew951)
// @description Adds in stage resetting to the Battle Frontier that allows you to set a target stage and infinitely farm the Battle Frontier while being fully AFK. Also, gives the appropriate amount of Battle Points and Money without needing to fail and lose a stage.
// @copyright https://github.com/Ephenia
// @license GPL-3.0 License
// @version 1.4
// @homepageURL https://github.com/Ephenia/Pokeclicker-Scripts/
// @supportURL https://github.com/Ephenia/Pokeclicker-Scripts/issues
// @downloadURL https://raw.githubusercontent.com/Ephenia/Pokeclicker-Scripts/master/autobattlefrontier.user.js
// @updateURL https://raw.githubusercontent.com/Ephenia/Pokeclicker-Scripts/master/autobattlefrontier.user.js
// @match https://www.pokeclicker.com/
// @icon https://www.google.com/s2/favicons?domain=pokeclicker.com
// @grant none
// @run-at document-idle
// ==/UserScript==
var awaitFloorReset;
var existHTML = false;
var battleFrontFloor;
var bfOneClickState;
var bfOneClickColor;
var bpImg = `<img src="assets/images/currency/battlePoint.svg" height="25px">`
var moneyImg = `<img src="assets/images/currency/money.svg" height="25px">`
function initBattleFrontier() {
addGlobalStyle('#battle-front-cont { position:absolute;right:5px;top:5px;width:auto;height:41px; }');
addGlobalStyle('#bf-one-click-btn { position:absolute;left:5px;top:5px;width:auto;height:41px; }');
const middleCol = document.getElementById('middle-column');
//If you initially load the game and are at the Battle Frontier entry, to keep things smooth
checkBattleFrontierEntry();
middleCol.addEventListener('click', event => {
checkBattleFrontierEntry();
if (BattleFrontierRunner.started() && existHTML) {
//console.log("already started")
}
if (BattleFrontierRunner.started() && !existHTML) {
existHTML = true;
createHTML();
floorReset();
//console.log("starting")
}
});
function checkBattleFrontierEntry() {
const bfEnter = $( "button:contains('Enter Battle Frontier')" );
if (bfEnter.is(":visible")) {
bfEnter[0].addEventListener('click', () => {
modifyBattleFrontier();
});
}
}
function modifyBattleFrontier() {
const middleCol = document.getElementById('middle-column');
const bfStartNew = middleCol.querySelector('[onclick="BattleFrontierRunner.start(false)"]');
bfStartNew.setAttribute('onclick', 'BattleFrontierRunner.start(true)');
bfStartNew.textContent = 'Start (Stage: 0)';
}
function floorReset() {
awaitFloorReset = setInterval(function () {
if (BattleFrontierRunner.started()) {
if(bfOneClickState === "ON") {
oneClick();
} else {
if (BattleFrontierRunner.stage() > battleFrontFloor && battleFrontFloor > 0) {
battleReset();
BattleFrontierRunner.stage(1);
}
}
} else {
existHTML = false;
document.getElementById('battle-front-cont').remove();
document.getElementById('bf-one-click-btn').remove();
clearInterval(awaitFloorReset);
}
}, 50);
}
function createHTML() {
if (bfOneClickState == "OFF") {
bfOneClickColor = "danger"
} else {
bfOneClickColor = "success"
}
const battleFrontInfo = document.getElementById('battleFrontierInformation');
const battleFrontTitle = battleFrontInfo.querySelector('div');
const oneClickBtn = document.createElement("div");
oneClickBtn.setAttribute("id", "bf-one-click-btn");
oneClickBtn.innerHTML = `<button id="bf-one-click-start" class="btn btn-block btn-`+ bfOneClickColor + `" style="font-size: 8pt;">One Click Attack [`+ bfOneClickState + `]</button>`
oneClickBtn.addEventListener('click', event => { toggleOneClick() })
const bfInput = document.createElement("div");
bfInput.setAttribute("id", "battle-front-cont");
bfInput.innerHTML = `Max Stage: <input id="battle-front-input" style="width: 70px;"> <button id="battle-front-input-submit" class="btn btn-block btn-danger" style="font-size: 8pt; width: 42px; display:inline-block;">OK</button>`
battleFrontTitle.before(bfInput);
battleFrontTitle.before(oneClickBtn);
document.getElementById('battle-front-input').value = battleFrontFloor.toLocaleString('en-US');
document.querySelector('#battle-front-input-submit').addEventListener('click', event => {
battleFrontFloor = +document.getElementById('battle-front-input').value.replace(/[A-Za-z!@#$%^&*()]/g, '').replace(/[,]/g, "");
localStorage.setItem("battleFrontFloor", battleFrontFloor);
document.getElementById('battle-front-input').value = battleFrontFloor.toLocaleString('en-US');
});
const bfQuit = battleFrontInfo.querySelector('[onclick="BattleFrontierRunner.battleQuit()"]');
bfQuit.setAttribute('onclick', 'BattleFrontierRunner.end()');
bfQuit.addEventListener('click', () => {modifyBattleFrontier();});
}
function battleReset() {
// Current stage - 1 as the player didn't beat the current stage
var stageBeaten = BattleFrontierRunner.stage() - 1;
if (stageBeaten > 0) {
// Give Battle Points and Money based on how far the user got
var battleMultiplier = Math.max(stageBeaten / 100, 1);
var battlePointsEarned = Math.round(stageBeaten * battleMultiplier);
var moneyEarned = stageBeaten * 100 * battleMultiplier;
//notification popup
Notifier.notify({
title: 'Battle Frontier',
message: `You managed to beat stage ` + stageBeaten + `.<br/>You received ` + bpImg + battlePointsEarned.toLocaleString() + ` BP<br>You recieved ` + moneyImg + moneyEarned.toLocaleString() + ` money.`,
type: NotificationConstants.NotificationOption.success,
});
// Award battle points and money
App.game.wallet.gainBattlePoints(battlePointsEarned);
App.game.wallet.gainMoney(moneyEarned);
}
}
function toggleOneClick() {
if (bfOneClickState == "OFF") {
bfOneClickState = "ON"
document.getElementById("bf-one-click-start").classList.remove('btn-danger');
document.getElementById("bf-one-click-start").classList.add('btn-success');
} else {
bfOneClickState = "OFF"
document.getElementById("bf-one-click-start").classList.remove('btn-success');
document.getElementById("bf-one-click-start").classList.add('btn-danger');
}
localStorage.setItem("bfOneClickState", bfOneClickState);
document.getElementById('bf-one-click-start').innerHTML = `One Click [` + bfOneClickState + `]`
}
function oneClick() {
if(Battle.enemyPokemon().maxHealth() > App.game.party.calculatePokemonAttack(
Battle.enemyPokemon().type1,
Battle.enemyPokemon().type2, true,)
) {
battleReset();
BattleFrontierRunner.stage(1);
}
}
}
if (localStorage.getItem('battleFrontFloor') == null) {
localStorage.setItem("battleFrontFloor", 0);
}
if (localStorage.getItem('bfOneClickState') == null) {
localStorage.setItem("bfOneClickState", "OFF");
}
battleFrontFloor = +localStorage.getItem('battleFrontFloor');
bfOneClickState = localStorage.getItem('bfOneClickState');
function loadScript(){
var oldInit = Preload.hideSplashScreen
Preload.hideSplashScreen = function(){
var result = oldInit.apply(this, arguments)
initBattleFrontier()
return result
}
}
var scriptName = 'autobattlefrontier'
if (document.getElementById('scriptHandler') != undefined){
var scriptElement = document.createElement('div')
scriptElement.id = scriptName
document.getElementById('scriptHandler').appendChild(scriptElement)
if (localStorage.getItem(scriptName) != null){
if (localStorage.getItem(scriptName) == 'true'){
loadScript()
}
}
else{
localStorage.setItem(scriptName, 'true')
loadScript()
}
}
else{
loadScript();
}
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}