Skip to content

Commit

Permalink
Revert "recycle items in cascading" (#3956)
Browse files Browse the repository at this point in the history
  • Loading branch information
BriceSD authored Aug 14, 2016
1 parent 8321879 commit 40ea942
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 97 deletions.
5 changes: 1 addition & 4 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@
"type": "RecycleItems",
"config": {
"min_empty_space": 15,
"max_balls_keep": 150,
"max_potions_keep": 50,
"max_berries_keep": 70,
"max_revives_keep": 70,
"item_filter": {
"Pokeball": { "keep" : 100 },
"Potion": { "keep" : 10 },
Expand Down Expand Up @@ -168,5 +164,6 @@
"Muk": {},
"Weezing": {},
"Flareon": {}

}
}
100 changes: 7 additions & 93 deletions pokemongo_bot/cell_workers/recycle_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ 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},
Expand All @@ -48,11 +44,6 @@ 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):
Expand Down Expand Up @@ -86,100 +77,23 @@ def work(self):
:return: Returns whether or not the task went well
:rtype: WorkerResult
"""

# TODO: Use new inventory everywhere and then remove the inventory update
# Updating inventory

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

worker_result = WorkerResult.SUCCESS

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():
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
"""
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.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
return worker_result

def get_category_inventory_list(self, category_inventory):
"""
Returns an array of items with the item id and item count.
: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):
"""
Expand All @@ -193,8 +107,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)
Expand Down

0 comments on commit 40ea942

Please sign in to comment.