From c7066823b48e0c8285419c78db6d666e89493789 Mon Sep 17 00:00:00 2001 From: garfield-oo7 <77141836+garfield-oo7@users.noreply.github.com> Date: Sat, 7 Nov 2026 01:08:37 +0800 Subject: [PATCH 1/2] fix(lua.endpoints): make vouchers added to the shop buyable add put the voucher card in G.shop_vouchers without the shop UI, so buy failed with "attempt to index field 'buy_button' (a nil value)". Create it with create_shop_card_ui, as the Voucher Tag does, and wait for the buy button (created in a delayed event) before returning. --- src/lua/endpoints/add.lua | 8 ++++++++ tests/lua/endpoints/test_add.py | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/lua/endpoints/add.lua b/src/lua/endpoints/add.lua index 0bee6a21..c6c72796 100644 --- a/src/lua/endpoints/add.lua +++ b/src/lua/endpoints/add.lua @@ -442,6 +442,12 @@ return { return end + -- Vouchers added to the shop need the shop UI (price and redeem button), + -- same as the Voucher Tag does with create_shop_card_ui + if card_type == "voucher" and result then + create_shop_card_ui(result, "Voucher", G.shop_vouchers) ---@diagnostic disable-line: undefined-global + end + -- Set custom perish_tally if perishable was provided if args.perishable and result and result.ability then result.ability.perish_tally = args.perishable @@ -464,9 +470,11 @@ return { and G.consumeables.config and G.consumeables.config.card_count == initial_consumable_count + 1 elseif card_type == "voucher" then + -- The shop UI (buy button) is created in a delayed event added = G.shop_vouchers and G.shop_vouchers.config and G.shop_vouchers.config.card_count == initial_voucher_count + 1 + and result.children.buy_button ~= nil elseif card_type == "pack" then added = G.shop_booster and G.shop_booster.config diff --git a/tests/lua/endpoints/test_add.py b/tests/lua/endpoints/test_add.py index fe11a58b..1054c663 100644 --- a/tests/lua/endpoints/test_add.py +++ b/tests/lua/endpoints/test_add.py @@ -84,6 +84,22 @@ def test_add_voucher(self, client: httpx.Client) -> None: assert after["vouchers"]["count"] == 1 assert after["vouchers"]["cards"][0]["key"] == "v_overstock_norm" + def test_add_voucher_then_buy(self, client: httpx.Client) -> None: + """Test that an added voucher can be bought (redeemed) from the shop.""" + gamestate = load_fixture( + client, + "add", + "state-SHOP--jokers.count-0--consumables.count-0--vouchers.count-0--packs.count-0", + ) + assert gamestate["state"] == "SHOP" + assert_gamestate_response(api(client, "set", {"money": 50})) + response = api(client, "add", {"key": "v_overstock_norm"}) + assert_gamestate_response(response) + response = api(client, "buy", {"voucher": 0}) + after = assert_gamestate_response(response) + assert after["vouchers"]["count"] == 0 + assert "v_overstock_norm" in after["used_vouchers"] + def test_add_pack(self, client: httpx.Client) -> None: """Test adding a pack with valid key in SHOP state.""" gamestate = load_fixture( From 445e1151b72ea488a13cd60e750e061353e06151 Mon Sep 17 00:00:00 2001 From: garfield-oo7 <77141836+garfield-oo7@users.noreply.github.com> Date: Sat, 7 Nov 2026 01:08:37 +0800 Subject: [PATCH 2/2] feat(lua.endpoints): add reroll_boss endpoint Reroll the Boss blind from the blind selection screen, like the in-game Reroll Boss button. It mirrors G.FUNCS.reroll_boss_button: requires Director's Cut (one reroll per ante) or Retcon (unlimited), costs $10 and respects bankrupt_at (Credit Card). The response is sent once the game clears its boss_reroll lock. Expose round.boss_rerolled in the gamestate so clients can tell whether Director's Cut was already used this ante. Docs, OpenRPC spec, types, CLI method enum and tests included. --- CLAUDE.md | 1 + balatrobot.lua | 1 + docs/api.md | 24 +++ docs/cli.md | 2 +- src/balatrobot/cli/api.py | 1 + src/lua/endpoints/reroll_boss.lua | 109 ++++++++++ src/lua/utils/gamestate.lua | 3 + src/lua/utils/openrpc.json | 30 +++ src/lua/utils/types.lua | 6 +- tests/cli/test_api_cmd.py | 2 +- tests/fixtures/fixtures.json | 268 ++++++++++++++++++++++++ tests/lua/endpoints/test_reroll_boss.py | 134 ++++++++++++ 12 files changed, 577 insertions(+), 4 deletions(-) create mode 100644 src/lua/endpoints/reroll_boss.lua create mode 100644 tests/lua/endpoints/test_reroll_boss.py diff --git a/CLAUDE.md b/CLAUDE.md index 85f7cbd8..952b648a 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -117,6 +117,7 @@ Runs inside the game engine and exposes an API. - `play.lua`: Play a card from the hand. - `rearrange.lua`: Rearrange cards in hand, jokers, or consumables. - `reroll.lua`: Reroll to update the cards in the shop area. + - `reroll_boss.lua`: Reroll the Boss blind (requires Director's Cut or Retcon). - `save.lua`: Save the current run state to a file. - `screenshot.lua`: Take a screenshot of the current game state. - `select.lua`: Select the current blind. diff --git a/balatrobot.lua b/balatrobot.lua index 90b3a54f..8696d498 100644 --- a/balatrobot.lua +++ b/balatrobot.lua @@ -24,6 +24,7 @@ BB_ENDPOINTS = { -- Blind selection endpoints "src/lua/endpoints/skip.lua", "src/lua/endpoints/select.lua", + "src/lua/endpoints/reroll_boss.lua", -- Play/discard endpoints "src/lua/endpoints/play.lua", "src/lua/endpoints/discard.lua", diff --git a/docs/api.md b/docs/api.md index 6f3ed22f..ffab0ae4 100644 --- a/docs/api.md +++ b/docs/api.md @@ -121,6 +121,7 @@ MENU ──► BLIND_SELECT ──► SELECTING_HAND ──► ROUND_EVAL ── - [`load`](#load) - Load a saved run from a file - [`select`](#select) - Select the current blind to begin the round - [`skip`](#skip) - Skip the current blind (Small or Big only) +- [`reroll_boss`](#reroll_boss) - Reroll the Boss blind (requires Director's Cut or Retcon) - [`buy`](#buy) - Buy a card, voucher, or pack from the shop - [`pack`](#pack) - Select a card or skip a pack from an opened booster pack, requires to you select targets for Tarot/Spectral consumables when applicable - [`sell`](#sell) - Sell a joker or consumable @@ -317,6 +318,28 @@ curl -X POST http://127.0.0.1:12346 \ --- +### `reroll_boss` + +Reroll the upcoming Boss blind from the blind selection screen, like the in-game "Reroll Boss" button. Requires the Director's Cut voucher (one reroll per ante) or the Retcon voucher (unlimited rerolls). Each reroll costs $10. The new Boss is random and can occasionally be the same one. + +Use `used_vouchers` and `round.boss_rerolled` in the [GameState](#gamestate-schema) to check whether a reroll is available. + +**Returns:** [GameState](#gamestate-schema) + +**Errors:** `INVALID_STATE`, `NOT_ALLOWED` + +**Required State:** `BLIND_SELECT` + +**Example:** + +```bash +curl -X POST http://127.0.0.1:12346 \ + -H "Content-Type: application/json" \ + -d '{"jsonrpc": "2.0", "method": "reroll_boss", "id": 1}' +``` + +--- + ### `buy` Buy a card, voucher, or pack from the shop. @@ -767,6 +790,7 @@ Represents a card area (hand, jokers, consumables, shop, etc.). "discards_left": 3, "discards_used": 0, "reroll_cost": 5, + "boss_rerolled": false, "chips": 0 } ``` diff --git a/docs/cli.md b/docs/cli.md index 133f6d95..952a8c98 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -81,7 +81,7 @@ uvx balatrobot api METHOD [PARAMS] [OPTIONS] ### Available Methods -`add`, `buy`, `cash_out`, `discard`, `gamestate`, `health`, `load`, `menu`, `next_round`, `pack`, `play`, `rearrange`, `reroll`, `save`, `screenshot`, `select`, `sell`, `set`, `skip`, `start`, `use` +`add`, `buy`, `cash_out`, `discard`, `gamestate`, `health`, `load`, `menu`, `next_round`, `pack`, `play`, `rearrange`, `reroll`, `reroll_boss`, `save`, `screenshot`, `select`, `sell`, `set`, `skip`, `start`, `use` For detailed method documentation including parameters and schemas, see the [OpenRPC specification](../src/lua/utils/openrpc.json). diff --git a/src/balatrobot/cli/api.py b/src/balatrobot/cli/api.py index 7e20b6ca..ce029a3c 100644 --- a/src/balatrobot/cli/api.py +++ b/src/balatrobot/cli/api.py @@ -26,6 +26,7 @@ class Method(StrEnum): PLAY = "play" REARRANGE = "rearrange" REROLL = "reroll" + REROLL_BOSS = "reroll_boss" SAVE = "save" SCREENSHOT = "screenshot" SELECT = "select" diff --git a/src/lua/endpoints/reroll_boss.lua b/src/lua/endpoints/reroll_boss.lua new file mode 100644 index 00000000..7051b4b2 --- /dev/null +++ b/src/lua/endpoints/reroll_boss.lua @@ -0,0 +1,109 @@ +-- src/lua/endpoints/reroll_boss.lua + +-- ========================================================================== +-- RerollBoss Endpoint Params +-- ========================================================================== + +---@class Request.Endpoint.RerollBoss.Params + +-- ========================================================================== +-- RerollBoss Endpoint +-- ========================================================================== + +-- Hard-coded in the game (G.FUNCS.reroll_boss_button / G.FUNCS.reroll_boss) +local BOSS_REROLL_COST = 10 + +---@type Endpoint +return { + + name = "reroll_boss", + + description = "Reroll the Boss blind (requires Director's Cut or Retcon voucher)", + + schema = {}, + + requires_state = { G.STATES.BLIND_SELECT }, + + ---@param _ Request.Endpoint.RerollBoss.Params + ---@param send_response fun(response: Response.Endpoint) + execute = function(_, send_response) + sendDebugMessage("Init reroll_boss()", "BB.ENDPOINTS") + + -- Same checks as G.FUNCS.reroll_boss_button (the in-game button) + local used_vouchers = G.GAME.used_vouchers or {} + local has_retcon = used_vouchers["v_retcon"] and true or false + local has_directors_cut = used_vouchers["v_directors_cut"] and true or false + + if not has_retcon and not has_directors_cut then + send_response({ + message = "Cannot reroll Boss blind without Director's Cut or Retcon voucher", + name = BB_ERROR_NAMES.NOT_ALLOWED, + }) + return + end + + if not has_retcon and G.GAME.round_resets.boss_rerolled then + send_response({ + message = "Boss blind already rerolled this ante (Director's Cut allows one reroll per ante)", + name = BB_ERROR_NAMES.NOT_ALLOWED, + }) + return + end + + -- Check affordability (accounting for Credit Card joker via bankrupt_at) + local available_money = G.GAME.dollars - G.GAME.bankrupt_at + if available_money < BOSS_REROLL_COST then + send_response({ + message = "Not enough dollars to reroll Boss blind. Available: " + .. available_money + .. ", Required: " + .. BOSS_REROLL_COST, + name = BB_ERROR_NAMES.NOT_ALLOWED, + }) + return + end + + if not (G.blind_select_opts and G.blind_select_opts.boss) or G.CONTROLLER.locks.boss_reroll then + send_response({ + message = "Boss blind cannot be rerolled right now", + name = BB_ERROR_NAMES.NOT_ALLOWED, + }) + return + end + + sendDebugMessage( + string.format("Rerolling boss %s (money=$%d)", G.GAME.round_resets.blind_choices.Boss, G.GAME.dollars), + "BB.ENDPOINTS" + ) + G.FUNCS.reroll_boss(nil) + + -- Wait for the reroll to complete + -- The game sets G.CONTROLLER.locks.boss_reroll and clears it in an event + -- queued after the new boss pane is built. Non-blocking, otherwise this + -- event would block the queue in front of the event that clears the lock. + G.E_MANAGER:add_event(Event({ + trigger = "condition", + blocking = false, + func = function() + local done = ( + G.STATE == G.STATES.BLIND_SELECT + and G.CONTROLLER.locks.boss_reroll == nil + and G.blind_select_opts ~= nil + and G.blind_select_opts.boss ~= nil + ) + if done then + sendDebugMessage( + string.format( + "Return reroll_boss() boss=%s money=$%d", + G.GAME.round_resets.blind_choices.Boss, + G.GAME.dollars + ), + "BB.ENDPOINTS" + ) + send_response(BB_GAMESTATE.get_gamestate()) + end + return done + end, + })) + end, +} diff --git a/src/lua/utils/gamestate.lua b/src/lua/utils/gamestate.lua index a7cc2b97..5d47ce57 100644 --- a/src/lua/utils/gamestate.lua +++ b/src/lua/utils/gamestate.lua @@ -463,6 +463,9 @@ local function extract_round_info() round.reroll_cost = G.GAME.current_round.reroll_cost end + -- Boss reroll flag is stored in G.GAME.round_resets (reset each ante) + round.boss_rerolled = (G.GAME.round_resets and G.GAME.round_resets.boss_rerolled) == true + -- Chips is stored in G.GAME not G.GAME.current_round if G.GAME.chips then round.chips = G.GAME.chips diff --git a/src/lua/utils/openrpc.json b/src/lua/utils/openrpc.json index eaea0856..92d650ba 100644 --- a/src/lua/utils/openrpc.json +++ b/src/lua/utils/openrpc.json @@ -484,6 +484,32 @@ } ] }, + { + "name": "reroll_boss", + "summary": "Reroll the Boss blind", + "description": "Reroll the upcoming Boss blind from the blind selection screen. Requires the Director's Cut (once per ante) or Retcon (unlimited) voucher and costs $10.", + "tags": [ + { + "$ref": "#/components/tags/blind" + } + ], + "params": [], + "result": { + "name": "gamestate", + "description": "Complete game state after rerolling the Boss blind", + "schema": { + "$ref": "#/components/schemas/GameState" + } + }, + "errors": [ + { + "$ref": "#/components/errors/InvalidState" + }, + { + "$ref": "#/components/errors/NotAllowed" + } + ] + }, { "name": "save", "summary": "Save the current run state to a file", @@ -1047,6 +1073,10 @@ "type": "integer", "description": "Current cost to reroll the shop" }, + "boss_rerolled": { + "type": "boolean", + "description": "Whether the Boss blind was already rerolled this ante (Director's Cut allows one reroll per ante)" + }, "chips": { "type": "integer", "description": "Current chips scored in this round" diff --git a/src/lua/utils/types.lua b/src/lua/utils/types.lua index 53f43b13..da238ca6 100644 --- a/src/lua/utils/types.lua +++ b/src/lua/utils/types.lua @@ -45,6 +45,7 @@ ---@field discards_left integer? Number of discards remaining in this round ---@field discards_used integer? Number of discards used in this round ---@field reroll_cost integer? Current cost to reroll the shop +---@field boss_rerolled boolean? Whether the Boss blind was already rerolled this ante ---@field chips integer? Current chips scored in this round ---@class Blind @@ -142,8 +143,8 @@ ---@alias Request.Endpoint.Method ---| "add" | "buy" | "cash_out" | "discard" | "gamestate" | "health" | "load" ----| "menu" | "next_round" | "play" | "rearrange" | "reroll" | "save" ----| "screenshot" | "select" | "sell" | "set" | "skip" | "start" | "use" +---| "menu" | "next_round" | "play" | "rearrange" | "reroll" | "reroll_boss" +---| "save" | "screenshot" | "select" | "sell" | "set" | "skip" | "start" | "use" ---@alias Request.Endpoint.Test.Method ---| "echo" | "endpoint" | "error" | "state" | "validation" @@ -162,6 +163,7 @@ ---| Request.Endpoint.Play.Params ---| Request.Endpoint.Rearrange.Params ---| Request.Endpoint.Reroll.Params +---| Request.Endpoint.RerollBoss.Params ---| Request.Endpoint.Save.Params ---| Request.Endpoint.Screenshot.Params ---| Request.Endpoint.Select.Params diff --git a/tests/cli/test_api_cmd.py b/tests/cli/test_api_cmd.py index c5e363fc..9e67c93c 100644 --- a/tests/cli/test_api_cmd.py +++ b/tests/cli/test_api_cmd.py @@ -50,7 +50,7 @@ def test_api_all_methods_valid(self): from balatrobot.cli.api import Method methods = [m.value for m in Method] - assert len(methods) == 21 + assert len(methods) == 22 assert "health" in methods assert "gamestate" in methods diff --git a/tests/fixtures/fixtures.json b/tests/fixtures/fixtures.json index 44ceffae..b9320cf7 100644 --- a/tests/fixtures/fixtures.json +++ b/tests/fixtures/fixtures.json @@ -811,6 +811,274 @@ } ] }, + "reroll_boss": { + "state-BLIND_SELECT": [ + { + "method": "menu", + "params": {} + }, + { + "method": "start", + "params": { + "deck": "RED", + "stake": "WHITE", + "seed": "TEST123" + } + } + ], + "state-SHOP--used_vouchers.v_directors_cut": [ + { + "method": "menu", + "params": {} + }, + { + "method": "start", + "params": { + "deck": "RED", + "stake": "WHITE", + "seed": "TEST123" + } + }, + { + "method": "select", + "params": {} + }, + { + "method": "set", + "params": { + "chips": 1000 + } + }, + { + "method": "play", + "params": { + "cards": [ + 0 + ] + } + }, + { + "method": "cash_out", + "params": {} + }, + { + "method": "add", + "params": { + "key": "v_directors_cut" + } + }, + { + "method": "set", + "params": { + "money": 50 + } + }, + { + "method": "buy", + "params": { + "voucher": 1 + } + } + ], + "state-BLIND_SELECT--used_vouchers.v_directors_cut": [ + { + "method": "menu", + "params": {} + }, + { + "method": "start", + "params": { + "deck": "RED", + "stake": "WHITE", + "seed": "TEST123" + } + }, + { + "method": "select", + "params": {} + }, + { + "method": "set", + "params": { + "chips": 1000 + } + }, + { + "method": "play", + "params": { + "cards": [ + 0 + ] + } + }, + { + "method": "cash_out", + "params": {} + }, + { + "method": "add", + "params": { + "key": "v_directors_cut" + } + }, + { + "method": "set", + "params": { + "money": 50 + } + }, + { + "method": "buy", + "params": { + "voucher": 1 + } + }, + { + "method": "next_round", + "params": {} + } + ], + "state-BLIND_SELECT--used_vouchers.v_directors_cut--money-0": [ + { + "method": "menu", + "params": {} + }, + { + "method": "start", + "params": { + "deck": "RED", + "stake": "WHITE", + "seed": "TEST123" + } + }, + { + "method": "select", + "params": {} + }, + { + "method": "set", + "params": { + "chips": 1000 + } + }, + { + "method": "play", + "params": { + "cards": [ + 0 + ] + } + }, + { + "method": "cash_out", + "params": {} + }, + { + "method": "add", + "params": { + "key": "v_directors_cut" + } + }, + { + "method": "set", + "params": { + "money": 50 + } + }, + { + "method": "buy", + "params": { + "voucher": 1 + } + }, + { + "method": "next_round", + "params": {} + }, + { + "method": "set", + "params": { + "money": 0 + } + } + ], + "state-BLIND_SELECT--used_vouchers.v_retcon": [ + { + "method": "menu", + "params": {} + }, + { + "method": "start", + "params": { + "deck": "RED", + "stake": "WHITE", + "seed": "TEST123" + } + }, + { + "method": "select", + "params": {} + }, + { + "method": "set", + "params": { + "chips": 1000 + } + }, + { + "method": "play", + "params": { + "cards": [ + 0 + ] + } + }, + { + "method": "cash_out", + "params": {} + }, + { + "method": "add", + "params": { + "key": "v_directors_cut" + } + }, + { + "method": "set", + "params": { + "money": 50 + } + }, + { + "method": "buy", + "params": { + "voucher": 1 + } + }, + { + "method": "add", + "params": { + "key": "v_retcon" + } + }, + { + "method": "buy", + "params": { + "voucher": 1 + } + }, + { + "method": "set", + "params": { + "money": 50 + } + }, + { + "method": "next_round", + "params": {} + } + ] + }, "buy": { "state-BLIND_SELECT": [ { diff --git a/tests/lua/endpoints/test_reroll_boss.py b/tests/lua/endpoints/test_reroll_boss.py new file mode 100644 index 00000000..adc7563b --- /dev/null +++ b/tests/lua/endpoints/test_reroll_boss.py @@ -0,0 +1,134 @@ +"""Tests for src/lua/endpoints/reroll_boss.lua""" + +import httpx + +from tests.lua.conftest import ( + api, + assert_error_response, + assert_gamestate_response, + load_fixture, +) + + +class TestRerollBossEndpoint: + """Test basic reroll_boss endpoint functionality.""" + + def test_reroll_boss_with_directors_cut(self, client: httpx.Client) -> None: + """Test rerolling the Boss blind with Director's Cut.""" + before = load_fixture( + client, "reroll_boss", "state-BLIND_SELECT--used_vouchers.v_directors_cut" + ) + assert before["state"] == "BLIND_SELECT" + assert "v_directors_cut" in before["used_vouchers"] + assert before["round"]["boss_rerolled"] is False + response = api(client, "reroll_boss", {}) + after = assert_gamestate_response(response, state="BLIND_SELECT") + assert after["money"] == before["money"] - 10 + assert after["round"]["boss_rerolled"] is True + assert after["blinds"]["boss"]["type"] == "BOSS" + assert after["blinds"]["boss"]["status"] == "UPCOMING" + + def test_reroll_boss_directors_cut_once_per_ante( + self, client: httpx.Client + ) -> None: + """Test that Director's Cut allows only one Boss reroll per ante.""" + load_fixture( + client, "reroll_boss", "state-BLIND_SELECT--used_vouchers.v_directors_cut" + ) + assert_gamestate_response(api(client, "reroll_boss", {})) + assert_error_response( + api(client, "reroll_boss", {}), + "NOT_ALLOWED", + "Boss blind already rerolled this ante", + ) + + def test_reroll_boss_with_retcon(self, client: httpx.Client) -> None: + """Test that Retcon allows unlimited Boss rerolls.""" + before = load_fixture( + client, "reroll_boss", "state-BLIND_SELECT--used_vouchers.v_retcon" + ) + assert "v_retcon" in before["used_vouchers"] + money = before["money"] + for _ in range(3): + response = api(client, "reroll_boss", {}) + after = assert_gamestate_response(response, state="BLIND_SELECT") + money -= 10 + assert after["money"] == money + assert after["round"]["boss_rerolled"] is True + + def test_reroll_boss_without_voucher(self, client: httpx.Client) -> None: + """Test reroll_boss without Director's Cut or Retcon.""" + gamestate = load_fixture(client, "reroll_boss", "state-BLIND_SELECT") + assert gamestate["state"] == "BLIND_SELECT" + assert "v_directors_cut" not in gamestate["used_vouchers"] + assert_error_response( + api(client, "reroll_boss", {}), + "NOT_ALLOWED", + "Cannot reroll Boss blind without Director's Cut or Retcon voucher", + ) + + def test_reroll_boss_insufficient_funds(self, client: httpx.Client) -> None: + """Test reroll_boss when player has insufficient funds.""" + gamestate = load_fixture( + client, + "reroll_boss", + "state-BLIND_SELECT--used_vouchers.v_directors_cut--money-0", + ) + assert gamestate["money"] == 0 + assert_error_response( + api(client, "reroll_boss", {}), + "NOT_ALLOWED", + "Not enough dollars to reroll Boss blind", + ) + + def test_reroll_boss_with_credit_card_joker(self, client: httpx.Client) -> None: + """Test reroll_boss with Credit Card joker (can go negative).""" + gamestate = load_fixture( + client, "reroll_boss", "state-SHOP--used_vouchers.v_directors_cut" + ) + assert gamestate["state"] == "SHOP" + assert_gamestate_response(api(client, "add", {"key": "j_credit_card"})) + assert_gamestate_response(api(client, "set", {"money": 0})) + assert_gamestate_response(api(client, "next_round", {}), state="BLIND_SELECT") + response = api(client, "reroll_boss", {}) + after = assert_gamestate_response(response, state="BLIND_SELECT") + assert after["money"] == -10 + + def test_reroll_boss_resets_next_ante(self, client: httpx.Client) -> None: + """Test that the Director's Cut reroll is available again next ante.""" + load_fixture( + client, "reroll_boss", "state-BLIND_SELECT--used_vouchers.v_directors_cut" + ) + gamestate = assert_gamestate_response(api(client, "reroll_boss", {})) + assert gamestate["round"]["boss_rerolled"] is True + ante = gamestate["ante_num"] + # Beat the Big and Boss blinds (the fixture already beat the Small one) + for _ in range(2): + assert_gamestate_response(api(client, "select", {})) + assert_gamestate_response(api(client, "set", {"chips": 1000000})) + assert_gamestate_response(api(client, "play", {"cards": [0]})) + assert_gamestate_response(api(client, "cash_out", {})) + assert_gamestate_response(api(client, "set", {"money": 50})) + gamestate = assert_gamestate_response(api(client, "next_round", {})) + assert gamestate["state"] == "BLIND_SELECT" + assert gamestate["ante_num"] == ante + 1 + assert gamestate["round"]["boss_rerolled"] is False + response = api(client, "reroll_boss", {}) + after = assert_gamestate_response(response, state="BLIND_SELECT") + assert after["round"]["boss_rerolled"] is True + + +class TestRerollBossEndpointStateRequirements: + """Test reroll_boss endpoint state requirements.""" + + def test_reroll_boss_from_SHOP(self, client: httpx.Client): + """Test that reroll_boss fails when not in BLIND_SELECT state.""" + gamestate = load_fixture( + client, "reroll_boss", "state-SHOP--used_vouchers.v_directors_cut" + ) + assert gamestate["state"] == "SHOP" + assert_error_response( + api(client, "reroll_boss", {}), + "INVALID_STATE", + "Method 'reroll_boss' requires one of these states: BLIND_SELECT", + )