示例#1
0
class Cmd_mission(commands.Cog):

    def __init__(self, client):
        self.client = client

    @commands.check(Basic_checker().is_game_ready)
    @commands.check(Basic_checker().is_registered)
    @commands.command()
    async def mission(self, ctx, choice = None):
        """
        Allow the player to display the mission panel

        Or to start a mission if the `choice` parameter is != `None`

        - Parameter :

        `choice` (`int`) : Mission index
        """

        # init
        player = Player(ctx, self.client, ctx.message.author)
        mission = Mission_manager()
        embed = await Custom_embed(
            self.client, title = "Missions", description = "Welcome to the Missions panel"
        ).setup_embed()    
        
        # start mission
        if(choice != None):
            if(choice.isdigit()):
                choice = int(choice)
                await mission.start_mission(ctx, self.client, player, choice)

        else:
            # display the missions panel
            pass
示例#2
0
class Cmd_cancel(commands.Cog):
    def __init__(self, client):
        self.client = client

    @commands.check(Basic_checker().is_game_ready)
    @commands.check(Basic_checker().is_registered)
    @commands.group(invoke_without_command=False)
    async def cancel(self, ctx):
        """
        Allow the player to cancel an action
        """

        return

    @cancel.command()
    async def fight(self, ctx):
        """
        Allow the player to reset its `in_fight` status
        """

        # init
        player = Player(ctx, self.client, ctx.message.author)
        checker = Fight_checker()

        # check if the player is in a fight
        if player.id in checker.in_fight:
            checker.in_fight.remove(player.id)

            await ctx.send("You are no longer in a fight.")

        else:
            await ctx.send("You're not in a fight.")
示例#3
0
class Cmd_summon(commands.Cog):
    def __init__(self, client):
        self.client = client
        self.cost = {"basic": 5}

    @commands.check(Basic_checker().is_game_ready)
    @commands.check(Basic_checker().is_registered)
    @commands.group(aliases=["sum"], invoke_without_command=True)
    async def summon(self, ctx):
        """
        Command group :

        - basic {multi} default {single}
        """

        # init
        helper = Helper(self.client, ctx, ctx.message.author)
        summon_help = await Help_summon().get_embed(self.client)

        # send the help
        await helper.display_help(summon_help)

        return

    @commands.check(Basic_checker().is_game_ready)
    @commands.check(Basic_checker().is_registered)
    @summon.command()
    async def basic(self, ctx):
        """
        Summon a character from the basic banner.
        """

        # init
        player = Player(ctx, self.client, ctx.message.author)
        summoner = Summoner(self.client)
        displayer = Character_displayer(self.client, ctx, player)

        # get player's resource
        await player.resource.update()

        if (player.resource.dragonstone >= self.cost["basic"]):
            # draw
            drawn_character = await summoner.summon(player, _type="basic")
            await drawn_character.init()

            # display
            displayer.character = drawn_character
            await displayer.display(summon_format=True)

            # apply the cost
            await player.resource.remove_dragonstone(self.cost["basic"])

        else:
            await ctx.send(
                f"<@{player.id}> You do not have enough **Dragon Stones**{game_icon['dragonstone']} to summon ({player.resource.dragonstone:,} / {self.cost['basic']:,})."
            )

        return
示例#4
0
class Cmd_help(commands.Cog):
    def __init__(self, client):
        self.client = client

    @commands.check(Basic_checker().is_game_ready)
    @commands.command()
    async def help(self, ctx, command=None):
        """
        Displays the help.

        - Parameter : 

        `command` (str) : The name of the command which the user wants to see the help.
        """

        # init
        player = Player(ctx, self.client, ctx.message.author)
        helper = Helper(self.client, ctx, player)

        if (command == None):
            await helper.helper_manager()

        else:
            help_panel = await helper.get_help_command(command)

            if not help_panel is None:
                await helper.display_help(help_panel)

            else:
                await ctx.send(
                    f"Sorry, the help panel for the command `{command}` has not been found."
                )
示例#5
0
class Cmd_show(commands.Cog):
    def __init__(self, client):
        self.client = client

    @commands.check(Basic_checker().is_game_ready)
    @commands.command()
    async def show(self, ctx, character_id, level=None):
        """
        Allow the player to see a character's stats and abilities by passing its global id.

        If a unique id is passed, displays the unique character.
        """

        # init
        player = Player(ctx, self.client, ctx.message.author)
        character_getter = Character_getter()
        displayer = Character_displayer(self.client, ctx, player)

        if (level != None):
            if (level.isdigit()):
                level = int(level)

                if (level > 150):
                    level = 150

            else:
                level = None

        # global id
        if (character_id.isdigit()):
            character_id = int(character_id)
            character = await character_getter.get_character(character_id)

            if (character != None):
                displayer.character = character

                await displayer.display(basic_format=True, level=level)

            else:
                await ctx.send(
                    f"<@{player.id}> Character `#{character_id}` not found.")

        # unique id
        else:
            character = await character_getter.get_from_unique(
                self.client, character_id)

            if (character != None):
                displayer.character = character

                await displayer.display(basic_format=True, level=level)

            else:
                await ctx.send(
                    f"<@{player.id}> Character `#{character_id}` not found.")
示例#6
0
class Cmd_profile(commands.Cog):
    def __init__(self, client):
        self.client = client

    @commands.check(Basic_checker().is_game_ready)
    @commands.check(Basic_checker().is_registered)
    @commands.command(aliases=["p"])
    async def profile(self, ctx):
        """
        Call the player's profile.
        """

        # init
        # player
        player = Player(ctx, self.client, ctx.message.author)
        await player.resource.update()  # update the resources count
        char_amount = await player.box.get_characters_amount()
        # embed
        profile_embed = await Custom_embed(
            self.client, thumb=player.avatar,
            title=f"{player.name}'s profile").setup_embed()

        # prepare the embed
        profile_embed.add_field(name=":star: Level", value=0, inline=True)

        profile_embed.add_field(
            name=f"{game_icon['dragonstone']} Dragon stone",
            value=f"{player.resource.dragonstone:,}",
            inline=True)

        profile_embed.add_field(name=f"{game_icon['zenis']} Zenis",
                                value=f"{player.resource.zenis:,}",
                                inline=True)

        profile_embed.add_field(name=":trophy: Collection",
                                value=f"{char_amount:,}",
                                inline=True)

        # display the profile
        await ctx.send(embed=profile_embed)
示例#7
0
class Cmd_box(commands.Cog):
    def __init__(self, client):
        self.client = client

    @commands.check(Basic_checker().is_game_ready)
    @commands.check(Basic_checker().is_registered)
    @commands.check(Box_checker().has_opened_box)
    @commands.command()
    async def box(self, ctx, character_id: int = None):
        """
        Displays the player's box

        - Parameter :

        `character_id` : Represents the character global id to display.
        """

        # init
        player = Player(ctx, self.client, ctx.message.author)

        # box
        await player.box.manager(character_id=character_id)
示例#8
0
class Cmd_start(commands.Cog):
    def __init__(self, client):
        self.client = client

    @commands.check(Basic_checker().is_game_ready)
    @commands.check(Start_checker().need_register)
    @commands.command()
    async def start(self, ctx):
        """
        Allow the player to start an adventure.
        """

        # init
        db = Database(self.client.db)
        player = Player(ctx, self.client, ctx.message.author)
        summoner = Summoner(self.client)

        # insert the player into the tables
        await db.execute(
            """INSERT INTO player_info(player_id, player_name, player_register_date) VALUES ($1, $2, $3)""",
            (player.id, player.name, time.strftime("%d/%m/%y", time.gmtime())))
        await db.execute(
            """INSERT INTO player_resource(player_id, player_name, player_dragonstone) VALUES ($1, $2, 25)""",
            (
                player.id,
                player.name,
            ))
        await db.execute(
            """INSERT INTO player_combat_info(player_id, player_name) VALUES ($1, $2)""",
            (
                player.id,
                player.name,
            ))

        # generate 3 saibaiman
        for i in range(3):
            await db.execute(
                """
                            INSERT INTO character_unique(character_owner_id, character_owner_name, character_global_id, 
                            character_type, character_rarity)
                            VALUES($1, $2, $3, $4, 0)""",
                [player.id, player.name, (i + 1),
                 random.randint(0, 4)])

        await summoner.set_unique_id()

        # get the summoned characters
        summoned = await db.fetch(f"""
            SELECT character_unique_id FROM character_unique WHERE character_owner_id = {player.id};
            """)

        # assign summoned character
        slot = ["a", "b", "c"]

        for a in range(3):
            await asyncio.sleep(0)

            await db.execute(f"""
                UPDATE player_combat_info 
                SET player_fighter_{slot[a]} = '{summoned[a][0]}'
                WHERE player_id = {player.id};
                """)

        # welcome message
        welcome = f"<@{player.id}> Hello and welcome to **Discord Ball Z III** - *Open Beta* !\nWe're hoping you to enjoy your adventure !\n\nHere are **25**{game_icon['dragonstone']}, they will help you to **summon** your first heroes that will fight for you !\n\nIf you have any question, do not hesitate to consult the `d!help` command or join the **Official Server** : https://discord.gg/eZf2p7h"

        await ctx.send(welcome)
示例#9
0
class Cmd_fighter(commands.Cog):
    
    def __init__(self, client):
        self.client = client
        self.getter = Character_getter()
        self.icon = Icon_displayer()

    @commands.check(Basic_checker().is_game_ready)
    @commands.check(Basic_checker().is_registered)
    @commands.group()
    async def fighter(self, ctx):
        """
        The fighter command group
        """

        # display the fighter help here

    ################ FIGHTER ###################
    @commands.check(Basic_checker().is_game_ready)
    @commands.check(Basic_checker().is_registered)
    @fighter.command()
    async def remove(self, ctx, slot):
        """
        Allows the player to remove a character from a slot.
        """

        # init
        player = Player(ctx, self.client, ctx.message.author)
        player_team = await player.team.get_team()
        getter = Character_getter()
        possible_slot = ["a", "b", "c"]


        # remove the slot
        if slot.lower() in possible_slot:
            await player.team.remove(slot)
            removed_character = await getter.get_from_unique(self.client, player_team[slot])
            await removed_character.init()

            await ctx.send(f"<@{player.id}> You have successfully removed {removed_character.image.icon}**{removed_character.info.name}** {removed_character.type.icon}{removed_character.rarity.icon} from the slot **{slot.upper()}**.")

        else:  # unexisting slot
            await ctx.send(f"<@{player.id}> Slot **{slot.upper()}** not found.")

        return
        
    @commands.check(Basic_checker().is_game_ready)
    @commands.check(Basic_checker().is_registered)
    @fighter.command()
    async def team(self, ctx):
        """
        Displays the player's team.
        """

        # init
        player = Player(ctx, self.client, ctx.message.author)
        player_team = await player.team.get_team()
        player_team_info = await player.team.get_info()
        embed = await Custom_embed(self.client).setup_embed()

        char_a, char_b, char_c = None, None, None

        # set the info icon
        player_team_info["rarity"] = await self.icon.get_rarity_icon(player_team_info["rarity"])

        # set the player team display
        ### a 
        if(player_team["a"] == None):
            player_team["a"] = "--"
        
        else:
            char_a = await self.getter.get_from_unique(self.client, player_team["a"])
            char_a = f"`{player_team['a']}` | {char_a.image.icon}{char_a.info.name} {char_a.type.icon}{char_a.rarity.icon} lv.{char_a.level:,}"
        
        ### b
        if(player_team["b"] == None):
            player_team["b"] = "--"
        
        else:
            char_b = await self.getter.get_from_unique(self.client, player_team["b"])
            char_b = f"`{player_team['b']}` | {char_b.image.icon}{char_b.info.name} {char_b.type.icon}{char_b.rarity.icon} lv.{char_b.level:,}" 
        
        ### c
        if(player_team["c"] == None):
            player_team["c"] = "--"
        
        else:
            char_c = await self.getter.get_from_unique(self.client, player_team["c"])
            char_c = f"`{player_team['c']}` | {char_c.image.icon}{char_c.info.name} {char_c.type.icon}{char_c.rarity.icon} lv.{char_c.level:,}"

        # set display
        display_infos = f"""
        *Average level* : {player_team_info['level']}
        *Average rarity* : {player_team_info['rarity']}
        """

        display_character = f"""
        A : **{char_a}** 👑
        B : **{char_b}**
        C : **{char_c}**
        """

        # set the embed
        embed.set_thumbnail(url = player.avatar)
        embed.add_field(
            name = f"{player.name}'s team",
            value = display_infos,
            inline = False
        )

        embed.add_field(
            name = "Fighters",
            value = display_character,
            inline = False
        )

        await ctx.send(embed = embed)

    #################### SET ####################
    @commands.check(Basic_checker().is_game_ready)
    @commands.check(Basic_checker().is_registered)
    @fighter.group(invoke_without_command = True)
    async def set(self, cxt):
        """
        Allow the player to set a fighter
        """

        # display the set help here

    @commands.check(Basic_checker().is_game_ready)
    @commands.check(Basic_checker().is_registered)
    @set.command()
    async def a(self, ctx, character_id):
        """
        Set the fighter slot a
        """

        # init
        player = Player(ctx, self.client, ctx.message.author)
        fighter = Fighter(ctx, self.client, player)

        await fighter.fighter_command("a", character_id)
    
    @commands.check(Basic_checker().is_game_ready)
    @commands.check(Basic_checker().is_registered)
    @set.command()
    async def b(self, ctx, character_id):
        """
        Set the fighter slot b
        """

        # init
        player = Player(ctx, self.client, ctx.message.author)
        fighter = Fighter(ctx, self.client, player)

        await fighter.fighter_command("b", character_id)
    
    @commands.check(Basic_checker().is_game_ready)
    @commands.check(Basic_checker().is_registered)
    @set.command()
    async def c(self, ctx, character_id):
        """
        Set the fighter slot c
        """

        # init
        player = Player(ctx, self.client, ctx.message.author)
        fighter = Fighter(ctx, self.client, player)

        await fighter.fighter_command("c", character_id)
示例#10
0
class Cmd_train(commands.Cog):
    def __init__(self, client):
        self.client = client

    @commands.check(Basic_checker().is_game_ready)
    @commands.check(Basic_checker().is_registered)
    @commands.check(Fight_checker().is_in_fight)
    @commands.check(Fight_checker().has_team)
    @commands.command()
    async def train(self, ctx):
        """
        `coroutine`

        Start a fight against an adaptative team.

        The opponent team level is scaled on the player team level, same for the rarity.

        If the player wins the fight, his character gain some xp.
        """

        # init
        caller = ctx.message.author
        player = Player(ctx, self.client, caller)
        getter = Character_getter()
        tool = Train(self.client)
        leveller = Leveller(self.client, ctx)

        # get caller team
        caller_team = await player.team.get_team()
        player_team = [
            await getter.get_from_unique(self.client, caller_team["a"]), await
            getter.get_from_unique(self.client, caller_team["b"]), await
            getter.get_from_unique(self.client, caller_team["c"])
        ]

        # get opponent team
        opponent_team = await tool.generate_opponent_team(player)

        # test
        opponent_team = [
            await getter.get_character(1), await getter.get_character(2), await
            getter.get_character(3)
        ]

        for char in opponent_team:
            await asyncio.sleep(0)

            char.is_npc = True

        ############ end test ########

        team = [player_team, opponent_team]

        fight = Fight(self.client, ctx, player)

        await ctx.send(f"<@{player.id}> You enter in combat.")

        winner = await fight.run_fight(team)

        # redefine team
        caller_team = await player.team.get_team()

        # check winning condition
        id_team = [caller_team["a"], caller_team["b"], caller_team["c"]]

        # set the xp
        # init
        xp_won = 100
        player_info = await player.team.get_info()
        player_team_level, player_team_rarity = player_info[
            "level"], player_info["rarity"]

        # set the xp gain
        xp_won += (((1.5 * 100) - 100) *
                   player_team_level) + (100 * (player_team_rarity - 1))

        if (winner == 0):  # if the player wins it
            # add xp
            await leveller.team_add_xp(player, id_team, xp_won)

        elif (winner == 2):  # if draw
            # half xp gained
            await leveller.team_add_xp(player, team, xp_won / 2)