Add percentage modifiers to timetoheight
This commit is contained in:
parent
f4ecbf9ba3
commit
915ca4bf7c
@ -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;
|
||||
for (let i = beginHeight; i < destHeight; i++) {
|
||||
const waterTime = parseFloat(functions.getWaterTime(i));
|
||||
// console.log("Height: " + i + "Time: " + waterTime);
|
||||
time += waterTime;
|
||||
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) {
|
||||
|
@ -8,26 +8,53 @@ module.exports = {
|
||||
.setDescription('Calculate how long it would take to reach a given height')
|
||||
.addIntegerOption(o =>
|
||||
o.setName('endheight')
|
||||
.setDescription('Ending tree height in feet')
|
||||
.setRequired(true))
|
||||
.setDescription('Ending tree height in feet')
|
||||
.setRequired(true)
|
||||
)
|
||||
.addIntegerOption(o =>
|
||||
o.setName('beginheight')
|
||||
.setDescription('Beginning tree height in feet')
|
||||
.setRequired(false)),
|
||||
.setDescription('Beginning tree height in feet')
|
||||
.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;
|
||||
}
|
||||
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;
|
||||
});
|
||||
},
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user