コード例 #1
0
 async def get_level(self, userid):
     async with self.bot.pool.acquire() as conn:
         ret = await conn.fetchval('SELECT xp FROM profile WHERE "user"=$1;', userid)
     if not ret:
         return ret
     else:
         return rpgtools.xptolevel(ret)
コード例 #2
0
ファイル: guild.py プロジェクト: hunterdishner/IdleRPG
 async def is_in_guild(userid, difficulty):
     user = await self.bot.pool.fetchrow(
         'SELECT guild, xp FROM profile WHERE "user"=$1;', userid
     )
     if user[0] == guild["id"]:
         difficulty += int(rpgtools.xptolevel(user[1]))
         return difficulty
     return False
コード例 #3
0
ファイル: guild.py プロジェクト: hunterdishner/IdleRPG
    async def adventure(self, ctx):
        async with self.bot.pool.acquire() as conn:
            guild = await conn.fetchrow(
                'SELECT * FROM profile p JOIN guild g ON (p.guild=g.id) WHERE p."user"=$1;',
                ctx.author.id,
            )
            check = await conn.fetchrow(
                'SELECT * FROM guildadventure WHERE "guildid"=$1;', guild["id"]
            )
            if check:
                return await ctx.send(
                    f"Your guild is already on an adventure! Use `{ctx.prefix}guild status` to view how long it still lasts."
                )

        await ctx.send(
            f"{ctx.author.mention} seeks a guild adventure for **{guild['name']}**! Write `guild adventure join` to join them! Unlimited players can join in the next 30 seconds. The minimum of players required is 3."
        )

        joined = [ctx.author]
        difficulty = int(rpgtools.xptolevel(guild[3]))
        started = False

        async def is_in_guild(userid, difficulty):
            user = await self.bot.pool.fetchrow(
                'SELECT guild, xp FROM profile WHERE "user"=$1;', userid
            )
            if user[0] == guild["id"]:
                difficulty += int(rpgtools.xptolevel(user[1]))
                return difficulty
            return False

        def apply(msg):
            return (
                msg.content.lower() == "guild adventure join"
                and msg.channel == ctx.channel
                and not msg.author.bot
                and msg.author not in joined
            )

        while not started:
            try:
                msg = await self.bot.wait_for("message", check=apply, timeout=30)
                test = await is_in_guild(msg.author.id, difficulty)
                if test:
                    difficulty = test
                    joined.append(msg.author)
                    await ctx.send(
                        f"Alright, {msg.author.mention}, you have been added."
                    )
                else:
                    await ctx.send("You aren't in their guild.")
            except:
                if len(joined) < 3:
                    return await ctx.send(
                        "You didn't get enough other players for the guild adventure."
                    )
                started = True

        time = str(difficulty * 0.5) + "h"

        await ctx.send(
            f"""
Guild adventure for **{guild['name']}** started!
Participants:
{', '.join([m.mention for m in joined])}

Difficulty is **{difficulty}**
Time it will take: **{time}**
"""
        )

        async with self.bot.pool.acquire() as conn:
            enddate = await conn.fetchval(
                "SELECT clock_timestamp() + $1::interval;", todelta(time)
            )
            await conn.execute(
                'INSERT INTO guildadventure ("guildid", "end", "difficulty") VALUES ($1, $2, $3);',
                guild["id"],
                enddate,
                difficulty,
            )
コード例 #4
0
ファイル: adventure.py プロジェクト: hunterdishner/IdleRPG
    async def status(self, ctx):
        async with self.bot.pool.acquire() as conn:
            ret = await conn.fetchrow('SELECT * FROM mission WHERE "name"=$1;',
                                      ctx.author.id)
            if not ret:
                return await ctx.send(
                    f"You are on no mission yet. Use `{ctx.prefix}adventure [DungeonID]` to go out on an adventure!"
                )
            isfinished = await conn.fetchrow(
                'SELECT * FROM mission WHERE name=$1 AND clock_timestamp() > "end";',
                ctx.author.id,
            )
            if isfinished:
                sword = await conn.fetchrow(
                    "SELECT ai.* FROM profile p JOIN allitems ai ON (p.user=ai.owner) JOIN inventory i ON (ai.id=i.item) WHERE i.equipped IS TRUE AND p.user=$1 AND type='Sword';",
                    ctx.author.id,
                )
                shield = await conn.fetchrow(
                    "SELECT ai.* FROM profile p JOIN allitems ai ON (p.user=ai.owner) JOIN inventory i ON (ai.id=i.item) WHERE i.equipped IS TRUE AND p.user=$1 AND type='Shield';",
                    ctx.author.id,
                )
                playerxp = await conn.fetchval(
                    'SELECT xp FROM profile WHERE "user"=$1;', ctx.author.id)
                playerlevel = rpgtools.xptolevel(playerxp)
                try:
                    swordbonus = sword[5]
                except:
                    swordbonus = 0
                try:
                    shieldbonus = shield[6]
                except:
                    shieldbonus = 0

                    # class test
                swordbonus, shieldbonus = await genstats(
                    self.bot, ctx.author.id, swordbonus, shieldbonus)

                boostertest = await conn.fetchval(
                    'SELECT "end" FROM boosters WHERE "user"=$1 AND "type"=$2;',
                    ctx.author.id,
                    2,
                )
                boostertest2 = await conn.fetchval(
                    'SELECT "end" FROM boosters WHERE "user"=$1 AND "type"=$2 AND clock_timestamp() < "end";',
                    ctx.author.id,
                    2,
                )
                if not boostertest and not boostertest2:
                    success = rpgtools.calcchance(
                        swordbonus,
                        shieldbonus,
                        isfinished[3],
                        int(playerlevel),
                        returnsuccess=True,
                    )
                elif boostertest and not boostertest2:
                    await conn.execute(
                        'DELETE FROM boosters WHERE "user"=$1 AND "type"=$2;',
                        ctx.author.id,
                        2,
                    )
                    success = rpgtools.calcchance(
                        swordbonus,
                        shieldbonus,
                        isfinished[3],
                        int(playerlevel),
                        returnsuccess=True,
                    )
                elif boostertest and boostertest2:
                    success = rpgtools.calcchance(
                        swordbonus,
                        shieldbonus,
                        isfinished[3],
                        int(playerlevel),
                        returnsuccess=True,
                        booster=True,
                    )
                if success:
                    if isfinished[3] < 6:
                        maximumstat = float(
                            random.randint(1, isfinished[3] * 5))
                    else:
                        maximumstat = float(random.randint(1, 25))
                    boostertest = await conn.fetchval(
                        'SELECT "end" FROM boosters WHERE "user"=$1 AND "type"=$2;',
                        ctx.author.id,
                        3,
                    )
                    boostertest2 = await conn.fetchval(
                        'SELECT "end" FROM boosters WHERE "user"=$1 AND "type"=$2 AND clock_timestamp() < "end";',
                        ctx.author.id,
                        3,
                    )
                    if not boostertest and not boostertest2:
                        gold = random.randint(1, 30) * isfinished[3]
                    elif boostertest and not boostertest2:
                        await conn.execute(
                            'DELETE FROM boosters WHERE "user"=$1 AND "type"=$2;',
                            ctx.author.id,
                            3,
                        )
                        gold = random.randint(1, 30) * isfinished[3]
                    elif boostertest and boostertest2:
                        gold = int(
                            random.randint(1, 30) * isfinished[3] * 1.25)
                    xp = random.randint(200, 1000) * isfinished[3]
                    shieldorsword = random.choice(["sw", "sh"])
                    names = [
                        "Victo's",
                        "Arsandor's",
                        "Nuhulu's",
                        "Legendary",
                        "Vosag's",
                        "Mitoa's",
                        "Scofin's",
                        "Skeeren's",
                        "Ager's",
                        "Hazuro's",
                        "Atarbu's",
                        "Jadea's",
                        "Zosus'",
                        "Thocubra's",
                        "Utrice's",
                        "Lingoad's",
                        "Zlatorpian's",
                    ]
                    if shieldorsword == "sw":
                        item = await conn.fetchrow(
                            'INSERT INTO allitems ("owner", "name", "value", "type", "damage", "armor") VALUES ($1, $2, $3, $4, $5, $6) RETURNING *;',
                            ctx.author.id,
                            random.choice(names) +
                            random.choice([" Sword", " Blade", " Stich"]),
                            random.randint(1, 40) * isfinished[3],
                            "Sword",
                            maximumstat,
                            0.00,
                        )
                    if shieldorsword == "sh":
                        item = await conn.fetchrow(
                            'INSERT INTO allitems ("owner", "name", "value", "type", "damage", "armor") VALUES ($1, $2, $3, $4, $5, $6) RETURNING *;',
                            ctx.author.id,
                            random.choice(names) +
                            random.choice([" Shield", " Defender", " Aegis"]),
                            random.randint(1, 40) * isfinished[3],
                            "Shield",
                            0.00,
                            maximumstat,
                        )
                    await conn.execute(
                        'INSERT INTO inventory ("item", "equipped") VALUES ($1, $2);',
                        item[0],
                        False,
                    )
                    # marriage partner should get 50% of the money
                    partner = await conn.fetchval(
                        'SELECT marriage FROM profile WHERE "user"=$1;',
                        ctx.author.id)
                    if partner != 0:
                        await conn.execute(
                            'UPDATE profile SET money=money+$1 WHERE "user"=$2;',
                            int(gold / 2),
                            partner,
                        )
                        # guild money
                    guild = await conn.fetchval(
                        'SELECT guild FROM profile WHERE "user"=$1;',
                        ctx.author.id)
                    if guild != 0:
                        await conn.execute(
                            'UPDATE guild SET money=money+$1 WHERE "id"=$2;',
                            int(gold / 10),
                            guild,
                        )

                    await conn.execute(
                        'UPDATE profile SET money=money+$1 WHERE "user"=$2;',
                        gold,
                        ctx.author.id,
                    )
                    await conn.execute(
                        'UPDATE profile SET xp=xp+$1 WHERE "user"=$2;',
                        xp,
                        ctx.author.id,
                    )
                    await conn.execute(
                        'UPDATE profile SET completed=completed+1 WHERE "user"=$1;',
                        ctx.author.id,
                    )
                    if partner == 0:
                        await ctx.send(
                            f"You have completed your dungeon and received **${gold}** as well as a new weapon: **{item[2]}**. Experience gained: **{xp}**."
                        )
                    else:
                        await ctx.send(
                            f"You have completed your dungeon and received **${gold}** as well as a new weapon: **{item[2]}**. Experience gained: **{xp}**.\nYour partner received **${int(gold/2)}**."
                        )
                else:
                    await ctx.send("You died on your mission. Try again!")
                    await conn.execute(
                        'UPDATE profile SET deaths=deaths+1 WHERE "user"=$1;',
                        ctx.author.id,
                    )
                await conn.execute('DELETE FROM mission WHERE "name"=$1;',
                                   ctx.author.id)
            else:
                # mission = await conn.fetchrow('SELECT * FROM mission WHERE name=$1 AND clock_timestamp() < "end";', ctx.author.id)
                mission = ret
                remain = await conn.fetchval("SELECT $1-clock_timestamp();",
                                             mission[2])
                dungeon = await conn.fetchrow(
                    "SELECT * FROM dungeon WHERE id=$1;", mission[3])
                await ctx.send(
                    f"You are currently in the adventure with difficulty `{mission[3]}`.\nApproximate end in `{str(remain).split('.')[0]}`\nDungeon Name: `{dungeon[1]}`"
                )
コード例 #5
0
ファイル: adventure.py プロジェクト: hunterdishner/IdleRPG
    async def adventures(self, ctx):
        async with self.bot.pool.acquire() as conn:
            alldungeons = await conn.fetch(
                'SELECT * FROM dungeon ORDER BY "id";')
            if alldungeons == []:
                owner = (await self.bot.application_info()).owner
                return await ctx.send(
                    "Either no adventures exist or a serious issue occured. Contact `{owner}` please and tell me what you tried."
                )
            sword = await conn.fetchrow(
                "SELECT ai.* FROM profile p JOIN allitems ai ON (p.user=ai.owner) JOIN inventory i ON (ai.id=i.item) WHERE i.equipped IS TRUE AND p.user=$1 AND type='Sword';",
                ctx.author.id,
            )
            shield = await conn.fetchrow(
                "SELECT ai.* FROM profile p JOIN allitems ai ON (p.user=ai.owner) JOIN inventory i ON (ai.id=i.item) WHERE i.equipped IS TRUE AND p.user=$1 AND type='Shield';",
                ctx.author.id,
            )
            playerxp = await conn.fetchval(
                'SELECT xp FROM profile WHERE "user"=$1;', ctx.author.id)
            playerlevel = rpgtools.xptolevel(playerxp)
            try:
                swordbonus = sword[5]
            except:
                swordbonus = 0
            try:
                shieldbonus = shield[6]
            except:
                shieldbonus = 0
            chances = []
            msg = await ctx.send("Loading images...")
            for row in alldungeons:
                success = rpgtools.calcchance(
                    swordbonus,
                    shieldbonus,
                    row[2],
                    int(playerlevel),
                    returnsuccess=False,
                )
                chances.append(
                    (success[0] - success[2], success[1] + success[2]))
            thing = functools.partial(makeadventures, chances)
            images = await self.bot.loop.run_in_executor(None, thing)
            await msg.delete()
            currentpage = 0
            maxpage = len(images) - 1
            f = discord.File(images[currentpage], filename="Adventure.png")
            msg = await ctx.send(
                file=f,
                embed=discord.Embed().set_image(
                    url="attachment://Adventure.png"),
            )
            await msg.add_reaction("\U000023ee")
            await msg.add_reaction("\U000025c0")
            await msg.add_reaction("\U000025b6")
            await msg.add_reaction("\U000023ed")
            await msg.add_reaction("\U0001f522")

            def reactioncheck(reaction, user):
                return (str(reaction.emoji) in [
                    "\U000025c0",
                    "\U000025b6",
                    "\U000023ee",
                    "\U000023ed",
                    "\U0001f522",
                ] and reaction.message.id == msg.id
                        and user.id == ctx.author.id)

            def msgcheck(amsg):
                return amsg.channel == ctx.channel and not amsg.author.bot

            browsing = True
            while browsing:
                try:
                    reaction, user = await self.bot.wait_for(
                        "reaction_add", timeout=60.0, check=reactioncheck)
                    if reaction.emoji == "\U000025c0":
                        if currentpage == 0:
                            pass
                        else:
                            currentpage -= 1
                            await msg.delete()
                            f = discord.File(images[currentpage],
                                             filename=f"Adventure.png")
                            msg = await ctx.send(
                                file=f,
                                embed=discord.Embed().set_image(
                                    url="attachment://Adventure.png"),
                            )
                        try:
                            await msg.remove_reaction(reaction.emoji, user)
                        except:
                            pass
                    elif reaction.emoji == "\U000025b6":
                        if currentpage == maxpage:
                            pass
                        else:
                            currentpage += 1
                            await msg.delete()
                            f = discord.File(images[currentpage],
                                             filename="Adventure.png")
                            msg = await ctx.send(
                                file=f,
                                embed=discord.Embed().set_image(
                                    url="attachment://Adventure.png"),
                            )
                        try:
                            await msg.remove_reaction(reaction.emoji, user)
                        except:
                            pass
                    elif reaction.emoji == "\U000023ed":
                        currentpage = maxpage
                        await msg.delete()
                        f = discord.File(images[currentpage],
                                         filename="Adventure.png")
                        msg = await ctx.send(
                            file=f,
                            embed=discord.Embed().set_image(
                                url="attachment://Adventure.png"),
                        )
                        try:
                            await msg.remove_reaction(reaction.emoji, user)
                        except:
                            pass
                    elif reaction.emoji == "\U000023ee":
                        currentpage = 0
                        await msg.delete()
                        f = discord.File(images[currentpage],
                                         filename="Adventure.png")
                        msg = await ctx.send(
                            file=f,
                            embed=discord.Embed().set_image(
                                url="attachment://Adventure.png"),
                        )
                        try:
                            await msg.remove_reaction(reaction.emoji, user)
                        except:
                            pass
                    elif reaction.emoji == "\U0001f522":
                        question = await ctx.send(
                            f"Enter a page number from `1` to `{maxpage+1}`")
                        num = await self.bot.wait_for("message",
                                                      timeout=10,
                                                      check=msgcheck)
                        if num is not None:
                            try:
                                num2 = int(num.content)
                                if num2 >= 1 and num2 <= maxpage + 1:
                                    currentpage = num2 - 1
                                    await msg.delete()
                                    f = discord.File(images[currentpage],
                                                     filename="Adventure.png")
                                    msg = await ctx.send(
                                        file=f,
                                        embed=discord.Embed().set_image(
                                            url="attachment://Adventure.png"),
                                    )
                                else:
                                    mymsg = await ctx.send(
                                        f"Must be between `1` and `{maxpage+1}`.",
                                        delete_after=2,
                                    )
                                try:
                                    await num.delete()
                                except:
                                    pass
                            except:
                                mymsg = await ctx.send("That is no number!",
                                                       delete_after=2)
                        await question.delete()
                        try:
                            await msg.remove_reaction(reaction.emoji, user)
                        except:
                            pass
                    try:
                        await msg.add_reaction("\U000023ee")
                        await msg.add_reaction("\U000025c0")
                        await msg.add_reaction("\U000025b6")
                        await msg.add_reaction("\U000023ed")
                        await msg.add_reaction("\U0001f522")
                    except:
                        pass
                except:
                    browsing = False
                    try:
                        await msg.clear_reactions()
                    except:
                        pass
                    finally:
                        break