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

Added absolute candy limit #5766

Merged
merged 4 commits into from
Oct 7, 2016
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -46,6 +46,7 @@
"best_in_family": true,
"// candy_limit = 0 means no limit, so it will never change current buddy": {},
"candy_limit": 0,
"candy_limit_absolute":0,
"// force_first_change = true will always change buddy at start removing current one": {},
"force_first_change": false,
"buddy_change_wait_min": 3,
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"best_in_family": true,
"// candy_limit = 0 means no limit, so it will never change current buddy": {},
"candy_limit": 0,
"candy_limit_absolute":0,
"// force_first_change = true will always change buddy at start removing current one": {},
"force_first_change": false,
"buddy_change_wait_min": 3,
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 @@ -46,6 +46,7 @@
"best_in_family": true,
"// candy_limit = 0 means no limit, so it will never change current buddy": {},
"candy_limit": 0,
"candy_limit_absolute":0,
"// force_first_change = true will always change buddy at start removing current one": {},
"force_first_change": false,
"buddy_change_wait_min": 3,
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 @@ -46,6 +46,7 @@
"best_in_family": true,
"// candy_limit = 0 means no limit, so it will never change current buddy": {},
"candy_limit": 0,
"candy_limit_absolute":0,
"// force_first_change = true will always change buddy at start removing current one": {},
"force_first_change": false,
"buddy_change_wait_min": 3,
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 @@ -46,6 +46,7 @@
"best_in_family": true,
"// candy_limit = 0 means no limit, so it will never change current buddy": {},
"candy_limit": 0,
"candy_limit_absolute":0,
"// force_first_change = true will always change buddy at start removing current one": {},
"force_first_change": false,
"buddy_change_wait_min": 3,
Expand Down
2 changes: 2 additions & 0 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,7 @@ After setting a buddy it's not possible to remove it, only change it. So if a bu
* `buddy_list`: `Default: []`. List of pokemon names that will be used as buddy. If '[]' or 'none', will not use or change buddy.
* `best_in_family`: `Default: True`. If True, picks best Pokemon in the family (sorted by cp).
* `candy_limit`: `Default: 0`. Set the candy limit to be rewarded per buddy, when reaching this limit the bot will change the buddy to the next in the list. When candy_limit = 0 or only one buddy in list, it has no limit and never changes buddy.
* `candy_limit_absolute`: `Default: 0`. Set the absolute candy limit to be rewarded per buddy, when reaching this limit the bot will change the buddy to the next in the list. When candy_limit_absolute = 0 or only one buddy in list, it has no limit and never changes buddy. Use this to stop collecting candy when a candy threshold for your buddy's pokemon family is reached (e.g. 50 for evolving).
* `force_first_change`: `Default: False`. If True, will try to change buddy at bot start according to the buddy list. If False, will use the buddy already set until candy_limit is reached and then use the buddy list.
* `buddy_change_wait_min`: `Default: 3`. Minimum time (in seconds) that the buddy change takes.
* `buddy_change_wait_max`: `Default: 5`. Maximum time (in seconds) that the buddy change takes.
Expand All @@ -1314,6 +1315,7 @@ After setting a buddy it's not possible to remove it, only change it. So if a bu
"best_in_family": true,
"// candy_limit = 0 means no limit, so it will never change current buddy": {},
"candy_limit": 0,
"candy_limit_absolute": 0,
"// force_first_change = true will always change buddy at start removing current one": {},
"force_first_change": false,
"buddy_change_wait_min": 3,
Expand Down
27 changes: 24 additions & 3 deletions pokemongo_bot/cell_workers/buddy_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class BuddyPokemon(BaseTask):
"best_in_family": true,
"// candy_limit = 0 means no limit, so it will never change current buddy": {},
"candy_limit": 0,
"candy_limit_absolute": 0,
"// force_first_change = true will always change buddy at start removing current one": {},
"force_first_change": false,
"buddy_change_wait_min": 3,
Expand All @@ -42,6 +43,16 @@ class BuddyPokemon(BaseTask):
to the next in the list. When candy_limit = 0 or
only one buddy in list, it has no limit and never
changes buddy.
candy_limit_absolute: Default: 0. Set the absolute candy limit to be
rewarded per buddy, when reaching this
limit the bot will change the buddy to the
next in the list. When
candy_limit_absolute = 0 or only one buddy
in list, it has no limit and never changes
buddy. Use this to stop collecting candy
when a candy threshold for your buddy's
pokemon family is reached (e.g. 50 for
evolving).
force_first_change: Default: False. If True, will try to change buddy at
bot start according to the buddy list. If False, will
use the buddy already set until candy_limit is reached
Expand All @@ -61,6 +72,7 @@ def initialize(self):
self.buddy_list = self.config.get('buddy_list', [])
self.best_in_family = self.config.get('best_in_family', True)
self.candy_limit = self.config.get('candy_limit', 0) # 0 = No Limit
self.candy_limit_absolute = self.config.get('candy_limit_absolute', 0) # 0 = No Limit
self.force_first_change = self.config.get('force_first_change', False)
self.buddy_change_wait_min = self.config.get('buddy_change_wait_min', 3)
self.buddy_change_wait_max = self.config.get('buddy_change_wait_max', 5)
Expand Down Expand Up @@ -93,10 +105,16 @@ def work(self):
return WorkerResult.SUCCESS

if self.buddy_list:
if self.force_first_change or not self.buddy or self.candy_limit != 0 and self.candy_awarded >= self.candy_limit:
pokemon = self._get_pokemon_by_name(self._get_pokemon_by_id(self.buddy['id']).name)
if self.force_first_change or not self.buddy or pokemon is None or (self.candy_limit != 0 and self.candy_awarded >= self.candy_limit) or self._check_candy_limit_absolute(pokemon):
self.force_first_change = False

remaining = [name for name in self.buddy_list if name not in self.cache]
remaining = []
for name in self.buddy_list:
pokemon = self._get_pokemon_by_name(name)
if name not in self.cache and pokemon is not None and not self._check_candy_limit_absolute(pokemon):
remaining.append(name)

if not remaining:
self.cache = []
return WorkerResult.SUCCESS
Expand Down Expand Up @@ -199,6 +217,9 @@ def _get_award(self):
)
return False

def _check_candy_limit_absolute(self, pokemon):
return self.candy_limit_absolute != 0 and inventory.candies().get(pokemon.family_id).quantity >= self.candy_limit_absolute

def _check_old_reward(self):
if not self.buddy:
return
Expand All @@ -215,7 +236,7 @@ def _get_pokemon_by_name(self, name):
pokemons = inventory.pokemons().all()
pokemon = None
for p in pokemons:
if p.name.lower() == name:
if p.name.lower() == name.lower():
pokemon = p
break

Expand Down