aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-05-08 21:13:21 +0200
committerGitHub <noreply@github.com>2024-05-08 21:13:21 +0200
commit2d9844426886cd488703d05ee58558e05d4c3987 (patch)
tree8315b3b17945ff965af8a3aa8380458f39313fb0 /src/main/java/at/hannibal2/skyhanni/features
parent64ffd48ac791019ce4e4a610541b143a4c9d9b44 (diff)
downloadskyhanni-2d9844426886cd488703d05ee58558e05d4c3987.tar.gz
skyhanni-2d9844426886cd488703d05ee58558e05d4c3987.tar.bz2
skyhanni-2d9844426886cd488703d05ee58558e05d4c3987.zip
Feature: Profit per corpse loot (#1734)
Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilExcavatorAPI.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/mining/mineshaft/CorpeType.kt13
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/mining/mineshaft/CorpseAPI.kt85
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/mining/mineshaft/MineshaftCorpseProfitPer.kt54
5 files changed, 154 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilExcavatorAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilExcavatorAPI.kt
index def47812c..56b3242b9 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilExcavatorAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilExcavatorAPI.kt
@@ -113,7 +113,7 @@ object FossilExcavatorAPI {
} ?: return
// Workaround: If it is a enchanted book, we assume it is a paleontologist I book
if (pair.first.let { it == "§fEnchanted" || it == "§fEnchanted Book" }) {
- pair = "Paleontologist I" to pair.second
+ pair = "§9Paleontologist I" to pair.second
}
loot.add(pair)
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt
index 52b2f2447..74fb3be55 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt
@@ -27,7 +27,7 @@ class ProfitPerExcavation {
val pricePer = it.getPrice()
if (pricePer == -1.0) continue
val profit = amount * pricePer
- val text = "Found $name §8${amount.addSeparators()}x §7(§6${NumberUtil.format(profit)}§7)"
+ val text = "§eFound $name §8${amount.addSeparators()}x §7(§6${NumberUtil.format(profit)}§7)"
map[text] = profit
totalProfit += profit
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/mineshaft/CorpeType.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/mineshaft/CorpeType.kt
new file mode 100644
index 000000000..e2d385de5
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/mining/mineshaft/CorpeType.kt
@@ -0,0 +1,13 @@
+package at.hannibal2.skyhanni.features.mining.mineshaft
+
+import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
+
+enum class CorpeType(val displayName: String, private val keyName: String? = null) {
+ LAPIS("§9Lapis"),
+ TUNGSTEN("§7Tungsten", "TUNGSTEN_KEY"),
+ UMBER("§6Umber", "UMBER_KEY"),
+ VANGUARD("§fVanguard", "SKELETON_KEY"),
+ ;
+
+ val key by lazy { keyName?.asInternalName() }
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/mineshaft/CorpseAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/mineshaft/CorpseAPI.kt
new file mode 100644
index 000000000..db16e4d58
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/mining/mineshaft/CorpseAPI.kt
@@ -0,0 +1,85 @@
+package at.hannibal2.skyhanni.features.mining.mineshaft
+
+import at.hannibal2.skyhanni.data.IslandType
+import at.hannibal2.skyhanni.events.LorenzChatEvent
+import at.hannibal2.skyhanni.events.mining.CorpseLootedEvent
+import at.hannibal2.skyhanni.utils.ItemUtils
+import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.StringUtils.matches
+import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+class CorpseAPI {
+
+ private val patternGroup = RepoPattern.group("mining.mineshaft")
+ private val chatPatternGroup = patternGroup.group("chat")
+
+ /**
+ * REGEX-TEST: §r§b§l§r§9§lLAPIS §r§b§lCORPSE LOOT!
+ * REGEX-TEST: §r§b§l§r§7§lTUNGSTEN §r§b§lCORPSE LOOT!
+ * REGEX-TEST: §r§b§l§r§6§lUMBER §r§b§lCORPSE LOOT!
+ * REGEX-TEST: §r§b§l§r§f§lVANGUARD §r§b§lCORPSE LOOT!
+ */
+ private val startPattern by chatPatternGroup.pattern(
+ "start",
+ " {2}§r§b§l§r§(?<color>.)§l(?<name>.*) §r§b§lCORPSE LOOT! ?"
+ )
+
+ /**
+ * REGEX-TEST: §a§l▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
+ */
+ private val endPattern by chatPatternGroup.pattern("end", "§a§l▬{64}")
+
+ /**
+ * REGEX-TEST: §r§9☠ Fine Onyx Gemstone §r§8x2
+ */
+ private val itemPattern by chatPatternGroup.pattern("item", " {4}§r(?<item>.+)")
+
+ private var inLoot = false
+ private val loot = mutableListOf<Pair<String, Int>>()
+
+ private var corpeType: CorpeType? = null
+
+ @SubscribeEvent
+ fun onChat(event: LorenzChatEvent) {
+ if (!IslandType.MINESHAFT.isInIsland()) return
+
+ val message = event.message
+
+ startPattern.matchMatcher(message) {
+ inLoot = true
+ val name = group("name")
+ corpeType = CorpeType.valueOf(name)
+ return
+ }
+
+ if (!inLoot) return
+
+ if (endPattern.matches(message)) {
+ corpeType?.let {
+ CorpseLootedEvent(it, loot.toList()).postAndCatch()
+ }
+ corpeType = null
+ loot.clear()
+ inLoot = false
+ return
+ }
+ var pair = itemPattern.matchMatcher(message) {
+ /**
+ * TODO fix the bug that readItemAmount produces two different outputs:
+ * §r§fEnchanted Book -> §fEnchanted
+ * §fEnchanted Book §r§8x -> §fEnchanted Book
+ *
+ * also maybe this is no bug, as enchanted book is no real item?
+ */
+ ItemUtils.readItemAmount(group("item"))
+ } ?: return
+ // Workaround: If it is a enchanted book, we assume it is a paleontologist I book
+ if (pair.first.let { it == "§fEnchanted" || it == "§fEnchanted Book" }) {
+// pair = "Paleontologist I" to pair.second
+ pair = "§9Ice Cold I" to pair.second
+ }
+ loot.add(pair)
+ }
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/mineshaft/MineshaftCorpseProfitPer.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/mineshaft/MineshaftCorpseProfitPer.kt
new file mode 100644
index 000000000..d8dbe9e28
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/mining/mineshaft/MineshaftCorpseProfitPer.kt
@@ -0,0 +1,54 @@
+package at.hannibal2.skyhanni.features.mining.mineshaft
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.events.mining.CorpseLootedEvent
+import at.hannibal2.skyhanni.utils.ChatUtils
+import at.hannibal2.skyhanni.utils.CollectionUtils.sortedDesc
+import at.hannibal2.skyhanni.utils.ItemUtils.itemName
+import at.hannibal2.skyhanni.utils.NEUInternalName
+import at.hannibal2.skyhanni.utils.NEUItems.getPrice
+import at.hannibal2.skyhanni.utils.NumberUtil
+import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+class MineshaftCorpseProfitPer {
+ private val config get() = SkyHanniMod.feature.mining.mineshaft
+
+ @SubscribeEvent
+ fun onFossilExcavation(event: CorpseLootedEvent) {
+ if (!config.profitPerCorpseLoot) return
+ val loot = event.loot
+
+ var totalProfit = 0.0
+ val map = mutableMapOf<String, Double>()
+ for ((name, amount) in loot) {
+ if (name == "§bGlacite Powder") continue
+ NEUInternalName.fromItemNameOrNull(name)?.let {
+ val pricePer = it.getPrice()
+ if (pricePer == -1.0) continue
+ val profit = amount * pricePer
+ val text = "§eFound $name §8${amount.addSeparators()}x §7(§6${NumberUtil.format(profit)}§7)"
+ map[text] = profit
+ totalProfit += profit
+ }
+ }
+
+ val corpseType = event.corpseType
+ val name = corpseType.displayName
+
+ corpseType.key?.let {
+ val keyName = it.itemName
+ val price = it.getPrice()
+
+ map["$keyName: §c-${NumberUtil.format(price)}"] = -price
+ totalProfit -= price
+ }
+
+ val hover = map.sortedDesc().keys.toMutableList()
+ val profitPrefix = if (totalProfit < 0) "§c" else "§6"
+ val totalMessage = "Profit for $name Corpse§e: $profitPrefix${NumberUtil.format(totalProfit)}"
+ hover.add("")
+ hover.add("§e$totalMessage")
+ ChatUtils.hoverableChat(totalMessage, hover)
+ }
+}