use of POGOProtos.Networking.Responses.UseItemReviveResponseOuterClass.UseItemReviveResponse in project PokeGOAPI-Java by Grover-c13.
the class Pokemon method useRevive.
/**
* Use a revive item on the pokemon. Will check if there is enough revive & if the pokemon need
* to be revived.
*
* @param itemId {@link ItemId} of the Revive to use.
* @return Result, ERROR_CANNOT_USE if the requirements aren't met
* @throws RequestFailedException if an exception occurred while sending requests
*/
public UseItemReviveResponse.Result useRevive(ItemId itemId) throws RequestFailedException {
Item item = api.getInventories().getItemBag().getItem(itemId);
if (!item.isRevive() || item.getCount() < 1 || !isFainted())
return UseItemReviveResponse.Result.ERROR_CANNOT_USE;
UseItemReviveMessage reqMsg = UseItemReviveMessage.newBuilder().setItemId(itemId).setPokemonId(getId()).build();
ServerRequest serverRequest = new ServerRequest(RequestType.USE_ITEM_REVIVE, reqMsg);
api.getRequestHandler().sendServerRequests(serverRequest, true);
UseItemReviveResponse response;
try {
response = UseItemReviveResponse.parseFrom(serverRequest.getData());
if (response.getResult() == UseItemReviveResponse.Result.SUCCESS) {
item.setCount(item.getCount() - 1);
setStamina(response.getStamina());
}
return response.getResult();
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
}
Aggregations