-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
SoftBan Worker #1724
SoftBan Worker #1724
Changes from all commits
914c908
5def781
77b9243
9ee30eb
3f8281b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from pgoapi.utilities import f2i | ||
|
||
from pokemongo_bot import logger | ||
from pokemongo_bot.constants import Constants | ||
from pokemongo_bot.cell_workers import MoveToFortWorker, SeenFortWorker | ||
from pokemongo_bot.cell_workers.utils import distance | ||
from pokemongo_bot.worker_result import WorkerResult | ||
|
||
|
||
class SoftBanWorker(object): | ||
|
||
def __init__(self, bot): | ||
self.bot = bot | ||
self.api = bot.api | ||
self.config = bot.config | ||
|
||
def work(self): | ||
if not self.should_run(): | ||
return | ||
|
||
forts = self.bot.get_forts(order_by_distance=True) | ||
|
||
if len(forts) == 0: | ||
logger.log('Found no forts to reset softban, skipping...', 'red') | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to make sure, the intent here is to continue to the next worker if it can't find a fort? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, because we need to walk randomly until we can find a fort to walk to. |
||
logger.log('Got softban, fixing...', 'yellow') | ||
|
||
fort_distance = distance( | ||
self.bot.position[0], | ||
self.bot.position[1], | ||
forts[0]['latitude'], | ||
forts[0]['longitude'], | ||
) | ||
|
||
if fort_distance > Constants.MAX_DISTANCE_FORT_IS_REACHABLE: | ||
MoveToFortWorker(self.bot).work() | ||
self.bot.recent_forts = self.bot.recent_forts[0:-1] | ||
if forts[0]['id'] in self.bot.fort_timeouts: | ||
del self.bot.fort_timeouts[forts[0]['id']] | ||
return WorkerResult.RUNNING | ||
else: | ||
logger.log('Starting 50 spins...') | ||
for i in xrange(50): | ||
if (i + 1) % 10 == 0: | ||
logger.log('Spin #{}'.format(str(i+1))) | ||
self.spin_fort(forts[0]) | ||
self.softban = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This too. #1724 (comment) |
||
logger.log('Softban should be fixed.') | ||
|
||
def spin_fort(self, fort): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could get pulled out. Seems like there are a couple of places that would be able to use this function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely we should start service classes to wrap some API functions. I created #1726 for us to keep track of this. |
||
self.api.fort_search( | ||
fort_id=fort['id'], | ||
fort_latitude=fort['latitude'], | ||
fort_longitude=fort['longitude'], | ||
player_latitude=f2i(self.bot.position[0]), | ||
player_longitude=f2i(self.bot.position[1]) | ||
) | ||
self.api.call() | ||
|
||
def should_run(self): | ||
return self.bot.config.softban_fix and self.bot.softban |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@douglascamata , I am not sure this works. It's better be
self.bot.softban = True