Skip to content

Commit

Permalink
🎲 Refactor reroll cost value
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdodo committed Oct 15, 2024
1 parent 117cc64 commit 5fe77bc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions core/api/reroll-handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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$,
Expand All @@ -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;
}
Expand All @@ -56,7 +57,7 @@ export function rerollHandle({
},
playerMoney: {
...game.playerMoney,
[publicKey]: game.playerMoney[publicKey] - 2,
[publicKey]: game.playerMoney[publicKey] - getRerollCost(),
},
};

Expand Down
5 changes: 5 additions & 0 deletions core/automations/as-player-reroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -19,6 +20,10 @@ export async function asPlayerReroll(
),
);

if (moneyBefore < getRerollCost()) {
return;
}

await reroll(frontContext);

await firstValueFrom(
Expand Down
3 changes: 3 additions & 0 deletions core/utils/get-reroll-cost.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function getRerollCost() {
return 2;
}

0 comments on commit 5fe77bc

Please sign in to comment.