def tick(self, input_key, player): if not self.is_dead(): self.move(dims, player) self.regenerate_health() if Func.player_at_location(player, self.location): if self.is_enemy(): self.location = self.prevlocation[:] self.allow_movement = False Func.start_combat(player, self, input_key)
def interact(self, player): input_key = -1 while input_key is not ord("4"): if not self.quests: self.has_quest = False if self.talking is False: journal.insertln() journal.addstr(1, 1, self.dialogue["intro"][0]) self.conversation_start() self.talking = True conversation.refresh() Func.update_journal() input_key = conversation.getch() if input_key is ord("1"): self.talk(player) self.conversation_start() input_key = -1 elif input_key is ord("2"): if self.has_quest is True: while 1: journal.insertln() journal.addstr(1, 1, "These are the quests that I have") journal.border() journal.refresh() quest_list = [] for quest in self.quests: quest_list.append(quest.name) self.show_options(quest_list) quests = [] for quest in self.quests: quests.append(quest) input_key = conversation.getch() self.choose_quest(input_key, quests, player) self.conversation_start() break input_key = -1 else: journal.insertln() journal.addstr(1, 1, "I have no quest for you at the moment") journal.refresh() elif input_key is ord("3"): journal.insertln() journal.addstr(1, 1, self.dialogue["trade"][0]) if self.trade_inventory is not []: self.trade(player) self.conversation_start()
def load_npc_dialogue(name): # for NEW game only filename = 'Dialogue/' + Func.sanitize_filename(name) + '.json' if os.path.exists(filename): with open(filename, 'r') as a: dialogue = json.load(a) a.close() DebugLog.write("dialogue loaded" + "\n") return dialogue else: DebugLog.write("no dialogue\n")
def talk(self, player): topic_list = [] for topic in self.dialogue["talk"]: if topic["base_topic"]: topic_list.append(topic["topic"]) topic_list.append("Back") topics = [] for topic in self.dialogue["talk"]: if topic["base_topic"]: topics.append(topic) topics.append("") Func.print_to_journal("Hello") while 1: self.show_options(topic_list) input_key = conversation.getch() if not chr(input_key).isnumeric(): continue if int(chr(input_key)) - 1 >= len(topic_list): continue if topics[int(chr(input_key)) - 1] == "": break chosen_topic = topics[int(chr(input_key)) - 1] player.update_talk_quests(self, chosen_topic["topic"]) topic_list = [] for topic in chosen_topic["choices"]: topic_list.append(topic) topics = [] for topic in self.dialogue["talk"]: if topic["topic"] in chosen_topic["responses"]: topics.append(topic) for response in chosen_topic["responses"]: if response == "": topics.append(response) Func.print_to_journal(chosen_topic["content"])
def load_npcs_for_new_game(): for file in os.listdir("./NPCs"): if file.endswith(".json"): filename = "NPCs/" + file DebugLog.write(filename + "\n") with open(filename, 'r') as f: npc_data = json.load(f) f.close() name = npc_data["name"] character = npc_data["character"] race = npc_data["race"] if race == "Human": temp_npc = Human.Human( name, character, npc_data["id"], npc_data["spawn_location"], npc_data["location"], npc_data["health"], npc_data["level"], NpcClass.Relationship(npc_data["relationship"])) elif race == "Avaker": temp_npc = Avaker.Avaker( name, character, npc_data["id"], npc_data["spawn_location"], npc_data["location"], npc_data["health"], npc_data["level"], NpcClass.Relationship(npc_data["relationship"])) elif race == "Dragon": temp_npc = Dragon.Dragon( name, character, npc_data["id"], npc_data["spawn_location"], npc_data["location"], npc_data["health"], npc_data["level"], NpcClass.Relationship(npc_data["relationship"])) elif race == "Wolf": temp_npc = Wolf.Wolf( name, npc_data["id"], npc_data["spawn_location"], npc_data["location"], npc_data["health"], npc_data["level"], NpcClass.Relationship(npc_data["relationship"])) else: temp_npc = Unkown.Unknown( name, character, npc_data["id"], npc_data["spawn_location"], npc_data["location"], npc_data["health"], npc_data["level"], NpcClass.Relationship(npc_data["relationship"])) temp_npc.location = npc_data["location"] temp_npc.prevlocation = temp_npc.location[:] temp_npc.health = npc_data["health"] temp_npc.max_health = npc_data["max_health"] temp_npc.character = npc_data["character"] temp_npc.inventory = Func.load_inventory(npc_data["inventory"]) temp_npc.has_quest = npc_data["has_quest"] temp_npc.level = npc_data["level"] temp_npc.total_exp = npc_data["total_exp"] temp_npc.exp_for_next_level = npc_data["exp_for_next_level"] temp_npc.exp_to_next_level = npc_data["exp_to_next_level"] temp_npc.strength = npc_data["strength"] temp_npc.respawnable = npc_data["respawnable"] temp_npc.spawn_location = npc_data["spawn_location"] temp_npc.endurance = npc_data["endurance"] temp_npc.defense = npc_data["defense"] temp_npc.dialogue = NpcClass.load_npc_dialogue(name) temp_npc.quests = QuestClass.load_quests(npc_data["quests"]) temp_npc.allow_movement = npc_data["allow_movement"] # load equipped npc items if temp_npc.race is not NpcClass.Race.Wolf: equipped_item = npc_data["equipped"] for weapon in Items.all_weapons: if equipped_item["weapon"] is not None: if equipped_item["weapon"] == weapon.name: temp_npc.equipped["weapon"] = weapon for armour in Items.all_armours: if equipped_item["helmet"] is not None: if equipped_item["helmet"] == armour.name: temp_npc.equipped["helmet"] = armour if equipped_item["chest"] is not None: if equipped_item["chest"] == armour.name: temp_npc.equipped["chest"] = armour if equipped_item["gloves"] is not None: if equipped_item["gloves"] == armour.name: temp_npc.equipped["gloves"] = armour if equipped_item["belt"] is not None: if equipped_item["belt"] == armour.name: temp_npc.equipped["belt"] = armour if equipped_item["pants"] is not None: if equipped_item["pants"] == armour.name: temp_npc.equipped["pants"] = armour if equipped_item["shoes"] is not None: if equipped_item["shoes"] == armour.name: temp_npc.equipped["shoes"] = armour # load items to trade for trade_item in npc_data["trade_inventory"]: for item in Items.all_items: if trade_item == item.name: temp_npc.trade_inventory.append(item)
def load_npcs(save, npcs): npcs.clear() for npc in save["all_NPCs"]: filename = 'NPCs/' + Func.sanitize_filename(npc["name"]) + '.json' file = open(filename, "r") npc_data = json.load(file) name = npc_data["name"] character = npc_data["character"] race = npc_data["race"] if race == "Human": temp_npc = Human.Human( name, character, npc_data["id"], npc_data["spawn_location"], npc_data["location"], npc_data["health"], npc_data["level"], NpcClass.Relationship(npc_data["relationship"])) elif race == "Avaker": temp_npc = Avaker.Avaker( name, character, npc_data["id"], npc_data["spawn_location"], npc_data["location"], npc_data["health"], npc_data["level"], NpcClass.Relationship(npc_data["relationship"])) elif race == "Dragon": temp_npc = Dragon.Dragon( name, character, npc_data["id"], npc_data["spawn_location"], npc_data["location"], npc_data["health"], npc_data["level"], NpcClass.Relationship(npc_data["relationship"])) elif race == "Wolf": temp_npc = Wolf.Wolf( name, npc_data["id"], npc_data["spawn_location"], npc_data["location"], npc_data["health"], npc_data["level"], NpcClass.Relationship(npc_data["relationship"])) else: temp_npc = Unkown.Unknown( name, character, npc_data["id"], npc_data["spawn_location"], npc_data["location"], npc_data["health"], npc_data["level"], NpcClass.Relationship(npc_data["relationship"])) DebugLog.write(temp_npc.name + " Race: " + str(temp_npc.race)[5:] + "\r\n") temp_npc.prevlocation = temp_npc.location[:] temp_npc.health = npc["health"] temp_npc.max_health = npc_data["max_health"] temp_npc.inventory = Func.load_inventory(npc_data["inventory"]) temp_npc.has_quest = npc_data["has_quest"] temp_npc.level = npc_data["level"] temp_npc.total_exp = npc_data["total_exp"] temp_npc.exp_for_next_level = npc_data["exp_for_next_level"] temp_npc.exp_to_next_level = npc_data["exp_to_next_level"] temp_npc.strength = npc_data["strength"] temp_npc.respawnable = npc_data["respawnable"] temp_npc.endurance = npc_data["endurance"] temp_npc.defense = npc_data["defense"] temp_npc.dialogue = NpcClass.load_npc_dialogue(npc["name"]) temp_npc.quests = QuestClass.load_quests(npc_data["quests"]) temp_npc.allow_movement = npc["allow_movement"] # load equipped npc items if temp_npc.race is not NpcClass.Race.Wolf: equipped_item = npc_data["equipped"] for weapon in Items.all_weapons: if equipped_item["weapon"] is not None: if equipped_item["weapon"] == weapon.name: temp_npc.equipped["weapon"] = weapon for armour in Items.all_armours: if equipped_item["helmet"] is not None: if equipped_item["helmet"] == armour.name: temp_npc.equipped["helmet"] = armour if equipped_item["chest"] is not None: if equipped_item["chest"] == armour.name: temp_npc.equipped["chest"] = armour if equipped_item["gloves"] is not None: if equipped_item["gloves"] == armour.name: temp_npc.equipped["gloves"] = armour if equipped_item["belt"] is not None: if equipped_item["belt"] == armour.name: temp_npc.equipped["belt"] = armour if equipped_item["pants"] is not None: if equipped_item["pants"] == armour.name: temp_npc.equipped["pants"] = armour if equipped_item["shoes"] is not None: if equipped_item["shoes"] == armour.name: temp_npc.equipped["shoes"] = armour # load items to trade for trade_item in npc_data["trade_inventory"]: for item in Items.all_items: if trade_item == item.name: temp_npc.trade_inventory.append(item) DebugLog.write("NPCs loaded: " + str(len(npcs)) + "\n\n")
def tick(self, input_key, environment): global player_turn if self.exp_is_enough(): self.level_up() # opens the player inventory if input_key is ord("i"): conversation.border() conversation.addstr(1, 1, "1 - equip") conversation.addstr(2, 1, "2 - unequip") conversation.refresh() self.open_inventory() conversation.clear() conversation.refresh() if input_key is ord("l"): self.open_quest_log() if input_key is ord("r"): if self.is_dead(): self.respawn(30, 50) spawn_character(map_window, self, self.location[0], self.location[1]) if not self.is_dead(): self.move(input_key, dims) # checks to see if the player moves unto an enemy # if so it starts combat # if not the player regenerates health and updates its status result = Func.enemy_at_location(Character.all_enemies, self.location, enemy_status) if result["result"] is True: enemy = result["enemy"] Func.start_combat(self, enemy, input_key) self.update_all_quests(enemy, "") else: self.regenerate_health() self.update_player_status() # checks to see if the player moves onto an NPC # if so it starts interacting with it result = Func.npc_at_location(self.location, Character.all_NPCs) if result["result"] is True: NPC = result["npc"] if NPC.is_enemy(): NPC.allow_movement = False Func.start_combat(self, NPC, input_key) self.update_all_quests(NPC, "") else: self.update_all_quests(NPC, "") self.update_player_status() NPC.interact(self) Func.update_journal() NPC.talking = False conversation.clear() conversation.refresh() self.update_all_quests(NPC, "") # updates the quests that the player has then ends the player's turn Func.update_player_location(self, environment) player_turn = False Func.player_dead(self)