예제 #1
0
    async def rps(self, ctx, user_move: str = None, bid: str = None):
        try:
            bid = await user_json.can_do(ctx, ctx.author, bid)
        except:
            await ctx.send(embed=discord.Embed(
                title="",
                description=
                "You can start a rock-paper-scissor game with me by typing `{}rps <rock, paper, or scissors> <bet>`, {}."
                .format(ctx.prefix, ctx.author.mention)))
            return

        if user_move not in self.move_list.keys():
            await ctx.send(embed=discord.Embed(
                title="",
                description=
                "You can start a rock-paper-scissor game with me by typing `{}rps <rock, paper, or scissors> <bet>`, {}."
                .format(ctx.prefix, ctx.author.mention)))
            return

        # choosing the bot's move
        bot_move = random.choice(list(self.move_list))

        # grabbing initial bet
        initial_money = user_json.get_balance(ctx.author)

        # end conditions
        output = ["", ""]
        if user_move == bot_move:
            output[0] = "It's a tie!"
            output[1] = "Your bet is returned."
            bid = 0
        elif (user_move == "rock" and bot_move == "scissors") or (
                user_move == "paper"
                and bot_move == "rock") or (user_move == "scissors"
                                            and bot_move == "paper"):
            output[0] = "{} won!".format(ctx.author.name)
            output[1] = "You earned your bet!"
        else:
            output[0] = "{} lost!".format(ctx.author.name)
            output[1] = "You lost your bet!"
            bid = -bid

        user_json.add_balance(ctx.author, bid)
        embed = discord.Embed(title=output[0],
                              description="{} {} :boom: {}".format(
                                  ctx.author.mention,
                                  self.move_list[user_move],
                                  self.move_list[bot_move]))
        embed.add_field(name="Payout:",
                        value="{}\n{:,} тоХ {:,} {}".format(
                            output[1], initial_money,
                            user_json.get_balance(ctx.author),
                            user_json.get_currency_name()),
                        inline=False)
        await ctx.send(embed=embed)
예제 #2
0
파일: adventure.py 프로젝트: snafuPop/yvona
  async def on_message(self, ctx):
    if (user_json.is_registered(ctx.author)):
      if (ctx.author.id != 547516876851380293):
        # adding 10*<user's level> in credits
        user_json.add_balance(ctx.author, 10 + self.get_user_level(ctx))
      user_dict = user_json.get_users()

      # incrementing text posts
      user_dict[str(ctx.author.id)]["text_posts"] = user_dict[str(ctx.author.id)]["text_posts"] + 1

      # updates their username if applicable
      if user_dict[str(ctx.author.id)]["username"] != ctx.author.name:
        user_dict[str(ctx.author.id)]["username"] = ctx.author.name
      user_json.update(user_dict)
예제 #3
0
 def slot_payout(self, user, value):
   user_json.add_balance(user, value)
   user_json.add_slot_winnings(user, value)
예제 #4
0
파일: adventure.py 프로젝트: snafuPop/yvona
  async def raid(self, ctx, *, boss: str = None):
    if not await self.msg_is_registered(ctx): return

    user_dict = user_json.get_users()
    user_level = self.get_user_level(ctx)
    user_item_level = self.get_user_item_level(ctx)

    # user level isn't high enough to embark on a raid
    if user_level < 10:
      embed = discord.Embed(title = "**Level Too Low!**", description = "You think I'll let a whelp like you embark on a raid, {}? Come back when you're a little stronger - say, **level 10**.".format(ctx.author.mention), color = ctx.author.color)
      embed.set_footer(text = "(You're currently level {:,})".format(user_level))
      self.set_msg_thumbnail(embed, "raid")
      await ctx.send(embed = embed)
      ctx.command.reset_cooldown(ctx)
      return

    # print help information if no boss specified
    if boss == None:
      embed = discord.Embed(title = "**Raid**", description = "So you're interested in embarking on a **raid**, {0}? By embarking on a raid, you'll clash against a monster of tremendous strength and vigor. The damage you deal is based of your **item level**, so the higher your item level, the more damage you'll do and the more money you will receive as compensation for your efforts. Furthermore, once we eventually defeat a boss, we can begin to mobilize against a new threat. Of course, you'll also get EXP and I can only take you on a raid every **12 hours**.\n\nYour current item level is **{1}**, but you can increase that by using `{2}upgrade`. Once you think you're ready, you can use `{2}raid <name of raid zone>` to begin a raid. You can also check the status of all raid bosses with `{2}bosses`.".format(ctx.author.mention, user_item_level, ctx.prefix), color = ctx.author.color)
      self.set_msg_thumbnail(embed, "raid")
      await ctx.send(embed = embed)
      ctx.command.reset_cooldown(ctx)
      return

    boss_dict = user_json.get_bosses()
    boss_name = titlecase(boss)

    # boss is specified but non-existent
    if boss_name not in boss_dict.keys():
      embed = discord.Embed(title = "**Raid**", description = "Uhh... are you sure you got the name right, {}? You can check the status of all raid bosses with `{}bosses`.".format(ctx.author.mention, ctx.prefix), color = ctx.author.color)
      self.set_msg_thumbnail(embed, "raid")
      await ctx.send(embed = embed)
      ctx.command.reset_cooldown(ctx)
      return

    boss = boss_dict[boss_name]

    # no damage dealt - attack failed
    if self.get_user_item_level(ctx) < boss_dict[boss_name]["defense"]:
      embed = discord.Embed(title = "**Raid Results:**", description = "**{}** completely endured {}'s attack! Retreat!".format(boss_name, ctx.author.mention))
      embed.add_field(name = "**Notes:**", value = "When performing an attack against a boss, your item level is reduced by their defense. You're going to need to have a higher item level before you can challenge **{}** (your item level was **{:,}** while **{}'s** defense is **{:,}**). Try upgrading your item level with `{}upgrade`, then try again later.".format(boss_name, user_item_level, boss_name, boss["defense"], ctx.prefix))
      embed.add_field(name = "**Forgiveness Cooldown:**", value = "Because your attack failed, your cooldown timer has been reset.", inline = False)
      self.set_msg_thumbnail(embed, "raid")
      await ctx.send(embed = embed)
      ctx.command.reset_cooldown(ctx)
      return

    damage_dealt = int(self.calculate_damage_dealt(user_level, user_item_level, boss_dict[boss_name]["defense"]))

    # attack succeeded
    # contribution score is based on % of boss's health damaged
    # this score will never go above 1 (10% of HP) or below .01 (.1% of HP)
    contribution_score = 10*damage_dealt/boss["hp_max"]
    if contribution_score > 1: contribution_score = 1
    elif contribution_score < .01: contribution_score = .01
    money_earned = self.calculate_money_earned(contribution_score, boss["multiplier"], boss["hp_max"])
    exp_earned = self.calculate_exp_earned(contribution_score, boss["multiplier"], boss["hp_max"])

    # if boss was already killed
    if boss["hp_cur"] == 0:
      money_earned = int(money_earned * 1.5)
      exp_earned = int(exp_earned * 1.5)
      result_msg = ""
      result_msg += "**Contribution:** {:,} Damage Dealt\n".format(damage_dealt)
      result_msg += "**Bounty Earned:** {:,} {}\n".format(money_earned, user_json.get_currency_name())
      result_msg += "**EXP Earned:** {:,} exp\n".format(exp_earned)
      embed = discord.Embed(title = "**Raid Results:**", description = "A successful attack against **{}'s minions** was performed by {}!\n\n{}".format(boss_name, ctx.author.mention, result_msg), color = ctx.author.color)
      embed.add_field(name = "**Notes:**", value = "Although **{}** was slain long ago, their minions are still about. You'll receive a bonus towards your bounty as well as some extra EXP, but you should get ready to challenge the next boss if you can.".format(boss_name))

    # if boss hasn't been killed yet
    else:
      boss["hp_cur"] = boss["hp_cur"] - damage_dealt

      # check if boss was killed
      was_killed = False
      if boss["hp_cur"] <= 0:
        boss["hp_cur"] = 0
        was_killed = True

      # creating result message
      result_msg = ""
      result_msg += "**Contribution:** {:,} Damage Dealt ({:.2f}% of Boss's Total HP)\n".format(damage_dealt, (damage_dealt/boss["hp_max"])*100)
      result_msg += "**Remaining HP:** {:,} ({:.2f}% Remaining)\n".format(boss["hp_cur"], boss["hp_cur"]/boss["hp_max"]*100)
      result_msg += "**Bounty Earned:** {:,} {}\n".format(money_earned, user_json.get_currency_name())
      result_msg += "**EXP Earned:** {:,} exp\n".format(exp_earned)
      embed = discord.Embed(title = "**Raid Results:**", description = "A successful attack against **{}** was performed by {}!\n\n{}".format(boss_name, ctx.author.mention, result_msg), color = ctx.author.color)

      # adding loot if user dealt the finishing blow
      if was_killed:
        embed.add_field(name = "**{}** was slain!".format(boss_name), value = "Hail to the great warrior {}, who landed the killing blow to **{}**! For their efforts, they have received **{}** from its remains! Long live {}!".format(ctx.author.mention, boss_name, boss["loot"], ctx.author.mention))
        user_json.add_item(ctx.author, boss["loot"])

    self.set_msg_thumbnail(embed, "raid")

    user_json.add_balance(ctx.author, money_earned)
    user_json.add_loot_earnings(ctx.author, money_earned)
    user_json.add_raid(ctx.author)
    user_json.add_damage_dealt(ctx.author, damage_dealt)
    await user_json.add_exp(ctx, ctx.author, exp_earned)

    boss_dict[boss_name] = boss
    user_json.update_bosses(boss_dict)
    await ctx.send(embed = embed)
예제 #5
0
파일: adventure.py 프로젝트: snafuPop/yvona
  async def adventure(self, ctx, *, dungeon: str = None):
    if not await self.msg_is_registered(ctx): return

    # no dungeon specified
    if dungeon is None:
      embed = discord.Embed(title = "**Adventuring**", description = "Hello, {0}! Are you interested in exploring dungeons? Dungeons provide a consistent way of earning money and experience, though you can only go exploring every **10 minutes**. The higher your level, the more dungeons you can go to, and higher level dungeons provide more valuable loot! Keep in mind that the lower your level is compared to the recommended level of the dungeon, the lower your odds of performing a successful exploration. If the success rate is 0%, you can immediately go on another exploration.\n\nYou can pull up a list of dungeons that you can reasonably go to with `{1}dungeons` and explore a dungeon by using `{1}adventure <name of dungeon>`. Happy exploring!".format(ctx.author.mention, ctx.prefix), color = ctx.author.color)
      self.set_msg_thumbnail(embed, "adventure")
      await ctx.send(embed = embed)
      ctx.command.reset_cooldown(ctx)
      return

    dungeon_dict = user_json.get_dungeons()

    # if dungeon is specified but not a real dungeon
    if titlecase(dungeon) not in dungeon_dict["dungeons"]:
      embed = discord.Embed(title = "**Adventuring**", description = "Hmmm... I don't think that's the name of any dungeon I heard of, {}. You can see which dungeons you can go to by using `{}dungeons`.".format(ctx.author.mention, ctx.prefix), color = ctx.author.color)
      self.set_msg_thumbnail(embed, "adventure")
      await ctx.send(embed = embed)
      ctx.command.reset_cooldown(ctx)
      return

    # prepping dicts and keys
    dungeon = titlecase(dungeon)
    user_dict = user_json.get_users()
    user_level = user_dict[str(ctx.author.id)]["level"]
    dungeon_level = dungeon_dict["dungeons"][dungeon]["level"]

    # calculating success rate (min is 0%, max is 100%)
    success_rate = self.get_dungeon_success_rate(user_level, dungeon_level)
    if success_rate < 0: success_rate = 0
    if success_rate > 100: success_rate = 100
    random_rate = randint(0,100) # rng to determine success

    # if the adventure is successful
    if random_rate <= success_rate:
      loot_table = dungeon_dict["dungeons"][dungeon]["loot"]
      loot_list = self.get_loot(loot_table)
      payout = 0

      # calculating value of all loot
      for loot in loot_list:
        payout = payout + loot_table[loot] * self.get_user_item_level(ctx)
      user_json.add_balance(ctx.author, payout)
      exp = int(dungeon_dict["dungeons"][dungeon]["exp"] * uniform(.95,1.15))

      # creating embed
      embed = discord.Embed(title = "**Adventure successful!**", description = "{} embarked on an adventure to **{}** and succeeded!".format(ctx.author.mention, dungeon), color = ctx.author.color)
      embed.add_field(name = "**Loot found:**", value = ', '.join(loot_list), inline = False)
      embed.add_field(name = "**Results:**", value = "Sold **{:,}** piece(s) of loot for **{:,} {}**\nGained **{:,}** exp".format(len(loot_list), payout, user_json.get_currency_name(), exp) , inline = False)
      user_json.add_loot_earnings(ctx.author, payout)
      await user_json.add_exp(ctx, ctx.author, exp)

    # if the adventure failed
    else:
      embed = discord.Embed(title = "**Adventure failed...**", description = "{} embarked on an adventure to **{}** and failed!".format(ctx.author.mention, dungeon), color = ctx.author.color)
      if success_rate == 0:
        embed.add_field(name = "**Forgiveness Cooldown:**", value = "Because your chance to succeed was 0%, your cooldown timer has been reset.")
        ctx.command.reset_cooldown(ctx)

    embed.set_footer(text = "{}% success rate".format(success_rate))
    self.set_msg_thumbnail(embed, "adventure")
    await ctx.send(embed = embed)