From 9f4e281457ea73a9363cdf781351ed26be6ecbfc Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Tue, 13 Aug 2024 18:19:11 +0200 Subject: [PATCH] Feature: Farming Personal Best FF Gain (#2332) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../config/features/garden/GardenConfig.java | 9 ++ .../storage/ProfileSpecificStorage.java | 5 +- .../garden/contest/FarmingPersonalBestGain.kt | 95 +++++++++++++++++++ 3 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingPersonalBestGain.kt diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java index c4bbfacf34b0..b39f5f01ce63 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java @@ -217,6 +217,15 @@ public class GardenConfig { @FeatureToggle public boolean jacobContestSummary = true; + @Expose + @ConfigOption( + name = "Personal Best Increase FF", + desc = "Show in chat how much more FF you get from farming contest personal best bonus after beating the previous record." + ) + @ConfigEditorBoolean + @FeatureToggle + public boolean contestPersonalBestIncreaseFF = true; + // Does not have a config element! @Expose public Position cropSpeedMeterPos = new Position(278, -236, 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 3410d9b4de08..39ce4402b1a1 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java @@ -29,7 +29,6 @@ import at.hannibal2.skyhanni.features.garden.pests.VinylType; import at.hannibal2.skyhanni.features.garden.visitor.VisitorReward; import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryStrayTracker; -import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryUpgrade; import at.hannibal2.skyhanni.features.inventory.wardrobe.WardrobeAPI; import at.hannibal2.skyhanni.features.mining.MineshaftPityDisplay; import at.hannibal2.skyhanni.features.mining.fossilexcavator.ExcavatorProfitTracker; @@ -275,6 +274,10 @@ public static class GardenStorage { @Expose public Map latestTrueFarmingFortune = new HashMap<>(); + // TODO use in /ff guide + @Expose + public Map personalBestFF = new HashMap<>(); + @Expose @Nullable public CropAccessory savedCropAccessory = CropAccessory.NONE; diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingPersonalBestGain.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingPersonalBestGain.kt new file mode 100644 index 000000000000..7d009629b7c9 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingPersonalBestGain.kt @@ -0,0 +1,95 @@ +package at.hannibal2.skyhanni.features.garden.contest + +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.features.garden.CropType +import at.hannibal2.skyhanni.features.garden.GardenAPI +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.DelayedRun +import at.hannibal2.skyhanni.utils.LorenzUtils.round +import at.hannibal2.skyhanni.utils.NumberUtil.formatDouble +import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@SkyHanniModule +object FarmingPersonalBestGain { + private val config get() = GardenAPI.config + private val patternGroup = RepoPattern.group("garden.contest.personal.best") + + /** + * REGEX-TEST: §e[NPC] Jacob§f: §rYou collected §e1,400,694 §fitems! §d§lPERSONAL BEST§f! + */ + private val newPattern by patternGroup.pattern( + "collection.new", + "§e\\[NPC] Jacob§f: §rYou collected §e(?.*) §fitems! §d§lPERSONAL BEST§f!", + ) + + /** + * REGEX-TEST: §e[NPC] Jacob§f: §rYour previous Personal Best was §e1,176,372§f. + */ + private val oldPattern by patternGroup.pattern( + "collection.old", + "§e\\[NPC] Jacob§f: §rYour previous Personal Best was §e(?.*)§f.", + ) + + /** + * REGEX-TEST: §e[NPC] Jacob§f: §rYour §6Personal Bests §fperk is now granting you §6+46.69☘ Potato Fortune§f! + * + */ + private val newFFPattern by patternGroup.pattern( + "ff.new", + "§e\\[NPC] Jacob§f: §rYour §6Personal Bests §fperk is now granting you §6\\+(?.*)☘ (?.*) Fortune§f!", + ) + + var newCollected: Double? = null + var oldCollected: Double? = null + var newFF: Double? = null + var crop: String? = null + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (!isEnabled()) return + + newPattern.matchMatcher(event.message) { + newCollected = group("collected").formatDouble() + checkDelayed() + } + oldPattern.matchMatcher(event.message) { + oldCollected = group("collected").formatDouble() + checkDelayed() + } + newFFPattern.matchMatcher(event.message) { + val cropName = group("crop") + newFF = group("ff").formatDouble() + crop = cropName + val cropType = CropType.getByName(cropName) + GardenAPI.storage?.let { + it.personalBestFF[cropType] = newFF + } + checkDelayed() + } + } + + private fun checkDelayed() = DelayedRun.runNextTick { check() } + + private fun check() { + val newCollected = newCollected ?: return + val oldCollected = oldCollected ?: return + val newFF = newFF ?: return + val crop = crop ?: return + + this.newCollected = null + this.oldCollected = null + this.newFF = null + this.crop = null + + val collectionPerFF = newCollected / newFF + val oldFF = oldCollected / collectionPerFF + val ffDiff = newFF - oldFF + + ChatUtils.chat("This is §6${ffDiff.round(2)}☘ $crop Fortune §emore than previously!") + } + + fun isEnabled() = GardenAPI.inGarden() && config.contestPersonalBestIncreaseFF +}