Skip to content

Commit

Permalink
Consecutive Vanish Limit & Rest (#5115)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexyaoyang authored Sep 2, 2016
1 parent 1cc9da7 commit ebfead0
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 1 deletion.
5 changes: 5 additions & 0 deletions configs/config.json.cluster.example
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@
"berry_threshold": 0.35,
"vip_berry_threshold": 0.9,
"daily_catch_limit": 800,
"vanish_settings": {
"consecutive_vanish_limit": 10,
"rest_duration_min": "02:00:00",
"rest_duration_max": "04:00:00"
},
"catch_throw_parameters": {
"excellent_rate": 0.1,
"great_rate": 0.5,
Expand Down
5 changes: 5 additions & 0 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@
"vip_berry_threshold": 0.9,
"treat_unseen_as_vip": true,
"daily_catch_limit": 800,
"vanish_settings": {
"consecutive_vanish_limit": 10,
"rest_duration_min": "02:00:00",
"rest_duration_max": "04:00:00"
},
"catch_throw_parameters": {
"excellent_rate": 0.1,
"great_rate": 0.5,
Expand Down
5 changes: 5 additions & 0 deletions configs/config.json.map.example
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@
"berry_threshold": 0.35,
"vip_berry_threshold": 0.9,
"daily_catch_limit": 800,
"vanish_settings": {
"consecutive_vanish_limit": 10,
"rest_duration_min": "02:00:00",
"rest_duration_max": "04:00:00"
},
"catch_throw_parameters": {
"excellent_rate": 0.1,
"great_rate": 0.5,
Expand Down
5 changes: 5 additions & 0 deletions configs/config.json.path.example
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@
"vip_berry_threshold": 0.9,
"treat_unseen_as_vip": true,
"daily_catch_limit": 800,
"vanish_settings": {
"consecutive_vanish_limit": 10,
"rest_duration_min": "02:00:00",
"rest_duration_max": "04:00:00"
},
"catch_throw_parameters": {
"excellent_rate": 0.1,
"great_rate": 0.5,
Expand Down
5 changes: 5 additions & 0 deletions configs/config.json.pokemon.example
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@
"vip_berry_threshold": 0.9,
"treat_unseen_as_vip": true,
"daily_catch_limit": 800,
"vanish_settings": {
"consecutive_vanish_limit": 10,
"rest_duration_min": "02:00:00",
"rest_duration_max": "04:00:00"
},
"catch_throw_parameters": {
"excellent_rate": 0.1,
"great_rate": 0.5,
Expand Down
8 changes: 8 additions & 0 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,13 @@ def _register_events(self):
'pokemon_id'
)
)
self.event_manager.register_event(
'vanish_limit_reached',
parameters=(
'duration',
'resume'
)
)
self.event_manager.register_event('pokemon_not_in_range')
self.event_manager.register_event('pokemon_inventory_full')
self.event_manager.register_event(
Expand Down Expand Up @@ -619,6 +626,7 @@ def _register_events(self):
)
# database shit
self.event_manager.register_event('catch_log')
self.event_manager.register_event('vanish_log')
self.event_manager.register_event('evolve_log')
self.event_manager.register_event('login_log')
self.event_manager.register_event('transfer_log')
Expand Down
5 changes: 5 additions & 0 deletions pokemongo_bot/cell_workers/migrations/vanish_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from yoyo import step

step(
"CREATE TABLE IF NOT EXISTS vanish_log (pokemon text, cp real, iv real, encounter_id text, pokemon_id real, dated datetime DEFAULT CURRENT_TIMESTAMP)"
)
58 changes: 57 additions & 1 deletion pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import time
import sys

from random import random, randrange
from random import random, randrange, uniform
from pokemongo_bot import inventory
from pokemongo_bot.base_task import BaseTask
from pokemongo_bot.human_behaviour import sleep, action_delay
Expand All @@ -16,6 +16,7 @@
from pokemongo_bot.datastore import Datastore
from pokemongo_bot.base_dir import _base_dir
from datetime import datetime, timedelta
from utils import getSeconds

CATCH_STATUS_SUCCESS = 1
CATCH_STATUS_FAILED = 2
Expand Down Expand Up @@ -56,6 +57,7 @@ def initialize(self):
self.spawn_point_guid = ''
self.response_key = ''
self.response_status_key = ''
self.rest_completed = False

#Config
self.min_ultraball_to_keep = self.config.get('min_ultraball_to_keep', 10)
Expand All @@ -64,6 +66,11 @@ def initialize(self):
self.treat_unseen_as_vip = self.config.get('treat_unseen_as_vip', DEFAULT_UNSEEN_AS_VIP)
self.daily_catch_limit = self.config.get('daily_catch_limit', 800)

self.vanish_settings = self.config.get('vanish_settings', {})
self.consecutive_vanish_limit = self.vanish_settings.get('consecutive_vanish_limit', 10)
self.rest_duration_min = getSeconds(self.vanish_settings.get('rest_duration_min', "02:00:00"))
self.rest_duration_max = getSeconds(self.vanish_settings.get('rest_duration_max', "04:00:00"))

self.catch_throw_parameters = self.config.get('catch_throw_parameters', {})
self.catch_throw_parameters_spin_success_rate = self.catch_throw_parameters.get('spin_success_rate', 0.6)
self.catch_throw_parameters_excellent_rate = self.catch_throw_parameters.get('excellent_rate', 0.1)
Expand Down Expand Up @@ -505,6 +512,25 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):

# abandon if pokemon vanished
elif catch_pokemon_status == CATCH_STATUS_VANISHED:
#insert into DB
with self.bot.database as conn:
c = conn.cursor()
c.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='vanish_log'")
result = c.fetchone()

while True:
if result[0] == 1:
conn.execute('''INSERT INTO vanish_log (pokemon, cp, iv, encounter_id, pokemon_id) VALUES (?, ?, ?, ?, ?)''', (pokemon.name, pokemon.cp, pokemon.iv, str(encounter_id), pokemon.pokemon_id))
break
else:
self.emit_event(
'vanish_log',
sender=self,
level='info',
formatted="vanish_log table not found, skipping log"
)
break

self.emit_event(
'pokemon_vanished',
formatted='{pokemon} vanished!',
Expand All @@ -516,11 +542,24 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):
'pokemon_id': pokemon.pokemon_id
}
)

with self.bot.database as conn:
c = conn.cursor()
c.execute("SELECT DISTINCT COUNT(encounter_id) FROM vanish_log WHERE dated > (SELECT dated FROM catch_log WHERE dated IN (SELECT MAX(dated) FROM catch_log))")

result = c.fetchone()
self.consecutive_vanishes_so_far = result[0]

if self.rest_completed == False and self.consecutive_vanishes_so_far >= self.consecutive_vanish_limit:
self.start_rest()

if self._pct(catch_rate_by_ball[current_ball]) == 100:
self.bot.softban = True

# pokemon caught!
elif catch_pokemon_status == CATCH_STATUS_SUCCESS:
if self.rest_completed == True:
self.rest_completed = False
pokemon.unique_id = response_dict['responses']['CATCH_POKEMON']['captured_pokemon_id']
self.bot.metrics.captured_pokemon(pokemon.name, pokemon.cp, pokemon.iv_display, pokemon.iv)

Expand Down Expand Up @@ -663,3 +702,20 @@ def generate_throw_quality_parameters(self, throw_parameters):
throw_parameters['normalized_reticle_size'] = 1.25 + 0.70 * random()
throw_parameters['normalized_hit_position'] = 0.0
throw_parameters['throw_type_label'] = 'OK'

def start_rest(self):
duration = int(uniform(self.rest_duration_min, self.rest_duration_max))
resume = datetime.now() + timedelta(seconds=duration)

self.emit_event(
'vanish_limit_reached',
formatted="Vanish limit reached! Taking a rest now for {duration}, will resume at {resume}.",
data={
'duration': str(timedelta(seconds=duration)),
'resume': resume.strftime("%H:%M:%S")
}
)

sleep(duration)
self.rest_completed = True
self.bot.login()
1 change: 1 addition & 0 deletions pokemongo_bot/event_handlers/colored_logging_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class ColoredLoggingHandler(EventHandler):
'unset_pokemon_nickname': 'red',
'vip_pokemon': 'red',
'use_incense': 'blue',
'vanish_limit_reached': 'red',

'arrived_at_cluster': 'none',
'arrived_at_fort': 'none',
Expand Down

0 comments on commit ebfead0

Please sign in to comment.