added new logic to the new rewards

This commit is contained in:
DeSqBlocki
2026-08-23 00:43:43 +02:00
parent 4d858554be
commit 425686ec40
15 changed files with 1644 additions and 2662 deletions
+80 -10
View File
@@ -18,7 +18,8 @@ const {
} = require("./cookieEconomy");
const {
recordGameOutcome
recordGameOutcome,
trackProfileEvent
} = require("./profileSystem");
const GAME_COLLECTION =
@@ -112,7 +113,9 @@ async function startBlackjack(
interaction,
bet,
allowCustomBet = false,
allIn = false
source = "normal",
previousAllIn = false,
previousBet = 0
) {
if (
!allowCustomBet &&
@@ -196,6 +199,9 @@ async function startBlackjack(
getCookieBalance(houseId)
]);
const allIn =
bet === playerBalance;
if (playerBalance < bet) {
return temporaryEphemeralReply(
interaction,
@@ -276,6 +282,11 @@ async function startBlackjack(
doubled:
false,
allIn,
vaultAtBet:
playerBalance,
source,
previousAllIn,
previousBet,
deck,
playerCards,
dealerCards,
@@ -285,6 +296,20 @@ async function startBlackjack(
await games.insertOne(game);
await trackProfileEvent(
interaction,
playerId,
{
type: "game_start",
game: "blackjack",
source,
bet,
allIn,
previousAllIn,
previousBet
}
);
const playerBlackjack =
isBlackjack(playerCards);
@@ -370,7 +395,7 @@ async function startBlackjackAllIn(
interaction,
balance,
true,
true
"all_in"
);
}
@@ -405,6 +430,9 @@ async function runBlackjackBack(
const bet =
Number(parts[2]);
const previousAllIn =
parts[3] === "1";
if (
ownerId !==
interaction.user.id
@@ -435,7 +463,9 @@ async function runBlackjackBack(
interaction,
bet,
true,
false
"run_it_back",
previousAllIn,
bet
);
}
@@ -803,6 +833,32 @@ async function finishBlackjack(
game,
result
) {
const { db } = getCollections();
const claim = await db
.collection(GAME_COLLECTION)
.updateOne(
{
gameId: game.gameId,
state: "Playing"
},
{
$set: {
state: "Resolving"
}
}
);
if (claim.modifiedCount !== 1) {
return temporaryEphemeralReply(
interaction,
{
content:
"This Blackjack hand is already being resolved."
}
);
}
const houseId =
interaction.client.user.id;
@@ -845,6 +901,23 @@ async function finishBlackjack(
`[Blackjack] House cannot cover payout ${payout} for ${game.userId}`
);
await db
.collection(GAME_COLLECTION)
.updateOne(
{
gameId: game.gameId,
state: "Resolving"
},
{
$set: {
state: "Finished",
result: "PayoutError",
payout: 0,
finishedAt: getUnixTime()
}
}
);
return interaction.update({
embeds: [
new EmbedBuilder()
@@ -856,7 +929,7 @@ async function finishBlackjack(
)
.setFooter({
text:
`crumbBlackjackResult:${game.userId}:${game.originalBet}`
`crumbBlackjackResult:${game.userId}:${game.originalBet}:${game.allIn ? 1 : 0}`
})
],
components:
@@ -871,9 +944,6 @@ async function finishBlackjack(
);
}
const { db } =
getCollections();
await db
.collection(
GAME_COLLECTION
@@ -883,7 +953,7 @@ async function finishBlackjack(
gameId:
game.gameId,
state:
"Playing"
"Resolving"
},
{
$set: {
@@ -1010,7 +1080,7 @@ async function finishBlackjack(
)
.setFooter({
text:
`crumbBlackjackResult:${game.userId}:${game.originalBet}`
`crumbBlackjackResult:${game.userId}:${game.originalBet}:${game.allIn ? 1 : 0}`
});
return interaction.update({