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

Restore vip functionality #5502

Merged
merged 8 commits into from
Sep 17, 2016
Merged
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
79 changes: 59 additions & 20 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import
import os
import time
import json
import logging
import sys

from random import random, randrange, uniform
Expand All @@ -14,7 +14,7 @@
from pokemongo_bot.worker_result import WorkerResult
from pokemongo_bot.base_dir import _base_dir
from datetime import datetime, timedelta
from utils import getSeconds
from .utils import getSeconds

from pprint import pprint

Expand Down Expand Up @@ -44,12 +44,14 @@
'andor': lambda x, y, z: x and y or z
}

DEBUG_ON = False

class PokemonCatchWorker(BaseTask):

def __init__(self, pokemon, bot, config):
self.pokemon = pokemon
super(PokemonCatchWorker, self).__init__(bot, config)
if self.config.get('debug', False): DEBUG_ON = True

def initialize(self):
self.position = self.bot.position
Expand Down Expand Up @@ -124,8 +126,11 @@ def work(self, response_dict=None):
pokemon_data = response['wild_pokemon']['pokemon_data'] if 'wild_pokemon' in response else response['pokemon_data']
pokemon = Pokemon(pokemon_data)

# check if vip pokemon
is_vip = self._is_vip_pokemon(pokemon)

# skip ignored pokemon
if not self._should_catch_pokemon(pokemon):
if not self._should_catch_pokemon(pokemon) and not is_vip:
if not hasattr(self.bot,'skipped_pokemon'):
self.bot.skipped_pokemon = []

Expand All @@ -149,7 +154,6 @@ def work(self, response_dict=None):
)
return WorkerResult.SUCCESS

is_vip = self._is_vip_pokemon(pokemon)
if inventory.items().get(ITEM_POKEBALL).count < 1:
if inventory.items().get(ITEM_GREATBALL).count < 1:
if inventory.items().get(ITEM_ULTRABALL).count < 1:
Expand Down Expand Up @@ -261,6 +265,8 @@ def _pokemon_matches_config(self, config, pokemon, default_logic='and'):
'ca': True
}

catch_logic = pokemon_config.get('logic', default_logic)

candies = inventory.candies().get(pokemon.pokemon_id).quantity
threshold = pokemon_config.get('candy_threshold', -1)
if (threshold > 0 and candies >= threshold):
Expand All @@ -282,20 +288,21 @@ def _pokemon_matches_config(self, config, pokemon, default_logic='and'):
if pokemon_config.get('always_catch', False):
return True

catch_ncp = pokemon_config.get('catch_above_ncp', pokemon.cp_percent)
if pokemon.cp_percent >= catch_ncp:
catch_results['ncp'] = True

catch_cp = pokemon_config.get('catch_above_cp', pokemon.cp)
catch_below_cp = pokemon_config.get('catch_below_cp', pokemon.cp)
if catch_cp <= pokemon.cp <= catch_below_cp:
catch_results['cp'] = True
if pokemon_config.get('catch_above_ncp',-1) >= 0:
if pokemon.cp_percent >= pokemon_config.get('catch_above_ncp'):
catch_results['ncp'] = True

if pokemon_config.get('catch_above_cp',-1) >= 0:
if pokemon.cp >= pokemon_config.get('catch_above_cp'):
catch_results['cp'] = True

if pokemon_config.get('catch_below_cp',-1) >= 0:
if pokemon.cp <= pokemon_config.get('catch_below_cp'):
catch_results['cp'] = True

catch_iv = pokemon_config.get('catch_above_iv', pokemon.iv)
if pokemon.iv >= catch_iv:
catch_results['iv'] = True

if pokemon_config.get('catch_above_iv',-1) >= 0:
if pokemon.iv > pokemon_config.get('catch_above_iv', pokemon.iv):
catch_results['iv'] = True

catch_results['fa'] = ( len(pokemon_config.get('fast_attack', [])) == 0 or unicode(pokemon.fast_attack) in map(lambda x: unicode(x), pokemon_config.get('fast_attack', [])))
catch_results['ca'] = ( len(pokemon_config.get('charged_attack', [])) == 0 or unicode(pokemon.charged_attack) in map(lambda x: unicode(x), pokemon_config.get('charged_attack', [])))
Expand All @@ -307,13 +314,45 @@ def _pokemon_matches_config(self, config, pokemon, default_logic='and'):
self.bot.logger.debug("Pokemon locked!")
return False

# build catch results
cr = {
'ncp': catch_results['ncp'],
'cp': catch_results['cp'],
'iv': catch_results['iv']
'ncp': False,
'cp': False,
'iv': False
}
if catch_logic == 'and':
cr['ncp'] = True,
cr['cp'] = True,
cr['iv'] = True
elif catch_logic == 'andor':
cr['ncp'] = True,
cr['cp'] = True
elif catch_logic == 'orand':
cr['cp'] = True,
cr['iv'] = True

if pokemon_config.get('catch_above_ncp',-1) >= 0: cr['ncp'] = catch_results['ncp']
if pokemon_config.get('catch_above_cp',-1) >= 0: cr['cp'] = catch_results['cp']
if pokemon_config.get('catch_below_cp',-1) >= 0: cr['cp'] = catch_results['cp']
if pokemon_config.get('catch_above_iv',-1) >= 0: cr['iv'] = catch_results['iv']

if LOGIC_TO_FUNCTION[pokemon_config.get('logic', default_logic)](*cr.values()):
if DEBUG_ON:
print "Debug information for match rules..."
print "catch_results ncp = {}".format(catch_results['ncp'])
print "catch_results cp = {}".format(catch_results['cp'])
print "catch_results iv = {}".format(catch_results['iv'])
print "cr = {}".format(cr)
print "catch_above_ncp = {}".format(pokemon_config.get('catch_above_ncp'))
print "catch_above_cp iv = {}".format(pokemon_config.get('catch_above_cp'))
print "catch_below_cp iv = {}".format(pokemon_config.get('catch_below_cp'))
print "catch_above_iv iv = {}".format(pokemon_config.get('catch_above_iv'))
print "Pokemon {}".format(pokemon.name)
print "pokemon ncp = {}".format(pokemon.cp_percent)
print "pokemon cp = {}".format(pokemon.cp)
print "pokemon iv = {}".format(pokemon.iv)
print "catch logic = {}".format(catch_logic)

if LOGIC_TO_FUNCTION[catch_logic](*cr.values()):
return catch_results['fa'] and catch_results['ca']
else:
return False
Expand Down