aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt41
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/Storage.java31
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt6
-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.kt72
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt100
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/tracker/DisplayMode.kt7
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/tracker/SharedTracker.kt18
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerData.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerUtils.kt62
11 files changed, 296 insertions, 181 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index defde6616..93342d26f 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -141,7 +141,7 @@ import at.hannibal2.skyhanni.features.garden.contest.JacobContestTimeNeeded
import at.hannibal2.skyhanni.features.garden.contest.JacobFarmingContestsInventory
import at.hannibal2.skyhanni.features.garden.farming.CropMoneyDisplay
import at.hannibal2.skyhanni.features.garden.farming.CropSpeedMeter
-import at.hannibal2.skyhanni.features.garden.farming.DicerRngDropCounter
+import at.hannibal2.skyhanni.features.garden.farming.DicerDropTracker
import at.hannibal2.skyhanni.features.garden.farming.FarmingArmorDrops
import at.hannibal2.skyhanni.features.garden.farming.FarmingWeightDisplay
import at.hannibal2.skyhanni.features.garden.farming.GardenBurrowingSporesNotifier
@@ -500,7 +500,7 @@ class SkyHanniMod {
loadModule(GardenDeskInSBMenu())
loadModule(GardenLevelDisplay())
loadModule(FarmingWeightDisplay())
- loadModule(DicerRngDropCounter())
+ loadModule(DicerDropTracker)
loadModule(CropMoneyDisplay)
loadModule(JacobFarmingContestsInventory())
loadModule(GardenNextJacobContest)
@@ -605,7 +605,7 @@ class SkyHanniMod {
loadModule(GardenPlotBorders())
loadModule(CosmeticFollowingLine())
loadModule(SuperpairsClicksAlert())
- loadModule(PowderTracker())
+ loadModule(PowderTracker)
loadModule(ModifyVisualWords)
loadModule(TabListReader)
loadModule(TabListRenderer)
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt
index 69a77d6df..a290b9bf9 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt
@@ -9,7 +9,7 @@ import com.google.gson.JsonPrimitive
object ConfigUpdaterMigrator {
val logger = LorenzLogger("ConfigMigration")
- val configVersion = 6
+ val configVersion = 7
fun JsonElement.at(chain: List<String>, init: Boolean): JsonElement? {
if (chain.isEmpty()) return this
if (this !is JsonObject) return null
@@ -26,7 +26,14 @@ object ConfigUpdaterMigrator {
val new: JsonObject,
val oldVersion: Int,
var movesPerformed: Int,
+ val dynamicPrefix: Map<String, List<String>>,
) : LorenzEvent() {
+ init {
+ dynamicPrefix.entries.filter { it.value.isEmpty() }.forEach {
+ logger.log("Dynamic prefix ${it.key} does not resolve to anything.")
+ }
+ }
+
fun move(since: Int, oldPath: String, newPath: String, transform: (JsonElement) -> JsonElement = { it }) {
if (since <= oldVersion) {
logger.log("Skipping move from $oldPath to $newPath ($since <= $oldVersion)")
@@ -41,6 +48,22 @@ object ConfigUpdaterMigrator {
}
val op = oldPath.split(".")
val np = newPath.split(".")
+ if (op.first().startsWith("#")) {
+ require(np.first() == op.first())
+ val realPrefixes = dynamicPrefix[op.first()]
+ if (realPrefixes == null) {
+ logger.log("Could not resolve dynamic prefix $oldPath")
+ return
+ }
+ for (realPrefix in realPrefixes) {
+ move(
+ since,
+ "$realPrefix.${oldPath.substringAfter('.')}",
+ "$realPrefix.${newPath.substringAfter('.')}", transform
+ )
+ return
+ }
+ }
val oldElem = old.at(op, false)
if (oldElem == null) {
logger.log("Skipping move from $oldPath to $newPath ($oldPath not present)")
@@ -83,9 +106,23 @@ object ConfigUpdaterMigrator {
if (lV == configVersion) return config
return (lV until configVersion).fold(config) { acc, i ->
logger.log("Starting config transformation from $i to ${i + 1}")
+ val storage = acc.get("storage")?.asJsonObject
+ val dynamicPrefix: Map<String, List<String>> = mapOf(
+ "#profile" to
+ (storage?.get("players")?.asJsonObject?.entrySet()
+ ?.flatMap { player ->
+ player.value.asJsonObject.get("profiles")?.asJsonObject?.entrySet()?.map {
+ "storage.players.${player.key}.profiles.${it.key}"
+ } ?: listOf()
+ }
+ ?: listOf()),
+ "#player" to
+ (storage?.get("players")?.asJsonObject?.entrySet()?.map { "storage.players.${it.key}" }
+ ?: listOf()),
+ )
val migration = ConfigFixEvent(acc, JsonObject().also {
it.add("lastVersion", JsonPrimitive(i + 1))
- }, i, 0).also { it.postAndCatch() }
+ }, i, 0, dynamicPrefix).also { it.postAndCatch() }
logger.log("Transformations scheduled: ${migration.new}")
val mergesPerformed = merge(migration.old, migration.new)
logger.log("Migration done with $mergesPerformed merges and ${migration.movesPerformed} moves performed")
diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java
index ad17625fd..5c4ef3c63 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java
@@ -17,6 +17,7 @@ import at.hannibal2.skyhanni.features.misc.visualwords.VisualWord;
import at.hannibal2.skyhanni.features.rift.area.westvillage.KloonTerminal;
import at.hannibal2.skyhanni.utils.LorenzVec;
import at.hannibal2.skyhanni.utils.NEUInternalName;
+import at.hannibal2.skyhanni.utils.tracker.TrackerData;
import com.google.gson.annotations.Expose;
import net.minecraft.item.ItemStack;
@@ -143,7 +144,18 @@ public class Storage {
public CropAccessory savedCropAccessory = null;
@Expose
- public Map<String, Integer> dicerRngDrops = new HashMap<>();
+ public DicerDropTracker dicerDropTracker = new DicerDropTracker();
+
+ public static class DicerDropTracker extends TrackerData {
+
+ public void reset() {
+ drops.clear();
+ }
+
+ @Expose
+ public Map<CropType, Map<at.hannibal2.skyhanni.features.garden.farming.DicerDropTracker.DropRarity, Integer>> drops = new HashMap<>();
+
+ }
@Expose
public long informedAboutLowMatter = 0;
@@ -304,7 +316,13 @@ public class Storage {
@Expose
public Map<Integer, PowderTracker> powderTracker = new HashMap<>();
- public static class PowderTracker {
+ public static class PowderTracker extends TrackerData {
+
+ public void reset() {
+ rewards.clear();
+ totalChestPicked = 0;
+ }
+
@Expose
public int totalChestPicked = 0;
@@ -353,7 +371,14 @@ public class Storage {
@Expose
public Map<String, SlayerProfitList> slayerProfitData = new HashMap<>();
- public static class SlayerProfitList {
+ public static class SlayerProfitList extends TrackerData {
+
+ public void reset() {
+ items.clear();
+ mobKillCoins = 0;
+ slayerSpawnCost = 0;
+ slayerCompletedCount = 0;
+ }
@Expose
public Map<NEUInternalName, SlayerItemProfit> items = new HashMap<>();
diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
index cadd9fedc..c612a9742 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
@@ -20,11 +20,13 @@ import at.hannibal2.skyhanni.features.garden.GardenNextJacobContest
import at.hannibal2.skyhanni.features.garden.composter.ComposterOverlay
import at.hannibal2.skyhanni.features.garden.farming.CropMoneyDisplay
import at.hannibal2.skyhanni.features.garden.farming.CropSpeedMeter
+import at.hannibal2.skyhanni.features.garden.farming.DicerDropTracker
import at.hannibal2.skyhanni.features.garden.farming.FarmingWeightDisplay
import at.hannibal2.skyhanni.features.garden.farming.GardenStartLocation
import at.hannibal2.skyhanni.features.garden.fortuneguide.CaptureFarmingGear
import at.hannibal2.skyhanni.features.garden.fortuneguide.FFGuideGUI
import at.hannibal2.skyhanni.features.mining.KingTalismanHelper
+import at.hannibal2.skyhanni.features.mining.powdertracker.PowderTracker
import at.hannibal2.skyhanni.features.minion.MinionFeatures
import at.hannibal2.skyhanni.features.misc.CollectionTracker
import at.hannibal2.skyhanni.features.misc.LockMouseLook
@@ -158,7 +160,9 @@ object Commands {
"shclearfarmingitems",
"Clear farming items saved for the Farming Fortune Guide"
) { clearFarmingItems() }
- registerCommand("shresetghostcounter", "Resets the ghost counter stats") { GhostUtil.reset() }
+ registerCommand("shresetghostcounter", "Resets the ghost counter") { GhostUtil.reset() }
+ registerCommand("shresetpowdertracker", "Resets the powder tracker") { PowderTracker.resetCommand(it) }
+ registerCommand("shresetdicertracker", "Resets the dicer counter") { DicerDropTracker.resetCommand(it) }
registerCommand("shbingotoggle", "Toggle the bingo card display mode") { BingoCardDisplay.toggleCommand() }
registerCommand(
"shfarmingprofile",
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"
- )
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/DisplayMode.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/DisplayMode.kt
new file mode 100644
index 000000000..6c0e14439
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/DisplayMode.kt
@@ -0,0 +1,7 @@
+package at.hannibal2.skyhanni.utils.tracker
+
+enum class DisplayMode(val displayName: String) {
+ TOTAL("Total"),
+ CURRENT("This Session"),
+ ;
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SharedTracker.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SharedTracker.kt
new file mode 100644
index 000000000..341600467
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SharedTracker.kt
@@ -0,0 +1,18 @@
+package at.hannibal2.skyhanni.utils.tracker
+
+class SharedTracker<T : TrackerData>(
+ private val total: T,
+ private val currentSession: T,
+) {
+ fun modify(modifyFunction: (T) -> Unit) {
+ modifyFunction(total)
+ modifyFunction(currentSession)
+ }
+
+ fun get(displayMode: DisplayMode) = when (displayMode) {
+ DisplayMode.TOTAL -> total
+ DisplayMode.CURRENT -> currentSession
+ }
+
+ fun getCurrent() = get(TrackerUtils.currentDisplayMode)
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerData.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerData.kt
new file mode 100644
index 000000000..3c4a8bbd0
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerData.kt
@@ -0,0 +1,5 @@
+package at.hannibal2.skyhanni.utils.tracker
+
+abstract class TrackerData {
+ abstract fun reset()
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerUtils.kt
new file mode 100644
index 000000000..c223f17e7
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerUtils.kt
@@ -0,0 +1,62 @@
+package at.hannibal2.skyhanni.utils.tracker
+
+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.renderables.Renderable
+
+object TrackerUtils {
+ var currentDisplayMode = DisplayMode.TOTAL
+
+ fun MutableList<List<Any>>.addDisplayModeToggle(update: () -> Unit) {
+ addSelector<DisplayMode>(
+ "§7Display Mode: ",
+ getName = { type -> type.displayName },
+ isCurrent = { it == currentDisplayMode },
+ onChange = {
+ currentDisplayMode = it
+ update()
+ }
+ )
+ }
+
+ fun MutableList<List<Any>>.addSessionResetButton(name: String, data: SharedTracker<*>?, update: () -> Unit) {
+ addAsSingletonList(
+ Renderable.clickAndHover(
+ "§cReset session!",
+ listOf(
+ "§cThis will reset your",
+ "§ccurrent session for",
+ "§c$name"
+ ),
+ ) {
+ data?.get(DisplayMode.CURRENT)?.let {
+ reset(it) {
+ update()
+ }
+ }
+ })
+ }
+
+ fun resetCommand(name: String, command: String, args: Array<String>, data: SharedTracker<*>?, update: () -> Unit) {
+ if (args.size == 1 && args[0].lowercase() == "confirm") {
+ reset(data?.get(DisplayMode.TOTAL)) {
+ update()
+ LorenzUtils.chat("§e[SkyHanni] You reset your $name data!")
+ }
+ return
+ }
+
+ LorenzUtils.clickableChat(
+ "§e[SkyHanni] Are you sure you want to reset all your $name data? Click here to confirm.",
+ "$command confirm"
+ )
+ }
+
+ fun reset(data: TrackerData?, update: () -> Unit) {
+ data?.let {
+ it.reset()
+ update()
+ }
+ }
+}