From d503904d174af2a0dfcb0d568cad5d29647714bc Mon Sep 17 00:00:00 2001 From: UltraFaceguy Date: Sun, 11 Jul 2021 13:59:07 -0400 Subject: [PATCH] Fixing heatmap --- .../face/strife/data/champion/Champion.java | 41 ++++++++++++------- .../face/strife/managers/ChampionManager.java | 1 + 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/main/java/land/face/strife/data/champion/Champion.java b/src/main/java/land/face/strife/data/champion/Champion.java index 83512497..48722bd4 100644 --- a/src/main/java/land/face/strife/data/champion/Champion.java +++ b/src/main/java/land/face/strife/data/champion/Champion.java @@ -24,12 +24,14 @@ import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.stream.Collectors; import java.util.stream.IntStream; import land.face.strife.StrifePlugin; import land.face.strife.data.CombatDetailsContainer; import land.face.strife.managers.StatUpdateManager; import land.face.strife.stats.StrifeStat; import land.face.strife.stats.StrifeTrait; +import org.bukkit.ChatColor; import org.bukkit.entity.Player; public class Champion { @@ -116,10 +118,10 @@ public int getPendingLevel(StrifeAttribute stat) { } public void buildAttributeHeatmap() { - float red = 0; - float yellow = 0; - float green = 0; - float blue = 0; + int red = 0; + int yellow = 0; + int green = 0; + int blue = 0; for (StrifeAttribute attribute : getLevelMap().keySet()) { switch (attribute.getKey()) { case "str": @@ -136,15 +138,27 @@ public void buildAttributeHeatmap() { break; } } - float total = red + yellow + green + blue; - red = red / total; - yellow = yellow / total; - green = green / total; - blue = blue / total; - attributeHeatmap = IntStream.range(0, (int) (red * 8)).mapToObj(i -> "⬤").toString() + - IntStream.range(0, (int) (yellow * 8)).mapToObj(i -> "⬤") + - IntStream.range(0, (int) (green * 8)).mapToObj(i -> "⬤") + - IntStream.range(0, (int) (blue * 8)).mapToObj(i -> "⬤"); + float total = Math.max(1, red + yellow + green + blue); + int segments = 40 - player.getName().length(); + + int redSegments = (int) Math.ceil((float) segments * (float) red / total); + total -= red; + segments -= redSegments; + + int yellowSegments = (int) Math.floor((float) segments * (float) yellow / total); + total -= yellow; + segments -= yellowSegments; + + int greenSegments = (int) Math.ceil((float) segments * (float) green / total); + segments -= greenSegments; + + int blueSegments = segments; + + attributeHeatmap = + ChatColor.RED + IntStream.range(0, redSegments).mapToObj(i -> "▌").collect(Collectors.joining()) + + ChatColor.YELLOW + IntStream.range(0, yellowSegments).mapToObj(i -> "▌").collect(Collectors.joining()) + + ChatColor.GREEN + IntStream.range(0, greenSegments).mapToObj(i -> "▌").collect(Collectors.joining()) + + ChatColor.BLUE + IntStream.range(0, blueSegments).mapToObj(i -> "▌").collect(Collectors.joining()); } public String getAttributeHeatmap() { @@ -181,7 +195,6 @@ public int getUnusedStatPoints() { public void setUnusedStatPoints(int unusedStatPoints) { saveData.setUnusedStatPoints(unusedStatPoints); - buildAttributeHeatmap(); } public int getPendingUnusedStatPoints() { diff --git a/src/main/java/land/face/strife/managers/ChampionManager.java b/src/main/java/land/face/strife/managers/ChampionManager.java index 8f484e95..3242aaad 100644 --- a/src/main/java/land/face/strife/managers/ChampionManager.java +++ b/src/main/java/land/face/strife/managers/ChampionManager.java @@ -145,6 +145,7 @@ public void savePendingStats(Champion champion) { } } champion.getSaveData().savePendingStats(); + champion.buildAttributeHeatmap(); rebuildAttributes(champion); }