initial
This commit is contained in:
43
commands/howlucky.js
Normal file
43
commands/howlucky.js
Normal file
@ -0,0 +1,43 @@
|
||||
const { SlashCommandBuilder, SlashCommandNumberOption } = require("discord.js");
|
||||
|
||||
let tries = (module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("howlucky")
|
||||
.setDescription("How lucky are you?")
|
||||
.addNumberOption(
|
||||
new SlashCommandNumberOption()
|
||||
.setName("tries")
|
||||
.setDescription("how many tries you have")
|
||||
.setRequired(true)
|
||||
.setMinValue(1)
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName("probability")
|
||||
.setDescription("you can guess")
|
||||
.setRequired(true)
|
||||
),
|
||||
async execute(interaction) {
|
||||
let probabilitylowernum;
|
||||
if (interaction.options.getString("probability").split("/")[1] == null) {
|
||||
probabilitylowernum = parseInt(
|
||||
interaction.options.getString("probability")
|
||||
);
|
||||
} else {
|
||||
probabilitylowernum = parseInt(
|
||||
interaction.options.getString("probability").split("/")[1]
|
||||
);
|
||||
}
|
||||
let result =
|
||||
(interaction.options.getNumber("tries") / probabilitylowernum) * 100;
|
||||
await interaction.reply(
|
||||
`With a drop chance of ${interaction.options.getString(
|
||||
"probability"
|
||||
)}, getting a drop within ${interaction.options.getNumber(
|
||||
"tries"
|
||||
)} tries has a **${
|
||||
Math.round(result * 100) / 100
|
||||
}%** chance of happening.`
|
||||
);
|
||||
},
|
||||
});
|
65
commands/howmanyruns.js
Normal file
65
commands/howmanyruns.js
Normal file
@ -0,0 +1,65 @@
|
||||
const { SlashCommandBuilder, SlashCommandNumberOption } = require("discord.js");
|
||||
|
||||
function calculate(desiredPercent, probability, itemsPerRun, minutesPerRun) {
|
||||
let result = [];
|
||||
//const numberOfRuns = Math.round(
|
||||
// Math.log(1 - desiredPercent) / Math.log(1 - probability)
|
||||
//);
|
||||
const numberOfItems = Math.log(1 - desiredPercent) / Math.log(1 - probability);
|
||||
const numberOfRuns = numberOfItems / itemsPerRun;
|
||||
const hoursToGetPercent = (numberOfRuns * minutesPerRun) / 60;
|
||||
result.push(`${Math.round(desiredPercent * 100)}%`.padEnd(7, " ")); // prob
|
||||
result.push(`${Math.ceil(numberOfItems)}`.padEnd(7, " ")); // items
|
||||
result.push(`${Math.ceil(numberOfRuns)}`.padEnd(7, " ")); // runs
|
||||
result.push(`${Math.round(hoursToGetPercent)}`.padEnd(7, " ")); // hours
|
||||
return result.join("\t") + "\n";
|
||||
}
|
||||
|
||||
let tries = (module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("howmanyruns")
|
||||
.setDescription("How lucky are you?")
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName("probability")
|
||||
.setDescription("you can guess")
|
||||
.setRequired(true)
|
||||
)
|
||||
.addNumberOption(
|
||||
new SlashCommandNumberOption()
|
||||
.setName("items-per-run")
|
||||
.setDescription("how many items every run")
|
||||
.setRequired(true)
|
||||
.setMinValue(1)
|
||||
)
|
||||
.addNumberOption((option) =>
|
||||
option
|
||||
.setName("minutes-per-run")
|
||||
.setDescription("how long each run takes")
|
||||
.setRequired(true)
|
||||
.setMinValue(1)
|
||||
),
|
||||
async execute(interaction) {
|
||||
let strprobability;
|
||||
if (interaction.options.getString("probability").split("/")[1] == null) {
|
||||
strprobability = parseInt(interaction.options.getString("probability"));
|
||||
} else {
|
||||
strprobability = parseInt(
|
||||
interaction.options.getString("probability").split("/")[1]
|
||||
);
|
||||
}
|
||||
const items = interaction.options.getNumber("items-per-run");
|
||||
const probability = 1 / strprobability;
|
||||
const minutes = interaction.options.getNumber("minutes-per-run");
|
||||
let result = "";
|
||||
result += calculate(0.1, probability, items, minutes);
|
||||
result += calculate(0.25, probability, items, minutes);
|
||||
result += calculate(0.5, probability, items, minutes);
|
||||
result += calculate(0.75, probability, items, minutes);
|
||||
result += calculate(0.9, probability, items, minutes);
|
||||
result += calculate(0.95, probability, items, minutes);
|
||||
await interaction.reply(
|
||||
`Assuming you get ${items} item(s) per run.\nYou spend ${minutes} minute(s) per run and probability is 1/${strprobability}.\n\`\`\`${"Prob".padEnd(7, " ")}\t${"Items".padEnd(7, " ")}\t${"Runs".padEnd(7, " ")}\tHours\n${result}\`\`\``
|
||||
);
|
||||
},
|
||||
});
|
Reference in New Issue
Block a user