Kill_Modification = [mod_1, mod_2, mod_3, mod_4] #---------------------------------- # Story Results #---------------------------------- One = StoryNode("MurderBlackmailer_Request_from_Invoker", {"Node_Type" : "Info"}, A) One.set_modification(Move_1) Two = StoryNode("Go_To_Victim", {"Node_Type" : "Go_To"}, B) Two.set_modification(Move_2) Three = StoryNode("Kill_Victim", {"Node_Type" : "MurderBlackmailer"}, B) Three.set_modification(Kill_Modification) Four = StoryNode("Return_to_Invoker", {"Node_Type" : "Return"}, A) Four.set_modification(Move_1) MurderBlackmailer_Story = StoryGraph("MurderBlackmailer_Story", [One, Two, Three, Four]) MurderBlackmailer_Story.connect(One, {}, Two) MurderBlackmailer_Story.connect(Two, {}, Three) MurderBlackmailer_Story.connect(Three, {}, Four) MurderBlackmailer_Rule = RewriteRule(None, MurderBlackmailer, MurderBlackmailer_Story, None, "Murder_Blackmailer") #---------------------------------------------------- # GiveGift Skeleton #---------------------------------------------------- #---------------------------------- # Social Condition #---------------------------------- A = SocialNode("Invoker", {"type" : "NPC", "alive" : True}) B = SocialNode("Recipient", {"type" : "NPC", "alive" : True})
#---------------------------------- # Social Modification #---------------------------------- #---------------------------------- # Story Condition #---------------------------------- Murder = StoryNode("Give_Gift", {"Node_Type" : "Give_Item"}, Recipient) Ambush_Story_Condition = StoryGraph("Stolen_Gift_Condition", [Murder]) #---------------------------------- # Story Outcome #---------------------------------- Spare = StoryNode("Stolen_Gift", {"Node_Type" : "Robbery", "Additional" : "Branched_Node"}, Monster) Foigh = StoryNode("Fight_For_Gift", {"Node_Type" : "Fight", "Additional" : "Branched_Node"}, Monster) Ambush_Story_Outcome = StoryGraph("Stolen_Gift_Story_Outcome", [Murder, Foigh, Spare]) Ambush_Story_Outcome.connect(Spare, {}, Foigh) Ambush_Rule = RewriteRule(Ambush_Story_Condition, Ambush_Social_Condition, Ambush_Story_Outcome, None, "Stolen_Gift", True) ##---------------------------------------------------- ## Ambush Skeleton ##---------------------------------------------------- # ##---------------------------------- ## Social Condition ##---------------------------------- #Lover = SocialNode("Lover", {"alive" : True}) #Target = SocialNode("Victim", {"alive" : True}) # #Ambush_Social_Condition = Graph("Ambush_Social_Condition", [Target, Lover]) #Ambush_Social_Condition.connect(Lover, {"Loves" : "N/A"}, Target) # ##----------------------------------
def readGraph(self): tree = ET.parse(self._filename) root = tree.getroot() #Get our graph name graph_name = root.attrib.get('name') #Process the nodes node_list = [] for node in root.iter('node'): story_node_name = node.attrib['name'] node_attributes = {} #Get the target node_target = node.find('target').text #Get the node type node_attributes['Node_Type'] = node.find('nodetype').text #Get the attributes for attribute in node.findall('attr'): attribute_type = attribute.attrib.get('type') attribute_name = attribute.attrib.get('name') attribute_value = attribute.find('value').text if attribute_type == 'bool': node_attributes[attribute_name] = ( attribute_value == "True") elif attribute_type == 'int': node_attributes[attribute_name] = int(attribute_value) elif attribute_type == 'float': node_attributes[attribute_name] = float(attribute_value) else: node_attributes[attribute_name] = attribute_value new_node = StoryNode(story_node_name, node_attributes, self._graph.get_node_from_name(node_target)) if not node.attrib['modification'] == 'None': modification_filename = self._path + "Modifications/" + node.attrib[ 'modification'] modification_reader = XMLModificationReader( modification_filename) modification = modification_reader.readModification() new_node.set_modification(modification) node_list.append(new_node) #Create the Return Graph returnGraph = StoryGraph(graph_name, node_list) #Begin Making the connections for connection in root.iter('connection'): connect_from = connection.attrib.get('from') from_node = returnGraph.get_node_from_name(connect_from) connect_to = connection.attrib.get('to') to_node = returnGraph.get_node_from_name(connect_to) relation = connection.find('relation').attrib if relation.keys()[0] == "none": relation = {} returnGraph.connect(from_node, relation, to_node) return returnGraph
def readGraph(self): tree = ET.parse(self._filename) root = tree.getroot() #Get our graph name graph_name = root.attrib.get('name') #Process the nodes node_list = [] for node in root.iter('node'): story_node_name = node.attrib['name'] node_attributes = {} #Get the target node_target = node.find('target').text #Get the node type node_attributes['Node_Type'] = node.find('nodetype').text #Get the attributes for attribute in node.findall('attr'): attribute_type = attribute.attrib.get('type') attribute_name = attribute.attrib.get('name') attribute_value = attribute.find('value').text if attribute_type == 'bool': node_attributes[attribute_name] = (attribute_value == "True") elif attribute_type == 'int': node_attributes[attribute_name] = int(attribute_value) elif attribute_type == 'float': node_attributes[attribute_name] = float(attribute_value) else: node_attributes[attribute_name] = attribute_value new_node = StoryNode(story_node_name, node_attributes, self._graph.get_node_from_name(node_target)) if not node.attrib['modification'] == 'None': modification_filename = self._path + "Modifications/" + node.attrib['modification'] modification_reader = XMLModificationReader(modification_filename) modification = modification_reader.readModification() new_node.set_modification(modification) node_list.append(new_node) #Create the Return Graph returnGraph = StoryGraph(graph_name, node_list) #Begin Making the connections for connection in root.iter('connection'): connect_from = connection.attrib.get('from') from_node = returnGraph.get_node_from_name(connect_from) connect_to = connection.attrib.get('to') to_node= returnGraph.get_node_from_name(connect_to) relation = connection.find('relation').attrib if relation.keys()[0] == "none": relation = {} returnGraph.connect(from_node, relation, to_node) return returnGraph