diff options
author | Empa <42304516+ItsEmpa@users.noreply.github.com> | 2024-04-03 20:56:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-03 20:56:48 +0200 |
commit | 82a65251bb57f87459a6ef664c6321542b5cfccc (patch) | |
tree | aeec03713b12910d7618c1b0b294a6e18245fad0 /src/main/java | |
parent | 2f85351bacddb9ab3704a53c778d558a755bcc06 (diff) | |
download | skyhanni-82a65251bb57f87459a6ef664c6321542b5cfccc.tar.gz skyhanni-82a65251bb57f87459a6ef664c6321542b5cfccc.tar.bz2 skyhanni-82a65251bb57f87459a6ef664c6321542b5cfccc.zip |
Feature: Pest Profit Tracker (#1321)
Diffstat (limited to 'src/main/java')
6 files changed, 198 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 440c1922e..b98feae29 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -210,6 +210,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 @@ -813,6 +814,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 ac8ce0df7..1b8c2bdeb 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 @@ -247,6 +248,10 @@ object Commands { "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" ) { MythologicalCreatureTracker.resetCommand(it) } 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 000000000..549acb9db --- /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 messages", + desc = "Hides regular pest drop messages." + ) + @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 95c476da8..6aada35c5 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 @@ -27,6 +27,11 @@ public class PestsConfig { public PestTimerConfig pestTimer = new PestTimerConfig(); @Expose + @ConfigOption(name = "Pest Profit Tracker", desc = "") + @Accordion + public PestProfitTrackerConfig pestProfitTacker = new PestProfitTrackerConfig(); + + @Expose @ConfigOption(name = "Spray", desc = "") @Accordion public SprayConfig spray = new SprayConfig(); 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 912e26ffa..967e9b02d 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.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.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 class ProfileSpecificStorage { @Expose public Map<String, LorenzVec> npcVisitorLocations = new HashMap<>(); + + @Expose + public PestProfitTracker.Data pestProfitTracker = new PestProfitTracker.Data(); } @Expose 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 000000000..9ba0da2e7 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestProfitTracker.kt @@ -0,0 +1,146 @@ +package at.hannibal2.skyhanni.features.garden.pests + +import at.hannibal2.skyhanni.SkyHanniMod +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.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(?<amount>[0-9]*)x (?<item>.*) §efor killing an? §6(?<pest>.*)§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! (?:§.)*(?<item>.+) §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<String> { + 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<String> { + val pestsCoinsFormat = NumberUtil.format(item.totalAmount) + return listOf( + "§7Killing pests gives you coins.", + "§7You got §6$pestsCoinsFormat coins §7that way." + ) + } + + @Expose + var totalPestsKills = 0L + } + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (!isEnabled()) return + pestLootPattern.matchMatcher(event.message) { + val amount = group("amount").toInt() + val internalName = NEUInternalName.fromItemNameOrNull(group("item")) ?: return + + tracker.addItem(internalName, amount) + addKill() + if (config.hideChat) event.blockedReason = "pest_drop" + } + pestRareDropPattern.matchMatcher(event.message) { + val internalName = NEUInternalName.fromItemNameOrNull(group("item")) ?: 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 drawDisplay(data: Data): List<List<Any>> = 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()) + } + } + + fun resetCommand(args: Array<String>) { + tracker.resetCommand(args, "shresetpestprofittracker") + } + + fun isEnabled() = GardenAPI.inGarden() && config.enabled +} |