Esempio n. 1
0
    def work(self):
        """
        Start the process of recycling items if necessary.
        :return: Returns whether or not the task went well
        :rtype: WorkerResult
        """

        # TODO: Use new inventory everywhere and then remove this inventory update
        inventory.refresh_inventory()

        worker_result = WorkerResult.SUCCESS
        if self.should_run():

            if not (self.max_balls_keep is None):
                worker_result = self.recycle_excess_category_max(self.max_balls_keep, [1,2,3,4])
            if not (self.max_potions_keep is None):
                worker_result = self.recycle_excess_category_max(self.max_potions_keep, [101,102,103,104])
            if not (self.max_berries_keep is None):
                worker_result = self.recycle_excess_category_max(self.max_berries_keep, [701,702,703,704,705])
            if not (self.max_revives_keep is None):
                worker_result = self.recycle_excess_category_max(self.max_revives_keep, [201,202])

            inventory.refresh_inventory()

            for item_in_inventory in inventory.items().all():

                if self.item_should_be_recycled(item_in_inventory):
                    # Make the bot appears more human
                    action_delay(self.recycle_wait_min, self.recycle_wait_max)
                    # If at any recycling process call we got an error, we consider that the result of this task is error too.
                    if ItemRecycler(self.bot, item_in_inventory, self.get_amount_to_recycle(item_in_inventory)).work() == WorkerResult.ERROR:
                        worker_result = WorkerResult.ERROR

        return worker_result
Esempio n. 2
0
    def recycle(self, amount_to_recycle):
        """
        Recycle (discard) the specified amount of item from the item inventory.
        It is making a call to the server to request a recycling as well as updating the cached inventory.
        :param amount_to_recycle: The amount to recycle.
        :type amount_to_recycle: int
        :return: Returns whether or not the task went well
        :rtype: worker_result.WorkerResult
        """
        if self.count < amount_to_recycle:
            raise Exception('Tried to remove more {} than you have'.format(self.name))

        item_recycler = ItemRecycler(_inventory.bot, self, amount_to_recycle)
        item_recycler_work_result = item_recycler.work()

        if item_recycler.is_recycling_success():
            self.remove(amount_to_recycle)

        return item_recycler_work_result
Esempio n. 3
0
    def recycle(self, amount_to_recycle):
        """
        Recycle (discard) the specified amount of item from the item inventory.
        It is making a call to the server to request a recycling as well as updating the cached inventory.
        :param amount_to_recycle: The amount to recycle.
        :type amount_to_recycle: int
        :return: Returns whether or not the task went well
        :rtype: worker_result.WorkerResult
        """
        if self.count < amount_to_recycle:
            raise Exception('Tried to remove more {} than you have'.format(self.name))

        item_recycler = ItemRecycler(_inventory.bot, self, amount_to_recycle)
        item_recycler_work_result = item_recycler.work()

        if item_recycler.is_recycling_success():
            self.remove(amount_to_recycle)

        return item_recycler_work_result
Esempio n. 4
0
 def recycle_excess_category_max(self, category_max, category_items_list):
     """
     Recycle the item which excess the category max
     :param category_max:
     :param category_items_list:
     :return: none:
     :rtype: None
     """
     worker_result = WorkerResult.SUCCESS
     category_inventory = self.get_category_inventory_list(category_items_list)
     category_count = 0
     for i in category_inventory:
        category_count = category_count + i[1]
     items_to_recycle = self.get_category_items_to_recycle(category_inventory, category_count, category_max)
     for item in items_to_recycle:
         action_delay(self.recycle_wait_min, self.recycle_wait_max)
         if ItemRecycler(self.bot, inventory.items().get(item[0]), item[1]).work() == WorkerResult.ERROR:
             worker_result = WorkerResult.ERROR
     return worker_result