Improve balloon-pop

This commit is contained in:
Daniel Odendahl Jr
2018-08-27 16:48:53 +00:00
parent 9aa97d394e
commit 6cb05f68e4
2 changed files with 14 additions and 16 deletions
+13 -15
View File
@@ -12,8 +12,7 @@ module.exports = class BalloonPopCommand extends Command {
{ {
key: 'opponent', key: 'opponent',
prompt: 'What user would you like to play against?', prompt: 'What user would you like to play against?',
type: 'user', type: 'user'
default: () => this.client.user
} }
] ]
}); });
@@ -22,17 +21,16 @@ module.exports = class BalloonPopCommand extends Command {
} }
async run(msg, { opponent }) { async run(msg, { opponent }) {
if (opponent.bot) return msg.reply('Bots may not be played against.');
if (opponent.id === msg.author.id) return msg.reply('You may not play against yourself.'); if (opponent.id === msg.author.id) return msg.reply('You may not play against yourself.');
if (this.playing.has(msg.channel.id)) return msg.reply('Only one game may be occurring per channel.'); if (this.playing.has(msg.channel.id)) return msg.reply('Only one game may be occurring per channel.');
this.playing.add(msg.channel.id); this.playing.add(msg.channel.id);
try { try {
if (!opponent.bot) { await msg.say(`${opponent}, do you accept this challenge?`);
await msg.say(`${opponent}, do you accept this challenge?`); const verification = await verify(msg.channel, opponent);
const verification = await verify(msg.channel, opponent); if (!verification) {
if (!verification) { this.playing.delete(msg.channel.id);
this.playing.delete(msg.channel.id); return msg.say('Looks like they declined...');
return msg.say('Looks like they declined...');
}
} }
let userTurn = false; let userTurn = false;
let winner = null; let winner = null;
@@ -42,14 +40,14 @@ module.exports = class BalloonPopCommand extends Command {
const user = userTurn ? msg.author : opponent; const user = userTurn ? msg.author : opponent;
let pump; let pump;
++turns; ++turns;
if (!opponent.bot || (opponent.bot && userTurn)) { if (turns === 1) {
await msg.say(`${user}, do you pump the balloon?`); await msg.say(`${user} pumps the balloon!`);
pump = await verify(msg.channel, user); pump = true;
} else { } else {
pump = Boolean(Math.floor(Math.random() * 2)); await msg.say(`${user}, do you pump the balloon again?`);
pump = await verify(msg.channel, user);
} }
if (pump) { if (pump) {
await msg.say(`${user} pumps the balloon!`);
remains -= randomRange(25, 75); remains -= randomRange(25, 75);
const popped = Math.floor(Math.random() * remains); const popped = Math.floor(Math.random() * remains);
if (popped <= 0) { if (popped <= 0) {
@@ -58,11 +56,11 @@ module.exports = class BalloonPopCommand extends Command {
break; break;
} }
if (turns >= 3) { if (turns >= 3) {
await msg.say(`${user} steps back!`);
turns = 0; turns = 0;
userTurn = !userTurn; userTurn = !userTurn;
} }
} else { } else {
await msg.say(`${user} steps back!`);
turns = 0; turns = 0;
userTurn = !userTurn; userTurn = !userTurn;
} }
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiao", "name": "xiao",
"version": "87.4.1", "version": "87.4.2",
"description": "Your personal server companion.", "description": "Your personal server companion.",
"main": "Xiao.js", "main": "Xiao.js",
"scripts": { "scripts": {