Skip to content

Commit

Permalink
better multiclassing tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammers21 committed Feb 22, 2025
1 parent 5d4adb1 commit 6aa8309
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 17 deletions.
6 changes: 6 additions & 0 deletions src/io/github/sammers/pla/blizzard/WowAPICharacter.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ public String fullName() {
return Character.fullNameByRealmAndName(name, realm);
}

public Set<Long> altsAndItself() {
Set<Long> all = new HashSet<>(alts);
all.add(id);
return all;
}

public static WowAPICharacter fromJson(JsonObject entries) {
List<PvpBracket> brcktsFromJson;
JsonArray array = entries.getJsonArray("brackets");
Expand Down
60 changes: 43 additions & 17 deletions src/io/github/sammers/pla/logic/Calculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,52 @@ public static Multiclassers calculateMulticlassers(Snapshot shuffleSnapshot, Cha
if (shuffleSnapshot == null) {
return new Multiclassers(List.of());
}
Map<Integer, List<Character>> charsGrpd = new HashMap<>();
// charter_id -> alt group
Map<Long, Set<Long>> charsGrpd = new HashMap<>();
for (Character character : shuffleSnapshot.characters()) {
WowAPICharacter wowAPICharacter = cache.getByFullName(character.fullName());
if (wowAPICharacter != null) {
charsGrpd.compute(wowAPICharacter.petHash(), (k, v) -> {
if (k == -1) {
return null;
} else if (v == null) {
ArrayList<Character> characters = new ArrayList<>();
characters.add(character);
return characters;
} else {
v.add(character);
return v;
Set<Long> alts = null;
Set<Long> altsAndItself = wowAPICharacter.altsAndItself();
// first try to find an existing group
for (Long charId : altsAndItself) {
alts = charsGrpd.get(charId);
if (alts != null) {
break;
}
}
// if no group found, create a new one
if (alts == null) {
for (Long charId : altsAndItself) {
charsGrpd.put(charId, altsAndItself);
}
});
} else {
// if group found, merge it with the new one
alts.addAll(altsAndItself);
}
}
}
Map<String, List<Character>> groups = new HashMap<>();
for (Character character : shuffleSnapshot.characters()) {
WowAPICharacter wowAPICharacter = cache.getByFullName(character.fullName());
if (wowAPICharacter != null) {
Set<Long> alts = charsGrpd.get(wowAPICharacter.id());
if (alts == null) {
alts = Set.of(wowAPICharacter.id());
}
String key = alts.stream().sorted().map(Object::toString).collect(Collectors.joining(","));
List<Character> characters = groups.get(key);
if (characters == null) {
characters = new ArrayList<>();
characters.add(character);
} else {
characters.add(character);
}
groups.put(key, characters);
}
}
Map<String, Multiclassers.Info> res = new HashMap<>();
for (Map.Entry<Integer, List<Character>> entry : charsGrpd.entrySet()) {
List<Multiclassers.Info> res = new ArrayList<>();
for (Map.Entry<String, List<Character>> entry : groups.entrySet()) {
List<Character> characters = entry.getValue();
// group by spec
Map<String, List<Character>> specGrpd = characters.stream().collect(Collectors.groupingBy(Character::fullSpec));
Expand All @@ -75,10 +101,10 @@ public static Multiclassers calculateMulticlassers(Snapshot shuffleSnapshot, Cha
int totalScore = specAndScore.values().stream().mapToInt(Multiclassers.CharAndScore::score).sum();
Character main = specAndScore.values().stream().max(Comparator.comparing(Multiclassers.CharAndScore::score)).orElseThrow().character();
Multiclassers.Info info = new Multiclassers.Info(-1, totalScore, main, specAndScore);
res.put(entry.getKey().toString(), info);
res.add(info);
}
// sort by total score
List<Info> list = res.values().stream().sorted(Comparator.comparing(Multiclassers.Info::totalScore).reversed()).toList();
List<Info> list = res.stream().sorted(Comparator.comparing(Multiclassers.Info::totalScore).reversed()).toList();
List<Info> resList = new ArrayList<>(list.size());
for (int i = 0; i < list.size(); i++) {
Info info = list.get(i);
Expand Down Expand Up @@ -471,7 +497,7 @@ public static byte[] gzipCompress(byte[] uncompressedData) {
}

public static byte[] gzipUncompress(byte[] compressedData) {
if (compressedData ==null ) {
if (compressedData == null) {
return null;
}
byte[] result = new byte[]{};
Expand Down

0 comments on commit 6aa8309

Please sign in to comment.