Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions balatrobot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
24 changes: 24 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
```
Expand Down
2 changes: 1 addition & 1 deletion docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
1 change: 1 addition & 0 deletions src/balatrobot/cli/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Method(StrEnum):
PLAY = "play"
REARRANGE = "rearrange"
REROLL = "reroll"
REROLL_BOSS = "reroll_boss"
SAVE = "save"
SCREENSHOT = "screenshot"
SELECT = "select"
Expand Down
8 changes: 8 additions & 0 deletions src/lua/endpoints/add.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
109 changes: 109 additions & 0 deletions src/lua/endpoints/reroll_boss.lua
Original file line number Diff line number Diff line change
@@ -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,
}
3 changes: 3 additions & 0 deletions src/lua/utils/gamestate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions src/lua/utils/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions src/lua/utils/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/test_api_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading
Loading