aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
authorHiZe <super@hize.be>2024-05-31 01:35:19 +0200
committerGitHub <noreply@github.com>2024-05-31 01:35:19 +0200
commit2e44956441fd8a589993360ed66f18ef950cb49a (patch)
tree8a66397555b119ee7ba8668989dfa2b0ae66e990 /src/main/java/at/hannibal2/skyhanni
parent23ce43b83c5707f07952327a2fcc21fe01e8db46 (diff)
downloadskyhanni-2e44956441fd8a589993360ed66f18ef950cb49a.tar.gz
skyhanni-2e44956441fd8a589993360ed66f18ef950cb49a.tar.bz2
skyhanni-2e44956441fd8a589993360ed66f18ef950cb49a.zip
Backend: Use SkillAPI in SkillExpGainEvent (#1788)
Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt96
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt11
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/SkillExpGainEvent.kt4
3 files changed, 67 insertions, 44 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
index e5c9067cd..842b9ec84 100644
--- a/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
@@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.events.DebugDataCollectEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.NeuRepositoryReloadEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
+import at.hannibal2.skyhanni.events.SkillExpGainEvent
import at.hannibal2.skyhanni.events.SkillOverflowLevelupEvent
import at.hannibal2.skyhanni.features.skillprogress.SkillProgress
import at.hannibal2.skyhanni.features.skillprogress.SkillType
@@ -27,6 +28,7 @@ import at.hannibal2.skyhanni.utils.NumberUtil.formatLong
import at.hannibal2.skyhanni.utils.NumberUtil.formatLongOrUserError
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary
import at.hannibal2.skyhanni.utils.SimpleTimeMark
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.TabListData
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
@@ -53,11 +55,15 @@ object SkillAPI {
)
private val skillTabPattern by patternGroup.pattern(
"skill.tab",
- "(?:§e§lSkills: §r§a)?\\s*(?<type>\\w+) (?<level>\\d+): §r§.(?<progress>.+)%$"
+ " (?<type>\\w+)(?: (?<level>\\d+))?: §r§a(?<progress>[0-9.]+)%"
)
private val maxSkillTabPattern by patternGroup.pattern(
"skill.tab.max",
- "(?:§e§lSkills: §r§a)?\\s*(?<type>\\w+) (?<level>\\d+): §r§c§lMAX\$"
+ " (?<type>\\w+) (?<level>\\d+): §r§c§lMAX"
+ )
+ private val skillTabNoPercentPattern by patternGroup.pattern(
+ "skill.tab.nopercent",
+ " §r§a(?<type>\\w+)(?: (?<level>\\d+))?: §r§e(?<current>[0-9,.]+)§r§6/§r§e(?<needed>[0-9kmb]+)"
)
var skillXPInfoMap = mutableMapOf<SkillType, SkillXPInfo>()
@@ -120,6 +126,9 @@ object SkillAPI {
skillPercentPattern -> handleSkillPatternPercent(matcher, skillType)
skillMultiplierPattern -> handleSkillPatternMultiplier(matcher, skillType, skillInfo)
}
+
+ SkillExpGainEvent(skillType, matcher.group("gained").formatDouble()).postAndCatch()
+
showDisplay = true
lastUpdate = SimpleTimeMark.now()
skillXp.lastUpdate = SimpleTimeMark.now()
@@ -274,48 +283,71 @@ object SkillAPI {
}
private fun handleSkillPatternPercent(matcher: Matcher, skillType: SkillType) {
- var tablistLevel = 0
+ var current = 0L
+ var needed = 0L
+ var xpPercentage = 0.0
+ var isPercentPatternFound = false
+ var tablistLevel: Int? = null
+
for (line in TabListData.getTabList()) {
- var levelMatcher = skillTabPattern.matcher(line)
- if (levelMatcher.matches()) {
- val type = levelMatcher.group("type")
- if (type != skillType.displayName) continue
- tablistLevel = levelMatcher.group("level").toInt()
- if (levelMatcher.group("type").lowercase() != activeSkill?.lowercaseName) tablistLevel = 0
- } else {
- levelMatcher = maxSkillTabPattern.matcher(line)
- if (levelMatcher.matches()) {
- tablistLevel = levelMatcher.group("level").toInt()
- if (levelMatcher.group("type").lowercase() != activeSkill?.lowercaseName) tablistLevel = 0
+ skillTabPattern.matchMatcher(line) {
+ if (group("type") == skillType.displayName) {
+ tablistLevel = group("level").toInt()
+ isPercentPatternFound = true
+ if (group("type").lowercase() != activeSkill?.lowercaseName) tablistLevel = null
+ }
+ }
+
+ maxSkillTabPattern.matchMatcher(line) {
+ tablistLevel = group("level").toInt()
+ if (group("type").lowercase() != activeSkill?.lowercaseName) tablistLevel = null
+ }
+
+ skillTabNoPercentPattern.matchMatcher(line) {
+ if (group("type") == skillType.displayName) {
+ tablistLevel = group("level").toInt()
+ current = group("current").formatLong()
+ needed = group("needed").formatLong()
+ isPercentPatternFound = false
+ return@matchMatcher
}
}
+ xpPercentage = matcher.group("progress").formatDouble()
}
+
val existingLevel = getSkillInfo(skillType) ?: SkillInfo()
- val xpPercentage = matcher.group("progress").formatDouble()
- val levelXp = calculateLevelXp(existingLevel.level - 1)
- val nextLevelDiff = levelArray.getOrNull(tablistLevel)?.toDouble() ?: 7_600_000.0
- val nextLevelProgress = nextLevelDiff * xpPercentage / 100
- val totalXp = levelXp + nextLevelProgress
- val (_, currentOverflow, currentMaxOverflow, totalOverflow) = getSkillInfo(
- tablistLevel,
- nextLevelProgress.toLong(),
- nextLevelDiff.toLong(),
- totalXp.toLong()
- )
+ tablistLevel?.let { level ->
+ if (isPercentPatternFound) {
+ val levelXp = calculateLevelXp(existingLevel.level - 1)
+ val nextLevelDiff = levelArray.getOrNull(level)?.toDouble() ?: 7_600_000.0
+ val nextLevelProgress = nextLevelDiff * xpPercentage / 100
+ val totalXp = levelXp + nextLevelProgress
+ updateSkillInfo(existingLevel, level, nextLevelProgress.toLong(), nextLevelDiff.toLong(), totalXp.toLong(), matcher.group("gained"))
+ } else {
+ val exactLevel = getLevelExact(needed)
+ val levelXp = calculateLevelXp(existingLevel.level - 1).toLong() + current
+ updateSkillInfo(existingLevel, exactLevel, current, needed, levelXp, matcher.group("gained"))
+ }
+ storage?.set(skillType, existingLevel)
+ }
+ }
+
+ private fun updateSkillInfo(existingLevel: SkillInfo, level: Int, currentXp: Long, maxXp: Long, totalXp: Long, gained: String) {
+ val (levelOverflow, currentOverflow, currentMaxOverflow, totalOverflow) = getSkillInfo(level, currentXp, maxXp, totalXp)
+
existingLevel.apply {
- this.totalXp = totalXp.toLong()
- this.currentXp = nextLevelProgress.toLong()
- this.currentXpMax = nextLevelDiff.toLong()
- this.level = tablistLevel
+ this.totalXp = totalXp
+ this.currentXp = currentXp
+ this.currentXpMax = maxXp
+ this.level = level
this.overflowTotalXp = totalOverflow
this.overflowCurrentXp = currentOverflow
this.overflowCurrentXpMax = currentMaxOverflow
- this.overflowLevel = tablistLevel
+ this.overflowLevel = levelOverflow
- this.lastGain = matcher.group("gained")
+ this.lastGain = gained
}
- storage?.set(skillType, existingLevel)
}
private fun handleSkillPatternMultiplier(matcher: Matcher, skillType: SkillType, skillInfo: SkillInfo) {
diff --git a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt
index 439a35e72..25d48a525 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt
@@ -3,7 +3,6 @@ package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.events.ActionBarUpdateEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
-import at.hannibal2.skyhanni.events.SkillExpGainEvent
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils
@@ -24,10 +23,6 @@ class SkillExperience {
"inventory",
".* §e(?<number>.*)§6/.*"
)
- private val actionBarLowLevelPattern by patternGroup.pattern(
- "actionbarlow",
- ".*§3+(?<add>.+) (?<skill>.*) \\((?<percentage>.*)%\\).*"
- )
@SubscribeEvent
fun onProfileJoin(event: ProfileJoinEvent) {
@@ -46,11 +41,6 @@ class SkillExperience {
val baseExp = getExpForLevel(nextLevel - 1)
val totalExp = baseExp + overflow
skillExp[skill] = totalExp
- SkillExpGainEvent(skill).postAndCatch()
- }
- actionBarLowLevelPattern.matchMatcher(event.actionBar) {
- val skill = group("skill").lowercase()
- SkillExpGainEvent(skill).postAndCatch()
}
}
@@ -186,4 +176,3 @@ class SkillExperience {
)
}
}
-
diff --git a/src/main/java/at/hannibal2/skyhanni/events/SkillExpGainEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/SkillExpGainEvent.kt
index c6c7be5cc..09365a7ba 100644
--- a/src/main/java/at/hannibal2/skyhanni/events/SkillExpGainEvent.kt
+++ b/src/main/java/at/hannibal2/skyhanni/events/SkillExpGainEvent.kt
@@ -1,4 +1,6 @@
package at.hannibal2.skyhanni.events
+import at.hannibal2.skyhanni.features.skillprogress.SkillType
+
// does not know how much exp is there, also gets called multiple times
-class SkillExpGainEvent(val skill: String) : LorenzEvent()
+class SkillExpGainEvent(val skill: SkillType, val gained: Double) : LorenzEvent()