Skip to content

feat(lua.endpoints): add reroll_boss endpoint - #245

Closed
garfield-oo7 wants to merge 2 commits into
coder:mainfrom
garfield-oo7:feat/reroll-boss
Closed

garfield-oo7 wants to merge 2 commits into
coder:mainfrom
garfield-oo7:feat/reroll-boss

Conversation

@garfield-oo7

Copy link
Copy Markdown

What

A new reroll_boss endpoint that rerolls the upcoming Boss blind from the blind selection screen, the same as the in-game "Reroll Boss" button that Director's Cut / Retcon add.

  • src/lua/endpoints/reroll_boss.lua (requires_state = BLIND_SELECT) applies the same checks as G.FUNCS.reroll_boss_button and then calls G.FUNCS.reroll_boss:
    • NOT_ALLOWED without v_directors_cut or v_retcon in used_vouchers
    • NOT_ALLOWED when Director's Cut was already used this ante (G.GAME.round_resets.boss_rerolled) and Retcon is not owned
    • NOT_ALLOWED when dollars - bankrupt_at < 10 (so Credit Card works)
    • The response is sent after the game clears G.CONTROLLER.locks.boss_reroll. The wait event is non-blocking because the game clears the lock in an event queued behind it.
  • The gamestate gets round.boss_rerolled (boolean), so a client can tell whether Director's Cut is still available this ante. It is always present (false included).
  • Docs (docs/api.md, docs/cli.md, CLAUDE.md), the OpenRPC spec (method and Round.boss_rerolled), Lua types and the balatrobot api method enum are updated.

A small separate fix (its own commit), found while writing the tests: add with a v_* key put the voucher in the shop without its shop UI, so buy {"voucher": i} on it crashed with attempt to index field 'buy_button' (a nil value). add now calls create_shop_card_ui (as the Voucher Tag does) and waits for the buy button before it returns.

Why

Bots could not use Director's Cut or Retcon at all: the vouchers could be bought, but their effect had no API.

How tested

On Linux (Steam/Proton), with the branch installed as the mod:

  • tests/lua/endpoints/test_reroll_boss.py (new, 8 tests): Director's Cut reroll (money -10, flag set), the second reroll in an ante is refused, Retcon rerolls 3 times, no voucher, $0, Credit Card at $0 (goes to -10), flag reset and reroll available again next ante, INVALID_STATE from SHOP.
  • tests/lua/endpoints/test_add.py::test_add_voucher_then_buy (new).
  • pytest -n 3 tests/lua: every tests/lua/endpoints test passes (433 passed). The failures were all tests/lua/core dispatcher/validator tests that need the debug test endpoints (DebugPlus, not installed on my machine), plus test_concurrent_requests_do_not_crash erroring on a missing instance fixture. Both are unrelated to this change.
  • pytest tests/cli: passes when run serially. With -n 2 (as in make test), test_api_error_formatted and test_api_output_is_indented_json fail with "Server disconnected" on main as well, without this change.
  • make quality passes (ruff, ty, mdformat, stylua 2.6.0 src/lua).
  • Manual check: bought Director's Cut, then reroll_boss changed the boss and money went $40 → $30. A second call returned the once-per-ante error.

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.
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.
@garfield-oo7

Copy link
Copy Markdown
Author

Closing this as a duplicate: I've just seen that dev already has a reroll_boss endpoint (f58ce86) with blinds.boss.reroll_available, and it also handles buying vouchers added with add. Sorry for the noise, and thanks for the work on dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant