use of com.pokegoapi.api.listener.TutorialListener in project PokeGOAPI-Java by Grover-c13.
the class PlayerProfile method encounterTutorialComplete.
/**
* Encounter tutorial complete. In other words, catch the first Pokémon
*
* @throws RequestFailedException if an exception occurred while sending requests
*/
public void encounterTutorialComplete() throws RequestFailedException {
StarterPokemon starter = StarterPokemon.random();
List<TutorialListener> listeners = api.getListeners(TutorialListener.class);
for (TutorialListener listener : listeners) {
StarterPokemon pokemon = listener.selectStarter(api);
if (pokemon != null) {
starter = pokemon;
break;
}
}
final EncounterTutorialCompleteMessage.Builder builder = EncounterTutorialCompleteMessage.newBuilder().setPokemonId(starter.getPokemon());
ServerRequest request = new ServerRequest(RequestType.ENCOUNTER_TUTORIAL_COMPLETE, builder.build());
api.getRequestHandler().sendServerRequests(request, true);
final GetPlayerMessage getPlayerReqMsg = GetPlayerMessage.newBuilder().setPlayerLocale(playerLocale.getPlayerLocale()).build();
request = new ServerRequest(RequestType.GET_PLAYER, getPlayerReqMsg);
api.getRequestHandler().sendServerRequests(request, true);
try {
updateProfile(GetPlayerResponse.parseFrom(request.getData()));
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
}
use of com.pokegoapi.api.listener.TutorialListener in project PokeGOAPI-Java by Grover-c13.
the class PlayerProfile method setupAvatar.
/**
* Setup an avatar for the current account
*
* @throws RequestFailedException if an exception occurred while sending requests
*/
public void setupAvatar() throws RequestFailedException {
SecureRandom random = new SecureRandom();
PlayerGender gender = random.nextInt(100) % 2 == 0 ? PlayerGender.FEMALE : PlayerGender.MALE;
PlayerAvatar avatar = new PlayerAvatar(gender, random.nextInt(PlayerAvatar.getAvailableSkins()), random.nextInt(PlayerAvatar.getAvailableHair()), random.nextInt(PlayerAvatar.getAvailableShirts(gender)), random.nextInt(PlayerAvatar.getAvailablePants(gender)), random.nextInt(PlayerAvatar.getAvailableHats()), random.nextInt(PlayerAvatar.getAvailableShoes()), random.nextInt(PlayerAvatar.getAvailableEyes()), random.nextInt(PlayerAvatar.getAvailableBags(gender)));
List<TutorialListener> listeners = api.getListeners(TutorialListener.class);
for (TutorialListener listener : listeners) {
PlayerAvatar listenerAvatar = listener.selectAvatar(api);
if (listenerAvatar != null) {
avatar = listenerAvatar;
break;
}
}
final SetAvatarMessage setAvatarMessage = SetAvatarMessage.newBuilder().setPlayerAvatar(avatar.getAvatar()).build();
ServerRequest request = new ServerRequest(RequestType.SET_AVATAR, setAvatarMessage);
api.getRequestHandler().sendServerRequests(request, true);
try {
SetAvatarResponse setAvatarResponse = SetAvatarResponse.parseFrom(request.getData());
playerData = setAvatarResponse.getPlayerData();
updateProfile(playerData);
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
markTutorial(TutorialStateOuterClass.TutorialState.AVATAR_SELECTION);
api.getAssetDigest();
}
use of com.pokegoapi.api.listener.TutorialListener in project PokeGOAPI-Java by Grover-c13.
the class PlayerProfile method claimCodeName.
/**
* Setup an user name for our account
*
* @param lastFailure the last name used that was already taken; null for first try.
* @return the claimed codename
* @throws RequestFailedException if an exception occurred while sending requests
*/
public String claimCodeName(String lastFailure) throws RequestFailedException {
if (getPlayerData().getRemainingCodenameClaims() <= 0) {
throw new RuntimeException("You have no remaining codename claims!");
}
String name = randomCodenameGenerator();
List<TutorialListener> listeners = api.getListeners(TutorialListener.class);
for (TutorialListener listener : listeners) {
String listenerName = listener.claimName(api, lastFailure);
if (listenerName != null) {
name = listenerName;
break;
}
}
ClaimCodenameMessage claimCodenameMessage = ClaimCodenameMessage.newBuilder().setCodename(name).build();
ServerRequest request = new ServerRequest(RequestType.CLAIM_CODENAME, claimCodenameMessage);
api.getRequestHandler().sendServerRequests(request, true);
String updatedCodename;
try {
ClaimCodenameResponse claimCodenameResponse = ClaimCodenameResponse.parseFrom(request.getData());
if (claimCodenameResponse.getStatus() != ClaimCodenameResponse.Status.SUCCESS) {
return claimCodeName(name);
}
updatedCodename = claimCodenameResponse.getCodename();
if (claimCodenameResponse.hasUpdatedPlayer()) {
updateProfile(claimCodenameResponse.getUpdatedPlayer());
}
if (updatedCodename != null) {
markTutorial(TutorialStateOuterClass.TutorialState.NAME_SELECTION);
final GetPlayerMessage getPlayerReqMsg = GetPlayerMessage.newBuilder().setPlayerLocale(playerLocale.getPlayerLocale()).build();
request = new ServerRequest(RequestType.GET_PLAYER, getPlayerReqMsg);
api.getRequestHandler().sendServerRequests(request, true);
updateProfile(GetPlayerResponse.parseFrom(request.getData()));
}
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
return updatedCodename;
}
use of com.pokegoapi.api.listener.TutorialListener in project PokeGOAPI-Java by Grover-c13.
the class TutorialHandleExample method main.
/**
* Goes through the tutorial with custom responses.
*
* @param args args
*/
public static void main(String[] args) {
OkHttpClient http = new OkHttpClient();
final PokemonGo api = new PokemonGo(http);
try {
// Add listener to listen for all tutorial related events, must be registered before login is called,
// otherwise it will not be used
api.addListener(new TutorialListener() {
@Override
public String claimName(PokemonGo api, String lastFailure) {
//Last attempt to set a codename failed, set a random one by returning null
if (lastFailure != null) {
System.out.println("Codename \"" + lastFailure + "\" is already taken. Using random name.");
return null;
}
System.out.println("Selecting codename");
//Set the PTC name as the POGO username
return ExampleConstants.LOGIN;
}
@Override
public StarterPokemon selectStarter(PokemonGo api) {
//Catch Charmander as your starter pokemon
System.out.println("Selecting starter pokemon");
return StarterPokemon.CHARMANDER;
}
@Override
public PlayerAvatar selectAvatar(PokemonGo api) {
System.out.println("Selecting player avatar");
return new PlayerAvatar(PlayerGender.FEMALE, Avatar.Skin.YELLOW.id(), Avatar.Hair.BLACK.id(), Avatar.FemaleShirt.BLUE.id(), Avatar.FemalePants.BLACK_PURPLE_STRIPE.id(), Avatar.FemaleHat.BLACK_YELLOW_POKEBALL.id(), Avatar.FemaleShoes.BLACK_YELLOW_STRIPE.id(), Avatar.Eye.BROWN.id(), Avatar.FemaleBackpack.GRAY_BLACK_YELLOW_POKEBALL.id());
}
});
HashProvider hasher = ExampleConstants.getHashProvider();
api.login(new PtcCredentialProvider(http, ExampleConstants.LOGIN, ExampleConstants.PASSWORD), hasher);
api.setLocation(ExampleConstants.LATITUDE, ExampleConstants.LONGITUDE, ExampleConstants.ALTITUDE);
} catch (RequestFailedException e) {
Log.e("Main", "Failed to login!", e);
}
}
Aggregations