use of POGOProtos.Networking.Requests.Messages.UseItemReviveMessageOuterClass.UseItemReviveMessage 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.inventories.itemBag.getItem(itemId);
if (!item.isRevive() || item.count < 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.requestHandler.sendServerRequests(serverRequest, true);
UseItemReviveResponse response;
try {
response = UseItemReviveResponse.parseFrom(serverRequest.getData());
if (response.getResult() == UseItemReviveResponse.Result.SUCCESS) {
item.setCount(item.count - 1);
this.stamina = response.getStamina();
}
return response.getResult();
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
}
Aggregations