Exemple #1
0
 async def active(self, ctx, PokemonTeamNumber: int):
     """sets the new active Pokemon"""
     try:
         if PokemonTeamNumber == 1:
             await ctx.channel.send("```Pokemon is already leading your Party!```")
         else:
             await ctx.channel.send(PlayerLogic.set_active_pokemon(ctx.message.author.id, 1, PokemonTeamNumber))
     except (NotAPlayerException, InputError) as err:
         await ctx.channel.send(err.message)
     except DatabaseException:
         await Shutdown.shutdown(ctx)
Exemple #2
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)
Exemple #3
0
 async def inventory(self, ctx):
     """returns all contents of your inventory"""
     try:
         current_player_items = PlayerLogic.get_items_for_player_id(
             ctx.message.author.id)
         await ctx.channel.send("```This are your items! {Item:Amount} ```")
         await ctx.channel.send({
             item['item_name']: item['amount']
             for item in current_player_items.dicts() if item['amount'] > 0
         })
     except DatabaseException:
         await Shutdown.shutdown(ctx)
Exemple #4
0
    async def attack_info(self, ctx):
        """shows the attacks of the active pokemon"""
        try:
            team = PlayerLogic.get_player_team(ctx.message.author.id)
            for p in team:
                outStr = f"```{p.pokemon.pokemon_name}:"
                attacks = AttackLogic.get_attacks(p)
                for a in attacks:
                    outStr += f" \n\t {a.attack.attack_name}"

                await ctx.channel.send(outStr + "```")
        except Exception:
            await ctx.channel.send("Invalid Team")
Exemple #5
0
 def has_item(item_name: str, player_id: int, quantity: int = 1) -> bool:
     """returns if the specified player has quantity or more of the specified item."""
     item = ItemLogic.get_item_by_name(item_name)
     player = PlayerLogic.get_player_by_id(player_id)
     try:
         res = (PlayerItem.select().where(
             (PlayerItem.player == player.player_id) & (PlayerItem.item == item.item_id)))
         if len(res) <= 0:
             return False
         else:
             return quantity <= res.get().amount
     except Exception as e:
         raise DatabaseException(e.message)
Exemple #6
0
 async def use_item(self, ctx, item: str, pokemon_team_number: int):
     """uses the item on the specified team member and ends your turn"""
     try:
         if PlayerLogic.is_in_battle(ctx.message.author.id):
             res = ItemLogic.use_item(player_id=ctx.message.author.id, item_name=item, team_position=pokemon_team_number)
             await FightingPokemon.handle_item_use_result(ctx, res)
             await ctx.channel.send("```"+AttackLogic.set_no_attack_turn(ctx.message.author.id, NonAttackAction(2))+"```")
         else:
             res = ItemLogic.use_item(player_id=ctx.message.author.id, item_name=item, team_position=pokemon_team_number)
             await FightingPokemon.handle_item_use_result(ctx,res)
     except DatabaseException:
         await Shutdown.shutdown(ctx)
     except Exception as e:
         await ctx.channel.send(e.message)
Exemple #7
0
    def player_attack_input(player: int, attack: Attack) -> str:
        gs = GameState.get_instance()
        if PlayerLogic.get_by_team_position(player).current_hp == 0:
            raise InputError(
                "please use the choose command, your current Pokemon is knocked out!"
            )
        gs.set_battle_input(player, attack)

        if gs.is_player_battle(player) and gs.are_battle_instructions_complete(
                player):
            return AttackLogic.initiate_battle_turn(player)
        elif gs.is_wild_battle(player):
            return AttackLogic.wild_battle_turn(player)
        return "AttackInput saved"
Exemple #8
0
    def wild_battle_turn(player):
        gs = GameState.get_instance()
        aktivep = PlayerLogic.get_by_team_position(player)
        wild = gs.get_current_wild_pokemon()
        dmgp1 = AttackLogic._calculate_damage(aktivep, wild,
                                              gs.get_queued_attack(player))
        dmgp2 = AttackLogic._calculate_damage(
            wild, aktivep,
            gs.get_attacks_for_wild_pokemon()[random.randint(0, 3)].attack)

        gs.reset_queued_attacks_wild(player)

        return AttackLogic._battle_order_bot(aktivep, wild,
                                             (player, wild.player_id), dmgp1,
                                             dmgp2)
Exemple #9
0
 def _get_next_position(player_id: int):
     from src.Logic.PlayerLogic import PlayerLogic
     team = PlayerLogic.get_player_team(player_id=player_id)
     if len(team) == config["maxTeamSize"]:
         return None
     return len(team) + 1
Exemple #10
0
 async def retrieve(self, ctx, boxed_id: int):
     """puts the specified pokemon on the next free spot in your team"""
     player_pokemon: PlayerPokemon = PlayerLogic.retrieve_pokemon_by_id(
         ctx.message.author.id, boxed_id)
     await ctx.channel.send(
         f"```Retrieved: {player_pokemon.pokemon.pokemon_name}```")
Exemple #11
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)
Exemple #12
0
 async def box(self, ctx):
     """shows your benched pokemon"""
     pokemon = PlayerLogic.get_pokemon_in_box(ctx.message.author.id)
     await ctx.channel.send(
         f"```{[x.pokemon.pokemon_name for x in pokemon]}```")
Exemple #13
0
 def gain_xp(player) -> int:
     return PokemonLogic.add_xp(PlayerLogic.get_by_team_position(player), random.randint(100, 500))
Exemple #14
0
 def player_lose_penalty(player: Player):
     level = PlayerLogic.get_highest_teammember(player)
     return PlayerLogic.add_money(player, (120*level)*-1)
Exemple #15
0
 def battle_teams(team1id, team2id):
     team1 = PlayerLogic.get_player_team(team1id)
     team2 = PlayerLogic.get_player_team(team2id)
     return f"```Player1 {GameLogic.get_team_text(team1)}\nPlayer2 {GameLogic.get_team_text(team2)}```"
Exemple #16
0
 async def store(self, ctx, team_member_id: int):
     """stores your pokemon in the box"""
     player_pokemon: PlayerPokemon = PlayerLogic.store_pokemon_by_team_member_id(
         ctx.message.author.id, team_member_id)
     await ctx.channel.send(
         f"```Stored: {player_pokemon.pokemon.pokemon_name}```")
Exemple #17
0
 def gain_money(player) -> int:
     return PlayerLogic.add_money(player, random.randint(100, 500))