-
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
Fixed seperate transfer bug in worker #1286
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b4a619d
Merge remote-tracking branch 'refs/remotes/origin/dev' into transfer-…
fredrik-hellmangroup 2dfe6f2
seperate worker for transfering pokemons to professor
fredrik-hellmangroup 3b3dcd4
Fixed bug where config parameters wasnt checked
fredrik-hellmangroup 08b7a97
Initial_transfer renamed to release_pokemons
fredrik-hellmangroup 7ad1c2d
added back exception which was missing
fredrik-hellmangroup 69ee170
Default conf value and fixed typo
fredrik-hellmangroup d2f5a00
Capital leter
fredrik-hellmangroup e5b0984
missed to rename on some places
fredrik-hellmangroup 54a9a0b
Merge remote-tracking branch 'refs/remotes/origin/dev' into transfer-…
fredrik-hellmangroup bc6dca5
Log format update
fredrik-hellmangroup 8da686a
moved runtime error to evolved_capture statement
fredrik-hellmangroup 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
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
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 |
---|---|---|
|
@@ -4,8 +4,8 @@ | |
from sets import Set | ||
|
||
from pokemongo_bot import logger | ||
from pokemongo_bot.human_behaviour import sleep, action_delay | ||
|
||
from pokemongo_bot.human_behaviour import sleep | ||
from pokemon_transfer_worker import PokemonTransferWorker | ||
|
||
class PokemonCatchWorker(object): | ||
BAG_FULL = 'bag_full' | ||
|
@@ -34,9 +34,11 @@ def work(self): | |
if self.response_key in response_dict['responses']: | ||
if self.response_status_key in response_dict['responses'][self.response_key]: | ||
if response_dict['responses'][self.response_key][self.response_status_key] is 7: | ||
if self.config.initial_transfer: | ||
if self.config.release_pokemon: | ||
logger.log('Pokemon Bag is full!', 'red') | ||
return PokemonCatchWorker.BAG_FULL | ||
worker = PokemonTransferWorker(self) | ||
worker.work() | ||
|
||
else: | ||
raise RuntimeError('Pokemon Bag is full!') | ||
|
||
|
@@ -192,6 +194,10 @@ def work(self): | |
if status is 1: | ||
|
||
id_list2 = self.count_pokemon_inventory() | ||
pokemon_to_transfer = list(Set(id_list2) - Set(id_list1)) | ||
if len(pokemon_to_transfer) == 0: | ||
raise RuntimeError( | ||
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. Maybe it's because I don't have a lot of state on this, but why are we raising a runtime error? Shouldn't the bot just "return" in this case? I don't think workers should cause the bot to exit |
||
'Trying to transfer or evolve 0 pokemons!') | ||
|
||
self.bot.metrics.captured_pokemon(pokemon_name, cp, iv_display, pokemon_potential) | ||
|
||
|
@@ -202,7 +208,6 @@ def work(self): | |
), 'blue') | ||
|
||
if self.config.evolve_captured: | ||
pokemon_to_transfer = list(Set(id_list2) - Set(id_list1)) | ||
# No need to capture this even for metrics, player stats includes it. | ||
self.api.evolve_pokemon(pokemon_id=pokemon_to_transfer[0]) | ||
response_dict = self.api.call() | ||
|
@@ -214,55 +219,8 @@ def work(self): | |
logger.log( | ||
'Failed to evolve {}!'.format(pokemon_name)) | ||
|
||
if self.should_release_pokemon(pokemon_name, cp, pokemon_potential, response_dict): | ||
# Transfering Pokemon | ||
pokemon_to_transfer = list( | ||
Set(id_list2) - Set(id_list1)) | ||
if len(pokemon_to_transfer) == 0: | ||
raise RuntimeError( | ||
'Trying to transfer 0 pokemons!') | ||
# Add slight delay between capture & candy transfer #774 | ||
logger.log("Waiting briefly before transferring pokemon") | ||
action_delay(self.config.action_wait_min, self.config.action_wait_max) | ||
self.transfer_pokemon(pokemon_to_transfer[0]) | ||
self.bot.metrics.released_pokemon() | ||
logger.log( | ||
'{} has been exchanged for candy!'.format(pokemon_name), 'green') | ||
|
||
break | ||
time.sleep(5) | ||
|
||
def _transfer_low_cp_pokemon(self, value): | ||
response_dict = self.bot.get_inventory() | ||
self._transfer_all_low_cp_pokemon(value, response_dict) | ||
|
||
def _transfer_all_low_cp_pokemon(self, value, response_dict): | ||
try: | ||
reduce(dict.__getitem__, [ | ||
"responses", "GET_INVENTORY", "inventory_delta", "inventory_items"], response_dict) | ||
except KeyError: | ||
pass | ||
else: | ||
for item in response_dict['responses']['GET_INVENTORY']['inventory_delta']['inventory_items']: | ||
try: | ||
reduce(dict.__getitem__, [ | ||
"inventory_item_data", "pokemon"], item) | ||
except KeyError: | ||
pass | ||
else: | ||
pokemon = item['inventory_item_data']['pokemon'] | ||
self._execute_pokemon_transfer(value, pokemon) | ||
time.sleep(1.2) | ||
|
||
def _execute_pokemon_transfer(self, value, pokemon): | ||
if 'cp' in pokemon and pokemon['cp'] < value: | ||
self.api.release_pokemon(pokemon_id=pokemon['id']) | ||
response_dict = self.api.call() | ||
|
||
def transfer_pokemon(self, pid): | ||
self.api.release_pokemon(pokemon_id=pid) | ||
response_dict = self.api.call() | ||
|
||
def count_pokemon_inventory(self): | ||
self.bot.latest_inventory = None # Need accurate count of balls/berries/pokemons | ||
response_dict = self.bot.get_inventory() | ||
|
@@ -337,47 +295,6 @@ def _get_catch_config_for(self, pokemon): | |
catch_config = self.config.catch.get('any') | ||
return catch_config | ||
|
||
def should_release_pokemon(self, pokemon_name, cp, iv, response_dict): | ||
release_config = self._get_release_config_for(pokemon_name) | ||
cp_iv_logic = release_config.get('logic') | ||
if not cp_iv_logic: | ||
cp_iv_logic = self._get_release_config_for('any').get('logic', 'and') | ||
|
||
release_results = { | ||
'cp': False, | ||
'iv': False, | ||
} | ||
|
||
if release_config.get('never_release', False): | ||
return False | ||
|
||
if release_config.get('always_release', False): | ||
return True | ||
|
||
release_cp = release_config.get('release_below_cp', 0) | ||
if cp < release_cp: | ||
release_results['cp'] = True | ||
|
||
release_iv = release_config.get('release_below_iv', 0) | ||
if iv < release_iv: | ||
release_results['iv'] = True | ||
|
||
logic_to_function = { | ||
'or': lambda x, y: x or y, | ||
'and': lambda x, y: x and y | ||
} | ||
|
||
#logger.log( | ||
# "Release config for {}: CP {} {} IV {}".format( | ||
# pokemon_name, | ||
# min_cp, | ||
# cp_iv_logic, | ||
# min_iv | ||
# ), 'yellow' | ||
#) | ||
|
||
return logic_to_function[cp_iv_logic](*release_results.values()) | ||
|
||
def _get_release_config_for(self, pokemon): | ||
release_config = self.config.release.get(pokemon) | ||
if not release_config: | ||
|
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
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.
I thought we weren't going to do this?