aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorHiZe <super@hize.be>2024-06-01 11:19:31 +0200
committerGitHub <noreply@github.com>2024-06-01 11:19:31 +0200
commit6e75bd6dc33b23507e952267015628ba542715b9 (patch)
tree2db59cecdac12d8b5b6f2cf46edfc4e7a812b113 /src/main/java/at/hannibal2/skyhanni/features
parenta926a1ffe1edee456ede638c28e439fb3ae8958e (diff)
downloadskyhanni-6e75bd6dc33b23507e952267015628ba542715b9.tar.gz
skyhanni-6e75bd6dc33b23507e952267015628ba542715b9.tar.bz2
skyhanni-6e75bd6dc33b23507e952267015628ba542715b9.zip
Improvement + Fix: Sound for special stray rabbit (#1913)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryAPI.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryDataLoader.kt178
2 files changed, 127 insertions, 56 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryAPI.kt
index 8b9ef3f2a..568f8f4fe 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryAPI.kt
@@ -17,6 +17,7 @@ import at.hannibal2.skyhanni.utils.NumberUtil.formatLong
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.SkyblockSeason
+import at.hannibal2.skyhanni.utils.SoundUtils
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.UtilsPatterns
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
@@ -71,6 +72,9 @@ object ChocolateFactoryAPI {
var bestAffordableSlot = -1
var bestPossibleSlot = -1
+ var specialRabbitTextures = listOf<String>()
+ var warningSound = SoundUtils.createSound("note.pling", 1f)
+
@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
if (!isEnabled()) return
@@ -110,6 +114,7 @@ object ChocolateFactoryAPI {
coachRabbitIndex = data.coachRabbitIndex
maxRabbits = data.maxRabbits
maxPrestige = data.maxPrestige
+ specialRabbitTextures = data.specialRabbits
ChocolateFactoryUpgrade.updateIgnoredSlots()
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryDataLoader.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryDataLoader.kt
index 3d052da7a..108c24451 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryDataLoader.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryDataLoader.kt
@@ -1,10 +1,15 @@
package at.hannibal2.skyhanni.features.inventory.chocolatefactory
+import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
+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.utils.ConditionalUtils
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.LorenzUtils.round
import at.hannibal2.skyhanni.utils.NumberUtil.formatDouble
@@ -84,6 +89,14 @@ object ChocolateFactoryDataLoader {
"rabbit.clickme",
"§e§lCLICK ME!"
)
+
+ /**
+ * REGEX-TEST: §6§lGolden Rabbit §8- §aStampede
+ */
+ private val clickMeGoldenRabbitPattern by ChocolateFactoryAPI.patternGroup.pattern(
+ "rabbit.clickme.golden",
+ "§6§lGolden Rabbit §8- §a(?<name>.*)"
+ )
private val rabbitAmountPattern by ChocolateFactoryAPI.patternGroup.pattern(
"rabbit.amount",
"Rabbit \\S+ - \\[(?<amount>\\d+)].*"
@@ -118,6 +131,23 @@ object ChocolateFactoryDataLoader {
clearData()
}
+ @SubscribeEvent
+ fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
+ event.move(
+ 46,
+ "inventory.chocolateFactory.rabbitWarning",
+ "inventory.chocolateFactory.rabbitWarning.rabbitWarning"
+ )
+ }
+
+ @SubscribeEvent
+ fun onConfigLoad(event: ConfigLoadEvent) {
+ val soundProperty = config.rabbitWarning.specialRabbitSound
+ ConditionalUtils.onToggle(soundProperty) {
+ ChocolateFactoryAPI.warningSound = SoundUtils.createSound(soundProperty.get(), 1f)
+ }
+ }
+
private fun clearData() {
ChocolateFactoryAPI.inChocolateFactory = false
ChocolateFactoryAPI.chocolateFactoryPaused = false
@@ -281,84 +311,120 @@ object ChocolateFactoryDataLoader {
private fun processItem(list: MutableList<ChocolateFactoryUpgrade>, item: ItemStack, slotIndex: Int) {
if (slotIndex == ChocolateFactoryAPI.prestigeIndex) return
- if (config.rabbitWarning && clickMeRabbitPattern.matches(item.name)) {
- SoundUtils.playBeepSound()
- ChocolateFactoryAPI.clickRabbitSlot = slotIndex
- }
+
+ handleRabbitWarnings(item, slotIndex)
if (slotIndex !in ChocolateFactoryAPI.otherUpgradeSlots && slotIndex !in ChocolateFactoryAPI.rabbitSlots) return
val itemName = item.name.removeColor()
val lore = item.getLore()
val upgradeCost = ChocolateFactoryAPI.getChocolateBuyCost(lore)
-
val averageChocolate = ChocolateAmount.averageChocPerSecond().round(2)
val isMaxed = upgradeCost == null
- var isRabbit = false
- var level: Int? = null
- var newAverageChocolate: Double? = null
-
- when (slotIndex) {
- in ChocolateFactoryAPI.rabbitSlots -> {
- level = rabbitAmountPattern.matchMatcher(itemName) {
- group("amount").formatInt()
- } ?: run {
- if (unemployedRabbitPattern.matches(itemName)) 0 else null
- } ?: return
- isRabbit = true
-
- if (isMaxed) {
- val rabbitUpgradeItem = ChocolateFactoryUpgrade(slotIndex, level, null, isRabbit = true)
- list.add(rabbitUpgradeItem)
- return
- }
-
- val chocolateIncrease = ChocolateFactoryAPI.rabbitSlots[slotIndex] ?: 0
- newAverageChocolate = ChocolateAmount.averageChocPerSecond(rawPerSecondIncrease = chocolateIncrease)
- }
-
- in ChocolateFactoryAPI.otherUpgradeSlots -> {
- level = upgradeTierPattern.matchMatcher(itemName) {
- group("tier").romanToDecimal()
- } ?: run {
- if (otherUpgradePattern.matches(itemName)) 0 else null
- } ?: return
+ if (slotIndex in ChocolateFactoryAPI.rabbitSlots) {
+ handleRabbitSlot(list, itemName, slotIndex, isMaxed, upgradeCost, averageChocolate)
+ } else if (slotIndex in ChocolateFactoryAPI.otherUpgradeSlots) {
+ handleOtherUpgradeSlot(list, itemName, slotIndex, isMaxed, upgradeCost, averageChocolate)
+ }
+ }
- if (slotIndex == ChocolateFactoryAPI.timeTowerIndex) this.profileStorage?.timeTowerLevel = level
+ private fun handleRabbitSlot(
+ list: MutableList<ChocolateFactoryUpgrade>,
+ itemName: String,
+ slotIndex: Int,
+ isMaxed: Boolean,
+ upgradeCost: Long?,
+ averageChocolate: Double,
+ ) {
+ val level = rabbitAmountPattern.matchMatcher(itemName) {
+ group("amount").formatInt()
+ } ?: run {
+ if (unemployedRabbitPattern.matches(itemName)) 0 else null
+ } ?: return
+
+ if (isMaxed) {
+ val rabbitUpgradeItem = ChocolateFactoryUpgrade(slotIndex, level, null, isRabbit = true)
+ list.add(rabbitUpgradeItem)
+ return
+ }
- if (isMaxed) {
- val otherUpgrade = ChocolateFactoryUpgrade(slotIndex, level, null)
- list.add(otherUpgrade)
- return
- }
+ val chocolateIncrease = ChocolateFactoryAPI.rabbitSlots[slotIndex] ?: 0
+ val newAverageChocolate = ChocolateAmount.averageChocPerSecond(rawPerSecondIncrease = chocolateIncrease)
+ addUpgradeToList(list, slotIndex, level, upgradeCost, averageChocolate, newAverageChocolate, isRabbit = true)
+ }
- newAverageChocolate = when (slotIndex) {
- ChocolateFactoryAPI.timeTowerIndex -> ChocolateAmount.averageChocPerSecond(
- includeTower = true
- )
+ private fun handleOtherUpgradeSlot(
+ list: MutableList<ChocolateFactoryUpgrade>,
+ itemName: String,
+ slotIndex: Int,
+ isMaxed: Boolean,
+ upgradeCost: Long?,
+ averageChocolate: Double,
+ ) {
+ val level = upgradeTierPattern.matchMatcher(itemName) {
+ group("tier").romanToDecimal()
+ } ?: run {
+ if (otherUpgradePattern.matches(itemName)) 0 else null
+ } ?: return
+
+ if (slotIndex == ChocolateFactoryAPI.timeTowerIndex) {
+ this.profileStorage?.timeTowerLevel = level
+ }
- ChocolateFactoryAPI.coachRabbitIndex -> ChocolateAmount.averageChocPerSecond(
- baseMultiplierIncrease = 0.01
- )
+ if (isMaxed) {
+ val otherUpgrade = ChocolateFactoryUpgrade(slotIndex, level, null)
+ list.add(otherUpgrade)
+ return
+ }
- else -> {
- val otherUpgrade = ChocolateFactoryUpgrade(slotIndex, level, upgradeCost)
- list.add(otherUpgrade)
- return
- }
- }
+ val newAverageChocolate = when (slotIndex) {
+ ChocolateFactoryAPI.timeTowerIndex -> ChocolateAmount.averageChocPerSecond(includeTower = true)
+ ChocolateFactoryAPI.coachRabbitIndex -> ChocolateAmount.averageChocPerSecond(baseMultiplierIncrease = 0.01)
+ else -> {
+ val otherUpgrade = ChocolateFactoryUpgrade(slotIndex, level, upgradeCost)
+ list.add(otherUpgrade)
+ return
}
}
- if (level == null || newAverageChocolate == null || upgradeCost == null) return
- val extra = (newAverageChocolate - averageChocolate).round(2)
- val effectiveCost = (upgradeCost / extra).round(2)
+ addUpgradeToList(list, slotIndex, level, upgradeCost, averageChocolate, newAverageChocolate, isRabbit = false)
+ }
+ private fun addUpgradeToList(
+ list: MutableList<ChocolateFactoryUpgrade>,
+ slotIndex: Int,
+ level: Int,
+ upgradeCost: Long?,
+ averageChocolate: Double,
+ newAverageChocolate: Double,
+ isRabbit: Boolean,
+ ) {
+ val extra = (newAverageChocolate - averageChocolate).round(2)
+ val effectiveCost = (upgradeCost!! / extra).round(2)
val upgrade = ChocolateFactoryUpgrade(slotIndex, level, upgradeCost, extra, effectiveCost, isRabbit = isRabbit)
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) {
+ if (config.rabbitWarning.rabbitWarning) {
+ SoundUtils.playBeepSound()
+ }
+
+ if (warningConfig.specialRabbitWarning
+ && (isGoldenRabbit || item.getSkullTexture() in specialRabbitTextures)
+ ) {
+ SoundUtils.repeatSound(100, warningConfig.repeatSound, ChocolateFactoryAPI.warningSound)
+ }
+
+ ChocolateFactoryAPI.clickRabbitSlot = slotIndex
+ }
+ }
+
private fun findBestUpgrades(list: MutableList<ChocolateFactoryUpgrade>) {
val profileStorage = profileStorage ?: return