aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/mining/HotmConfig.java20
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/HotmData.kt33
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/mining/PowderPerHotmPerk.kt90
3 files changed, 131 insertions, 12 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/mining/HotmConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/mining/HotmConfig.java
index cbe7d0be0..3f6ef33db 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/mining/HotmConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/mining/HotmConfig.java
@@ -1,9 +1,12 @@
package at.hannibal2.skyhanni.config.features.mining;
import at.hannibal2.skyhanni.config.FeatureToggle;
+import at.hannibal2.skyhanni.features.mining.PowderPerHotmPerk.PowderSpentDesign;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
+import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDropdown;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;
+import org.jetbrains.annotations.NotNull;
public class HotmConfig {
@@ -24,4 +27,21 @@ public class HotmConfig {
@ConfigEditorBoolean
@FeatureToggle
public boolean tokenStackSize = true;
+
+ @Expose
+ @ConfigOption(name = "Powder Spent", desc = "Shows the amount of powder spent on a perk.")
+ @ConfigEditorBoolean
+ @FeatureToggle
+ public boolean powderSpent = true;
+
+ @Expose
+ @ConfigOption(name = "Powder Spent Design", desc = "Changes the design of the powder spent display.")
+ @ConfigEditorDropdown
+ public @NotNull PowderSpentDesign powderSpentDesign = PowderSpentDesign.NUMBER_AND_PERCENTAGE;
+
+ @Expose
+ @ConfigOption(name = "Powder for 10 Levels", desc = "Shows the amount of powder needed to level a perk 10 times when pressing shift.")
+ @ConfigEditorBoolean
+ @FeatureToggle
+ public boolean powderFor10Levels = true;
}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/HotmData.kt b/src/main/java/at/hannibal2/skyhanni/data/HotmData.kt
index 8c6db7df0..c299f5d52 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/HotmData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/HotmData.kt
@@ -37,7 +37,7 @@ import kotlin.math.floor
import kotlin.math.pow
enum class HotmData(
- guiName: String,
+ val guiName: String,
val maxLevel: Int,
val costFun: ((Int) -> (Double?)),
val rewardFun: ((Int) -> (Map<HotmReward, Double>)),
@@ -372,6 +372,10 @@ enum class HotmData(
fun getReward() = rewardFun(activeLevel)
+ fun calculateTotalCost(desiredLevel: Int) = (1 until desiredLevel).sumOf { level -> costFun(level) ?: 0.0 }.toInt()
+
+ val totalCostMaxLevel = calculateTotalCost(maxLevel)
+
// TODO move all object functions into hotm api?
@SkyHanniModule
companion object {
@@ -406,6 +410,11 @@ enum class HotmData(
) // unused for now since the assumption is when enabled isn't found it is disabled,
// but the value might be useful in the future or for debugging
+ val perkCostPattern by patternGroup.pattern(
+ "perk.cost",
+ "(?:§.)*§7Cost",
+ )
+
private val resetChatPattern by patternGroup.pattern(
"reset.chat",
"§aReset your §r§5Heart of the Mountain§r§a! Your Perks and Abilities have been reset.",
@@ -471,6 +480,8 @@ enum class HotmData(
}
}
+ fun getPerkByNameOrNull(name: String): HotmData? = entries.find { it.guiName == name }
+
private fun resetTree() = entries.forEach {
it.activeLevel = 0
it.enabled = false
@@ -574,17 +585,15 @@ enum class HotmData(
private fun handelSkyMall(lore: List<String>) {
if (!SKY_MALL.enabled || !SKY_MALL.isUnlocked) HotmAPI.skymall = null
else {
- val index = (
- lore.indexOfFirstMatch(skyMallCurrentEffect) ?: run {
- ErrorManager.logErrorStateWithData(
- "Could not read the skymall effect from the hotm tree",
- "skyMallCurrentEffect didn't match",
- "lore" to lore,
- )
- return
- }
- ) + 1
- skymallPattern.matchMatcher(lore[index]) {
+ val index = lore.indexOfFirstMatch(skyMallCurrentEffect) ?: run {
+ ErrorManager.logErrorStateWithData(
+ "Could not read the skymall effect from the hotm tree",
+ "skyMallCurrentEffect didn't match",
+ "lore" to lore,
+ )
+ return
+ }
+ skymallPattern.matchMatcher(lore[index + 1]) {
val perk = group("perk")
HotmAPI.skymall = SkymallPerk.entries.firstOrNull { it.itemPattern.matches(perk) } ?: run {
ErrorManager.logErrorStateWithData(
diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/PowderPerHotmPerk.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/PowderPerHotmPerk.kt
new file mode 100644
index 000000000..4acf5f3ad
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/mining/PowderPerHotmPerk.kt
@@ -0,0 +1,90 @@
+package at.hannibal2.skyhanni.features.mining
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.data.HotmData
+import at.hannibal2.skyhanni.events.LorenzToolTipEvent
+import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
+import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.LorenzUtils.round
+import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
+import at.hannibal2.skyhanni.utils.NumberUtil.fractionOf
+import at.hannibal2.skyhanni.utils.RegexUtils.matches
+import at.hannibal2.skyhanni.utils.StringUtils.removeColor
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import org.lwjgl.input.Keyboard
+
+@SkyHanniModule
+object PowderPerHotmPerk {
+
+ private val config get() = SkyHanniMod.feature.mining.hotm
+
+ @SubscribeEvent
+ fun onTooltip(event: LorenzToolTipEvent) {
+ if (!isEnabled()) return
+
+ val itemName = event.itemStack.displayName
+ val perk = HotmData.getPerkByNameOrNull(itemName.removeColor()) ?: return
+
+ if (perk.getLevelUpCost() == null) return
+
+ if (config.powderSpent) event.toolTip.add(2, handlePowderSpend(perk))
+ if (config.powderFor10Levels) handlePowderFor10Levels(event, perk)
+ }
+
+ private fun handlePowderFor10Levels(event: LorenzToolTipEvent, perk: HotmData) {
+ if (!Keyboard.KEY_LSHIFT.isKeyHeld()) return
+
+ val indexOfCost = event.toolTip.indexOfFirst { HotmData.perkCostPattern.matches(it) }
+
+ if (indexOfCost == -1) return
+
+ val powderFor10Levels =
+ perk.calculateTotalCost(perk.activeLevel + 10) - perk.calculateTotalCost(perk.activeLevel)
+
+ event.toolTip.add(indexOfCost + 2, "§7Powder for 10 levels: §e${powderFor10Levels.addSeparators()}")
+ }
+
+ private fun handlePowderSpend(perk: HotmData): String {
+ val currentPowderSpend = perk.calculateTotalCost(perk.activeLevel)
+ val maxPowderNeeded = perk.totalCostMaxLevel
+ val percentage = (currentPowderSpend.fractionOf(maxPowderNeeded) * 100).round(2)
+
+ return when (config.powderSpentDesign) {
+ PowderSpentDesign.NUMBER -> {
+ if (perk.activeLevel == perk.maxLevel) {
+ "§7Powder spent: §e${maxPowderNeeded.addSeparators()} §7(§aMax level§7)"
+ } else {
+ "§7Powder spent: §e${currentPowderSpend.addSeparators()}§7 / §e${maxPowderNeeded.addSeparators()}"
+ }
+ }
+
+ PowderSpentDesign.PERCENTAGE -> {
+ if (perk.activeLevel == perk.maxLevel) {
+ "§7Powder spent: §e$percentage% §7(§aMax level§7)"
+ } else {
+ "§7Powder spent: §e$percentage%§7 of max"
+ }
+ }
+
+ PowderSpentDesign.NUMBER_AND_PERCENTAGE -> {
+ if (perk.activeLevel == perk.maxLevel) {
+ "§7Powder spent: §e${maxPowderNeeded.addSeparators()} §7(§aMax level§7)"
+ } else {
+ "§7Powder spent: §e${currentPowderSpend.addSeparators()}§7/§e${maxPowderNeeded.addSeparators()}§7 (§e$percentage%§7)"
+ }
+ }
+ }
+ }
+
+ enum class PowderSpentDesign(val str: String) {
+ NUMBER("Number"),
+ PERCENTAGE("Percentage"),
+ NUMBER_AND_PERCENTAGE("Number and Percentage");
+
+ override fun toString() = str
+ }
+
+ private fun isEnabled() = LorenzUtils.inSkyBlock && HotmData.inInventory &&
+ (config.powderSpent || config.powderFor10Levels)
+}