def learn_utterances(self, word): learned = False print("Learn Utterances") print(utterances.filter_utts(contains_word=word)) for utt in utterances.filter_utts(contains_word=word): print(utt.printable(None, self)) utt_known = True for utt_word in utt.word_array: if utt_word not in self.known_words: utt_known = False if utt_known: if utt in self.known_utterances[utterances.UTT_UNKNOWN]: self.known_utterances[utterances.UTT_UNKNOWN].remove(utt) learned = True self.known_utterances[utt.utype].append(utt) messages.MSG_CENTER.add_message((messages.PLAYER_NEW_UTT, utt.printable(None, self)), delay_dispatch=True) return learned
def choose_utterance(self, phase, prompt=None): # TODO: This works, but it's messy, clean it up. if prompt is not None: if not utterances.coherent(phase, prompt): options = utterances.filter_utts(utype=utterances.UTT_CONF) return random.choice(options) if phase == utterances.UTT_GREET: options = utterances.filter_utts(utype=utterances.UTT_GREET) elif phase == utterances.UTT_PART: options = utterances.filter_utts(utype=utterances.UTT_PART) else: if prompt is None: options = utterances.filter_utts(utterances.UTT_Q) else: for key in self.traits: if isinstance(self.traits[key], prompt.prompts_for): options = utterances.filter_utts(responds_with=self.traits[key]) return random.choice(options)
def __init__(self): Character.__init__(self) self.known_utterances = dict() self.known_words = [] self.learning_words = dict() for key in utterances.utt_dict: self.known_utterances[key] = [] # Presumably the player-character can at the very least emote properly. for utt in utterances.filter_utts(class_type=utterances.Emotive): self.known_utterances[utt.utype].append(utt)
def TestResponses(ai1, ai2): utt_type = random.choice([utterances.UTT_Q, utterances.UTT_GREET, utterances.UTT_PART]) chosen_utt = random.choice(utterances.filter_utts(utype=utt_type)) print(chosen_utt.printable(ai1, ai1)) print(ai2.choose_utterance(phase=utt_type, prompt=chosen_utt).printable(ai2, ai2))