forked from ensingm2/SteamMonsterGameScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautomator.js
309 lines (252 loc) · 7.96 KB
/
automator.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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
// Compiled and costomized by reddit user /u/therusher
// Credit to reddit users /u/leandr0c and /u/kolodz for additional code
// Custom variables
var debug = false;
var clicksPerSecond = 100;
var autoClickerVariance = Math.floor(clicksPerSecond / 10);
var respawnCheckFreq = 5000;
var targetSwapperFreq = 1000;
var abilityUseCheckFreq = 2000;
var itemUseCheckFreq = 5000;
//item use variables
var useMedicsAtPercent = 30;
var useNukeOnSpawnerAbovePercent = 75;
// You shouldn't need to ever change this, you only push to server every 1s anyway
var autoClickerFreq = 1000;
// variables to store the setIntervals
var autoRespawner, autoClicker, autoTargetSwapper, autoAbilityUser, autoItemUser;
// ================ STARTER FUNCTIONS ================
function startAutoClicker() {
if(autoClicker) {
console.log("Autoclicker is already running!");
return;
}
autoClicker = setInterval( function(){
//Vary the number of clicks by up to the autoClickerVariance variable (plus or minus)
var randomVariance = Math.floor(Math.random() * autoClickerVariance * 2) - (autoClickerVariance);
var clicks = clicksPerSecond + randomVariance;
//Set the variable to be sent to the server
g_Minigame.m_CurrentScene.m_nClicks = clicks;
if(debug)
console.log('Clicking ' + clicks + ' times this second.');
}, autoClickerFreq);
console.log("autoClicker has been started.");
}
function startAutoRespawner() {
if(autoRespawner) {
console.log("autoRespawner is already running!");
return;
}
autoRespawner = setInterval( function(){
if(debug)
console.log('Checking if the player is dead.');
// Credit to /u/kolodz for base code. http://www.reddit.com/r/SteamMonsterGame/comments/39joz2/javascript_auto_respawn/
if(g_Minigame.m_CurrentScene.m_bIsDead) {
if(debug)
console.log('Player is dead. Respawning.');
RespawnPlayer();
}
}, respawnCheckFreq);
console.log("autoRespawner has been started.");
}
function startAutoTargetSwapper() {
if(autoTargetSwapper) {
console.log("autoTargetSwapper is already running!");
return;
}
autoTargetSwapper = setInterval(function() {
var target = null;
g_Minigame.m_CurrentScene.m_rgEnemies.each(function(mob){
//No target yet
if(!target)
target = mob;
//different type, prioritize by type (treasure > boss > miniboss > spawner > creep)
// 0 - Spawner
// 1 - Creeps
// 2 - Boss
// 3 - MiniBoss
// 4 - Treasure Mob
//(why are the types so disorganized?)
else if(mob.m_data.type == target.m_data.type) {
// Treasure Mob
if(mob.m_data.type == 4)
target = mob;
//Boss (?)
else if(mob.m_data.type == 2 && target.m_data.type != 3 && target.m_data.type != 0 )
target = mob;
//MiniBoss (?)
if(mob.m_data.type == 3 && target.m_data.type < 2)
target = mob;
// Spawner
else if(mob.m_data.type == 0)
target = mob;
//Creeps should never be targeted by this block
}
//Same type, prioritize by health remaining
else if(target.m_data.hp < mob.m_data.hp)
target = mob;
});
//Switch to that target
if(target){
g_Minigame.m_CurrentScene.m_rgPlayerData.current_lane != target.m_nLane && g_Minigame.CurrentScene().TryChangeLane(target.m_nLane);
g_Minigame.CurrentScene().TryChangeTarget(target.m_nID);
}
}, targetSwapperFreq);
console.log("autoTargetSwapper has been started.");
}
function startAutoAbilityUser() {
if(autoAbilityUser) {
console.log("autoAbilityUser is already running!");
return;
}
autoAbilityUser = setInterval(function() {
if(debug)
console.log("Checking if it's useful to use an ability.");
var percentHPRemaining = g_Minigame.CurrentScene().m_rgPlayerData.hp / g_Minigame.CurrentScene().m_rgPlayerTechTree.max_hp * 100;
var target = g_Minigame.m_CurrentScene.m_rgEnemies[g_Minigame.m_CurrentScene.m_rgPlayerData.target];
var targetPercentHPRemaining;
if(target)
targetPercentHPRemaining = target.m_data.hp / target.m_data.max_hp * 100;
// Morale Booster
if(hasAbility(5)) {
// TODO: Implement this
}
// Good Luck Charm
if(hasAbility(6)) {
// TODO: Implement this
}
// Medics
if(percentHPRemaining <= useMedicsAtPercent && !g_Minigame.m_CurrentScene.m_bIsDead) {
if(debug)
console.log("Health below threshold. Need medics!");
// TODO: Only use if there isn't already a Medics active?
if(hasAbility(7)) {
if(debug)
console.log("Unleash the medics!");
castAbility(7);
}
else if(debug)
console.log("No medics to unleash!");
}
// Metal Detector
if(hasAbility(8)) {
// TODO: Implement this
}
// Decrease Cooldowns
if(hasAbility(9)) {
// TODO: Any logic to using this?
if(debug)
console.log('Decreasing cooldowns.');
// TODO: make sure one's not active already
castAbility(9);
}
// Tactical Nuke
if(target && target.m_data.type == 0 && targetPercentHPRemaining >= useNukeOnSpawnerAbovePercent) {
// TODO: make sure no other nuke is active
if(hasAbility(10)) {
if(debug)
console.log('Nuclear launch detected.');
castAbility(10);
}
}
// Cluster Bomb
if(hasAbility(11)) {
// TODO: Implement this
}
// Napalm
if(hasAbility(12)) {
// TODO: Implement this
}
}, abilityUseCheckFreq);
console.log("autoAbilityUser has been started.");
}
function startAutoItemUser() {
if(autoItemUser) {
console.log("autoItemUser is already running!");
return;
}
autoItemUser = setInterval(function() {
if(debug)
console.log("Checking if it's useful to use an item.");
// TODO: Implement This
}, itemUseCheckFreq);
console.log("autoItemUser has been started.");
}
function startAllAutos() {
startAutoClicker();
startAutoRespawner();
startAutoTargetSwapper();
startAutoAbilityUser();
startAutoItemUser();
}
// ================ STOPPER FUNCTIONS ================
function stopAutoClicker() {
if(autoClicker) {
clearInterval(autoClicker);
autoClicker = null;
console.log("autoClicker has been stopped.");
}
else
console.log("No autoClicker is running to stop.");
}
function stopAutoRespawner() {
if(autoRespawner) {
clearInterval(autoRespawner);
autoRespawner = null;
console.log("autoRespawner has been stopped.");
}
else
console.log("No autoRespawner is running to stop.");
}
function stopAutoTargetSwapper() {
if(autoTargetSwapper){
clearInterval(autoTargetSwapper);
autoTargetSwapper = null;
console.log("autoTargetSwapper has been stopped.");
}
else
console.log("No autoTargetSwapper is running to stop.");
}
function stopAutoAbilityUser() {
if(autoAbilityUser){
clearInterval(autoAbilityUser);
autoAbilityUser = null;
console.log("autoAbilityUser has been stopped.");
}
else
console.log("No autoAbilityUser is running to stop.");
}
function stopAutoItemUser() {
if(autoItemUser){
clearInterval(autoItemUser);
autoItemUser = null;
console.log("autoItemUser has been stopped.");
}
else
console.log("No autoItemUser is running to stop.");
}
function stopAllAutos() {
stopAutoClicker();
stopAutoRespawner();
stopAutoTargetSwapper();
stopAutoAbilityUser();
stopAutoItemUser();
}
function disableAutoNukes() {
useNukeOnSpawnerAbovePercent = 200;
console.log('Automatic nukes have been disabled');
}
// ================ HELPER FUNCTIONS ================
function castAbility(abilityID) {
if(hasAbility(abilityID))
g_Minigame.CurrentScene().TryAbility(document.getElementById('ability_' + abilityID).childElements()[0]);
}
// thanks to /u/mouseasw for the base code: https://github.com/mouseas/steamSummerMinigame/blob/master/autoPlay.js
function hasAbility(abilityID) {
// each bit in unlocked_abilities_bitfield corresponds to an ability.
// the above condition checks if the ability's bit is set or cleared. I.e. it checks if
// the player has purchased the specified ability.
return ((1 << abilityID) & g_Minigame.CurrentScene().m_rgPlayerTechTree.unlocked_abilities_bitfield) && g_Minigame.CurrentScene().GetCooldownForAbility(abilityID) <= 0;
}
//Start all autos
startAllAutos();