This commit is contained in:
Milo
2025-09-24 17:23:20 +02:00
parent af83c9f7c2
commit cc917b4714
2 changed files with 119 additions and 64 deletions

View File

@@ -124,7 +124,7 @@ export function blackjackRoutes(io) {
bank,
currentBet: 0,
inRound: false,
hands: [{ cards: [], stood: false, busted: false, doubled: false, surrendered: false, hasActed: false }],
hands: [{ cards: [], stood: false, busted: false, doubled: false, surrendered: false, hasActed: false, bet: 0 }],
activeHand: 0,
joined_at: Date.now(),
msgId: null,
@@ -231,6 +231,7 @@ export function blackjackRoutes(io) {
}
p.currentBet = bet;
p.hands[p.activeHand].bet = bet;
emitToast({ type: "player-bet", userId, amount: bet });
emitUpdate("bet-placed", snapshot(room));
return res.status(200).json({ message: "bet-accepted" });
@@ -247,15 +248,32 @@ export function blackjackRoutes(io) {
if (action === "double" && !room.settings.fakeMoney) {
const userDB = getUser.get(userId);
const coins = userDB?.coins ?? 0;
if (coins < p.currentBet) return res.status(403).json({ message: "insufficient-funds-for-double" });
updateUserCoins.run({ id: userId, coins: coins - p.currentBet });
const hand = p.hands[p.activeHand];
if (coins < hand.bet) return res.status(403).json({ message: "insufficient-funds-for-double" });
updateUserCoins.run({ id: userId, coins: coins - hand.bet });
insertLog.run({
id: `${userId}-blackjack-${Date.now()}`,
user_id: userId, target_user_id: null,
action: 'BLACKJACK_DOUBLE',
coins_amount: -p.currentBet, user_new_amount: coins - p.currentBet,
coins_amount: -hand.bet, user_new_amount: coins - hand.bet,
});
p.bank = coins - p.currentBet;
p.bank = coins - hand.bet;
// effective bet size is handled in settlement via hand.doubled flag
}
if (action === "split" && !room.settings.fakeMoney) {
const userDB = getUser.get(userId);
const coins = userDB?.coins ?? 0;
const hand = p.hands[p.activeHand];
if (coins < hand.bet) return res.status(403).json({ message: "insufficient-funds-for-split" });
updateUserCoins.run({ id: userId, coins: coins - hand.bet });
insertLog.run({
id: `${userId}-blackjack-${Date.now()}`,
user_id: userId, target_user_id: null,
action: 'BLACKJACK_SPLIT',
coins_amount: -hand.bet, user_new_amount: coins - hand.bet,
});
p.bank = coins - hand.bet;
// effective bet size is handled in settlement via hand.doubled flag
}