diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerDropTracker.kt (renamed from src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerRngDropCounter.kt) | 129 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt | 72 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt | 100 |
3 files changed, 129 insertions, 172 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerRngDropCounter.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerDropTracker.kt index d72540720..a3b4f73cb 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerRngDropCounter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerDropTracker.kt @@ -1,8 +1,10 @@ package at.hannibal2.skyhanni.features.garden.farming import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.ConfigManager import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator -import at.hannibal2.skyhanni.events.ConfigLoadEvent +import at.hannibal2.skyhanni.config.Storage.ProfileSpecific.GardenStorage.DicerDropTracker +import at.hannibal2.skyhanni.data.ProfileStorageData import at.hannibal2.skyhanni.events.GardenToolChangeEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.LorenzChatEvent @@ -10,19 +12,28 @@ import at.hannibal2.skyhanni.events.PreProfileSwitchEvent import at.hannibal2.skyhanni.features.garden.CropType import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList +import at.hannibal2.skyhanni.utils.LorenzUtils.addOrPut import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators -import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings +import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import at.hannibal2.skyhanni.utils.tracker.DisplayMode +import at.hannibal2.skyhanni.utils.tracker.SharedTracker +import at.hannibal2.skyhanni.utils.tracker.TrackerUtils +import at.hannibal2.skyhanni.utils.tracker.TrackerUtils.addDisplayModeToggle +import at.hannibal2.skyhanni.utils.tracker.TrackerUtils.addSessionResetButton +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.inventory.GuiInventory import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -class DicerRngDropCounter { - private var display = emptyList<String>() - private val drops = mutableMapOf<CropType, MutableMap<DropRarity, Int>>() +object DicerDropTracker { + private var display = emptyList<List<Any>>() private val itemDrops = mutableListOf<ItemDrop>() private val config get() = SkyHanniMod.feature.garden.dicerCounters + private val currentSessionData = DicerDropTracker() + private var inventoryOpen = false init { - initDrops() itemDrops.add(ItemDrop(CropType.MELON, DropRarity.UNCOMMON, "§a§lUNCOMMON DROP! §r§eDicer dropped §r§a(\\d+)x §r§aEnchanted Melon§r§e!".toRegex())) itemDrops.add(ItemDrop(CropType.MELON, DropRarity.RARE, "§9§lRARE DROP! §r§eDicer dropped §r§a(\\d+)x §r§aEnchanted Melon§r§e!".toRegex())) itemDrops.add(ItemDrop(CropType.MELON, DropRarity.CRAZY_RARE, "§d§lCRAZY RARE DROP! §r§eDicer dropped §r§[a|9](\\d+)x §r§[a|9]Enchanted Melon(?: Block)?§r§e!".toRegex())) @@ -34,11 +45,6 @@ class DicerRngDropCounter { itemDrops.add(ItemDrop(CropType.PUMPKIN, DropRarity.PRAY_TO_RNGESUS, "§5§lPRAY TO RNGESUS DROP! §r§eDicer dropped §r§[a|9](\\d+)x §r§(aEnchanted|9Polished) Pumpkin§r§e!".toRegex())) } - private fun initDrops() { - drops[CropType.MELON] = mutableMapOf() - drops[CropType.PUMPKIN] = mutableMapOf() - } - enum class DropRarity(val displayName: String) { UNCOMMON("§a§lUNCOMMON DROP"), RARE("§9§lRARE DROP"), @@ -49,8 +55,6 @@ class DicerRngDropCounter { @SubscribeEvent fun onPreProfileSwitch(event: PreProfileSwitchEvent) { display = emptyList() - drops.clear() - initDrops() } @SubscribeEvent @@ -62,10 +66,8 @@ class DicerRngDropCounter { for (drop in itemDrops) { if (drop.pattern.matches(message)) { addDrop(drop.crop, drop.rarity) - saveConfig() - update() if (config.hideChat) { - event.blockedReason = "dicer_rng_drop_counter" + event.blockedReason = "dicer_drop_tracker" } return } @@ -73,19 +75,30 @@ class DicerRngDropCounter { } private fun update() { - display = drawDisplay() + currentDisplay()?.let { + display = drawDisplay(it) + } } - private fun drawDisplay(): List<String> { - val help = mutableListOf<String>() - val items = drops[cropInHand] ?: return help - help.add("§7RNG Drops for $toolName§7:") + private fun drawDisplay(storage: DicerDropTracker) = buildList<List<Any>> { + val cropInHand = cropInHand ?: return@buildList + val items = storage.drops.getOrPut(cropInHand) { mutableMapOf() } + addAsSingletonList("§7Dicer Drop Tracker for $toolName§7:") + if (inventoryOpen) { + addDisplayModeToggle { + update() + } + } for ((rarity, amount) in items.sortedDesc()) { val displayName = rarity.displayName - help.add(" §7- §e${amount.addSeparators()}x $displayName") + addAsSingletonList(" §7- §e${amount.addSeparators()}x $displayName") } - return help + if (inventoryOpen && TrackerUtils.currentDisplayMode == DisplayMode.CURRENT) { + addSessionResetButton("Dicer Drop Tracker", getSharedTracker()) { + update() + } + } } private var cropInHand: CropType? = null @@ -102,42 +115,27 @@ class DicerRngDropCounter { } private fun addDrop(crop: CropType, rarity: DropRarity) { - val map = drops[crop]!! - val old = map[rarity] ?: 0 - map[rarity] = old + 1 - } - - @SubscribeEvent - fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { - if (isEnabled()) { - config.pos.renderStrings(display, posLabel = "Dicer Counter") + val sharedTracker = getSharedTracker() ?: return + sharedTracker.modify { + val map = it.drops.getOrPut(crop) { mutableMapOf() } + map.addOrPut(rarity, 1) } + update() } - class ItemDrop(val crop: CropType, val rarity: DropRarity, val pattern: Regex) + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent) { + if (!isEnabled()) return - private fun saveConfig() { - val map = GardenAPI.storage?.dicerRngDrops ?: return - map.clear() - for (drop in drops) { - val crop = drop.key - for ((rarity, amount) in drop.value) { - map[crop.cropName + "." + rarity.name] = amount - } + val currentlyOpen = Minecraft.getMinecraft().currentScreen is GuiInventory + if (inventoryOpen != currentlyOpen) { + inventoryOpen = currentlyOpen + update() } + config.pos.renderStringsAndItems(display, posLabel = "Dicer Drop Tracker") } - @SubscribeEvent - fun onConfigLoad(event: ConfigLoadEvent) { - val map = GardenAPI.storage?.dicerRngDrops ?: return - for ((internalName, amount) in map) { - val split = internalName.split(".") - val crop = CropType.getByName(split[0]) - val rarityName = split[1] - val rarity = DropRarity.valueOf(rarityName) - drops[crop]!![rarity] = amount - } - } + class ItemDrop(val crop: CropType, val rarity: DropRarity, val pattern: Regex) fun isEnabled() = GardenAPI.inGarden() && config.display @@ -146,5 +144,32 @@ class DicerRngDropCounter { event.move(3, "garden.dicerCounterDisplay", "garden.dicerCounters.display") event.move(3, "garden.dicerCounterHideChat", "garden.dicerCounters.hideChat") event.move(3, "garden.dicerCounterPos", "garden.dicerCounters.pos") + + event.move(7, "#profile.garden.dicerRngDrops", "#profile.garden.dicerDropTracker.drops") { old -> + val items: MutableMap<CropType, MutableMap<DropRarity, Int>> = mutableMapOf() + val oldItems = ConfigManager.gson.fromJson<Map<String, Int>>(old, Map::class.java) + for ((internalName, amount) in oldItems) { + val split = internalName.split(".") + val crop = CropType.getByName(split[0]) + val rarityName = split[1] + val rarity = DropRarity.valueOf(rarityName) + items.getOrPut(crop) { mutableMapOf() }[rarity] = amount + } + + ConfigManager.gson.toJsonTree(items) + } + } + + private fun currentDisplay() = getSharedTracker()?.getCurrent() + + private fun getSharedTracker(): SharedTracker<DicerDropTracker>? { + val profileSpecific = ProfileStorageData.profileSpecific ?: return null + return SharedTracker(profileSpecific.garden.dicerDropTracker, currentSessionData) + } + + fun resetCommand(args: Array<String>) { + TrackerUtils.resetCommand("Dicer Drop Tracker", "shresetdicertracker", args, getSharedTracker()) { + update() + } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt index 9db8553aa..7269797cb 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt @@ -12,19 +12,23 @@ import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList -import at.hannibal2.skyhanni.utils.LorenzUtils.addSelector import at.hannibal2.skyhanni.utils.LorenzUtils.afterChange import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.tracker.DisplayMode +import at.hannibal2.skyhanni.utils.tracker.SharedTracker +import at.hannibal2.skyhanni.utils.tracker.TrackerUtils +import at.hannibal2.skyhanni.utils.tracker.TrackerUtils.addDisplayModeToggle +import at.hannibal2.skyhanni.utils.tracker.TrackerUtils.addSessionResetButton import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiInventory import net.minecraft.entity.boss.BossStatus import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.concurrent.fixedRateTimer -class PowderTracker { +object PowderTracker { private val config get() = SkyHanniMod.feature.mining.powderTracker private var display = emptyList<List<Any>>() @@ -42,7 +46,6 @@ class PowderTracker { private val chestInfo = ResourceInfo(0L, 0L, 0, 0.0, mutableListOf()) private var doublePowder = false private var powderTimer = "" - private var currentDisplayMode = DisplayMode.TOTAL private var inventoryOpen = false private var currentSessionData = mutableMapOf<Int, Storage.ProfileSpecific.PowderTracker>() private val gemstones = listOf( @@ -87,7 +90,7 @@ class PowderTracker { fun onChat(event: LorenzChatEvent) { if (!isEnabled()) return val msg = event.message - val both = currentLog() ?: return + val both = getSharedTracker() ?: return if (config.greatExplorerMaxed) { uncovered.matchMatcher(msg) { @@ -187,26 +190,25 @@ class PowderTracker { for (index in config.textFormat.get()) { add(map[index]) } + + if (inventoryOpen && TrackerUtils.currentDisplayMode == DisplayMode.CURRENT) { + addSessionResetButton("Powder Tracker", getSharedTracker()) { + saveAndUpdate() + } + } } private fun drawDisplay() = buildList<List<Any>> { addAsSingletonList("§b§lPowder Tracker") if (inventoryOpen) { - addSelector<DisplayMode>( - "§7Display Mode: ", - getName = { type -> type.displayName }, - isCurrent = { it == currentDisplayMode }, - onChange = { - currentDisplayMode = it - saveAndUpdate() - } - ) + addDisplayModeToggle { + saveAndUpdate() + } } else { addAsSingletonList("") } - val both = currentLog() ?: return@buildList - val display = both.get(currentDisplayMode) + val display = currentDisplay() ?: return@buildList val chestPerHour = format(chestInfo.perHour) addAsSingletonList("§d${display.totalChestPicked.addSeparators()} Total Chests Picked §7($chestPerHour/h)") @@ -262,13 +264,13 @@ class PowderTracker { val count = rewards.getOrDefault(reward, 0).addSeparators() addAsSingletonList("§b$count ${reward.displayName}") } - } private fun MutableList<List<Any>>.addPerHour( map: MutableMap<PowderChestReward, Long>, reward: PowderChestReward, - info: ResourceInfo) { + info: ResourceInfo + ) { val mithrilCount = map.getOrDefault(reward, 0).addSeparators() val mithrilPerHour = format(info.perHour) addAsSingletonList("§b$mithrilCount ${reward.displayName} §7($mithrilPerHour/h)") @@ -301,16 +303,14 @@ class PowderTracker { } private fun calculate(info: ResourceInfo, reward: PowderChestReward) { - val both = currentLog() ?: return - val display = both.get(currentDisplayMode) + val display = currentDisplay() ?: return val rewards = display.rewards info.estimated = 0 info.estimated += rewards.getOrDefault(reward, 0) } private fun calculateChest() { - val both = currentLog() ?: return - val display = both.get(currentDisplayMode) + val display = currentDisplay() ?: return chestInfo.estimated = 0 chestInfo.estimated += display.totalChestPicked } @@ -342,37 +342,23 @@ class PowderTracker { val perMin: MutableList<Long> ) - enum class DisplayMode(val displayName: String) { - TOTAL("Total"), - CURRENT("This Session"), - ; - } + private fun currentDisplay() = getSharedTracker()?.getCurrent() - private fun currentLog(): AbstractPowderTracker? { + private fun getSharedTracker(): SharedTracker<Storage.ProfileSpecific.PowderTracker>? { val profileSpecific = ProfileStorageData.profileSpecific ?: return null - return AbstractPowderTracker( + return SharedTracker( profileSpecific.powderTracker.getOrPut(0) { Storage.ProfileSpecific.PowderTracker() }, currentSessionData.getOrPut(0) { Storage.ProfileSpecific.PowderTracker() } ) } - class AbstractPowderTracker( - private val total: Storage.ProfileSpecific.PowderTracker, - private val currentSession: Storage.ProfileSpecific.PowderTracker, - ) { - - fun modify(modifyFunction: (Storage.ProfileSpecific.PowderTracker) -> Unit) { - modifyFunction(total) - modifyFunction(currentSession) - } + private fun isEnabled() = + LorenzUtils.inSkyBlock && LorenzUtils.skyBlockIsland == IslandType.CRYSTAL_HOLLOWS && config.enabled - fun get(displayMode: DisplayMode) = when (displayMode) { - DisplayMode.TOTAL -> total - DisplayMode.CURRENT -> currentSession + fun resetCommand(args: Array<String>) { + TrackerUtils.resetCommand("Powder Tracker", "shresetpowdertracker", args, getSharedTracker()) { + saveAndUpdate() } } - - private fun isEnabled() = - LorenzUtils.inSkyBlock && LorenzUtils.skyBlockIsland == IslandType.CRYSTAL_HOLLOWS && config.enabled } diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt index 2aebe7e57..71c990fc0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt @@ -33,6 +33,11 @@ import at.hannibal2.skyhanni.utils.StringUtils import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.jsonobjects.SlayerProfitTrackerItemsJson import at.hannibal2.skyhanni.utils.renderables.Renderable +import at.hannibal2.skyhanni.utils.tracker.DisplayMode +import at.hannibal2.skyhanni.utils.tracker.SharedTracker +import at.hannibal2.skyhanni.utils.tracker.TrackerUtils +import at.hannibal2.skyhanni.utils.tracker.TrackerUtils.addDisplayModeToggle +import at.hannibal2.skyhanni.utils.tracker.TrackerUtils.addSessionResetButton import com.google.common.cache.CacheBuilder import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiInventory @@ -53,12 +58,10 @@ object SlayerItemProfitTracker { private val logger = LorenzLogger("slayer/item_profit_tracker") private var inventoryOpen = false private var lastClickDelay = 0L - private var currentDisplayMode = DisplayMode.TOTAL private var currentSessionData = mutableMapOf<String, SlayerProfitList>() private fun addSlayerCosts(price: Int) { - val itemLog = currentLog() ?: return - itemLog.modify { + getSharedTracker()?.modify { it.slayerSpawnCost += price } update() @@ -94,18 +97,14 @@ object SlayerItemProfitTracker { } private fun addMobKillCoins(coins: Int) { - val itemLog = currentLog() ?: return - - itemLog.modify { + getSharedTracker()?.modify { it.mobKillCoins += coins } update() } private fun addItemPickup(internalName: NEUInternalName, stackSize: Int) { - val itemLog = currentLog() ?: return - - itemLog.modify { + getSharedTracker()?.modify { val slayerItemProfit = it.items.getOrPut(internalName) { SlayerProfitList.SlayerItemProfit() } slayerItemProfit.timesDropped++ @@ -115,12 +114,13 @@ object SlayerItemProfitTracker { update() } - private fun currentLog(): AbstractSlayerProfitList? { - if (itemLogCategory == "") return null + private fun currentDisplay() = getSharedTracker()?.getCurrent() + private fun getSharedTracker(): SharedTracker<SlayerProfitList>? { + if (itemLogCategory == "") return null val profileSpecific = ProfileStorageData.profileSpecific ?: return null - return AbstractSlayerProfitList( + return SharedTracker( profileSpecific.slayerProfitData.getOrPut(itemLogCategory) { SlayerProfitList() }, currentSessionData.getOrPut(itemLogCategory) { SlayerProfitList() } ) @@ -128,9 +128,7 @@ object SlayerItemProfitTracker { @SubscribeEvent fun onQuestComplete(event: SlayerQuestCompleteEvent) { - val itemLog = currentLog() ?: return - - itemLog.modify { + getSharedTracker()?.modify { it.slayerCompletedCount++ } @@ -202,20 +200,13 @@ object SlayerItemProfitTracker { } private fun drawDisplay() = buildList<List<Any>> { - val both = currentLog() ?: return@buildList - val itemLog = both.get(currentDisplayMode) + val itemLog = currentDisplay() ?: return@buildList addAsSingletonList("§e§l$itemLogCategory Profit Tracker") if (inventoryOpen) { - addSelector<DisplayMode>( - "§7Display Mode: ", - getName = { type -> type.displayName }, - isCurrent = { it == currentDisplayMode }, - onChange = { - currentDisplayMode = it - update() - } - ) + addDisplayModeToggle { + update() + } } var profit = 0.0 @@ -322,27 +313,13 @@ object SlayerItemProfitTracker { } ) } - if (inventoryOpen && currentDisplayMode == DisplayMode.CURRENT) { - addAsSingletonList( - Renderable.clickAndHover( - "§cReset session!", - listOf("§cThis will reset your", "§ccurrent session for", "§c$itemLogCategory"), - ) { - resetData(DisplayMode.CURRENT) - update() - }) + if (inventoryOpen && TrackerUtils.currentDisplayMode == DisplayMode.CURRENT) { + addSessionResetButton("$itemLogCategory Slayer", getSharedTracker()) { + update() + } } } - private fun resetData(displayMode: DisplayMode) { - val currentLog = currentLog() ?: return - val list = currentLog.get(displayMode) - list.items.clear() - list.mobKillCoins = 0 - list.slayerSpawnCost = 0 - list.slayerCompletedCount = 0 - } - private fun getPrice(internalName: NEUInternalName) = when (config.priceFrom) { 0 -> internalName.getBazaarData()?.sellPrice ?: internalName.getPriceOrNull() ?: 0.0 1 -> internalName.getBazaarData()?.buyPrice ?: internalName.getPriceOrNull() ?: 0.0 @@ -361,53 +338,22 @@ object SlayerItemProfitTracker { update() } - config.pos.renderStringsAndItems(display, posLabel = "Slayer Item Profit Tracker") } - enum class DisplayMode(val displayName: String) { - TOTAL("Total"), - CURRENT("This Session"), - ; - } - - class AbstractSlayerProfitList( - private val total: SlayerProfitList, - private val currentSession: SlayerProfitList, - ) { - - fun modify(modifyFunction: (SlayerProfitList) -> Unit) { - modifyFunction(total) - modifyFunction(currentSession) - } - - fun get(displayMode: DisplayMode) = when (displayMode) { - DisplayMode.TOTAL -> total - DisplayMode.CURRENT -> currentSession - } - } - fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled fun clearProfitCommand(args: Array<String>) { if (itemLogCategory == "") { LorenzUtils.chat( "§c[SkyHanni] No current slayer data found. " + - "Go to a slayer area and start the specific slayer type you want to reset the data of." + "Go to a slayer area and start the specific slayer type you want to reset the data of." ) return } - if (args.size == 1 && args[0].lowercase() == "confirm") { - resetData(DisplayMode.TOTAL) + TrackerUtils.resetCommand("$itemLogCategory Slayer", "shclearslayerprofits", args, getSharedTracker()) { update() - LorenzUtils.chat("§e[SkyHanni] You reset your $itemLogCategory slayer data!") - return } - - LorenzUtils.clickableChat( - "§e[SkyHanni] Are you sure you want to reset all your $itemLogCategory slayer data? Click here to confirm.", - "shclearslayerprofits confirm" - ) } } |