From 1c0cb4f9accae5072540ee032b411063c0393ee0 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:30:28 +0100 Subject: Fix: getting slayer spawn cost from bank (#1218) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../features/slayer/SlayerProfitTracker.kt | 26 +++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni') diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt index fefc5cf0c..9a709e43b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.data.SlayerAPI import at.hannibal2.skyhanni.data.jsonobjects.repo.SlayerProfitTrackerItemsJson import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.ItemAddEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.PurseChangeCause import at.hannibal2.skyhanni.events.PurseChangeEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent @@ -18,8 +19,11 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.NumberUtil.formatDouble +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.renderables.Renderable +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import at.hannibal2.skyhanni.utils.tracker.ItemTrackerData import at.hannibal2.skyhanni.utils.tracker.SkyHanniItemTracker import com.google.gson.JsonObject @@ -35,6 +39,14 @@ object SlayerProfitTracker { private var baseSlayerType = "" private val trackers = mutableMapOf>() + /** + * REGEX-TEST: §7Took 1.9k coins from your bank for auto-slayer... + */ + private val autoSlayerBankPattern by RepoPattern.pattern( + "slayer.autoslayer.bank.chat", + "§7Took (?.+) coins from your bank for auto-slayer\\.\\.\\." + ) + class Data : ItemTrackerData() { override fun resetItems() { @@ -71,9 +83,9 @@ object SlayerProfitTracker { private val ItemTrackerData.TrackedItem.timesDropped get() = timesGained - private fun addSlayerCosts(price: Int) { + private fun addSlayerCosts(price: Double) { getTracker()?.modify { - it.slayerSpawnCost += price + it.slayerSpawnCost += price.toInt() } } @@ -92,7 +104,15 @@ object SlayerProfitTracker { getTracker()?.addCoins(coins.toInt()) } if (event.reason == PurseChangeCause.LOSE_SLAYER_QUEST_STARTED) { - addSlayerCosts(coins.toInt()) + addSlayerCosts(coins) + } + } + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (!isEnabled()) return + autoSlayerBankPattern.matchMatcher(event.message) { + addSlayerCosts(group("coins").formatDouble()) } } -- cgit