use of POGOProtos.Networking.Responses.UseItemPotionResponseOuterClass.UseItemPotionResponse in project PokeGOAPI-Java by Grover-c13.
the class Pokemon method usePotion.
/**
* use a potion on that pokemon. Will check if there is enough potions and if the pokemon need
* to be healed.
*
* @param itemId {@link ItemId} of the potion to use.
* @return Result, ERROR_CANNOT_USE if the requirements aren't met
* @throws RequestFailedException if an exception occurred while sending requests
*/
public UseItemPotionResponse.Result usePotion(ItemId itemId) throws RequestFailedException {
Item potion = api.inventories.itemBag.getItem(itemId);
// some sanity check, to prevent wrong use of this call
if (!potion.isPotion() || potion.count < 1 || !isInjured())
return UseItemPotionResponse.Result.ERROR_CANNOT_USE;
UseItemPotionMessageOuterClass.UseItemPotionMessage reqMsg = UseItemPotionMessageOuterClass.UseItemPotionMessage.newBuilder().setItemId(itemId).setPokemonId(getId()).build();
ServerRequest serverRequest = new ServerRequest(RequestType.USE_ITEM_POTION, reqMsg);
api.requestHandler.sendServerRequests(serverRequest, true);
UseItemPotionResponse response;
try {
response = UseItemPotionResponse.parseFrom(serverRequest.getData());
if (response.getResult() == UseItemPotionResponse.Result.SUCCESS) {
potion.setCount(potion.count - 1);
this.stamina = response.getStamina();
}
return response.getResult();
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
}
Aggregations