Search in sources :

Example 21 with Pokemon

use of pokeraidbot.domain.pokemon.Pokemon in project pokeraidbot by magnusmickelsson.

the class EggHatchedCommand method executeWithConfig.

@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
    final User user = commandEvent.getAuthor();
    final String userName = user.getName();
    final String[] args = commandEvent.getArgs().split(" ");
    if (args.length < 2) {
        throw new UserMessedUpException(userName, localeService.getMessageFor(LocaleService.BAD_SYNTAX, localeService.getLocaleForUser(user), "!raid hatch Ho-Oh solna platform"));
    }
    String pokemonName = args[0].trim().toLowerCase();
    final String[] gymArguments = ArrayUtils.removeAll(args, 0);
    String gymName = StringUtils.join(gymArguments, " ");
    final String region = config.getRegion();
    final Gym gym = gymRepository.search(user, gymName, region);
    final Raid raid = raidRepository.getActiveRaidOrFallbackToExRaid(gym, region, user);
    final Pokemon pokemon = pokemonRepository.search(pokemonName, user);
    final PokemonRaidInfo existingRaidInfo = raidStrategyService.getRaidInfo(raid.getPokemon());
    final int newBossTier = raidStrategyService.getRaidInfo(pokemon).getBossTier();
    if (!raid.getPokemon().isEgg()) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.EGG_ALREADY_HATCHED, localeService.getLocaleForUser(user), raid.getPokemon().toString()));
    }
    if (pokemon.isEgg() || newBossTier != existingRaidInfo.getBossTier()) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.EGG_WRONG_TIER, localeService.getLocaleForUser(user)));
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Trying to hatch raid " + raid + " into " + pokemonName);
    }
    AlterRaidCommand.changePokemon(gymRepository, localeService, pokemonRepository, raidRepository, commandEvent, config, user, userName, pokemonName, gymArguments);
}
Also used : User(net.dv8tion.jda.core.entities.User) PokemonRaidInfo(pokeraidbot.domain.pokemon.PokemonRaidInfo) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) Gym(pokeraidbot.domain.gym.Gym) Raid(pokeraidbot.domain.raid.Raid) Pokemon(pokeraidbot.domain.pokemon.Pokemon)

Example 22 with Pokemon

use of pokeraidbot.domain.pokemon.Pokemon in project pokeraidbot by magnusmickelsson.

the class NewRaidCommand method executeWithConfig.

@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
    final User user = commandEvent.getAuthor();
    final String[] args = commandEvent.getArgs().replaceAll("\\s{1,3}", " ").split(" ");
    if (args.length < 3) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.BAD_SYNTAX, localeService.getLocaleForUser(user), "!raid new ho-oh 10:00 solna platform"));
    }
    String pokemonName = args[0];
    final Pokemon pokemon = pokemonRepository.search(pokemonName, user);
    String timeString = args[1];
    LocalTime endsAtTime = Utils.parseTime(user, timeString, localeService);
    LocalDateTime endsAt = LocalDateTime.of(LocalDate.now(), endsAtTime);
    assertTimeNotInNoRaidTimespan(user, endsAtTime, localeService);
    assertTimeNotMoreThanXHoursFromNow(user, endsAtTime, localeService, 2);
    assertCreateRaidTimeNotBeforeNow(user, endsAt, localeService);
    StringBuilder gymNameBuilder = new StringBuilder();
    for (int i = 2; i < args.length; i++) {
        gymNameBuilder.append(args[i]).append(" ");
    }
    String gymName = gymNameBuilder.toString().trim();
    final Gym gym = gymRepository.search(user, gymName, config.getRegion());
    final Raid raid = new Raid(pokemon, endsAt, gym, localeService, config.getRegion());
    raidRepository.newRaid(user, raid, commandEvent.getGuild(), config, "!raid new " + raid.getPokemon().getName() + " " + printTimeIfSameDay(raid.getEndOfRaid()) + " " + raid.getGym().getName());
    final Locale locale = localeService.getLocaleForUser(user);
    replyBasedOnConfigAndRemoveAfter(config, commandEvent, localeService.getMessageFor(LocaleService.NEW_RAID_CREATED, locale, raid.toString(locale)), BotServerMain.timeToRemoveFeedbackInSeconds);
}
Also used : LocalDateTime(java.time.LocalDateTime) Locale(java.util.Locale) User(net.dv8tion.jda.core.entities.User) LocalTime(java.time.LocalTime) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) Gym(pokeraidbot.domain.gym.Gym) Pokemon(pokeraidbot.domain.pokemon.Pokemon) Raid(pokeraidbot.domain.raid.Raid)

Aggregations

Pokemon (pokeraidbot.domain.pokemon.Pokemon)22 Gym (pokeraidbot.domain.gym.Gym)11 User (net.dv8tion.jda.core.entities.User)10 Raid (pokeraidbot.domain.raid.Raid)10 LocalDateTime (java.time.LocalDateTime)6 Locale (java.util.Locale)6 UserMessedUpException (pokeraidbot.domain.errors.UserMessedUpException)6 Test (org.junit.Test)5 PokemonTypes (pokeraidbot.domain.pokemon.PokemonTypes)5 LocalTime (java.time.LocalTime)4 PokemonRaidInfo (pokeraidbot.domain.pokemon.PokemonRaidInfo)4 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)3 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)3 RaidGroup (pokeraidbot.infrastructure.jpa.raid.RaidGroup)3 LocalDate (java.time.LocalDate)2 SignUp (pokeraidbot.domain.raid.signup.SignUp)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 SelfUser (net.dv8tion.jda.core.entities.SelfUser)1 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)1