Ejemplo n.º 1
0
    async def profile(self, ctx, *, user: discord.User = None):
        if user is None:
            user = ctx.author

        if user.bot:
            if user.id == self.bot.user.id:
                await self.bot.send(ctx, ctx.l.econ.pp.bot_1)
            else:
                await self.bot.send(ctx, ctx.l.econ.pp.bot_2)
            return

        db_user = await self.db.fetch_user(user.id)
        u_items = await self.db.fetch_items(user.id)

        total_wealth = db_user['emeralds'] + db_user.get(
            'vault_bal', 0) * 9 + sum([
                u_it.get('sell_price', 0) * u_it.get('amount', 0)
                for u_it in u_items
            ])
        health_bar = make_health_bar(db_user['health'], 20,
                                     self.d.emojis.heart_full,
                                     self.d.emojis.heart_half,
                                     self.d.emojis.heart_empty)

        vote_streak = db_user['vote_streak']
        voted_today = arrow.utcnow().shift(days=-1) < arrow.get(
            0 if db_user['streak_time'] is None else db_user['streak_time'])

        embed = discord.Embed(color=self.d.cc, description=health_bar)
        embed.set_author(name=user.display_name, icon_url=user.avatar_url_as())

        embed.add_field(name=ctx.l.econ.pp.total_wealth,
                        value=f'{total_wealth}{self.d.emojis.emerald}')
        embed.add_field(name='\uFEFF', value='\uFEFF')
        embed.add_field(name=ctx.l.econ.pp.cmds_sent,
                        value=self.d.cmd_lb.get(user.id, 0))

        embed.add_field(name=ctx.l.econ.pp.streak,
                        value=(vote_streak if vote_streak else 0))
        embed.add_field(name='\uFEFF', value='\uFEFF')
        embed.add_field(name=ctx.l.econ.pp.voted,
                        value=voted_today * ctx.l.econ.pp.yep +
                        ctx.l.econ.pp.nope * (not voted_today))

        embed.add_field(name=ctx.l.econ.pp.pick,
                        value=(await self.db.fetch_pickaxe(user.id)))
        embed.add_field(name='\uFEFF', value='\uFEFF')
        embed.add_field(name=ctx.l.econ.pp.sword,
                        value=(await self.db.fetch_sword(user.id)))

        await ctx.send(embed=embed)
Ejemplo n.º 2
0
    async def spawn_event(self, ctx):
        try:
            await asyncio.sleep(random.randint(1, 200)/100)

            if ctx.guild is None:
                return

            db_guild = await self.db.fetch_guild(ctx.guild.id)
            diff = db_guild['difficulty']

            if diff == 'peaceful': return

            # difficulty multiplier
            diff_multi = 1.5 if diff == 'hard' else 1

            # type of mob that will be spawned, just a string
            mob_key = random.choice(list(self.d.mobs_mech.mobs))

            mob = self.d.mobs_mech.mobs[mob_key].copy()
            mob.update(ctx.l.mobs_mech.mobs[mob_key])
            mob = cj.classify(mob)

            embed = discord.Embed(
                color=self.d.cc,
                title=f'**{random.choice(ctx.l.mobs_mech.mob_drops).format(mob.nice.lower())}**',
                description='Do you want to `fight` the mob?'  # fight it you little baby
            )

            embed.set_image(url=mob.image)

            embed_msg = await ctx.send(embed=embed)

            while True:
                try:
                    engage_msg = await self.bot.wait_for('message', check=(lambda m: self.engage_check(m, ctx)), timeout=15)
                except asyncio.TimeoutError:
                    await embed_msg.edit(suppress=True)
                    return

                u = engage_msg.author
                u_db = await self.db.fetch_user(u.id)

                if u_db['health'] < 2:
                    await self.bot.send(ctx, ctx.l.mobs_mech.no_health)
                else:
                    break

            await embed_msg.edit(suppress=True)

            u_sword = await self.db.fetch_sword(u.id)
            slime_trophy = await self.db.fetch_item(u.id, 'Slime Trophy')

            self.d.pause_econ[u.id] = arrow.utcnow()  # used later on to clear pause_econ based on who's been in there for tooo long

            u_health = u_db['health']
            mob_max_health = mob.health

            iteration = 0

            while True:
                iteration += 1

                embed = discord.Embed(color=self.d.cc, title='Do you want to `attack` or `flee`?')
                embed.set_image(url=mob.image)

                embed.add_field(  # user health bar
                    name=f'**{u.display_name}**',
                    value=make_health_bar(u_health, 20, self.d.emojis.heart_full, self.d.emojis.heart_half, self.d.emojis.heart_empty),
                    inline=False
                )

                embed.add_field(  # mob health bar
                    name=f'**{mob.nice}**',
                    value=make_health_bar(
                        mob.health,
                        mob_max_health,
                        self.d.emojis.heart_full,
                        self.d.emojis.heart_half,
                        self.d.emojis.heart_empty
                    ),
                    inline=False
                )

                msg = await ctx.send(embed=embed)

                try:
                    resp = await self.bot.wait_for('message', check=(lambda m: self.attack_check(m, engage_msg)), timeout=15)  # wait for response
                except asyncio.TimeoutError:  # user didn't respond
                    await msg.edit(suppress=True)

                    self.d.pause_econ.pop(u.id, None)
                    await self.db.update_user(u.id, 'health', u_health)

                    await self.bot.send(ctx, random.choice(ctx.l.mobs_mech.flee_insults))

                    return

                if resp.content.lower() in self.d.mobs_mech.valid_flees:  # user decides to not fight mob anymore cause they a little baby
                    await msg.edit(suppress=True)

                    self.d.pause_econ.pop(u.id, None)
                    await self.db.update_user(u.id, 'health', u_health)

                    await self.bot.send(ctx, random.choice(ctx.l.mobs_mech.flee_insults))

                    return

                u_dmg = await self.calc_sword_damage(u.id, u_sword, diff_multi)  # calculate damage

                if mob_key == 'baby_slime':
                    if iteration < 3 and slime_trophy is None:
                        u_dmg = 0
                    elif slime_trophy is not None and random.choice((True, False, False,)):
                        u_dmg = 0
                    elif iteration >= 3 and random.choice((True, False,)):
                        u_dmg = 0

                mob.health -= u_dmg

                if mob.health < 1:  # user wins
                    self.d.pause_econ.pop(u.id, None)
                    await self.bot.send(ctx, random.choice(ctx.l.mobs_mech.user_finishers).format(mob.nice.lower(), u_sword.lower()))
                    break
                else:
                    if mob_key == 'baby_slime' and u_dmg == 0:
                        await self.bot.send(ctx, random.choice(mob.misses).format(u_sword.lower()))
                    else:
                        await self.bot.send(ctx, random.choice(ctx.l.mobs_mech.user_attacks).format(mob.nice.lower(), u_sword.lower()))  # user attack message

                await asyncio.sleep(1)

                m_dmg = random.randint(2, 6)

                if mob_key == 'creeper':
                    if iteration > 2:
                        if random.choice((True, False, False)):
                            self.d.pause_econ.pop(u.id, None)

                            u_health = 0

                            await self.bot.send(ctx, random.choice(mob.finishers))
                            break

                    m_dmg = 0

                u_health -= m_dmg

                if u_health < 1:  # mob wins
                    self.d.pause_econ.pop(u.id, None)
                    await self.bot.send(ctx, random.choice(mob.finishers))
                    break
                else:
                    await self.bot.send(ctx, random.choice(mob.attacks))

                await asyncio.sleep(1.75)

                await msg.edit(suppress=True)

            await msg.edit(suppress=True)  # remove old Message

            embed = discord.Embed(color=self.d.cc)  # create new embed which shows health to show that user has lost / won
            embed.set_image(url=mob.image)

            # if u_health == 1: u_health = 2
            # if mob.health == 1: mob.health = 2

            # if u_health < 1 or mob.health < 1:
            #     if u_health > mob.health:
            #         u_health = 1
            #         mob.health = 0
            #     else:
            #         u_health = 0
            #         mob.health = 1

            embed.add_field(  # user health bar
                name=f'**{u.display_name}**',
                value=make_health_bar(
                    (u_health if u_health >= 0 else 0),
                    20,
                    self.d.emojis.heart_full,
                    self.d.emojis.heart_half,
                    self.d.emojis.heart_empty
                ),
                inline=False
            )

            embed.add_field(  # mob health bar
                name=f'**{mob.nice}**',
                value=make_health_bar(
                    (mob.health if mob.health >= 0 else 0),
                    mob_max_health,
                    self.d.emojis.heart_full,
                    self.d.emojis.heart_half,
                    self.d.emojis.heart_empty
                ),
                inline=False
            )

            await ctx.send(embed=embed)

            await self.db.update_user(u.id, 'health', u_health)

            u_db = await self.db.fetch_user(u.id)
            u_bal = u_db['emeralds']

            if u_health > 0:  # user win
                if mob_key != 'baby_slime' or random.randint(0, 25) != 1:
                    if diff == 'easy':  # copied this ~~meth~~ math from the old code idek what it does lmao
                        ems_won = int(u_bal * (1 / random.choice((3, 3.25, 3.5, 3.75, 4)))) if u_bal < 256 else int(
                            512 * (1 / random.choice((3, 3.25, 3.5, 3.75, 4))))
                    else:  # diff hard
                        ems_won = int(u_bal * (1 / random.choice((1.75, 2, 2.25, 2.5)))) if u_bal < 256 else int(
                            512 * (1 / random.choice((1.75, 2, 2.25, 2.5))))

                    ems_won = int((ems_won if ems_won > 0 else 1) * diff_multi)

                    if await self.db.fetch_item(u.id, 'Looting II Book') is not None:
                        ems_won = int(ems_won * 1.75)
                    elif await self.db.fetch_item(u.id, 'Looting I Book') is not None:
                        ems_won = int(ems_won * 1.25)

                    await self.db.balance_add(u.id, ems_won)
                    await self.db.update_lb(u.id, 'mobs_killed', 1, 'add')

                    await self.bot.send(ctx, random.choice(ctx.l.mobs_mech.found).format(ems_won, self.d.emojis.emerald))
                else:
                    if diff == 'easy':
                        balls_won = random.randint(1, 10)
                    else:
                        balls_won = random.randint(1, 20)

                    await self.db.add_item(u.id, 'Slime Ball', 5, balls_won, True)

                    await self.bot.send(ctx, random.choice(ctx.l.mobs_mech.found).format(balls_won, self.d.emojis.slimeball))
            else:  # mob win
                if diff == 'easy':  # haha code copying go brrrrrrrrr
                    ems_lost = int(u_bal * (1 / (random.choice([3.05, 3.3, 3.55, 3.8])+.3))) if u_bal > 20 else random.randint(2, 4)
                else:  # diff hard
                    ems_lost = int(u_bal * (1 / (random.choice([1.45, 1.55, 1.65, 1.75])+.3))) if u_bal > 20 else random.randint(5, 9)

                ems_lost = await self.db.balance_sub(u.id, ems_lost)

                if mob_key == 'creeper':
                    await self.bot.send(ctx, random.choice(ctx.l.mobs_mech.lost.creeper).format(ems_lost, self.d.emojis.emerald))
                else:
                    await self.bot.send(ctx, random.choice(ctx.l.mobs_mech.lost.normal).format(mob.nice.lower(), ems_lost, self.d.emojis.emerald))
        except Exception as e:
            await self.events.debug_error(ctx, e)
Ejemplo n.º 3
0
    async def _spawn_event(self, ctx):
        if ctx.guild is None:  # ignore dms
            return

        db_guild = await self.db.fetch_guild(ctx.guild.id)
        difficulty = db_guild["difficulty"]

        if difficulty == "peaceful":
            return

        difficulty_multi = 1.5 if difficulty == "hard" else 1

        # type of mob to be spawned
        mob_key = random.choice(tuple(self.d.mobs_mech.mobs))
        mob = cj.classify({
            **self.d.mobs_mech.mobs[mob_key].copy(),
            **ctx.l.mobs_mech.mobs[mob_key]
        })
        mob_max_health = mob.health

        await asyncio.sleep(random.random() * 3)

        # engage embed
        embed = discord.Embed(
            color=self.d.cc,
            title=
            f"**{random.choice(ctx.l.mobs_mech.mob_drops).format(mob.nice.lower())}**",
            description=ctx.l.mobs_mech.type_engage,
        )
        embed.set_image(url=mob.image)

        engage_msg = await ctx.send(embed=embed)

        # get the user who is going to be attacking the mob
        while True:
            try:
                initial_attack_msg = await self.bot.wait_for(
                    "message", check=self.engage_check(ctx), timeout=15)
            except asyncio.TimeoutError:
                await engage_msg.edit(suppress=True)
                return

            if (await self.ipc.eval(f"econ_paused_users.get({ctx.author.id})")
                ).result is not None:
                continue

            user = initial_attack_msg.author
            db_user = await self.db.fetch_user(user.id)
            user_health = db_user["health"]

            if user_health < 1:
                await self.bot.send_embed(ctx, ctx.l.mobs_mech.no_health)
                continue

            break

        # fetch user's sword, slime trophy, and suppress the engage message
        user_sword, slime_trophy, _ = await asyncio.gather(
            self.db.fetch_sword(user.id),
            self.db.fetch_item(user.id, "Slime Trophy"),
            engage_msg.edit(suppress=True),
        )

        await self.ipc.exec(
            f"econ_paused_users[{ctx.author.id}] = {time.time()}")

        try:
            for iteration in itertools.count(start=1):

                # create embed with mob image
                embed = discord.Embed(color=self.d.cc,
                                      title=ctx.l.mobs_mech.attack_or_flee)
                embed.set_image(url=mob.image)

                # add user health bar to embed
                embed.add_field(
                    name=f"**{user.display_name}**",
                    value=make_health_bar(user_health, 20,
                                          self.d.emojis.heart_full,
                                          self.d.emojis.heart_half,
                                          self.d.emojis.heart_empty),
                    inline=False,
                )

                # add mob health bar to embed
                embed.add_field(
                    name=f"**{mob.nice}**",
                    value=make_health_bar(
                        mob.health,
                        mob_max_health,
                        self.d.emojis.heart_full,
                        self.d.emojis.heart_half,
                        self.d.emojis.heart_empty,
                    ),
                    inline=False,
                )

                fight_msg = await ctx.send(embed=embed)

                try:
                    user_action_msg = await self.bot.wait_for(
                        "message",
                        check=self.attack_check(ctx, initial_attack_msg),
                        timeout=30)
                    user_action = user_action_msg.content.lower()
                except asyncio.TimeoutError:
                    timed_out = True
                else:
                    timed_out = False

                # check if user is a f*****g baby
                if timed_out or user_action in self.d.mobs_mech.valid_flees:
                    await fight_msg.edit(suppress=True)
                    await self.bot.send_embed(
                        ctx, random.choice(ctx.l.mobs_mech.flee_insults))

                    return

                user_dmg = await self.calculate_sword_damage(
                    user.id, user_sword, difficulty_multi)

                # bebe slime is godlike
                if mob_key == "baby_slime":
                    if iteration < 3 and slime_trophy is None:
                        user_dmg = 0
                    elif slime_trophy is not None and random.choice(
                        (True, False, False)):
                        user_dmg = 0
                    elif iteration >= 3 and random.choice((True, False)):
                        user_dmg = 0

                mob.health -= user_dmg

                if mob.health < 1:  # user wins
                    await fight_msg.edit(suppress=True)
                    await self.bot.send_embed(
                        ctx,
                        random.choice(ctx.l.mobs_mech.user_finishers).format(
                            mob.nice.lower(), user_sword.lower()))

                    break
                else:
                    if mob_key == "baby_slime" and user_dmg == 0:  # say user missed the slime
                        await self.bot.send_embed(
                            ctx,
                            random.choice(mob.misses).format(
                                user_sword.lower()))
                    else:  # send regular attack message
                        await self.bot.send_embed(
                            ctx,
                            random.choice(ctx.l.mobs_mech.user_attacks).format(
                                mob.nice.lower(), user_sword.lower()))

                async with ctx.typing():
                    await asyncio.sleep(0.75 + random.random() * 2)

                mob_dmg = random.randint(2, 6)

                if mob_key == "creeper":  # add creeper mechanics
                    if iteration > 2:
                        if random.choice(
                            (True, True, False)
                        ):  # creeper yeets your bloodied corpse across the map
                            user_health = 0

                            await fight_msg.edit(suppress=True)
                            await self.bot.send_embed(
                                ctx, random.choice(mob.finishers))

                            break

                    mob_dmg = 0

                user_health -= mob_dmg
                user_health = max(user_health, 0)

                if user_health < 1:  # you == noob
                    await self.bot.send_embed(ctx,
                                              random.choice(mob.finishers))
                    break
                else:
                    await self.bot.send_embed(ctx, random.choice(mob.attacks))

                async with ctx.typing():
                    await asyncio.sleep(0.75 + random.random() * 2)

                await fight_msg.edit(suppress=True)

            # outside of the for loop
            embed = discord.Embed(color=self.d.cc)
            embed.set_image(url=mob.image)

            embed.add_field(  # user health bar
                name=f"**{user.display_name}**",
                value=make_health_bar(
                    max(user_health, 0),
                    20,
                    self.d.emojis.heart_full,
                    self.d.emojis.heart_half,
                    self.d.emojis.heart_empty,
                ),
                inline=False,
            )

            embed.add_field(  # mob health bar
                name=f"**{mob.nice}**",
                value=make_health_bar(
                    max(mob.health, 0),
                    mob_max_health,
                    self.d.emojis.heart_full,
                    self.d.emojis.heart_half,
                    self.d.emojis.heart_empty,
                ),
                inline=False,
            )

            await ctx.send(embed=embed)

            db_user = await self.db.fetch_user(user.id)
            user_bal = db_user["emeralds"]

            if user_health > 0:  # user win
                if mob_key != "baby_slime" or random.randint(0, 25) != 1:
                    if difficulty == "easy":  # copied this ~~meth~~ math from the old code idek what it does lmao
                        ems_won = (int(user_bal * (1 / random.choice(
                            (3, 3.25, 3.5, 3.75, 4)))) if user_bal < 256 else
                                   int(512 * (1 / random.choice(
                                       (3, 3.25, 3.5, 3.75, 4)))))
                    else:  # difficulty hard
                        ems_won = (int(user_bal * (1 / random.choice(
                            (1.75, 2, 2.25, 2.5)))) if user_bal < 256 else int(
                                512 * (1 / random.choice(
                                    (1.75, 2, 2.25, 2.5)))))

                    ems_won = int(
                        (ems_won if ems_won > 0 else 1) * difficulty_multi)

                    if await self.db.fetch_item(user.id,
                                                "Looting II Book") is not None:
                        ems_won = int(ems_won * 1.75)
                    elif await self.db.fetch_item(
                            user.id, "Looting I Book") is not None:
                        ems_won = int(ems_won * 1.25)

                    await self.db.balance_add(user.id, ems_won)
                    await self.db.update_lb(user.id, "mobs_killed", 1, "add")

                    await self.bot.send_embed(
                        ctx,
                        random.choice(ctx.l.mobs_mech.found).format(
                            ems_won, self.d.emojis.emerald))
                else:
                    if difficulty == "easy":
                        balls_won = random.randint(1, 10)
                    else:
                        balls_won = random.randint(1, 20)

                    if await self.db.fetch_item(user.id,
                                                "Looting II Book") is not None:
                        balls_won *= 1.5
                    elif await self.db.fetch_item(
                            user.id, "Looting I Book") is not None:
                        balls_won *= 1.25

                    balls_won = round(balls_won)

                    await self.db.add_item(user.id, "Slime Ball", 5, balls_won,
                                           True)

                    await self.bot.send_embed(
                        ctx,
                        random.choice(ctx.l.mobs_mech.found).format(
                            balls_won, self.d.emojis.slimeball))
            else:  # mob win
                if difficulty == "easy":  # haha code copying go brrrrrrrrr
                    ems_lost = (int(
                        user_bal *
                        (1 / (random.choice([3.05, 3.3, 3.55, 3.8]) + 0.3)))
                                if user_bal > 20 else random.randint(2, 4))
                else:  # difficulty hard
                    ems_lost = (int(
                        user_bal *
                        (1 / (random.choice([1.45, 1.55, 1.65, 1.75]) + 0.3)))
                                if user_bal > 20 else random.randint(5, 9))

                ems_lost = await self.db.balance_sub(user.id, ems_lost)

                if mob_key == "creeper":
                    await self.bot.send_embed(
                        ctx,
                        random.choice(ctx.l.mobs_mech.lost.creeper).format(
                            ems_lost, self.d.emojis.emerald))
                else:
                    await self.bot.send_embed(
                        ctx,
                        random.choice(ctx.l.mobs_mech.lost.normal).format(
                            mob.nice.lower(), ems_lost, self.d.emojis.emerald),
                    )
        finally:
            await self.db.update_user(user.id, health=user_health)
            await self.ipc.eval(f"econ_paused_users.pop({ctx.author.id}, None)"
                                )  # unpause user