Skip to content

Commit

Permalink
Improvement + Fix: Personal Bests Gain (#2996)
Browse files Browse the repository at this point in the history
Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com>
Co-authored-by: Chiss5618 <78828070+Chiss5618@users.noreply.github.com>
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
  • Loading branch information
4 people authored Nov 29, 2024
1 parent ba8d210 commit 030c373
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.google.gson.JsonPrimitive
object ConfigUpdaterMigrator {

val logger = LorenzLogger("ConfigMigration")
const val CONFIG_VERSION = 67
const val CONFIG_VERSION = 68
fun JsonElement.at(chain: List<String>, init: Boolean): JsonElement? {
if (chain.isEmpty()) return this
if (this !is JsonObject) return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ public class GardenConfig {
@Accordion
public AtmosphericFilterDisplayConfig atmosphericFilterDisplay = new AtmosphericFilterDisplayConfig();

@Expose
@ConfigOption(name = "Personal Bests", desc = "")
@Accordion
public PersonalBestsConfig personalBests = new PersonalBestsConfig();

@Expose
@ConfigOption(name = "Plot Price", desc = "Show the price of the plot in coins when inside the Configure Plots inventory.")
@ConfigEditorBoolean
Expand Down Expand Up @@ -211,15 +216,6 @@ 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
@@ -0,0 +1,26 @@
package at.hannibal2.skyhanni.config.features.garden;

import at.hannibal2.skyhanni.config.FeatureToggle;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;


public class PersonalBestsConfig {
@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 increaseFF = true;

@Expose
@ConfigOption(
name = "Overflow Personal Bests",
desc = "Show in chat how much more FF you would have gotten over your previous record if personal best fortune cap was not 100."
)
@ConfigEditorBoolean
public boolean overflow = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data class GardenJson(
@Expose val visitors: Map<String, GardenVisitor>,
@Expose @SerializedName("organic_matter") val organicMatter: Map<NEUInternalName, Double>,
@Expose val fuel: Map<NEUInternalName, Double>,
@Expose @SerializedName("personal_best_increment") val personalBestIncrement: Map<CropType, Int>,
)

data class GardenVisitor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package at.hannibal2.skyhanni.features.garden.contest

import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.data.jsonobjects.repo.GardenJson
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.features.garden.CropType
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
Expand All @@ -14,8 +17,9 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
object FarmingPersonalBestGain {
private val config get() = GardenAPI.config
private val config get() = GardenAPI.config.personalBests
private val patternGroup = RepoPattern.group("garden.contest.personal.best")
private var personalBestIncrements = mapOf<CropType, Int>()

/**
* REGEX-TEST: §e[NPC] Jacob§f: §rYou collected §e1,400,694 §fitems! §d§lPERSONAL BEST§f!
Expand Down Expand Up @@ -46,6 +50,18 @@ object FarmingPersonalBestGain {
var oldCollected: Double? = null
var newFF: Double? = null
var crop: String? = null
var cropType: CropType? = null

@SubscribeEvent
fun onRepoReload(event: RepositoryReloadEvent) {
val data = event.getConstant<GardenJson>("Garden")
personalBestIncrements = data.personalBestIncrement
}

@SubscribeEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.move(68, "garden.contestPersonalBestIncreaseFF", "garden.personalBests.increaseFF")
}

@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
Expand All @@ -55,6 +71,7 @@ object FarmingPersonalBestGain {
newCollected = group("collected").formatDouble()
checkDelayed()
}

oldPattern.matchMatcher(event.message) {
oldCollected = group("collected").formatDouble()
checkDelayed()
Expand All @@ -63,7 +80,7 @@ object FarmingPersonalBestGain {
val cropName = group("crop")
newFF = group("ff").formatDouble()
crop = cropName
val cropType = CropType.getByName(cropName)
cropType = CropType.getByName(cropName)
GardenAPI.storage?.let {
it.personalBestFF[cropType] = newFF
}
Expand All @@ -78,18 +95,24 @@ object FarmingPersonalBestGain {
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 pbIncrement = personalBestIncrements[cropType] ?: return
val oldFF = oldCollected / (pbIncrement * 100)
val newOverflowFF = newCollected / (pbIncrement * 100)
val ffDiff = newFF - oldFF
val overflowFFDiff = newOverflowFF - oldFF

ChatUtils.chat("This is §6${ffDiff.roundTo(2)}$crop Fortune §emore than previously!")
if (oldFF < 100 && !config.overflow) {
ChatUtils.chat("This is §6${ffDiff.roundTo(2)}$crop Fortune §emore than previously!")
} else if (newOverflowFF > 100 && config.overflow) {
ChatUtils.chat("You have §6${newOverflowFF.roundTo(2)}$crop Fortune §eincluding overflow!")
ChatUtils.chat("This is §6${overflowFFDiff.roundTo(2)}$crop Fortune §emore than previously!")
}
}

fun isEnabled() = GardenAPI.inGarden() && config.contestPersonalBestIncreaseFF
fun isEnabled() = GardenAPI.inGarden() && config.increaseFF
}

0 comments on commit 030c373

Please sign in to comment.