示例#1
0
  static List<Pokemon> decodeBoxPokemonList(byte[] bytes) {
    final int numPokemon = bytes[0];
    if (numPokemon < 0 || numPokemon > MAX_BOX_SLOTS) {
      return Collections.emptyList();
    }

    final List<Pokemon> pokemon = new ArrayList<>(numPokemon);
    final int capacity = 20;
    for (int i = 0; i < numPokemon; i++) {
      final PokemonBuilder pokemonBuilder =
          decodeBoxPokemon(
              ByteUtil.getBytes(bytes, capacity + 2 + i * BOX_POKEMON_LENGTH, BOX_POKEMON_LENGTH));

      final int trainerNameOffset =
          1 + (capacity + 1) + capacity * BOX_POKEMON_LENGTH + i * NAME_LENGTH;
      pokemonBuilder.setOriginalTrainerName(
          CharacterDecoder.decodeCharacters(
              ByteUtil.getBytes(bytes, trainerNameOffset, NAME_LENGTH)));
      final int nicknameOffset =
          1
              + (capacity + 1)
              + capacity * BOX_POKEMON_LENGTH
              + capacity * NAME_LENGTH
              + i * NAME_LENGTH;
      pokemonBuilder.setNickname(
          CharacterDecoder.decodeCharacters(ByteUtil.getBytes(bytes, nicknameOffset, NAME_LENGTH)));

      pokemon.add(pokemonBuilder.createPokemon());
    }
    return pokemon;
  }
示例#2
0
  static List<Pokemon> decodePokemonPartyList(byte[] bytes) {
    final int numPokemon = bytes[0];
    final List<Pokemon> pokemon = new ArrayList<>(numPokemon);
    final int capacity = 6;
    for (int i = 0; i < numPokemon; i++) {
      final PokemonBuilder pokemonBuilder =
          decodePartyPokemon(
              ByteUtil.getBytes(
                  bytes, capacity + 2 + i * PARTY_POKEMON_LENGTH, PARTY_POKEMON_LENGTH));

      final int trainerNameOffset =
          1 + (capacity + 1) + capacity * PARTY_POKEMON_LENGTH + i * NAME_LENGTH;
      pokemonBuilder.setOriginalTrainerName(
          CharacterDecoder.decodeCharacters(
              ByteUtil.getBytes(bytes, trainerNameOffset, NAME_LENGTH)));
      final int nicknameOffset =
          1
              + (capacity + 1)
              + capacity * PARTY_POKEMON_LENGTH
              + capacity * NAME_LENGTH
              + i * NAME_LENGTH;
      pokemonBuilder.setNickname(
          CharacterDecoder.decodeCharacters(ByteUtil.getBytes(bytes, nicknameOffset, NAME_LENGTH)));

      pokemon.add(pokemonBuilder.createPokemon());
    }
    return pokemon;
  }