Skip to content

Commit

Permalink
Check for tutorial completion
Browse files Browse the repository at this point in the history
* Use empty default username for nickname
On gmail accounts, it would be suspect to have @gmail.com in nickname
Nickname is not set if user does not set one in config

* Fix typo

* Fix result key name

* Moved to own task

* Add example in config

* Rebased to latest dev on top of :
Fixing live stats crash on first run (PokemonGoF#4088)
in order for the bot to reach the task without crashing
  • Loading branch information
net8q committed Aug 17, 2016
1 parent a940e54 commit 1914d1d
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 6 deletions.
9 changes: 8 additions & 1 deletion configs/config.json.cluster.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@
}
},
{
"type": "CollectLevelUpReward"
"type": "CompleteTutorial",
"config": {
"enabled": false,
"// set a name": "",
"nickname": "",
}
},
"type": "CollectLevelUpReward"
},
{
"type": "IncubateEggs",
Expand Down
9 changes: 8 additions & 1 deletion configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@
}
},
{
"type": "CollectLevelUpReward"
"type": "CompleteTutorial",
"config": {
"enabled": false,
"// set a name": "",
"nickname": "",
}
},
"type": "CollectLevelUpReward"
},
{
"type": "IncubateEggs",
Expand Down
9 changes: 8 additions & 1 deletion configs/config.json.map.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@
}
},
{
"type": "CollectLevelUpReward"
"type": "CompleteTutorial",
"config": {
"enabled": false,
"// set a name": "",
"nickname": "",
}
},
"type": "CollectLevelUpReward"
},
{
"type": "IncubateEggs",
Expand Down
9 changes: 8 additions & 1 deletion configs/config.json.optimizer.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@
}
},
{
"type": "CollectLevelUpReward"
"type": "CompleteTutorial",
"config": {
"enabled": false,
"// set a name": "",
"nickname": "",
}
},
"type": "CollectLevelUpReward"
},
{
"type": "IncubateEggs",
Expand Down
9 changes: 8 additions & 1 deletion configs/config.json.path.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@
}
},
{
"type": "CollectLevelUpReward"
"type": "CompleteTutorial",
"config": {
"enabled": false,
"// set a name": "",
"nickname": "",
}
},
"type": "CollectLevelUpReward"
},
{
"type": "IncubateEggs",
Expand Down
9 changes: 8 additions & 1 deletion configs/config.json.pokemon.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@
}
},
{
"type": "CollectLevelUpReward"
"type": "CompleteTutorial",
"config": {
"enabled": false,
"// set a name": "",
"nickname": "",
}
},
"type": "CollectLevelUpReward"
},
{
"type": "IncubateEggs",
Expand Down
1 change: 1 addition & 0 deletions pokemongo_bot/cell_workers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
from sleep_schedule import SleepSchedule
from update_live_stats import UpdateLiveStats
from catch_pokemon import CatchPokemon
from complete_tutorial import CompleteTutorial
136 changes: 136 additions & 0 deletions pokemongo_bot/cell_workers/complete_tutorial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import random

from pokemongo_bot import logger
from pokemongo_bot.base_task import BaseTask
from pokemongo_bot.worker_result import WorkerResult
from pokemongo_bot.human_behaviour import sleep



class CompleteTutorial(BaseTask):

SUPPORTED_TASK_API_VERSION = 1

def initialize(self):
self.api = self.bot.api
self.nickname = self.config.get('nickname','')
self.team = self.config.get('team',0)

def should_run(self):
return True

def work(self):

if not self.should_run():
return WorkerResult.SUCCESS

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

def _check_tutorial_state(self):
self._player=self.bot.player_data

tutorial_state = self._player.get('tutorial_state', [])
# LEGAL_SCREEN = 0
if not 0 in tutorial_state:
sleep(2)
if self._set_tutorial_state(0):
self.logger.info('Completed legal screen')
tutorial_state = self._player.get('tutorial_state', [])
else:
return False

# AVATAR_SELECTION = 1
if not 1 in tutorial_state:
# TODO : choose avatar ?
sleep(3)
if self._set_tutorial_state(1):
self.logger.info('Completed avatar selection')
tutorial_state = self._player.get('tutorial_state', [])
else:
return False

# POKEMON_CAPTURE = 3
if not 3 in tutorial_state:
sleep(10)
if self._encounter_tutorial():
self.logger.info('Completed first capture')
else:
self.logger.error('Error during first capture')
return False

# NAME_SELECTION = 4
if not 4 in tutorial_state:
if not self.nickname:
self.logger.info("No nickname defined in config")
return False

self.logger.info(u'Trying to set {} as nickname'.format(self.nickname))
sleep(5)
if self._set_nickname(self.nickname):
self._set_tutorial_state(4)
tutorial_state = self._player.get('tutorial_state', [])
else:
self.logger.error('Error trying to set nickname')
return False

# FIRST_TIME_EXPERIENCE_COMPLETE = 7
if not 7 in tutorial_state:
if self._set_tutorial_state(7):
self.logger.info('Completed first time experience')
else:
return False

return True

def _encounter_tutorial(self):
# You just need to call the API with the pokemon you choose
# Probably can't get MewTwo as first pokemon though
first_pokemon_id = random.choice([1, 4, 7])
response_dict = self.api.encounter_tutorial_complete(
pokemon_id=first_pokemon_id)
try:
if response_dict['responses']['ENCOUNTER_TUTORIAL_COMPLETE']['result'] == 1:
return True
else:
self.logger.error("Error during encouter tutorial")
return False
except KeyError:
self.logger.error("KeyError during encouter tutorial")
return False

def _set_nickname(self, nickname):
response_dict = self.api.claim_codename(codename=nickname)
try:
result = response_dict['responses']['CLAIM_CODENAME']['status']
if result == 1:
self.logger.info(u'Name changed to {}'.format(nickname))
return True
else:
# Would be nice to get the text directly from the proto Enum
error_codes = {
0: 'UNSET',
1: 'SUCCESS',
2: 'CODENAME_NOT_AVAILABLE',
3: 'CODENAME_NOT_VALID',
4: 'CURRENT_OWNER',
5: 'CODENAME_CHANGE_NOT_ALLOWED'
}
self.logger.error(
u'Error while changing nickname : {}'.format(error_codes[result]))
return False
except KeyError:
return False

def _set_tutorial_state(self, completed):
response_dict = self.api.mark_tutorial_complete(tutorials_completed=[
completed], send_marketing_emails=False, send_push_notifications=False)
try:
self._player = response_dict['responses'][
'MARK_TUTORIAL_COMPLETE']['player_data']
return response_dict['responses']['MARK_TUTORIAL_COMPLETE']['success']
except KeyError:
self.logger.error("KeyError while setting tutorial state")
return False

0 comments on commit 1914d1d

Please sign in to comment.