mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-25 06:42:51 +02:00
Fix
This commit is contained in:
+45
-43
@@ -61,7 +61,8 @@ module.exports = class PokerCommand extends Command {
|
|||||||
id: player,
|
id: player,
|
||||||
hand: [],
|
hand: [],
|
||||||
user: this.client.users.cache.get(player),
|
user: this.client.users.cache.get(player),
|
||||||
currentBet: 0
|
currentBet: 0,
|
||||||
|
hasGoneOnce: false
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
let winner = null;
|
let winner = null;
|
||||||
@@ -95,16 +96,8 @@ 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 turnOver = false;
|
const keepGoing = await this.gameRound(msg, players, folded, turnData, bigBlind, smallBlind);
|
||||||
let turnRotation = this.makeTurnRotation(players, folded, bigBlind, smallBlind);
|
if (!keepGoing) continue;
|
||||||
while (!turnOver) turnOver = await this.bettingRound(msg, players, turnRotation, folded, turnData);
|
|
||||||
if (turnRotation.length === 1) {
|
|
||||||
const remainer = players.get(turnRotation[0]);
|
|
||||||
await msg.say(`${remainer.user} takes the pot.`);
|
|
||||||
remainer.money += turnData.pot;
|
|
||||||
await this.resetGame(msg, players);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const dealerHand = deck.draw(3);
|
const dealerHand = deck.draw(3);
|
||||||
await msg.say(stripIndents`
|
await msg.say(stripIndents`
|
||||||
**Dealer Hand:**
|
**Dealer Hand:**
|
||||||
@@ -113,16 +106,8 @@ module.exports = class PokerCommand extends Command {
|
|||||||
_Next betting round begins in 5 seconds._
|
_Next betting round begins in 5 seconds._
|
||||||
`);
|
`);
|
||||||
await delay(5000);
|
await delay(5000);
|
||||||
turnOver = false;
|
const keepGoing = await this.gameRound(msg, players, folded, turnData, bigBlind, smallBlind);
|
||||||
turnRotation = this.makeTurnRotation(players, folded, bigBlind, smallBlind);
|
if (!keepGoing) continue;
|
||||||
while (!turnOver) turnOver = await this.bettingRound(msg, players, turnRotation, folded, turnData);
|
|
||||||
if (turnRotation.length === 1) {
|
|
||||||
const remainer = players.get(turnRotation[0]);
|
|
||||||
await msg.say(`${remainer.user} takes the pot.`);
|
|
||||||
remainer.money += turnData.pot;
|
|
||||||
await this.resetGame(msg, players);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
dealerHand.push(deck.draw());
|
dealerHand.push(deck.draw());
|
||||||
await msg.say(stripIndents`
|
await msg.say(stripIndents`
|
||||||
**Dealer Hand:**
|
**Dealer Hand:**
|
||||||
@@ -131,16 +116,8 @@ module.exports = class PokerCommand extends Command {
|
|||||||
_Next betting round begins in 5 seconds._
|
_Next betting round begins in 5 seconds._
|
||||||
`);
|
`);
|
||||||
await delay(5000);
|
await delay(5000);
|
||||||
turnOver = false;
|
const keepGoing = await this.gameRound(msg, players, folded, turnData, bigBlind, smallBlind);
|
||||||
turnRotation = this.makeTurnRotation(players, folded, bigBlind, smallBlind);
|
if (!keepGoing) continue;
|
||||||
while (!turnOver) turnOver = await this.bettingRound(msg, players, turnRotation, folded, turnData);
|
|
||||||
if (turnRotation.length === 1) {
|
|
||||||
const remainer = players.get(turnRotation[0]);
|
|
||||||
await msg.say(`${remainer.user} takes the pot.`);
|
|
||||||
remainer.money += turnData.pot;
|
|
||||||
await this.resetGame(msg, players);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
dealerHand.push(deck.draw());
|
dealerHand.push(deck.draw());
|
||||||
await msg.say(stripIndents`
|
await msg.say(stripIndents`
|
||||||
**Dealer Hand:**
|
**Dealer Hand:**
|
||||||
@@ -149,16 +126,8 @@ module.exports = class PokerCommand extends Command {
|
|||||||
_Next betting round begins in 5 seconds._
|
_Next betting round begins in 5 seconds._
|
||||||
`);
|
`);
|
||||||
await delay(5000);
|
await delay(5000);
|
||||||
turnOver = false;
|
const keepGoing = await this.gameRound(msg, players, folded, turnData, bigBlind, smallBlind);
|
||||||
turnRotation = this.makeTurnRotation(players, folded, bigBlind, smallBlind);
|
if (!keepGoing) continue;
|
||||||
while (!turnOver) turnOver = await this.bettingRound(msg, players, turnRotation, folded, turnData);
|
|
||||||
if (turnRotation.length === 1) {
|
|
||||||
const remainer = players.get(turnRotation[0]);
|
|
||||||
await msg.say(`${remainer.user} takes the pot.`);
|
|
||||||
remainer.money += turnData.pot;
|
|
||||||
await this.resetGame(msg, players);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const solved = [];
|
const solved = [];
|
||||||
for (const playerID of turnRotation) {
|
for (const playerID of turnRotation) {
|
||||||
if (folded.includes(playerID)) continue;
|
if (folded.includes(playerID)) continue;
|
||||||
@@ -175,6 +144,11 @@ module.exports = class PokerCommand extends Command {
|
|||||||
await msg.say(stripIndents`
|
await msg.say(stripIndents`
|
||||||
The pot will be split between ${list(winners.map(w => `**${w.user.user}**`))}.
|
The pot will be split between ${list(winners.map(w => `**${w.user.user}**`))}.
|
||||||
${winners.map(winner.descr).join(', ')}
|
${winners.map(winner.descr).join(', ')}
|
||||||
|
|
||||||
|
__**Results**__
|
||||||
|
${solved.map(solve => `${solve.user.user.tag}: ${solve.descr}`).join('\n')}
|
||||||
|
|
||||||
|
_Next game starting in 10 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;
|
||||||
@@ -184,6 +158,8 @@ 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._
|
||||||
`);
|
`);
|
||||||
winners[0].user.money += turnData.pot;
|
winners[0].user.money += turnData.pot;
|
||||||
}
|
}
|
||||||
@@ -192,6 +168,7 @@ module.exports = class PokerCommand extends Command {
|
|||||||
winner = players.first();
|
winner = players.first();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
await delay(10000);
|
||||||
}
|
}
|
||||||
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}!`);
|
||||||
@@ -236,6 +213,21 @@ module.exports = class PokerCommand extends Command {
|
|||||||
].filter(player => !folded.includes(player));
|
].filter(player => !folded.includes(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async gameRound(msg, players, folded, turnData, bigBlind, smallBlind) {
|
||||||
|
let turnOver = false;
|
||||||
|
let turnRotation = this.makeTurnRotation(players, folded, bigBlind, smallBlind);
|
||||||
|
while (!turnOver) turnOver = await this.bettingRound(msg, players, turnRotation, folded, turnData);
|
||||||
|
this.resetHasGoneOnce();
|
||||||
|
if (turnRotation.length === 1) {
|
||||||
|
const remainer = players.get(turnRotation[0]);
|
||||||
|
await msg.say(`${remainer.user} takes the pot.`);
|
||||||
|
remainer.money += turnData.pot;
|
||||||
|
await this.resetGame(msg, players);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
async bettingRound(msg, players, turnRotation, folded, data) {
|
async bettingRound(msg, players, turnRotation, folded, data) {
|
||||||
const oldHighestBetter = data.highestBetter;
|
const oldHighestBetter = data.highestBetter;
|
||||||
const turnPlayer = players.get(turnRotation[0]);
|
const turnPlayer = players.get(turnRotation[0]);
|
||||||
@@ -296,8 +288,12 @@ module.exports = class PokerCommand extends Command {
|
|||||||
}
|
}
|
||||||
if (choiceAction !== 'fold') turnRotation.push(turnRotation[0]);
|
if (choiceAction !== 'fold') turnRotation.push(turnRotation[0]);
|
||||||
turnRotation.shift();
|
turnRotation.shift();
|
||||||
return (oldHighestBetter.id === turnPlayer.id && choiceAction === 'check')
|
turnPlayer.hasGoneOnce = true;
|
||||||
|| (oldHighestBetter.currentBet === turnPlayer.currentBet && turnRotation[0] === oldHighestBetter.id)
|
const nextPlayer = players.get(turnRotation[0]);
|
||||||
|
return (oldHighestBetter.id === turnPlayer.id && choiceAction === 'check' && nextPlayer.hasGoneOnce)
|
||||||
|
|| (oldHighestBetter.currentBet === turnPlayer.currentBet
|
||||||
|
&& turnRotation[0] === oldHighestBetter.id
|
||||||
|
&& nextPlayer.hasGoneOnce)
|
||||||
|| turnRotation.length === 1;
|
|| turnRotation.length === 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,8 +305,14 @@ module.exports = class PokerCommand extends Command {
|
|||||||
} else {
|
} else {
|
||||||
player.currentBet = 0;
|
player.currentBet = 0;
|
||||||
player.hand = [];
|
player.hand = [];
|
||||||
|
player.hasGoneOnce = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resetHasGoneOnce(players) {
|
||||||
|
for (const player of players.values()) player.hasGoneOnce = false;
|
||||||
|
return players;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user