Poker Fixes

This commit is contained in:
Dragon Fire
2020-06-11 10:25:45 -04:00
parent abaeee894d
commit c994db725e
2 changed files with 22 additions and 21 deletions
+21 -20
View File
@@ -56,7 +56,7 @@ module.exports = class PokerCommand extends Command {
const { players, deck, turnData } = this.client.games.get(msg.channel.id).data; const { players, deck, turnData } = this.client.games.get(msg.channel.id).data;
for (const player of awaitedPlayers) { for (const player of awaitedPlayers) {
players.set(player, { players.set(player, {
money: 5000, money: 2000,
id: player, id: player,
hand: [], hand: [],
user: await this.client.users.fetch(player), user: await this.client.users.fetch(player),
@@ -98,37 +98,37 @@ module.exports = class PokerCommand extends Command {
turnData.pot = bigBlindAmount + smallBlindAmount; turnData.pot = bigBlindAmount + smallBlindAmount;
turnData.currentBet = bigBlindAmount; turnData.currentBet = bigBlindAmount;
turnData.highestBetter = bigBlind; turnData.highestBetter = bigBlind;
let keepGoing = await this.gameRound(msg, players, folded, turnData, bigBlind, smallBlind); let keepGoing = await this.gameRound(msg, players, deck, folded, turnData, bigBlind, smallBlind);
if (!keepGoing) continue; if (!keepGoing) continue;
const dealerHand = deck.draw(3); const dealerHand = deck.draw(3);
await msg.say(stripIndents` await msg.say(stripIndents`
**Dealer Hand:** **Dealer Hand:**
${dealerHand.map(card => card.textDisplay).join('\n')} ${dealerHand.map(card => card.textDisplay).join('\n')}
_Next betting round begins in 5 seconds._ _Next betting round begins in 10 seconds._
`); `);
await delay(5000); await delay(10000);
keepGoing = await this.gameRound(msg, players, folded, turnData, bigBlind, smallBlind); keepGoing = await this.gameRound(msg, players, deck, folded, turnData, bigBlind, smallBlind);
if (!keepGoing) continue; if (!keepGoing) continue;
dealerHand.push(deck.draw()); dealerHand.push(deck.draw());
await msg.say(stripIndents` await msg.say(stripIndents`
**Dealer Hand:** **Dealer Hand:**
${dealerHand.map(card => card.textDisplay).join('\n')} ${dealerHand.map(card => card.textDisplay).join('\n')}
_Next betting round begins in 5 seconds._ _Next betting round begins in 10 seconds._
`); `);
await delay(5000); await delay(10000);
keepGoing = await this.gameRound(msg, players, folded, turnData, bigBlind, smallBlind); keepGoing = await this.gameRound(msg, players, deck, folded, turnData, bigBlind, smallBlind);
if (!keepGoing) continue; if (!keepGoing) continue;
dealerHand.push(deck.draw()); dealerHand.push(deck.draw());
await msg.say(stripIndents` await msg.say(stripIndents`
**Dealer Hand:** **Dealer Hand:**
${dealerHand.map(card => card.textDisplay).join('\n')} ${dealerHand.map(card => card.textDisplay).join('\n')}
_Next betting round begins in 5 seconds._ _Next betting round begins in 10 seconds._
`); `);
await delay(5000); await delay(10000);
keepGoing = await this.gameRound(msg, players, folded, turnData, bigBlind, smallBlind); keepGoing = await this.gameRound(msg, players, deck, folded, turnData, bigBlind, smallBlind);
if (!keepGoing) continue; if (!keepGoing) continue;
const solved = []; const solved = [];
for (const playerID of rotation) { for (const playerID of rotation) {
@@ -150,7 +150,7 @@ module.exports = class PokerCommand extends Command {
__**Results**__ __**Results**__
${solved.map(solve => `${solve.user.user.tag}: ${solve.descr}`).join('\n')} ${solved.map(solve => `${solve.user.user.tag}: ${solve.descr}`).join('\n')}
_Next game starting in 10 seconds._ _Next game starting in 15 seconds._
`); `);
const splitPot = turnData.pot / winners.length; const splitPot = turnData.pot / winners.length;
for (const win of winners) win.user.money += splitPot; for (const win of winners) win.user.money += splitPot;
@@ -161,16 +161,16 @@ module.exports = class PokerCommand extends Command {
__**Results**__ __**Results**__
${solved.map(solve => `${solve.user.user.tag}: ${solve.descr}`).join('\n')} ${solved.map(solve => `${solve.user.user.tag}: ${solve.descr}`).join('\n')}
_Next game starting in 10 seconds._ _Next game starting in 15 seconds._
`); `);
winners[0].user.money += turnData.pot; winners[0].user.money += turnData.pot;
} }
await this.resetGame(msg, players); await this.resetGame(msg, players, deck);
if (players.size <= 1) { if (players.size <= 1) {
winner = players.first(); winner = players.first();
break; break;
} }
await delay(10000); await delay(15000);
} }
this.client.games.delete(msg.channel.id); this.client.games.delete(msg.channel.id);
return msg.say(`Congrats, ${winner.user}!`); return msg.say(`Congrats, ${winner.user}!`);
@@ -197,7 +197,7 @@ module.exports = class PokerCommand extends Command {
].filter(player => !folded.includes(player)); ].filter(player => !folded.includes(player));
} }
async gameRound(msg, players, folded, turnData, bigBlind, smallBlind) { async gameRound(msg, players, deck, folded, turnData, bigBlind, smallBlind) {
let turnOver = false; let turnOver = false;
const turnRotation = this.makeTurnRotation(players, folded, bigBlind, smallBlind); const turnRotation = this.makeTurnRotation(players, folded, bigBlind, smallBlind);
while (!turnOver) turnOver = await this.bettingRound(msg, players, turnRotation, folded, turnData); while (!turnOver) turnOver = await this.bettingRound(msg, players, turnRotation, folded, turnData);
@@ -207,11 +207,11 @@ module.exports = class PokerCommand extends Command {
await msg.say(stripIndents` await msg.say(stripIndents`
${remainer.user} takes the pot. ${remainer.user} takes the pot.
_Next game starting in 10 seconds._ _Next game starting in 15 seconds._
`); `);
remainer.money += turnData.pot; remainer.money += turnData.pot;
await this.resetGame(msg, players); await this.resetGame(msg, players, deck);
await delay(10000); await delay(15000);
return false; return false;
} }
return true; return true;
@@ -291,7 +291,8 @@ module.exports = class PokerCommand extends Command {
|| turnRotation.length === 1; || turnRotation.length === 1;
} }
async resetGame(msg, players) { async resetGame(msg, players, deck) {
deck.reset();
for (const player of players.values()) { for (const player of players.values()) {
if (player.money <= 0 || player.strikes >= 3) { if (player.money <= 0 || player.strikes >= 3) {
await msg.say(`${player.user} has been kicked.`); await msg.say(`${player.user} has been kicked.`);
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiao", "name": "xiao",
"version": "116.16.0", "version": "116.16.1",
"description": "Your personal server companion.", "description": "Your personal server companion.",
"main": "Xiao.js", "main": "Xiao.js",
"scripts": { "scripts": {