Skip to content

Commit

Permalink
Merge pull request #155 from RShadbolt/feature/vinegarEta
Browse files Browse the repository at this point in the history
Adding ETA to vinegar throw to UI
  • Loading branch information
TheExkaliburg authored Aug 12, 2023
2 parents 4df912b + 2e6c563 commit 36914c0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
8 changes: 7 additions & 1 deletion frontend/src/components/ladder/LadderWindowBody.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
class="w-full rounded-l-none border-l-0 whitespace-nowrap"
@click="throwVinegar"
>
{{ lang("vinegar") }}
{{ vinegarButtonLabel }}
</FairButton>
<FairButton
v-else
Expand Down Expand Up @@ -168,6 +168,12 @@ const multiButtonLabel = computed<string>(() => {
return `+${lang("multi_short")} (${useTimeFormatter(eta)})`;
});
const vinegarButtonLabel = computed<string>(() => {
const eta = useEta(yourRanker.value).toVinegarThrow();
if (eta === 0 || eta === Infinity) return `${lang("vinegar")}`;
return `${lang("vinegar")} (${useTimeFormatter(eta)})`;
});
const yourFormattedMulti = computed<string>(() => {
return yourRanker.value.multi.toString().padStart(2, "0");
});
Expand Down
29 changes: 29 additions & 0 deletions frontend/src/composables/useEta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,34 @@ export const useEta = (ranker: Ranker) => {
return Math.max(etaRequirement, toFirst() + 30);
}

function toVinegarThrow(): number {
if (!ranker.growing) return 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();
}

return {
toRanker,
toPoints,
Expand All @@ -186,6 +214,7 @@ export const useEta = (ranker: Ranker) => {
toFirst,
toPromotionRequirement,
toPromote,
toVinegarThrow,
};
};

Expand Down

0 comments on commit 36914c0

Please sign in to comment.