mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-15 00:12:38 +02:00
Russian Roulette many players
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
const Command = require('../../structures/Command');
|
const Command = require('../../structures/Command');
|
||||||
const { stripIndents } = require('common-tags');
|
const { stripIndents } = require('common-tags');
|
||||||
const { shuffle, verify } = require('../../util/Util');
|
const { shuffle, verify, awaitPlayers, removeFromArray } = require('../../util/Util');
|
||||||
|
|
||||||
module.exports = class RussianRouletteCommand extends Command {
|
module.exports = class RussianRouletteCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
@@ -12,58 +12,75 @@ module.exports = class RussianRouletteCommand extends Command {
|
|||||||
description: 'Who will pull the trigger and die first?',
|
description: 'Who will pull the trigger and die first?',
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
key: 'opponent',
|
key: 'playersCount',
|
||||||
prompt: 'What user would you like to play against? To play against AI, choose me.',
|
prompt: 'How many players are you expecting to have?',
|
||||||
type: 'user'
|
type: 'integer',
|
||||||
|
min: 1,
|
||||||
|
max: 7
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(msg, { opponent }) {
|
async run(msg, { playersCount }) {
|
||||||
if (opponent.id === msg.author.id) return msg.reply('You may not challenge yourself.');
|
|
||||||
if (this.client.blacklist.user.includes(opponent.id)) return msg.reply('This user is blacklisted.');
|
|
||||||
const current = this.client.games.get(msg.channel.id);
|
const current = this.client.games.get(msg.channel.id);
|
||||||
if (current) return msg.reply(`Please wait until the current game of \`${current.name}\` is finished.`);
|
if (current) return msg.reply(`Please wait until the current game of \`${current.name}\` is finished.`);
|
||||||
this.client.games.set(msg.channel.id, { name: this.name });
|
this.client.games.set(msg.channel.id, { name: this.name });
|
||||||
try {
|
try {
|
||||||
if (!opponent.bot) {
|
const awaitedPlayers = await awaitPlayers(msg, playersCount, 1, this.client.blacklist.user);
|
||||||
await msg.say(`${opponent}, do you accept this challenge?`);
|
if (!awaitedPlayers) {
|
||||||
const verification = await verify(msg.channel, opponent);
|
this.client.games.delete(msg.channel.id);
|
||||||
if (!verification) {
|
return msg.say('Game could not be started...');
|
||||||
this.client.games.delete(msg.channel.id);
|
|
||||||
return msg.say('Looks like they declined...');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
let userTurn = true;
|
const players = new Collection();
|
||||||
|
for (const player of awaitedPlayers) {
|
||||||
|
players.set(player, {
|
||||||
|
id: player,
|
||||||
|
user: await this.client.users.fetch(player)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
players.set(this.client.user.id, {
|
||||||
|
id: this.client.user.id,
|
||||||
|
user: this.client.user
|
||||||
|
});
|
||||||
|
const turn = shuffle(players.map(player => player.id));
|
||||||
const gun = shuffle([true, false, false, false, false, false, false, false]);
|
const gun = shuffle([true, false, false, false, false, false, false, false]);
|
||||||
let round = 0;
|
let round = 0;
|
||||||
let winner = null;
|
let loser = null;
|
||||||
let quit = false;
|
|
||||||
while (!winner) {
|
while (!winner) {
|
||||||
const player = userTurn ? msg.author : opponent;
|
const player = players.get(turn[0]);
|
||||||
const notPlayer = userTurn ? opponent : msg.author;
|
turn.push(turn[0]);
|
||||||
|
turn.shift();
|
||||||
if (gun[round]) {
|
if (gun[round]) {
|
||||||
await msg.say(`**${player.tag}** pulls the trigger... **And dies!**`);
|
await msg.say(`**${player.tag}** pulls the trigger... **And dies!**`);
|
||||||
winner = notPlayer;
|
loser = player;
|
||||||
} else {
|
} else {
|
||||||
await msg.say(stripIndents`
|
await msg.say(stripIndents`
|
||||||
**${player.tag}** pulls the trigger... **And lives...**
|
**${player.tag}** pulls the trigger... **And lives...**
|
||||||
${opponent.bot ? 'Continue?' : `Will you take the gun, ${notPlayer}?`} (${8 - round - 1} shots left)
|
${opponent.bot ? '' : `Will you take the gun, ${players.get(turn[0]).user}?`}
|
||||||
`);
|
`);
|
||||||
const keepGoing = await verify(msg.channel, opponent.bot ? msg.author : notPlayer);
|
if (!opponent.bot) {
|
||||||
if (!keepGoing) {
|
let first = true;
|
||||||
if (opponent.bot) winner = opponent;
|
for (const next of turn) {
|
||||||
else winner = player;
|
const nextPlayer = players.get(next);
|
||||||
quit = true;
|
if (!first) {
|
||||||
|
await msg.say(stripIndents`
|
||||||
|
Coward.
|
||||||
|
${nextPlayer.user}, will YOU take the gun?
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
if (first) first = false;
|
||||||
|
const keepGoing = await verify(msg.channel, nextPlayer.user);
|
||||||
|
if (keepGoing) break;
|
||||||
|
players.delete(next);
|
||||||
|
removeFromArray(turn, next);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
round++;
|
round++;
|
||||||
userTurn = !userTurn;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.client.games.delete(msg.channel.id);
|
this.client.games.delete(msg.channel.id);
|
||||||
if (quit) return msg.say(`${winner} wins, because their opponent was a coward.`);
|
return msg.say(`The loser is ${loser.user}!`);
|
||||||
return msg.say(`The winner is ${winner}!`);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.client.games.delete(msg.channel.id);
|
this.client.games.delete(msg.channel.id);
|
||||||
throw err;
|
throw err;
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "138.4.0",
|
"version": "138.5.0",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
Reference in New Issue
Block a user