-
Notifications
You must be signed in to change notification settings - Fork 1
/
testing.js
203 lines (187 loc) · 6.16 KB
/
testing.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
window.$ = $;
window.keepClicking = 1;
window.keepClickingWait = 10;
function autoclickCookie() {
window.$("#bigCookie").click();
if (window.keepClicking) {
setTimeout(autoclickCookie, window.keepClickingWait);
}
};
window.keepClickingGolden = 1;
function autoclickGolden() {
let waitTime = 10;
if ($(".shimmer") != null) {
const image = $(".shimmer").style.backgroundImage
if (image.indexOf("goldCookie") > 0) {
console.log(`Clicking shimer ${image} at ${new Date()}`);
$(".shimmer").click();
} else if (image.indexOf("wrathCookie") > 0) {
console.log(`Clicking shimer ${image} at ${new Date()}`);
$(".shimmer").click();
} else if (image.indexOf("frostedReindeer") > 0) {
console.log(`Clicking shimer ${image} at ${new Date()}`);
$(".shimmer").click();
} else {
console.log(`Clicking unexpected shimmer ${image} at ${new Date()}`);
$(".shimmer").click();
}
} else {
waitTime = 1000;
// console.log(`No Golden Cookie at ${new Date()}`);
}
if (window.keepClickingGolden) {
setTimeout(autoclickGolden, waitTime);
}
}
function earlyBuyBonus(x, y) {
const cps = y.storedCps * Game.globalCpsMult;
return (x.bulkPrice - y.bulkPrice) * cps / Game.cookiesPs
}
function bestEarlyBuyBonusItem(x) {
let bestBonus = undefined;
const objs = window.Game.ObjectsById;
let i = 0;
for (i = 0; i < objs.length; i++) {
const obj = objs[i];
if (!obj.locked && (obj.bulkPrice < x.bulkPrice)) {
if (bestBonus == undefined || (earlyBuyBonus(x, bestBonus) < earlyBuyBonus(x, obj))) {
bestBonus = obj;
}
}
}
return bestBonus;
}
function bestEarlyBuyBonus(x) {
let bestBonus = 0;
const objs = window.Game.ObjectsById;
let i = 0;
for (i = 0; i < objs.length; i++) {
const obj = objs[i];
if (!obj.locked && (obj.bulkPrice < x.bulkPrice)) {
if (bestBonus < earlyBuyBonus(x, obj)) {
bestBonus = earlyBuyBonus(x, obj);
}
}
}
return bestBonus;
}
function payback(obj) {
const cps = obj.storedCps * Game.globalCpsMult;
const bestBonus = bestEarlyBuyBonus(obj);
const payb = (obj.bulkPrice + bestBonus) / cps;
// console.log(`obj ${obj.name}, bestBonus ${bestBonus}, raw payback ${obj.bulkPrice / cps}, payback ${payb}`);
return payb;
}
function payback_v(obj) {
const cps = obj.storedCps * Game.globalCpsMult;
const bestBonus = bestEarlyBuyBonus(obj);
const payb = (obj.bulkPrice + bestBonus) / cps;
console.log(`obj ${obj.name}, bestBonus ${bestBonus}, raw payback ${obj.bulkPrice}/${cps} = ${obj.bulkPrice / cps}, payback ${payb}`);
return payb;
}
function bestvalue() {
const objs = window.Game.ObjectsById;
let best = undefined;
let i = 0;
for (i = 0; i < objs.length; i++) {
const obj = objs[i];
const cps = obj.storedCps * Game.globalCpsMult;
const payb = obj.bulkPrice / cps
// console.log(`${obj.name} produces ${cps}, costs ${obj.bulkPrice}, islocked ${obj.locked}, payback ${payb}, i ${i}, len ${objs.length}`);
if (!obj.locked) {
if ((best == undefined) || (payback(obj) < payback(best))) {
best = obj;
}
}
}
// console.log(`best: ${best.name}, payback ${payback(best)}`)
return best;
}
function upgradeEquivalentCps(u) {
if (u.buildingTie) {
return u.buildingTie.storedTotalCps * Game.globalCpsMult;
}
if (u.pool === "cookie") {
return Game.cookiesPs * u.power / 100;
}
return 0;
}
function upgradePayback(obj) {
const cps = upgradeEquivalentCps(obj);
const payb = obj.getPrice() / cps;
// console.log(`obj ${obj.name}, bestBonus ${bestBonus}, raw payback ${obj.bulkPrice / cps}, payback ${payb}`);
return payb;
}
function upgradePayback_v(obj) {
const cps = upgradeEquivalentCps(obj);
const payb = obj.getPrice() / cps;
console.log(`obj ${obj.name}, raw payback ${obj.getPrice()}/${cps} = ${obj.bulkPrice / cps}, payback ${payb}`);
return payb;
}
function bestupgrade() {
const objs = window.Game.UpgradesInStore.filter(u => upgradeEquivalentCps(u) > 0);
let best = undefined;
let i = 0;
for (i = 0; i < objs.length; i++) {
const obj = objs[i];
if ((best == undefined) || (upgradePayback(obj) < upgradePayback(best))) {
best = obj;
}
}
// console.log(`best upgrade: ${best.name}, payback ${upgradePayback(best)}`)
return best;
}
function shorten(n) {
}
window.keepBuying = 1;
function prettySeconds(seconds) {
function fmt(n,u) {
return `${n.toFixed(2)} ${u}`;
}
if (seconds < 60) {
return fmt(seconds, 'seconds');
}
const minutes = seconds / 60;
if (minutes < 60) {
return fmt(minutes, 'minutes');
}
const hours = minutes / 60;
if (hours < 24) {
return fmt(hours, 'hours');
}
const days = hours/ 24;
if (days < 7) {
return fmt(days, 'days');
}
const weeks = days / 7;
if (weeks < 52) {
return fmt(weeks, 'weeks');
}
const years = days/365;
return fmt(years, 'years');
}
function autobuy() {
const bestobj = bestvalue();
const bestup = bestupgrade();
function summary() {
const bo = bestobj?`${bestobj.name} ${prettySeconds(payback(bestobj))}`:'no object';
const bu = bestup?`${bestup.name} ${prettySeconds(upgradePayback(bestup))}`:'no upgrade';
return `${bo} vs ${bu}`;
}
const bestv = bestup?(bestobj?(
payback(bestobj) < upgradePayback(bestup)?bestobj:bestup
):bestup):bestobj;
const otherv = bestv === bestup?bestobj: bestup;
let waitTime = 1000;
const price = bestv.bulkPrice == undefined?bestv.getPrice():bestv.bulkPrice;
if (price < Game.cookies) {
console.log(`buying ${bestv.name} at ${new Date() } (${summary()})`);
bestv.buy();
waitTime = 100;
} else {
console.log(`can't afford ${bestv.name}`);
}
if (window.keepBuying) {
setTimeout(autobuy, waitTime);
}
}