diff options
| author | Roman / Nea <roman.graef@gmail.com> | 2022-02-18 14:57:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-18 14:57:06 +0100 |
| commit | f035ce00967bce495390bf4d7bc8ad17ab74073a (patch) | |
| tree | 44a172a8087ba1ded8c80b8a978832bbac5dee68 /src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java | |
| parent | 393f3c8f9279f5d8f5e33933ce6ef985d65a92f0 (diff) | |
| download | notenoughupdates-f035ce00967bce495390bf4d7bc8ad17ab74073a.tar.gz notenoughupdates-f035ce00967bce495390bf4d7bc8ad17ab74073a.tar.bz2 notenoughupdates-f035ce00967bce495390bf4d7bc8ad17ab74073a.zip | |
kat sitter overlay (#83)
* kat sitter overlay
* Remove unused scan function
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java')
| -rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java b/src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java index cac4cf74..d1bed30e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java @@ -2,6 +2,7 @@ package io.github.moulberry.notenoughupdates.util; import com.google.common.base.Splitter; import com.google.gson.JsonArray; +import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; @@ -13,6 +14,9 @@ import java.util.HashMap; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; public class XPInformation { private static final XPInformation INSTANCE = new XPInformation(); @@ -208,4 +212,24 @@ public class XPInformation { skillInfoMap.put(skill.toLowerCase(), info); } } + + public double getPetLevel(String petId, double exp, String rarity) { + Stream<JsonElement> pet_levels = StreamSupport.stream(Constants.PETS.get("pet_levels").getAsJsonArray().spliterator(), false); + int pet_rarity_offset = Constants.PETS.getAsJsonObject("pet_rarity_offset").get(rarity).getAsInt(); + JsonObject custom_pet_leveling = Constants.PETS.getAsJsonObject("custom_pet_leveling").getAsJsonObject(petId); + List<Integer> xpLevelsRequired = pet_levels.skip(pet_rarity_offset).limit(100).map(JsonElement::getAsInt).collect(Collectors.toList()); + if (custom_pet_leveling != null && custom_pet_leveling.get("type").getAsInt() == 1) + xpLevelsRequired.addAll(StreamSupport.stream(custom_pet_leveling.getAsJsonArray("pet_levels").spliterator(), false).map(JsonElement::getAsInt).collect(Collectors.toList())); + double remainingExp = exp; + for (int i = 0; i < xpLevelsRequired.size(); i++) { + int xpForCurrentLevel = xpLevelsRequired.get(i); + if (remainingExp >= xpForCurrentLevel) { + remainingExp -= xpForCurrentLevel; + } else { + return i + 1 + remainingExp / xpForCurrentLevel; + } + } + return xpLevelsRequired.size(); + } + } |
