diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-04-13 22:05:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-13 22:05:36 +0200 |
commit | 6c02dfed05d21d80a90624c432f372cba7f35767 (patch) | |
tree | d2d657ae17d303a9ab3864e51906928d74745da5 /src/main/java | |
parent | 714a722e748cb082af808c3168e7e7ab0c594adb (diff) | |
download | skyhanni-6c02dfed05d21d80a90624c432f372cba7f35767.tar.gz skyhanni-6c02dfed05d21d80a90624c432f372cba7f35767.tar.bz2 skyhanni-6c02dfed05d21d80a90624c432f372cba7f35767.zip |
New Feature: Excavation Profit Tracker (#1432)
Co-authored-by: Empa <42304516+ItsEmpa@users.noreply.github.com>
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java')
18 files changed, 449 insertions, 71 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 170dfb524..248d5fb50 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -271,7 +271,9 @@ import at.hannibal2.skyhanni.features.mining.crystalhollows.CrystalHollowsNamesI import at.hannibal2.skyhanni.features.mining.crystalhollows.CrystalHollowsWalls import at.hannibal2.skyhanni.features.mining.eventtracker.MiningEventDisplay import at.hannibal2.skyhanni.features.mining.eventtracker.MiningEventTracker -import at.hannibal2.skyhanni.features.mining.fossilexcavator.FossilExcavator +import at.hannibal2.skyhanni.features.mining.fossilexcavator.ExcavatorProfitTracker +import at.hannibal2.skyhanni.features.mining.fossilexcavator.FossilExcavatorAPI +import at.hannibal2.skyhanni.features.mining.fossilexcavator.solver.FossilSolverDisplay import at.hannibal2.skyhanni.features.mining.powdertracker.PowderTracker import at.hannibal2.skyhanni.features.minion.InfernoMinionFeatures import at.hannibal2.skyhanni.features.minion.MinionCollectLogic @@ -539,6 +541,7 @@ class SkyHanniMod { loadModule(LorenzUtils) loadModule(NEUItems) loadModule(PestAPI) + loadModule(FossilExcavatorAPI) // features loadModule(BazaarOrderHelper()) @@ -663,7 +666,8 @@ class SkyHanniMod { loadModule(GardenCropMilestoneDisplay) loadModule(GardenCustomKeybinds) loadModule(ChickenHeadTimer()) - loadModule(FossilExcavator) + loadModule(FossilSolverDisplay) + loadModule(ExcavatorProfitTracker()) loadModule(GardenOptimalSpeed()) loadModule(GardenLevelDisplay()) loadModule(FarmingWeightDisplay()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt index 7907c0f37..75569686c 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt @@ -11,7 +11,7 @@ import com.google.gson.JsonPrimitive object ConfigUpdaterMigrator { val logger = LorenzLogger("ConfigMigration") - const val CONFIG_VERSION = 35 + const val CONFIG_VERSION = 36 fun JsonElement.at(chain: List<String>, init: Boolean): JsonElement? { if (chain.isEmpty()) return this if (this !is JsonObject) return null diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/mining/ExcavatorProfitTrackerConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/mining/ExcavatorProfitTrackerConfig.java new file mode 100644 index 000000000..6a3886411 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/mining/ExcavatorProfitTrackerConfig.java @@ -0,0 +1,40 @@ +package at.hannibal2.skyhanni.config.features.mining; + +import at.hannibal2.skyhanni.config.FeatureToggle; +import at.hannibal2.skyhanni.config.core.config.Position; +import com.google.gson.annotations.Expose; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigLink; +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; + +public class ExcavatorProfitTrackerConfig { + + @Expose + @ConfigOption( + name = "Enabled", + desc = "Count all drops you gain while excavating in the Fossil Research Center." + ) + @ConfigEditorBoolean + @FeatureToggle + public boolean enabled = true; + + @Expose + @ConfigOption( + name = "Track Glacite Powder", + desc = "Track Glacite Powder gained as well (no profit, but progress)." + ) + @ConfigEditorBoolean + public boolean trackGlacitePowder = true; + + @Expose + @ConfigOption( + name = "Track Fossil Dust", + desc = "Track Fossil Dust and use it for profit calculation." + ) + @ConfigEditorBoolean + public boolean showFossilDust = true; + + @Expose + @ConfigLink(owner = ExcavatorProfitTrackerConfig.class, field = "enabled") + public Position position = new Position(-380, 150, false, true); +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/mining/FossilExcavatorConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/mining/FossilExcavatorConfig.java index d9a3ac7ba..f1b70c6b3 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/mining/FossilExcavatorConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/mining/FossilExcavatorConfig.java @@ -1,29 +1,19 @@ package at.hannibal2.skyhanni.config.features.mining; -import at.hannibal2.skyhanni.config.FeatureToggle; -import at.hannibal2.skyhanni.config.core.config.Position; import com.google.gson.annotations.Expose; -import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; -import io.github.notenoughupdates.moulconfig.annotations.ConfigLink; +import io.github.notenoughupdates.moulconfig.annotations.Accordion; import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; public class FossilExcavatorConfig { @Expose - @ConfigOption(name = "Fossil Excavator Helper", desc = "Helps you find fossils in the fossil excavator. " + - "§eWill always solve if you have at least 18 clicks. Solves everything except Spine, Ugly and Helix in 16 clicks.") - @ConfigEditorBoolean - @FeatureToggle - public boolean enabled = true; + @ConfigOption(name = "Fossil Excavator Solver", desc = "") + @Accordion + public FossilExcavatorSolverConfig solver = new FossilExcavatorSolverConfig(); @Expose - @ConfigOption(name = "Show Percentage", desc = "Shows percentage chance that next click will be a fossil. " + - "§eThis assumes there is a fossil hidden in the dirt.") - @ConfigEditorBoolean - public boolean showPercentage = true; - - @Expose - @ConfigLink(owner = FossilExcavatorConfig.class, field = "enabled") - public Position position = new Position(183, 212, false, true); + @ConfigOption(name = "Excavator Profit Tracker", desc = "") + @Accordion + public ExcavatorProfitTrackerConfig profitTracker = new ExcavatorProfitTrackerConfig(); } diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/mining/FossilExcavatorSolverConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/mining/FossilExcavatorSolverConfig.java new file mode 100644 index 000000000..6b881f7d7 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/mining/FossilExcavatorSolverConfig.java @@ -0,0 +1,28 @@ +package at.hannibal2.skyhanni.config.features.mining; + +import at.hannibal2.skyhanni.config.FeatureToggle; +import at.hannibal2.skyhanni.config.core.config.Position; +import com.google.gson.annotations.Expose; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigLink; +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; + +public class FossilExcavatorSolverConfig { + + @Expose + @ConfigOption(name = "Fossil Excavator Helper", desc = "Helps you find fossils in the fossil excavator. " + + "§eWill always solve if you have at least 18 clicks. Solves everything except Spine, Ugly and Helix in 16 clicks.") + @ConfigEditorBoolean + @FeatureToggle + public boolean enabled = true; + + @Expose + @ConfigOption(name = "Show Percentage", desc = "Shows percentage chance that next click will be a fossil. " + + "§eThis assumes there is a fossil hidden in the dirt.") + @ConfigEditorBoolean + public boolean showPercentage = true; + + @Expose + @ConfigLink(owner = FossilExcavatorSolverConfig.class, field = "enabled") + public Position position = new Position(183, 212, false, true); +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java index 7e40825fe..0ec04b195 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java @@ -20,9 +20,10 @@ import at.hannibal2.skyhanni.features.garden.farming.ArmorDropTracker; import at.hannibal2.skyhanni.features.garden.farming.DicerRngDropTracker; import at.hannibal2.skyhanni.features.garden.farming.lane.FarmingLane; import at.hannibal2.skyhanni.features.garden.fortuneguide.FarmingItems; -import at.hannibal2.skyhanni.features.garden.pests.VinylType; import at.hannibal2.skyhanni.features.garden.pests.PestProfitTracker; +import at.hannibal2.skyhanni.features.garden.pests.VinylType; import at.hannibal2.skyhanni.features.garden.visitor.VisitorReward; +import at.hannibal2.skyhanni.features.mining.fossilexcavator.ExcavatorProfitTracker; import at.hannibal2.skyhanni.features.mining.powdertracker.PowderTracker; import at.hannibal2.skyhanni.features.misc.trevor.TrevorTracker; import at.hannibal2.skyhanni.features.rift.area.westvillage.VerminTracker; @@ -384,6 +385,9 @@ public class ProfileSpecificStorage { @Expose public List<String> kingsTalkedTo = new ArrayList<>(); + + @Expose + public ExcavatorProfitTracker.Data fossilExcavatorProfitTracker = new ExcavatorProfitTracker.Data(); } @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/events/mining/FossilExcavationEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/mining/FossilExcavationEvent.kt new file mode 100644 index 000000000..b672def95 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/mining/FossilExcavationEvent.kt @@ -0,0 +1,5 @@ +package at.hannibal2.skyhanni.events.mining + +import at.hannibal2.skyhanni.events.LorenzEvent + +class FossilExcavationEvent(val loot: List<Pair<String, Int>>): LorenzEvent() diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ExcavatorProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ExcavatorProfitTracker.kt new file mode 100644 index 000000000..b2bc4a910 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ExcavatorProfitTracker.kt @@ -0,0 +1,212 @@ +package at.hannibal2.skyhanni.features.mining.fossilexcavator + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.IslandChangeEvent +import at.hannibal2.skyhanni.events.mining.FossilExcavationEvent +import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList +import at.hannibal2.skyhanni.utils.ItemUtils.itemName +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland +import at.hannibal2.skyhanni.utils.NEUInternalName +import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName +import at.hannibal2.skyhanni.utils.NEUItems.getPrice +import at.hannibal2.skyhanni.utils.NumberUtil +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.StringUtils +import at.hannibal2.skyhanni.utils.renderables.Renderable +import at.hannibal2.skyhanni.utils.tracker.ItemTrackerData +import at.hannibal2.skyhanni.utils.tracker.SkyHanniItemTracker +import com.google.gson.annotations.Expose +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.inventory.GuiChest +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class ExcavatorProfitTracker { + + private val config get() = SkyHanniMod.feature.mining.fossilExcavator.profitTracker + + private val tracker = SkyHanniItemTracker( + "Fossil Excavation Profit Tracker", + { Data() }, + { it.mining.fossilExcavatorProfitTracker }) { drawDisplay(it) } + + class Data : ItemTrackerData() { + override fun resetItems() { + timesExcavated = 0 + glacitePowderGained = 0 + fossilDustGained = 0 + } + + override fun getDescription(timesGained: Long): List<String> { + val percentage = timesGained.toDouble() / timesExcavated + val dropRate = LorenzUtils.formatPercentage(percentage.coerceAtMost(1.0)) + return listOf( + "§7Dropped §e${timesGained.addSeparators()} §7times.", + "§7Your drop rate: §c$dropRate." + ) + } + + override fun getCoinName(item: TrackedItem) = "<no coins>" + + override fun getCoinDescription(item: TrackedItem): List<String> { + return listOf( + "<no coins>" + ) + } + + @Expose + var timesExcavated = 0L + var glacitePowderGained = 0L + var fossilDustGained = 0L + } + + private val scrapItem = "SUSPICIOUS_SCRAP".asInternalName() + + private fun drawDisplay(data: Data): List<List<Any>> = buildList { + addAsSingletonList("§e§lFossil Excavation Profit Tracker") + var profit = tracker.drawItems(data, { true }, this) + + val timesExcavated = data.timesExcavated + addAsSingletonList( + Renderable.hoverTips( + "§7Times excavated: §e${timesExcavated.addSeparators()}", + listOf("§7You excavated §e${timesExcavated.addSeparators()} §7times.") + ) + ) + + profit = addScrap(timesExcavated, profit) + if (config.showFossilDust) { + profit = addFossilDust(data.fossilDustGained, profit) + } + if (config.trackGlacitePowder) { + addGlacitePowder(data) + } + + addAsSingletonList(tracker.addTotalProfit(profit, data.timesExcavated, "excavation")) + + tracker.addPriceFromButton(this) + } + + private fun MutableList<List<Any>>.addFossilDust( + fossilDustGained: Long, + profit: Double, + ): Double { + if (fossilDustGained <= 0) return profit + // TODO use same price source as profit tracker + val pricePer = scrapItem.getPrice() / 500 + val fossilDustPrice = pricePer * fossilDustGained + addAsSingletonList( + Renderable.hoverTips( + "§7${NumberUtil.format(fossilDustGained)}x §fFossil Dust§7: §6${NumberUtil.format(fossilDustPrice)}", + listOf( + "§7You gained §6${NumberUtil.format(fossilDustPrice)} coins §7in total", + "§7for all §e$fossilDustGained §fFossil Dust", + "§7you have collected.", + "", + "§7Price Per Fossil Dust: §6${NumberUtil.format(pricePer)}" + ) + ) + ) + return profit + fossilDustPrice + } + + private fun MutableList<List<Any>>.addGlacitePowder(data: Data) { + val glacitePowderGained = data.glacitePowderGained + if (glacitePowderGained <= 0) return + addAsSingletonList( + Renderable.hoverTips( + "§bGlacite Powder§7: §e${glacitePowderGained.addSeparators()}", + listOf( + "§7No real profit,", + "§7but still nice to see! Right?", + ) + ) + ) + } + + private fun MutableList<List<Any>>.addScrap( + timesExcavated: Long, + profit: Double, + ): Double { + if (timesExcavated <= 0) return profit + // TODO use same price source as profit tracker + val scrapPrice = timesExcavated * scrapItem.getPrice() + val name = StringUtils.pluralize(timesExcavated.toInt(), scrapItem.itemName) + addAsSingletonList( + Renderable.hoverTips( + "${scrapItem.itemName} §7price: §c-${NumberUtil.format(scrapPrice)}", + listOf( + "§7You paid §c${NumberUtil.format(scrapPrice)} coins §7in total", + "§7for all §e$timesExcavated $name", + "§7you have used." + ) + ) + ) + return profit - scrapPrice + } + + @SubscribeEvent + fun onFossilExcavation(event: FossilExcavationEvent) { + if (!isEnabled()) return + for ((name, amount) in event.loot) { + addItem(name, amount) + } + tracker.modify { + it.timesExcavated++ + } + } + + private fun addItem(name: String, amount: Int) { + if (name == "§bGlacite Powder") { + if (config.trackGlacitePowder) { + tracker.modify { + it.glacitePowderGained += amount + } + } + return + } + if (name == "§fFossil Dust") { + if (config.showFossilDust) { + tracker.modify { + it.fossilDustGained += amount + } + } + return + } + + val internalName = NEUInternalName.fromItemNameOrNull(name) + if (internalName == null) { + ChatUtils.debug("no price for exavator profit: '$name'") + return + } + // TODO use primitive item stacks in trackers + tracker.addItem(internalName, amount) + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent) { + if (!isEnabled()) return + val inChest = Minecraft.getMinecraft().currentScreen is GuiChest + if (inChest) { + // Only show in excavation menu + if (!FossilExcavatorAPI.inExcavatorMenu) { + return + } + } + + tracker.renderDisplay(config.position) + } + + @SubscribeEvent + fun onIslandChange(event: IslandChangeEvent) { + if (event.newIsland == IslandType.DWARVEN_MINES) { + tracker.firstUpdate() + } + } + + fun isEnabled() = IslandType.DWARVEN_MINES.isInIsland() && config.enabled + && LorenzUtils.skyBlockArea == "Fossil Research Center" +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilExcavatorAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilExcavatorAPI.kt new file mode 100644 index 000000000..40971c87e --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilExcavatorAPI.kt @@ -0,0 +1,107 @@ +package at.hannibal2.skyhanni.features.mining.fossilexcavator + +import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.events.InventoryCloseEvent +import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent +import at.hannibal2.skyhanni.events.InventoryUpdatedEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent +import at.hannibal2.skyhanni.events.mining.FossilExcavationEvent +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.matches +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +object FossilExcavatorAPI { + + private val patternGroup = RepoPattern.group("mining.fossil.excavator") + private val chatPatternGroup = patternGroup.group("chat") + + /** + * REGEX-TEST: §r§6§lEXCAVATION COMPLETE + */ + private val startPattern by chatPatternGroup.pattern("start", " {2}§r§6§lEXCAVATION COMPLETE ") + + /** + * REGEX-TEST: §a§l▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ + */ + private val endPattern by chatPatternGroup.pattern("end", "§a§l▬{64}") + + /** + * REGEX-TEST: §r§6Tusk Fossil + */ + private val itemPattern by chatPatternGroup.pattern("item", " {4}§r(?<item>.+)") + + /** + * REGEX-TEST: §cYou didn't find anything. Maybe next time! + */ + private val emptyPattern by chatPatternGroup.pattern("empty", "§cYou didn't find anything. Maybe next time!") + + private var inLoot = false + private val loot = mutableListOf<Pair<String, Int>>() + + var inInventory = false + var inExcavatorMenu = false + + @SubscribeEvent + fun onInventoryOpen(event: InventoryFullyOpenedEvent) { + if (!IslandType.DWARVEN_MINES.isInIsland()) return + if (event.inventoryName != "Fossil Excavator") return + inInventory = true + } + + @SubscribeEvent + fun onInventoryUpdated(event: InventoryUpdatedEvent) { + if (!inInventory) return + val slots = InventoryUtils.getItemsInOpenChest() + val itemNames = slots.map { it.stack.displayName.removeColor() } + inExcavatorMenu = itemNames.any { it == "Start Excavator" } + } + + @SubscribeEvent + fun onWorldChange(event: LorenzWorldChangeEvent) { + inInventory = false + inExcavatorMenu = false + } + + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + inInventory = false + inExcavatorMenu = false + } + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (!IslandType.DWARVEN_MINES.isInIsland()) return + + val message = event.message + + if (emptyPattern.matches(message)) { + FossilExcavationEvent(emptyList()).postAndCatch() + } + + + if (startPattern.matches(message)) { + inLoot = true + return + } + + if (!inLoot) return + + if (endPattern.matches(message)) { + FossilExcavationEvent(loot.toList()).postAndCatch() + loot.clear() + inLoot = false + return + } + + val pair = itemPattern.matchMatcher(message) { + ItemUtils.readItemAmount(group("item")) + } ?: return + loot.add(pair) + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilMutation.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/solver/FossilMutation.kt index f039b2ef0..724e2a5aa 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilMutation.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/solver/FossilMutation.kt @@ -1,4 +1,4 @@ -package at.hannibal2.skyhanni.features.mining.fossilexcavator +package at.hannibal2.skyhanni.features.mining.fossilexcavator.solver enum class FossilMutation(val modification: (FossilShape) -> FossilShape) { ROTATE_0({ positions -> positions.rotate(0) }), diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilShape.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/solver/FossilShape.kt index c30bb9175..ae8b25593 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilShape.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/solver/FossilShape.kt @@ -1,4 +1,4 @@ -package at.hannibal2.skyhanni.features.mining.fossilexcavator +package at.hannibal2.skyhanni.features.mining.fossilexcavator.solver data class FossilShape(val tiles: List<FossilTile>) { fun width() = tiles.maxOf { it.x } - tiles.minOf { it.x } diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilExcavatorSolver.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/solver/FossilSolver.kt index b12e33674..7af22d701 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilExcavatorSolver.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/solver/FossilSolver.kt @@ -1,6 +1,6 @@ -package at.hannibal2.skyhanni.features.mining.fossilexcavator +package at.hannibal2.skyhanni.features.mining.fossilexcavator.solver -object FossilExcavatorSolver { +object FossilSolver { /* to be used when they have less than 18 clicks - solves 361/404 in at most 16 clicks @@ -34,7 +34,7 @@ object FossilExcavatorSolver { private var currentlySolving = false private fun getCurrentSequence(): Set<Triple<FossilTile, Double, Int>> { - return if (FossilExcavator.maxCharges < 18) { + return if (FossilSolverDisplay.maxCharges < 18) { riskyStartingSequence } else { safeStartingSequence @@ -62,13 +62,13 @@ object FossilExcavatorSolver { if (needsMoveSequence) { val movesTaken = invalidPositions.size if (movesTaken >= getCurrentSequence().size) { - FossilExcavator.showError() + FossilSolverDisplay.showError() currentlySolving = false return } val nextMove = getCurrentSequence().elementAt(movesTaken) - FossilExcavator.nextData(nextMove.first, nextMove.second, nextMove.third) + FossilSolverDisplay.nextData(nextMove.first, nextMove.second, nextMove.third) currentlySolving = false return } @@ -78,7 +78,7 @@ object FossilExcavatorSolver { val possibleFossilTypes = if (percentage == null) FossilType.entries else { val possibleFossils = FossilType.getByPercentage(percentage) - FossilExcavator.possibleFossilTypes = possibleFossils.toSet() + FossilSolverDisplay.possibleFossilTypes = possibleFossils.toSet() possibleFossils } @@ -106,12 +106,12 @@ object FossilExcavatorSolver { val bestPosition = possibleClickPositions.maxByOrNull { it.value } ?: run { if (fossilLocations.isNotEmpty()) { - FossilExcavator.showCompleted() + FossilSolverDisplay.showCompleted() currentlySolving = false return } - FossilExcavator.showError() + FossilSolverDisplay.showError() currentlySolving = false return } @@ -119,7 +119,7 @@ object FossilExcavatorSolver { val nextMove = bestPosition.key val correctPercentage = bestPosition.value / totalPossibleTiles currentlySolving = false - FossilExcavator.nextData(nextMove, correctPercentage, totalPossibleTiles.toInt()) + FossilSolverDisplay.nextData(nextMove, correctPercentage, totalPossibleTiles.toInt()) } private fun isValidFossilPosition( diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilExcavator.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/solver/FossilSolverDisplay.kt index e1c46e12e..590575ecd 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilExcavator.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/solver/FossilSolverDisplay.kt @@ -1,15 +1,16 @@ -package at.hannibal2.skyhanni.features.mining.fossilexcavator +package at.hannibal2.skyhanni.features.mining.fossilexcavator.solver import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.SkyHanniMod.Companion.coroutineScope +import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent -import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.RenderInventoryItemTipEvent +import at.hannibal2.skyhanni.features.mining.fossilexcavator.FossilExcavatorAPI import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzColor @@ -24,9 +25,9 @@ import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import kotlinx.coroutines.launch import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -object FossilExcavator { +object FossilSolverDisplay { - private val config get() = SkyHanniMod.feature.mining.fossilExcavator + private val config get() = SkyHanniMod.feature.mining.fossilExcavator.solver private val patternGroup = RepoPattern.group("mining.fossilexcavator") private val chargesRemainingPattern by patternGroup.pattern( @@ -38,8 +39,7 @@ object FossilExcavator { "Fossil Excavation Progress: (?<progress>[\\d.]+%)" ) - private var inInventory = false - private var inExcavatorMenu = false + private val inExcavatorMenu get() = FossilExcavatorAPI.inExcavatorMenu private var foundPercentage = false private var percentage: String? = null @@ -64,13 +64,6 @@ object FossilExcavator { var possibleFossilTypes = setOf<FossilType>() @SubscribeEvent - fun onInventoryOpen(event: InventoryFullyOpenedEvent) { - if (!isEnabled()) return - if (event.inventoryName != "Fossil Excavator") return - inInventory = true - } - - @SubscribeEvent fun onWorldChange(event: LorenzWorldChangeEvent) { clearData() } @@ -81,8 +74,6 @@ object FossilExcavator { } private fun clearData() { - inInventory = false - inExcavatorMenu = false foundPercentage = false percentage = null chargesRemaining = 0 @@ -97,12 +88,10 @@ object FossilExcavator { @SubscribeEvent fun onTick(event: LorenzTickEvent) { if (!isEnabled()) return - if (!inInventory) return val slots = InventoryUtils.getItemsInOpenChest() val itemNames = slots.map { it.stack.displayName.removeColor() } if (itemNames != inventoryItemNames) { inventoryItemNames = itemNames - inExcavatorMenu = itemNames.any { it == "Start Excavator" } if (inExcavatorMenu) return updateData() @@ -146,14 +135,13 @@ object FossilExcavator { } coroutineScope.launch { - FossilExcavatorSolver.findBestTile(fossilLocations, dirtLocations, percentage) + FossilSolver.findBestTile(fossilLocations, dirtLocations, percentage) } } @SubscribeEvent fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { if (!isEnabled()) return - if (!inInventory) return if (inExcavatorMenu) return event.makePickblock() @@ -168,7 +156,6 @@ object FossilExcavator { @SubscribeEvent fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { if (!isEnabled()) return - if (!inInventory) return if (inExcavatorMenu) return if (slotToClick == null) return @@ -182,7 +169,6 @@ object FossilExcavator { @SubscribeEvent fun onRenderItemTip(event: RenderInventoryItemTipEvent) { if (!isEnabled()) return - if (!inInventory) return if (!config.showPercentage) return if (slotToClick != event.slot.slotNumber) return if (inExcavatorMenu) return @@ -196,11 +182,10 @@ object FossilExcavator { @SubscribeEvent fun onBackgroundDraw(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) { if (!isEnabled()) return - if (!inInventory) return if (inExcavatorMenu) { // render here so they can move it around. As if you press key while doing the excavator you lose the scrap - config.position.renderString("§eExcavator solver gui", posLabel = "Fossil Excavator") + config.position.renderString("§eExcavator solver gui", posLabel = "Fossil Excavator Solver") return } @@ -209,9 +194,9 @@ object FossilExcavator { when { isNotPossible -> displayList.add(NOT_POSSIBLE_STRING) isCompleted -> displayList.add(SOLVED_STRING) - else -> displayList.add("$FOSSILS_REMAINING_STRING§a$possibleFossilsRemaining") + else -> displayList.add("${FOSSILS_REMAINING_STRING}§a$possibleFossilsRemaining") } - displayList.add("$CHARGES_REMAINING_STRING§a$chargesRemaining") + displayList.add("${CHARGES_REMAINING_STRING}§a$chargesRemaining") if (possibleFossilTypes.isNotEmpty()) { displayList.add("§ePossible Fossil types:") @@ -220,15 +205,20 @@ object FossilExcavator { } } - config.position.renderStrings(displayList, posLabel = "Fossil Excavator") + config.position.renderStrings(displayList, posLabel = "Fossil Excavator Solver") + } + + @SubscribeEvent + fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { + event.move(36, "mining.fossilExcavator", "mining.fossilExcavator.solver") } fun nextData(slotToClick: FossilTile, correctPercentage: Double, fossilsRemaining: Int) { val formattedPercentage = (correctPercentage * 100).round(1) - this.possibleFossilsRemaining = fossilsRemaining - this.slotToClick = slotToClick.toSlotIndex() - this.correctPercentage = "§2$formattedPercentage%" + possibleFossilsRemaining = fossilsRemaining + FossilSolverDisplay.slotToClick = slotToClick.toSlotIndex() + FossilSolverDisplay.correctPercentage = "§2$formattedPercentage%" } fun showError() { @@ -239,5 +229,5 @@ object FossilExcavator { isCompleted = true } - private fun isEnabled() = IslandType.DWARVEN_MINES.isInIsland() && config.enabled + private fun isEnabled() = IslandType.DWARVEN_MINES.isInIsland() && config.enabled && FossilExcavatorAPI.inInventory } diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilTile.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/solver/FossilTile.kt index 1c6ba7070..e671633cb 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilTile.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/solver/FossilTile.kt @@ -1,4 +1,4 @@ -package at.hannibal2.skyhanni.features.mining.fossilexcavator +package at.hannibal2.skyhanni.features.mining.fossilexcavator.solver data class FossilTile(val x: Int, val y: Int) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilType.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/solver/FossilType.kt index 208dfac96..e97271dfb 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilType.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/solver/FossilType.kt @@ -1,4 +1,4 @@ -package at.hannibal2.skyhanni.features.mining.fossilexcavator +package at.hannibal2.skyhanni.features.mining.fossilexcavator.solver enum class FossilType( val displayName: String, diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index 94558d949..5104c52b3 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -12,6 +12,7 @@ import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.isRecombobulated import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import at.hannibal2.skyhanni.utils.StringUtils.removeResets import com.google.gson.GsonBuilder import com.google.gson.JsonObject import net.minecraft.client.Minecraft @@ -293,9 +294,9 @@ object ItemUtils { fun readItemAmount(originalInput: String): Pair<String, Int>? { // This workaround fixes 'Tubto Cacti I Book' - val input = if (originalInput.endsWith(" Book")) { + val input = (if (originalInput.endsWith(" Book")) { originalInput.replace(" Book", "") - } else originalInput + } else originalInput).removeResets() if (itemAmountCache.containsKey(input)) { return itemAmountCache[input]!! @@ -313,9 +314,6 @@ object ItemUtils { string = string.substring(2) val matcher = UtilsPatterns.readAmountAfterPattern.matcher(string) if (!matcher.matches()) { - println("") - println("input: '$input'") - println("string: '$string'") return null } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt b/src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt index 97a4ab51c..e6a244f09 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt @@ -53,7 +53,7 @@ object UtilsPatterns { ) val readAmountAfterPattern by patternGroup.pattern( "item.amount.behind", - "(?<name>(?:['\\w-]+ ?)+)(?:§8x(?<amount>[\\d,]+))?" + "(?<name>(?:§.)*(?:[^§] ?)+)(?:§8x(?<amount>[\\d,]+))?" ) val timeAmountPattern by patternGroup.pattern( diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt index a64471e75..46bb84f04 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt @@ -183,7 +183,7 @@ class SkyHanniItemTracker<Data : ItemTrackerData>( } fun addTotalProfit(profit: Double, totalAmount: Long, action: String): Renderable { - val profitFormat = profit.addSeparators() + val profitFormat = profit.toInt().addSeparators() val profitPrefix = if (profit < 0) "§c" else "§6" val tips = if (totalAmount > 0) { |