Skip to content

Commit 037b35f

Browse files
committed
Add: Waiting time for deals
1 parent 9b14fce commit 037b35f

File tree

4 files changed

+44
-10
lines changed

4 files changed

+44
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9-
## [2042.10] - 2021-09-19
9+
## [2042.11] - 2021-09-19
1010
### Added
11-
- Add: nested pre-deal finder
11+
- Add: Highlight pre-deal that can advance best-deal waiting time.
12+
- Add: Waiting time for deals.
1213

1314
### Changed
1415
- Change: calc deltaTime from price / deltaCps
1516

17+
## [2042.10] - 2021-09-19
1618
### Fixed
1719
- Ignore toggle type upgrades
1820

RELEASE.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
## [2042.10] - 2021-09-19
2-
### Fixed
3-
- Ignore toggle type upgrades
1+
## [2042.11] - 2021-09-19
2+
### Added
3+
- Add: Highlight pre-deal that can advance best-deal waiting time.
4+
- Add: Waiting time for deals.
5+
6+
### Changed
7+
- Change: calc deltaTime from price / deltaCps

info.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"ID": "Best Deal Helper",
44
"Author": "Jethro Yu",
55
"Description": "Help you choose best deal!",
6-
"ModVersion": 2042.10,
6+
"ModVersion": 2042.11,
77
"GameVersion": 2.042,
88
"Date": "19/09/2021",
99
"Dependencies": ["CCSE"],

main.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ let BestDealHelper = {
194194
if (me.price > Game.cookies) {
195195
me.timeToTargetCookie = (me.price - Game.cookies) / Game.cookiesPs + target.price / me.newCookiesPs;
196196
} else {
197-
me.timeToTargetCookie = (target.price - (Game.cookies - me.price)) / me.newCookiesPs;
197+
me.timeToTargetCookie = (target.price + me.price - Game.cookies) / me.newCookiesPs;
198198
}
199199
});
200200
helpers.sort((a, b) => a.timeToTargetCookie - b.timeToTargetCookie);
@@ -212,7 +212,7 @@ let BestDealHelper = {
212212
span.innerHTML = "";
213213
for (let i = 0; i < text.length; i++) {
214214
let charElem = document.createElement("span");
215-
charElem.style.color = "hsl(" + (360 * i / text.length) + ",80%,50%)";
215+
charElem.style.color = "hsl(" + (360 * i / text.length) + ",90%,80%)";
216216
charElem.innerHTML = text[i];
217217
span.appendChild(charElem);
218218
}
@@ -255,7 +255,7 @@ let BestDealHelper = {
255255
}
256256
rank++;
257257
if (rank < all.length) {
258-
palette.unshift("#64007c");
258+
palette.unshift("#d82aff");
259259
domain.unshift(all[all.length - 1].cpsAcceleration);
260260
}
261261

@@ -266,27 +266,51 @@ let BestDealHelper = {
266266
if (allAcc.length === 0) return;
267267
const avg = allAcc.reduce((a, b) => a + b, 0) / allAcc.length;
268268

269+
// Calculate waiting times
270+
all.forEach(function (me) {
271+
me.waitingTime = "";
272+
if (me.price < Game.cookies) return;
273+
274+
const seconds = (me.price - Game.cookies) / Game.cookiesPs;
275+
let a = [
276+
Math.floor(seconds / 60 / 60 / 24 / 365) + "y",
277+
Math.floor(seconds / 60 / 60 / 24 % 365) + "d",
278+
Math.floor(seconds / 60 / 60 % 24) + "h",
279+
Math.floor(seconds / 60 % 60) + "m",
280+
Math.floor(seconds % 60) + "s"];
281+
while (a.length && ["0y", "0d", "0m", "0h"].includes(a[0])) a.shift();
282+
if (Math.floor(seconds / 60 / 60 / 24 / 365) > 100) {
283+
me.waitingTime = ">100y";
284+
} else {
285+
me.waitingTime = a.slice(0, 2);
286+
}
287+
});
288+
269289
// Notation for upgrades
270290
for (const i in upgrades) {
271291
let me = upgrades[i];
272292
me.l = document.querySelector("#upgrade" + i);
293+
// Node
273294
let span = document.querySelector("#upgradeAcc" + i);
274295
if (!span) {
275296
span = document.createElement("span");
276297
span.id = "upgradeAcc" + i;
277298
span.style.fontWeight = "bolder";
278299
span.style.position = "absolute";
279300
span.style.bottom = "0px";
280-
span.style.left = "-2px";
301+
span.style.left = "-5px";
281302
span.style.textShadow = "0px 2px 6px #000, 0px 1px 1px #000";
282303
span.style.transform = "scale(0.8,1)";
283304
l("upgrade" + i).appendChild(span);
284305
}
306+
307+
// Text
285308
if (me.cpsAcceleration === 0) {
286309
span.textContent = "";
287310
continue;
288311
}
289312
span.textContent = Beautify(me.cpsAcceleration * 100 / avg, 1) + "%";
313+
if (me.waitingTime) span.innerHTML = me.waitingTime + "<br>" + span.textContent;
290314
if (me.isBestHelper) {
291315
MOD.rainbow(span);
292316
} else {
@@ -296,6 +320,7 @@ let BestDealHelper = {
296320
// Notation for buildings
297321
for (const i in buildings) {
298322
let me = buildings[i];
323+
// Node
299324
let span = document.querySelector("#productAcc" + me.id);
300325
if (!span) {
301326
span = document.createElement("span");
@@ -304,11 +329,14 @@ let BestDealHelper = {
304329
span.style.display = "block";
305330
MOD.insertAfter(span, l("productPrice" + me.id));
306331
}
332+
333+
// Text
307334
if (me.cpsAcceleration === 0) {
308335
span.textContent = "";
309336
continue;
310337
}
311338
span.textContent = " 💹" + Beautify(me.cpsAcceleration * 100 / avg, 2) + "%";
339+
if (me.waitingTime) span.textContent += " ⏳" + me.waitingTime;
312340
if (me.isBestHelper) {
313341
MOD.rainbow(span);
314342
} else {

0 commit comments

Comments
 (0)