blob: 4521aa2b90d2081fce4e59e30c774c51738f091a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
package at.hannibal2.skyhanni.features.dungeon
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.LorenzToolTipEvent
import at.hannibal2.skyhanni.events.RenderItemTipEvent
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.InventoryUtils.getInventoryName
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.inventory.ContainerChest
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class DungeonFinderFeatures {
private val config get() = SkyHanniMod.feature.dungeon.partyFinder
private val pricePattern = "([0-9]{2,3}K|[0-9]{1,3}M|[0-9]+\\.[0-9]M|[0-9] ?mil)".toRegex(RegexOption.IGNORE_CASE)
private val carryPattern = "(carry|cary|carries|caries|comp|to cata [0-9]{2})".toRegex(RegexOption.IGNORE_CASE)
private val nonPugPattern = "(perm|vc|discord)".toRegex(RegexOption.IGNORE_CASE)
private val memberPattern = "^ §.*?§.: §.([A-Z]+)§. \\(§.([0-9]+)§.\\)".toRegex(RegexOption.IGNORE_CASE)
private val ineligiblePattern =
"^§c(Requires .*$|You don't meet the requirement!|Complete previous floor first!$)".toRegex()
private val classLevelPattern = " §.(?<playerName>.*)§f: §e(?<className>.*)§b \\(§e(?<level>.*)§b\\)".toPattern()
private val notePattern = "^(§7§7Note: |§f[^§])".toRegex()
private var selectedClass = ""
@SubscribeEvent
fun onRenderItemTip(event: RenderItemTipEvent) {
if (!LorenzUtils.inSkyBlock || LorenzUtils.skyBlockArea != "Dungeon Hub") return
if (!config.floorAsStackSize) return
val itemName = event.stack.name?.removeColor() ?: ""
val invName = InventoryUtils.openInventoryName()
if (invName == "Select Floor") {
if (itemName == "Any") {
event.stackTip = "A"
} else if (itemName == "Entrance") {
event.stackTip = "E"
} else if (itemName.startsWith("Floor ")) {
event.stackTip = itemName.split(' ').last().romanToDecimalIfNecessary().toString()
}
} else if (itemName.startsWith("The Catacombs - ") || itemName.startsWith("MM Catacombs -")) {
val floor = itemName.split(" - ").last().removeColor()
val floorNum = floor.split(' ').last().romanToDecimalIfNecessary().toString()
val isMasterMode = itemName.contains("MM ")
event.stackTip = if (floor.contains("Entrance")) {
"E"
} else if (isMasterMode) {
"M${floorNum}"
} else {
"F${floorNum}"
}
} else if (itemName.endsWith("'s Party")) {
val floor = event.stack.getLore().find { it.startsWith("§7Floor: ") } ?: return
val dungeon = event.stack.getLore().find { it.startsWith("§7Dungeon: ") } ?: return
val floorNum = floor.split(' ').last().romanToDecimalIfNecessary().toString()
val isMasterMode = dungeon.contains("Master Mode")
event.stackTip = if (floor.contains("Entrance")) {
"E"
} else if (isMasterMode) {
"M${floorNum}"
} else {
"F${floorNum}"
}
}
}
@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
if (!LorenzUtils.inSkyBlock || LorenzUtils.skyBlockArea != "Dungeon Hub") return
if (event.inventoryName != "Catacombs Gate") return
val lore = event.inventoryItems[45]?.getLore() ?: return
if (lore[0] == "§7View and select a dungeon class.") {
selectedClass = lore[2].split(" ").last().removeColor()
}
}
@SubscribeEvent
fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) {
if (!LorenzUtils.inSkyBlock) return
if (event.gui !is GuiChest) return
val chest = event.gui.inventorySlots as ContainerChest
val inventoryName = chest.getInventoryName()
if (inventoryName != "Party Finder") return
for (slot in chest.inventorySlots) {
if (slot == null) continue
if (slot.slotNumber != slot.slotIndex) continue
if (slot.stack == null) continue
val itemName = slot.stack.name ?: continue
if (!itemName.endsWith(" Party")) continue
if (config.markIneligibleGroups && slot.stack.getLore().any { ineligiblePattern.matches(it) }) {
slot highlight LorenzColor.DARK_RED
continue
}
if (config.markPaidCarries) {
val note = slot.stack.getLore().filter { notePattern.containsMatchIn(it) }.joinToString(" ")
if (pricePattern.containsMatchIn(note) && carryPattern.containsMatchIn(note)) {
slot highlight LorenzColor.RED
continue
}
}
if (config.markNonPugs) {
val note = slot.stack.getLore().filter { notePattern.containsMatchIn(it) }.joinToString(" ")
if (nonPugPattern.containsMatchIn(note)) {
slot highlight LorenzColor.LIGHT_PURPLE
continue
}
}
val members = slot.stack.getLore().filter { memberPattern.matches(it) }
val memberLevels = members.map { memberPattern.matchEntire(it)?.groupValues?.get(2)?.toInt() ?: 0 }
val memberClasses = members.map { memberPattern.matchEntire(it)?.groupValues?.get(1) ?: "" }
if (memberLevels.any { it <= config.markBelowClassLevel }) {
slot highlight LorenzColor.YELLOW
continue
}
if (config.markMissingClass && memberClasses.none { it == selectedClass }) {
slot highlight LorenzColor.GREEN
}
}
}
@SubscribeEvent
fun onItemTooltip(event: LorenzToolTipEvent) {
if (!LorenzUtils.inSkyBlock) return
if (!config.coloredClassLevel) return
val chestName = InventoryUtils.openInventoryName()
if (chestName != "Party Finder") return
val stack = event.itemStack
for ((index, line) in stack.getLore().withIndex()) {
classLevelPattern.matchMatcher(line) {
val playerName = group("playerName")
val className = group("className")
val level = group("level").toInt()
val color = getColor(level)
event.toolTip[index + 1] = " §b$playerName§f: §e$className $color$level"
}
}
}
@SubscribeEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.move(2, "dungeon.partyFinderColoredClassLevel", "dungeon.partyFinder.coloredClassLevel")
}
}
fun getColor(level: Int): String {
if (level >= 50) return "§c§l"
if (level >= 45) return "§c"
if (level >= 40) return "§d"
if (level >= 35) return "§6"
if (level >= 30) return "§5"
if (level >= 25) return "§9"
if (level >= 20) return "§a"
if (level >= 10) return "§f"
return "§7"
}
|