diff options
author | Linnea Gräf <nea@nea.moe> | 2024-04-12 08:00:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-12 08:00:46 +0200 |
commit | 3cd5ec334fb6cbbdf4e44f471c9895cca8db1000 (patch) | |
tree | ccd1d53894102afbe86e3f9781fa1f6a5b015ea3 /src/main | |
parent | 810d9c3bdbfc2323bf9ddc76f944e39aa8b86fbf (diff) | |
download | NotEnoughUpdates-3cd5ec334fb6cbbdf4e44f471c9895cca8db1000.tar.gz NotEnoughUpdates-3cd5ec334fb6cbbdf4e44f471c9895cca8db1000.tar.bz2 NotEnoughUpdates-3cd5ec334fb6cbbdf4e44f471c9895cca8db1000.zip |
Fix skill experience detection (#1085)
Diffstat (limited to 'src/main')
8 files changed, 225 insertions, 131 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java index 6f539121..fb12906a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java @@ -879,6 +879,7 @@ public class PetInfoOverlay extends TextOverlay { } } + // TODO: Add support for sub menus in /tab, so we can configure "Always show most recently gained skill" in the Skill tab widget public void updatePetLevels() { HashMap<String, XPInformation.SkillInfo> skillInfoMap = XPInformation.getInstance().getSkillInfoMap(); @@ -888,7 +889,7 @@ public class PetInfoOverlay extends TextOverlay { for (Map.Entry<String, XPInformation.SkillInfo> entry : skillInfoMap.entrySet()) { if (entry.getValue().level == 50 && entry.getValue().fromApi) continue; - float skillXp = entry.getValue().totalXp; + float skillXp = (float) entry.getValue().totalXp; if (skillInfoMapLast.containsKey(entry.getKey())) { float skillXpLast = skillInfoMapLast.get(entry.getKey()); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/CombatSkillOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/CombatSkillOverlay.java index 26704f47..3f2618fe 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/CombatSkillOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/CombatSkillOverlay.java @@ -24,6 +24,7 @@ import io.github.moulberry.notenoughupdates.core.config.Position; import io.github.moulberry.notenoughupdates.core.util.lerp.LerpUtils; import io.github.moulberry.notenoughupdates.util.Utils; import io.github.moulberry.notenoughupdates.util.XPInformation; +import lombok.var; import net.minecraft.client.Minecraft; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -176,9 +177,13 @@ public class CombatSkillOverlay String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); skillInfoLast = skillInfo; - skillInfo = XPInformation.getInstance().getSkillInfo(skillType); + var s = NotEnoughUpdates.INSTANCE.config.skillOverlays.combatText; + skillInfo = XPInformation.getInstance().getSkillInfo( + skillType, + s.contains(1) || s.contains(2) || s.contains(3) || s.contains(4) + ); if (skillInfo != null) { - float totalXp = skillInfo.totalXp; + float totalXp = (float) skillInfo.totalXp; if (lastTotalXp > 0) { float delta = totalXp - lastTotalXp; @@ -285,9 +290,9 @@ public class CombatSkillOverlay .append(EnumChatFormatting.GRAY) .append(" ["); - float progress = skillInfo.currentXp / skillInfo.currentXpMax; + float progress = (float) (skillInfo.currentXp / skillInfo.currentXpMax); if (skillInfoLast != null && skillInfo.currentXpMax == skillInfoLast.currentXpMax) { - progress = interp(progress, skillInfoLast.currentXp / skillInfoLast.currentXpMax); + progress = interp(progress, (float) (skillInfoLast.currentXp / skillInfoLast.currentXpMax)); } float lines = 25; @@ -308,7 +313,7 @@ public class CombatSkillOverlay int current = (int) skillInfo.currentXp; if (skillInfoLast != null && skillInfo.currentXpMax == skillInfoLast.currentXpMax) { - current = (int) interp(current, skillInfoLast.currentXp); + current = (int) interp(current, (float) skillInfoLast.currentXp); } int remaining = (int) (skillInfo.currentXpMax - skillInfo.currentXp); @@ -342,7 +347,7 @@ public class CombatSkillOverlay if (skillInfo != null && skillInfo.level == 60) { int current = (int) skillInfo.currentXp; if (skillInfoLast != null && skillInfo.currentXpMax == skillInfoLast.currentXpMax) { - current = (int) interp(current, skillInfoLast.currentXp); + current = (int) interp(current,(float) skillInfoLast.currentXp); } lineMap.put( diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/FarmingSkillOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/FarmingSkillOverlay.java index f071c788..3fc89b59 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/FarmingSkillOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/FarmingSkillOverlay.java @@ -30,6 +30,7 @@ import io.github.moulberry.notenoughupdates.util.Utils; import io.github.moulberry.notenoughupdates.util.XPInformation; import io.github.moulberry.notenoughupdates.util.hypixelapi.HypixelItemAPI; import lombok.val; +import lombok.var; import net.minecraft.client.Minecraft; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -281,9 +282,17 @@ public class FarmingSkillOverlay extends TextOverlay { private void updateSkillInfo() { skillInfoLast = skillInfo; - skillInfo = XPInformation.getInstance().getSkillInfo(skillType); + var s = NotEnoughUpdates.INSTANCE.config.skillOverlays.farmingText; + skillInfo = XPInformation.getInstance().getSkillInfo( + skillType, + s.contains(2) || + s.contains(3) || + s.contains(4) || + s.contains(5) || + s.contains(7) + ); if (skillInfo != null) { - float totalXp = skillInfo.totalXp; + float totalXp = (float) skillInfo.totalXp; if (lastTotalXp > 0) { float delta = totalXp - lastTotalXp; @@ -556,9 +565,9 @@ public class FarmingSkillOverlay extends TextOverlay { .append(EnumChatFormatting.GRAY) .append(" ["); - float progress = skillInfo.currentXp / skillInfo.currentXpMax; + float progress = (float) (skillInfo.currentXp / skillInfo.currentXpMax); if (skillInfoLast != null && skillInfo.currentXpMax == skillInfoLast.currentXpMax) { - progress = interpolate(progress, skillInfoLast.currentXp / skillInfoLast.currentXpMax); + progress = interpolate(progress, (float) (skillInfoLast.currentXp / skillInfoLast.currentXpMax)); } float lines = 25; @@ -579,7 +588,7 @@ public class FarmingSkillOverlay extends TextOverlay { int current = (int) skillInfo.currentXp; if (skillInfoLast != null && skillInfo.currentXpMax == skillInfoLast.currentXpMax) { - current = (int) interpolate(current, skillInfoLast.currentXp); + current = (int) interpolate(current, (float) skillInfoLast.currentXp); } int remaining = (int) (skillInfo.currentXpMax - skillInfo.currentXp); @@ -613,7 +622,7 @@ public class FarmingSkillOverlay extends TextOverlay { if (skillInfo != null && skillInfo.level == 60) { int current = (int) skillInfo.currentXp; if (skillInfoLast != null && skillInfo.currentXpMax == skillInfoLast.currentXpMax) { - current = (int) interpolate(current, skillInfoLast.currentXp); + current = (int) interpolate(current, (float) skillInfoLast.currentXp); } if (foraging == 0) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/FishingSkillOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/FishingSkillOverlay.java index 4139b1e6..6991e12e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/FishingSkillOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/FishingSkillOverlay.java @@ -25,6 +25,7 @@ import io.github.moulberry.notenoughupdates.core.config.Position; import io.github.moulberry.notenoughupdates.core.util.lerp.LerpUtils; import io.github.moulberry.notenoughupdates.util.Utils; import io.github.moulberry.notenoughupdates.util.XPInformation; +import lombok.var; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.ISound; import net.minecraft.client.audio.PositionedSound; @@ -178,9 +179,17 @@ public class FishingSkillOverlay String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); skillInfoLast = skillInfo; - skillInfo = XPInformation.getInstance().getSkillInfo(skillType); + var s = NotEnoughUpdates.INSTANCE.config.skillOverlays.fishingText; + skillInfo = XPInformation.getInstance().getSkillInfo( + skillType, + s.contains(1) || + s.contains(2) || + s.contains(3) || + s.contains(4) || + s.contains(5) + ); if (skillInfo != null) { - float totalXp = skillInfo.totalXp; + float totalXp = (float) skillInfo.totalXp; if (lastTotalXp > 0) { float delta = totalXp - lastTotalXp; @@ -311,9 +320,9 @@ public class FishingSkillOverlay .append(EnumChatFormatting.GRAY) .append(" ["); - float progress = skillInfo.currentXp / skillInfo.currentXpMax; + float progress = (float) (skillInfo.currentXp / skillInfo.currentXpMax); if (skillInfoLast != null && skillInfo.currentXpMax == skillInfoLast.currentXpMax) { - progress = interp(progress, skillInfoLast.currentXp / skillInfoLast.currentXpMax); + progress = interp(progress, (float) (skillInfoLast.currentXp / skillInfoLast.currentXpMax)); } float lines = 25; @@ -334,7 +343,7 @@ public class FishingSkillOverlay int current = (int) skillInfo.currentXp; if (skillInfoLast != null && skillInfo.currentXpMax == skillInfoLast.currentXpMax) { - current = (int) interp(current, skillInfoLast.currentXp); + current = (int) interp(current, (float) skillInfoLast.currentXp); } int remaining = (int) (skillInfo.currentXpMax - skillInfo.currentXp); @@ -368,7 +377,7 @@ public class FishingSkillOverlay if (skillInfo != null && skillInfo.level == 50) { int current = (int) skillInfo.currentXp; if (skillInfoLast != null && skillInfo.currentXpMax == skillInfoLast.currentXpMax) { - current = (int) interp(current, skillInfoLast.currentXp); + current = (int) interp(current, (float) skillInfoLast.currentXp); } lineMap.put( diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningSkillOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningSkillOverlay.java index 68de64a7..15deece8 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningSkillOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningSkillOverlay.java @@ -24,6 +24,7 @@ import io.github.moulberry.notenoughupdates.core.config.Position; import io.github.moulberry.notenoughupdates.core.util.lerp.LerpUtils; import io.github.moulberry.notenoughupdates.util.Utils; import io.github.moulberry.notenoughupdates.util.XPInformation; +import lombok.var; import net.minecraft.client.Minecraft; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -169,9 +170,17 @@ public class MiningSkillOverlay String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); skillInfoLast = skillInfo; - skillInfo = XPInformation.getInstance().getSkillInfo(skillType); + var s = NotEnoughUpdates.INSTANCE.config.skillOverlays.miningText; + skillInfo = XPInformation.getInstance().getSkillInfo( + skillType, + s.contains(2) || + s.contains(3) || + s.contains(4) || + s.contains(5) || + s.contains(7) + ); if (skillInfo != null) { - float totalXp = skillInfo.totalXp; + float totalXp = (float) skillInfo.totalXp; if (lastTotalXp > 0) { float delta = totalXp - lastTotalXp; @@ -298,9 +307,9 @@ public class MiningSkillOverlay .append(EnumChatFormatting.GRAY) .append(" ["); - float progress = skillInfo.currentXp / skillInfo.currentXpMax; + float progress = (float) (skillInfo.currentXp / skillInfo.currentXpMax); if (skillInfoLast != null && skillInfo.currentXpMax == skillInfoLast.currentXpMax) { - progress = interp(progress, skillInfoLast.currentXp / skillInfoLast.currentXpMax); + progress = interp(progress, (float) (skillInfoLast.currentXp / skillInfoLast.currentXpMax)); } float lines = 25; @@ -321,7 +330,7 @@ public class MiningSkillOverlay int current = (int) skillInfo.currentXp; if (skillInfoLast != null && skillInfo.currentXpMax == skillInfoLast.currentXpMax) { - current = (int) interp(current, skillInfoLast.currentXp); + current = (int) interp(current, (float) skillInfoLast.currentXp); } int remaining = (int) (skillInfo.currentXpMax - skillInfo.currentXp); @@ -355,7 +364,7 @@ public class MiningSkillOverlay if (skillInfo != null && skillInfo.level == 60) { int current = (int) skillInfo.currentXp; if (skillInfoLast != null && skillInfo.currentXpMax == skillInfoLast.currentXpMax) { - current = (int) interp(current, skillInfoLast.currentXp); + current = (int) interp(current, (float) skillInfoLast.currentXp); } lineMap.put( 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 117545c9..e474f348 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java @@ -24,12 +24,18 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe; import io.github.moulberry.notenoughupdates.core.util.StringUtils; +import io.github.moulberry.notenoughupdates.miscfeatures.tablisttutorial.TablistAPI; +import lombok.var; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -43,16 +49,15 @@ public class XPInformation { public static class SkillInfo { public int level; - public float totalXp; - public float currentXp; - public float currentXpMax; + public double totalXp; + public double currentXp; + public double currentXpMax; public boolean fromApi = false; } private final HashMap<String, SkillInfo> skillInfoMap = new HashMap<>(); public HashMap<String, Float> updateWithPercentage = new HashMap<>(); - - public int correctionCounter = 0; + public HashMap<String, Float> increment = new HashMap<>(); private static final Splitter SPACE_SPLITTER = Splitter.on(" ").omitEmptyStrings().trimResults(); private static final Pattern SKILL_PATTERN = Pattern.compile( @@ -66,144 +71,189 @@ public class XPInformation { return skillInfoMap; } - public SkillInfo getSkillInfo(String skillName) { - return skillInfoMap.get(skillName.toLowerCase()); + private Set<String> failedSkills = new HashSet<>(); + + public @Nullable SkillInfo getSkillInfo(String skillName, boolean isHighlyInterested) { + var obj = skillInfoMap.get(skillName.toLowerCase()); + if (isHighlyInterested && failedSkills.contains(skillName.toLowerCase())) { + TablistAPI.getWidgetLines(TablistAPI.WidgetNames.SKILLS); + } + return obj; } private String lastActionBar = null; @SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true) public void onChatReceived(ClientChatReceivedEvent event) { - if (event.type == 2) { - JsonObject leveling = Constants.LEVELING; - if (leveling == null) return; + if (event.type != 2) { + return; + } + JsonObject leveling = Constants.LEVELING; + if (leveling == null) return; - String actionBar = StringUtils.cleanColour(event.message.getUnformattedText()); + String actionBar = StringUtils.cleanColour(event.message.getUnformattedText()); - if (lastActionBar != null && lastActionBar.equalsIgnoreCase(actionBar)) { - return; - } - lastActionBar = actionBar; + if (lastActionBar != null && lastActionBar.equalsIgnoreCase(actionBar)) { + return; + } + lastActionBar = actionBar; + + List<String> components = SPACE_SPLITTER.splitToList(actionBar); + + for (String component : components) { + Matcher matcher = SKILL_PATTERN.matcher(component); + if (matcher.matches()) { + String skillS = matcher.group(2); + String currentXpS = matcher.group(3).replace(",", ""); + String maxXpS = matcher.group(4).replace(",", ""); + + float currentXp = Float.parseFloat(currentXpS); + float maxXp = Float.parseFloat(maxXpS); + + SkillInfo skillInfo = new SkillInfo(); + skillInfo.currentXp = currentXp; + skillInfo.currentXpMax = maxXp; + skillInfo.totalXp = currentXp; + + JsonArray levelingArray = leveling.getAsJsonArray("leveling_xp"); + for (int i = 0; i < levelingArray.size(); i++) { + float cap = levelingArray.get(i).getAsFloat(); + if (maxXp > 0 && maxXp <= cap) { + break; + } - List<String> components = SPACE_SPLITTER.splitToList(actionBar); + skillInfo.totalXp += cap; + skillInfo.level++; + } - for (String component : components) { - Matcher matcher = SKILL_PATTERN.matcher(component); + skillInfoMap.put(skillS.toLowerCase(), skillInfo); + return; + } else { + matcher = SKILL_PATTERN_PERCENTAGE.matcher(component); if (matcher.matches()) { String skillS = matcher.group(2); - String currentXpS = matcher.group(3).replace(",", ""); - String maxXpS = matcher.group(4).replace(",", ""); - - float currentXp = Float.parseFloat(currentXpS); - float maxXp = Float.parseFloat(maxXpS); - - SkillInfo skillInfo = new SkillInfo(); - skillInfo.currentXp = currentXp; - skillInfo.currentXpMax = maxXp; - skillInfo.totalXp = currentXp; - - JsonArray levelingArray = leveling.getAsJsonArray("leveling_xp"); - for (int i = 0; i < levelingArray.size(); i++) { - float cap = levelingArray.get(i).getAsFloat(); - if (maxXp > 0 && maxXp <= cap) { - break; - } + String xpPercentageS = matcher.group(3).replace(",", ""); - skillInfo.totalXp += cap; - skillInfo.level++; + float xpPercentage = Float.parseFloat(xpPercentageS); + if (updateWithPercentage.containsKey(skillS.toLowerCase())) { + failedSkills.add(skillS.toLowerCase()); } - - skillInfoMap.put(skillS.toLowerCase(), skillInfo); - return; + updateWithPercentage.put(skillS.toLowerCase(), xpPercentage); + increment.put(skillS.toLowerCase(), Float.parseFloat(matcher.group(1).replace(",", ""))); } else { - matcher = SKILL_PATTERN_PERCENTAGE.matcher(component); + matcher = SKILL_PATTERN_MULTIPLIER.matcher(component); + if (matcher.matches()) { String skillS = matcher.group(2); - String xpPercentageS = matcher.group(3).replace(",", ""); - - float xpPercentage = Float.parseFloat(xpPercentageS); - updateWithPercentage.put(skillS.toLowerCase(), xpPercentage); - } else { - matcher = SKILL_PATTERN_MULTIPLIER.matcher(component); - - if (matcher.matches()) { - String skillS = matcher.group(2); - String currentXpS = matcher.group(3).replace(",", ""); - String maxXpS = matcher.group(4).replace(",", ""); - - float maxMult = 1; - if (maxXpS.endsWith("k")) { - maxMult = 1000; - maxXpS = maxXpS.substring(0, maxXpS.length() - 1); - } else if (maxXpS.endsWith("m")) { - maxMult = 1000000; - maxXpS = maxXpS.substring(0, maxXpS.length() - 1); - } else if (maxXpS.endsWith("b")) { - maxMult = 1000000000; - maxXpS = maxXpS.substring(0, maxXpS.length() - 1); - } - - float currentXp = Float.parseFloat(currentXpS); - float maxXp = Float.parseFloat(maxXpS) * maxMult; + String currentXpS = matcher.group(3).replace(",", ""); + String maxXpS = matcher.group(4).replace(",", ""); + + float maxMult = 1; + if (maxXpS.endsWith("k")) { + maxMult = 1000; + maxXpS = maxXpS.substring(0, maxXpS.length() - 1); + } else if (maxXpS.endsWith("m")) { + maxMult = 1000000; + maxXpS = maxXpS.substring(0, maxXpS.length() - 1); + } else if (maxXpS.endsWith("b")) { + maxMult = 1000000000; + maxXpS = maxXpS.substring(0, maxXpS.length() - 1); + } - SkillInfo skillInfo = new SkillInfo(); - skillInfo.currentXp = currentXp; - skillInfo.currentXpMax = maxXp; - skillInfo.totalXp = currentXp; + float currentXp = Float.parseFloat(currentXpS); + float maxXp = Float.parseFloat(maxXpS) * maxMult; - JsonArray levelingArray = leveling.getAsJsonArray("leveling_xp"); - for (int i = 0; i < levelingArray.size(); i++) { - float cap = levelingArray.get(i).getAsFloat(); - if (maxXp > 0 && maxXp <= cap) { - break; - } + SkillInfo skillInfo = new SkillInfo(); + skillInfo.currentXp = currentXp; + skillInfo.currentXpMax = maxXp; + skillInfo.totalXp = currentXp; - skillInfo.totalXp += cap; - skillInfo.level++; + JsonArray levelingArray = leveling.getAsJsonArray("leveling_xp"); + for (int i = 0; i < levelingArray.size(); i++) { + float cap = levelingArray.get(i).getAsFloat(); + if (maxXp > 0 && maxXp <= cap) { + break; } - skillInfoMap.put(skillS.toLowerCase(), skillInfo); - return; + skillInfo.totalXp += cap; + skillInfo.level++; } + + skillInfoMap.put(skillS.toLowerCase(), skillInfo); + return; } } } } } + private Pattern tablistSkillPattern = + Pattern.compile( + " (?<type>[^ ]+) (?<level>\\d+): (?:(?<percentage>\\d+(\\.\\d+)?)%|(?<amount>[0-9,]+(\\.\\d+)?)/.*|(?<max>MAX))"); + + // Car Pentry + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent event) { + if (event.phase != TickEvent.Phase.END) return; + var widgetLines = TablistAPI.getOptionalWidgetLines(TablistAPI.WidgetNames.SKILLS); + for (String widgetLine : widgetLines) { + Matcher matcher = tablistSkillPattern.matcher(Utils.cleanColour(widgetLine)); + if (!matcher.matches()) + continue; + var type = matcher.group("type"); + assert type != null; + var level = Integer.parseInt(matcher.group("level")); + var percentage = matcher.group("percentage"); + var percentageAsNumber = percentage != null ? Double.parseDouble(percentage) / 100 : null; + var amount = matcher.group("amount"); + var amountAsNumber = amount != null ? Double.parseDouble(amount.replace(",", "")) : null; + var isMax = matcher.group("max") != null; + // TODO: use this extra information for good (not evil) + updateLevel(type.toLowerCase(), level); + } + } + public void updateLevel(String skill, int level) { if (updateWithPercentage.containsKey(skill)) { JsonObject leveling = Constants.LEVELING; if (leveling == null) return; - SkillInfo skillInfo = new SkillInfo(); - skillInfo.totalXp = 0; - skillInfo.level = level; + SkillInfo newSkillInfo = new SkillInfo(); + newSkillInfo.totalXp = 0; + newSkillInfo.level = level; JsonArray levelingArray = leveling.getAsJsonArray("leveling_xp"); for (int i = 0; i < levelingArray.size(); i++) { float cap = levelingArray.get(i).getAsFloat(); if (i == level) { - skillInfo.currentXp += updateWithPercentage.get(skill) / 100f * cap; - skillInfo.totalXp += skillInfo.currentXp; - skillInfo.currentXpMax = cap; + newSkillInfo.currentXp += updateWithPercentage.get(skill) / 100f * cap; + newSkillInfo.totalXp += newSkillInfo.currentXp; + newSkillInfo.currentXpMax = cap; break; } else { - skillInfo.totalXp += cap; + newSkillInfo.totalXp += cap; } } - SkillInfo old = skillInfoMap.get(skill.toLowerCase()); - - if (old.totalXp <= skillInfo.totalXp) { - correctionCounter--; - if (correctionCounter < 0) correctionCounter = 0; - - skillInfoMap.put(skill.toLowerCase(), skillInfo); - } else if (++correctionCounter >= 10) { - correctionCounter = 0; - skillInfoMap.put(skill.toLowerCase(), skillInfo); + SkillInfo oldSkillInfo = skillInfoMap.get(skill.toLowerCase()); + float inc = increment.getOrDefault(skill.toLowerCase(), 0F); + if (oldSkillInfo != null && oldSkillInfo.totalXp + inc > newSkillInfo.totalXp && oldSkillInfo.totalXp - inc * 5 < newSkillInfo.totalXp) { + SkillInfo incrementedSkillInfo = new SkillInfo(); + incrementedSkillInfo.totalXp = oldSkillInfo.totalXp + inc; + boolean isNotLevelUp = oldSkillInfo.currentXp + inc < oldSkillInfo.currentXpMax; + incrementedSkillInfo.level = + (isNotLevelUp) ? oldSkillInfo.level : oldSkillInfo.level + 1; + incrementedSkillInfo.currentXp = + isNotLevelUp ? oldSkillInfo.currentXp + inc : oldSkillInfo.currentXp + inc - oldSkillInfo.currentXpMax; + incrementedSkillInfo.currentXpMax = + incrementedSkillInfo.level < levelingArray.size() && incrementedSkillInfo.level >= 0 + ? levelingArray.get(incrementedSkillInfo.level).getAsFloat() + : 0F; + skillInfoMap.put(skill.toLowerCase(), incrementedSkillInfo); + } else { + skillInfoMap.put(skill.toLowerCase(), newSkillInfo); } + failedSkills.remove(skill.toLowerCase()); } updateWithPercentage.clear(); } diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/tablisttutorial/TablistAPI.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/tablisttutorial/TablistAPI.kt index 7ff2f3a3..277ed6e3 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/tablisttutorial/TablistAPI.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/tablisttutorial/TablistAPI.kt @@ -122,7 +122,18 @@ object TablistAPI { enum class WidgetNames(val regex: Regex?) { COMMISSIONS(null), - SKILLS(null), + /* + '§e§lSkills:' + ' Farming 50: §r§a43.3%' + ' Mining 60: §r§c§lMAX' + ' Combat 46: §r§a21.7%' + ' Foraging 23: §r§a43.5%' + * */ + SKILLS(Regex("Skills:( .*)?")), + /* + * '§e§lSkills: §r§aCombat 46: §r§321.7%' + * */ + DUNGEON_SKILLS(Regex("Skills: (.*)")), TRAPPER(null), FORGE(Regex("Forges:( \\(\\d/\\d\\))?")), POWDER(Regex.fromLiteral("Powders:")), @@ -130,7 +141,7 @@ object TablistAPI { ; override fun toString(): String { - return this.name.lowercase().split(" ").joinToString(" ") { str -> + return this.name.lowercase().split("_").joinToString(" ") { str -> str.replaceFirstChar { if (it.isLowerCase()) { it.titlecase( diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/TabSkillInfoParser.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/TabSkillInfoParser.kt index 0c3e1901..2f3e256a 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/TabSkillInfoParser.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/TabSkillInfoParser.kt @@ -90,14 +90,14 @@ object TabSkillInfoParser { val nextLevelProgress = nextLevelDiff * progress / 100 val totalXp = levelXp + nextLevelProgress - val existingLevel = XPInformation.getInstance().getSkillInfo(name) ?: XPInformation.SkillInfo() + val existingLevel = XPInformation.getInstance().getSkillInfo(name, false) ?: XPInformation.SkillInfo() // Only update if the numbers are substantially different if (!isWithinPercentageRange(totalXp, existingLevel.totalXp.toDouble(), 1.0)) { existingLevel.level = level - existingLevel.totalXp = totalXp.toFloat() - existingLevel.currentXp = nextLevelProgress.toFloat() - existingLevel.currentXpMax = nextLevelDiff.toFloat() + existingLevel.totalXp = totalXp + existingLevel.currentXp = nextLevelProgress + existingLevel.currentXpMax = nextLevelDiff XPInformation.getInstance().skillInfoMap[name] = existingLevel } @@ -107,13 +107,13 @@ object TabSkillInfoParser { val name = maxLevelMatcher.group("type")!!.lowercase() val level = maxLevelMatcher.group("level")!!.toInt() - val existingLevel = XPInformation.getInstance().getSkillInfo(name) ?: XPInformation.SkillInfo() + val existingLevel = XPInformation.getInstance().getSkillInfo(name, false) ?: XPInformation.SkillInfo() if (existingLevel.level != level) { existingLevel.level = level val levelingArray = levelArray(name) val totalXp = calculateLevelXp(levelingArray, level - 1) - existingLevel.totalXp = totalXp.toFloat() + existingLevel.totalXp = totalXp XPInformation.getInstance().skillInfoMap[name] = existingLevel } } |