added more achievments

This commit is contained in:
DeSqBlocki
2026-08-22 22:10:41 +02:00
parent ae35f61522
commit ca823726e3
12 changed files with 4977 additions and 1998 deletions
+33 -283
View File
@@ -22,12 +22,6 @@ const {
} = require("./profileSystem");
/*
* ============================================================
* CONFIG
* ============================================================
*/
const GAME_COLLECTION =
"items_games";
@@ -41,12 +35,6 @@ const BLACKJACK_BETS = [
];
/*
* ============================================================
* SHOW BLACKJACK MENU
* ============================================================
*/
async function showBlackjack(
interaction
) {
@@ -70,10 +58,6 @@ async function showBlackjack(
}
/*
* Resume an unfinished game.
*/
const active =
await getActiveBlackjack(
interaction.user.id,
@@ -146,26 +130,12 @@ async function showBlackjack(
}
/*
* ============================================================
* START GAME
* ============================================================
*/
async function startBlackjack(
interaction,
bet,
allowCustomBet =
false
) {
/*
* Normal wager buttons must use one of our
* predefined values.
*
* All In and Run It Back are allowed to use
* custom wager amounts.
*/
if (
!allowCustomBet
&&
@@ -183,11 +153,6 @@ async function startBlackjack(
}
/*
* Every wager, predefined or custom, must
* still be a positive safe integer.
*/
if (
!Number.isSafeInteger(
bet
@@ -238,10 +203,6 @@ async function startBlackjack(
);
/*
* Prevent multiple active hands.
*/
const existing =
await getActiveBlackjack(
interaction.user.id,
@@ -297,18 +258,6 @@ async function startBlackjack(
}
/*
* Natural Blackjack returns:
*
* wager + 3:2 winnings
*
* = 2.5x total payout.
*
* The wager will move into the house before
* resolution, so the house currently needs
* enough to cover the additional 1.5x.
*/
if (
houseBalance <
Math.ceil(
@@ -326,10 +275,6 @@ async function startBlackjack(
}
/*
* Take wager.
*/
try {
await transferCookies(
playerId,
@@ -356,12 +301,6 @@ async function startBlackjack(
}
/*
* ========================================================
* REAL 52-CARD DECK
* ========================================================
*/
const deck =
createDeck();
@@ -426,12 +365,6 @@ async function startBlackjack(
);
/*
* ========================================================
* NATURAL BLACKJACK CHECK
* ========================================================
*/
const playerBlackjack =
isBlackjack(
playerCards
@@ -448,10 +381,6 @@ async function startBlackjack(
playerBlackjack ||
dealerBlackjack
) {
/*
* Both natural Blackjack = Push.
*/
if (
playerBlackjack &&
dealerBlackjack
@@ -496,12 +425,6 @@ async function startBlackjack(
}
/*
* ============================================================
* ALL IN
* ============================================================
*/
async function startBlackjackAllIn(
interaction
) {
@@ -525,10 +448,6 @@ async function startBlackjackAllIn(
}
/*
* Resolve balance at click time.
*/
const balance =
await getCookieBalance(
interaction.user.id
@@ -549,11 +468,6 @@ async function startBlackjackAllIn(
}
/*
* true allows the balance to be used even though
* it likely isn't one of BLACKJACK_BETS.
*/
return startBlackjack(
interaction,
balance,
@@ -562,16 +476,6 @@ async function startBlackjackAllIn(
}
/*
* ============================================================
* RUN IT BACK
* ============================================================
*
* Reuses only the previous BET.
*
* A completely new shuffled deck and hand are created.
*/
async function runBlackjackBack(
interaction
) {
@@ -588,12 +492,6 @@ async function runBlackjackBack(
[];
/*
* Expected:
*
* crumbBlackjackResult:<userId>:<bet>
*/
if (
parts[0] !==
"crumbBlackjackResult"
@@ -650,13 +548,6 @@ async function runBlackjackBack(
}
/*
* Reuse the exact previous wager.
*
* true is required because a previous All In bet
* may not be part of BLACKJACK_BETS.
*/
return startBlackjack(
interaction,
bet,
@@ -665,12 +556,6 @@ async function runBlackjackBack(
}
/*
* ============================================================
* HIT
* ============================================================
*/
async function hitBlackjack(
interaction
) {
@@ -748,27 +633,25 @@ async function hitBlackjack(
getCollections();
const games =
db.collection(
await db
.collection(
GAME_COLLECTION
);
)
.updateOne(
{
gameId:
game.gameId,
await games.updateOne(
{
gameId:
game.gameId,
state:
"Playing"
},
{
$set: {
deck,
playerCards
state:
"Playing"
},
{
$set: {
deck,
playerCards
}
}
}
);
);
const updated = {
@@ -778,10 +661,6 @@ async function hitBlackjack(
};
/*
* Bust.
*/
if (
score >
21
@@ -794,10 +673,6 @@ async function hitBlackjack(
}
/*
* Automatically stand on exactly 21.
*/
if (
score ===
21
@@ -824,12 +699,6 @@ async function hitBlackjack(
}
/*
* ============================================================
* STAND
* ============================================================
*/
async function standBlackjack(
interaction,
suppliedGame =
@@ -884,10 +753,6 @@ async function standBlackjack(
];
/*
* Dealer stands on 17.
*/
while (
getHandValue(
dealerCards
@@ -950,10 +815,6 @@ async function standBlackjack(
}
/*
* Same value = Push.
*/
else {
result =
"Push";
@@ -968,12 +829,6 @@ async function standBlackjack(
}
/*
* ============================================================
* DOUBLE
* ============================================================
*/
async function doubleBlackjack(
interaction
) {
@@ -1008,10 +863,6 @@ async function doubleBlackjack(
}
/*
* Double only on initial two cards.
*/
if (
game.playerCards.length !==
2
@@ -1086,10 +937,6 @@ async function doubleBlackjack(
];
/*
* Double receives exactly one additional card.
*/
playerCards.push(
deck.pop()
);
@@ -1158,10 +1005,6 @@ async function doubleBlackjack(
}
/*
* Double automatically stands.
*/
return standBlackjack(
interaction,
updated
@@ -1169,12 +1012,6 @@ async function doubleBlackjack(
}
/*
* ============================================================
* FINISH GAME
* ============================================================
*/
async function finishBlackjack(
interaction,
game,
@@ -1188,11 +1025,9 @@ async function finishBlackjack(
0;
switch (result) {
/*
* Normal win.
*/
switch (
result
) {
case "Win":
case "DealerBust":
@@ -1203,12 +1038,6 @@ async function finishBlackjack(
break;
/*
* Push:
*
* Return exactly the wager.
*/
case "Push":
payout =
@@ -1217,12 +1046,6 @@ async function finishBlackjack(
break;
/*
* Natural Blackjack:
*
* stake + 3:2 winnings.
*/
case "Blackjack":
payout =
@@ -1234,10 +1057,6 @@ async function finishBlackjack(
break;
/*
* Bust / Loss / Dealer Blackjack.
*/
default:
payout =
@@ -1245,10 +1064,6 @@ async function finishBlackjack(
}
/*
* Pay player.
*/
if (
payout >
0
@@ -1281,7 +1096,7 @@ async function finishBlackjack(
.setFooter({
text:
`crumbBlackjackResult:${game.userId}:${game.originalBet ?? game.bet}`
`crumbBlackjackResult:${game.userId}:${game.originalBet}`
})
],
@@ -1299,10 +1114,6 @@ async function finishBlackjack(
}
/*
* Mark game finished.
*/
const {
db
} =
@@ -1356,6 +1167,7 @@ async function finishBlackjack(
let profileResult;
if (
result ===
"Push"
@@ -1364,6 +1176,7 @@ async function finishBlackjack(
"push";
}
else if (
[
"Win",
@@ -1377,6 +1190,7 @@ async function finishBlackjack(
"win";
}
else {
profileResult =
"loss";
@@ -1394,7 +1208,9 @@ async function finishBlackjack(
"blackjack",
result:
profileResult
profileResult,
profit
}
);
@@ -1416,6 +1232,7 @@ async function finishBlackjack(
);
}
else if (
profit <
0
@@ -1520,12 +1337,15 @@ async function finishBlackjack(
)
/*
* Owner + previous exact wager.
* Important:
*
* Run It Back uses the original wager,
* not the doubled total.
*/
.setFooter({
text:
`crumbBlackjackResult:${game.userId}:${game.originalBet ?? game.bet}`
`crumbBlackjackResult:${game.userId}:${game.originalBet}`
});
@@ -1540,12 +1360,6 @@ async function finishBlackjack(
}
/*
* ============================================================
* GAME EMBED
* ============================================================
*/
function buildGameEmbed(
game
) {
@@ -1608,12 +1422,6 @@ function buildGameEmbed(
}
/*
* ============================================================
* BET BUTTONS
* ============================================================
*/
function buildBetButtons() {
return [
new ActionRowBuilder()
@@ -1624,18 +1432,14 @@ function buildBetButtons() {
.setCustomId(
`crumbBlackjackBet${bet}`
)
.setLabel(
bet.toLocaleString()
)
.setEmoji(
"🍪"
)
.setStyle(
bet >=
500
bet >= 500
? ButtonStyle.Primary
: ButtonStyle.Secondary
)
@@ -1676,12 +1480,6 @@ function buildBetButtons() {
}
/*
* ============================================================
* ACTIVE GAME BUTTONS
* ============================================================
*/
function buildGameButtons(
game
) {
@@ -1744,12 +1542,6 @@ function buildGameButtons(
}
/*
* ============================================================
* RESULT BUTTONS
* ============================================================
*/
function buildResultButtons() {
return [
new ActionRowBuilder()
@@ -1800,12 +1592,6 @@ function buildResultButtons() {
}
/*
* ============================================================
* CARDS
* ============================================================
*/
function createDeck() {
const suits = [
"♠️",
@@ -1988,12 +1774,6 @@ function formatCards(
}
/*
* ============================================================
* DATABASE LOOKUPS
* ============================================================
*/
async function getActiveBlackjack(
userId,
guildId
@@ -2072,12 +1852,6 @@ async function getGameFromInteraction(
}
/*
* ============================================================
* SESSION OWNER
* ============================================================
*/
function getBlackjackSessionOwner(
interaction
) {
@@ -2110,12 +1884,6 @@ function getBlackjackSessionOwner(
}
/*
* Active hand:
*
* crumbBlackjack:<gameId>:<userId>
*/
if (
parts[0] ===
"crumbBlackjack"
@@ -2124,12 +1892,6 @@ function getBlackjackSessionOwner(
}
/*
* Finished result:
*
* crumbBlackjackResult:<userId>:<bet>
*/
if (
parts[0] ===
"crumbBlackjackResult"
@@ -2142,12 +1904,6 @@ function getBlackjackSessionOwner(
}
/*
* ============================================================
* RESULT TITLES
* ============================================================
*/
function getResultTitle(
result
) {
@@ -2191,12 +1947,6 @@ function getResultTitle(
}
/*
* ============================================================
* EXPORTS
* ============================================================
*/
module.exports = {
showBlackjack,