Add percentage modifiers to timetoheight
This commit is contained in:
parent
1f115252ca
commit
02201b2bfa
@ -649,31 +649,32 @@ const functions = {
|
|||||||
}
|
}
|
||||||
return `${waterParts.value} ${waterParts.units}`;
|
return `${waterParts.value} ${waterParts.units}`;
|
||||||
},
|
},
|
||||||
timeToHeight(beginHeight, destHeight) {
|
timeToHeight(beginHeight, destHeight, efficiency, quality) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let time = 0;
|
let time = 0;
|
||||||
for (let i = beginHeight; i < destHeight; i++) {
|
if ((efficiency) && (quality)) {
|
||||||
const waterTime = parseFloat(functions.getWaterTime(i));
|
for (let i = beginHeight; i < destHeight; i++) {
|
||||||
// console.log("Height: " + i + "Time: " + waterTime);
|
const randNum = Math.floor(Math.random() * 100);
|
||||||
time += waterTime;
|
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
|
resolve(this.parseWaterTime(time));
|
||||||
// 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);
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
sleep(ms) {
|
sleep(ms) {
|
||||||
|
@ -8,26 +8,53 @@ module.exports = {
|
|||||||
.setDescription('Calculate how long it would take to reach a given height')
|
.setDescription('Calculate how long it would take to reach a given height')
|
||||||
.addIntegerOption(o =>
|
.addIntegerOption(o =>
|
||||||
o.setName('endheight')
|
o.setName('endheight')
|
||||||
.setDescription('Ending tree height in feet')
|
.setDescription('Ending tree height in feet')
|
||||||
.setRequired(true))
|
.setRequired(true)
|
||||||
|
)
|
||||||
.addIntegerOption(o =>
|
.addIntegerOption(o =>
|
||||||
o.setName('beginheight')
|
o.setName('beginheight')
|
||||||
.setDescription('Beginning tree height in feet')
|
.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) {
|
async execute(interaction) {
|
||||||
await interaction.deferReply({ ephemeral: true });
|
await interaction.deferReply({ ephemeral: true });
|
||||||
let beginHeight = interaction.options.getInteger('beginheight');
|
const inBeginHeight = interaction.options.getInteger('beginheight');
|
||||||
const endHeight = interaction.options.getInteger('endheight');
|
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);
|
const guildInfo = interaction.client.guildInfos.get(interaction.guild.id);
|
||||||
beginHeight = guildInfo.treeHeight;
|
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.`);
|
const timeString = await fn.timeToHeight(beginHeight, endHeight, efficiency, quality);
|
||||||
}).catch(err => {
|
if (efficiency && quality) {
|
||||||
interaction.editReply("Error: " + err);
|
replyContent = `I estimate that a tree with ${efficiency}% Composter Efficiency and ${quality}% Compost Quality growing from ${beginHeight}ft to ${endHeight}ft will take ${timeString}`;
|
||||||
console.error(err);
|
} else {
|
||||||
return;
|
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