Esempio n. 1
0
    async def need_register(self, ctx):
        """
        `coroutine`

        Check if the player is already registered or not.

        --

        Return : bool
        """

        # init
        handler = ctx.bot.db
        db = Database(handler)

        # check if the player is found
        player = await db.fetchval(
            f"""
            SELECT player_id FROM player_info
            WHERE player_id = {ctx.message.author.id};
            """
        )

        # check if registered
        if(player == None):
            return(True)
        
        else:
            await ctx.send(f"<@{ctx.message.author.id}> ❌ You are already registered.")
            return(False)
Esempio n. 2
0
    async def is_registered(self, ctx):
        """
        `coroutine`

        Check if the caller is already registered in the databse or not.

        --

        Return : bool
        """

        # init
        handler = ctx.bot.db
        db = Database(handler)

        # get the player
        player = await db.fetchval(
            f"""
            SELECT player_id FROM player_info
            WHERE player_id = {ctx.message.author.id};
            """
        )

        # check if registered
        if(player == None):
            await ctx.send(f"<@{ctx.message.author.id}> ❌ You must be **registered** to perform this action.\nUse `d!start` to do so.")
            return(False)
        
        else:
            return(True)
Esempio n. 3
0
    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)
Esempio n. 4
0
    def __init__(self, db_pool, player):
        # parameters
        self.db = Database(db_pool)
        self.player = player

        # init
        self.language = None
        self.translator = None
Esempio n. 5
0
    def __init__(self, client, player):
        # basic
        self.client = client
        self.player = player
        self.db = Database(self.client.db)

        # team
        self.team = {"a": None, "b": None, "c": None}
Esempio n. 6
0
    def __init__(self, client, player):
        # basics
        self.client = client
        self.player = player
        self.db = Database(self.client.db)

        # resource
        self.dragonstone = 0
        self.zenis = 0
Esempio n. 7
0
class Basic_checker:
    """
    Manages the basic checks.
    """

    database = Database(None)

    # method
    async def is_registered(self, ctx):
        """
        `coroutine`

        Check if the caller is already registered in the databse or not.

        --

        Return : bool
        """

        # init
        handler = ctx.bot.db
        db = Database(handler)

        # get the player
        player = await db.fetchval(
            f"""
            SELECT player_id FROM player_info
            WHERE player_id = {ctx.message.author.id};
            """
        )

        # check if registered
        if(player == None):
            await ctx.send(f"<@{ctx.message.author.id}> ❌ You must be **registered** to perform this action.\nUse `d!start` to do so.")
            return(False)
        
        else:
            return(True)

    async def is_game_ready(self, ctx):
        """
        `coroutine`

        Tells if the game is ready to use or not.

        --

        Return : bool
        """

        # init
        game_status = Bot_config.is_ready

        return(game_status)
Esempio n. 8
0
    async def fighter_command(self, slot, character_id):
        """
        Allow the player to select the fighter to set

        `character_id` : int - Represents the character to display
        """

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

        # if a global id is passed
        if(character_id.isdigit()):
            box_data = await player.box.get_data(character_id)
            character_id = int(character_id)
            
            # ask the player to pick the id of his character
            explanation = await self.ctx.send(f"<@{player.id}> Please select a fighter among the following.\n**Close the box** (`❌`) once you have chosen your character, then, **type its index** number :")

            # display the available characters
            await player.box.manager(character_id)

            # ask for choice
            unique_id = await tool.wait_for_fighter_index(box_data)
            if(unique_id == None):
                await self.ctx.send(f"<@{player.id}> Error : character not found.")
                return

            character = await self.getter.get_from_unique(self.client, unique_id)
            await character.init()

            # set the fighter
            possible = await player.team.set_fighter(slot, unique_id)

            if(possible == False):  # the character is already in the team
                await self.ctx.send(f"<@{player.id}> You already have a {character.image.icon}**{character.info.name}** in your team. **Remove** it or choose a different character.")
            
            else:
                # confirm
                await self.ctx.send(f"<@{player.id}> You have successfully set {character.image.icon}**{character.info.name}** {character.type.icon}{character.rarity.icon} lv.{character.level:,} as **fighter {slot.upper()}** !")
            
            await explanation.delete()
        
        else:  # if the character_id is a unique id
            db = Database(self.client.db)
            # check if the player has the character
            owns_character = await db.fetchval(f"SELECT character_owner_name FROM character_unique WHERE character_unique_id = '{character_id}' AND character_owner_id = {player.id};")

            if(owns_character != None):
                character = await self.getter.get_from_unique(self.client, character_id)

                if(character == None):
                    await self.ctx.send(f"<@{player.id}> Character with unique id \"{character_id}\" not found. Please try with another id.\nYou can find your character's unique id by using `d!box [character id]`. The **unique id** format is `aaaa0`.")
                
                else:  # the character has been found
                    await character.init()

                    # set the fighter
                    possible = await player.team.set_fighter(slot, character_id)

                    if(possible == False):  # the character is already in the team
                        await self.ctx.send(f"<@{player.id}> You already have a {character.image.icon}**{character.info.name}** in your team. **Remove** it or choose a different character.")
                
                    else:
                        # confirm
                        await self.ctx.send(f"<@{player.id}> You have successfully set {character.image.icon}**{character.info.name}** {character.type.icon}{character.rarity.icon} lv.{character.level:,} as **fighter {slot.upper()}** !")
                
            else:  # doesn't own the character
                await self.ctx.send(f"<@{player.id}> Character `{character_id}` not found.")
                return
Esempio n. 9
0
 def __init__(self, client):
     self.db = Database(client.db)
     self.sorted = None
Esempio n. 10
0
 def __init__(self, client):
     self.client = client
     self.db = Database(self.client.db)
     self.tables = []
Esempio n. 11
0
    async def get_from_unique(self, client, unique_id):
        """
        `coroutine`

        Get a character instance from its unique id.

        - Parameter : 

        `client` : Represents a `discord.Client`. The client must contain a connection pool to the database.

        `unique_id` : str - Represents the character's unique id to look for.

        --

        Return : character instance. None if not found.
        """

        # init
        db = Database(client.db)
        character = None
        char_father = await db.fetch(
            f"SELECT * FROM character_unique WHERE character_unique_id = '{unique_id}';"
        )

        if (len(char_father) > 0):
            # sort the data
            char_id = char_father[0][4]
            char_type = char_father[0][5]
            char_rarity = char_father[0][6]
            char_level = char_father[0][7]
            char_star = char_father[0][9]
            char_training = {
                "health": char_father[0][10],
                "armor": char_father[0][11],
                "spirit": char_father[0][12],
                "physical": char_father[0][13],
                "ki": char_father[0][14]
            }

            # get the character instance
            character = await self.get_character(char_id)

            # set the character's stats
            character.type.value = char_type
            character.rarity.value = char_rarity
            character.level = char_level

            # training items
            character.enhancement["star"] = char_star
            character.enhancement["training"]["defense"][
                "health"] = char_training["health"]
            character.enhancement["training"]["defense"][
                "armor"] = char_training["armor"]
            character.enhancement["training"]["defense"][
                "armor"] = char_training["spirit"]
            character.enhancement["training"]["damage"][
                "physical"] = char_training["physical"]
            character.enhancement["training"]["damage"]["ki"] = char_training[
                "ki"]

            # init the object
            await character.init()

        return (character)
Esempio n. 12
0
 def __init__(self, client, ctx):
     # basic
     self.client = client
     self.ctx = ctx
     self.db = Database(self.client.db)
     self.getter = Character_getter()
Esempio n. 13
0
    f"d!help | v{Bot_config.version} - {Bot_config.phase}")

# init client
client = commands.AutoShardedBot(command_prefix=Bot_config.prefix,
                                 help_command=None,
                                 activity=presence_activity)
cog = Cog_loader(client)

# logs
logger = logging.getLogger('discord')
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename='discord.log',
                              encoding='utf-8',
                              mode='w')
handler.setFormatter(
    logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler)

# _init
# create the database connection pool
database = Database(
    None)  # pass None as we do not have set up a connection pool yet
client.db = client.loop.run_until_complete(database.init())
background = Background_manager(client)

# loading the cogs
if __name__ == "__main__":
    cog.load_cog()

# run the bot
client.run(Bot_config.token)
Esempio n. 14
0
 def __init__(self, ctx, client, player):
     # basics
     self.client = client
     self.ctx = ctx
     self.player = player
     self.db = Database(self.client.db)