From 386b9be450f1791aba2d4d326535d9a2abf07f9f Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Tue, 16 Aug 2016 02:27:22 +0200 Subject: [PATCH 1/2] Alternative IV Calculation + Use of Two-Letter-System --- .../corriekay/pokegoutil/utils/ConfigKey.java | 1 + .../pokegoutil/utils/pokemon/PokeHandler.java | 12 ++---- .../utils/pokemon/PokemonUtils.java | 38 +++++++++++++------ .../corriekay/pokegoutil/windows/MenuBar.java | 5 +++ .../pokegoutil/windows/PokemonTab.java | 31 ++++++++------- 5 files changed, 53 insertions(+), 34 deletions(-) diff --git a/src/me/corriekay/pokegoutil/utils/ConfigKey.java b/src/me/corriekay/pokegoutil/utils/ConfigKey.java index 5b4433ea..41ba9e56 100644 --- a/src/me/corriekay/pokegoutil/utils/ConfigKey.java +++ b/src/me/corriekay/pokegoutil/utils/ConfigKey.java @@ -24,6 +24,7 @@ public enum ConfigKey { TRANSFER_AFTER_EVOLVE("settings.transferAfterEvolve", false, Boolean.class), SHOW_BULK_POPUP("settings.popupAfterBulk", true, Boolean.class), INCLUDE_FAMILY("settings.includeFamily", true, Boolean.class), + ALTERNATIVE_IV_CALCULATION("settings.alternativeIvCalculation", false, Boolean.class), LANGUAGE("options.lang", "en", String.class), FONT_SIZE("options.fontsize", 0, Integer.class), diff --git a/src/me/corriekay/pokegoutil/utils/pokemon/PokeHandler.java b/src/me/corriekay/pokegoutil/utils/pokemon/PokeHandler.java index 281bac57..56c92748 100644 --- a/src/me/corriekay/pokegoutil/utils/pokemon/PokeHandler.java +++ b/src/me/corriekay/pokegoutil/utils/pokemon/PokeHandler.java @@ -243,13 +243,7 @@ public String get(Pokemon p) { IV_RATING("IV Rating in two digits (XX for 100%)") { @Override public String get(Pokemon p) { - return Utilities.percentageWithTwoCharacters(p.getIvRatio()); - } - }, - IV_RATING_LONG("IV Rating") { - @Override - public String get(Pokemon p) { - return String.valueOf(Utilities.percentage(p.getIvRatio())); + return Utilities.percentageWithTwoCharacters(PokemonUtils.ivRating(p)); } }, IV_HEX("IV Values in hexadecimal, like \"9FA\" (F = 15)") { @@ -350,13 +344,13 @@ public String get(Pokemon p) { DPS_1_RATING("Rating for Move 1 (Percentage of max possible) in two digits (XX for 100%)") { @Override public String get(Pokemon p) { - return Utilities.percentageWithTwoCharacters(PokemonUtils.moveRating(p, true)); + return PokemonUtils.moveRating(p, true); } }, DPS_2_RATING("Rating for Move 2 (Percentage of max possible) in two digits (XX for 100%)") { @Override public String get(Pokemon p) { - return Utilities.percentageWithTwoCharacters(PokemonUtils.moveRating(p, false)); + return PokemonUtils.moveRating(p, false); } }, TYPE_1("Pokémon Type 1 abbreviated (Ghost = Gh)") { diff --git a/src/me/corriekay/pokegoutil/utils/pokemon/PokemonUtils.java b/src/me/corriekay/pokegoutil/utils/pokemon/PokemonUtils.java index 3ffc48e8..56484998 100644 --- a/src/me/corriekay/pokegoutil/utils/pokemon/PokemonUtils.java +++ b/src/me/corriekay/pokegoutil/utils/pokemon/PokemonUtils.java @@ -3,6 +3,8 @@ import POGOProtos.Enums.PokemonMoveOuterClass.PokemonMove; import com.pokegoapi.api.player.Team; import com.pokegoapi.api.pokemon.*; +import me.corriekay.pokegoutil.utils.ConfigKey; +import me.corriekay.pokegoutil.utils.ConfigNew; import me.corriekay.pokegoutil.utils.Utilities; import org.apache.commons.lang3.StringUtils; @@ -13,6 +15,18 @@ private PokemonUtils() { /* Prevent initializing this class */ } public static final long GYM_OFFENSE_MAX = 510_419L; public static final long GYM_DEFENSE_MAX = 9_530_079_725L; + public static double ivRating(Pokemon p) { + if (ConfigNew.getConfig().getBool(ConfigKey.ALTERNATIVE_IV_CALCULATION)) { + PokemonMeta meta = p.getMeta(); + double cpMax = (meta.getBaseAttack() + 15) * Math.pow(meta.getBaseDefense() + 15, 0.5) * Math.pow(meta.getBaseStamina() + 15, 0.5); + double cpMin = meta.getBaseAttack() * Math.pow(meta.getBaseDefense(), 0.5) * Math.pow(meta.getBaseStamina(), 0.5); + double cpIv = (meta.getBaseAttack() + p.getIndividualAttack()) * Math.pow(meta.getBaseDefense() + p.getIndividualDefense(), 0.5) * Math.pow(meta.getBaseStamina() + p.getIndividualStamina(), 0.5); + return (cpIv - cpMin) / (cpMax - cpMin); + } else { + return (p.getIndividualAttack() + p.getIndividualDefense() + p.getIndividualStamina()) / 45.0; + } + } + public static String convertTeamColorToName(int teamValue) { Team[] teams = Team.values(); @@ -24,7 +38,7 @@ public static String convertTeamColorToName(int teamValue) { return "UNKNOWN_TEAM"; } - public static double moveRating(Pokemon p, boolean primary) { + public static String moveRating(Pokemon p, boolean primary) { PokemonMeta pMeta = p.getMeta(); double highestDps = 0; @@ -36,7 +50,7 @@ public static double moveRating(Pokemon p, boolean primary) { // Now rate it double currentDps = dpsForMove(p, primary); - return Utilities.percentage(currentDps / highestDps); + return Utilities.percentageWithTwoCharacters(currentDps, highestDps); } public static double dpsForMove(Pokemon p, boolean primary) { @@ -65,8 +79,8 @@ private static double dpsForMove(Pokemon p, PokemonMove move, boolean primary) { * * @param p A Pokemon object * @return Rating of a Pokemon's overall attacking power considering damage, health & defense - * @see https://www.reddit.com/r/TheSilphRoad/comments/4vcobt/posthotfix_pokemon_go_full_moveset_rankings/ - * @see i607ch00 + * @link https://www.reddit.com/r/TheSilphRoad/comments/4vcobt/posthotfix_pokemon_go_full_moveset_rankings/ + * @link i607ch00 */ public static long duelAbility(Pokemon p) { return PokemonUtils.gymOffense(p) * PokemonUtils.tankiness(p); @@ -78,8 +92,8 @@ public static long duelAbility(Pokemon p) { * * @param p A Pokemon object * @return Rating of a Pokemon's pure offensive ability over time considering move set - * @see https://www.reddit.com/r/TheSilphRoad/comments/4vcobt/posthotfix_pokemon_go_full_moveset_rankings/ - * @see i607ch00 + * @link https://www.reddit.com/r/TheSilphRoad/comments/4vcobt/posthotfix_pokemon_go_full_moveset_rankings/ + * @link i607ch00 */ public static long gymOffense(Pokemon p) { double gymOffense = Math.max(PokemonUtils.dpsForMove(p, true) * 100, PokemonUtils.weaveDPS(p, 0)) * (p.getMeta().getBaseAttack() + p.getIndividualAttack()); @@ -92,8 +106,8 @@ public static long gymOffense(Pokemon p) { * * @param p A Pokemon object * @return Rating of a Pokemon's AI controlled gym defense over time considering move set - * @see https://www.reddit.com/r/TheSilphRoad/comments/4vcobt/posthotfix_pokemon_go_full_moveset_rankings/ - * @see i607ch00 + * @link https://www.reddit.com/r/TheSilphRoad/comments/4vcobt/posthotfix_pokemon_go_full_moveset_rankings/ + * @link i607ch00 */ public static long gymDefense(Pokemon p) { double gymDefense = PokemonUtils.weaveDPS(p, 2000) * (p.getMeta().getBaseAttack() + p.getIndividualAttack()) * PokemonUtils.tankiness(p); @@ -108,8 +122,8 @@ public static long gymDefense(Pokemon p) { * * @param p A Pokemon object * @return Rating of a Pokemon's tankiness :) - * @see https://www.reddit.com/r/TheSilphRoad/comments/4vcobt/posthotfix_pokemon_go_full_moveset_rankings/ - * @see i607ch00 + * @link https://www.reddit.com/r/TheSilphRoad/comments/4vcobt/posthotfix_pokemon_go_full_moveset_rankings/ + * @link i607ch00 */ public static long tankiness(Pokemon p) { return (p.getMeta().getBaseStamina() + p.getIndividualStamina()) * (p.getMeta().getBaseDefense() + p.getIndividualDefense()); @@ -124,8 +138,8 @@ public static long tankiness(Pokemon p) { * @param p A Pokemon object * @param additionalDelay Allow a delay in milliseconds for gym offense (0ms) vs gym defense (2000ms) * @return Damage over 100 seconds for a Pokemon's moveset - * @see https://www.reddit.com/r/TheSilphRoad/comments/4vcobt/posthotfix_pokemon_go_full_moveset_rankings/ - * @see i607ch00 + * @link https://www.reddit.com/r/TheSilphRoad/comments/4vcobt/posthotfix_pokemon_go_full_moveset_rankings/ + * @link i607ch00 */ public static double weaveDPS(Pokemon p, Integer additionalDelay) { double critDamageBonus = 0.5; diff --git a/src/me/corriekay/pokegoutil/windows/MenuBar.java b/src/me/corriekay/pokegoutil/windows/MenuBar.java index 80c0cf75..124f8cc4 100644 --- a/src/me/corriekay/pokegoutil/windows/MenuBar.java +++ b/src/me/corriekay/pokegoutil/windows/MenuBar.java @@ -66,6 +66,11 @@ public MenuBar(PokemonGo go) { includeFamily.addItemListener(e -> config.setBool(ConfigKey.INCLUDE_FAMILY, includeFamily.isSelected())); settings.add(includeFamily); + JCheckBoxMenuItem alternativeIVCalculation = new JCheckBoxMenuItem("Use Alternative IV Calculation (weighted stats)"); + alternativeIVCalculation.setSelected(config.getBool(ConfigKey.ALTERNATIVE_IV_CALCULATION)); + alternativeIVCalculation.addItemListener(e -> config.setBool(ConfigKey.ALTERNATIVE_IV_CALCULATION, alternativeIVCalculation.isSelected())); + settings.add(alternativeIVCalculation); + add(settings); // Help menu diff --git a/src/me/corriekay/pokegoutil/windows/PokemonTab.java b/src/me/corriekay/pokegoutil/windows/PokemonTab.java index 0ea0d1aa..75c7ee9c 100644 --- a/src/me/corriekay/pokegoutil/windows/PokemonTab.java +++ b/src/me/corriekay/pokegoutil/windows/PokemonTab.java @@ -575,7 +575,7 @@ private JPanel _buildPanelForOperation(String operation, ArrayList poke pokes.forEach(p -> { String str = PokeHandler.getLocalPokeName(p) + " - CP: " + p.getCp() + ", IV: " - + Utilities.percentage(p.getIvRatio()) + "%"; + + Utilities.percentageWithTwoCharacters(PokemonUtils.ivRating(p)) + "%"; switch (operation) { case "Evolve": str += " Cost: " + p.getCandiesToEvolve(); @@ -700,7 +700,7 @@ private static class PokemonTable extends JTable { * 0 String - Nickname * 1 Integer - Pokemon Number * 2 String - Type / Pokemon - * 3 Double - IV % + * 3 String(Percentage) - IV Rating * 4 Double - Level * 5 Integer - Attack * 6 Integer - Defense @@ -724,8 +724,8 @@ private static class PokemonTable extends JTable { * 24 Long - duelAbility * 25 Integer - gymOffense * 26 Integer - gymDefense - * 27 Double - Move 1 Rating - * 28 Double - Move 2 Rating + * 27 String(Percentage) - Move 1 Rating + * 28 String(Percentage) - Move 2 Rating */ ConfigNew config = ConfigNew.getConfig(); @@ -753,7 +753,7 @@ private void constructNewTableModel(PokemonGo go, List pokes) { PokemonTableModel ptm = new PokemonTableModel(go, pokes, this); setModel(ptm); TableRowSorter trs = new TableRowSorter<>(getModel()); - Comparator c = (i1, i2) -> Math.round(i1 - i2); + Comparator c = (i1, i2) -> i1 - i2; Comparator cDouble = (d1, d2) -> (int) (d1 - d2); Comparator cDate = (date1, date2) -> DateHelper.fromString(date1).compareTo(DateHelper.fromString(date2)); Comparator cNullableInt = (s1, s2) -> { @@ -763,9 +763,14 @@ private void constructNewTableModel(PokemonGo go, List pokes) { s2 = "0"; return Integer.parseInt(s1) - Integer.parseInt(s2); }; + Comparator cPercentageWithTwoCharacters = (s1, s2) -> { + int i1 = ("XX".equals(s1)) ? 100 : Integer.parseInt(s1); + int i2 = ("XX".equals(s2)) ? 100 : Integer.parseInt(s2); + return i1 - i2; + }; Comparator cLong = (l1, l2) -> l2.compareTo(l1); trs.setComparator(0, c); - trs.setComparator(3, cDouble); + trs.setComparator(3, cPercentageWithTwoCharacters); trs.setComparator(4, cDouble); trs.setComparator(5, c); trs.setComparator(6, c); @@ -783,8 +788,8 @@ private void constructNewTableModel(PokemonGo go, List pokes) { trs.setComparator(24, cLong); trs.setComparator(25, cLong); trs.setComparator(26, cLong); - trs.setComparator(27, cDouble); - trs.setComparator(28, cDouble); + trs.setComparator(27, cPercentageWithTwoCharacters); + trs.setComparator(28, cPercentageWithTwoCharacters); setRowSorter(trs); List sortKeys = new ArrayList<>(); sortKeys.add(new SortKey(sortColIndex1, sortOrder1)); @@ -827,9 +832,9 @@ private static class PokemonTableModel extends AbstractTableModel { private final ArrayList pokeCol = new ArrayList<>(); private final ArrayList numIdCol = new ArrayList<>();//0 private final ArrayList nickCol = new ArrayList<>(),//1 - speciesCol = new ArrayList<>();//2 - private final ArrayList ivCol = new ArrayList<>(),//3 - levelCol = new ArrayList<>();//4 + speciesCol = new ArrayList<>(),//2 + ivCol = new ArrayList<>();//3 + private final ArrayList levelCol = new ArrayList<>();//4 private final ArrayList atkCol = new ArrayList<>(),//5 defCol = new ArrayList<>(),//6 stamCol = new ArrayList<>();//7 @@ -852,7 +857,7 @@ private static class PokemonTableModel extends AbstractTableModel { private final ArrayList duelAbilityCol = new ArrayList<>();//24 private final ArrayList gymOffenseCol = new ArrayList<>();//25 private final ArrayList gymDefenseCol = new ArrayList<>();//26 - private final ArrayList move1RatingCol = new ArrayList<>(),//27 + private final ArrayList move1RatingCol = new ArrayList<>(),//27 move2RatingCol = new ArrayList<>();//28 @Deprecated @@ -866,7 +871,7 @@ private PokemonTableModel(PokemonGo go, List pokes, PokemonTable pt) { speciesCol.add(i.getValue(), PokeHandler.getLocalPokeName(p)); levelCol.add(i.getValue(), (double) p.getLevel()); - ivCol.add(i.getValue(), Utilities.percentage(p.getIvRatio())); + ivCol.add(i.getValue(), Utilities.percentageWithTwoCharacters(PokemonUtils.ivRating(p))); cpCol.add(i.getValue(), p.getCp()); atkCol.add(i.getValue(), p.getIndividualAttack()); defCol.add(i.getValue(), p.getIndividualDefense()); From ff1f5cf329927a543807d86e238f3365a2e47d51 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Tue, 16 Aug 2016 02:44:38 +0200 Subject: [PATCH 2/2] Refreshes List on settings change --- src/me/corriekay/pokegoutil/windows/MenuBar.java | 14 +++++++++++--- .../pokegoutil/windows/PokemonGoMainWindow.java | 5 +++-- .../corriekay/pokegoutil/windows/PokemonTab.java | 4 ++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/me/corriekay/pokegoutil/windows/MenuBar.java b/src/me/corriekay/pokegoutil/windows/MenuBar.java index 124f8cc4..30a6f185 100644 --- a/src/me/corriekay/pokegoutil/windows/MenuBar.java +++ b/src/me/corriekay/pokegoutil/windows/MenuBar.java @@ -18,7 +18,7 @@ public class MenuBar extends JMenuBar { private final PokemonGo go; private ConfigNew config = ConfigNew.getConfig(); - public MenuBar(PokemonGo go) { + public MenuBar(PokemonGo go, PokemonTab pokemonTab) { this.go = go; JMenu file, settings, help; @@ -63,12 +63,20 @@ public MenuBar(PokemonGo go) { JCheckBoxMenuItem includeFamily = new JCheckBoxMenuItem("Include Family On Searchbar"); includeFamily.setSelected(config.getBool(ConfigKey.INCLUDE_FAMILY)); - includeFamily.addItemListener(e -> config.setBool(ConfigKey.INCLUDE_FAMILY, includeFamily.isSelected())); + includeFamily.addItemListener(e -> { + config.setBool(ConfigKey.INCLUDE_FAMILY, includeFamily.isSelected()); + if (!pokemonTab.getSelectedPokemon().isEmpty()) { + SwingUtilities.invokeLater(pokemonTab::refreshList); + } + }); settings.add(includeFamily); JCheckBoxMenuItem alternativeIVCalculation = new JCheckBoxMenuItem("Use Alternative IV Calculation (weighted stats)"); alternativeIVCalculation.setSelected(config.getBool(ConfigKey.ALTERNATIVE_IV_CALCULATION)); - alternativeIVCalculation.addItemListener(e -> config.setBool(ConfigKey.ALTERNATIVE_IV_CALCULATION, alternativeIVCalculation.isSelected())); + alternativeIVCalculation.addItemListener(e -> { + config.setBool(ConfigKey.ALTERNATIVE_IV_CALCULATION, alternativeIVCalculation.isSelected()); + SwingUtilities.invokeLater(pokemonTab::refreshList); + }); settings.add(alternativeIVCalculation); add(settings); diff --git a/src/me/corriekay/pokegoutil/windows/PokemonGoMainWindow.java b/src/me/corriekay/pokegoutil/windows/PokemonGoMainWindow.java index 83f0616f..14d08e70 100644 --- a/src/me/corriekay/pokegoutil/windows/PokemonGoMainWindow.java +++ b/src/me/corriekay/pokegoutil/windows/PokemonGoMainWindow.java @@ -70,8 +70,9 @@ public void componentMoved(ComponentEvent e) { int posy = config.getInt(ConfigKey.WINDOW_POS_Y, pt.y); setLocation(posx, posy); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setJMenuBar(new MenuBar(go)); - tab.add("Pokémon", new PokemonTab(go)); + PokemonTab pokemonTab = new PokemonTab(go); + setJMenuBar(new MenuBar(go, pokemonTab)); + tab.add("Pokémon", pokemonTab); add(tab, BorderLayout.CENTER); diff --git a/src/me/corriekay/pokegoutil/windows/PokemonTab.java b/src/me/corriekay/pokegoutil/windows/PokemonTab.java index 75c7ee9c..0df4e780 100644 --- a/src/me/corriekay/pokegoutil/windows/PokemonTab.java +++ b/src/me/corriekay/pokegoutil/windows/PokemonTab.java @@ -597,7 +597,7 @@ private JPanel _buildPanelForOperation(String operation, ArrayList poke return panel; } - private ArrayList getSelectedPokemon() { + public ArrayList getSelectedPokemon() { ArrayList pokes = new ArrayList<>(); PokemonTableModel model = (PokemonTableModel) pt.getModel(); for (int i : pt.getSelectedRows()) { @@ -609,7 +609,7 @@ private ArrayList getSelectedPokemon() { return pokes; } - private void refreshList() { + public void refreshList() { List pokes = new ArrayList<>(); String search = searchBar.getText().replaceAll(" ", "").replaceAll("_", "").replaceAll("snek", "ekans").toLowerCase(); String[] terms = search.split(";");