Improvements to timetoheights calculations display
This commit is contained in:
parent
a44a83beeb
commit
5f37a3e5a3
@ -123,6 +123,16 @@ const functions = {
|
||||
.setDescription(description)
|
||||
.setFooter({ text: strings.embeds.roleMenuFooter });
|
||||
return { embeds: [embed], components: [actionRow] };
|
||||
},
|
||||
information(content, fields) {
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(strings.embeds.color)
|
||||
.setTitle('Information')
|
||||
.setDescription(content)
|
||||
.setFooter({ text: `v${package.version} - ${strings.embeds.footer}` });
|
||||
if (fields) embed.addFields(fields);
|
||||
const messageContents = { embeds: [embed], ephemeral: true };
|
||||
return messageContents;
|
||||
}
|
||||
},
|
||||
comparisonEmbed(content, guildInfo) {
|
||||
@ -652,6 +662,9 @@ const functions = {
|
||||
timeToHeight(beginHeight, destHeight, efficiency, quality) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let time = 0;
|
||||
let oldTime = 0;
|
||||
let compostAppliedCount = 0;
|
||||
let totalWaterCount = 0;
|
||||
if ((efficiency) && (quality)) {
|
||||
for (let i = beginHeight; i < destHeight; i++) {
|
||||
const randNum = Math.floor(Math.random() * 100);
|
||||
@ -661,9 +674,15 @@ const functions = {
|
||||
let waterTime = functions.getWaterTime(i);
|
||||
let reductionTime = waterTime * qualityPercent;
|
||||
let finalTime = waterTime - reductionTime;
|
||||
compostAppliedCount++;
|
||||
totalWaterCount++;
|
||||
time += parseFloat(finalTime);
|
||||
oldTime += waterTime;
|
||||
} else {
|
||||
time += parseFloat(functions.getWaterTime(i));
|
||||
totalWaterCount++;
|
||||
let waterTime = parseFloat(functions.getWaterTime(i));
|
||||
time += waterTime;
|
||||
oldTime += waterTime;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -673,8 +692,15 @@ const functions = {
|
||||
time += waterTime;
|
||||
}
|
||||
}
|
||||
|
||||
resolve(this.parseWaterTime(time));
|
||||
const readableWaterTime = this.parseWaterTime(time);
|
||||
const savedTime = this.parseWaterTime(oldTime - time);
|
||||
resolve({
|
||||
time: readableWaterTime,
|
||||
totalWaterCount: totalWaterCount ? totalWaterCount : undefined,
|
||||
compostAppliedCount: compostAppliedCount ? compostAppliedCount : undefined,
|
||||
average: totalWaterCount ? parseFloat((compostAppliedCount / totalWaterCount) * 100).toFixed(1) : undefined,
|
||||
savedTime: savedTime
|
||||
});
|
||||
});
|
||||
},
|
||||
sleep(ms) {
|
||||
|
@ -0,0 +1,21 @@
|
||||
information(content, fields) {
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(strings.embeds.color)
|
||||
.setTitle('Information')
|
||||
.setDescription(content)
|
||||
.setFooter({ text: `v${package.version} - ${strings.embeds.footer}` });
|
||||
if (fields) embed.addFields(fields);
|
||||
const messageContents = { embeds: [embed], ephemeral: true };
|
||||
return messageContents;
|
||||
}
|
||||
|
||||
replyContent = `I estimate that a tree with ${efficiency}% Composter Efficiency and ${quality}% Compost Quality growing from ${beginHeight}ft to ${endHeight}ft will take ${time}`;
|
||||
replyFields = [
|
||||
{ name: `Start Height:`, value: `**${beginHeight}ft**`, inline: true },
|
||||
{ name: `End Height:`, value: `**${endHeight}**`, inline: true },
|
||||
{ name: `Efficiency:`, value: `**${efficiency}%**`, inline: true },
|
||||
{ name: `Quality:`, value: `**${quality}%**`, inline: true },
|
||||
{ name: `Summary`, value: `Compost Applied **${compostAppliedCount}** times, out of **${totalWaterCount}** waterings, for an average of **${average}%**` }
|
||||
];
|
||||
|
||||
const reply = information(replyContent, replyFields);
|
@ -36,16 +36,10 @@ module.exports = {
|
||||
await interaction.deferReply({ ephemeral: private });
|
||||
const inBeginHeight = interaction.options.getInteger('beginheight');
|
||||
const endHeight = interaction.options.getInteger('endheight');
|
||||
const efficiency = interaction.options.getInteger('efficiency');
|
||||
const quality = interaction.options.getInteger('quality');
|
||||
const efficiency = interaction.options.getInteger('efficiency') != undefined ? interaction.options.getInteger('efficiency') : 10;
|
||||
const quality = interaction.options.getInteger('quality') != undefined ? interaction.options.getInteger('quality') : 5;
|
||||
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;
|
||||
@ -53,14 +47,23 @@ module.exports = {
|
||||
beginHeight = inBeginHeight;
|
||||
}
|
||||
|
||||
const timeString = await fn.timeToHeight(beginHeight, endHeight, efficiency, quality);
|
||||
const timeToHeightResults = await fn.timeToHeight(beginHeight, endHeight, efficiency, quality);
|
||||
const { time, totalWaterCount, compostAppliedCount, average, savedTime } = timeToHeightResults;
|
||||
let replyFields = undefined;
|
||||
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}`;
|
||||
replyContent = `I estimate that a tree with ${efficiency}% Composter Efficiency and ${quality}% Compost Quality growing from ${beginHeight}ft to ${endHeight}ft will take ${time}`;
|
||||
replyFields = [
|
||||
{ name: `Height Gained:`, value: `${endHeight - beginHeight}ft`, inline: true},
|
||||
{ name: `E/Q:`, value: `${efficiency}%/${quality}%`, inline: true},
|
||||
{ name: `Compost Applied`, value: `${compostAppliedCount} times`, inline: true },
|
||||
{ name: `Compost Average`, value: `${average}%`, inline: true },
|
||||
{ name: `Saved Time`, value: savedTime, inline: true }
|
||||
];
|
||||
} else {
|
||||
replyContent = `I estimate that a tree growing from ${beginHeight}ft to ${endHeight}ft will take ${timeString}`;
|
||||
replyContent = `I estimate that a tree growing from ${beginHeight}ft to ${endHeight}ft will take ${time}`;
|
||||
}
|
||||
|
||||
const reply = fn.builders.embed(replyContent)
|
||||
const reply = fn.builders.embeds.information(replyContent, replyFields)
|
||||
await interaction.editReply(reply);
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user