Skip to content

Commit

Permalink
Improvement + Fix: Custom CF Reminder (#2334)
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 4b2935b commit 67dd38b
Showing 1 changed file with 56 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ import at.hannibal2.skyhanni.utils.HypixelCommands
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NumberUtil.formatLong
import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat
import at.hannibal2.skyhanni.utils.RegexUtils.matchAll
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SoundUtils
import at.hannibal2.skyhanni.utils.TimeUtils.format
import at.hannibal2.skyhanni.utils.TimeUtils.minutes
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
Expand All @@ -43,11 +49,36 @@ object ChocolateFactoryCustomReminder {

private var lastUpgradeWarning = SimpleTimeMark.farPast()

private val patternGroup = RepoPattern.group("inventory.chocolate.factory")

/**
* REGEX-TEST: §cRequires 400B all-time Chocolate!
*/
private val milestoneCostLorePattern by patternGroup.pattern(
"milestone.cost",
"§cRequires (?<amount>.*) all-time Chocolate!",
)

/**
* REGEX-TEST: §cYou don't have enough Chocolate!
*/
private val chatMessagePattern by patternGroup.list(
"chat.hide",
"§cYou don't have enough Chocolate!",
"§cYou don't have the required items!",
"§cYou must collect (.*) all-time Chocolate!",
)

@SubscribeEvent
fun onChat(event: SystemMessageEvent) {
if (!isEnabled()) return
if (!ChocolateFactoryAPI.inChocolateFactory) return
if (configReminder.hideChat) {
if (event.message == "§cYou don't have enough Chocolate!") {

if (chatMessagePattern.matches(event.message)) {
//§cYou don't have the required items!
//§cYou must collect 300B all-time Chocolate!
// if (event.message == "§cYou don't have enough Chocolate!") {
event.blockedReason = "custom_reminder"
}
}
Expand All @@ -64,17 +95,37 @@ object ChocolateFactoryCustomReminder {
if (!isEnabled()) return
val item = event.item ?: return
if (event.clickedButton != 0) return
// TODO add support for prestige and for Chocolate Milestone
val cost = ChocolateFactoryAPI.getChocolateBuyCost(item.getLore()) ?: return
val (cost, name) = getCostAndName(item) ?: return
val duration = ChocolateAmount.CURRENT.timeUntilGoal(cost)
val nextLevelName = ChocolateFactoryAPI.getNextLevelName(item) ?: return

// the user has enough chocolate, and just bought something
if (duration.isNegative()) {
reset()
return
}
setReminder(cost, nextLevelName)
setReminder(cost, name)
}

// TODO add support for prestige
private fun getCostAndName(item: ItemStack): Pair<Long, String>? {
val list = item.getLore()
val cost = ChocolateFactoryAPI.getChocolateBuyCost(list)
if (cost == null) {
milestoneCostLorePattern.matchAll(list) {
// math needed to get from "time until current chocolate" to "time until all time chocolate"
val amount = group("amount").formatLong()
val allTime = ChocolateAmount.ALL_TIME.chocolate()
val missingAllTime = amount - allTime
val current = ChocolateAmount.CURRENT.chocolate()
val missing = missingAllTime + current

return missing to "§6${amount.shortFormat()} Chocolate Milestone"
}
return null
}

val nextLevelName = ChocolateFactoryAPI.getNextLevelName(item) ?: item.name
return cost to nextLevelName
}

@SubscribeEvent
Expand Down

0 comments on commit 67dd38b

Please sign in to comment.