-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
recycle items in cascading #3930
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7b38f05
recycle items in cascading
kowloon 8a026a2
revert the changes of Improved documentation
kowloon 69e2fb6
revert the missing change in Improved documentation
kowloon 4d10b69
fix incorrect maximum variables issue
kowloon 1a1da59
Removed unnecessary parameters
kowloon e84c831
updates removed unnecessary parameters
kowloon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,10 @@ class RecycleItems(BaseTask): | |
"type": "RecycleItems", | ||
"config": { | ||
"min_empty_space": 6, # 6 by default | ||
"max_balls_keep": 150, | ||
"max_potions_keep": 50, | ||
"max_berries_keep": 70, | ||
"max_revives_keep": 70, | ||
"item_filter": { | ||
"Pokeball": {"keep": 20}, | ||
"Greatball": {"keep": 50}, | ||
|
@@ -44,6 +48,11 @@ class RecycleItems(BaseTask): | |
def initialize(self): | ||
self.items_filter = self.config.get('item_filter', {}) | ||
self.min_empty_space = self.config.get('min_empty_space', None) | ||
self.max_balls_keep = self.config.get('max_balls_keep', None) | ||
self.max_potions_keep = self.config.get('max_potions_keep', None) | ||
self.max_berries_keep = self.config.get('max_berries_keep', None) | ||
self.max_revives_keep = self.config.get('max_revives_keep', None) | ||
|
||
self._validate_item_filter() | ||
|
||
def _validate_item_filter(self): | ||
|
@@ -67,7 +76,7 @@ def should_run(self): | |
:return: True if the recycling process should be run; otherwise, False. | ||
:rtype: bool | ||
""" | ||
if inventory.Items.get_space_left() < (DEFAULT_MIN_EMPTY_SPACE if self.min_empty_space is None else self.min_empty_space): | ||
if inventory.items().get_space_left() < (DEFAULT_MIN_EMPTY_SPACE if self.min_empty_space is None else self.min_empty_space): | ||
return True | ||
return False | ||
|
||
|
@@ -77,23 +86,97 @@ def work(self): | |
:return: Returns whether or not the task went well | ||
:rtype: WorkerResult | ||
""" | ||
|
||
# TODO: Use new inventory everywhere and then remove this inventory update | ||
|
||
# TODO: Use new inventory everywhere and then remove the inventory update | ||
# Updating inventory | ||
inventory.refresh_inventory() | ||
|
||
worker_result = WorkerResult.SUCCESS | ||
|
||
if self.should_run(): | ||
|
||
if not (self.max_balls_keep is None): | ||
self.recycle_excess_category_max(self.max_balls_keep, [1,2,3,4]) | ||
if not (self.max_potions_keep is None): | ||
self.recycle_excess_category_max(self.max_potions_keep, [101,102,103,104]) | ||
if not (self.max_berries_keep is None): | ||
self.recycle_excess_category_max(self.max_potions_keep, [701,702,703,704]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copypasta striked again :P |
||
if not (self.max_revives_keep is None): | ||
self.recycle_excess_category_max(self.max_potions_keep, [201,202]) | ||
|
||
for item_in_inventory in inventory.items().all(): | ||
amount_to_recycle = self.get_amount_to_recycle(item_in_inventory) | ||
|
||
if self.item_should_be_recycled(item_in_inventory): | ||
# Make the bot appears more human | ||
action_delay(self.bot.config.action_wait_min, self.bot.config.action_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 | ||
|
||
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 | ||
""" | ||
category_inventory = self.get_category_inventory_list(inventory, 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.bot.config.action_wait_min, self.bot.config.action_wait_max) | ||
if ItemRecycler(self.bot, inventory.items().get(item[0]), item[1]).work() == WorkerResult.ERROR: | ||
worker_result = WorkerResult.ERROR | ||
|
||
def get_category_inventory_list(self, inventory, category_inventory): | ||
""" | ||
Returns an array of items with the item id and item count. | ||
:param inventory: | ||
:param category_inventory: | ||
:return: array of items within a category: | ||
:rtype: array | ||
""" | ||
x = 0 | ||
category_inventory_list = [] | ||
for c in category_inventory: | ||
category_inventory_list.append([]) | ||
category_inventory_list[x].append(c) | ||
category_inventory_list[x].append(inventory.items().get(c).count) | ||
x = x + 1 | ||
return category_inventory_list | ||
|
||
def get_category_items_to_recycle(self, category_inventory, category_count, category_max): | ||
""" | ||
Returns an array to be recycle within a category of items with the item id and item count. | ||
:param category_inventory: | ||
:param category_count: | ||
:param category_max: | ||
:return: array of items to be recycle. | ||
:rtype: array | ||
""" | ||
x = 0 | ||
items_to_recycle = [] | ||
if category_count > self.max_balls_keep: | ||
items_to_be_recycled = category_count - category_max | ||
|
||
for item in category_inventory: | ||
if items_to_be_recycled == 0: | ||
break | ||
if items_to_be_recycled >= item[1]: | ||
items_to_recycle.append([]) | ||
items_to_recycle[x].append(item[0]) | ||
items_to_recycle[x].append(item[1]) | ||
else: | ||
items_to_recycle.append([]) | ||
items_to_recycle[x].append(item[0]) | ||
items_to_recycle[x].append(items_to_be_recycled) | ||
items_to_be_recycled = items_to_be_recycled - items_to_recycle[x][1] | ||
x = x + 1 | ||
return items_to_recycle | ||
|
||
def item_should_be_recycled(self, item): | ||
""" | ||
|
@@ -107,8 +190,8 @@ def item_should_be_recycled(self, item): | |
def get_amount_to_recycle(self, item): | ||
""" | ||
Determine the amount to recycle accordingly to user config | ||
:param item: Item to determine the amount to recycle. | ||
:return: The amount to recycle | ||
:param item: Item to determine the amount to recycle | ||
:return: The amount to recycle. | ||
:rtype: int | ||
""" | ||
amount_to_keep = self.get_amount_to_keep(item) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job on reverting changes, you forgot this one though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated