def __init__(self, scn_name, player_name, starting_scn=None, ending_scn=None): """ :param scn_name: :param player_name: :param starting_scn: :param ending_scn: """ if os.path.exists('./datas/player_data/{}/{}.play'.format( player_name, player_name)): self.player = Player().load(player_name) else: self.player = Player(player_name) Setting.CURRENT_PLAYER = self.player if self.player.current_scenario is None: self.scenario = scn.Scenario(scn_name) self.player.set_current_scenario(self.scenario) else: self.scenario = self.player.current_scenario self.starting_scn = starting_scn self.ending_scn = ending_scn self.stoped = False
def main(): """ :return: """ Player("Roger").save() Player("Thomas").save() nao_scenario_module(i_meet_you_local, i_know_you_local)
def i_know_you(face_name, current_player): """ Modifie le joueur actuel par celui qui a été reconnu par Nao. :param face_name: Le nom du joueur reconnu :param current_player: Le joueur actuel """ if face_name == current_player.player_name: return current_player.save() Setting.CURRENT_PLAYER = Player(face_name)
#!/usr/bin/env python # -*- coding: utf-8 -*- from NaoCreator.setting import Setting Setting(nao_connected=False, debug=True, bypass_wait_for=False, nao_quest_v="2.1", load_cpt_data=False, ip="169.254.88.3", USE_MIC=False) from NaoQuest.questor import Questor from PlayerManager.player_manager import Player from NaoSimulator.get_mic_input import record Player("swan").save() q = Questor('PlanterBulbe', "swan") q.launch() q.player.save()
# coding: utf-8 from NaoCreator.setting import Setting Setting(nao_connected=True, debug=True, nao_quest_v="2.1", bypass_wait_for=False, load_cpt_data=False, ip="169.254.88.3") from NaoQuest.questor import Questor from NaoQuest.scenario import Scenario from PlayerManager.player_manager import Player from NaoQuest.objectives.cpt_objective import CptObjective Player("tristan").save() q = Questor('demo', "tristan") q.launch()
class Questor: """ Gère l'exécution des Scénarios """ def __init__(self, scn_name, player_name, starting_scn=None, ending_scn=None): """ :param scn_name: :param player_name: :param starting_scn: :param ending_scn: """ if os.path.exists('./datas/player_data/{}/{}.play'.format( player_name, player_name)): self.player = Player().load(player_name) else: self.player = Player(player_name) Setting.CURRENT_PLAYER = self.player if self.player.current_scenario is None: self.scenario = scn.Scenario(scn_name) self.player.set_current_scenario(self.scenario) else: self.scenario = self.player.current_scenario self.starting_scn = starting_scn self.ending_scn = ending_scn self.stoped = False def launch(self): """ Démarre l'exécution du questor, termine lorsque le joueur change ou lorsque l'exécution est terminée. """ scn_end = False if self.starting_scn: Scenario(self.starting_scn).launch(self.player) self.player.set_current_scenario(self.scenario) while not self.stoped: self.player.current_scenario.caller = self if not self.player.current_scenario.launch(self.player): # Si le scénario courant, la quête courante ou l'objectif courant possède l'attribut "wait_for", # alors il est prioritaire. # Note: par défaut, l'attribut est à Faux sauf pour l'objective où il est à True. if max( getattr(self.player.current_scenario, "wait_for", False), getattr(self.player.current_quest, "wait_for", False), getattr(self.player.current_objective, "wait_for", True)): if wait_for(self.player): scn_end = False self.stop() else: if not self.next_scn(): scn_end = True self.stop() if self.ending_scn: Scenario(self.ending_scn).launch(self.player) return scn_end def next_scn(self): """ Modifie le scénario actuel en trouvant le scénario suivant. :return: False si il n'y a pas de scénario suivant, True sinon. """ todo = [ s for s in self.player.current_scenario.next_scenario if not s.completed ] if not todo: return False if len(todo) == 1: self.player.set_current_scenario(todo[0]) return True sm.speech_and_move( u"Il y a plusieurs scénarios disponibles. Lequel veux-tu executer?" ) kws = [ "premier", "2e" if not Setting.NAO_CONNECTED else "deuxième", "troisième", "quatrième", "cinquième", "sixième" ] sm.speech_and_move(u"".join([ u"Le {} s'intitule {}.".format(kws[i], todo[i].name) for i in range(len(todo)) ])) msg = nl.nao_listen().lower() rep = nkr.sentence_keywords(msg, kws) if not rep: print("Non reconnu !") return False self.player.set_current_scenario( Scenario( self.player.current_scenario.next_scenario[kws.index(rep)])) return True def stop(self): """ Stoppe le Questor et Nao """ print("Stopping Questor...") self.player.save() self.stoped = True print("Stoped.")
# coding: utf-8 from NaoCreator.setting import Setting Setting(nao_connected=False, debug=True, nao_quest_v="2.1", ip="192.168.0.1") from NaoQuest.questor import Questor from PlayerManager.player_manager import Player Player("boby").save() q = Questor('Absence', "boby") q.launch() q.player.save()