forked from Grover-c13/PokeGOAPI-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
343 additions
and
69 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
src/main/java/com/pokegoapi/api/inventory/EggIncubator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.pokegoapi.api.inventory; | ||
|
||
import POGOProtos.Inventory.EggIncubatorOuterClass; | ||
import POGOProtos.Networking.Requests.Messages.UseItemEggIncubatorMessageOuterClass.UseItemEggIncubatorMessage; | ||
import POGOProtos.Networking.Requests.RequestTypeOuterClass; | ||
import POGOProtos.Networking.Responses.UseItemEggIncubatorResponseOuterClass.UseItemEggIncubatorResponse; | ||
import com.google.protobuf.InvalidProtocolBufferException; | ||
import com.pokegoapi.api.PokemonGo; | ||
import com.pokegoapi.api.pokemon.EggPokemon; | ||
import com.pokegoapi.exceptions.LoginFailedException; | ||
import com.pokegoapi.exceptions.RemoteServerException; | ||
import com.pokegoapi.main.ServerRequest; | ||
import lombok.Getter; | ||
|
||
public class EggIncubator { | ||
private final EggIncubatorOuterClass.EggIncubator proto; | ||
private final PokemonGo pgo; | ||
@Getter | ||
private boolean inUse = false; | ||
|
||
/** | ||
* Create new EggIncubator with given proto. | ||
* | ||
* @param pgo the api | ||
* @param proto the proto | ||
*/ | ||
public EggIncubator(PokemonGo pgo, EggIncubatorOuterClass.EggIncubator proto) { | ||
this.pgo = pgo; | ||
this.proto = proto; | ||
this.inUse = proto.getPokemonId() != 0; | ||
} | ||
|
||
/** | ||
* Returns the remaining uses. | ||
* | ||
* @return uses remaining | ||
*/ | ||
public int getUsesRemaining() { | ||
return proto.getUsesRemaining(); | ||
} | ||
|
||
/** | ||
* Hatch an egg. | ||
* | ||
* @param egg the egg | ||
* @return status of putting egg in incubator | ||
* @throws RemoteServerException the remote server exception | ||
* @throws LoginFailedException the login failed exception | ||
*/ | ||
public UseItemEggIncubatorResponse.Result hatchEgg(EggPokemon egg) | ||
throws LoginFailedException, RemoteServerException { | ||
if (!egg.getIsEgg()) { | ||
return null; | ||
} | ||
UseItemEggIncubatorMessage reqMsg = UseItemEggIncubatorMessage.newBuilder() | ||
.setItemId(proto.getId()) | ||
.setPokemonId(egg.getId()) | ||
.build(); | ||
|
||
ServerRequest serverRequest = new ServerRequest(RequestTypeOuterClass.RequestType.USE_ITEM_EGG_INCUBATOR, reqMsg); | ||
pgo.getRequestHandler().sendServerRequests(serverRequest); | ||
|
||
UseItemEggIncubatorResponse response; | ||
try { | ||
response = UseItemEggIncubatorResponse.parseFrom(serverRequest.getData()); | ||
} catch (InvalidProtocolBufferException e) { | ||
throw new RemoteServerException(e); | ||
} | ||
|
||
pgo.getInventories().updateInventories(true); | ||
|
||
this.inUse = true; | ||
|
||
return response.getResult(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,8 +54,6 @@ public boolean test(Pokemon testPokemon) { | |
} | ||
} | ||
|
||
|
||
|
||
/** | ||
* Gets pokemon by pokemon id. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.