Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[newFeature] setFavoritePokemon #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SonnyX opened this issue Jul 25, 2016 · 5 comments
Closed

[newFeature] setFavoritePokemon #219

SonnyX opened this issue Jul 25, 2016 · 5 comments

Comments

@SonnyX
Copy link
Contributor

SonnyX commented Jul 25, 2016

Description:
Add a method to set the Pokemon as a favorite.

Expected behavior:
When true it becomes favorite, when false it clears it.

Should be placed at Pokemon.java, please add it without breaking checkStyleMain :)

    /**
    * Function to mark the pokemon as favorite or not.
    *
    * @param markFavorite Mark Pokemon as Favorite?
    * @return the SetFavoritePokemonResponse.Result
    * @throws LoginFailedException  the login failed exception
    * @throws RemoteServerException the remote server exception
    */
    public SetFavoritePokemonResponse.Result setFavoritePokemon(boolean markFavorite) 
            throws LoginFailedException, RemoteServerException {
        SetFavoritePokemonMessage reqMsg = SetFavoritePokemonMessage.newBuilder()
                .setPokemonId(getId())
                .setIsFavorite(markFavorite)
                .build();

        ServerRequest serverRequest = new ServerRequest(RequestType.SET_FAVORITE_POKEMON, reqMsg);
        pgo.getRequestHandler().sendServerRequests(serverRequest);

        SetFavoritePokemonResponse response;
        try {
            response = SetFavoritePokemonResponse.parseFrom(serverRequest.getData());
        } catch (InvalidProtocolBufferException e) {
            throw new RemoteServerException(e);
        }

        pgo.getInventories().getPokebank().removePokemon(this);
        pgo.getInventories().updateInventories();

        return response.getResult();
    }
@Jari27
Copy link
Contributor

Jari27 commented Jul 25, 2016

If you tested it and it works, why not submit a pull request?

@SonnyX
Copy link
Contributor Author

SonnyX commented Jul 25, 2016

Couldn't get it to pass checkStyleMain at first, now locally it succeeds. #222

@Jari27
Copy link
Contributor

Jari27 commented Jul 25, 2016

Why do you need to call pgo.getInventories().getPokebank().removePokemon(this);?

Also, maybe add a function isFavorite()?

@SonnyX
Copy link
Contributor Author

SonnyX commented Jul 25, 2016

@sadye I already saw a function named getFavorite() with most likely the same bahavior.
Also I called the removePokemon(this); you named above because the similar function renamePokemon(NickName) uses it as well, didn't put too much thought into it.

@vmarchaud
Copy link
Contributor

getFavorite() is just a isFavorite(), dont hesite to make a PR to deprecate getFavorite() and create a isFavorite().
since the method is merged in #222 i close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants