Skip to content
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

Transfert pokemon only when we don't have free slots #4344

Merged
merged 4 commits into from
Aug 20, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configs/config.json.cluster.example
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
{
"type": "TransferPokemon",
"config": {
"min_free_slot": 5,
"transfer_wait_min": 1,
"transfer_wait_max": 4
}
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
{
"type": "TransferPokemon",
"config": {
"min_free_slot": 5,
"transfer_wait_min": 1,
"transfer_wait_max": 4
}
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.map.example
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
{
"type": "TransferPokemon",
"config": {
"min_free_slot": 5,
"transfer_wait_min": 1,
"transfer_wait_max": 4
}
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.path.example
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
{
"type": "TransferPokemon",
"config": {
"min_free_slot": 5,
"transfer_wait_min": 1,
"transfer_wait_max": 4
}
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.pokemon.example
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
{
"type": "TransferPokemon",
"config": {
"min_free_slot": 5,
"transfer_wait_min": 1,
"transfer_wait_max": 4
}
Expand Down
5 changes: 3 additions & 2 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 this amount, the transfer process is triggered. | Big values (i.e 9999) will trigger the transfer porcess after each catch.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process*


### 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.
Expand Down Expand Up @@ -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'```

Expand Down Expand Up @@ -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`.

Expand Down
32 changes: 20 additions & 12 deletions pokemongo_bot/cell_workers/transfer_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,23 @@ 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)
keep_best, keep_best_cp, keep_best_iv = self._validate_keep_best_config(pokemon_name)
#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:
Expand All @@ -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
Expand Down Expand Up @@ -81,14 +86,17 @@ 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():
if pokemon.in_fort or pokemon.is_favorite:
continue

group_id = pokemon.pokemon_id

if group_id not in pokemon_groups:
pokemon_groups[group_id] = []

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -228,20 +236,20 @@ 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

release_config = self._get_release_config_for(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:
Expand All @@ -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

Expand Down