Skip to content

Commit

Permalink
Merge pull request #5995 from walaoaaa1234/Bulktransfer
Browse files Browse the repository at this point in the history
Bulktransfer improve
  • Loading branch information
Jcolomar authored Apr 4, 2017
2 parents 418f4a3 + e2024f5 commit 9e38b73
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 41 deletions.
38 changes: 19 additions & 19 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,26 @@
- [Options](#options)
- [Example](#example)
- [Sniping _(Sniper)_](#sniper)
- [Description](#description)
- [Options](#options)
- [Description](#description-1)
- [Options](#options-1)
- [Example](#example)
- [FollowPath Settings](#followpath-settings)
- [Description](#description)
- [Options](#options)
- [Sample Configuration](#sample-configuration)
- [Description](#description-2)
- [Options](#options-2)
- [Sample Configuration](#sample-configuration-1)
- [UpdateLiveStats Settings](#updatelivestats-settings)
- [Options](#options)
- [Sample Configuration](#sample-configuration)
- [Options](#options-3)
- [Sample Configuration](#sample-configuration-2)
- [UpdateLiveInventory Settings](#updateliveinventory-settings)
- [Description](#description)
- [Options](#options)
- [Sample configuration](#sample-configuration)
- [Description](#description-3)
- [Options](#options-4)
- [Sample configuration](#sample-configuration-3)
- [Example console output](#example-console-output)
- [UpdateHashStats Settings](#updatehashstats-settings)
- [Description](#description)
- [Options](#options)
- [Sample configuration](#sample-configuration)
- [Example console output](#example-console-output)
- [Description](#description-4)
- [Options](#options-5)
- [Sample configuration](#sample-configuration-4)
- [Example console output](#example-console-output-1)
- [Random Pause](#random-pause)
- [Egg Incubator](#egg-incubator)
- [ShowBestPokemon](#showbestpokemon)
Expand Down Expand Up @@ -121,7 +121,7 @@ Pauses the execution of the bot every day for some time

Simulates the user going to sleep every day for some time, the sleep time and the duration is changed every day by a random offset defined in the config file.

###Example Config
### Example Config
```
"sleep_schedule": {
"enabled": true,
Expand Down Expand Up @@ -436,7 +436,7 @@ 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'```

####Examples:
#### Examples:

- Keep the top 25 Zubat with the best hp_max:

Expand Down Expand Up @@ -1147,7 +1147,7 @@ Simulates the random pause of the day (speaking to someone, getting into a store
- `min_interval`: (HH:MM:SS) the minimum interval between each pause
- `max_interval`: (HH:MM:SS) the maximum interval between each pause

###Example Config
### Example Config
```
{
"type": "RandomPause",
Expand All @@ -1160,7 +1160,7 @@ Simulates the random pause of the day (speaking to someone, getting into a store
}
```

##Egg Incubator
## Egg Incubator
[[back to top](#table-of-contents)]

Configure how the bot should use the incubators.
Expand All @@ -1170,7 +1170,7 @@ Configure how the bot should use the incubators.
- `infinite`: ([2], [2,5], [2,5,10], []) the type of egg the infinite (ie. unbreakable) incubator(s) can incubate. If set to [2,5], the incubator(s) can only incubate the 2km and 5km eggs. If set to [], the incubator(s) will not incubate any type of egg.
- `breakable`: ([2], [2,5], [2,5,10], []) the type of egg the breakable incubator(s) can incubate. If set to [2,5], the incubator(s) can only incubate the 2km and 5km eggs. If set to [], the incubator(s) will not incubate any type of egg.

###Example Config
### Example Config
```
{
"type": "IncubateEggs",
Expand Down
2 changes: 2 additions & 0 deletions docs/pokemon_optimizer.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
- [Default configuration](#default-configuration)
- [Understand parameters](#understand-parameters)
- [enabled](#enabled)
- [bulktransfer_enabled](#bulktransfer_enabled)
- [max_bulktransfer](#max_bulktransfer)
- [min_slots_left](#min_slots_left)
- [action_wait_min](#action_wait_min)
- [action_wait_max](#action_wait_max)
Expand Down
46 changes: 24 additions & 22 deletions pokemongo_bot/cell_workers/pokemon_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,13 +699,15 @@ def transfer_pokemon(self, transfer):
4: 'ERROR_POKEMON_IS_EGG',
5: 'ERROR_POKEMON_IS_BUDDY'
}
pokemons = list(transfer)
if self.config_bulktransfer_enabled and len(pokemons) > 1:
while len(pokemons) > 0:
action_delay(self.config_action_wait_min, self.config_action_wait_max)
pokemon_ids = []
count = 0
transfered = []
while len(pokemons) > 0 and count < self.config_max_bulktransfer:
pokemon = pokemons.pop()
transfered.append(pokemon)
pokemon_ids.append(pokemon.unique_id)
count = count + 1
try:
Expand All @@ -717,32 +719,32 @@ def transfer_pokemon(self, transfer):
return False
except Exception:
return False
for pokemon in transfer:
candy = inventory.candies().get(pokemon.pokemon_id)

if self.config_transfer and (not self.bot.config.test):
candy.add(1)

self.emit_event("pokemon_release",
formatted="Exchanged {pokemon} [IV {iv}] [CP {cp}] [{candy} candies]",
data={"pokemon": pokemon.name,
"iv": pokemon.iv,
"cp": pokemon.cp,
"candy": candy.quantity})

for pokemon in transfered:
candy = inventory.candies().get(pokemon.pokemon_id)

if self.config_transfer and (not self.bot.config.test):
candy.add(1)

self.emit_event("pokemon_release",
formatted="Exchanged {pokemon} [IV {iv}] [CP {cp}] [{candy} candies]",
data={"pokemon": pokemon.name,
"iv": pokemon.iv,
"cp": pokemon.cp,
"candy": candy.quantity})

if self.config_transfer:
inventory.pokemons().remove(pokemon.unique_id)
if self.config_transfer:
inventory.pokemons().remove(pokemon.unique_id)

with self.bot.database as db:
cursor = db.cursor()
cursor.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='transfer_log'")
with self.bot.database as db:
cursor = db.cursor()
cursor.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='transfer_log'")

db_result = cursor.fetchone()
db_result = cursor.fetchone()

if db_result[0] == 1:
db.execute("INSERT INTO transfer_log (pokemon, iv, cp) VALUES (?, ?, ?)", (pokemon.name, pokemon.iv, pokemon.cp))
if db_result[0] == 1:
db.execute("INSERT INTO transfer_log (pokemon, iv, cp) VALUES (?, ?, ?)", (pokemon.name, pokemon.iv, pokemon.cp))

action_delay(self.config_action_wait_min, self.config_action_wait_max)
else:
for pokemon in pokemons:
if self.config_transfer and (not self.bot.config.test):
Expand Down

0 comments on commit 9e38b73

Please sign in to comment.