From fccea080f5b8eaf561e83dc62b84a3cd5ded5a8f Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Tue, 7 Nov 2023 22:54:04 +0100 Subject: Added more Armor Drop Tracker features. Added command /shresetarmordroptracker to reset the full data, added session support and added button to reset the current session. --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 4 +- .../java/at/hannibal2/skyhanni/config/Storage.java | 4 +- .../hannibal2/skyhanni/config/commands/Commands.kt | 5 + .../features/garden/farming/ArmorDropTracker.kt | 174 +++++++++++++++++++++ .../features/garden/farming/CropMoneyDisplay.kt | 2 +- .../features/garden/farming/FarmingArmorDrops.kt | 148 ------------------ .../skyhanni/utils/tracker/DisplayMode.kt | 2 +- .../skyhanni/utils/tracker/SharedTracker.kt | 4 +- .../skyhanni/utils/tracker/SkyHanniTracker.kt | 5 +- .../skyhanni/utils/tracker/TrackerUtils.kt | 2 +- 10 files changed, 189 insertions(+), 161 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/farming/ArmorDropTracker.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingArmorDrops.kt (limited to 'src/main') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index cd2a752d0..ca743ed50 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -139,10 +139,10 @@ import at.hannibal2.skyhanni.features.garden.contest.JacobContestFFNeededDisplay import at.hannibal2.skyhanni.features.garden.contest.JacobContestStatsSummary import at.hannibal2.skyhanni.features.garden.contest.JacobContestTimeNeeded import at.hannibal2.skyhanni.features.garden.contest.JacobFarmingContestsInventory +import at.hannibal2.skyhanni.features.garden.farming.ArmorDropTracker import at.hannibal2.skyhanni.features.garden.farming.CropMoneyDisplay import at.hannibal2.skyhanni.features.garden.farming.CropSpeedMeter import at.hannibal2.skyhanni.features.garden.farming.DicerDropTracker -import at.hannibal2.skyhanni.features.garden.farming.FarmingArmorDrops import at.hannibal2.skyhanni.features.garden.farming.FarmingWeightDisplay import at.hannibal2.skyhanni.features.garden.farming.GardenBurrowingSporesNotifier import at.hannibal2.skyhanni.features.garden.farming.GardenCropMilestoneDisplay @@ -505,7 +505,7 @@ class SkyHanniMod { loadModule(JacobFarmingContestsInventory()) loadModule(GardenNextJacobContest) loadModule(WrongFungiCutterWarning()) - loadModule(FarmingArmorDrops()) + loadModule(ArmorDropTracker) loadModule(JoinCrystalHollows()) loadModule(CrystalHollowsNamesInCore()) loadModule(GardenVisitorColorNames) diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java index 75c9cde83..26fdd365a 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java @@ -8,8 +8,8 @@ import at.hannibal2.skyhanni.features.event.jerry.frozentreasure.FrozenTreasure; import at.hannibal2.skyhanni.features.fishing.trophy.TrophyRarity; import at.hannibal2.skyhanni.features.garden.CropAccessory; import at.hannibal2.skyhanni.features.garden.CropType; +import at.hannibal2.skyhanni.features.garden.farming.ArmorDropTracker; import at.hannibal2.skyhanni.features.garden.farming.DicerDropTracker; -import at.hannibal2.skyhanni.features.garden.farming.FarmingArmorDrops; import at.hannibal2.skyhanni.features.garden.fortuneguide.FarmingItems; import at.hannibal2.skyhanni.features.garden.visitor.VisitorReward; import at.hannibal2.skyhanni.features.mining.powdertracker.PowderTracker; @@ -160,7 +160,7 @@ public class Storage { public long nextSixthVisitorArrival = 0; @Expose - public Map farmArmorDrops = new HashMap<>(); + public ArmorDropTracker.Data armorDropTracker = new ArmorDropTracker.Data(); @Expose public Map composterUpgrades = new HashMap<>(); diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt index 3933ed081..c96dbab65 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -19,6 +19,7 @@ import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.features.garden.GardenCropTimeCommand import at.hannibal2.skyhanni.features.garden.GardenNextJacobContest import at.hannibal2.skyhanni.features.garden.composter.ComposterOverlay +import at.hannibal2.skyhanni.features.garden.farming.ArmorDropTracker import at.hannibal2.skyhanni.features.garden.farming.CropMoneyDisplay import at.hannibal2.skyhanni.features.garden.farming.CropSpeedMeter import at.hannibal2.skyhanni.features.garden.farming.DicerDropTracker @@ -168,6 +169,10 @@ object Commands { "shresetendernodetracker", "Resets the Ender Node Tracker" ) { EnderNodeTracker.resetCommand(it) } + registerCommand( + "shresetarmordroptracker", + "Resets the Armor Drop Tracker" + ) { ArmorDropTracker.resetCommand(it) } registerCommand("shbingotoggle", "Toggle the bingo card display mode") { BingoCardDisplay.toggleCommand() } registerCommand( "shfarmingprofile", diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/ArmorDropTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/ArmorDropTracker.kt new file mode 100644 index 000000000..0d5bcbf19 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/ArmorDropTracker.kt @@ -0,0 +1,174 @@ +package at.hannibal2.skyhanni.features.garden.farming + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator +import at.hannibal2.skyhanni.events.ConfigLoadEvent +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.events.PreProfileSwitchEvent +import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import at.hannibal2.skyhanni.features.garden.CropType +import at.hannibal2.skyhanni.features.garden.GardenAPI +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList +import at.hannibal2.skyhanni.utils.LorenzUtils.addOrPut +import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.jsonobjects.ArmorDropsJson +import at.hannibal2.skyhanni.utils.jsonobjects.ArmorDropsJson.DropInfo +import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker +import at.hannibal2.skyhanni.utils.tracker.TrackerData +import com.google.gson.JsonObject +import com.google.gson.annotations.Expose +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.seconds + +object ArmorDropTracker { + private var display = emptyList>() + + private var hasArmor = false + private val armorPattern = "(FERMENTO|CROPIE|SQUASH|MELON)_(LEGGINGS|CHESTPLATE|BOOTS|HELMET)".toPattern() + private val config get() = SkyHanniMod.feature.garden.farmingArmorDrop + + private val tracker = SkyHanniTracker("Armor Drop Tracker", Data(), { it.garden.armorDropTracker }) { update() } + + class Data : TrackerData() { + override fun reset() { + drops.clear() + } + + @Expose + var drops: MutableMap = mutableMapOf() + } + + enum class ArmorDropType(val dropName: String, val chatMessage: String) { + CROPIE("§9Cropie", "§6§lRARE CROP! §r§f§r§9Cropie §r§b(Armor Set Bonus)"), + SQUASH("§5Squash", "§6§lRARE CROP! §r§f§r§5Squash §r§b(Armor Set Bonus)"), + FERMENTO("§6Fermento", "§6§lRARE CROP! §r§f§r§6Fermento §r§b(Armor Set Bonus)"), + } + + @SubscribeEvent + fun onPreProfileSwitch(event: PreProfileSwitchEvent) { + display = emptyList() + hasArmor = false + } + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + for (dropType in ArmorDropType.entries) { + if (dropType.chatMessage == event.message) { + addDrop(dropType) + if (config.hideChat) { + event.blockedReason = "farming_armor_drops" + } + } + } + } + + private fun addDrop(drop: ArmorDropType) { + tracker.modify { + it.drops.addOrPut(drop, 1) + } + update() + } + + private fun update() { + display = drawDisplay() + } + + private fun drawDisplay() = buildList> { + val drops = tracker.currentDisplay()?.drops ?: return@buildList + + addAsSingletonList("§7RNG Drops for Farming Armor:") + tracker.addDisplayModeToggle(this) + for ((drop, amount) in drops.sortedDesc()) { + val dropName = drop.dropName + addAsSingletonList(" §7- §e${amount.addSeparators()}x $dropName") + } + + tracker.addSessionResetButton(this) + } + + @SubscribeEvent + fun onConfigLoad(event: ConfigLoadEvent) { + update() + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent) { + if (!GardenAPI.inGarden()) return + if (!config.enabled) return + if (!hasArmor) return + + tracker.renderDisplay(config.pos, display) + } + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + if (!GardenAPI.inGarden()) return + if (!config.enabled) return + + if (event.isMod(30)) { + checkArmor() + } + } + + private fun checkArmor() { + val armorPieces = InventoryUtils.getArmor() + .mapNotNull { it?.getInternalName()?.asString() } + .count { armorPattern.matcher(it).matches() } + hasArmor = armorPieces > 1 + } + + @SubscribeEvent + fun onRepoReload(event: RepositoryReloadEvent) { + val data = event.getConstant("ArmorDrops") + armorDropInfo = data.special_crops + } + + private var armorDropInfo = mapOf() + private var currentArmorDropChance = 0.0 + private var lastCalculationTime = SimpleTimeMark.farPast() + + fun getDropsPerHour(crop: CropType?): Double { + if (crop == null) return 0.0 + + if (lastCalculationTime.passedSince() > 5.seconds) { + lastCalculationTime = SimpleTimeMark.now() + + val armorDropName = crop.specialDropType + val armorName = armorDropInfo[armorDropName]?.armor_type ?: return 0.0 + val pieceCount = InventoryUtils.getArmor() + .mapNotNull { it?.getInternalName()?.asString() } + .count { it.contains(armorName) || it.contains("FERMENTO") } + + val dropRates = armorDropInfo[armorDropName]?.chance ?: return 0.0 + var dropRate = 0.0 + if (pieceCount > 0 && dropRates.size >= pieceCount) { + dropRate = dropRates[pieceCount - 1] + } + currentArmorDropChance = (dropRate * 60 * 60.0) / 100 + } + return currentArmorDropChance + } + + @SubscribeEvent + fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { + event.move(3, "garden.farmingArmorDropsEnabled", "garden.farmingArmorDrop.enabled") + event.move(3, "garden.farmingArmorDropsHideChat", "garden.farmingArmorDrop.hideChat") + event.move(3, "garden.farmingArmorDropsPos", "garden.farmingArmorDrop.pos") + + event.move(8, "#profile.garden.farmArmorDrops", "#profile.garden.armorDropTracker") { old -> + val new = JsonObject() + new.add("drops", old) + new + } + } + + fun resetCommand(args: Array) { + tracker.resetCommand(args, "shresetarmordroptracker") + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt index 0cc07f7e7..91abf10a4 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt @@ -155,7 +155,7 @@ object CropMoneyDisplay { if (config.armor) { val amountPerHour = - it.multiplier * GardenCropSpeed.getRecentBPS() * FarmingArmorDrops.getDropsPerHour(it) + it.multiplier * GardenCropSpeed.getRecentBPS() * ArmorDropTracker.getDropsPerHour(it) extraArmorCoins = amountPerHour * it.specialDropType.asInternalName().getNpcPrice() } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingArmorDrops.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingArmorDrops.kt deleted file mode 100644 index 2617ad329..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingArmorDrops.kt +++ /dev/null @@ -1,148 +0,0 @@ -package at.hannibal2.skyhanni.features.garden.farming - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator -import at.hannibal2.skyhanni.events.ConfigLoadEvent -import at.hannibal2.skyhanni.events.GuiRenderEvent -import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.events.LorenzTickEvent -import at.hannibal2.skyhanni.events.PreProfileSwitchEvent -import at.hannibal2.skyhanni.events.RepositoryReloadEvent -import at.hannibal2.skyhanni.features.garden.CropType -import at.hannibal2.skyhanni.features.garden.GardenAPI -import at.hannibal2.skyhanni.utils.InventoryUtils -import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName -import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc -import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators -import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings -import at.hannibal2.skyhanni.utils.SimpleTimeMark -import at.hannibal2.skyhanni.utils.jsonobjects.ArmorDropsJson -import at.hannibal2.skyhanni.utils.jsonobjects.ArmorDropsJson.DropInfo -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import kotlin.time.Duration.Companion.seconds - -class FarmingArmorDrops { - private var display = emptyList() - private val storage get() = GardenAPI.storage - - private var hasArmor = false - private val armorPattern = "(FERMENTO|CROPIE|SQUASH|MELON)_(LEGGINGS|CHESTPLATE|BOOTS|HELMET)".toPattern() - private val config get() = SkyHanniMod.feature.garden.farmingArmorDrop - - enum class ArmorDropType(val dropName: String, val chatMessage: String) { - CROPIE("§9Cropie", "§6§lRARE CROP! §r§f§r§9Cropie §r§b(Armor Set Bonus)"), - SQUASH("§5Squash", "§6§lRARE CROP! §r§f§r§5Squash §r§b(Armor Set Bonus)"), - FERMENTO("§6Fermento", "§6§lRARE CROP! §r§f§r§6Fermento §r§b(Armor Set Bonus)"), - } - - @SubscribeEvent - fun onPreProfileSwitch(event: PreProfileSwitchEvent) { - display = emptyList() - hasArmor = false - } - - @SubscribeEvent - fun onChat(event: LorenzChatEvent) { - for (dropType in ArmorDropType.entries) { - if (dropType.chatMessage == event.message) { - addDrop(dropType) - if (config.hideChat) { - event.blockedReason = "farming_armor_drops" - } - } - } - } - - private fun addDrop(drop: ArmorDropType) { - val drops = storage?.farmArmorDrops ?: return - val old = drops[drop] ?: 0 - drops[drop] = old + 1 - update() - } - - private fun update() { - display = drawDisplay() - } - - private fun drawDisplay() = buildList { - val drops = storage?.farmArmorDrops ?: return@buildList - - add("§7RNG Drops for Farming Armor:") - for ((drop, amount) in drops.sortedDesc()) { - val dropName = drop.dropName - add(" §7- §e${amount.addSeparators()}x $dropName") - } - } - - @SubscribeEvent - fun onConfigLoad(event: ConfigLoadEvent) { - update() - } - - @SubscribeEvent - fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { - if (!GardenAPI.inGarden()) return - if (!config.enabled) return - if (!hasArmor) return - - config.pos.renderStrings(display, posLabel = "Farming Armor Drops") - } - - @SubscribeEvent - fun onTick(event: LorenzTickEvent) { - if (!GardenAPI.inGarden()) return - if (!config.enabled) return - - if (event.isMod(30)) { - checkArmor() - } - } - - private fun checkArmor() { - val armorPieces = InventoryUtils.getArmor() - .mapNotNull { it?.getInternalName()?.asString() } - .count { armorPattern.matcher(it).matches() } - hasArmor = armorPieces > 1 - } - - @SubscribeEvent - fun onRepoReload(event: RepositoryReloadEvent) { - val data = event.getConstant("ArmorDrops") - armorDropInfo = data.special_crops - } - - companion object { - var armorDropInfo = mapOf() - private var currentArmorDropChance = 0.0 - private var lastCalculationTime = SimpleTimeMark.farPast() - - fun getDropsPerHour(crop: CropType?): Double { - if (crop == null) return 0.0 - - if (lastCalculationTime.passedSince() > 5.seconds) { - lastCalculationTime = SimpleTimeMark.now() - - val armorDropName = crop.specialDropType - val armorName = armorDropInfo[armorDropName]?.armor_type ?: return 0.0 - val pieceCount = InventoryUtils.getArmor() - .mapNotNull { it?.getInternalName()?.asString() } - .count { it.contains(armorName) || it.contains("FERMENTO") } - - val dropRates = armorDropInfo[armorDropName]?.chance ?: return 0.0 - var dropRate = 0.0 - if (pieceCount > 0 && dropRates.size >= pieceCount) { - dropRate = dropRates[pieceCount - 1] - } - currentArmorDropChance = (dropRate * 60 * 60.0) / 100 - } - return currentArmorDropChance - } - } - - @SubscribeEvent - fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { - event.move(3, "garden.farmingArmorDropsEnabled", "garden.farmingArmorDrop.enabled") - event.move(3, "garden.farmingArmorDropsHideChat", "garden.farmingArmorDrop.hideChat") - event.move(3, "garden.farmingArmorDropsPos", "garden.farmingArmorDrop.pos") - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/DisplayMode.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/DisplayMode.kt index 6c0e14439..55441953c 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/DisplayMode.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/DisplayMode.kt @@ -2,6 +2,6 @@ package at.hannibal2.skyhanni.utils.tracker enum class DisplayMode(val displayName: String) { TOTAL("Total"), - CURRENT("This Session"), + SESSION("This Session"), ; } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SharedTracker.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SharedTracker.kt index 341600467..9b5ae1d90 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SharedTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SharedTracker.kt @@ -11,8 +11,6 @@ class SharedTracker( fun get(displayMode: DisplayMode) = when (displayMode) { DisplayMode.TOTAL -> total - DisplayMode.CURRENT -> currentSession + DisplayMode.SESSION -> currentSession } - - fun getCurrent() = get(TrackerUtils.currentDisplayMode) } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt index 6ff8febc7..e1b4c42ad 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt @@ -26,7 +26,7 @@ class SkyHanniTracker( } fun addSessionResetButton(list: MutableList>) { - if (inventoryOpen && TrackerUtils.currentDisplayMode == DisplayMode.CURRENT) { + if (inventoryOpen && TrackerUtils.currentDisplayMode == DisplayMode.SESSION) { list.addSessionResetButton(name, getSharedTracker()) { update() } @@ -45,8 +45,7 @@ class SkyHanniTracker( } } - // rename - fun currentDisplay() = getSharedTracker()?.getCurrent() + fun currentDisplay() = getSharedTracker()?.get(TrackerUtils.currentDisplayMode) fun resetCommand(args: Array, command: String) { TrackerUtils.resetCommand(name, command, args, getSharedTracker()) { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerUtils.kt index cc2dab37f..ec527c9e5 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerUtils.kt @@ -30,7 +30,7 @@ object TrackerUtils { "§c$name" ), ) { - data?.get(DisplayMode.CURRENT)?.let { + data?.get(DisplayMode.SESSION)?.let { reset(it) { update() } -- cgit