Skip to content

Commit 1202866

Browse files
committed
feat: add reroll shop action
1 parent c77c52b commit 1202866

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/lua/api.lua

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,12 +696,43 @@ API.functions["shop"] = function(args)
696696
end,
697697
}
698698

699+
elseif action == "reroll" then
700+
-- Capture the state before rerolling
701+
local dollars_before = G.GAME.dollars
702+
local reroll_cost = G.GAME.current_round and G.GAME.current_round.reroll_cost or 0
703+
local expected_dollars = dollars_before - reroll_cost
704+
705+
local times_rerolled_before = 0
706+
if G.GAME.round_scores and G.GAME.round_scores.times_rerolled then
707+
times_rerolled_before = G.GAME.round_scores.times_rerolled.amt or 0
708+
709+
sendDebugMessage("times_rerolled_before: " .. tostring(times_rerolled_before))
710+
end
711+
712+
-- Perform the reroll (nil element because the function doesn't require it)
713+
G.FUNCS.reroll_shop(nil)
714+
715+
---@type PendingRequest
716+
API.pending_requests["shop"] = {
717+
condition = function()
718+
return utils.COMPLETION_CONDITIONS.cash_out()
719+
and G.GAME.round_scores
720+
and G.GAME.round_scores.times_rerolled
721+
and G.GAME.round_scores.times_rerolled.amt == times_rerolled_before + 1
722+
and G.GAME.dollars == expected_dollars
723+
end,
724+
action = function()
725+
local game_state = utils.get_game_state()
726+
API.send_response(game_state)
727+
end,
728+
}
729+
699730
-- TODO: add other shop actions [buy_and_use | reroll | open_pack | redeem_voucher]
700731
else
701732
API.send_error_response(
702733
"Invalid action for shop",
703734
ERROR_CODES.INVALID_ACTION,
704-
{ action = action, valid_actions = { "next_round" } }
735+
{ action = action, valid_actions = { "next_round", "buy_card", "reroll" } }
705736
)
706737
return
707738
end

0 commit comments

Comments
 (0)