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

Deploying of lures if available #6049

Merged
merged 5 commits into from
May 26, 2017
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
3 changes: 2 additions & 1 deletion configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,8 @@
"enabled": true,
"spin_wait_min": 3,
"spin_wait_max": 5,
"daily_spin_limit": 1900
"daily_spin_limit": 1900,
"use_lure": false
}
},
{
Expand Down
1 change: 1 addition & 0 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ The behaviors of the bot are configured via the `tasks` key in the `config.json`
* `enabled`: Default true | Enable for disable this task
* `spin_wait_min`: Defaut 3 | Minimum wait after spinning a fort
* `spin_wait_max`: Default 5 | Maximum wait after spinning a fort
* `use_lure`: Default `False` | Enable to depoly lure (if available) at fort
* TransferPokemon
* `enable`: Disable or enable this task.
* `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.
Expand Down
4 changes: 4 additions & 0 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@ def _register_events(self):
)
self.event_manager.register_event('no_pokeballs')
self.event_manager.register_event('enough_ultraballs')
self.event_manager.register_event('lure_success')
self.event_manager.register_event('lure_failed')
self.event_manager.register_event('lure_not_enough')
self.event_manager.register_event('lure_info')
self.event_manager.register_event(
'pokemon_catch_rate',
parameters=(
Expand Down
40 changes: 39 additions & 1 deletion pokemongo_bot/cell_workers/spin_fort.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
SPIN_REQUEST_RESULT_IN_COOLDOWN_PERIOD = 3
SPIN_REQUEST_RESULT_INVENTORY_FULL = 4

LURE_REQUEST_RESULT_SUCCESS = 1
LURE_REQUEST_FORT_ALREADY_HAS_MODIFIER= 2
LURE_REQUEST_TOO_FAR_AWAY = 3
LURE_REQUEST_NO_ITEM_IN_INVENTORY = 4
LURE_REQUEST_POI_INACCESSIBLE = 5

class SpinFort(BaseTask):
SUPPORTED_TASK_API_VERSION = 1
Expand All @@ -36,6 +41,7 @@ def initialize(self):
self.spin_wait_max = self.config.get("spin_wait_max", 3)
self.min_interval = int(self.config.get('min_interval', 120))
self.exit_on_limit_reached = self.config.get("exit_on_limit_reached", True)
self.use_lure = self.config.get("use_lure", False)

def should_run(self):
has_space_for_loot = inventory.Items.has_space_for_loot()
Expand Down Expand Up @@ -72,7 +78,39 @@ def work(self):
lng = fort['longitude']

details = fort_details(self.bot, fort['id'], lat, lng)
fort_name = details.get('name', 'Unknown')
fort_name = details.get('name', 'Unknown')
check_fort_modifier = details.get('modifiers', {})
if check_fort_modifier:
# check_fort_modifier_id = check_fort_modifier[0].get('item_id')
self.emit_event('lure_info', formatted='A lure is already in fort, skip deploying lure')

if self.use_lure and not check_fort_modifier:
# check lures availiblity
lure_count = inventory.items().get(501).count

if lure_count > 1: # Only use lures when there's more than one
response_dict = self.bot.api.add_fort_modifier(
modifier_type=501,
fort_id = fort['id'],
player_latitude = f2i(self.bot.position[0]),
player_longitude = f2i(self.bot.position[1])
)

if ('responses' in response_dict) and ('ADD_FORT_MODIFIER' in response_dict['responses']):
add_modifier_deatils = response_dict['responses']['ADD_FORT_MODIFIER']
add_modifier_result = add_modifier_deatils.get('result', -1)
if (add_modifier_result == LURE_REQUEST_RESULT_SUCCESS):
self.emit_event('lure_success', formatted='You have successfully placed a lure')
if (add_modifier_result == LURE_REQUEST_FORT_ALREADY_HAS_MODIFIER):
self.emit_event('lure_failed', formatted='A lure has being placed before you try to do so')
if (add_modifier_result == LURE_REQUEST_TOO_FAR_AWAY):
self.emit_event('lure_failed', formatted='Pokestop out of range')
if (add_modifier_result == LURE_REQUEST_NO_ITEM_IN_INVENTORY):
self.emit_event('lure_not_enough', formatted='Not enough lure in inventory')
if (add_modifier_result == LURE_REQUEST_POI_INACCESSIBLE):
self.emit_event('lure_info', formatted='Unkown Error')
else:
self.emit_event('lure_not_enough', formatted='Not enough lure in inventory')

response_dict = self.bot.api.fort_search(
fort_id=fort['id'],
Expand Down