Updated Coinflip + some other changes

coin no longer favours heads, losing subtracts double your bet (unless you have less than that, in which case it subtracts until 0), corrected the scramble payout mismatch
This commit is contained in:
Darien Rousseau 2023-12-21 12:14:42 -06:00 committed by GitHub
parent 38c8811b51
commit 9526fa6a42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -72,7 +72,7 @@ checkAndModifyPoints = async (user, amount, override) => {
return row.points + amount; return row.points + amount;
} }
return false; return false;
}); });`
} }
checkPoints = (user) => { checkPoints = (user) => {
@ -642,26 +642,27 @@ client.on("interactionCreate", async interaction => {
}); });
// Flip the coin // Flip the coin
coin = Math.random() < 0.6 ? "heads" : "tails"; coin = Math.random() <= 0.5 ? "heads" : "tails";
before = await checkPoints(interaction.user);
side = interaction.options.getString("side"); side = interaction.options.getString("side");
outcome = coin == side ? true : false; outcome = coin == side ? true : false;
// If they win, give them the prize, if they lose, take the prize // If they win, give them the prize, if they lose take up to double the prize away
// if they lose inverse the bet // if they lose inverse the bet and double it
if (!outcome) bet = -bet; if (!outcome) bet = -bet * 2;
await checkAndModifyPoints(interaction.user, bet); bet = Math.max( 0, points + bet);
setCooldown(interaction.user, "coinflip", config.games.coinflip.cooldown * 60 * 1000) poor = bet <= 0 ? true : false;
await checkAndModifyPoints(interaction.user, bet, poor);
setCooldown(interaction.user, "coinflip", config.games.coinflip.cooldown * 60 * 1000) //sanity checks in case they somehow started a coinflip despite having a negative balance
if (coin == "heads") return interaction.reply({ if (coin == "heads") return interaction.reply({
embeds: [{ embeds: [{
title: "Coinflip", title: "Coinflip",
description: `You flipped ${config.games.coinflip.heads} and **${outcome ? "won" : "lost"}** ${Math.abs(bet)} coins!`, description: `You flipped ${config.games.coinflip.heads} and **${outcome ? "won" : "lost"}** ${poor ? Math.abs(points) : Math.abs(bet)} coins!`, // sanity check
color: outcome ? 0x00ff00 : 0xff0000 color: outcome ? 0x00ff00 : 0xff0000
}] }]
}); });
else if (coin == "tails") return interaction.reply({ else if (coin == "tails") return interaction.reply({
embeds: [{ embeds: [{
title: "Coinflip", title: "Coinflip",
description: `You flipped ${config.games.coinflip.tails} and **${outcome ? "won" : "lost"}** ${Math.abs(bet)} coins!`, description: `You flipped ${config.games.coinflip.tails} and **${outcome ? "won" : "lost"}** ${poor ? Math.abs(points) : Math.abs(bet)} coins!`,
color: outcome ? 0x00ff00 : 0xff0000 color: outcome ? 0x00ff00 : 0xff0000
}] }]
}); });
@ -913,13 +914,15 @@ function wordScramble() {
}).sort(function () { }).sort(function () {
return 0.5 - Math.random(); return 0.5 - Math.random();
}).join(''); }).join('');
// if the scrambled word is the same as the word, scramble it again // if the scrambled word is the same as the word, keep scrambling it until they are different
if (scrambledWord == word) { if (scrambledWord == word) {
scrambledWord = word.split('').sort(function () { while (scrambledWord == word) {
return 0.5 - Math.random(); scrambledWord = word.split('').sort(function () {
}).sort(function () { return 0.5 - Math.random();
return 0.5 - Math.random(); }).sort(function () {
}).join(''); return 0.5 - Math.random();
}).join('');
}
} }
return { return {
word: word, word: word,
@ -1074,9 +1077,10 @@ function playSlotMachine() {
return result; return result;
} }
const rockPaperScissors = (userChoice) => { const roshambo = (userChoice) => {
const choices = ['🪨', '📄', '✂️']; const choices = ['🪨', '📄', '✂️'];
const botChoice = choices[Math.floor(Math.random() * choices.length)]; //Changed it to be hardcoded because RPS only ever has 3 choices.
const botChoice = choices[Math.floor(Math.random() * 3)];
if (userChoice === botChoice) return 'It\'s a tie!'; if (userChoice === botChoice) return 'It\'s a tie!';
else if ( else if (