From e8cf987fbe036fefedb7fecb34791ae802a2bae9 Mon Sep 17 00:00:00 2001 From: Assel Meher Date: Sat, 20 Aug 2016 12:05:37 +0100 Subject: [PATCH 1/4] Transfert pokemon only when we don't have free slots --- configs/config.json.cluster.example | 1 + configs/config.json.example | 1 + configs/config.json.map.example | 1 + configs/config.json.path.example | 1 + configs/config.json.pokemon.example | 1 + .../cell_workers/transfer_pokemon.py | 32 ++++++++++++------- 6 files changed, 25 insertions(+), 12 deletions(-) diff --git a/configs/config.json.cluster.example b/configs/config.json.cluster.example index e0b09ac660..7ae6cf582f 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -60,6 +60,7 @@ { "type": "TransferPokemon", "config": { + "min_free_slot": 5, "transfer_wait_min": 1, "transfer_wait_max": 4 } diff --git a/configs/config.json.example b/configs/config.json.example index 8c41649005..bad38df3aa 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -70,6 +70,7 @@ { "type": "TransferPokemon", "config": { + "min_free_slot": 5, "transfer_wait_min": 1, "transfer_wait_max": 4 } diff --git a/configs/config.json.map.example b/configs/config.json.map.example index 04303db871..f7633179c9 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -60,6 +60,7 @@ { "type": "TransferPokemon", "config": { + "min_free_slot": 5, "transfer_wait_min": 1, "transfer_wait_max": 4 } diff --git a/configs/config.json.path.example b/configs/config.json.path.example index d8158a530e..ec37e837bf 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -60,6 +60,7 @@ { "type": "TransferPokemon", "config": { + "min_free_slot": 5, "transfer_wait_min": 1, "transfer_wait_max": 4 } diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index 3237983e68..7a04074f73 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -60,6 +60,7 @@ { "type": "TransferPokemon", "config": { + "min_free_slot": 5, "transfer_wait_min": 1, "transfer_wait_max": 4 } diff --git a/pokemongo_bot/cell_workers/transfer_pokemon.py b/pokemongo_bot/cell_workers/transfer_pokemon.py index e51fd82710..622d9fe170 100644 --- a/pokemongo_bot/cell_workers/transfer_pokemon.py +++ b/pokemongo_bot/cell_workers/transfer_pokemon.py @@ -14,10 +14,15 @@ class TransferPokemon(Datastore, BaseTask): def __init__(self, bot, config): super(TransferPokemon, self).__init__(bot, config) def initialize(self): + self.min_free_slot = self.config.get('min_free_slot', 5) self.transfer_wait_min = self.config.get('transfer_wait_min', 1) self.transfer_wait_max = self.config.get('transfer_wait_max', 4) def work(self): + + if not self._should_work(): + return + pokemon_groups = self._release_pokemon_get_groups() for pokemon_id, group in pokemon_groups.iteritems(): pokemon_name = Pokemons.name_for(pokemon_id) @@ -25,7 +30,7 @@ def work(self): #TODO continue list possible criteria keep_best_possible_criteria = ['cp','iv', 'iv_attack', 'iv_defense', 'iv_stamina', 'moveset.attack_perfection','moveset.defense_perfection','hp','hp_max'] keep_best_custom, keep_best_criteria, keep_amount = self._validate_keep_best_config_custom(pokemon_name, keep_best_possible_criteria) - + best_pokemon_ids = set() order_criteria = 'none' if keep_best: @@ -42,14 +47,14 @@ def work(self): if order_criteria == 'cp': order_criteria = 'cp and iv' else: - order_criteria = 'iv' + order_criteria = 'iv' elif keep_best_custom: limit = keep_amount keep_best_criteria = [str(keep_best_criteria[x]) for x in range(len(keep_best_criteria))] # not sure if the u of unicode will stay, so make it go away best_pokemons = sorted(group, key=attrgetter(*keep_best_criteria), reverse=True)[:limit] best_pokemon_ids = set(pokemon.unique_id for pokemon in best_pokemons) order_criteria = ' then '.join(keep_best_criteria) - + if keep_best or keep_best_custom: # remove best pokemons from all pokemons array all_pokemons = group @@ -81,6 +86,9 @@ def work(self): if self.should_release_pokemon(pokemon): self.release_pokemon(pokemon) + def _should_work(self): + return inventory.Pokemons.get_space_left() <= self.min_free_slot + def _release_pokemon_get_groups(self): pokemon_groups = {} for pokemon in inventory.pokemons().all(): @@ -88,7 +96,7 @@ def _release_pokemon_get_groups(self): continue group_id = pokemon.pokemon_id - + if group_id not in pokemon_groups: pokemon_groups[group_id] = [] @@ -184,7 +192,7 @@ def release_pokemon(self, pokemon): c = conn.cursor() c.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='transfer_log'") - result = c.fetchone() + result = c.fetchone() while True: if result[0] == 1: @@ -211,13 +219,13 @@ def _get_release_config_for(self, pokemon): def _validate_keep_best_config_custom(self, pokemon_name, keep_best_possible_custom): keep_best = False - release_config = self._get_release_config_for(pokemon_name) + release_config = self._get_release_config_for(pokemon_name) keep_best_custom = release_config.get('keep_best_custom', '') keep_amount = release_config.get('amount', 0) if keep_best_custom and keep_amount: keep_best = True - + keep_best_custom = keep_best_custom.split(',') for _str in keep_best_custom: if _str not in keep_best_possible_custom: @@ -228,12 +236,12 @@ def _validate_keep_best_config_custom(self, pokemon_name, keep_best_possible_cus keep_amount = int(keep_amount) except ValueError: keep_best = False - + if keep_amount < 0: keep_best = False - + return keep_best, keep_best_custom, keep_amount - + def _validate_keep_best_config(self, pokemon_name): keep_best = False @@ -241,7 +249,7 @@ def _validate_keep_best_config(self, pokemon_name): keep_best_cp = release_config.get('keep_best_cp', 0) keep_best_iv = release_config.get('keep_best_iv', 0) - + if keep_best_cp or keep_best_iv: keep_best = True try: @@ -253,7 +261,7 @@ def _validate_keep_best_config(self, pokemon_name): keep_best_iv = int(keep_best_iv) except ValueError: keep_best_iv = 0 - + if keep_best_cp < 0 or keep_best_iv < 0: keep_best = False From ae11a2c295cf5ad8af7de17994d380946205e59c Mon Sep 17 00:00:00 2001 From: Assel Meher Date: Sat, 20 Aug 2016 12:49:55 +0100 Subject: [PATCH 2/4] Update configuration file --- docs/configuration_files.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/configuration_files.md b/docs/configuration_files.md index f2b9f42b79..09f86df6e9 100644 --- a/docs/configuration_files.md +++ b/docs/configuration_files.md @@ -54,6 +54,7 @@ The behaviors of the bot are configured via the `tasks` key in the `config.json` * `max_revives_keep`: Default `None` | Maximum amount of revives to keep in inventory * SpinFort * TransferPokemon + * `min_free_slot`: Default `5` | Once the pokebag has less empty slots than that amount, the transfer process is triggered. ### Example configuration: The following configuration tells the bot to transfer all the Pokemon that match the transfer configuration rules, then recycle the items that match its configuration, then catch the pokemon that it can, so on, so forth. Note the last two tasks, MoveToFort and FollowSpiral. When a task is still in progress, it won't run the next things in the list. So it will move towards the fort, on each step running through the list of tasks again. Only when it arrives at the fort and there are no other stops available for it to move towards will it continue to the next step and follow the spiral. @@ -165,7 +166,7 @@ If you already have it, it will keep a stronger version and will transfer the a ### Keep the best custom pokemon configuration (dev branch) -Define a list of criteria to keep the best Pokemons according to those criteria. +Define a list of criteria to keep the best Pokemons according to those criteria. The list of criteria is the following:```'cp','iv', 'iv_attack', 'iv_defense', 'iv_stamina', 'moveset.attack_perfection', 'moveset.defense_perfection', 'hp', 'hp_max'``` @@ -373,7 +374,7 @@ This task will fetch current pokemon spawns from /raw_data of an PokemonGo-Map i * `update_map` - disable/enable if the map location should be automatically updated to the bots current location * `catch` - A dictionary of pokemon to catch with an assigned priority (higher => better) * `snipe_high_prio_only` - Whether to snipe pokemon above a certain threshold. -* `snipe_high_prio_threshold` - The threshold number corresponding with the `catch` dictionary. +* `snipe_high_prio_threshold` - The threshold number corresponding with the `catch` dictionary. * - Any pokemon above this threshold value will be caught by teleporting to its location, and getting back to original location if `snipe` is `True`. * - Any pokemon under this threshold value will make the bot walk to the Pokemon target wether `snipe` is `True` or `False`. From e04c236cd4fd04b852bd300836f9187eb0c68a9c Mon Sep 17 00:00:00 2001 From: Assel Meher Date: Sat, 20 Aug 2016 12:57:21 +0100 Subject: [PATCH 3/4] Added tip --- docs/configuration_files.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/configuration_files.md b/docs/configuration_files.md index 09f86df6e9..8dc8d6c8ce 100644 --- a/docs/configuration_files.md +++ b/docs/configuration_files.md @@ -54,7 +54,7 @@ The behaviors of the bot are configured via the `tasks` key in the `config.json` * `max_revives_keep`: Default `None` | Maximum amount of revives to keep in inventory * SpinFort * TransferPokemon - * `min_free_slot`: Default `5` | Once the pokebag has less empty slots than that amount, the transfer process is triggered. + * `min_free_slot`: Default `5` | Once the pokebag has less empty slots than this amount, the transfer process is triggered. | Big values (i.e 9999) will trigger the transfer porcess after each catch. ### Example configuration: The following configuration tells the bot to transfer all the Pokemon that match the transfer configuration rules, then recycle the items that match its configuration, then catch the pokemon that it can, so on, so forth. Note the last two tasks, MoveToFort and FollowSpiral. When a task is still in progress, it won't run the next things in the list. So it will move towards the fort, on each step running through the list of tasks again. Only when it arrives at the fort and there are no other stops available for it to move towards will it continue to the next step and follow the spiral. From f21ecd32d993171c7907f77591c2eae07ff7792a Mon Sep 17 00:00:00 2001 From: Assel Meher Date: Sat, 20 Aug 2016 13:03:09 +0100 Subject: [PATCH 4/4] Typo --- docs/configuration_files.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/configuration_files.md b/docs/configuration_files.md index 8dc8d6c8ce..e11c1aaa76 100644 --- a/docs/configuration_files.md +++ b/docs/configuration_files.md @@ -54,7 +54,7 @@ The behaviors of the bot are configured via the `tasks` key in the `config.json` * `max_revives_keep`: Default `None` | Maximum amount of revives to keep in inventory * SpinFort * TransferPokemon - * `min_free_slot`: Default `5` | Once the pokebag has less empty slots than this amount, the transfer process is triggered. | Big values (i.e 9999) will trigger the transfer porcess after each catch. + * `min_free_slot`: Default `5` | Once the pokebag has less empty slots than this amount, the transfer process is triggered. | Big values (i.e 9999) will trigger the transfer process after each catch. ### Example configuration: The following configuration tells the bot to transfer all the Pokemon that match the transfer configuration rules, then recycle the items that match its configuration, then catch the pokemon that it can, so on, so forth. Note the last two tasks, MoveToFort and FollowSpiral. When a task is still in progress, it won't run the next things in the list. So it will move towards the fort, on each step running through the list of tasks again. Only when it arrives at the fort and there are no other stops available for it to move towards will it continue to the next step and follow the spiral.