Esempio n. 1
0
    def _battle_order_bot(aktive: PlayerPokemon, wild: PlayerPokemon, players,
                          dmgp1: int, dmgp2: int):
        if aktive.pokemon.speed >= wild.pokemon.speed:
            obj = AttackLogic._battle_turn_bot(players, 1, wild, dmgp1)
            if obj[1]:
                obj2 = AttackLogic._battle_turn_bot(players, 0, aktive, dmgp2)
                if not obj2[1]:
                    wild.current_hp = PokemonLogic.get_pokemon_max_hp(wild)
                    wild.save()
                    return obj2[0]
            else:
                return obj[0]
        else:
            obj = AttackLogic._battle_turn_bot(players, 0, aktive, dmgp2)
            if obj[1]:
                obj2 = AttackLogic._battle_turn_bot(players, 1, wild, dmgp1)
                if not obj2[1]:
                    return obj2[0]
            else:
                wild.current_hp = PokemonLogic.get_pokemon_max_hp(wild)
                wild.save()
                return obj[0]

        return f"New Stats:" \
               f"\nPlayer 1:" \
               f"\nPokemon: {aktive.pokemon.pokemon_name}" \
               f"\nHP: {aktive.current_hp}" \
               f"\nBot:" \
               f"\nPokemon: {wild.pokemon.pokemon_name}" \
               f"\nHP: {wild.current_hp}"
Esempio n. 2
0
 def _battle_turn(players: tuple, playerindex: int, aktive: PlayerPokemon,
                  dmg: int):
     gs = GameState.get_instance()
     aktive.current_hp -= dmg
     if aktive.current_hp < 1:
         aktive.current_hp = 0
         aktive.save()
         if PlayerLogic.has_live_pokemon_left(players[playerindex]):
             return (
                 f"Player {playerindex + 1} knocked out the Enemies Pokemon, he has still Pokemon left. "
                 f"Use the choose Command to send a new one into battle!",
                 False)
         else:
             if playerindex == 0:
                 GameLogic.gain_money(players[0])
                 GameLogic.player_lose_penalty(players[1])
             else:
                 GameLogic.gain_money(players[1])
                 GameLogic.player_lose_penalty(players[0])
             gs.battle_finished(players)
             PokemonLogic.heal_team(players[0])
             PokemonLogic.heal_team(players[1])
             return (
                 f"Player {playerindex + 1} knocked out the Enemies Pokemon. There are no more Pokemon "
                 f"left. Player {playerindex + 1} won the battle.", False)
     aktive.save()
     return "", True
Esempio n. 3
0
    def create_player(player_id: int, pokemon_name: str, money: int = 10000):
        """creates an entry for the player in the database if not already existing"""
        try:
            PlayerLogic.get_player_by_id(player_id)
            raise PlayerAlreadyExistingException()
        except NotAPlayerException:
            pokemon: Pokemon = PokemonLogic.get_pokemon_by_name(pokemon_name)
            if pokemon.starter != 1:
                raise NotAStarterPokemonException(pokemon_name)
            player = Player.create(got_starter=1,
                                   money=money,
                                   player_id=player_id)
            player.save()
            starter: PlayerPokemon = PlayerPokemon.create(
                player_id=player.player_id,
                pokemon=pokemon.pokedex_id,
                pokemon_level=5,
                team_position=1,
                xp=500,
                current_hp=0)
            starter.current_hp = PokemonLogic.get_pokemon_max_hp(starter)
            starter.save()

            PlayerPokemonAttack.create(attack=1,
                                       player_pokemon=starter).insert()

            PlayerLogic.add_pokemon_to_player_pokedex(player.player_id,
                                                      pokemon.pokedex_id)
            PlayerLogic._assign_default_items(player)
Esempio n. 4
0
    def _battle_turn_bot(players: tuple, playerindex: int,
                         aktive: PlayerPokemon, dmg: int):
        gs = GameState.get_instance()
        aktive.current_hp -= dmg
        if aktive.current_hp < 1:
            aktive.current_hp = 0
            aktive.save()
            if playerindex == 1:
                GameLogic.gain_xp(players[0])
                gs.reset_current_wild_pokemon()
                gs.bot_battle_finished(players[0])
                return "The Wild Pokemon got defeated congratulations!", False
            else:
                if PlayerLogic.has_live_pokemon_left(players[playerindex]):
                    return (
                        f"The Wild Pokemon knocked you out, but you have Pokemon left. "
                        f"Use the choose Command to send a new one into battle!",
                        False)
                else:
                    GameLogic.player_lose_penalty(players[0])
                    gs.bot_battle_finished(players[0])
                    PokemonLogic.heal_team(players[0])

                    return (
                        "The Wild Pokemon knocked out all your Pokemon. The Fight is lost!"
                        " Good luck next time.", False)
        aktive.save()
        return "", True
Esempio n. 5
0
 def _calculate_damage(attack_p: PlayerPokemon, defense_p: PlayerPokemon,
                       attack: Attack) -> int:
     if type(attack) is NonAttackAction:
         return 0
     # accuracy:
     if random.randint(0, 101) > attack.accuracy:  # if doesn't hit
         return 0
     # deduced from https://www.pokewiki.de/Schaden
     base_a_pokemon = PokemonLogic.get_pokemon_by_id(
         attack_p.pokemon.pokedex_id)
     base_d_pokemon = PokemonLogic.get_pokemon_by_id(
         defense_p.pokemon.pokedex_id)
     # „Same-type attack bonus“.
     stab_bonus = 1.5 if (base_a_pokemon.poke_type_id
                          == attack.poke_type_id) else 1
     # multiplier for effectiveness
     type_multiplier = AttackLogic.get_type_multiplier(
         attack.poke_type_id, base_d_pokemon.poke_type_id)
     random_factor = random.randint(85, 101) / 100
     # att and def for calculating the ratios between defensive and offensive pokemon
     att_val = AttackLogic.calc_attack(attack_p) if (
         attack.attack_category
         == AttackLogic.get_physical_attack_cat().attack_category_id
     ) else AttackLogic.calc_sp_attack(attack_p)
     def_val = AttackLogic.calc_def(defense_p) if (
         attack.attack_category
         == AttackLogic.get_physical_attack_cat().attack_category_id
     ) else AttackLogic.calc_sp_def(defense_p)
     return int(((attack_p.pokemon_level * 0.4 + 2) * attack.attack_power *
                 (att_val / (50 * def_val)) + 2) * stab_bonus *
                type_multiplier.multiplier * random_factor)
Esempio n. 6
0
    async def spawn_new_pokemon(self):
        if self.channelId is not None and not PokemonLogic.wild_pokemon_in_battle():
            channel = self.bot.get_channel(self.channelId)
            await channel.send(f"```A wild Pokémon appeared. Type {self.bot.command_prefix}pBattle "
                               f"to engage in battle.```")
            wild = self.pokemons[random.randint(0, len(self.pokemons) - 1)]
            while wild.legendary or wild.starter:
                wild = self.pokemons[random.randint(0, len(self.pokemons) - 1)]

            level = GameLogic.get_mean_pokemon_level()
            PokemonLogic.create_wild_pokemon(wild, level)

            await channel.send(f"```It´s a {wild.pokemon_name}```")
Esempio n. 7
0
 async def start_adventure(self, ctx):
     """Get ready to start a wonderful adventure in the world of Pokémon"""
     try:
         starters = PokemonLogic.get_all_starters()
         await ctx.channel.send(
             "```Hello there! Welcome to the world of pokemon!\nMy name is PokePy! People call me the pokemon bot! "
             "This world is inhabited by creatures called pokemon! "
             "For some people, pokemon are pets. Others use them for fights. Myself... I study pokemon as a "
             "profession. "
             "Any good trainer knows that you can't learn unless you play the game. Being a good trainer is a long "
             "and complicated process which involves working with "
             "the pokemon you have in order to accumulate experience and catch more pokemon. "
             "A pokemon can appear anytime in tall grass. You need your own pokemon for your protection. "
             "There are a few pokemon here! Haha! They are inside the poke balls. When I was young, "
             "I was a serious pokemon trainer! "
             "In my old age, I have only a few left, but you can have one! Choose!```"
         )
         await ctx.channel.send(
             f"```Please choose a starter Pokemon with {self.bot.command_prefix}pPick<pokemon name>,"
             f" e.g. {self.bot.command_prefix}pStarter Red Charmander```")
         starter_text = "```These are eligible Starter-Pokemon:"
         for p in starters:
             starter_text += f"\n\t{p.pokemon_name}"
         await ctx.channel.send(starter_text + "```")
     except DatabaseException:
         await Shutdown.shutdown(ctx)
Esempio n. 8
0
 def try_catch_wild(player_id, player_item, ball):
     gs = GameState.get_instance()
     wild = gs.get_current_wild_pokemon()
     if gs.is_wild_battle(player_id):
         player_item.amount -= 1
         player_item.save()
         if GameLogic.catch(ball.catch_multiplier, wild.current_hp,
                            PokemonLogic.get_pokemon_max_hp(wild), wild.pokemon.catch_rate):
             gs.bot_battle_finished(player_id)
             PokemonLogic.pokemon_cought(player_id, wild, gs.get_attacks_for_wild_pokemon())
             gs.reset_current_wild_pokemon()
             return f"```Congratulations, you caught {wild.pokemon.pokemon_name}```", True
         else:
             from src.Logic.AttackLogic import AttackLogic
             return f"```You did not Catch the Wild Pokemon \n{AttackLogic.set_no_attack_turn(player_id, NonAttackAction.CATCH)}```", False
     else:
         raise InputError("You are not in Combat with the current Wild Pokemon!")
Esempio n. 9
0
 async def poke_center(self, ctx):
     """heals your team"""
     team = PlayerLogic.get_player_team(ctx.message.author.id)
     for p in team:
         p.current_hp = PokemonLogic.get_pokemon_max_hp(p)
         p.save()
         await ctx.channel.send(
             f"```HP Recoverd for {p.pokemon.pokemon_name}```")
Esempio n. 10
0
    async def team_info(self, ctx):
        """shows Information to your Team in Battle"""
        try:
            team = PlayerLogic.get_player_team(ctx.message.author.id)
            for p in team:
                await ctx.channel.send(PokemonLogic.get_player_pokemon_info(p))

        except Exception:
            await ctx.channel.send("Invalid Team")
Esempio n. 11
0
 def use_item(player_id: int, item_name: str, team_position: int) ->ItemUseResult:
     """uses the specified item on the pokemon at the specified team position."""
     player = PlayerLogic.get_player_by_id(player_id)
     item = ItemLogic.get_item_by_name(item_name)
     player_pokemon = PlayerLogic.get_by_team_position(player_id)
     gs = GameState.get_instance()
     if gs.is_player_in_combat(player.player_id):
         if ItemLogic.is_heal_item(item_name):
             if player_pokemon.current_hp > 0:
                 raise PokemonAlreadyKnockedOutException()
             else:
                 heal_item = ItemLogic.get_heal_item(item.name)
                 if not ItemLogic.has_item(item.item_name, player.player_id):
                     raise NotEnoughItemsException(item.item_name, 1)
                 if player_pokemon.current_hp <= 0:
                     raise PokemonAlreadyKnockedOutException()
                 PokemonLogic.heal(player_pokemon, heal_item.healing_amount)
                 ItemLogic._consume_item(player, item)
                 return ItemUseResult(heal_item.healing_amount, None)
         else:
             raise CurrentlyInBattleException("use " + item.item_name)
     else:
         if ItemLogic.is_heal_item(item.item_name):
             if player_pokemon.current_hp <= 0:
                 raise PokemonAlreadyKnockedOutException()
             else:
                 heal_item = ItemLogic.get_heal_item(item.name)
                 if not ItemLogic.has_item(item.item_name, player.player_id):
                     raise NotEnoughItemsException(item.item_name, 1)
                 PokemonLogic.heal(player_pokemon, heal_item)
                 ItemLogic._consume_item(player, item)
                 return ItemUseResult(heal_item.healing_amount, None)
         elif ItemLogic.is_evolution_stone(item.item_name):
             if not ItemLogic.has_item(item.item_name, player.player_id):
                 raise NotEnoughItemsException(item.item_name, 1)
             old_pokemon = player_pokemon.pokemon
             res = PokemonLogic.item_evolve(player_pokemon,item)
             ItemLogic._consume_item(player,item)
             return ItemUseResult(evolution_start=old_pokemon, evolution_result=res.pokemon)
         else:
             raise NotAnAppropriateItemException(item.item_name)
Esempio n. 12
0
    def get_pokedex_for_player(player_id: int):
        all_pokemon = list(PokemonLogic.get_all_pokemon())
        player_pokemon = PlayerPokedex.select().where(
            PlayerPokedex.player_id == player_id)

        # expect player to not have any pokemon
        pokedex_info = {p: False for p in all_pokemon}

        # this is not efficient but as long as it works it is fine
        for x in range(0, len(all_pokemon)):
            current_pokemon: Pokemon = all_pokemon[x]
            for y in range(0, len(player_pokemon)):
                current_player_pokemon: Pokemon = player_pokemon[y]
                if current_pokemon.pokedex_id == current_player_pokemon.pokemon.pokedex_id:
                    pokedex_info[current_pokemon] = True

        return pokedex_info
Esempio n. 13
0
 async def fill(self, ctx):
     """admin fill team with pokemon"""
     PokemonLogic.fill_team_with_random_pokemon(ctx.message.author.id)
Esempio n. 14
0
 def gain_xp(player) -> int:
     return PokemonLogic.add_xp(PlayerLogic.get_by_team_position(player), random.randint(100, 500))
Esempio n. 15
0
 def __init__(self, bot):
     self.bot = bot
     self.pokemons = PokemonLogic.get_all_pokemon()
     self.channelId = None
     self.spawn_new_pokemon.start()
Esempio n. 16
0
 def get_mean_pokemon_level() -> int:
     players = [p.player_id for p in PlayerLogic.get_all_players()]
     return PokemonLogic.get_active_pokemon_levels(players)
Esempio n. 17
0
 def calc_attack(p_pokemon: PlayerPokemon) -> int:
     p = PokemonLogic.get_pokemon_by_id(p_pokemon.pokemon.pokedex_id)
     return int(p.base_attack + (p_pokemon.pokemon_level *
                                 (p.base_attack / 50)))
Esempio n. 18
0
 def calc_def(p_pokemon: PlayerPokemon) -> int:
     p = PokemonLogic.get_pokemon_by_id(p_pokemon.pokemon.pokedex_id)
     return int(p.base_defense + (p_pokemon.pokemon_level *
                                  (p.base_defense / 50)))