-
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Farming Personal Best FF Gain (#2332)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
- Loading branch information
1 parent
5410157
commit 9f4e281
Showing
3 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingPersonalBestGain.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |