This repository has been archived by the owner on Jul 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
salienGameBot.user.js
287 lines (253 loc) · 7.45 KB
/
salienGameBot.user.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
// ==UserScript==
// @name SalienGame Bot
// @namespace https://github.com/starise/saliengame-bot
// @version 0.0.7
// @author starise
// @match *://steamcommunity.com/saliengame/*
// @grant none
// @downloadURL https://raw.githubusercontent.com/starise/saliengame-bot/master/salienGameBot.user.js
// @updateURL https://raw.githubusercontent.com/starise/saliengame-bot/master/salienGameBot.user.js
// ==/UserScript==
(function(context) {
const pixi = gApp;
const GAME = gGame;
const SERVER = gServer;
const SetMouse = function SetMouse(x, y) {
pixi.renderer.plugins.interaction.mouse.global.x = x;
pixi.renderer.plugins.interaction.mouse.global.y = y;
}
const EnemyManager = function EnemyManager() {
return GAME.m_State.m_EnemyManager;
}
const AttackManager = function AttackManager() {
return GAME.m_State.m_AttackManager;
}
const TryContinue = function Continue() {
let continued = false;
if (GAME.m_State.m_VictoryScreen) {
GAME.m_State.m_VictoryScreen.children.forEach(function(child) {
if (child.visible && child.x == 155 && child.y == 300) {// TODO: not this
continued = true;
child.pointertap();
}
})
}
if (GAME.m_State.m_LevelUpScreen) {
continued = false;
GAME.m_State.m_LevelUpScreen.children.forEach(function(child) {
if (child.visible && child.x == 155 && child.y == 300) {// TODO: not this
continued = true;
child.pointertap();
}
})
}
return continued;
}
const CanAttack = function CanAttack(attackname) {
let Manager = AttackManager().m_mapCooldowns.get(attackname);
let lastUsed = Manager.m_rtAttackLastUsed;
let canAttack = Manager.BAttack();
Manager.m_rtAttackLastUsed = lastUsed;
return canAttack;
}
// Let's challenge ourselves to be human here!
const CLICKS_PER_SECOND = 10;
const InGame = function InGame() {
return GAME.m_State.m_bRunning;
}
const InZoneSelect = function InZoneSelect() {
return GAME.m_State instanceof CBattleSelectionState;
}
const WORST_SCORE = -1 / 0;
const START_POS = pixi.renderer.width;
// context.lastZoneIndex;
let isJoining = false;
const EnemySpeed = function EnemySpeed(enemy) {
return enemy.m_Sprite.vx;
}
const EnemyDistance = function EnemyDistance(enemy) {
return (enemy.m_Sprite.x - k_nDamagePointx) / (START_POS - k_nDamagePointx);
}
const AimPoint = function AimPoint(enemy) {
return [
enemy.m_Sprite.x + enemy.m_Sprite.width / 2 + (EnemySpeed(enemy) * 20),
enemy.m_Sprite.y + enemy.m_Sprite.height / 2
];
}
class Attack {
constructor() {
this.nextAttackDelta = 0;
}
shouldAttack(delta, enemies) {
throw new Error("shouldAttack not implemented");
}
process(enemies) {
throw new Error("process not implemented");
}
getAttackName() {
throw new Error("no current attack name");
}
canAttack() {
return CanAttack(this.getAttackName());
}
getAttackData() {
return AttackManager().m_AttackData[this.getAttackName()];
}
}
// Basic clicking attack, attack closest
class ClickAttack extends Attack {
shouldAttack(delta) {
// Can't do basic attack when station is down
if (GAME.m_State.m_PlayerHealth <= 0)
return false;
this.nextAttackDelta -= delta;
return this.nextAttackDelta <= 0;;
}
score(enemy) {
if (enemy.m_bDead)
return WORST_SCORE;
return 1 - EnemyDistance(enemy);
}
process(enemies) {
let target, target_score = WORST_SCORE;
enemies.forEach((enemy) => {
if (!enemy.m_Sprite.visible)
return;
let now_score = this.score(enemy);
if (now_score > target_score) {
target = enemy, target_score = now_score;
}
});
if (target)
this.attack(target);
}
attack(enemy) {
enemy.m_Sprite.pointertap();
this.nextAttackDelta = 1 / CLICKS_PER_SECOND;
}
}
class ProjectileAttack extends Attack {
shouldAttack(delta) {
return CanAttack(this.getAttackName());
}
score(enemy) {
if (enemy.m_bDead)
return WORST_SCORE;
return enemy.m_nHealth;
}
process(enemies) {
let target, target_score = WORST_SCORE;
enemies.forEach((enemy) => {
if (!enemy.m_Sprite.visible)
return;
let now_score = this.score(enemy);
if (now_score > target_score) {
target = enemy, target_score = now_score;
}
});
if (target)
this.attack.apply(this, AimPoint(target));
}
attack(x, y) {
SetMouse(x, y)
AttackManager().m_mapKeyCodeToAttacks.get(this.getAttackData().keycode)()
}
}
// the '1' button (SlimeAttack PsychicAttack BeastAttack - depends on body type of your salien)
class SpecialAttack extends ProjectileAttack {
getAttackName() {
if (gSalien.m_BodyType == "slime")
return "slimeattack";
else if (gSalien.m_BodyType == "beast")
return "beastattack";
else
return "psychicattack";
}
}
class BombAttack extends ProjectileAttack {
getAttackName() {
return "explosion";
}
}
class BlackholeAttack extends ProjectileAttack {
getAttackName() {
return "blackhole";
}
}
class MeteorAttack extends ProjectileAttack {
getAttackName() {
return "boulder";
}
}
class FreezeAttack extends Attack {
getCurrent() {
return "flashfreeze";
}
shouldAttack(delta, enemies) {
let shouldAttack = false;
if (CanAttack(this.getCurrent())) {
enemies.forEach((enemy) => {
if (EnemyDistance(enemy) <= 0.05) {
shouldAttack = true;
}
});
}
return shouldAttack;
}
getData() {
return AttackManager().m_AttackData[this.getCurrent()];
}
process() {
AttackManager().m_mapKeyCodeToAttacks.get(this.getData().keycode)()
}
}
let attacks = [
new ClickAttack(),
new SpecialAttack(),
new FreezeAttack(),
new BombAttack(),
new BlackholeAttack(),
new MeteorAttack()
]
if (context.BOT_FUNCTION) {
pixi.ticker.remove(context.BOT_FUNCTION);
context.BOT_FUNCTION = undefined;
}
context.BOT_FUNCTION = function ticker(delta) {
delta /= 100;
if(GAME.m_IsStateLoading) {
return;
}
if (InZoneSelect() && context.lastZoneIndex !== undefined && !isJoining) {
isJoining = true;
if (GAME.m_State.m_PlanetData.zones[context.lastZoneIndex].captured)
{
context.lastZoneIndex = undefined;
return;
}
SERVER.JoinZone(
lastZoneIndex,
function (results) {
GAME.ChangeState(new CBattleState(GAME.m_State.m_PlanetData, context.lastZoneIndex));
},
GameLoadError
);
return;
}
33
if (!InGame()) {
if (TryContinue()) {
console.log("continued!");
}
return;
}
isJoining = false;
context.lastZoneIndex = GAME.m_State.m_unZoneIndex;
let state = EnemyManager();
let enemies = state.m_mapEnemies;
for (let attack of attacks)
if (attack.shouldAttack(delta, enemies))
attack.process(enemies);
}
pixi.ticker.add(context.BOT_FUNCTION);
})(window);