-
Notifications
You must be signed in to change notification settings - Fork 3
/
Automation.js
115 lines (90 loc) · 3.2 KB
/
Automation.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
// Load Garden Helper
Game.LoadMod('https://rawgit.com/yannprada/cookie-garden-helper/master/cookie-garden-helper.js');
// Stop runAllAutomation
clearInterval(runAllAutomation);
// Stops the machine from marching forward.
clearInterval(StonkManager);
// Get current resource averages. Run whenever curious. Displays Ticker Symbol, % Change In Last Tick, Current Average in console.
for (i = 0; i < resourceAverage.length; i++) {
console.log(document.querySelector("#bankGood-" + i + " > div:nth-child(1) > div:nth-child(2)").innerText + " " + resourceAverage[i]);
}
// Begins tracking the number of ticks which have occurred since starting the script. Useful for long averages.
var ticks = 1;
// Initializes resource values for averaging over time
var resourceAverage = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
for (i = 0; i < resourceAverage.length; i++) {
var currValDollar = document.querySelector("#bankGood-" + i + "-val").innerText;
var currVal = 1*currValDollar.substring(1);
resourceAverage[i] = currVal;
}
//These set how wide a swing in price you want.
// The multiplier for the max price to buy. Will be multiplied against running average price.
var buyMaxMult = .8;
// The multiplier for min price to sell. Will be multiplied against running average price.
var sellMinMult = 1.2;
// Begin the machine!
// Begin the machine!
// Begin the machine!
// Begin the machine!
function autoClick() {
// Click big cookie
document.getElementById('bigCookie').click();
// Click golden cookie
for (var h in Game.shimmers){
if(Game.shimmers[h].type=="golden" || Game.shimmers[h].type=="reindeer"){
Game.shimmers[h].pop();
}
}
// Buy Elder Pledge
if (!Game.Upgrades["Elder Pledge"].bought)
Game.Upgrades["Elder Pledge"].buy();
}
// This function is the master which repeats the commands below;
var runAllAutomation = setInterval(function() {
autoClick()
}, .05);
// Timer for Stonks
var StonkManager = setInterval(function() {
Stonks();
}, 1000);
// Controller
function Stonks(){
if (document.querySelector("#bankNextTick").innerText == "Next tick in 55 seconds.") {
if (ticks < 2000) {ticks++};
updateAverages(ticks);
if (ticks > 10) {BuySell()};
}
};
// Updates the knowledge of the stock's averages over time
function updateAverages(ticks){
var i;
for (i = 0; i < resourceAverage.length; i++) {
var currValDollar = document.querySelector("#bankGood-" + i + "-val").innerText;
var currVal = 1*currValDollar.substring(1);
resourceAverage[i] = (currVal - resourceAverage[i]) * (1 / ticks) + resourceAverage[i];
}
};
// Controls the Buy/Sell logic.
function BuySell(){
var i;
for (i = 0; i < resourceAverage.length; i++) {
var currValDollar = document.querySelector("#bankGood-" + i + "-val").innerText;
var currVal = 1*currValDollar.substring(1);
if (currVal < (resourceAverage[i] * buyMaxMult)) {
buyResource(i);
}
else if (currVal > (resourceAverage[i] * sellMinMult)) {
sellResource(i);
}
else {
}
}
};
// Purchases a resource
function buyResource(resNum){
document.querySelector("#bankGood-" + resNum + "_Max").click();
};
// Sells a resource
function sellResource(resNum){
document.querySelector("#bankGood-" + resNum + "_-All").click();
};