From 1825ac9bc71c97fed67ce43a95a946575d3a1cd0 Mon Sep 17 00:00:00 2001 From: Ryan Shadbolt Date: Fri, 21 Jul 2023 00:35:01 +0100 Subject: [PATCH 1/2] feat(frontend): basic implementation of vinegar ETA --- frontend/src/components/ladder/LadderWindowBody.vue | 8 +++++++- frontend/src/composables/useEta.ts | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/ladder/LadderWindowBody.vue b/frontend/src/components/ladder/LadderWindowBody.vue index 659e9997..4fe68447 100644 --- a/frontend/src/components/ladder/LadderWindowBody.vue +++ b/frontend/src/components/ladder/LadderWindowBody.vue @@ -82,7 +82,7 @@ class="w-full rounded-l-none border-l-0 whitespace-nowrap" @click="throwVinegar" > - {{ lang("vinegar") }} + {{ vinegarButtonLabel }} (() => { return `+${lang("multi_short")} (${useTimeFormatter(eta)})`; }); +const vinegarButtonLabel = computed(() => { + const eta = useEta(yourRanker.value).toVinegarThrow(); + if (eta === 0) return `${lang("vinegar")}`; + return `${lang("vinegar")} (${useTimeFormatter(eta)})`; +}); + const yourFormattedMulti = computed(() => { return yourRanker.value.multi.toString().padStart(2, "0"); }); diff --git a/frontend/src/composables/useEta.ts b/frontend/src/composables/useEta.ts index 0dc4c44a..dd05fa88 100644 --- a/frontend/src/composables/useEta.ts +++ b/frontend/src/composables/useEta.ts @@ -178,6 +178,18 @@ export const useEta = (ranker: Ranker) => { return Math.max(etaRequirement, toFirst() + 30); } + function toVinegarThrow(): number { + if (!ranker.growing) return 0; + const secondsToVinegar = + ladderUtils.getVinegarThrowCost.value.cmp(ranker.vinegar) >= 0 + ? ladderUtils.getVinegarThrowCost.value + .sub(ranker.vinegar) + .div(ranker.grapes) + : new Decimal(0); + + return secondsToVinegar.toNumber(); + } + return { toRanker, toPoints, @@ -186,6 +198,7 @@ export const useEta = (ranker: Ranker) => { toFirst, toPromotionRequirement, toPromote, + toVinegarThrow, }; }; From 2e6c56368f1ac3b3dd1e32e56564a2fca4fe2920 Mon Sep 17 00:00:00 2001 From: Ryan Shadbolt Date: Tue, 25 Jul 2023 11:52:02 +0100 Subject: [PATCH 2/2] feat(frontend): improved vinegar ETA while grapes increase --- .../components/ladder/LadderWindowBody.vue | 2 +- frontend/src/composables/useEta.ts | 28 +++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/ladder/LadderWindowBody.vue b/frontend/src/components/ladder/LadderWindowBody.vue index 4fe68447..164d0f20 100644 --- a/frontend/src/components/ladder/LadderWindowBody.vue +++ b/frontend/src/components/ladder/LadderWindowBody.vue @@ -170,7 +170,7 @@ const multiButtonLabel = computed(() => { const vinegarButtonLabel = computed(() => { const eta = useEta(yourRanker.value).toVinegarThrow(); - if (eta === 0) return `${lang("vinegar")}`; + if (eta === 0 || eta === Infinity) return `${lang("vinegar")}`; return `${lang("vinegar")} (${useTimeFormatter(eta)})`; }); diff --git a/frontend/src/composables/useEta.ts b/frontend/src/composables/useEta.ts index dd05fa88..91811090 100644 --- a/frontend/src/composables/useEta.ts +++ b/frontend/src/composables/useEta.ts @@ -180,12 +180,28 @@ export const useEta = (ranker: Ranker) => { function toVinegarThrow(): number { if (!ranker.growing) return 0; - const secondsToVinegar = - ladderUtils.getVinegarThrowCost.value.cmp(ranker.vinegar) >= 0 - ? ladderUtils.getVinegarThrowCost.value - .sub(ranker.vinegar) - .div(ranker.grapes) - : new Decimal(0); + + let secondsToVinegar: Decimal; + + if ( + ranker.rank === ladder.state.rankers.length && + ladder.state.rankers.length >= 1 + ) { + // TODO: When grape modifiers are implemented, acceleration can be changed. + const acceleration = 2; + const a = new Decimal(acceleration).div(2); + const b = ranker.grapes.sub(1); + const c = ranker.vinegar.sub(ladderUtils.getVinegarThrowCost.value); + + secondsToVinegar = solveQuadratic(a, b, c); + } else { + secondsToVinegar = + ladderUtils.getVinegarThrowCost.value.cmp(ranker.vinegar) >= 0 + ? ladderUtils.getVinegarThrowCost.value + .sub(ranker.vinegar) + .div(ranker.grapes) + : new Decimal(0); + } return secondsToVinegar.toNumber(); }