Exemple #1
0
 def search_attributes(self, searched):
     file = xml_file()
     file.load_file('data/armors.xml')
     root = file.root
     for node in root.iter('armor'):
         brand = str(node.find('brand').text)
         name = str(node.find('name').text)
         if brand + ' ' + name == searched:
             type = str(node.find('type').text)
             cost = str(node.find('cost').text)
             ev_num = int(node.find('ev').text)
             sp_elements = list(node.find('sp'))
             self.add_attribute('type',type)
             self.add_attribute('cost',cost)
             self.add_attribute('ev',ev_num)
             for sp_value in sp_elements:
                 self.add_sp_location(sp_value.tag, sp_value.text)
Exemple #2
0
    def save(self):
        x = xml_file()
        x.create_root("Character")
        x.create_sub_element("info", "root")
        x.create_sub_element("family", "root")
        x.create_sub_element("personality", "root")
        x.create_sub_element("skills", "root")
        x.create_sub_element("attributes", "root")
        x.create_sub_element("perks", "root")
        x.create_sub_element("talents", "root")

        x.create_sub_element("complications", "root")
        x.create_sub_element("cyberwears", "root")
        x.create_sub_element("items", "root")
        x.create_sub_element("lifepath", "root")

        x.create_sub_element("player", "info")
        x.create_sub_element("first_name", "info")
        x.create_sub_element("second_name", "info")
        x.create_sub_element("last_name", "info")
        x.create_sub_element("alias", "info")
        x.create_sub_element("age", "info")

        x.create_sub_element("family_rank", "family")
        x.create_sub_element("parents", "family")
        x.create_sub_element("parent_status", "family")
        x.create_sub_element("parent_event", "family")
        x.create_sub_element("family_status", "family")
        x.create_sub_element("family_event", "family")
        x.create_sub_element("childhood_enviroment", "family")
        x.create_sub_element("childhood_trauma_fortune", "family")
        x.create_sub_element("family_contact", "family")
        x.create_sub_element("siblings", "family")

        x.create_sub_element("prime_motivation", "personality")
        x.create_sub_element("most_valued_person", "personality")
        x.create_sub_element("most_valued_posession", "personality")
        x.create_sub_element("feels_about_people", "personality")
        x.create_sub_element("inmode", "personality")
        x.create_sub_element("exmode", "personality")

        x.set_text(self.get_attribute("player"), "player")
        x.set_text(self.get_attribute("First name"), "first_name")
        x.set_text(self.get_attribute("Second name"), "second_name")
        x.set_text(self.get_attribute("Last name"), "last_name")
        alias = self.get_attribute("Alias")
        x.set_text(alias, "alias")
        x.set_text(str(self.get_attribute("age")), "age")

        x.set_text(self.get_attribute("family rank"), "family_rank")
        x.set_text(self.get_attribute("parents"), "parents")
        x.set_text(self.get_attribute("parent status"), "parent_status")
        x.set_text(self.get_attribute("parent event"), "parent_event")
        x.set_text(self.get_attribute("family status"), "family_status")
        x.set_text(self.get_attribute("family event"), "family_event")
        x.set_text(self.get_attribute("childhood enviroment"), "childhood_enviroment")
        x.set_text(self.get_attribute("childhood trauma/fortune"), "childhood_trauma_fortune")
        x.set_text(self.get_attribute("family contact"), "family_contact")

        try:
            for sibling in self.siblings:
                x.create_sub_element("sibling", "family")
                x.set_value("gender", sibling.gender, "sibling")
                x.set_value("age", str(sibling.age), "sibling")
                x.set_value("relation", sibling.relation, "sibling")
                x.set_text(sibling.name, "sibling")
        except Exception:
            x.create_sub_element("sibling", "siblings")
            x.set_value("gender", "none", "sibling")
            x.set_value("age", "0", "sibling")
            x.set_value("relation", "none", "sibling")
            x.set_text("you are the only child", "sibling")

        x.set_text(self.get_attribute("prime motivation"), "prime_motivation")
        x.set_text(self.get_attribute("most valued person"), "most_valued_person")
        x.set_text(self.get_attribute("most valued posession"), "most_valued_posession")
        x.set_text(self.get_attribute("feels about people"), "feels_about_people")
        x.set_text(self.get_attribute("inmode"), "inmode")
        x.set_text(self.get_attribute("exmode"), "exmode")

        for quirk in self.get_attribute("quirks"):
            x.create_sub_element("quirk", "personality")
            x.set_text(quirk, "quirk")

        for disorder in self.get_attribute("disorders"):
            x.create_sub_element("disorder", "personality")
            x.set_text(disorder, "disorder")

        for phobia in self.get_attribute("phobias"):
            x.create_sub_element("phobia", "personality")
            x.set_text(phobia, "phobia")

        for hair in self.get_attribute("hair"):
            x.create_sub_element("hair", "personality")
            x.set_text(hair, "hair")

        for clothes in self.get_attribute("clothes"):
            x.create_sub_element("clothes", "personality")
            x.set_text(clothes, "clothes")

        for affe in self.get_attribute("affections"):
            x.create_sub_element("affection", "personality")
            x.set_text(affe, "affection")

        for attribute, value in self.__stats.items():
            x.create_sub_element("attribute", "attributes")
            x.set_value("type", attribute, "attribute")
            x.set_text(str(value), "attribute")
        for skill, value in self.__skills.items():
            x.create_sub_element("skill", "skills")
            x.set_value("type", skill, "skill")
            x.set_text(str(value), "skill")
        for perk, value in self.__perks.items():
            x.create_sub_element("perk", "perks")
            x.set_value("type", perk, "perk")
            x.set_text(str(value), "perk")
        for talent, value in self.__talents.items():
            x.create_sub_element("talent", "talents")
            x.set_value("type", talent, "talent")
            x.set_text(str(value), "talent")

        for complication, value in self.__complications.items():
            try:
                x.create_sub_element("complication", "complications")
                x.set_value("type", str(value), "complication")
                x.set_value("intensity", value.attributes["intensity"], "complication")
                x.set_value("frequency", value.attributes["frequency"], "complication")
                x.set_value("importance", value.attributes["importance"], "complication")
                x.set_text(str(value.attributes["total"]), "complication")
                # x.set_text(str(value), "complication")
            except Exception:
                print("failed to include complication into save file")

        try:
            for cyberwear in self.__cyberwear:
                if cyberwear.get_attribute("name") == "default":
                    for option in cyberwear.get_attribute("installed_options"):
                        x.create_sub_element("cyberwear", "cyberwears")
                        x.set_value("name", option.get_attribute("name"), "cyberwear")
                        x.set_text(str(option.get_attribute("effective_hum_cost")), "cyberwear")
                else:
                    x.create_sub_element("cyberwear", "cyberwears")
                    x.set_value("name", cyberwear.get_attribute("name"), "cyberwear")
                    x.set_text(cyberwear.get_attribute("effective_hum_cost"), "cyberwear")
                    for option in cyberwear.get_attribute("installed_options"):
                        x.create_sub_element("option", "cyberwear")
                        x.set_value("name", option.get_attribute("name"), "option")
                        x.set_text(option.get_attribute("effective_hum_cost"), "option")
        except Exception:
            print("failed to save cyberware")

        for key, value in self.__weapons.items():
            x.create_sub_element("item", "items")
            x.set_value("type", "weapon", "item")
            x.set_text(key, "item")

        for key, value in self.__armors.items():
            x.create_sub_element("item", "items")
            x.set_value("type", "armor", "item")
            x.set_text(key, "item")

        for key, value in self.__items.items():
            x.create_sub_element("item", "items")
            x.set_value("type", "item", "item")
            x.set_text(key, "item")

        for year in self.lifepath:
            x.create_sub_element("event", "lifepath")
            x.set_value("age", year.attributes["year"], "event")
            type = year.attributes["type"]
            x.set_value("type", type, "event")
            if type == "disaster":
                disaster = year.attributes["disaster type"]
                x.set_value("disaster_type", disaster, "event")
                if disaster == "debt":
                    x.set_value("amount", year.attributes["money"], "event")
                elif disaster == "prison/hostage":
                    x.set_value("prison_time", year.attributes["prison time"], "event")
                elif disaster == "drugs/illness":
                    x.set_value("effect", year.attributes["effect"], "event")
                elif disaster == "betrayel":
                    x.set_value("betrayel_type", year.attributes["blackmail type"], "event")
                elif disaster == "accident":
                    x.set_value("accident_type", year.attributes["accident type"], "event")
                elif disaster == "death":
                    x.set_value("death_type", year.attributes["death type"], "event")
                elif disaster == "false accusation":
                    x.set_value("accusation", year.attributes["accusation"], "event")
                elif disaster == "crime":
                    x.set_value("hunter", year.attributes["hunter"], "event")
                elif disaster == "corporation":
                    x.set_value("corporation_type", year.attributes["corporation type"], "event")
                elif disaster == "breakdown":
                    x.set_value("complication", year.attributes["breakdown type"], "event")
            elif type == "lucky":
                lucky = year.attributes["lucky type"]
                x.set_value("lucky_type", lucky, "event")
                if lucky == "powerful connection":
                    x.set_value("connection_type", year.attributes["connection type"], "event")
                elif lucky == "fortune":
                    x.set_value("amount", year.attributes["amount"], "event")
                else:
                    pass
            elif type == "friend":
                friend = year.attributes["friend type"]
                x.set_value("friend_type", friend, "event")
            elif type == "enemy":
                enemy_type = year.attributes["enemy type"]
                enemy_cause = year.attributes["enemy cause"]
                enemy_relation = year.attributes["enemy relation"]
                enemy_action = year.attributes["enemy action"]
                enemy_resources = year.attributes["enemy resources"]
                x.set_value("enemy_type", enemy_type, "event")
                x.set_value("cause", enemy_cause, "event")
                x.set_value("relation", enemy_relation, "event")
                x.set_value("reaction", enemy_action, "event")
                x.set_value("resources", enemy_resources, "event")
            elif type == "love":
                love_type = year.attributes["love type"]
                x.set_value("love_type", love_type, "event")
                if love_type == "tragic love":
                    x.set_value("mutual_feelings", year.attributes["mutual feelings"], "event")
                    x.set_value("tragic_type", year.attributes["tragedy"], "event")
                elif love_type == "with problems":
                    x.set_value("problem", year.attributes["problem"], "event")
                elif love_type == "complicated":
                    x.set_value("complication", year.attributes["complication"], "event")

        player = self.get_attribute("player")
        full_name = (
            self.get_attribute("First name")
            + " "
            + self.get_attribute("Second name")
            + " "
            + self.get_attribute("Alias")
            + " "
            + self.get_attribute("Last name")
        )
        if player != "npc":
            x.save_file("playerchars/" + player + "_" + full_name)
        else:
            x.save_file("npcs/" + full_name)
        x.save_file("lastchar_saved.xml")