forked from wchill/steamSummerMinigame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautoPlay.js
153 lines (128 loc) · 4.95 KB
/
autoPlay.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
var clickRate = 20; // change to number of desired clicks per second
var isAlreadyRunning = false;
var myMaxHealth = 0;
function doTheThing() {
if (isAlreadyRunning || g_Minigame === undefined) {
return;
}
isAlreadyRunning = true;
goToLaneWithLowest();
useMedicsIfRelevant();
// TODO use abilities if available and a suitable target exists
// - Tactical Nuke on a Spawner if below 50% and above 25% of its health
// - Cluster Bomb and Napalm if the current lane has a spawner and 2+ creeps
// - Good Luck if available
// - Metal Detector if a spawner death is imminent (predicted in > 2 and < 7 seconds)
// - Morale Booster if available and lane has > 2 live enemies
// - Decrease Cooldowns if another player used a long-cooldown ability < 10 seconds ago
// TODO purchase abilities and upgrades intelligently
// TODO click the current target a few times (<= 10/sec, so as not to cheat)
// TODO respawn if dead and respawn button is available
isAlreadyRunning = false;
}
function goToLaneWithLowest() {
// TODO check if it's a boss level, handle boss levels differently
// TODO prefer lane with a dying creep as long as all living spawners have >50% health
// determine which living spawner has lowest hp
var spawners = [];
for (var i = 0; i < 3; i++) {
for (var j = 0; j < 4; j++) {
var enemy = g_Minigame.CurrentScene().GetEnemy(i, j);
if (enemy && enemy.GetName() == 'Spawner') {
spawners[spawners.length] = g_Minigame.CurrentScene().GetEnemy(i, j);
}
}
}
var lowHP = 0;
var lowLane = 0;
var lowTarget = 0;
for (var i = 0; i < spawners.length; i++) {
if(spawners[i] && !spawners[i].m_bIsDestroyed) {
if(lowHP < 1 || spawners[i].m_flDisplayedHP < lowHP) {
lowHP = spawners[i].m_flDisplayedHP;
lowLane = spawners[i].m_nLane;
lowTarget = spawners[i].m_nID;
}
}
}
// if no spawners remain, determine which lane has a creep with the lowest health
if (lowHP < 1) {
// determine which living creep has the lowest hp
var creeps = [];
for (var i = 0; i < 3; i++) {
for (var j = 0; j < 4; j++) {
var enemy = g_Minigame.CurrentScene().GetEnemy(i, j);
if (enemy && enemy.m_data.type == 1) {
creeps[creeps.length] = g_Minigame.CurrentScene().GetEnemy(i, j);
}
}
}
for (var i = 0; i < creeps.length; i++) {
if (creeps[i] && !creeps[i].m_bIsDestroyed) {
if (lowHP < 1 || creeps[i].m_flDisplayedHP < lowHP) {
lowHP = creeps[i];
lowLane = creeps[i].m_nLane;
lowTarget = creeps[i].m_nID;
}
}
}
}
// go to the chosen lane
if (g_Minigame.CurrentScene().m_nExpectedLane != lowLane) {
//console.log('switching langes');
g_Minigame.CurrentScene().TryChangeLane(lowLane);
}
// target the chosen enemy
if (g_Minigame.CurrentScene().m_nTarget != lowTarget) {
//console.log('switching targets');
g_Minigame.CurrentScene().TryChangeTarget(lowTarget);
}
}
function useMedicsIfRelevant() {
// regularly check HP to try to determine max health (I haven't found the variable for it yet)
if (g_Minigame.CurrentScene().m_rgPlayerData.hp > myMaxHealth) {
myMaxHealth = g_Minigame.CurrentScene().m_rgPlayerData.hp
}
// check if health is below 50%
var hpPercent = g_Minigame.CurrentScene().m_rgPlayerData.hp / myMaxHealth;
if (hpPercent > 0.5) {
return; // no need to heal - HP is above 50%
}
// check if Medics is purchased and cooled down
if ((1 << 7) & g_Minigame.CurrentScene().m_rgPlayerTechTree.unlocked_abilities_bitfield) {
// each bit in unlocked_abilities_bitfield corresponds to an ability. Medics is ability 7.
// the above condition checks if the Medics bit is set or cleared. I.e. it checks if
// the player has the Medics ability.
var abilitiesInCooldown = g_Minigame.CurrentScene().m_rgPlayerData.active_abilities;
for (var i = 1; i < abilitiesInCooldown.length; i++) {
if (abilitiesInCooldown[i].ability == 7) {
return; // Medics is in cooldown, can't use it.
}
}
// Medics is purchased, cooled down, and needed. Trigger it.
console.log('Medics is purchased, cooled down, and needed. Trigger it.');
if (document.getElementById('ability_7')) {
g_Minigame.CurrentScene().TryAbility(document.getElementById('ability_7').childElements()[0]);
}
}
}
var thingTimer = window.setInterval(doTheThing, 1000);
function clickTheThing() {
g_Minigame.m_CurrentScene.DoClick(
{
data: {
getLocalPosition: function() {
var enemy = g_Minigame.m_CurrentScene.GetEnemy(
g_Minigame.m_CurrentScene.m_rgPlayerData.current_lane,
g_Minigame.m_CurrentScene.m_rgPlayerData.target),
laneOffset = enemy.m_nLane * 440;
return {
x: enemy.m_Sprite.position.x - laneOffset,
y: enemy.m_Sprite.position.y - 52
}
}
}
}
);
}
var clickTimer = window.setInterval(clickTheThing, 1000/clickRate);