From ad5f173b1c94abb644494ce9f89238dba84dc0ac Mon Sep 17 00:00:00 2001 From: Empa <42304516+ItsEmpa@users.noreply.github.com> Date: Fri, 29 Mar 2024 23:09:37 +0100 Subject: [PATCH 1/3] innit --- .../java/at/hannibal2/skyhanni/SkyHanniMod.kt | 2 + .../skyhanni/config/commands/Commands.kt | 5 + .../garden/pests/PestProfitTrackerConfig.java | 36 ++++ .../features/garden/pests/PestsConfig.java | 5 + .../storage/ProfileSpecificStorage.java | 4 + .../data/jsonobjects/repo/PestDrops.java | 11 ++ .../garden/pests/PestProfitTracker.kt | 157 ++++++++++++++++++ 7 files changed, 220 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestProfitTrackerConfig.java create mode 100644 src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/PestDrops.java create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestProfitTracker.kt diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 22f0d3196562..b020db3a319c 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -206,6 +206,7 @@ import at.hannibal2.skyhanni.features.garden.inventory.plots.GardenPlotMenuHighl import at.hannibal2.skyhanni.features.garden.pests.PestAPI import at.hannibal2.skyhanni.features.garden.pests.PestFinder import at.hannibal2.skyhanni.features.garden.pests.PestParticleWaypoint +import at.hannibal2.skyhanni.features.garden.pests.PestProfitTracker import at.hannibal2.skyhanni.features.garden.pests.PestSpawn import at.hannibal2.skyhanni.features.garden.pests.PestSpawnTimer import at.hannibal2.skyhanni.features.garden.pests.SprayDisplay @@ -806,6 +807,7 @@ class SkyHanniMod { loadModule(LimboPlaytime()) loadModule(RareDropMessages()) loadModule(CraftMaterialsFromBazaar()) + loadModule(PestProfitTracker) init() 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 ac8ce0df7079..1b8c2bdeb2ce 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -44,6 +44,7 @@ import at.hannibal2.skyhanni.features.garden.farming.GardenStartLocation import at.hannibal2.skyhanni.features.garden.farming.lane.FarmingLaneCreator import at.hannibal2.skyhanni.features.garden.fortuneguide.CaptureFarmingGear import at.hannibal2.skyhanni.features.garden.fortuneguide.FFGuideGUI +import at.hannibal2.skyhanni.features.garden.pests.PestProfitTracker import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorDropStatistics import at.hannibal2.skyhanni.features.mining.KingTalismanHelper import at.hannibal2.skyhanni.features.mining.powdertracker.PowderTracker @@ -246,6 +247,10 @@ object Commands { "shresetdianaprofittracker", "Resets the Diana Profit Tracker" ) { DianaProfitTracker.resetCommand(it) } + registerCommand( + "shresetpestprofittracker", + "Resets the Pest Profit Tracker" + ) { PestProfitTracker.resetCommand(it) } registerCommand( "shresetmythologicalcreatureracker", "Resets the Mythological Creature Tracker" diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestProfitTrackerConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestProfitTrackerConfig.java new file mode 100644 index 000000000000..acc9b7400b9f --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestProfitTrackerConfig.java @@ -0,0 +1,36 @@ +package at.hannibal2.skyhanni.config.features.garden.pests; + +import at.hannibal2.skyhanni.config.FeatureToggle; +import at.hannibal2.skyhanni.config.core.config.Position; +import com.google.gson.annotations.Expose; +import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; +import io.github.moulberry.moulconfig.annotations.ConfigEditorSlider; +import io.github.moulberry.moulconfig.annotations.ConfigOption; + +public class PestProfitTrackerConfig { + + @Expose + @ConfigOption( + name = "Enabled", + desc = "Count all items you pick up when killing pests." + ) + @ConfigEditorBoolean + @FeatureToggle + public boolean enabled = true; + + @Expose + @ConfigOption( + name = "Hide regular drop messages.", + desc = "" + ) + @ConfigEditorBoolean + public boolean hideChat = true; + + @Expose + @ConfigOption(name = "Time Displayed", desc = "Time displayed after killing a pest.") + @ConfigEditorSlider(minValue = 5, maxValue = 60, minStep = 1) + public int timeDisplayed = 30; + + @Expose + public Position position = new Position(20, 20, false, true); +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestsConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestsConfig.java index 95c476da8361..6aada35c58b6 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestsConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestsConfig.java @@ -26,6 +26,11 @@ public class PestsConfig { @Accordion public PestTimerConfig pestTimer = new PestTimerConfig(); + @Expose + @ConfigOption(name = "Pest Profit Tracker", desc = "") + @Accordion + public PestProfitTrackerConfig pestProfitTacker = new PestProfitTrackerConfig(); + @Expose @ConfigOption(name = "Spray", desc = "") @Accordion 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 912e26ffa540..967e9b02df21 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java @@ -20,6 +20,7 @@ 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.PestProfitTracker; import at.hannibal2.skyhanni.features.garden.visitor.VisitorReward; import at.hannibal2.skyhanni.features.mining.powdertracker.PowderTracker; import at.hannibal2.skyhanni.features.misc.trevor.TrevorTracker; @@ -283,6 +284,9 @@ public static class FarmingWeightConfig { @Expose public Map npcVisitorLocations = new HashMap<>(); + + @Expose + public PestProfitTracker.Data pestProfitTracker = new PestProfitTracker.Data(); } @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/PestDrops.java b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/PestDrops.java new file mode 100644 index 000000000000..6d396021074e --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/PestDrops.java @@ -0,0 +1,11 @@ +package at.hannibal2.skyhanni.data.jsonobjects.repo; + +import at.hannibal2.skyhanni.utils.NEUInternalName; +import com.google.gson.annotations.Expose; + +import java.util.List; + +public class PestDrops { + @Expose + public List pest_drops; +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestProfitTracker.kt new file mode 100644 index 000000000000..0637883316d6 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestProfitTracker.kt @@ -0,0 +1,157 @@ +package at.hannibal2.skyhanni.features.garden.pests + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.jsonobjects.repo.PestDrops +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.PurseChangeCause +import at.hannibal2.skyhanni.events.PurseChangeEvent +import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import at.hannibal2.skyhanni.features.garden.GardenAPI +import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUInternalName +import at.hannibal2.skyhanni.utils.NumberUtil +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.renderables.Renderable +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import at.hannibal2.skyhanni.utils.tracker.ItemTrackerData +import at.hannibal2.skyhanni.utils.tracker.SkyHanniItemTracker +import com.google.gson.annotations.Expose +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.seconds + +object PestProfitTracker { + val config get() = SkyHanniMod.feature.garden.pests.pestProfitTacker + + private val patternGroup = RepoPattern.group("garden.pests.tracker") + + /** + * REGEX-TEST: §eYou received §a7x Enchanted Potato §efor killing a §6Locust§e! + * REGEX-TEST: §eYou received §a6x Enchanted Cocoa Beans §efor killing a §6Moth§e! + */ + private val pestLootPattern by patternGroup.pattern( + "loot", + "§eYou received §a(?[0-9]*)x (?.*) §efor killing an? §6(?.*)§e!" + ) + /** + * REGEX-TEST: §6§lRARE DROP! §9Mutant Nether Wart §6(§6+1,344☘) + * REGEX-TEST: §6§lPET DROP! §r§5Slug §6(§6+1300☘) + */ + private val pestRareDropPattern by patternGroup.pattern( + "raredrop", + "§6§l(?:RARE|PET) DROP! (?:§.)*(?.+) §6\\(§6\\+.*☘\\)" + ) + + private var lastPestKillTime = SimpleTimeMark.farPast() + private val tracker = SkyHanniItemTracker( + "Pest Profit Tracker", + { Data() }, + { it.garden.pestProfitTracker }) { drawDisplay(it) } + + class Data : ItemTrackerData() { + override fun resetItems() { + totalPestsKills = 0L + } + + override fun getDescription(timesGained: Long): List { + val percentage = timesGained.toDouble() / totalPestsKills + 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) = "§6Pest Kill Coins" + + override fun getCoinDescription(item: TrackedItem): List { + val pestsCoinsFormat = NumberUtil.format(item.totalAmount) + return listOf( + "§7Killing pests gives you coins.", + "§7You got §6$pestsCoinsFormat coins §7that way." + ) + } + + @Expose + var totalPestsKills = 0L + } + + private var allowedItems = listOf() + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (!isEnabled()) return + pestLootPattern.matchMatcher(event.message) { + val amount = group("amount").toInt() + val internalName = NEUInternalName.fromItemNameOrNull(group("item")) ?: return + if (!isAllowedItem(internalName)) return + tracker.addItem(internalName,amount) + addKill() + if (config.hideChat) event.blockedReason = "pest_drop" + } + pestRareDropPattern.matchMatcher(event.message) { + val internalName = NEUInternalName.fromItemNameOrNull(group("item")) ?: return + if (!isAllowedItem(internalName)) return + tracker.addItem(internalName, 1) + // pests always have guaranteed loot, therefore there's no need to add kill here + } + } + + private fun addKill() { + tracker.modify { + it.totalPestsKills++ + } + lastPestKillTime = SimpleTimeMark.now() + } + + private fun isAllowedItem(internalName: NEUInternalName): Boolean = internalName in allowedItems + + private fun drawDisplay(data: Data): List> = buildList { + addAsSingletonList("§e§lPest Profit Tracker") + val profit = tracker.drawItems(data, { true }, this) + + val pestsKilled = data.totalPestsKills + addAsSingletonList( + Renderable.hoverTips( + "§7Pests killed: §e${pestsKilled.addSeparators()}", + listOf("§7You killed pests §e${pestsKilled.addSeparators()} §7times.") + ) + ) + addAsSingletonList(tracker.addTotalProfit(profit, data.totalPestsKills, "kill")) + + tracker.addPriceFromButton(this) + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent) { + if (!isEnabled()) return + if (GardenAPI.isCurrentlyFarming()) return + if (lastPestKillTime.passedSince() > config.timeDisplayed.seconds && !PestAPI.hasVacuumInHand()) return + + tracker.renderDisplay(config.position) + + } + + @SubscribeEvent + fun onPurseChange(event: PurseChangeEvent) { + if (!isEnabled()) return + val coins = event.coins + if (event.reason == PurseChangeCause.GAIN_MOB_KILL && lastPestKillTime.passedSince() < 2.seconds) { + tracker.addCoins(coins.toInt()) + } + } + + @SubscribeEvent + fun onRepoReload(event: RepositoryReloadEvent) { + allowedItems = event.getConstant("PestDrops").pest_drops + } + + fun resetCommand(args: Array) { + tracker.resetCommand(args, "shresetpestprofittracker") + } + + fun isEnabled() = GardenAPI.inGarden() && config.enabled +} From c096fcdeabcb0a8fbc239b8f1c936cb1365e69eb Mon Sep 17 00:00:00 2001 From: Empa <42304516+ItsEmpa@users.noreply.github.com> Date: Sat, 30 Mar 2024 14:46:38 +0100 Subject: [PATCH 2/3] change description --- .../config/features/garden/pests/PestProfitTrackerConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestProfitTrackerConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestProfitTrackerConfig.java index acc9b7400b9f..549acb9dbcf5 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestProfitTrackerConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestProfitTrackerConfig.java @@ -20,8 +20,8 @@ public class PestProfitTrackerConfig { @Expose @ConfigOption( - name = "Hide regular drop messages.", - desc = "" + name = "Hide messages", + desc = "Hides regular pest drop messages." ) @ConfigEditorBoolean public boolean hideChat = true; From c4fb59bc06d68381490fb7982201eac13596fa06 Mon Sep 17 00:00:00 2001 From: Empa <42304516+ItsEmpa@users.noreply.github.com> Date: Wed, 3 Apr 2024 20:37:34 +0200 Subject: [PATCH 3/3] cleanup and removed pest drops from repo --- .../data/jsonobjects/repo/PestDrops.java | 11 ----------- .../garden/pests/PestProfitTracker.kt | 19 ++++--------------- 2 files changed, 4 insertions(+), 26 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/PestDrops.java diff --git a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/PestDrops.java b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/PestDrops.java deleted file mode 100644 index 6d396021074e..000000000000 --- a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/PestDrops.java +++ /dev/null @@ -1,11 +0,0 @@ -package at.hannibal2.skyhanni.data.jsonobjects.repo; - -import at.hannibal2.skyhanni.utils.NEUInternalName; -import com.google.gson.annotations.Expose; - -import java.util.List; - -public class PestDrops { - @Expose - public List pest_drops; -} diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestProfitTracker.kt index 0637883316d6..9ba0da2e7e33 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestProfitTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestProfitTracker.kt @@ -1,12 +1,10 @@ package at.hannibal2.skyhanni.features.garden.pests import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.jsonobjects.repo.PestDrops import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.PurseChangeCause import at.hannibal2.skyhanni.events.PurseChangeEvent -import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.LorenzUtils @@ -36,6 +34,7 @@ object PestProfitTracker { "loot", "§eYou received §a(?[0-9]*)x (?.*) §efor killing an? §6(?.*)§e!" ) + /** * REGEX-TEST: §6§lRARE DROP! §9Mutant Nether Wart §6(§6+1,344☘) * REGEX-TEST: §6§lPET DROP! §r§5Slug §6(§6+1300☘) @@ -79,22 +78,20 @@ object PestProfitTracker { var totalPestsKills = 0L } - private var allowedItems = listOf() - @SubscribeEvent fun onChat(event: LorenzChatEvent) { if (!isEnabled()) return pestLootPattern.matchMatcher(event.message) { val amount = group("amount").toInt() val internalName = NEUInternalName.fromItemNameOrNull(group("item")) ?: return - if (!isAllowedItem(internalName)) return - tracker.addItem(internalName,amount) + + tracker.addItem(internalName, amount) addKill() if (config.hideChat) event.blockedReason = "pest_drop" } pestRareDropPattern.matchMatcher(event.message) { val internalName = NEUInternalName.fromItemNameOrNull(group("item")) ?: return - if (!isAllowedItem(internalName)) return + tracker.addItem(internalName, 1) // pests always have guaranteed loot, therefore there's no need to add kill here } @@ -107,8 +104,6 @@ object PestProfitTracker { lastPestKillTime = SimpleTimeMark.now() } - private fun isAllowedItem(internalName: NEUInternalName): Boolean = internalName in allowedItems - private fun drawDisplay(data: Data): List> = buildList { addAsSingletonList("§e§lPest Profit Tracker") val profit = tracker.drawItems(data, { true }, this) @@ -132,7 +127,6 @@ object PestProfitTracker { if (lastPestKillTime.passedSince() > config.timeDisplayed.seconds && !PestAPI.hasVacuumInHand()) return tracker.renderDisplay(config.position) - } @SubscribeEvent @@ -144,11 +138,6 @@ object PestProfitTracker { } } - @SubscribeEvent - fun onRepoReload(event: RepositoryReloadEvent) { - allowedItems = event.getConstant("PestDrops").pest_drops - } - fun resetCommand(args: Array) { tracker.resetCommand(args, "shresetpestprofittracker") }