Add percentage modifiers to timetoheight

This commit is contained in:
Skylar Grant 2023-02-26 12:09:24 -05:00
parent f4ecbf9ba3
commit 915ca4bf7c
2 changed files with 64 additions and 36 deletions

View File

@ -649,31 +649,32 @@ const functions = {
}
return `${waterParts.value} ${waterParts.units}`;
},
timeToHeight(beginHeight, destHeight) {
timeToHeight(beginHeight, destHeight, efficiency, quality) {
return new Promise((resolve, reject) => {
let time = 0;
if ((efficiency) && (quality)) {
for (let i = beginHeight; i < destHeight; i++) {
const randNum = Math.floor(Math.random() * 100);
const compostApplied = randNum <= efficiency;
if (compostApplied) {
let qualityPercent = quality / 100;
let waterTime = functions.getWaterTime(i);
let reductionTime = waterTime * qualityPercent;
let finalTime = waterTime - reductionTime;
time += parseFloat(finalTime);
} else {
time += parseFloat(functions.getWaterTime(i));
}
}
} else {
for (let i = beginHeight; i < destHeight; i++) {
const waterTime = parseFloat(functions.getWaterTime(i));
// console.log("Height: " + i + "Time: " + waterTime);
time += waterTime;
}
// 60 secs in min
// 3600 secs in hr
// 86400 sec in day
let units = " secs";
if (60 < time && time <= 3600) { // Minutes
time = parseFloat(time / 60).toFixed(1);
units = " mins";
} else if (3600 < time && time <= 86400) {
time = parseFloat(time / 3600).toFixed(1);
units = " hrs";
} else if (86400 < time) {
time = parseFloat(time / 86400).toFixed(1);
units = " days";
}
resolve(time + units);
resolve(this.parseWaterTime(time));
});
},
sleep(ms) {

View File

@ -9,25 +9,52 @@ module.exports = {
.addIntegerOption(o =>
o.setName('endheight')
.setDescription('Ending tree height in feet')
.setRequired(true))
.setRequired(true)
)
.addIntegerOption(o =>
o.setName('beginheight')
.setDescription('Beginning tree height in feet')
.setRequired(false)),
.setRequired(false)
)
.addIntegerOption(o =>
o.setName('efficiency')
.setDescription('Composter efficiency percentage, rounded')
.setRequired(false)
)
.addIntegerOption(o =>
o.setName('quality')
.setDescription('Compost quality percentage, rounded')
.setRequired(false)
),
async execute(interaction) {
await interaction.deferReply({ ephemeral: true });
let beginHeight = interaction.options.getInteger('beginheight');
const inBeginHeight = interaction.options.getInteger('beginheight');
const endHeight = interaction.options.getInteger('endheight');
if (!beginHeight) {
const efficiency = interaction.options.getInteger('efficiency');
const quality = interaction.options.getInteger('quality');
let beginHeight, replyContent;
if ((efficiency && !quality) || (quality && !efficiency)) {
const reply = fn.builders.embed("You must include **both** efficiency *and* quality, I only received one.");
await interaction.editReply(reply).catch(e => console.error(e));
return;
}
if (!inBeginHeight) {
const guildInfo = interaction.client.guildInfos.get(interaction.guild.id);
beginHeight = guildInfo.treeHeight;
} else {
beginHeight = inBeginHeight;
}
const timeString = await fn.timeToHeight(beginHeight, endHeight, efficiency, quality);
if (efficiency && quality) {
replyContent = `I estimate that a tree with ${efficiency}% Composter Efficiency and ${quality}% Compost Quality growing from ${beginHeight}ft to ${endHeight}ft will take ${timeString}`;
} else {
replyContent = `I estimate that a tree growing from ${beginHeight}ft to ${endHeight}ft will take ${timeString}`;
}
const reply = fn.builders.embed(replyContent)
await interaction.editReply(reply);
}
fn.timeToHeight(beginHeight, endHeight).then(res => {
interaction.editReply(`It will take a tree that is ${beginHeight}ft tall ${res} to reach ${endHeight}ft.`);
}).catch(err => {
interaction.editReply("Error: " + err);
console.error(err);
return;
});
},
};