Ejemplo n.º 1
0
    def heal_yes(self, bot: Bot, update: Update, trainer: Trainer,
                 database: Database):
        delete_message(bot, update)

        pokeraw = trainer.get_team(
            database,
            "id, species_id, level, name, teamnr, currenthp, hp_dv, hp_exp"
        )  # blocktimer
        row_count = database.dict_cursor.rowcount
        healtime = row_count * 5

        #   "UPDATE trainer SET blocktimer = NOW() + INTERVAL %s MINUTE WHERE id = %  s;", (healtime, cid,))
        # trainer.set_attribute("blocktimer", "NOW() + INTERVAL {0} MINUTE".format(healtime))
        trainer.blocktimer = dt.datetime.now() + dt.timedelta(minutes=healtime)
        # d.cmd("UPDATE pokemon SET currenthp = %s WHERE id = %s", (temppoke.calculate_max_hp(), temppoke.id,))
        for poke in pokeraw:
            poke.currenthp = poke.calculate_max_hp()
            poke.update_values(database, "currenthp")
            # poke.set_attribute("currenthp", "{0}".format(poke.calculate_max_hp()))

        center_buttons = [[
            InlineKeyboardButton("Pick up!", callback_data='pickuppkmn')
        ]]

        center_keys = InlineKeyboardMarkup(center_buttons)

        bot.send_message(
            Trainer.id,
            "Ok. We'll need your Pokémon. Come back in {0} minutes and pick up your Pokémon. You can't do anything while we are healing your Pokémon. Please take a seat in our waiting room..."
            .format(healtime),
            reply_markup=center_keys)
        trainer.menu_id = MenuId.CENTER_HEAL_BLOCKER

        trainer.update_values(database, "blocktimer")
        trainer.update_values(database, "menu_id")
Ejemplo n.º 2
0
def start_wild(trainer: Trainer, species_id: int, level: int,
               database: Database) -> (bool, str):
    """
    Starts a new fight between a trainer and a new wild pokemon, that will be spawned. The bot send a new battle message
    to the trainer

    :param database: pokemon database
    :param bot: telegram bot, which send the message
    :param trainer: trainer in the fight
    :param species_id: species of the wild pokemon
    :param level: level of the wild pokemon
    """
    wild_pokemon = Pokemon.create_new(database,
                                      Data.all_species[species_id - 1], level)
    trainer_team = trainer.get_team(database, "id, currenthp")
    for p in trainer_team:
        if p.currenthp > 0:
            trainer_pokemon = p
            break
    else:
        return False, "Trainer in fight with no available pokemon!"
    trainer_pokemon.load_values(
        database,
        "hp_dv, attack_dv, defense_dv, special_dv, speed_dv, hp_exp, attack_exp, "
        "defense_exp, special_exp, speed_exp, species_id, currenthp, level, "
        "name")
    trainer.fight = Fight.create_new(database, wild_pokemon, trainer_pokemon)
    trainer.menu_id = int(MenuId.BATTLE)
    trainer.update_values(database, "fight, menu_id")

    return True, "Wild %s appeared!" % wild_pokemon.name
Ejemplo n.º 3
0
 def yes_name(self, bot: Bot, update: Update, trainer: Trainer,
              database: Database):
     """Rename Message"""
     delete_message(bot, update)
     bot.send_message(
         trainer.id,
         text="Okay nice! How do you want to call your little friend?"
         " (Please only use normal character [A-Z, a-z], maximal 16 chars)")
     trainer.load_values(database=database, values="menu_id")
     trainer.menu_id = int(MenuId.ENTER_NAME)
     trainer.update_values(database, "menu_id")
Ejemplo n.º 4
0
    def search(self, bot: Bot, update: Update, trainer: Trainer, database: Database):
        """sets earch MenuID and sends instructions"""
        delete_message(bot, update)

        dex_but = [[InlineKeyboardButton("⏪ Exit Search", callback_data = str(ButtonId.POKEDEX_EXIT_SEARCH))]]
        dex_keys = InlineKeyboardMarkup(dex_but)

        bot.send_message(trainer.id,
                         "Here you can search for a Pokemon-Species-ID or a Pokemon-Species-Name."
                         " So please send me a name or number from 1 to 151 now! Write "
                         " \"exit\"  to leave or click here: ", reply_markup = dex_keys)

        trainer.menu_id = int(MenuId.POKEDEX_SEARCH)
        trainer.update_values(database, "menu_id")
Ejemplo n.º 5
0
 def heal_no(self, bot: Bot, update: Update, trainer: Trainer,
             database: Database):
     trainer.menu_id = MenuId.MAIN_MENU
     trainer.update_values(database, "menu_id")
     try:
         update.callback_query.message.delete()
     except TelegramError:
         bot.answerCallbackQuery(callback_query_id=update.callback_query.id,
                                 text="Don't click that fast...",
                                 show_alert=False)
     bot.send_message(
         Trainer.id,
         "We hope to see you again! Write or click on /handler to show the handler"
     )
Ejemplo n.º 6
0
    def no_name(self, bot: Bot, update: Update, trainer: Trainer,
                database: Database):
        """Dont want to Rename"""
        delete_message(bot, update)
        bot.send_message(
            trainer.id,
            text="Nice! Have fun with your new friend! You two seem very strong!"
            " Click on the button bellow to show the Mainmenu.",
            reply_markup=InlineKeyboardMarkup([[
                InlineKeyboardButton("Menu",
                                     callback_data=str(ButtonId.MAINMENU))
            ]]))

        trainer.menu_id = int(MenuId.MAIN_MENU)
        trainer.lastcatched = None
        trainer.update_values(database, "menu_id, lastcatched")
Ejemplo n.º 7
0
    def choosed(self, bot: Bot, update: Update, trainer: Trainer,
                database: Database):
        """Choose Pokemon"""
        data = update.callback_query.data
        species = int(data.replace(str(ButtonId.CHOOSE_STARTER), ""))

        poke = Pokemon.create_new(database, all_species[species], 5, trainer)
        delete_message(bot, update)
        bot.sendSticker(trainer.id, Stickerpacks.get_item(0))
        bot.send_message(trainer.id,
                         text="Nice, " + poke.name +
                         " is your first Pokémon!\n" +
                         poke.species.pokedextext +
                         "\nDo you want to give your Pokémon a nickname?",
                         reply_markup=self.return_rename_buttons())
        trainer.menu_id = int(MenuId.CHOOSE_IF_RENAME)
        trainer.lastcatched = poke.id
        trainer.update_values(database, "menu_id, lastcatched")
        dexter = Pokedex(poke.id, trainer.id)
        dexter.create_new(database, poke.species.id, trainer)
Ejemplo n.º 8
0
    def search_for(self, bot: Bot, update: Update, trainer: Trainer, database: Database):
        """searches for a pokemon"""
        input_data =  update.message.text

        # Exit Search
        if input_data.upper() == "EXIT":
            trainer.menu_id = int(MenuId.MAIN_MENU)
            trainer.update_values(database, "menu_id")
            self.send_menu(bot, trainer)

        # If Input is a number
        elif input_data.isdigit():
            dexnum = int(update.message.text)
            if dexnum > 151 or dexnum < 1:
                bot.send_message(trainer.id, "Invalid Dex number...")
            else:
                self.search_entry(database, bot, update, trainer.id, dexnum)

        # searches for a Name
        else:
            dexterraw = Pokedex.get_all(database,
                                        columns = "id, trainerid",
                                        where = "trainerid = " + str(trainer.id),
                                        order = "id")
            idar = {'null': None}

            for j in dexterraw:
                idar[Data.all_species[j.id - 1].name.upper()] = j.id
            input_dex = update.message.text.upper()

            keylist = []
            for k in idar.keys():
                keylist.append(str(k))

            if input_dex in keylist:
                self.search_entry(database, bot, update, trainer.id, idar[input_dex])
            else:
                bot.send_message(trainer.id,
                         "There is no entry with " +
                         input_dex +
                         " Do this Pokémon really exist? Check your spelling and try it one more time!")
Ejemplo n.º 9
0
 def pickuppkmn(self, bot: Bot, update: Update, trainer: Trainer,
                database: Database):
     trainer.get_values(database, "blocktimer")
     blocktime = trainer.blocktimer
     if blocktime <= dt.datetime.now():
         bot.send_message(
             Trainer.id,
             text=
             """Thank you! Your Pokémon are fighting fit! We hope to see you again! Hehe... What? I'm not a s****t... Click or write /handler to show the handler!"""
         )
         # d.cmd("UPDATE trainer SET blocktimer = NULL WHERE id = %s;", (cid,))
         trainer.blocktime = None
         trainer.menu_id = 3
         trainer.update_values(database, "menu_id, blocktimer")
         pass
     else:
         waitfor = blocktime - dt.datetime.now()
         minutes = (waitfor.days * 1440) + (waitfor.seconds /
                                            60) + 1  # + waitfor.minute
         bot.answerCallbackQuery(callback_query_id=update.callback_query.id,
                                 text="Wait for %d min..." % minutes,
                                 show_alert=False)
Ejemplo n.º 10
0
    def rename(self, bot: Bot, update: Update, trainer: Trainer,
               database: Database):
        """Rename Pokemon"""
        trainer.load_values(database=database, values="lastcatched")
        poke = Pokemon(trainer.lastcatched)
        poke.load_values(database, "species_id")

        name = update.message.text[0:16].replace(" ", "")

        c = True

        for c in name:
            if (not (c.isupper() or c.islower())):
                c = False

        if c:
            poke.name = name
            trainer.menu_id = int(MenuId.MAIN_MENU)
            trainer.lastcatched = None
            trainer.update_values(database, "menu_id, lastcatched")
            poke.update_values(database, "name")
            bot.send_message(
                trainer.id,
                text=
                "You want to call your {1} {0}? Great! I think you will become good friends. Your {0} seems very strong! Click on the button bellow to show the Mainmenu."
                .format(poke.name, poke.species.name),
                reply_markup=InlineKeyboardMarkup([[
                    InlineKeyboardButton("Menu",
                                         callback_data=str(ButtonId.MAINMENU))
                ]]))

        else:
            bot.send_message(
                trainer.id,
                text=
                "Youuuu little rascal. There were bad character in this name, try it again."
            )
Ejemplo n.º 11
0
    def heal(self, bot: Bot, update: Update, trainer: Trainer,
             database: Database):
        """
        if menu_id==3:
        Ask the player if the trainer wants to heal his Pokemonteam and prints the time the pokemon need to heal.
        Gets id and teamnr from database.
        Yes = menu_id -> MenuId.POKEMON_CENTER
        """
        pokemon = trainer.get_team(database, "id, teamnr")
        row_count = database.dict_cursor.rowcount
        healtime = row_count * minutes_to_heal
        center_buttons = [[
            InlineKeyboardButton("Heal, please!", callback_data='heal_y'),
            InlineKeyboardButton("Nope.", callback_data='heal_n')
        ]]

        center_keys = InlineKeyboardMarkup(center_buttons)
        bot.send_message(
            id,
            "Welcome to our Pokémon Center! We heal your Pokémon back to perfect health! Shall we heal your Pokémon? We will need {0} minutes to heal every Pokémon in your team."
            .format(healtime),
            reply_markup=center_keys)
        trainer.menu_id = MenuId.POKEMON_CENTER
        trainer.update_values(database, "menu_id")
Ejemplo n.º 12
0
 def reset_fight(bot: Bot, update: Update, trainer: Trainer, database: Database):
     trainer.menu_id = int(MenuId.MAIN_MENU)
     trainer.fight = None
     trainer.update_values(database, "fight, menu_id")
Ejemplo n.º 13
0
 def exit_search(self, bot: Bot, update: Update, trainer: Trainer, database: Database):
     trainer.menu_id = int(MenuId.MAIN_MENU)
     trainer.update_values(database, "menu_id")
     self.send_menu(bot, trainer)