diff options
| author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2024-05-02 20:21:50 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-02 12:21:50 +0200 |
| commit | 51cc5a1516c1c31589de1018f194068277219998 (patch) | |
| tree | 04c2147071f54fda666e4a823589ba2dd699a41e | |
| parent | 0ce81ffab719984f9f0a86a4e443bbb318953402 (diff) | |
| download | SkyHanni-51cc5a1516c1c31589de1018f194068277219998.tar.gz SkyHanni-51cc5a1516c1c31589de1018f194068277219998.tar.bz2 SkyHanni-51cc5a1516c1c31589de1018f194068277219998.zip | |
Improvement: Show stars on time tower and coach jackrabbit (#1641)
12 files changed, 529 insertions, 348 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 5e017eb90..b9b7846de 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -271,6 +271,7 @@ import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarOrderHelper import at.hannibal2.skyhanni.features.inventory.bazaar.CraftMaterialsFromBazaar import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryAPI import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryBarnManager +import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryDataLoader import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryInventory import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryShortcut import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryStats @@ -633,6 +634,7 @@ class SkyHanniMod { loadModule(SkyblockXPInChat()) loadModule(AreaMiniBossFeatures()) loadModule(MobHighlight()) + loadModule(ChocolateFactoryDataLoader) loadModule(ChocolateFactoryBarnManager) loadModule(ChocolateFactoryShortcut()) loadModule(ChocolateFactoryInventory) diff --git a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java index ba60712e9..9ae839329 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java @@ -93,6 +93,9 @@ public class ProfileSpecificStorage { public int maxTimeTowerUses = 3; @Expose + public long bestUpgradeAvailableAt = 0; + + @Expose public long lastDataSave = 0; @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorRewardWarning.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorRewardWarning.kt index 935be19c0..883562a0b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorRewardWarning.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorRewardWarning.kt @@ -27,7 +27,7 @@ class VisitorRewardWarning { private val config get() = VisitorAPI.config.rewardWarning @SubscribeEvent - fun onBackgroundDrawn(event: GuiContainerEvent.ForegroundDrawnEvent) { + fun onForegroundDrawn(event: GuiContainerEvent.ForegroundDrawnEvent) { if (!VisitorAPI.inInventory) return val visitor = VisitorAPI.getVisitor(lastClickedNpc) ?: return diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt index 60ce618c8..5fcaf580b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt @@ -93,7 +93,7 @@ class HideNotClickableItems { } @SubscribeEvent - fun onBackgroundDrawn(event: GuiContainerEvent.ForegroundDrawnEvent) { + fun onForegroundDrawn(event: GuiContainerEvent.ForegroundDrawnEvent) { if (!LorenzUtils.inSkyBlock) return if (isDisabled()) return if (bypasssActive()) return diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt index 78ed735ec..a1fb4a359 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt @@ -56,7 +56,7 @@ class QuickCraftFeatures { } @SubscribeEvent - fun onBackgroundDrawn(event: GuiContainerEvent.ForegroundDrawnEvent) { + fun onForegroundDrawn(event: GuiContainerEvent.ForegroundDrawnEvent) { val inventoryType = getInventoryType() ?: return if (KeyboardManager.isModifierKeyDown()) return if (event.gui !is GuiChest) return diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateAmount.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateAmount.kt index cf22746ef..8a34cccb3 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateAmount.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateAmount.kt @@ -24,7 +24,7 @@ enum class ChocolateAmount(val chocolate: () -> Long) { } } - private fun timeUntilGoal(goal: Long): Duration { + fun timeUntilGoal(goal: Long): Duration { val profileStorage = ChocolateFactoryAPI.profileStorage ?: return Duration.ZERO val updatedAgo = SimpleTimeMark(profileStorage.lastDataSave).passedSince().inWholeSeconds @@ -33,6 +33,8 @@ enum class ChocolateAmount(val chocolate: () -> Long) { val rawChocolatePerSecond = profileStorage.rawChocPerSecond val timeTowerMultiplier = baseMultiplier + profileStorage.timeTowerLevel * 0.1 + if (rawChocolatePerSecond == 0) return Duration.INFINITE + var needed = goal - chocolate() val secondsUntilTowerExpires = ChocolateFactoryTimeTowerManager.timeTowerActiveDuration().inWholeSeconds @@ -57,5 +59,24 @@ enum class ChocolateAmount(val chocolate: () -> Long) { val perSecond = ChocolateFactoryAPI.chocolatePerSecond return (perSecond * secondsSinceUpdate).toLong() } + + fun averageChocPerSecond( + baseMultiplierIncrease: Double = 0.0, + rawPerSecondIncrease: Int = 0, + timeTowerLevelIncrease: Int = 0, + ): Double { + val profileStorage = profileStorage ?: return 0.0 + + val baseMultiplier = profileStorage.rawChocolateMultiplier + baseMultiplierIncrease + val rawPerSecond = profileStorage.rawChocPerSecond + rawPerSecondIncrease + val timeTowerLevel = profileStorage.timeTowerLevel + timeTowerLevelIncrease + + val timeTowerCooldown = profileStorage.timeTowerCooldown + + val basePerSecond = rawPerSecond * baseMultiplier + val towerCalc = (rawPerSecond * timeTowerLevel * .1) / timeTowerCooldown + + return basePerSecond + towerCalc + } } } 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 5780b4d24..1472d0199 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 @@ -6,33 +6,19 @@ import at.hannibal2.skyhanni.config.features.inventory.chocolatefactory.Chocolat import at.hannibal2.skyhanni.config.storage.ProfileSpecificStorage.ChocolateFactoryStorage import at.hannibal2.skyhanni.data.ProfileStorageData import at.hannibal2.skyhanni.data.jsonobjects.repo.HoppityEggLocationsJson -import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent -import at.hannibal2.skyhanni.events.InventoryUpdatedEvent -import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggLocator import at.hannibal2.skyhanni.utils.CollectionUtils.nextAfter 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.name import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.NumberUtil.formatDouble -import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.NumberUtil.formatLong -import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal -import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.SkyblockSeason -import at.hannibal2.skyhanni.utils.SoundUtils -import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import at.hannibal2.skyhanni.utils.TimeUtils import at.hannibal2.skyhanni.utils.UtilsPatterns import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern -import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object ChocolateFactoryAPI { @@ -41,62 +27,10 @@ object ChocolateFactoryAPI { val profileStorage: ChocolateFactoryStorage? get() = ProfileStorageData.profileSpecific?.chocolateFactory val patternGroup = RepoPattern.group("misc.chocolatefactory") - private val chocolateAmountPattern by patternGroup.pattern( + val chocolateAmountPattern by patternGroup.pattern( "chocolate.amount", "(?<amount>[\\d,]+) Chocolate" ) - private val chocolatePerSecondPattern by patternGroup.pattern( - "chocolate.persecond", - "§6(?<amount>[\\d.,]+) §8per second" - ) - private val chocolateAllTimePattern by patternGroup.pattern( - "chocolate.alltime", - "§7All-time Chocolate: §6(?<amount>[\\d,]+)" - ) - private val chocolateThisPrestigePattern by patternGroup.pattern( - "chocolate.thisprestige", - "§7Chocolate this Prestige: §6(?<amount>[\\d,]+)" - ) - private val chocolateMultiplierPattern by patternGroup.pattern( - "chocolate.multiplier", - "§7Total Multiplier: §6(?<amount>[\\d.]+)x" - ) - private val barnAmountPattern by patternGroup.pattern( - "barn.amount", - "§7Your Barn: §.(?<rabbits>\\d+)§7/§.(?<max>\\d+) Rabbits" - ) - private val prestigeLevelPattern by patternGroup.pattern( - "prestige.level", - "§6Chocolate Factory (?<prestige>[IVX]+)" - ) - private val chocolateForPrestigePattern by patternGroup.pattern( - "chocolate.forprestige", - "§7§cRequires (?<amount>\\w+) Chocolate this.*" - ) - private val clickMeRabbitPattern by patternGroup.pattern( - "rabbit.clickme", - "§e§lCLICK ME!" - ) - private val leaderboardPlacePattern by patternGroup.pattern( - "leaderboard.place", - "§7You are §8#§b(?<position>[\\d,]+)" - ) - private val leaderboardPercentilePattern by patternGroup.pattern( - "leaderboard.percentile", - "§7§8You are in the top §.(?<percent>[\\d.]+)%§8 of players!" - ) - private val timeTowerAmountPattern by patternGroup.pattern( - "timetower.amount", - "§7Charges: §.(?<uses>\\d+)§7/§a(?<max>\\d+)" - ) - private val timeTowerStatusPattern by patternGroup.pattern( - "timetower.status", - "§7Status: §.§l(?<status>INACTIVE|ACTIVE)(?: §f)?(?<acitveTime>\\w*)" - ) - private val timeTowerRechargePattern by patternGroup.pattern( - "timetower.recharge", - "§7Next Charge: §a(?<duration>\\w+)" - ) private val chocolateFactoryInventoryNamePattern by patternGroup.pattern( "inventory.name", "Hoppity|Chocolate Factory Milestones" @@ -106,11 +40,11 @@ object ChocolateFactoryAPI { var otherUpgradeSlots = setOf<Int>() var noPickblockSlots = setOf<Int>() var barnIndex = 34 - private var infoIndex = 13 - private var productionInfoIndex = 45 + var infoIndex = 13 + var productionInfoIndex = 45 var prestigeIndex = 28 var milestoneIndex = 53 - private var leaderboardIndex = 51 + var leaderboardIndex = 51 var handCookieIndex = 38 var timeTowerIndex = 39 var shrineIndex = 41 @@ -126,11 +60,12 @@ object ChocolateFactoryAPI { var leaderboardPercentile: Double? = null var chocolateForPrestige = 150_000_000L - val upgradeableSlots: MutableSet<Int> = mutableSetOf() - var bestUpgrade: Int? = null - var bestRabbitUpgrade: String? = null var clickRabbitSlot: Int? = null + val factoryUpgrades = mutableListOf<ChocolateFactoryUpgrade>() + var bestAffordableSlot = -1 + var bestPossibleSlot = -1 + @SubscribeEvent fun onInventoryOpen(event: InventoryFullyOpenedEvent) { if (!isEnabled()) return @@ -143,166 +78,10 @@ object ChocolateFactoryAPI { if (event.inventoryName != "Chocolate Factory") return inChocolateFactory = true + factoryUpgrades.clear() DelayedRun.runNextTick { - updateInventoryItems(event.inventoryItems) - } - } - - @SubscribeEvent - fun onInventoryUpdated(event: InventoryUpdatedEvent) { - if (!inChocolateFactory) return - - updateInventoryItems(event.inventoryItems) - } - - private fun updateInventoryItems(inventory: Map<Int, ItemStack>) { - val infoItem = InventoryUtils.getItemAtSlotIndex(infoIndex) ?: return - val prestigeItem = InventoryUtils.getItemAtSlotIndex(prestigeIndex) ?: return - val productionInfoItem = InventoryUtils.getItemAtSlotIndex(productionInfoIndex) ?: return - val leaderboardItem = InventoryUtils.getItemAtSlotIndex(leaderboardIndex) ?: return - val barnItem = InventoryUtils.getItemAtSlotIndex(barnIndex) ?: return - val timeTowerItem = InventoryUtils.getItemAtSlotIndex(timeTowerIndex) ?: return - - processInfoItems(infoItem, prestigeItem, productionInfoItem, leaderboardItem, barnItem, timeTowerItem) - - bestUpgrade = null - upgradeableSlots.clear() - var bestAffordableUpgradeRatio = Double.MAX_VALUE - var bestPossibleUpgradeRatio = Double.MAX_VALUE - clickRabbitSlot = null - - for ((slotIndex, item) in inventory) { - if (config.rabbitWarning && clickMeRabbitPattern.matches(item.name)) { - SoundUtils.playBeepSound() - clickRabbitSlot = slotIndex - } - - val lore = item.getLore() - val upgradeCost = getChocolateBuyCost(lore) ?: continue - - val canAfford = upgradeCost <= ChocolateAmount.CURRENT.chocolate() - if (canAfford) upgradeableSlots.add(slotIndex) - - if (slotIndex in rabbitSlots) { - val chocolateIncrease = rabbitSlots[slotIndex] ?: 0 - val upgradeRatio = upgradeCost.toDouble() / chocolateIncrease - - if (canAfford && upgradeRatio < bestAffordableUpgradeRatio) { - bestUpgrade = slotIndex - bestAffordableUpgradeRatio = upgradeRatio - } - if (upgradeRatio < bestPossibleUpgradeRatio) { - bestPossibleUpgradeRatio = upgradeRatio - bestRabbitUpgrade = item.name - } - } - } - } - - private fun processInfoItems( - chocolateItem: ItemStack, - prestigeItem: ItemStack, - productionItem: ItemStack, - leaderboardItem: ItemStack, - barnItem: ItemStack, - timeTowerItem: ItemStack, - ) { - val profileStorage = profileStorage ?: return - - leaderboardPosition = null - leaderboardPercentile = null - - chocolateAmountPattern.matchMatcher(chocolateItem.name.removeColor()) { - profileStorage.currentChocolate = group("amount").formatLong() - } - for (line in chocolateItem.getLore()) { - chocolatePerSecondPattern.matchMatcher(line) { - chocolatePerSecond = group("amount").formatDouble() - } - chocolateAllTimePattern.matchMatcher(line) { - profileStorage.chocolateAllTime = group("amount").formatLong() - } - } - prestigeLevelPattern.matchMatcher(prestigeItem.name) { - currentPrestige = group("prestige").romanToDecimal() - } - for (line in prestigeItem.getLore()) { - chocolateThisPrestigePattern.matchMatcher(line) { - profileStorage.chocolateThisPrestige = group("amount").formatLong() - } - chocolateForPrestigePattern.matchMatcher(line) { - chocolateForPrestige = group("amount").formatLong() - } - } - productionItem.getLore().matchFirst(chocolateMultiplierPattern) { - val currentMultiplier = group("amount").formatDouble() - profileStorage.chocolateMultiplier = currentMultiplier - - if (ChocolateFactoryTimeTowerManager.timeTowerActive()) { - profileStorage.rawChocolateMultiplier = currentMultiplier - profileStorage.timeTowerLevel * 0.1 - } else { - profileStorage.rawChocolateMultiplier = currentMultiplier - } - } - for (line in leaderboardItem.getLore()) { - leaderboardPlacePattern.matchMatcher(line) { - leaderboardPosition = group("position").formatInt() - } - leaderboardPercentilePattern.matchMatcher(line) { - leaderboardPercentile = group("percent").formatDouble() - } + ChocolateFactoryDataLoader.updateInventoryItems(event.inventoryItems) } - barnItem.getLore().matchFirst(barnAmountPattern) { - profileStorage.currentRabbits = group("rabbits").formatInt() - profileStorage.maxRabbits = group("max").formatInt() - ChocolateFactoryBarnManager.trySendBarnFullMessage() - } - for (line in timeTowerItem.getLore()) { - timeTowerAmountPattern.matchMatcher(line) { - profileStorage.currentTimeTowerUses = group("uses").formatInt() - profileStorage.maxTimeTowerUses = group("max").formatInt() - ChocolateFactoryTimeTowerManager.checkTimeTowerWarning(true) - } - 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 - profileStorage.currentTimeTowerEnds = activeUntil.toMillis() - } - } - 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 nextTimeTower = SimpleTimeMark.now() + timeUntilTower - profileStorage.nextTimeTower = nextTimeTower.toMillis() - } - } - profileStorage.rawChocPerSecond = (chocolatePerSecond / profileStorage.chocolateMultiplier).toInt() - profileStorage.lastDataSave = SimpleTimeMark.now().toMillis() - - if (!config.statsDisplay) return - ChocolateFactoryStats.updateDisplay() - } - - @SubscribeEvent - fun onWorldChange(event: LorenzWorldChangeEvent) { - clearData() - } - - @SubscribeEvent - fun onInventoryClose(event: InventoryCloseEvent) { - clearData() - } - - private fun clearData() { - inChocolateFactory = false - chocolateFactoryPaused = false } @SubscribeEvent @@ -326,7 +105,7 @@ object ChocolateFactoryAPI { coachRabbitIndex = data.coachRabbitIndex maxRabbits = data.maxRabbits - ChocolateFactoryTooltip.updateIgnoredSlots() + ChocolateFactoryUpgrade.updateIgnoredSlots() } @SubscribeEvent 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 new file mode 100644 index 000000000..a5de5d15a --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryDataLoader.kt @@ -0,0 +1,358 @@ +package at.hannibal2.skyhanni.features.inventory.chocolatefactory + +import at.hannibal2.skyhanni.events.InventoryCloseEvent +import at.hannibal2.skyhanni.events.InventoryUpdatedEvent +import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.LorenzUtils.round +import at.hannibal2.skyhanni.utils.NumberUtil.formatDouble +import at.hannibal2.skyhanni.utils.NumberUtil.formatInt +import at.hannibal2.skyhanni.utils.NumberUtil.formatLong +import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.SoundUtils +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.matches +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import at.hannibal2.skyhanni.utils.TimeUtils +import net.minecraft.item.ItemStack +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +object ChocolateFactoryDataLoader { + + private val config get() = ChocolateFactoryAPI.config + private val profileStorage get() = ChocolateFactoryAPI.profileStorage + + private val chocolatePerSecondPattern by ChocolateFactoryAPI.patternGroup.pattern( + "chocolate.persecond", + "§6(?<amount>[\\d.,]+) §8per second" + ) + private val chocolateAllTimePattern by ChocolateFactoryAPI.patternGroup.pattern( + "chocolate.alltime", + "§7All-time Chocolate: §6(?<amount>[\\d,]+)" + ) + private val prestigeLevelPattern by ChocolateFactoryAPI.patternGroup.pattern( + "prestige.level", + "§6Chocolate Factory (?<prestige>[IVX]+)" + ) + private val chocolateThisPrestigePattern by ChocolateFactoryAPI.patternGroup.pattern( + "chocolate.thisprestige", + "§7Chocolate this Prestige: §6(?<amount>[\\d,]+)" + ) + private val chocolateForPrestigePattern by ChocolateFactoryAPI.patternGroup.pattern( + "chocolate.forprestige", + "§7§cRequires (?<amount>\\w+) Chocolate this.*" + ) + private val chocolateMultiplierPattern by ChocolateFactoryAPI.patternGroup.pattern( + "chocolate.multiplier", + "§7Total Multiplier: §6(?<amount>[\\d.]+)x" + ) + private val leaderboardPlacePattern by ChocolateFactoryAPI.patternGroup.pattern( + "leaderboard.place", + "§7You are §8#§b(?<position>[\\d,]+)" + ) + private val leaderboardPercentilePattern by ChocolateFactoryAPI.patternGroup.pattern( + "leaderboard.percentile", + "§7§8You are in the top §.(?<percent>[\\d.]+)%§8 of players!" + ) + private val barnAmountPattern by ChocolateFactoryAPI.patternGroup.pattern( + "barn.amount", + "§7Your Barn: §.(?<rabbits>\\d+)§7/§.(?<max>\\d+) Rabbits" + ) + private val timeTowerAmountPattern by ChocolateFactoryAPI.patternGroup.pattern( + "timetower.amount", + "§7Charges: §.(?<uses>\\d+)§7/§a(?<max>\\d+)" + ) + private val timeTowerStatusPattern by ChocolateFactoryAPI.patternGroup.pattern( + "timetower.status", + "§7Status: §.§l(?<status>INACTIVE|ACTIVE)(?: §f)?(?<acitveTime>\\w*)" + ) + private val timeTowerRechargePattern by ChocolateFactoryAPI.patternGroup.pattern( + "timetower.recharge", + "§7Next Charge: §a(?<duration>\\w+)" + ) + private val clickMeRabbitPattern by ChocolateFactoryAPI.patternGroup.pattern( + "rabbit.clickme", + "§e§lCLICK ME!" + ) + private val rabbitAmountPattern by ChocolateFactoryAPI.patternGroup.pattern( + "rabbit.amount", + "Rabbit \\S+ - \\[(?<amount>\\d+)].*" + ) + private val upgradeTierPattern by ChocolateFactoryAPI.patternGroup.pattern( + "upgradetier", + ".*\\s(?<tier>[IVXLC]+)" + ) + private val unemployedRabbitPattern by ChocolateFactoryAPI.patternGroup.pattern( + "rabbit.unemployed", + "Rabbit \\w+ - Unemployed" + ) + + @SubscribeEvent + fun onInventoryUpdated(event: InventoryUpdatedEvent) { + if (!ChocolateFactoryAPI.inChocolateFactory) return + + updateInventoryItems(event.inventoryItems) + } + + @SubscribeEvent + fun onWorldChange(event: LorenzWorldChangeEvent) { + clearData() + } + + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + clearData() + } + + private fun clearData() { + ChocolateFactoryAPI.inChocolateFactory = false + ChocolateFactoryAPI.chocolateFactoryPaused = false + ChocolateFactoryAPI.factoryUpgrades.clear() + ChocolateFactoryAPI.bestAffordableSlot = -1 + ChocolateFactoryAPI.bestPossibleSlot = -1 + } + + fun updateInventoryItems(inventory: Map<Int, ItemStack>) { + val profileStorage = profileStorage ?: return + + val chocolateItem = InventoryUtils.getItemAtSlotIndex(ChocolateFactoryAPI.infoIndex) ?: return + val prestigeItem = InventoryUtils.getItemAtSlotIndex(ChocolateFactoryAPI.prestigeIndex) ?: return + val productionInfoItem = InventoryUtils.getItemAtSlotIndex(ChocolateFactoryAPI.productionInfoIndex) ?: return + val leaderboardItem = InventoryUtils.getItemAtSlotIndex(ChocolateFactoryAPI.leaderboardIndex) ?: return + val barnItem = InventoryUtils.getItemAtSlotIndex(ChocolateFactoryAPI.barnIndex) ?: return + val timeTowerItem = InventoryUtils.getItemAtSlotIndex(ChocolateFactoryAPI.timeTowerIndex) ?: return + + processChocolateItem(chocolateItem) + processPrestigeItem(prestigeItem) + processProductionItem(productionInfoItem) + processLeaderboardItem(leaderboardItem) + processBarnItem(barnItem) + processTimeTowerItem(timeTowerItem) + + ChocolateFactoryAPI.factoryUpgrades.clear() + + profileStorage.rawChocPerSecond = + (ChocolateFactoryAPI.chocolatePerSecond / profileStorage.chocolateMultiplier).toInt() + profileStorage.lastDataSave = SimpleTimeMark.now().toMillis() + + ChocolateFactoryStats.updateDisplay() + + processInventory(inventory) + + findBestUpgrades() + } + + private fun processChocolateItem(item: ItemStack) { + val profileStorage = profileStorage ?: return + + ChocolateFactoryAPI.chocolateAmountPattern.matchMatcher(item.name.removeColor()) { + profileStorage.currentChocolate = group("amount").formatLong() + } + for (line in item.getLore()) { + chocolatePerSecondPattern.matchMatcher(line) { + ChocolateFactoryAPI.chocolatePerSecond = group("amount").formatDouble() + } + chocolateAllTimePattern.matchMatcher(line) { + profileStorage.chocolateAllTime = group("amount").formatLong() + } + } + } + + private fun processPrestigeItem(item: ItemStack) { + val profileStorage = profileStorage ?: return + + prestigeLevelPattern.matchMatcher(item.name) { + ChocolateFactoryAPI.currentPrestige = group("prestige").romanToDecimal() + } + var prestigeCost: Long? = null + for (line in item.getLore()) { + chocolateThisPrestigePattern.matchMatcher(line) { + profileStorage.chocolateThisPrestige = group("amount").formatLong() + } + chocolateForPrestigePattern.matchMatcher(line) { + ChocolateFactoryAPI.chocolateForPrestige = group("amount").formatLong() + prestigeCost = ChocolateFactoryAPI.chocolateForPrestige + } + } + val prestigeUpgrade = ChocolateFactoryUpgrade( + ChocolateFactoryAPI.prestigeIndex, + ChocolateFactoryAPI.currentPrestige, + prestigeCost, + isPrestige = true + ) + ChocolateFactoryAPI.factoryUpgrades.add(prestigeUpgrade) + } + + private fun processProductionItem(item: ItemStack) { + val profileStorage = profileStorage ?: return + + item.getLore().matchFirst(chocolateMultiplierPattern) { + val currentMultiplier = group("amount").formatDouble() + profileStorage.chocolateMultiplier = currentMultiplier + + if (ChocolateFactoryTimeTowerManager.timeTowerActive()) { + profileStorage.rawChocolateMultiplier = currentMultiplier - profileStorage.timeTowerLevel * 0.1 + } else { + profileStorage.rawChocolateMultiplier = currentMultiplier + } + } + } + + private fun processLeaderboardItem(item: ItemStack) { + ChocolateFactoryAPI.leaderboardPosition = null + ChocolateFactoryAPI.leaderboardPercentile = null + + for (line in item.getLore()) { + leaderboardPlacePattern.matchMatcher(line) { + ChocolateFactoryAPI.leaderboardPosition = group("position").formatInt() + } + leaderboardPercentilePattern.matchMatcher(line) { + ChocolateFactoryAPI.leaderboardPercentile = group("percent").formatDouble() + } + } + } + + private fun processBarnItem(item: ItemStack) { + val profileStorage = profileStorage ?: return + + item.getLore().matchFirst(barnAmountPattern) { + profileStorage.currentRabbits = group("rabbits").formatInt() + profileStorage.maxRabbits = group("max").formatInt() + ChocolateFactoryBarnManager.trySendBarnFullMessage() + } + } + + private fun processTimeTowerItem(item: ItemStack) { + val profileStorage = profileStorage ?: return + + for (line in item.getLore()) { + timeTowerAmountPattern.matchMatcher(line) { + profileStorage.currentTimeTowerUses = group("uses").formatInt() + profileStorage.maxTimeTowerUses = group("max").formatInt() + ChocolateFactoryTimeTowerManager.checkTimeTowerWarning(true) + } + 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 + profileStorage.currentTimeTowerEnds = activeUntil.toMillis() + } + } + 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 nextTimeTower = SimpleTimeMark.now() + timeUntilTower + profileStorage.nextTimeTower = nextTimeTower.toMillis() + } + } + } + + private fun processInventory(inventory: Map<Int, ItemStack>) { + val profileStorage = profileStorage ?: return + + ChocolateFactoryAPI.clickRabbitSlot = null + + for ((slotIndex, item) in inventory) { + if (config.rabbitWarning && clickMeRabbitPattern.matches(item.name)) { + SoundUtils.playBeepSound() + ChocolateFactoryAPI.clickRabbitSlot = slotIndex + } + + |
