Skip to content

Commit

Permalink
Fix name length limit + Reworked patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfsblvt committed Aug 11, 2016
1 parent 33f1ea0 commit 4606f9d
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 51 additions & 9 deletions src/me/corriekay/pokegoutil/utils/pokemon/PokeHandler.java
Expand Up @@ -3,6 +3,8 @@
import POGOProtos.Networking.Responses.NicknamePokemonResponseOuterClass.NicknamePokemonResponse;
import com.pokegoapi.api.pokemon.Pokemon;
import com.pokegoapi.api.pokemon.PokemonMeta;
import com.pokegoapi.api.pokemon.PokemonMoveMeta;
import com.pokegoapi.api.pokemon.PokemonMoveMetaRegistry;
import com.pokegoapi.exceptions.LoginFailedException;
import com.pokegoapi.exceptions.RemoteServerException;
import com.pokegoapi.util.PokeNames;
Expand All @@ -17,6 +19,8 @@
import java.util.regex.Pattern;

public class PokeHandler {
public static final int MAX_NICKNAME_LENGTH = 12;

private ArrayList<Pokemon> mons;

public PokeHandler(Pokemon pokemon) {
Expand Down Expand Up @@ -55,7 +59,7 @@ private static String generatePokemonNickname(String pattern, Pokemon pokemon, P
// Do nothing, nothing to replace
}
}
return pokeNick;
return StringUtils.substring(pokeNick, 0, MAX_NICKNAME_LENGTH);
}

/***
Expand All @@ -74,7 +78,7 @@ public static NicknamePokemonResponse.Result renameWithPattern(String pattern, P
* it every time we process a pokemon. This should save resources.
*/
private static Pattern getRenamePattern() {
return Pattern.compile("(%([a-zA-Z_]+)%)");
return Pattern.compile("(%([a-zA-Z0-9_]+)%)");
}

/***
Expand Down Expand Up @@ -192,6 +196,18 @@ public String get(Pokemon p) {
return getLocalPokeName(p);
}
},
NAME_4("Pokémon Name (First four letters)") {
@Override
public String get(Pokemon p) {
return StringUtils.substring(getLocalPokeName(p), 0, 4);
}
},
NAME_6("Pokémon Name (First six letters)") {
@Override
public String get(Pokemon p) {
return StringUtils.substring(getLocalPokeName(p), 0, 6);
}
},
CP("Combat Points") {
@Override
public String get(Pokemon p) {
Expand All @@ -216,10 +232,16 @@ public String get(Pokemon p) {
return String.valueOf(Math.round(p.getIvRatio() * 100 * 100) / 100.0);
}
},
IV("IV Values (All three, like \"15/15/15\")") {
IV_RATING_INT("IV Rating (Rounded to integer)") {
@Override
public String get(Pokemon p) {
return String.valueOf(Math.round(p.getIvRatio() * 100));
}
},
IV_HEX("IV Values in hexadecimal, like \"9FA\" (F = 15)") {
@Override
public String get(Pokemon p) {
return p.getIndividualAttack() + "/" + p.getIndividualDefense() + "/" + p.getIndividualStamina();
return (Integer.toHexString(p.getIndividualAttack()) + Integer.toHexString(p.getIndividualDefense()) + Integer.toHexString(p.getIndividualStamina())).toUpperCase();
}
},
IV_ATT("IV Attack") {
Expand Down Expand Up @@ -250,22 +272,42 @@ public String get(Pokemon p) {
return String.valueOf(PokemonCpUtils.getMaxCp(attack, defense, stamina));
}
},
TYPE1("Pokémon Type 1") {
MOVE_TYPES("Types of both moves, displayed with first letter. (Fire, Normal = FN)") {
@Override
public String get(Pokemon p) {
PokemonMoveMeta pm1 = PokemonMoveMetaRegistry.getMeta(p.getMove1());
PokemonMoveMeta pm2 = PokemonMoveMetaRegistry.getMeta(p.getMove2());
return pm1.toString().toUpperCase().charAt(0) + "" + pm2.toString().toUpperCase().charAt(0);

This comment has been minimized.

Copy link
@QuadTog

QuadTog Aug 11, 2016

Move Types should pull the first two chars. Otherwise we'll have issues with types like Fighting, Flying, Fire and Fairy = F.

This fix still means we'll have issues with Fire and Ground but those can be fixed by taking the first and last char from the type string: Fire = Fe, Ground = Gd.

This comment has been minimized.

Copy link
@Wolfsblvt

Wolfsblvt Aug 11, 2016

Author Owner

Can you submit an issue about it? A single issue please, just with that statement here. Then we can fix it.

This comment has been minimized.

Copy link
@Wolfsblvt

Wolfsblvt Aug 11, 2016

Author Owner

Don't mind, i have done it already. #199

}
},
DPS_1("Damage per second for Move 1") {
@Override
public String get(Pokemon p) {
return String.valueOf(Math.round(PokemonUtils.dpsForMove1(p)));
}
},
DPS_2("Damage per second for Move 2") {
@Override
public String get(Pokemon p) {
return String.valueOf(Math.round(PokemonUtils.dpsForMove2(p)));
}
},
TYPE_1("Pokémon Type 1 (First two letters)") {
@Override
public String get(Pokemon p) {
return StringUtils.capitalize(p.getMeta().getType1().toString().toLowerCase());
return StringUtils.substring(StringUtils.capitalize(p.getMeta().getType1().toString().toLowerCase()), 0, 2);
}
},
TYPE2("Pokémon Type 2") {
TYPE_2("Pokémon Type 2 (First two letters)") {
@Override
public String get(Pokemon p) {
return StringUtils.capitalize(p.getMeta().getType2().toString().toLowerCase().replaceAll("none", ""));
return StringUtils.substring(StringUtils.capitalize(p.getMeta().getType2().toString().toLowerCase().replaceAll("none", "")), 0, 2);
}
},
ID("Pokédex Id") {
@Override
public String get(Pokemon p) {
return String.valueOf(p.getId());
return String.valueOf(p.getPokemonId().getNumber());
}
};

Expand Down
20 changes: 20 additions & 0 deletions src/me/corriekay/pokegoutil/utils/pokemon/PokemonUtils.java
@@ -1,6 +1,10 @@
package me.corriekay.pokegoutil.utils.pokemon;

import POGOProtos.Enums.PokemonMoveOuterClass.PokemonMove;
import com.pokegoapi.api.player.Team;
import com.pokegoapi.api.pokemon.Pokemon;
import com.pokegoapi.api.pokemon.PokemonMoveMeta;
import com.pokegoapi.api.pokemon.PokemonMoveMetaRegistry;
import org.apache.commons.lang3.StringUtils;

public final class PokemonUtils {
Expand All @@ -16,4 +20,20 @@ public static String convertTeamColorToName(int teamValue) {
}
return "UNKNOWN_TEAM";
}

public static Double dpsForMove1(Pokemon p) {
PokemonMoveMeta pm1 = PokemonMoveMetaRegistry.getMeta(p.getMove1());
Double dps1 = (double) pm1.getPower() / (double) pm1.getTime() * 1000;
if (p.getMeta().getType1().equals(pm1.getType()) || p.getMeta().getType2().equals(pm1.getType()))
dps1 = dps1 * 1.25;
return dps1;
}

public static Double dpsForMove2(Pokemon p) {
PokemonMoveMeta pm2 = PokemonMoveMetaRegistry.getMeta(p.getMove2());
Double dps2 = (double) pm2.getPower() / (double) (pm2.getTime() + 500) * 1000;
if (p.getMeta().getType1().equals(pm2.getType()) || p.getMeta().getType2().equals(pm2.getType()))
dps2 = dps2 * 1.25;
return dps2;
}
}
11 changes: 3 additions & 8 deletions src/me/corriekay/pokegoutil/windows/PokemonTab.java
Expand Up @@ -16,6 +16,7 @@
import me.corriekay.pokegoutil.utils.pokemon.PokeHandler;
import me.corriekay.pokegoutil.utils.pokemon.PokemonCpUtils;
import me.corriekay.pokegoutil.utils.helpers.DateHelper;
import me.corriekay.pokegoutil.utils.pokemon.PokemonUtils;
import me.corriekay.pokegoutil.utils.ui.GhostText;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
Expand Down Expand Up @@ -687,14 +688,8 @@ private PokemonTableModel(PokemonGo go, List<Pokemon> pokes, PokemonTable pt) {
type1Col.add(i.getValue(), StringUtils.capitalize(p.getMeta().getType1().toString().toLowerCase()));
type2Col.add(i.getValue(), StringUtils.capitalize(p.getMeta().getType2().toString().toLowerCase().replaceAll("none", "")));

PokemonMoveMeta pm1 = PokemonMoveMetaRegistry.getMeta(p.getMove1());
PokemonMoveMeta pm2 = PokemonMoveMetaRegistry.getMeta(p.getMove2());
Double dps1 = (double) pm1.getPower() / (double) pm1.getTime() * 1000;
Double dps2 = (double) pm2.getPower() / (double) (pm2.getTime() + 500) * 1000;
if (p.getMeta().getType1().equals(pm1.getType()) || p.getMeta().getType2().equals(pm1.getType()))
dps1 = dps1 * 1.25;
if (p.getMeta().getType1().equals(pm2.getType()) || p.getMeta().getType2().equals(pm2.getType()))
dps2 = dps2 * 1.25;
Double dps1 = PokemonUtils.dpsForMove1(p);
Double dps2 = PokemonUtils.dpsForMove2(p);

move1Col.add(i.getValue(), WordUtils.capitalize(p.getMove1().toString().toLowerCase().replaceAll("_fast", "").replaceAll("_", " ")) + " (" + String.format("%.2f", dps1) + "dps)");
move2Col.add(i.getValue(), WordUtils.capitalize(p.getMove2().toString().toLowerCase().replaceAll("_", " ")) + " (" + String.format("%.2f", dps2) + "dps)");
Expand Down

0 comments on commit 4606f9d

Please sign in to comment.