From 5fe77bccce34dc586b46b6edc43047199bfa5913 Mon Sep 17 00:00:00 2001 From: Thomas Riffard Date: Tue, 15 Oct 2024 23:52:13 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=B2=20Refactor=20reroll=20cost=20value?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/api/reroll-handle.ts | 5 +++-- core/automations/as-player-reroll.ts | 5 +++++ core/utils/get-reroll-cost.ts | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 core/utils/get-reroll-cost.ts diff --git a/core/api/reroll-handle.ts b/core/api/reroll-handle.ts index 9259db8..031ab8b 100644 --- a/core/api/reroll-handle.ts +++ b/core/api/reroll-handle.ts @@ -5,6 +5,7 @@ import { checkInvalidSignature } from "../utils/check-invalid-signature"; import { checkTimestamp } from "../utils/check-timestamp"; import type { Pool } from "../types/pool"; import { checkGameHasPlayer } from "../utils/check-game-has-player"; +import { getRerollCost } from "../utils/get-reroll-cost"; export function rerollHandle({ connections$, @@ -31,7 +32,7 @@ export function rerollHandle({ const { game, pool, commit, abort } = transaction; try { - if (game.playerMoney[publicKey] < 2) { + if (game.playerMoney[publicKey] < getRerollCost()) { await abort(); return; } @@ -56,7 +57,7 @@ export function rerollHandle({ }, playerMoney: { ...game.playerMoney, - [publicKey]: game.playerMoney[publicKey] - 2, + [publicKey]: game.playerMoney[publicKey] - getRerollCost(), }, }; diff --git a/core/automations/as-player-reroll.ts b/core/automations/as-player-reroll.ts index 7406ebd..081664f 100644 --- a/core/automations/as-player-reroll.ts +++ b/core/automations/as-player-reroll.ts @@ -2,6 +2,7 @@ import { reroll } from "../api/reroll"; import type { TestContext } from "../types/test-context"; import { firstValueFrom, map, filter } from "rxjs"; import { observeGame } from "../api/observe-game"; +import { getRerollCost } from "../utils/get-reroll-cost"; export async function asPlayerReroll( testContext: TestContext, @@ -19,6 +20,10 @@ export async function asPlayerReroll( ), ); + if (moneyBefore < getRerollCost()) { + return; + } + await reroll(frontContext); await firstValueFrom( diff --git a/core/utils/get-reroll-cost.ts b/core/utils/get-reroll-cost.ts new file mode 100644 index 0000000..59dd2ce --- /dev/null +++ b/core/utils/get-reroll-cost.ts @@ -0,0 +1,3 @@ +export function getRerollCost() { + return 2; +}