fix: Correct PnL calculation by using betAmount in net profit computation
Some checks failed
Deploy to Production / test (push) Failing after 34s
Some checks failed
Deploy to Production / test (push) Failing after 34s
- Add betAmount field to BlackjackState to track the base bet - Fix finishPlayerTurns: multiply hand.bet by state.betAmount for actual money bets - Fix GameServer: roundPayouts are already gross payouts (not multipliers) - Update cumulative PnL calculation to correctly subtract actual bet amount - Add betAmount support to riggedState test helper
This commit is contained in:
@@ -95,10 +95,9 @@ export class GameServer {
|
||||
const gameName = gameRegistry.get(room.gameSlug)?.name ?? "Game";
|
||||
const payoutDetails: Record<string, { net: number }> = {};
|
||||
|
||||
for (const [playerId, multiplier] of Object.entries(roundPayouts)) {
|
||||
if (multiplier <= 0) continue;
|
||||
const grossPayout = Math.floor(betAmount * multiplier);
|
||||
const netProfit = grossPayout - betAmount; // Calculate net profit (gross payout minus original bet)
|
||||
for (const [playerId, grossPayout] of Object.entries(roundPayouts)) {
|
||||
// roundPayout is already the gross payout amount (not a multiplier)
|
||||
const netProfit = Math.floor(grossPayout) - betAmount; // Calculate net profit (gross payout minus original bet)
|
||||
try {
|
||||
await economyService.modifyUserBalance(
|
||||
playerId,
|
||||
|
||||
Reference in New Issue
Block a user