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 /src/main | |
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)
Diffstat (limited to 'src/main')
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 + } + + if (slotIndex !in ChocolateFactoryAPI.otherUpgradeSlots && slotIndex !in ChocolateFactoryAPI.rabbitSlots) continue + + 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 { + unemployedRabbitPattern.matchMatcher(itemName) { + 0 + } + } ?: continue + isRabbit = true + + if (isMaxed) { + val rabbitUpgradeItem = ChocolateFactoryUpgrade(slotIndex, level, null, isRabbit = true) + ChocolateFactoryAPI.factoryUpgrades.add(rabbitUpgradeItem) + continue + } + + val chocolateIncrease = ChocolateFactoryAPI.rabbitSlots[slotIndex] ?: 0 + newAverageChocolate = ChocolateAmount.averageChocPerSecond(rawPerSecondIncrease = chocolateIncrease) + } + + in ChocolateFactoryAPI.otherUpgradeSlots -> { + level = upgradeTierPattern.matchMatcher(itemName) { + group("tier").romanToDecimal() + } ?: continue + + if (slotIndex == ChocolateFactoryAPI.timeTowerIndex) profileStorage.timeTowerLevel = level + + if (isMaxed) { + val otherUpgrade = ChocolateFactoryUpgrade(slotIndex, level, null) + ChocolateFactoryAPI.factoryUpgrades.add(otherUpgrade) + continue + } + + newAverageChocolate = when (slotIndex) { + ChocolateFactoryAPI.timeTowerIndex -> ChocolateAmount.averageChocPerSecond( + timeTowerLevelIncrease = 1 + ) + + ChocolateFactoryAPI.coachRabbitIndex -> ChocolateAmount.averageChocPerSecond( + baseMultiplierIncrease = 0.01 + ) + + else -> { + val otherUpgrade = ChocolateFactoryUpgrade(slotIndex, level, upgradeCost) + ChocolateFactoryAPI.factoryUpgrades.add(otherUpgrade) + continue + } + } + } + } + if (level == null || newAverageChocolate == null || upgradeCost == null) continue + + val extra = (newAverageChocolate - averageChocolate).round(2) + val effectiveCost = (upgradeCost / extra).round(2) + + val upgrade = + ChocolateFactoryUpgrade(slotIndex, level, upgradeCost, extra, effectiveCost, isRabbit = isRabbit) + ChocolateFactoryAPI.factoryUpgrades.add(upgrade) + } + } + + private fun findBestUpgrades() { + val profileStorage = profileStorage ?: return + + val notMaxed = ChocolateFactoryAPI.factoryUpgrades.filter { !it.isMaxed } + + val bestUpgrade = notMaxed.minByOrNull { it.effectiveCost ?: Double.MAX_VALUE } + profileStorage.bestUpgradeAvailableAt = bestUpgrade?.canAffordAt?.toMillis() ?: 0 + ChocolateFactoryAPI.bestPossibleSlot = bestUpgrade?.getValidUpgradeIndex() ?: -1 + + val affordAbleUpgrade = notMaxed.filter { it.canAfford() }.minByOrNull { it.effectiveCost ?: Double.MAX_VALUE } + ChocolateFactoryAPI.bestAffordableSlot = affordAbleUpgrade?.getValidUpgradeIndex() ?: -1 + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryInventory.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryInventory.kt index 0e5caca37..45b6bde86 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryInventory.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryInventory.kt @@ -1,49 +1,38 @@ package at.hannibal2.skyhanni.features.inventory.chocolatefactory import at.hannibal2.skyhanni.events.GuiContainerEvent -import at.hannibal2.skyhanni.events.GuiRenderItemEvent import at.hannibal2.skyhanni.events.RenderInventoryItemTipEvent 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.LorenzColor -import at.hannibal2.skyhanni.utils.NumberUtil.formatInt -import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal import at.hannibal2.skyhanni.utils.RenderUtils.drawSlotText import at.hannibal2.skyhanni.utils.RenderUtils.highlight import at.hannibal2.skyhanni.utils.StringUtils.matchFirst -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher -import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object ChocolateFactoryInventory { private val config get() = ChocolateFactoryAPI.config - private val profileStorage get() = ChocolateFactoryAPI.profileStorage - 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 unclaimedRewardsPattern by ChocolateFactoryAPI.patternGroup.pattern( "unclaimedrewards", "§7§aYou have \\d+ unclaimed rewards?!" ) @SubscribeEvent - fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.GuiRenderItemPost) { + fun onForegroundDrawn(event: GuiContainerEvent.ForegroundDrawnEvent) { if (!ChocolateFactoryAPI.inChocolateFactory) return if (!config.highlightUpgrades) return - val item = event.stack ?: return - val itemName = item.name - if (itemName != ChocolateFactoryAPI.bestRabbitUpgrade) return - event.drawSlotText(event.x + 18, event.y, "§6✦", .8f) + for (slot in InventoryUtils.getItemsInOpenChest()) { + if (slot.stack == null) continue + val slotIndex = slot.slotNumber + + if (slotIndex == ChocolateFactoryAPI.bestPossibleSlot) { + event.drawSlotText(slot.xDisplayPosition + 18, slot.yDisplayPosition, "§6✦", 1f) + } + } } @SubscribeEvent @@ -52,27 +41,32 @@ object ChocolateFactoryInventory { if (!config.highlightUpgrades) return for (slot in InventoryUtils.getItemsInOpenChest()) { - if (slot.slotIndex in ChocolateFactoryAPI.upgradeableSlots) { - if (slot.slotIndex == ChocolateFactoryAPI.bestUpgrade) { - slot highlight LorenzColor.GREEN.addOpacity(200) - } else { + if (slot.stack == null) continue + val slotIndex = slot.slotNumber + + ChocolateFactoryAPI.factoryUpgrades.find { it.slotIndex == slotIndex }?.let { upgrade -> + if (upgrade.canAfford()) { slot highlight LorenzColor.GREEN.addOpacity(75) } } - if (slot.slotIndex == ChocolateFactoryAPI.barnIndex && ChocolateFactoryBarnManager.barnFull) { + if (slotIndex == ChocolateFactoryAPI.bestAffordableSlot) { + slot highlight LorenzColor.GREEN.addOpacity(200) + } + + if (slotIndex == ChocolateFactoryAPI.barnIndex && ChocolateFactoryBarnManager.barnFull) { slot highlight LorenzColor.RED } - if (slot.slotIndex == ChocolateFactoryAPI.clickRabbitSlot) { + if (slotIndex == ChocolateFactoryAPI.clickRabbitSlot) { slot highlight LorenzColor.RED } - if (slot.slotIndex == ChocolateFactoryAPI.milestoneIndex) { + if (slotIndex == ChocolateFactoryAPI.milestoneIndex) { slot.stack?.getLore()?.matchFirst(unclaimedRewardsPattern) { slot highlight LorenzColor.RED } } - if (slot.slotIndex == ChocolateFactoryAPI.timeTowerIndex) { + if (slotIndex == ChocolateFactoryAPI.timeTowerIndex) { if (ChocolateFactoryTimeTowerManager.timeTowerActive()) { - slot highlight LorenzColor.LIGHT_PURPLE + slot highlight LorenzColor.LIGHT_PURPLE.addOpacity(200) } if (ChocolateFactoryTimeTowerManager.timeTowerFull()) { slot highlight LorenzColor.RED @@ -85,36 +79,9 @@ object ChocolateFactoryInventory { fun onRenderItemTip(event: RenderInventoryItemTipEvent) { if (!ChocolateFactoryAPI.inChocolateFactory) return if (!config.showStackSizes) return - val profileStorage = profileStorage ?: return - - val item = event.stack - val itemName = item.name.removeColor() - val slotNumber = event.slot.slotNumber - - if (slotNumber in ChocolateFactoryAPI.rabbitSlots) { - rabbitAmountPattern.matchMatcher(itemName) { - val rabbitTip = when (val rabbitAmount = group("amount").formatInt()) { - in (0..9) -> "$rabbitAmount" - in (10..74) -> "§a$rabbitAmount" - in (75..124) -> "§9$rabbitAmount" - in (125..174) -> "§5$rabbitAmount" - in (175..199) -> "§6$rabbitAmount" - 200 -> "§d$rabbitAmount" - else -> "§c$rabbitAmount" - } - - event.stackTip = rabbitTip - } - } - if (slotNumber in ChocolateFactoryAPI.otherUpgradeSlots) { - upgradeTierPattern.matchMatcher(itemName) { - val level = group("tier").romanToDecimal() - - if (slotNumber == ChocolateFactoryAPI.timeTowerIndex) profileStorage.timeTowerLevel = level - event.stackTip = level.toString() - } - } + val upgradeInfo = ChocolateFactoryAPI.factoryUpgrades.find { it.slotIndex == event.slot.slotNumber } ?: return + event.stackTip = upgradeInfo.stackTip() } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryTooltip.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryTooltip.kt index 7bd7fd90f..b2f33f09b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryTooltip.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryTooltip.kt @@ -11,17 +11,6 @@ object ChocolateFactoryTooltip { private val config get() = ChocolateFactoryAPI.config - private var ignoredSlotIndexes = listOf<Int>() - - fun updateIgnoredSlots() { - ignoredSlotIndexes = listOf( - ChocolateFactoryAPI.prestigeIndex, - ChocolateFactoryAPI.handCookieIndex, - ChocolateFactoryAPI.shrineIndex, - ChocolateFactoryAPI.barnIndex, - ) - } - @SubscribeEvent(priority = EventPriority.HIGH) fun onTooltip(event: LorenzToolTipEvent) { if (!ChocolateFactoryAPI.inChocolateFactory) return @@ -31,58 +20,25 @@ object ChocolateFactoryTooltip { if (slotIndex == ChocolateFactoryAPI.prestigeIndex) return if (slotIndex !in ChocolateFactoryAPI.otherUpgradeSlots && slotIndex !in ChocolateFactoryAPI.rabbitSlots) return - val upgradeCost = ChocolateFactoryAPI.getChocolateBuyCost(event.toolTip) ?: return - - event.toolTip.add("§8§m-----------------") - val timeToUpgrade = ChocolateAmount.CURRENT.formattedTimeUntilGoal(upgradeCost) - - event.toolTip.add("§7Time until upgrade: §e$timeToUpgrade") - - if (slotIndex in ignoredSlotIndexes) return - - val averageChocolate = averageChocPerSecond().round(2) - - val newAverageChocolate = when (slotIndex) { - in ChocolateFactoryAPI.rabbitSlots -> { - val chocolateIncrease = ChocolateFactoryAPI.rabbitSlots[slotIndex] ?: 0 - averageChocPerSecond(rawPerSecondIncrease = chocolateIncrease) - } + val upgradeInfo = ChocolateFactoryAPI.factoryUpgrades.find { it.slotIndex == slotIndex } ?: return - ChocolateFactoryAPI.timeTowerIndex -> averageChocPerSecond(timeTowerLevelIncrease = 1) - ChocolateFactoryAPI.coachRabbitIndex -> averageChocPerSecond(baseMultiplierIncrease = 0.01) - else -> averageChocolate - }.round(2) + if (slotIndex == ChocolateFactoryAPI.timeTowerIndex && upgradeInfo.isMaxed) { + event.toolTip.add("§8§m-----------------") + event.toolTip.add("§7One charge will give: §6${chocPerTimeTower().addSeparators()}") + } - val extra = (newAverageChocolate - averageChocolate).round(2) - val ratioForUpgrade = (upgradeCost / extra).round(2) + if (upgradeInfo.isMaxed) return - event.toolTip.add("§7Extra: §6$extra §7choc/s") - event.toolTip.add("§7Effective Cost: §6${ratioForUpgrade.addSeparators()}") + event.toolTip.add("§8§m-----------------") + event.toolTip.add("§7Time until upgrade: §e${upgradeInfo.formattedTimeUntilGoal()}") + event.toolTip.add("§7Extra: §6${upgradeInfo.extraPerSecond?.round(2) ?: "N/A"} §7choc/s") + event.toolTip.add("§7Effective Cost: §6${upgradeInfo.effectiveCost?.addSeparators() ?: "N/A"}") if (slotIndex == ChocolateFactoryAPI.timeTowerIndex) { event.toolTip.add("§7One charge will give: §6${chocPerTimeTower().addSeparators()}") } } - private 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 - } - private fun chocPerTimeTower(): Int { val profileStorage = profileStorage ?: return 0 val amountPerSecond = profileStorage.rawChocPerSecond * profileStorage.timeTowerLevel * .1 diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryUpgrade.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryUpgrade.kt new file mode 100644 index 000000000..1358e197d --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryUpgrade.kt @@ -0,0 +1,76 @@ +package at.hannibal2.skyhanni.features.inventory.chocolatefactory + +import at.hannibal2.skyhanni.utils.SimpleTimeMark + +data class ChocolateFactoryUpgrade( + val slotIndex: Int, + val level: Int, + val price: Long?, + val extraPerSecond: Double? = null, + val effectiveCost: Double? = null, + val isRabbit: Boolean = false, + val isPrestige: Boolean = false, +) { + private var chocolateAmountType = ChocolateAmount.CURRENT + var isMaxed = price == null + var canAffordAt: SimpleTimeMark? = null + + init { + if (isPrestige) { + chocolateAmountType = ChocolateAmount.PRESTIGE + } + val canAffordIn = chocolateAmountType.timeUntilGoal(price ?: 0) + canAffordAt = when { + canAffordIn.isInfinite() -> SimpleTimeMark.farFuture() + else -> SimpleTimeMark.now() + canAffordIn + } + } + + fun canAfford(): Boolean { + if (price == null) return false + return chocolateAmountType.chocolate() >= price + } + + fun formattedTimeUntilGoal(): String { + return chocolateAmountType.formattedTimeUntilGoal(price ?: 0) + } + + fun stackTip(): String { + return when { + level == 0 -> "" + isMaxed -> "§a✔" + + isRabbit -> when (level) { + in (0..9) -> "$level" + in (10..74) -> "§a$level" + in (75..124) -> "§9$level" + in (125..174) -> "§5$level" + in (175..199) -> "§6$level" + 200 -> "§d$level" + else -> "§c$level" + } + + else -> "$level" + } + } + + fun getValidUpgradeIndex(): Int { + return when (slotIndex) { + in ignoredSlotIndexes -> -1 + else -> slotIndex + } + } + + companion object { + var ignoredSlotIndexes = listOf<Int>() + + fun updateIgnoredSlots() { + ignoredSlotIndexes = listOf( + ChocolateFactoryAPI.prestigeIndex, + ChocolateFactoryAPI.handCookieIndex, + ChocolateFactoryAPI.shrineIndex, + ChocolateFactoryAPI.barnIndex, + ) + } + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt index 4f62c62bd..f96d03da2 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.data.GuiEditManager import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getAbsX import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getAbsY import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getDummySize +import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.GuiRenderItemEvent import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent import at.hannibal2.skyhanni.events.RenderGuiItemOverlayEvent @@ -1451,6 +1452,24 @@ object RenderUtils { text: String, scale: Float, ) { + RenderUtils.drawSlotText(xPos, yPos, text, scale) + } + + fun GuiContainerEvent.ForegroundDrawnEvent.drawSlotText( + xPos: Int, + yPos: Int, + text: String, + scale: Float, + ) { + RenderUtils.drawSlotText(xPos, yPos, text, scale) + } + + private fun drawSlotText( + xPos: Int, + yPos: Int, + text: String, + scale: Float, + ) { val fontRenderer = Minecraft.getMinecraft().fontRendererObj GlStateManager.disableLighting() |