randomRange util function

This commit is contained in:
Daniel Odendahl Jr
2017-10-30 18:13:00 +00:00
parent e6bbebb6ff
commit 4984318fc4
6 changed files with 22 additions and 15 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
const { Command } = require('discord.js-commando');
const { stripIndents } = require('common-tags');
const { verify } = require('../../util/Util');
const { randomRange, verify } = require('../../util/Util');
module.exports = class BattleCommand extends Command {
constructor(client) {
@@ -88,7 +88,7 @@ module.exports = class BattleCommand extends Command {
} else if (choice === 'special') {
const hit = Math.floor(Math.random() * 4) + 1;
if (hit === 1) {
const damage = Math.floor(Math.random() * ((guard ? 150 : 300) - 100 + 1)) + 100;
const damage = randomRange(100, guard ? 150 : 300);
await msg.say(`${user} deals **${damage}** damage!`);
dealDamage(damage);
} else {
+8 -6
View File
@@ -1,4 +1,5 @@
const { Command } = require('discord.js-commando');
const { randomRange } = require('../../util/Util');
const fishes = require('../../assets/json/fishy');
module.exports = class FishyCommand extends Command {
@@ -13,13 +14,14 @@ module.exports = class FishyCommand extends Command {
}
run(msg) {
const fish = Math.floor(Math.random() * 10) + 1;
const fishID = Math.floor(Math.random() * 10) + 1;
let rarity;
if (fish < 5) rarity = 'junk';
else if (fish < 8) rarity = 'common';
else if (fish < 10) rarity = 'uncommon';
if (fishID < 5) rarity = 'junk';
else if (fishID < 8) rarity = 'common';
else if (fishID < 10) rarity = 'uncommon';
else rarity = 'rare';
const worth = Math.floor(Math.random() * (fishes[rarity].max - fishes[rarity].min + 1)) + fishes[rarity].min;
return msg.say(`You caught a ${fishes[rarity].symbol}. I bet it'd sell for around $${worth}.`);
const fish = fishes[rarity];
const worth = randomRange(fish.min, fish.max);
return msg.say(`You caught a ${fish.symbol}. I bet it'd sell for around $${worth}.`);
}
};
+2 -3
View File
@@ -1,5 +1,5 @@
const { Command } = require('discord.js-commando');
const { wait, verify } = require('../../util/Util');
const { wait, randomRange, verify } = require('../../util/Util');
const words = ['fire', 'draw', 'shoot', 'bang', 'pull'];
module.exports = class GunfightCommand extends Command {
@@ -36,8 +36,7 @@ module.exports = class GunfightCommand extends Command {
return msg.say('Looks like they declined...');
}
await msg.say('Get Ready...');
const length = Math.floor(Math.random() * (30000 - 1000 + 1)) + 1000;
await wait(length);
await wait(randomRange(1000, 30000));
const word = words[Math.floor(Math.random() * words.length)];
await msg.say(`TYPE \`${word.toUpperCase()}\` NOW!`);
const filter = res => [opponent.id, msg.author.id].includes(res.author.id) && res.content.toLowerCase() === word;