-
-
Notifications
You must be signed in to change notification settings - Fork 217
/
Copy pathSkillTooltip.kt
95 lines (87 loc) · 4.86 KB
/
SkillTooltip.kt
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
package at.hannibal2.skyhanni.features.skillprogress
import at.hannibal2.skyhanni.api.SkillAPI
import at.hannibal2.skyhanni.api.SkillAPI.excludedSkills
import at.hannibal2.skyhanni.events.LorenzToolTipEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.cleanName
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.roundTo
import at.hannibal2.skyhanni.utils.NumberUtil.toRoman
import at.hannibal2.skyhanni.utils.StringUtils
import at.hannibal2.skyhanni.utils.StringUtils.isRoman
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@SkyHanniModule
object SkillTooltip {
private val overflowConfig get() = SkillProgress.config.overflowConfig
private val customGoalConfig get() = SkillProgress.config.customGoalConfig
@SubscribeEvent
fun onTooltip(event: LorenzToolTipEvent) {
if (!LorenzUtils.inSkyBlock) return
val inventoryName = InventoryUtils.openInventoryName()
val stack = event.itemStack
if (inventoryName == "Your Skills" && stack.getLore().any { it.contains("Click to view!") }) {
val iterator = event.toolTip.listIterator()
val split = stack.cleanName().split(" ")
val skillName = split.first()
val skill = SkillType.getByNameOrNull(skillName) ?: return
val useRoman = split.last().isRoman()
val skillInfo = SkillAPI.storage?.get(skill) ?: return
val showCustomGoal = skillInfo.customGoalLevel != 0 && customGoalConfig.enableInSkillMenuTooltip
var next = false
for (line in iterator) {
val maxReached = "§7§8Max Skill level reached!"
if (line.contains(maxReached) && overflowConfig.enableInSkillMenuTooltip) {
val progress = (skillInfo.overflowCurrentXp.toDouble() / skillInfo.overflowCurrentXpMax) * 100
val percent = "§e${progress.roundTo(1)}%"
val currentLevel = skillInfo.overflowLevel
val level = if (useRoman) currentLevel.toRoman() else currentLevel
val nextLevel = if (useRoman) (currentLevel + 1).toRoman() else currentLevel + 1
iterator.set("§7Progress to Level $nextLevel: $percent")
event.itemStack.name = "§a${skill.displayName} $level"
next = true
continue
}
val bar = " "
if (next && overflowConfig.enableInSkillMenuTooltip) {
if (line.contains(bar)) {
val progress = (skillInfo.overflowCurrentXp.toDouble() / skillInfo.overflowCurrentXpMax)
val progressBar = StringUtils.progressBar(progress)
iterator.set(
"$progressBar §e${skillInfo.overflowCurrentXp.addSeparators()}§6/" +
"§e${skillInfo.overflowCurrentXpMax.addSeparators()}"
)
iterator.add("")
}
}
if ((line.contains(bar) || line.contains("/")) && showCustomGoal) {
val targetLevel = skillInfo.customGoalLevel
var have = skillInfo.overflowTotalXp
val need = SkillUtil.xpRequiredForLevel(targetLevel.toDouble())
val xpFor50 = SkillUtil.xpRequiredForLevel(50.0)
val xpFor60 = SkillUtil.xpRequiredForLevel(60.0)
have += if (skillInfo.overflowLevel >= 60 && skill in excludedSkills || skillInfo.overflowLevel in 50..59) xpFor50
else if (skillInfo.overflowLevel >= 60 && skill !in excludedSkills) xpFor60
else 0
val progress = have.toDouble() / need
val progressBar = StringUtils.progressBar(progress)
val nextLevel = if (useRoman) targetLevel.toRoman() else targetLevel
val percent = "§e${(progress * 100).roundTo(1)}%"
iterator.add("")
iterator.add("§7Progress to Level $nextLevel: $percent")
iterator.add("$progressBar §e${have.addSeparators()}§6/§e${need.addSeparators()}")
iterator.add("")
}
if (next && overflowConfig.enableInSkillMenuTooltip) {
if (line.contains(bar)) {
iterator.add("§b§lOVERFLOW XP:")
iterator.add("§7▸ ${skillInfo.overflowTotalXp.addSeparators()}")
}
}
}
}
}
}