Skip to content

Commit

Permalink
Feature: Farming Personal Best FF Gain (#2332)
Browse files Browse the repository at this point in the history
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
  • Loading branch information
hannibal002 and hannibal002 authored Aug 13, 2024
1 parent 5410157 commit 9f4e281
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -275,6 +274,10 @@ public static class GardenStorage {
@Expose
public Map<CropType, Double> latestTrueFarmingFortune = new HashMap<>();

// TODO use in /ff guide
@Expose
public Map<CropType, Double> personalBestFF = new HashMap<>();

@Expose
@Nullable
public CropAccessory savedCropAccessory = CropAccessory.NONE;
Expand Down
Original file line number Diff line number Diff line change
@@ -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(?<collected>.*) §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(?<collected>.*)§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\\+(?<ff>.*)☘ (?<crop>.*) 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
}

0 comments on commit 9f4e281

Please sign in to comment.