aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman / Linnea Gräf <roman.graef@gmail.com>2022-12-25 11:41:08 +0100
committerGitHub <noreply@github.com>2022-12-25 11:41:08 +0100
commit9cc5c71a0a8812a14cdc39d7a6b020506fb336cd (patch)
tree2f4d9648328c74dd75ba46faa6aa49250babadf6
parent978e084c4a9f3d8899ccbfa9894b42e5bbf0aa3a (diff)
downloadNotEnoughUpdates-9cc5c71a0a8812a14cdc39d7a6b020506fb336cd.tar.gz
NotEnoughUpdates-9cc5c71a0a8812a14cdc39d7a6b020506fb336cd.tar.bz2
NotEnoughUpdates-9cc5c71a0a8812a14cdc39d7a6b020506fb336cd.zip
PetLeveling: return stub exp ladder on misformed repo data (#508)
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/util/PetLeveling.kt19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/PetLeveling.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/PetLeveling.kt
index 0a9e37b9..56f84d54 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/PetLeveling.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/PetLeveling.kt
@@ -91,17 +91,22 @@ object PetLeveling {
}
}
+ val stubExpLadder by lazy {
+ Utils.showOutdatedRepoNotification()
+ ExpLadder(listOf(1, 1))
+ }
+
internal fun getPetLevelingForPet0(petIdWithoutRarity: String, rarity: Rarity): ExpLadder {
- val petConstants = this.petConstants ?: Constants.PETS
- var levels = petConstants["pet_levels"].asJsonArray.map { it.asLong }.toMutableList()
- val customLeveling = petConstants["custom_pet_leveling"].asJsonObject[petIdWithoutRarity]
- val offset = petConstants["pet_rarity_offset"].asJsonObject[rarity.name].asInt
+ val petConstants = this.petConstants ?: Constants.PETS ?: return stubExpLadder
+ var levels = petConstants["pet_levels"]?.asJsonArray?.map { it.asLong }?.toMutableList() ?: return stubExpLadder
+ val customLeveling = petConstants["custom_pet_leveling"]?.asJsonObject?.get(petIdWithoutRarity)
+ val offset = petConstants["pet_rarity_offset"]?.asJsonObject?.get(rarity.name)?.asInt ?: return stubExpLadder
var maxLevel = 100
if (customLeveling is JsonObject) {
- val customLevels by lazy { customLeveling["pet_levels"].asJsonArray.map { it.asLong } }
+ val customLevels by lazy { customLeveling["pet_levels"]?.asJsonArray?.map { it.asLong } }
when (customLeveling["type"]?.asInt ?: 0) {
- 1 -> levels.addAll(customLevels)
- 2 -> levels = customLevels.toMutableList()
+ 1 -> levels.addAll(customLevels ?: return stubExpLadder)
+ 2 -> levels = customLevels?.toMutableList() ?: return stubExpLadder
}
maxLevel = customLeveling["max_level"]?.asInt ?: maxLevel
}