Skip to content

Commit

Permalink
Fix: Stray Screen Flash V3 (hannibal002#3052)
Browse files Browse the repository at this point in the history
Co-authored-by: hannibal2 <[email protected]>
  • Loading branch information
DavidArthurCole and hannibal002 authored Dec 13, 2024
1 parent 92462e9 commit bd58e6d
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ public class ChocolateFactoryConfig {
));

@Expose
@ConfigOption(name = "Rabbit Warning", desc = "")
@ConfigOption(name = "Stray Rabbit Warning", desc = "")
@Accordion
public ChocolateFactoryRabbitWarningConfig rabbitWarning = new ChocolateFactoryRabbitWarningConfig();
public ChocolateFactoryStrayRabbitWarningConfig rabbitWarning = new ChocolateFactoryStrayRabbitWarningConfig();

@Expose
@ConfigOption(name = "Upgrade Warnings", desc = "")
@Accordion
public ChocolateUpgradeWarningsConfig chocolateUpgradeWarnings = new ChocolateUpgradeWarningsConfig();
public ChocolateFactoryUpgradeWarningsConfig chocolateUpgradeWarnings = new ChocolateFactoryUpgradeWarningsConfig();

@Expose
@ConfigOption(name = "Chocolate Shop Price", desc = "")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
package at.hannibal2.skyhanni.config.features.inventory.chocolatefactory;

import at.hannibal2.skyhanni.utils.LorenzColor;
import at.hannibal2.skyhanni.utils.OSUtils;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorButton;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorColour;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDropdown;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorText;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;
import io.github.notenoughupdates.moulconfig.observer.Property;
import org.jetbrains.annotations.NotNull;

public class ChocolateFactoryRabbitWarningConfig {
public class ChocolateFactoryStrayRabbitWarningConfig {

@Expose
@ConfigOption(name = "Rabbit Warning", desc = "Warn when stray rabbits of a certain tier appear.")
@ConfigOption(name = "Warning Level", desc = "Warn when stray rabbits of a certain tier appear.")
@ConfigEditorDropdown
public StrayTypeEntry rabbitWarningLevel = StrayTypeEntry.ALL;

@Expose
@ConfigOption(name = "Highlight Color", desc = "Choose the color that stray rabbits should be highlighted as.")
@ConfigEditorColour
public String inventoryHighlightColor = LorenzColor.RED.toConfigColor();

@Expose
@ConfigOption(name = "Warning Sound", desc = "The sound that plays for a special rabbit.\n" +
"§eYou can use custom sounds, put it in the §bskyhanni/sounds §efolder in your resource pack.\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;
import io.github.notenoughupdates.moulconfig.observer.Property;

public class ChocolateUpgradeWarningsConfig {
public class ChocolateFactoryUpgradeWarningsConfig {
@Expose
@ConfigOption(name = "Upgrade Warning", desc = "Chat notification when you have a chocolate factory upgrade available to purchase.")
@ConfigEditorBoolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactor
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryStrayTracker
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryStrayTracker.duplicateDoradoStrayPattern
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryStrayTracker.duplicatePseudoStrayPattern
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryStrayTracker.formLoreToSingleLine
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.DelayedRun
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.getSingleLineLore
import at.hannibal2.skyhanni.utils.LorenzRarity
import at.hannibal2.skyhanni.utils.LorenzRarity.DIVINE
import at.hannibal2.skyhanni.utils.LorenzRarity.LEGENDARY
Expand Down Expand Up @@ -188,15 +188,18 @@ object HoppityAPI {
return (month % 2 == 1) == (day % 2 == 0)
}

private fun Map<Int, ItemStack>.filterStrayProcessable() = filter { (slotNumber, stack) ->
fun filterMayBeStray(items: Map<Int, ItemStack>) = items.filter { (slotIndex, stack) ->
// Strays can only appear in the first 3 rows of the inventory, excluding the middle slot of the middle row.
slotNumber != 13 && slotNumber in 0..26 &&
// Don't process the same slot twice.
!processedStraySlots.contains(slotNumber) &&
slotIndex != 13 && slotIndex in 0..26 &&
// Stack must not be null, and must be a skull.
stack.item != null && stack.item == Items.skull &&
// All strays are skulls with a display name, and lore.
stack.hasDisplayName() && stack.getLore().isNotEmpty()
// All strays have a display name, all the time.
stack.hasDisplayName() && stack.displayName.isNotEmpty()
}

private fun Map<Int, ItemStack>.filterStrayProcessable() = filterMayBeStray(this).filter {
!processedStraySlots.contains(it.key) && // Don't process the same slot twice.
it.value.getLore().isNotEmpty() // All processable strays have lore.
}


Expand Down Expand Up @@ -262,7 +265,7 @@ object HoppityAPI {
else -> return@matchMatcher
}
}
ChocolateFactoryStrayTracker.strayDoradoPattern.matchMatcher(formLoreToSingleLine(itemStack.getLore())) {
ChocolateFactoryStrayTracker.strayDoradoPattern.matchMatcher(itemStack.getSingleLineLore()) {
// If the lore contains the escape pattern, we don't want to fire the event.
// There are also 3 separate messages that can match, which is why we need to check the time since the last fire.
if (ChocolateFactoryStrayTracker.doradoEscapeStrayPattern.anyMatches(itemStack.getLore())) return@matchMatcher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ object ChocolateFactoryAPI {

val config: ChocolateFactoryConfig get() = SkyHanniMod.feature.inventory.chocolateFactory
val profileStorage: ChocolateFactoryStorage? get() = ProfileStorageData.profileSpecific?.chocolateFactory

val patternGroup = RepoPattern.group("misc.chocolatefactory")

// <editor-fold desc="Patterns">
/**
* REGEX-TEST: 46,559,892,200 Chocolate
*/
Expand Down Expand Up @@ -76,6 +76,16 @@ object ChocolateFactoryAPI {
"(?<employee>(?:§.+)+Rabbit .*)§8 - §7\\[\\d*§7] .*",
)

/**
* REGEX-TEST: §7You caught a stray §6§lGolden Rabbit§7! §7You caught a glimpse of §6El Dorado§7, ...
* REGEX-TEST: §7You caught a stray §9Fish the Rabbit§7
*/
val caughtRabbitPattern by patternGroup.pattern(
"rabbit.caught",
".*§7You caught.*"
)
// </editor-fold>

var rabbitSlots = mapOf<Int, Int>()
var otherUpgradeSlots = setOf<Int>()
var noPickblockSlots = setOf<Int>()
Expand Down Expand Up @@ -106,8 +116,6 @@ object ChocolateFactoryAPI {
var leaderboardPercentile: Double? = null
var chocolateForPrestige = 150_000_000L

var clickRabbitSlot: Int? = null

var factoryUpgrades = listOf<ChocolateFactoryUpgrade>()
var bestAffordableSlot = -1
var bestPossibleSlot = -1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
package at.hannibal2.skyhanni.features.inventory.chocolatefactory

import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.config.features.inventory.chocolatefactory.ChocolateFactoryRabbitWarningConfig.StrayTypeEntry
import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryUpdatedEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryAPI.specialRabbitTextures
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryScreenFlash.isRarityOrHigher
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryScreenFlash.isSpecial
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.ConditionalUtils
import at.hannibal2.skyhanni.utils.HypixelCommands
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.getSkullTexture
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzRarity
import at.hannibal2.skyhanni.utils.NumberUtil.formatDouble
import at.hannibal2.skyhanni.utils.NumberUtil.formatInt
import at.hannibal2.skyhanni.utils.NumberUtil.formatLong
Expand Down Expand Up @@ -140,7 +134,7 @@ object ChocolateFactoryDataLoader {

/**
* REGEX-TEST: §7Status: §a§lACTIVE §f59m58s
* REGEX-TEST:
* REGEX-TEST: §7Status: §c§lINACTIVE
*/
private val timeTowerStatusPattern by ChocolateFactoryAPI.patternGroup.pattern(
"timetower.status",
Expand Down Expand Up @@ -422,21 +416,14 @@ object ChocolateFactoryDataLoader {
timeTowerStatusPattern.matchMatcher(line) {
val activeTime = group("acitveTime")
if (activeTime.isNotEmpty()) {
// todo in future fix this issue with TimeUtils.getDuration
val formattedGroup = activeTime.replace("h", "h ").replace("m", "m ")

val activeDuration = TimeUtils.getDuration(formattedGroup)
val activeUntil = SimpleTimeMark.now() + activeDuration
val activeUntil = SimpleTimeMark.now() + TimeUtils.getDuration(activeTime)
profileStorage.currentTimeTowerEnds = activeUntil
} else {
profileStorage.currentTimeTowerEnds = SimpleTimeMark.farPast()
}
}
timeTowerRechargePattern.matchMatcher(line) {
// todo in future fix this issue with TimeUtils.getDuration
val formattedGroup = group("duration").replace("h", "h ").replace("m", "m ")

val timeUntilTower = TimeUtils.getDuration(formattedGroup)
val timeUntilTower = TimeUtils.getDuration(group("duration"))
val nextTimeTower = SimpleTimeMark.now() + timeUntilTower
profileStorage.nextTimeTower = nextTimeTower
}
Expand Down Expand Up @@ -467,8 +454,6 @@ object ChocolateFactoryDataLoader {
}

private fun processInventory(list: MutableList<ChocolateFactoryUpgrade>, inventory: Map<Int, ItemStack>) {
ChocolateFactoryAPI.clickRabbitSlot = null

for ((slotIndex, item) in inventory) {
processItem(list, item, slotIndex)
}
Expand All @@ -477,8 +462,6 @@ object ChocolateFactoryDataLoader {
private fun processItem(list: MutableList<ChocolateFactoryUpgrade>, item: ItemStack, slotIndex: Int) {
if (slotIndex == ChocolateFactoryAPI.prestigeIndex) return

handleRabbitWarnings(item, slotIndex)

if (slotIndex !in ChocolateFactoryAPI.otherUpgradeSlots && slotIndex !in ChocolateFactoryAPI.rabbitSlots) return

val itemName = item.name.removeColor()
Expand Down Expand Up @@ -571,34 +554,6 @@ object ChocolateFactoryDataLoader {
list.add(upgrade)
}

private fun handleRabbitWarnings(item: ItemStack, slotIndex: Int) {
val isGoldenRabbit = clickMeGoldenRabbitPattern.matches(item.name)
val warningConfig = config.rabbitWarning

if (!clickMeRabbitPattern.matches(item.name) && !isGoldenRabbit) return
if (shouldWarnAboutStray(item)) {
if (isGoldenRabbit || item.getSkullTexture() in specialRabbitTextures) {
SoundUtils.repeatSound(100, warningConfig.repeatSound, ChocolateFactoryAPI.warningSound)
} else SoundUtils.playBeepSound()
}

ChocolateFactoryAPI.clickRabbitSlot = slotIndex
}

private fun shouldWarnAboutStray(item: ItemStack) = when (config.rabbitWarning.rabbitWarningLevel) {
StrayTypeEntry.SPECIAL -> isSpecial(item)

StrayTypeEntry.LEGENDARY_P -> isRarityOrHigher(item, LorenzRarity.LEGENDARY)
StrayTypeEntry.EPIC_P -> isRarityOrHigher(item, LorenzRarity.EPIC)
StrayTypeEntry.RARE_P -> isRarityOrHigher(item, LorenzRarity.RARE)
StrayTypeEntry.UNCOMMON_P -> isRarityOrHigher(item, LorenzRarity.UNCOMMON)

StrayTypeEntry.ALL -> clickMeRabbitPattern.matches(item.name) || isSpecial(item)

StrayTypeEntry.NONE -> false
else -> false
}

private fun findBestUpgrades(list: List<ChocolateFactoryUpgrade>) {
val profileStorage = profileStorage ?: return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ object ChocolateFactoryInventory {
if (slotIndex == ChocolateFactoryAPI.barnIndex && ChocolateFactoryBarnManager.barnFull) {
slot highlight LorenzColor.RED
}
if (slotIndex == ChocolateFactoryAPI.clickRabbitSlot) {
slot highlight LorenzColor.RED
}
if (slotIndex == ChocolateFactoryAPI.milestoneIndex) {
unclaimedRewardsPattern.firstMatcher(slot.stack?.getLore().orEmpty()) {
slot highlight LorenzColor.RED
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut
import at.hannibal2.skyhanni.utils.CollectionUtils.sortedDesc
import at.hannibal2.skyhanni.utils.DelayedRun
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.getSingleLineLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzRarity
import at.hannibal2.skyhanni.utils.LorenzRarity.LEGENDARY
Expand Down Expand Up @@ -156,11 +156,6 @@ object ChocolateFactoryStrayTracker {
var goldenTypesCaught: MutableMap<String, Int> = mutableMapOf()
}

fun formLoreToSingleLine(lore: List<String>): String {
val notEmptyLines = lore.filter { it.isNotEmpty() }
return notEmptyLines.joinToString(" ")
}

private fun incrementRarity(rarity: LorenzRarity, chocAmount: Long = 0) {
tracker.modify { it.straysCaught.addOrPut(rarity, 1) }
val extraTime = ChocolateFactoryAPI.timeUntilNeed(chocAmount + 1)
Expand Down Expand Up @@ -228,7 +223,7 @@ object ChocolateFactoryStrayTracker {
if (!isEnabled() || claimedStraysSlots.contains(slotNumber)) return false

claimedStraysSlots.add(slotNumber)
val loreLine = formLoreToSingleLine(itemStack.getLore())
val loreLine = itemStack.getSingleLineLore()

// "Base" strays - Common -> Epic, raw choc only reward.
strayLorePattern.matchMatcher(loreLine) {
Expand Down
Loading

0 comments on commit bd58e6d

Please sign in to comment.