from story import Story import json from ai_llm import AI_LLM class Quest: def __init__(self, quest_dets="quest.json", stories_dets="stories.json"): self.stories = {} llm_client = AI_LLM() self.current_story = None self.quest_complete = False with open(stories_dets, "r") as file: storiesJson = json.load(file) with open(quest_dets, "r") as file: self.quest = json.load(file) for story in storiesJson: self.stories[story] = Story(storiesJson[story], llm_client) @staticmethod def get_initial_messages(quest_dets="quest.json", stories_dets="stories.json"): initial_messages = [] with open(stories_dets, "r") as file: storiesJson = json.load(file) with open(quest_dets, "r") as file: quest = json.load(file) initial_messages.append(quest["description"]) for story in storiesJson: display_message = story display_message += ": \n" display_message += storiesJson[story]["description"] initial_messages.append(display_message) return initial_messages, quest["hints"], quest["images"] def play_next_turn(self, user_input=""): codex = {} if self.quest_complete: return self.quest["quest_complete_message"], [], [], codex if self.current_story == None: if user_input not in self.stories: return self.quest_complete, self.quest["invalid_story_choice_message"], self.quest["hints"], self.quest["images"], codex else: self.current_story = user_input is_game_complete, display_message, hints, images, codex = self.stories[self.current_story].play_next_turn(user_input) if is_game_complete: if len(self.stories) == 0: self.quest_complete = True display_message = self.quest["quest_complete_message"] hints = [] images = [] else: self.stories.pop(self.current_story) start_quest_msg, hints, images = self.__start_new_story_msg() #The story has been popped, should be an updated list display_message += start_quest_msg self.current_story = None return self.quest_complete, display_message, hints, images, codex def __start_new_story_msg(self): display_message = self.quest["description"] display_message += "\n\n" for story in self.stories: display_message += story display_message += ":\n" display_message += self.stories[story].get_story_description() display_message += "\n\n" return display_message, self.quest["hints"], self.quest["images"]