From 2814ec54cc699e7c1e7ad3f26acc02302cc98c9b Mon Sep 17 00:00:00 2001 From: Stuart Travers Date: Fri, 16 Sep 2016 11:18:37 +1000 Subject: [PATCH] Added release_below_ivcp and keep_best_ivcp Refer #5225 --- configs/config.json.cluster.example | 4 +- configs/config.json.example | 4 +- configs/config.json.map.example | 4 +- configs/config.json.path.example | 4 +- configs/config.json.pokemon.example | 2 +- pokemongo_bot/__init__.py | 8 +- .../cell_workers/transfer_pokemon.py | 78 ++++++++++++++----- .../event_handlers/logging_handler.py | 1 + 8 files changed, 79 insertions(+), 26 deletions(-) diff --git a/configs/config.json.cluster.example b/configs/config.json.cluster.example index 4deddb7db1..61ea61076b 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -268,7 +268,7 @@ "// Rattata": { "always_catch" : true } }, "release": { - "any": {"release_below_cp": 0, "release_below_iv": 0, "logic": "or"}, + "any": {"release_below_cp": 0, "release_below_iv": 0, "release_below_ivcp": 0, "logic": "or"}, "// Example of always releasing Rattata:": {}, "// Rattata": {"always_release": true}, "// Example of keeping 3 stronger (based on CP) Pidgey:": {}, @@ -277,6 +277,8 @@ "// Zubat": {"keep_best_iv": 2}, "// Keep no more than 3 best IV pokemon for every pokemon type": {}, "// any": {"keep_best_iv": 3}, + "// Keep no more than 3 best IVCP pokemon for every pokemon type": {}, + "// any": {"keep_best_ivcp": 3}, "// Discard all pokemon in bag except 100 pokemon with best CP": {}, "// all": {"keep_best_cp": 100}, "// Example of keeping the 2 strongest (based on CP) and 3 best (based on IV) Zubat:": {}, diff --git a/configs/config.json.example b/configs/config.json.example index d167f1ba47..467f4f185c 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -345,7 +345,7 @@ "Vaporeon": { "catch_above_iv": 0.99, "charged_attack": ["Hydro Pump"], "fast_attack": ["Water Gun"]} }, "release": { - "any": {"release_below_cp": 0, "release_below_iv": 0, "logic": "or"}, + "any": {"release_below_cp": 0, "release_below_iv": 0, "release_below_ivcp": 0, "logic": "or"}, "// Example of always releasing Rattata:": {}, "// Rattata": {"always_release": true}, "// Example of keeping 3 stronger (based on CP) Pidgey:": {}, @@ -354,6 +354,8 @@ "// Zubat": {"keep_best_iv": 2}, "// Keep no more than 3 best IV pokemon for every pokemon type": {}, "// any": {"keep_best_iv": 3}, + "// Keep no more than 3 best IVCP pokemon for every pokemon type": {}, + "// any": {"keep_best_ivcp": 3}, "// Discard all pokemon in bag except 100 pokemon with best CP": {}, "// all": {"keep_best_cp": 100}, "// Example of keeping the 2 strongest (based on CP) and 3 best (based on IV) Zubat:": {}, diff --git a/configs/config.json.map.example b/configs/config.json.map.example index 4d52e7ea08..856ce3e865 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -534,7 +534,7 @@ "// Rattata": { "always_catch" : true } }, "release": { - "any": {"release_below_cp": 0, "release_below_iv": 0, "logic": "or"}, + "any": {"release_below_cp": 0, "release_below_iv": 0, "release_below_ivcp": 0, "logic": "or"}, "// Example of always releasing Rattata:": {}, "// Rattata": {"always_release": true}, "// Example of keeping 3 stronger (based on CP) Pidgey:": {}, @@ -543,6 +543,8 @@ "// Zubat": {"keep_best_iv": 2}, "// Keep no more than 3 best IV pokemon for every pokemon type": {}, "// any": {"keep_best_iv": 3}, + "// Keep no more than 3 best IVCP pokemon for every pokemon type": {}, + "// any": {"keep_best_ivcp": 3}, "// Discard all pokemon in bag except 100 pokemon with best CP": {}, "// all": {"keep_best_cp": 100}, "// Example of keeping the 2 strongest (based on CP) and 3 best (based on IV) Zubat:": {}, diff --git a/configs/config.json.path.example b/configs/config.json.path.example index da649ce38d..98c7e68f65 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -274,7 +274,7 @@ "// Rattata": { "always_catch" : true } }, "release": { - "any": {"release_below_cp": 0, "release_below_iv": 0, "logic": "or"}, + "any": {"release_below_cp": 0, "release_below_iv": 0, "release_below_ivcp": 0, "logic": "or"}, "// Example of always releasing Rattata:": {}, "// Rattata": {"always_release": true}, "// Example of keeping 3 stronger (based on CP) Pidgey:": {}, @@ -283,6 +283,8 @@ "// Zubat": {"keep_best_iv": 2}, "// Keep no more than 3 best IV pokemon for every pokemon type": {}, "// any": {"keep_best_iv": 3}, + "// Keep no more than 3 best IVCP pokemon for every pokemon type": {}, + "// any": {"keep_best_ivcp": 3}, "// Discard all pokemon in bag except 100 pokemon with best CP": {}, "// all": {"keep_best_cp": 100}, "// Example of keeping the 2 strongest (based on CP) and 3 best (based on IV) Zubat:": {}, diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index 000fa1deec..151e8c97c4 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -348,7 +348,7 @@ "Kangaskhan": { "always_catch": true } }, "release": { - "any": {"release_below_cp": 0, "release_below_iv": 0, "logic": "or" }, + "any": {"release_below_cp": 0, "release_below_iv": 0, "release_below_ivcp": 0, "logic": "or" }, "// Legendary pokemons (Goes under S-Tier)": {}, "Lapras": { "release_below_cp": 1041, "release_below_iv": 0.8, "logic": "and" }, diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 04eaf5ae67..71c427e7da 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -565,12 +565,16 @@ def _register_events(self): self.event_manager.register_event( 'future_pokemon_release', parameters=( - 'pokemon', 'cp', 'iv', 'below_iv', 'below_cp', 'cp_iv_logic' + 'pokemon', 'cp', 'iv', 'ivcp', 'below_iv', 'below_cp', 'below_ivcp', 'cp_iv_logic' ) ) self.event_manager.register_event( 'pokemon_release', - parameters=('pokemon', 'iv', 'cp', 'candy') + parameters=('pokemon', 'iv', 'cp', 'ivcp', 'candy') + ) + self.event_manager.register_event( + 'pokemon_keep', + parameters=('pokemon', 'iv', 'cp', 'ivcp') ) # polyline walker diff --git a/pokemongo_bot/cell_workers/transfer_pokemon.py b/pokemongo_bot/cell_workers/transfer_pokemon.py index 8c57726587..424fcfa2c1 100644 --- a/pokemongo_bot/cell_workers/transfer_pokemon.py +++ b/pokemongo_bot/cell_workers/transfer_pokemon.py @@ -35,6 +35,7 @@ def work(self): self._release_pokemon_worst_in_group(group, 'all') def _should_work(self): + return True random_number = randrange (0,20,1) return inventory.Pokemons.get_space_left() <= self.min_free_slot - random_number @@ -54,10 +55,10 @@ def _release_pokemon_get_groups(self): return pokemon_groups def _release_pokemon_worst_in_group(self, group, pokemon_name): - keep_best, keep_best_cp, keep_best_iv = self._validate_keep_best_config( + keep_best, keep_best_cp, keep_best_iv, keep_best_ivcp = self._validate_keep_best_config( pokemon_name) # TODO continue list possible criteria - keep_best_possible_criteria = ['cp', 'iv', 'iv_attack', 'iv_defense', 'iv_stamina', + keep_best_possible_criteria = ['cp', 'iv', 'iv_attack', 'iv_defense', 'iv_stamina', 'ivcp', '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) @@ -65,24 +66,36 @@ def _release_pokemon_worst_in_group(self, group, pokemon_name): best_pokemon_ids = set() order_criteria = 'none' if keep_best: - if keep_best_cp >= 1: + if keep_best_ivcp > 0: + ivcp_limit = keep_best_ivcp + best_ivcp_pokemons = sorted(group, key=lambda x: ( + x.ivcp), reverse=True)[:ivcp_limit] + best_pokemon_ids = set( + pokemon.unique_id for pokemon in best_ivcp_pokemons) + order_criteria = 'ivcp' + + if keep_best_cp > 0: cp_limit = keep_best_cp best_cp_pokemons = sorted(group, key=lambda x: ( x.cp, x.iv), reverse=True)[:cp_limit] best_pokemon_ids = set( pokemon.unique_id for pokemon in best_cp_pokemons) - order_criteria = 'cp' + if order_criteria != 'none': + order_criteria = order_criteria + ' and cp' + else: + order_criteria = 'cp' - if keep_best_iv >= 1: + if keep_best_iv > 0: iv_limit = keep_best_iv best_iv_pokemons = sorted(group, key=lambda x: ( x.iv, x.cp), reverse=True)[:iv_limit] best_pokemon_ids |= set( pokemon.unique_id for pokemon in best_iv_pokemons) - if order_criteria == 'cp': - order_criteria = 'cp and iv' + if order_criteria != 'none': + order_criteria = order_criteria + ' and iv' else: order_criteria = 'iv' + elif keep_best_custom: limit = keep_amount # not sure if the u of unicode will stay, so make it go away @@ -118,6 +131,18 @@ def _release_pokemon_worst_in_group(self, group, pokemon_name): 'criteria': order_criteria } ) + for pokemon in best_pokemons: + self.emit_event( + 'pokemon_keep', + data={ + 'pokemon': pokemon.name, + 'iv': pokemon.iv, + 'cp': pokemon.cp, + 'ivcp': pokemon.ivcp + }, + formatted="Kept {} (CP: {}, IV: {}, IVCP: {})".format(pokemon.name, pokemon.cp, pokemon.iv, pokemon.ivcp), + ) + for pokemon in transfer_pokemons: self.release_pokemon(pokemon) else: @@ -133,7 +158,8 @@ def should_release_pokemon(self, pokemon, keep_best_mode=False): and not release_config.has_key('never_release') and not release_config.has_key('always_release') and not release_config.has_key('release_below_cp') - and not release_config.has_key('release_below_iv')): + and not release_config.has_key('release_below_iv') + and not release_config.has_key('release_below_ivcp')): return True cp_iv_logic = release_config.get('logic') @@ -144,6 +170,7 @@ def should_release_pokemon(self, pokemon, keep_best_mode=False): release_results = { 'cp': False, 'iv': False, + 'ivcp': False } if release_config.get('never_release', False): @@ -160,23 +187,29 @@ def should_release_pokemon(self, pokemon, keep_best_mode=False): if pokemon.iv < release_iv: release_results['iv'] = True + release_ivcp = release_config.get('release_below_ivcp', 0) + if pokemon.ivcp < release_ivcp: + release_results['ivcp'] = True + logic_to_function = { - 'or': lambda x, y: x or y, - 'and': lambda x, y: x and y + 'or': lambda x, y, z: x or y or z, + 'and': lambda x, y, z: x and y and z } if logic_to_function[cp_iv_logic](*release_results.values()): self.emit_event( 'future_pokemon_release', - formatted="*Releasing {}* CP: {}, IV: {} | based on rule: CP < {} {} IV < {}".format(pokemon.name, pokemon.cp, pokemon.iv, - release_cp, cp_iv_logic.upper(),release_iv), + formatted="*Releasing {}* CP: {}, IV: {}, IVCP: {} | based on rule: CP < {} {} IV < {} IVCP < {}".format(pokemon.name, pokemon.cp, pokemon.iv, pokemon.ivcp, + release_cp, cp_iv_logic.upper(),release_iv, release_ivcp), data={ 'pokemon': pokemon.name, 'cp': pokemon.cp, 'iv': pokemon.iv, + 'ivcp': pokemon.ivcp, 'below_cp': release_cp, 'cp_iv_logic': cp_iv_logic.upper(), - 'below_iv': release_iv + 'below_iv': release_iv, + 'below_ivcp': release_ivcp }, ) @@ -209,9 +242,10 @@ def release_pokemon(self, pokemon): 'pokemon': pokemon.name, 'iv': pokemon.iv, 'cp': pokemon.cp, + 'ivcp': pokemon.ivcp, 'candy': candy.quantity }, - formatted="*{} Released* You now have {} {} candies".format(pokemon.name, candy.quantity, pokemon.name), + formatted="Released {} (CP: {}, IV: {}, IVCP: {}) You now have {} {} candies".format(pokemon.name, pokemon.cp, pokemon.iv, pokemon.ivcp, candy.quantity, pokemon.name), ) with self.bot.database as conn: c = conn.cursor() @@ -276,8 +310,9 @@ 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) + keep_best_ivcp = release_config.get('keep_best_ivcp', 0) - if keep_best_cp or keep_best_iv: + if keep_best_cp or keep_best_iv or keep_best_ivcp: keep_best = True try: keep_best_cp = int(keep_best_cp) @@ -289,10 +324,15 @@ def _validate_keep_best_config(self, pokemon_name): except ValueError: keep_best_iv = 0 - if keep_best_cp < 0 or keep_best_iv < 0: + try: + keep_best_ivcp = int(keep_best_ivcp) + except ValueError: + keep_best_ivcp = 0 + + if keep_best_cp < 0 or keep_best_iv < 0 or keep_best_ivcp < 0: keep_best = False - if keep_best_cp == 0 and keep_best_iv == 0: + if keep_best_cp == 0 and keep_best_iv == 0 and keep_best_ivcp == 0: keep_best = False - - return keep_best, keep_best_cp, keep_best_iv + + return keep_best, keep_best_cp, keep_best_iv, keep_best_ivcp diff --git a/pokemongo_bot/event_handlers/logging_handler.py b/pokemongo_bot/event_handlers/logging_handler.py index 2dff9dbb79..a841165980 100644 --- a/pokemongo_bot/event_handlers/logging_handler.py +++ b/pokemongo_bot/event_handlers/logging_handler.py @@ -55,6 +55,7 @@ class LoggingHandler(EventHandler): 'pokemon_inventory_full': 'red', 'pokemon_nickname_invalid': 'red', 'pokemon_not_in_range': 'yellow', + 'pokemon_keep': 'green', 'pokemon_release': 'green', 'pokemon_upgraded': 'green', 'pokemon_vanished': 'red',