@@ -24,17 +24,15 @@ object PlayerDataUpdater {
24
24
25
25
private fun crystalHollowsChecker () {
26
26
listenEvent<CrystalFoundEvent , Unit > {
27
- playerData.currentProfile?.mining?.crystalHollows?.crystals?.find { it.crystal == crystal }?.state =
28
- CrystalState .FOUND
27
+ currentProfile.mining.crystalHollows.crystals.find { it.crystal == crystal }?.state = CrystalState .FOUND
29
28
}
30
29
31
30
listenEvent<NucleusRunCompleteEvent , Unit > {
32
- playerData. currentProfile? .mining? .crystalHollows? .crystals? .forEach { it.state = CrystalState .NOT_FOUND }
31
+ currentProfile.mining.crystalHollows.crystals.forEach { it.state = CrystalState .NOT_FOUND }
33
32
}
34
33
35
34
listenEvent<CrystalPlaceEvent , Unit > {
36
- playerData.currentProfile?.mining?.crystalHollows?.crystals?.find { it.crystal == crystal }?.state =
37
- CrystalState .PLACED
35
+ currentProfile.mining.crystalHollows.crystals.find { it.crystal == crystal }?.state = CrystalState .PLACED
38
36
}
39
37
}
40
38
@@ -47,56 +45,56 @@ object PlayerDataUpdater {
47
45
lore.map { it.string }.forEach {
48
46
val crystalName = crystalNames.find { c -> it.contains(c) } ? : return @forEach
49
47
val crystal = Crystal .entries.first { c -> c.displayName == crystalName }
50
- playerData.currentProfile?.mining?.crystalHollows?.crystals?.first { instance -> instance.crystal == crystal }?.state =
51
- if (crystalNotFoundRegex.matches(it)) {
52
- CrystalState .NOT_FOUND
53
- } else if (crystalNotPlacedRegex.matches(it)) {
54
- CrystalState .FOUND
55
- } else {
56
- CrystalState .PLACED
57
- }
48
+ val newState = when {
49
+ crystalNotFoundRegex.matches(it) -> CrystalState .NOT_FOUND
50
+ crystalNotPlacedRegex.matches(it) -> CrystalState .FOUND
51
+ else -> CrystalState .PLACED
52
+ }
53
+ currentProfile.mining.crystalHollows.crystals.first { instance -> instance.crystal == crystal }.state = newState
58
54
}
59
55
}
60
56
61
57
val hotmTitleRegex = regex(" menu.hotm.hotm" )
62
58
val crystalHollowsCrystalsRegex = regex(" menu.hotm.crystal.itemName" )
63
59
val abilitySelectedRegex = regex(" menu.hotm.abilities.selected" )
64
60
val peakOfTheMountainRegex = regex(" menu.hotm.potm" )
61
+ val peakOfTheMountainLevelRegex = regex(" menu.hotm.potm.level" )
65
62
66
63
val mithrilPowderRegex = regex(" menu.hotm.mithrilPowder" )
67
64
val gemstonePowderRegex = regex(" menu.hotm.gemstonePowder" )
68
65
val glacitePowderRegex = regex(" menu.hotm.glacitePowder" )
69
66
listenEvent<SetItemEvent , Unit > {
70
- if (hotmTitleRegex.matches(PlayerSessionData .currentScreen?.title?.string.toString())) return @listenEvent
67
+ if (! hotmTitleRegex.matches(PlayerSessionData .currentScreen?.title?.string.toString())) return @listenEvent
71
68
72
- val itemNameString = itemStack.displayName.string
69
+ val itemNameString = itemStack.nameAsString
73
70
when {
74
71
crystalHollowsCrystalsRegex.matches(itemNameString) -> updateCrystalState(itemStack)
75
72
MiningAbility .rawNames.any { name -> itemNameString.contains(name) } -> {
76
73
val selected = itemStack.lore.any { lore -> abilitySelectedRegex.matches(lore.string) }
77
74
if (selected) {
78
75
val rawName =
79
76
MiningAbility .rawNames.find { name -> itemNameString.contains(name) } ? : return @listenEvent
80
- playerData. currentProfile? .mining? .selectedAbility = MiningAbility .byRawName(rawName)
77
+ currentProfile.mining.selectedAbility = MiningAbility .byRawName(rawName)
81
78
}
82
79
}
83
80
peakOfTheMountainRegex.matches(itemNameString) -> {
84
81
val lore = itemStack.lore
85
82
val firstLine = lore.first().string
86
- val level = firstLine.drop(6 ).first().digitToIntOrNull() ? : return @listenEvent
87
- playerData.currentProfile?.mining?.abilityLevel = if (level > 1 ) 2 else 1
83
+ val level = peakOfTheMountainLevelRegex.singleGroup(firstLine)?.toIntOrNull() ? : return @listenEvent
84
+ currentProfile.mining.abilityLevel = if (level > 1 ) 2 else 1
85
+ currentProfile.mining.peakOfTheMountain = level
88
86
}
89
87
hotmTitleRegex.matches(itemNameString) -> {
90
88
val lore = itemStack.lore.map { line -> line.string }
91
89
val (mithrilPowder, gemstonePowder, glacitePowder) = lore.mapNotNull { line ->
92
90
mithrilPowderRegex.singleGroup(line) ? : gemstonePowderRegex.singleGroup(line)
93
91
? : glacitePowderRegex.singleGroup(line)
94
92
}
95
- playerData. currentProfile? .mining? .mithrilPowder =
93
+ currentProfile.mining.mithrilPowder =
96
94
mithrilPowder.doubleOrNull()?.toInt() ? : return @listenEvent
97
- playerData. currentProfile? .mining? .gemstonePowder =
95
+ currentProfile.mining.gemstonePowder =
98
96
gemstonePowder.doubleOrNull()?.toInt() ? : return @listenEvent
99
- playerData. currentProfile? .mining? .glacitePowder =
97
+ currentProfile.mining.glacitePowder =
100
98
glacitePowder.doubleOrNull()?.toInt() ? : return @listenEvent
101
99
}
102
100
}
@@ -115,15 +113,15 @@ object PlayerDataUpdater {
115
113
val glacitePowder = tablistGlacitePowderRegex.singleGroup(line)?.doubleOrNull()?.toInt()
116
114
117
115
if (mithrilPowder != null ) {
118
- playerData. currentProfile? .mining? .mithrilPowder = mithrilPowder
116
+ currentProfile.mining.mithrilPowder = mithrilPowder
119
117
EventHandler .invokeEvent(PowderGainEvent (PowderGainEvent .PowderType .MITHRIL , mithrilPowder))
120
118
}
121
119
if (gemstonePowder != null ) {
122
- playerData. currentProfile? .mining? .gemstonePowder = gemstonePowder
120
+ currentProfile.mining.gemstonePowder = gemstonePowder
123
121
EventHandler .invokeEvent(PowderGainEvent (PowderGainEvent .PowderType .GEMSTONE , gemstonePowder))
124
122
}
125
123
if (glacitePowder != null ) {
126
- playerData. currentProfile? .mining? .glacitePowder = glacitePowder
124
+ currentProfile.mining.glacitePowder = glacitePowder
127
125
EventHandler .invokeEvent(PowderGainEvent (PowderGainEvent .PowderType .GLACITE , glacitePowder))
128
126
}
129
127
}
0 commit comments