Пример #1
0
    async def sell_item(self, item_name, **details):
        player = details["author"]
        channel = details["channel"]
        price_divisor = 4 / 3

        if item_name not in player.inventory[self.inventory_slot]:
            raise util.BattleBananaException(
                channel,
                self.item_type.title() + " not found!")
        if item_name == self.default_item:
            raise util.BattleBananaException(
                channel, "You can't sell that " + self.item_type + "!")

        item = self.get_item(item_name)
        sell_price = item.price // price_divisor
        setattr(player, self.item_type, self.default_item)
        player.inventory[self.inventory_slot].remove(item_name)
        player.money += sell_price
        await util.say(
            channel,
            ("**" + player.name_clean + "** sold the " + self.item_type +
             " **" + item.name_clean + "** for ``" +
             util.format_number(sell_price, money=True, full_precision=True) +
             "``"))
        player.save()
Пример #2
0
    async def mything(ctx, *args, **details):
        player = details["author"]
        page = 1

        things_info = thing_info_preview(player)
        thing_type = things_info["thing_type"]

        if len(args) == 1:
            page = args[0]

        if type(page) is int:
            page -= 1
            thing_list = things_info["thing_list"]
            title = player.get_name_possession_clean() + " " + thing_type.title()+"s"
            thing_embed = things_info["thing_lister"](thing_list, page, title, price_divisor=4 / 3,
                                                      footer_more="But wait there's more! Do " + details["cmd_key"] +
                                                                  things_info["my_command"] + " " + str(page + 2))
            await util.reply(ctx, embed=thing_embed)
        else:
            thing_name = page.lower()
            thing = things_info["thing_getter"](thing_name)
            if thing is None:
                raise util.BattleBananaException(ctx.channel, thing_type.title() + " not found!")
            thing_embed = things_info["thing_info"](thing_name, **details,
                                                    embed=discord.Embed(type="rich", color=gconf.DUE_COLOUR))
            thing_embed.set_footer(text="Do " + details["cmd_key"] + things_info[
                "set_command"] + " " + thing.name + " to use this " + thing_type + "!")
            await util.reply(ctx, embed=thing_embed)
Пример #3
0
 def page_getter(item_list, page, title, **extras):
     page_size = 12
     page_embed = discord.Embed(
         title=title + (" : Page " + str(page + 1) if page > 0 else ""),
         type="rich",
         color=gconf.DUE_COLOUR)
     if len(item_list) > 0 or page != 0:
         if page * page_size >= len(item_list):
             raise util.BattleBananaException(None, "Page not found")
         for item_index in range(page_size * page,
                                 page_size * page + page_size):
             if item_index >= len(item_list):
                 break
             item_add(page_embed,
                      item_list[item_index],
                      index=item_index,
                      **extras)
         if page_size * page + page_size < len(item_list):
             page_embed.set_footer(text=extras.get(
                 "footer_more", "There's more on the next page!"))
         else:
             page_embed.set_footer(
                 text=extras.get("footer_end", "That's all!"))
     else:
         page_embed.description = extras.get("empty_list",
                                             "There's nothing here!")
     return page_embed
Пример #4
0
 async def buy_item(self, item_name, **details):
     customer = details["author"]
     channel = details["channel"]
     if item_name in customer.inventory[self.inventory_slot]:
         raise util.BattleBananaException(
             channel, "You already own that " + self.item_type)
     item = self.get_item(item_name)
     if item is None:
         raise util.BattleBananaException(
             channel,
             self.item_type.title() + " not found!")
     if not self.can_buy(customer, item):
         return True
     if customer.money - item.price >= 0:
         customer.money -= item.price
         customer.inventory[self.inventory_slot].append(item_name)
         if self.item_equipped_on_buy(customer, item_name):
             await util.say(
                 channel,
                 ("**%s** bought the %s **%s** for %s" %
                  (customer.name_clean, self.item_type, item.name_clean,
                   util.format_number(
                       item.price, money=True, ull_precision=True))))
         else:
             await util.say(channel, ((
                 "**%s** bought the %s **%s** for %s\n" +
                 ":warning: You have not yet set this %s! Do **%sset%s %s** to use this %s"
             ) % (customer.name_clean, self.item_type, item.name_clean,
                  util.format_number(
                      item.price, money=True, full_precision=True),
                  self.item_type, details["cmd_key"], self.set_name
                  if hasattr(self, "set_name") else self.item_type,
                  item_name, self.item_type)))
         customer.save()
     else:
         await util.say(
             channel,
             ":anger: You can't afford that " + self.item_type + ".")
Пример #5
0
    async def setthing(ctx, *args, **details):
        player = details["author"]
        thing_info = item_info_setter()
        thing_type = thing_info["thing_type"]
        thing_inventory_slot = thing_info["thing_inventory_slot"]

        thing_id = args[0].lower()
        if thing_id in player.inventory[thing_inventory_slot]:
            # This SHOULD a property setter function
            setattr(player, thing_type, thing_id)
            # This should be a property returning the 'thing' object
            thing = getattr(player, thing_type)
            player.save()
            await util.reply(ctx,
                           ":white_check_mark: " + thing_type.title() + " set to **" + thing.name_clean + "**")
        else:
            raise util.BattleBananaException(ctx.channel, thing_type.title() + " not found!")