aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-07 21:50:26 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-07 21:50:26 +0100
commitbc27a67c4495c8e4a37f559e1224ebfc0d649e80 (patch)
tree99af830b9b78bd9ce3b0f4332c0bf824390629dd /src
parent5b7b2203c4ddeb1c9d40aff578cfab61df87d293 (diff)
downloadskyhanni-bc27a67c4495c8e4a37f559e1224ebfc0d649e80.tar.gz
skyhanni-bc27a67c4495c8e4a37f559e1224ebfc0d649e80.tar.bz2
skyhanni-bc27a67c4495c8e4a37f559e1224ebfc0d649e80.zip
Used SkyHanniTracker in SlayerItemProfitTracker
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/Storage.java57
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt132
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt3
4 files changed, 88 insertions, 108 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java
index 247792fb4..edab10936 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java
@@ -16,9 +16,9 @@ import at.hannibal2.skyhanni.features.mining.powdertracker.PowderTracker;
import at.hannibal2.skyhanni.features.misc.trevor.TrevorTracker;
import at.hannibal2.skyhanni.features.misc.visualwords.VisualWord;
import at.hannibal2.skyhanni.features.rift.area.westvillage.KloonTerminal;
+import at.hannibal2.skyhanni.features.slayer.SlayerItemProfitTracker;
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;
@@ -345,60 +345,7 @@ public class Storage {
}
@Expose
- public Map<String, SlayerProfitList> slayerProfitData = new HashMap<>();
-
- 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<>();
-
- @Expose
- public long mobKillCoins = 0;
-
- @Expose
- public long slayerSpawnCost = 0;
-
- @Expose
- public int slayerCompletedCount = 0;
-
- public static class SlayerItemProfit {
- @Expose
- public NEUInternalName internalName;
- @Expose
- public long timesDropped;
- @Expose
- public long totalAmount;
- @Expose
- public boolean hidden;
-
- @Override
- public String toString() {
- return "SlayerItemProfit{" +
- "internalName='" + internalName + '\'' +
- ", timesDropped=" + timesDropped +
- ", totalAmount=" + totalAmount +
- ", hidden=" + hidden +
- '}';
- }
- }
-
- @Override
- public String toString() {
- return "SlayerProfitList{" +
- "items=" + items +
- ", mobKillCoins=" + mobKillCoins +
- ", slayerSpawnCost=" + slayerSpawnCost +
- ", slayerCompletedCount=" + slayerCompletedCount +
- '}';
- }
- }
+ public Map<String, SlayerItemProfitTracker.Data> slayerProfitData = new HashMap<>();
@Expose
public Map<String, SlayerRngMeterStorage> slayerRngMeter = new HashMap<>();
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 f5c56cc9a..2f1999ea2 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
@@ -198,6 +198,10 @@ object PowderTracker {
addAsSingletonList("§b§lPowder Tracker")
tracker.addDisplayModeToggle(this, closedText = "")
+ if (!tracker.isInventoryOpen()) {
+ addAsSingletonList("")
+ }
+
val display = tracker.currentDisplay() ?: return@buildList
val chestPerHour = format(chestInfo.perHour)
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 71c990fc0..7c5cb5b6c 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt
@@ -1,8 +1,7 @@
package at.hannibal2.skyhanni.features.slayer
import at.hannibal2.skyhanni.SkyHanniMod
-import at.hannibal2.skyhanni.config.Storage.ProfileSpecific.SlayerProfitList
-import at.hannibal2.skyhanni.data.ProfileStorageData
+import at.hannibal2.skyhanni.config.Storage
import at.hannibal2.skyhanni.data.SlayerAPI
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.PacketEvent
@@ -28,19 +27,14 @@ import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull
import at.hannibal2.skyhanni.utils.NEUItems.getPriceOrNull
import at.hannibal2.skyhanni.utils.NumberUtil
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
-import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
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 at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker
+import at.hannibal2.skyhanni.utils.tracker.TrackerData
import com.google.common.cache.CacheBuilder
-import net.minecraft.client.Minecraft
-import net.minecraft.client.gui.inventory.GuiInventory
+import com.google.gson.annotations.Expose
import net.minecraft.entity.item.EntityItem
import net.minecraft.network.play.server.S0DPacketCollectItem
import net.minecraftforge.fml.common.eventhandler.EventPriority
@@ -55,13 +49,61 @@ object SlayerItemProfitTracker {
private var itemLogCategory = ""
private var baseSlayerType = ""
private var display = emptyList<List<Any>>()
- private val logger = LorenzLogger("slayer/item_profit_tracker")
- private var inventoryOpen = false
+ private val logger = LorenzLogger("slayer/profit_tracker")
private var lastClickDelay = 0L
- private var currentSessionData = mutableMapOf<String, SlayerProfitList>()
+ private val trackers = mutableMapOf<String, SkyHanniTracker<Data>>()
+
+ class Data : TrackerData() {
+ override fun reset() {
+ items.clear()
+ mobKillCoins = 0
+ slayerSpawnCost = 0
+ slayerCompletedCount = 0
+ }
+
+ @Expose
+ var items: MutableMap<NEUInternalName, SlayerItemProfit> = HashMap()
+
+ @Expose
+ var mobKillCoins: Long = 0
+
+ @Expose
+ var slayerSpawnCost: Long = 0
+
+ @Expose
+ var slayerCompletedCount = 0
+
+ class SlayerItemProfit {
+ @Expose
+ var internalName: NEUInternalName? = null
+
+ @Expose
+ var timesDropped: Long = 0
+
+ @Expose
+ var totalAmount: Long = 0
+
+ @Expose
+ var hidden = false
+
+ override fun toString() = "SlayerItemProfit{" +
+ "internalName='" + internalName + '\'' +
+ ", timesDropped=" + timesDropped +
+ ", totalAmount=" + totalAmount +
+ ", hidden=" + hidden +
+ '}'
+ }
+
+ override fun toString() = "SlayerProfitList{" +
+ "items=" + items +
+ ", mobKillCoins=" + mobKillCoins +
+ ", slayerSpawnCost=" + slayerSpawnCost +
+ ", slayerCompletedCount=" + slayerCompletedCount +
+ '}'
+ }
private fun addSlayerCosts(price: Int) {
- getSharedTracker()?.modify {
+ getTracker()?.modify {
it.slayerSpawnCost += price
}
update()
@@ -97,15 +139,15 @@ object SlayerItemProfitTracker {
}
private fun addMobKillCoins(coins: Int) {
- getSharedTracker()?.modify {
+ getTracker()?.modify {
it.mobKillCoins += coins
}
update()
}
private fun addItemPickup(internalName: NEUInternalName, stackSize: Int) {
- getSharedTracker()?.modify {
- val slayerItemProfit = it.items.getOrPut(internalName) { SlayerProfitList.SlayerItemProfit() }
+ getTracker()?.modify {
+ val slayerItemProfit = it.items.getOrPut(internalName) { Data.SlayerItemProfit() }
slayerItemProfit.timesDropped++
slayerItemProfit.totalAmount += stackSize
@@ -114,21 +156,22 @@ object SlayerItemProfitTracker {
update()
}
- private fun currentDisplay() = getSharedTracker()?.getCurrent()
-
- private fun getSharedTracker(): SharedTracker<SlayerProfitList>? {
+ private fun getTracker(): SkyHanniTracker<Data>? {
if (itemLogCategory == "") return null
- val profileSpecific = ProfileStorageData.profileSpecific ?: return null
- return SharedTracker(
- profileSpecific.slayerProfitData.getOrPut(itemLogCategory) { SlayerProfitList() },
- currentSessionData.getOrPut(itemLogCategory) { SlayerProfitList() }
- )
+ return trackers.getOrPut(itemLogCategory) {
+ val getStorage: (Storage.ProfileSpecific) -> Data = {
+ it.slayerProfitData.getOrPut(
+ itemLogCategory
+ ) { Data() }
+ }
+ SkyHanniTracker("$itemLogCategory Profit Tracker", Data(), getStorage) { update() }
+ }
}
@SubscribeEvent
fun onQuestComplete(event: SlayerQuestCompleteEvent) {
- getSharedTracker()?.modify {
+ getTracker()?.modify {
it.slayerCompletedCount++
}
@@ -196,18 +239,15 @@ object SlayerItemProfitTracker {
}
fun update() {
- display = drawDisplay()
+ val tracker = getTracker() ?: return
+ display = drawDisplay(tracker)
}
- private fun drawDisplay() = buildList<List<Any>> {
- val itemLog = currentDisplay() ?: return@buildList
+ private fun drawDisplay(tracker: SkyHanniTracker<Data>) = buildList<List<Any>> {
+ val itemLog = tracker.currentDisplay() ?: return@buildList
addAsSingletonList("§e§l$itemLogCategory Profit Tracker")
- if (inventoryOpen) {
- addDisplayModeToggle {
- update()
- }
- }
+ tracker.addDisplayModeToggle(this)
var profit = 0.0
val map = mutableMapOf<Renderable, Long>()
@@ -232,7 +272,7 @@ object SlayerItemProfitTracker {
val percentage = timesDropped.toDouble() / itemLog.slayerCompletedCount
val perBoss = LorenzUtils.formatPercentage(percentage.coerceAtMost(1.0))
- val renderable = if (inventoryOpen) Renderable.clickAndHover(
+ val renderable = if (tracker.isInventoryOpen()) Renderable.clickAndHover(
text, listOf(
"§7Dropped §e${timesDropped.addSeparators()} §7times.",
"§7Your drop rate: §c$perBoss",
@@ -254,7 +294,7 @@ object SlayerItemProfitTracker {
update()
}
} else Renderable.string(text)
- if (inventoryOpen || !hidden) {
+ if (tracker.isInventoryOpen() || !hidden) {
map[renderable] = price
}
profit += price
@@ -302,7 +342,7 @@ object SlayerItemProfitTracker {
val text = "§eTotal Profit: $profitPrefix$profitFormat"
addAsSingletonList(Renderable.hoverTips(text, listOf("§7Profit per boss: $profitPrefix$profitPerBossFormat")))
- if (inventoryOpen) {
+ if (tracker.isInventoryOpen()) {
addSelector<PriceSource>(
"",
getName = { type -> type.displayName },
@@ -313,11 +353,7 @@ object SlayerItemProfitTracker {
}
)
}
- if (inventoryOpen && TrackerUtils.currentDisplayMode == DisplayMode.CURRENT) {
- addSessionResetButton("$itemLogCategory Slayer", getSharedTracker()) {
- update()
- }
- }
+ tracker.addSessionResetButton(this)
}
private fun getPrice(internalName: NEUInternalName) = when (config.priceFrom) {
@@ -332,13 +368,7 @@ object SlayerItemProfitTracker {
if (!isEnabled()) return
if (!SlayerAPI.isInCorrectArea) return
- val currentlyOpen = Minecraft.getMinecraft().currentScreen is GuiInventory
- if (inventoryOpen != currentlyOpen) {
- inventoryOpen = currentlyOpen
- update()
- }
-
- config.pos.renderStringsAndItems(display, posLabel = "Slayer Item Profit Tracker")
+ getTracker()?.renderDisplay(config.pos, display)
}
fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled
@@ -352,8 +382,6 @@ object SlayerItemProfitTracker {
return
}
- TrackerUtils.resetCommand("$itemLogCategory Slayer", "shclearslayerprofits", args, getSharedTracker()) {
- update()
- }
+ getTracker()?.resetCommand(args, "shclearslayerprofits")
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt
index a63a47706..4d7b74243 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt
@@ -16,9 +16,10 @@ class SkyHanniTracker<Data : TrackerData>(
private val getStorage: (Storage.ProfileSpecific) -> Data,
private val update: () -> Unit,
) {
-
private var inventoryOpen = false
+ fun isInventoryOpen() = inventoryOpen
+
private fun getSharedTracker(): SharedTracker<Data>? {
val profileSpecific = ProfileStorageData.profileSpecific ?: return null
return SharedTracker(getStorage(profileSpecific), currentSessionData)