diff options
Diffstat (limited to 'commands/calculate')
-rw-r--r-- | commands/calculate/calcSpeed.js | 47 | ||||
-rw-r--r-- | commands/calculate/calculate.js | 36 | ||||
-rw-r--r-- | commands/calculate/hotmCalc.js | 66 | ||||
-rw-r--r-- | commands/calculate/tick.js | 93 |
4 files changed, 242 insertions, 0 deletions
diff --git a/commands/calculate/calcSpeed.js b/commands/calculate/calcSpeed.js new file mode 100644 index 0000000..1b2eae6 --- /dev/null +++ b/commands/calculate/calcSpeed.js @@ -0,0 +1,47 @@ +import constants from "../../util/constants" +import { parseNotatedInput } from "../../util/helperFunctions" +const PREFIX = constants.PREFIX + + +export function calcSpeed(powder) +{ + let speedLevels = 1, + professionalLevels = 1 + + if(powder == undefined || parseNotatedInput(powder) == "NI") return ChatLib.chat(constants.CALCULATEERRORMESSAGE) + powder = parseNotatedInput(powder) + + while(powder > msPowder(speedLevels) + profPowder(professionalLevels)) + { + if(ms2SpeedPerPowder(speedLevels + 1) > professionalSpeedPerPowder(professionalLevels + 1) && speedLevels < 50) + { + powder -= msPowder(speedLevels++) + } + else if (professionalLevels < 140) + { + powder -= profPowder(professionalLevels++) + } + else break + } + return ChatLib.chat(`&bGet &6&l${speedLevels} &bmining speed levels and &6&l${professionalLevels} &bprofessional levels.`) +} + +function ms2SpeedPerPowder(miningSpeedLevel) // 40 speed per level +{ + return 40/msPowder(miningSpeedLevel) +} + +function professionalSpeedPerPowder(professionalLevel) // 5 speed per level +{ + return 5/profPowder(professionalLevel) +} + +function msPowder(miningSpeedLevel) +{ + return Math.floor(Math.pow(miningSpeedLevel+1, 3.2)) +} + +function profPowder(professionalLevel) +{ + return Math.floor(Math.pow(professionalLevel+1, 2.3)) +}
\ No newline at end of file diff --git a/commands/calculate/calculate.js b/commands/calculate/calculate.js new file mode 100644 index 0000000..3d9d750 --- /dev/null +++ b/commands/calculate/calculate.js @@ -0,0 +1,36 @@ +import constants from "../../util/constants" +import { hotmCalc } from "./hotmCalc" +import { calcSpeed } from "./calcSpeed" +import { tickCommand } from "./tick" +import { helpCommand } from "../help" +const PREFIX = constants.PREFIX + + +export function calculate(args) +{ + switch(args[0].toLowerCase()) + { + case "hotm": + case "hotmcalc": + case "calchotm": + hotmCalc(args[1], args[2], args[3]) + break + case "tick": + tickCommand(args[1], args[2]) + break + case "calcspeed": + case "speed": + calcSpeed(args[1]) + break + case "help": + ChatLib.chat("&b--------------[ &a&l/cw calculate &b]--------------") + helpCommand("calculate tick", "Calculates tick data.", "(mining speed) (('r','jade', etc) || breaking power of block))") + helpCommand("calculate speed", "Calculates the ratio of mining speed 2 to professional with a certain amount of powder.", "(powder)") + helpCommand("calculate hotm", "Calculates powder between two levels of a certain perk.", "(perk) (minlevel) [maxlevel]") + ChatLib.chat("&b------------------------------------------") + return + default: + return ChatLib.chat(constants.CALCULATEERRORMESSAGE) + } +} + diff --git a/commands/calculate/hotmCalc.js b/commands/calculate/hotmCalc.js new file mode 100644 index 0000000..583b2b8 --- /dev/null +++ b/commands/calculate/hotmCalc.js @@ -0,0 +1,66 @@ +import constants from "../../util/constants" +import { addCommas } from "../../util/helperFunctions" +const PREFIX = constants.PREFIX + + +export function hotmCalc(hotmName, minLevel, maxLevel) +{ + if(hotmName == undefined) + { + let hotmData = JSON.parse(FileLib.read("Coleweight", "data/hotm.json")).data + + ChatLib.chat(`/cw calc hotm (hotmName listed below) (minLevel) [maxLevel]`) + for(let i = 0; i < hotmData.length; i++) + { + ChatLib.chat(hotmData[i].names[0]) + } + return + } + if(maxLevel == undefined) + { + maxLevel = minLevel + minLevel = 1 + } + + if(minLevel != parseInt(minLevel) || maxLevel != parseInt(maxLevel)) return ChatLib.chat(constants.CALCULATEERRORMESSAGE) + + minLevel = parseInt(minLevel) + maxLevel = parseInt(maxLevel) + let hotmObjectToFind = findHotmObject(hotmName) + if(hotmObjectToFind == undefined) return ChatLib.chat(`${PREFIX}&cDid not find HOTM perk with name '${hotmName}'!`) + + maxLevel = (maxLevel < hotmObjectToFind.maxLevel ? maxLevel : hotmObjectToFind.maxLevel) + + let powderSum = findCost(hotmObjectToFind.costFormula, minLevel, maxLevel), + reward = findReward(hotmObjectToFind.rewardFormula, minLevel, maxLevel) + + ChatLib.chat("") + ChatLib.chat(`&6${hotmObjectToFind.nameStringed} ${minLevel} - ${maxLevel} &bwill cost &6&l${addCommas(Math.round(powderSum))} &6${hotmObjectToFind.powderType[0].toUpperCase() + hotmObjectToFind.powderType.slice(1)} &bpowder.`) + ChatLib.chat(`&6${hotmObjectToFind.nameStringed} ${minLevel} - ${maxLevel} &bwill give &6&l${addCommas(Math.round(reward * 100) / 100)} &bof whatever reward is listed.`) + ChatLib.chat("") +} + +export function findHotmObject(hotmName) +{ + let hotmData = JSON.parse(FileLib.read("Coleweight", "data/hotm.json")).data + + for(let i = 0; i < hotmData.length; i++) + { + if(hotmData[i].names.includes(hotmName)) + return hotmData[i] + } +} + +export function findCost(costFormula, minLevel, maxLevel) +{ + let powderSum = 0 + + for(let currentLevel = minLevel; currentLevel < maxLevel; currentLevel++) // finds cost + powderSum += eval(costFormula.replace("currentLevel", currentLevel)) + return powderSum +} + +export function findReward(rewardFormula, minLevel, maxLevel) +{ + return eval(rewardFormula.replace("Level", 1+maxLevel-minLevel)) +}
\ No newline at end of file diff --git a/commands/calculate/tick.js b/commands/calculate/tick.js new file mode 100644 index 0000000..f8b2433 --- /dev/null +++ b/commands/calculate/tick.js @@ -0,0 +1,93 @@ +import constants from "../../util/constants" +const PREFIX = constants.PREFIX + +export function tickCommand(speed, block) +{ + if(speed == undefined || parseInt(speed) != speed) + return ChatLib.chat(`${PREFIX}&cMining speed must be an integer!`) + if(block == undefined) + return ChatLib.chat(constants.CALCULATEERRORMESSAGE) + const ticks = findTick(speed, block) + if(ticks.err) return ChatLib.chat(`${PREFIX}&cBlock must be a gemstone or positive breaking power! (or starting letter of gemstone)`) + + + ChatLib.chat(`\n&bCurrently mining blocks in &6&l${Math.round(ticks.currentBlockTick)} ticks` + + `\n&bCurrently mining shards in &6&l${Math.round(ticks.currentShardTick)} ticks` + + `\n&bNext block tick will be at: &6&l${Math.round(ticks.nextBlockSpeed)} mining speed` + + `\n&bNext shard tick will be at: &6&l${Math.round(ticks.nextShardSpeed)} mining speed` + + `\n&bYou need &6&l${Math.round(ticks.nextBlockSpeed - speed)} mining speed&b to get the next block tick.` + + `\n&bYou need &6&l${Math.round(ticks.nextShardSpeed - speed)} mining speed&b to get the next shard tick.\n`) +} + + +export function findTick(speed, block) +{ + let ticks = {err: false}, + strength = findStrength(block) + + ticks.currentBlockTick = strength*30/speed + ticks.currentShardTick = (strength-200)*30/speed + + if(strength < 1) return ticks.err = true + + + if(ticks.currentBlockTick < Math.floor(ticks.currentBlockTick) + 0.5) + ticks.nextBlockSpeed = strength*30/(Math.floor(ticks.currentBlockTick)-0.5) + else + ticks.nextBlockSpeed = strength*30/(Math.floor(ticks.currentBlockTick)+0.5) + + if(ticks.currentShardTick < Math.floor(ticks.currentShardTick) + 0.5) + ticks.nextShardSpeed = strength*30/(Math.floor(ticks.currentShardTick)-0.5) + else + ticks.nextShardSpeed = strength*30/(Math.floor(ticks.currentShardTick)+0.5) + + return ticks +} + +function findStrength(block) +{ + let strength = -1 + + if(block == parseInt(block) && block > 5) // change if add block to tick speed blocks in settings + strength = block + else + { + switch(block.toString().toLowerCase()) + { + case "0": + case "green_mithril": + strength = 800 + break + case "1": + case "blue_mithril": + strength = 1500 + break + case "2": + case "ruby": + case "r": + strength = 2500 + break + case "3": + case "j": + case "jade": + case "a": + case "amber": + case "amethyst": + case "s": + case "sapphire": + strength = 3200 + break + case "4": + case "t": + case "topaz": + case "o": + case "opal": + strength = 4000 + case "5": + case "jasper": + strength = 5000 + } + } + + return strength +} |