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

Assign to Team #5067

Merged
merged 7 commits into from
Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 3 additions & 1 deletion configs/config.json.cluster.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"config": {
"enabled": false,
"// set a name": "",
"nickname": ""
"nickname": "",
"// 0 = No Team, 1 = Blue, 2 = Red, 3 = Yellow": "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Red is 2 ... I thought Red is 3...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax = "proto3";
package POGOProtos.Enums;

enum TeamColor {
    NEUTRAL = 0;
    BLUE = 1;
    RED = 2;
    YELLOW = 3;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's wired, the red always jumped as the 3rd one.

"team": 0
}
},
{
Expand Down
4 changes: 3 additions & 1 deletion configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
"config": {
"enabled": false,
"// set a name": "",
"nickname": ""
"nickname": "",
"// 0 = No Team, 1 = Blue, 2 = Red, 3 = Yellow": "",
"team": 0
}
},
{
Expand Down
4 changes: 3 additions & 1 deletion configs/config.json.map.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"config": {
"enabled": false,
"// set a name": "",
"nickname": ""
"nickname": "",
"// 0 = No Team, 1 = Blue, 2 = Red, 3 = Yellow": "",
"team": 0
}
},
{
Expand Down
4 changes: 3 additions & 1 deletion configs/config.json.path.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"config": {
"enabled": false,
"// set a name": "",
"nickname": ""
"nickname": "",
"// 0 = No Team, 1 = Blue, 2 = Red, 3 = Yellow": "",
"team": 0
}
},
{
Expand Down
4 changes: 3 additions & 1 deletion configs/config.json.pokemon.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"config": {
"enabled": false,
"// set a name": "",
"nickname": ""
"nickname": "",
"// 0 = No Team, 1 = Blue, 2 = Red, 3 = Yellow": "",
"team": 0
}
},
{
Expand Down
57 changes: 45 additions & 12 deletions pokemongo_bot/cell_workers/complete_tutorial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import random

from pokemongo_bot import logger
from pokemongo_bot.inventory import player
from pokemongo_bot.base_task import BaseTask
from pokemongo_bot.worker_result import WorkerResult
from pokemongo_bot.human_behaviour import sleep
Expand All @@ -15,23 +16,22 @@ def initialize(self):
self.api = self.bot.api
self.nickname = self.config.get('nickname','')
self.team = self.config.get('team',0)
self.may_run = True

def should_run(self):
return self.may_run
self.tutorial_run = True
self.team_run = True

def work(self):

if not self.should_run():
return WorkerResult.SUCCESS
if self.tutorial_run:
self.tutorial_run = False
if not self._check_tutorial_state():
return WorkerResult.ERROR

# Only execute the worker once to avoid error loop
self.may_run = False
if self.team_run and player()._level >= 5:
self.team_run = False
if not self._set_team():
return WorkerResult.ERROR

if self._check_tutorial_state():
return WorkerResult.SUCCESS
else:
return WorkerResult.ERROR
return WorkerResult.SUCCESS

def _check_tutorial_state(self):
self._player=self.bot.player_data
Expand Down Expand Up @@ -179,3 +179,36 @@ def _set_tutorial_state(self, completed):
except KeyError:
self.logger.error("KeyError while setting tutorial state")
return False

def _set_team(self):
if self.team == 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Purpose? And where did you set it before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At initialize:
self.team = self.config.get('team',0)
If it is 0 then no team must be picked.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, didnt see that 😆

return True

if self.bot.player_data.get('team', 0) != 0:
self.logger.info(u'Team already picked')
return True

sleep(10)
response_dict = self.api.set_player_team(team=self.team)
try:
result = response_dict['responses']['SET_PLAYER_TEAM']['status']
if result == 1:
team_codes = {
1: 'Mystic (BLUE)',
2: 'Valor (RED)',
3: 'Instinct (YELLOW)'
}
self.logger.info(u'Picked Team {}.'.format(team_codes[self.team]))
return True
else:
error_codes = {
0: 'UNSET',
1: 'SUCCESS',
2: 'TEAM_ALREADY_SET',
3: 'FAILURE'
}
self.logger.error(u'Error while picking team : {}'.format(error_codes[result]))
return False
except KeyError:
return False