コード例 #1
0
    def _load(self, ability_group_info_element):

        # handle all the children
        for child in list(ability_group_info_element):

            tag = child.tag
            if tag == "abilitygrouptitle":
                if self.title is not None:
                    raise Exception("Only one abilitygrouptitle per file.")
                else:
                    self.title = child.text.strip()

            elif tag == "abilitygroupid":
                if self.ability_group_id is not None:
                    raise Exception(
                        "Only one abilitygroupid per ability. (%s) %s\n" %
                        (child.tag, str(child)))
                else:
                    # save the id location for debugging (can't have duplicates)!
                    ability_group_id = child.text
                    ability_group_location = "%s:%s" % (self.fname,
                                                        child.sourceline)
                    if ability_group_id in self._ids:
                        previous_location = self._ids[ability_group_id]
                        raise Exception(
                            "Ability group id: '%s' appears in two places %s and %s"
                            % (ability_group_id, ability_group_location,
                               previous_location))
                    else:
                        self._ids[ability_group_id] = ability_group_location

                    # save the id!
                    self.ability_group_id = ability_group_id

            elif tag == "abilitygroupfamily":
                self.family = child.text
                assert self.family in ("Mundane", "Combat", "Magic")

            elif tag == "abilitygroupdescription":
                if self.description is not None:
                    raise Exception(
                        "Only one abilitygroupdescription per file.")
                else:
                    self.description = children_to_string(child)

            elif tag is COMMENT:
                pass  # ignore comments!

            else:
                #
                raise Exception("UNKNOWN (%s) %s\n" % (child.tag, str(child)))
        return
コード例 #2
0
    def _load(self, archetype_node, fail_fast):
        # handle all the children
        for child in list(archetype_node):

            tag = child.tag
            if tag == "archetypetitle":
                if self.title is not None:
                    raise NonUniqueTagError(tag, self.fname, child.sourceline)
                else:
                    self.title = child.text.strip()

            elif tag == "archetypeid":
                if self.archetype_id is not None:
                    raise NonUniqueTagError(tag, self.fname, child.sourceline)
                else:
                    self.archetype_id = child.text.strip()

            elif tag == "archetypeac":
                if self.ac is not None:
                    raise NonUniqueTagError(tag, self.fname, child.sourceline)
                else:
                    self.ac = child.text.strip()

            elif tag == "archetypemove":
                if self.move is not None:
                    raise NonUniqueTagError(tag, self.fname, child.sourceline)
                else:
                    self.move = child.text.strip()

            elif tag == "inheritance":
                self._load_inheritance(inheritance=child)

            elif tag == "archetypedescription":
                if self.description is not None:
                    raise NonUniqueTagError(tag, self.fname, child.sourceline)
                else:
                    self.description = children_to_string(child)

            elif tag == "archetypeinitiative":
                if self.initiative is not None:
                    raise NonUniqueTagError(tag, self.fname, child.sourceline)
                    #raise Exception("Only one archetypeinitiative per file.")
                else:
                    self.initiative = convert_str_to_int(child.text)

            elif tag == "startingcash":
                if self.starting_cash is not None:
                    raise NonUniqueTagError(tag, self.fname, child.sourceline)
                else:
                    self.starting_cash = child.text

            elif tag == "startinggear":
                if self.starting_gear is not None:
                    raise NonUniqueTagError(tag, self.fname, child.sourceline)
                else:
                    self.starting_gear = normalize_ws(child.text)

            elif tag == "height":
                if self.height is not None:
                    raise NonUniqueTagError(tag, self.fname, child.sourceline)
                else:
                    self.height = parse_measurement_to_str(self.fname, child)

            elif tag == "weight":
                if self.weight is not None:
                    raise NonUniqueTagError(tag, self.fname, child.sourceline)
                else:
                    self.weight = parse_measurement_to_str(self.fname, child)

            elif tag == "appearance":
                if self.appearance is not None:
                    raise NonUniqueTagError(tag, self.fname, child.sourceline)
                else:
                    self.appearance = normalize_ws(child.text)

            elif tag == "age":
                if self.age is not None:
                    raise NonUniqueTagError(tag, self.fname, child.sourceline)
                else:
                    self.age = normalize_ws(child.text)

            elif tag == "aspectexamples":
                if self.aspect_examples is not None:
                    raise NonUniqueTagError(tag, self.fname, child.sourceline)
                else:
                    self.aspect_examples = child.text

            elif tag == "archetypetags":
                self.tags.load(child, fail_fast)

            elif tag == "archetypeinitialabilities":
                if self.initial_abilities is not None:
                    raise NonUniqueTagError(tag, self.fname, child.sourceline)
                else:
                    self.initial_abilities = children_to_string(child)

            elif tag == "levelprogressiontable":
                self.level_progression_table.load(child, fail_fast)

            elif tag == "abilitymodifiers":
                self._load_ability_modifiers(child)

            elif tag == "attrbonus":
                bonus = AttrBonus()
                bonus.parse(self.fname, child)
                self.attr_bonuses.append(bonus)

            elif tag == "attrmax":
                attr_max = AttrLimit()
                attr_max.parse(self.fname, AttrLimitType.MAX, child)
                self.attr_limits.append(attr_max)

            elif tag == "attrmin":
                attr_min = AttrLimit()
                attr_min.parse(self.fname, AttrLimitType.MIN, child)
                self.attr_limits.append(attr_min)

            elif tag is COMMENT:
                # ignore comments!
                pass

            else:
                raise Exception("UNKNOWN XML TAG (%s) File: %s Line: %s\n" %
                                (child.tag, self.fname, child.sourceline))
        return
コード例 #3
0
    def load_ability_level(cls, fname, ability, ability_level_element):
        level = cls()
        level.ability = ability

        # handle all the children
        for child in list(ability_level_element):
            tag = child.tag

            if tag == "defaultlore":
                if level.default_lore != 0:
                    raise Exception(
                        "Only one defaultlore per abilitylevel. (%s) %s\n" %
                        (child.tag, str(child)))
                else:
                    level.default_lore = int(child.text)

            elif tag == "innate":
                if level.innate:
                    raise Exception(
                        "Only one innate per abilitylevel. (%s) %s\n" %
                        (child.tag, str(child)))
                else:
                    level.innate = True

            elif tag == "successes":
                if level.successes > 0:
                    raise Exception(
                        "Only one successes per abilitylevel. (%s) %s\n" %
                        (child.tag, str(child)))
                else:
                    if child.text is not None:
                        level.successes = int(child.text)

            elif tag == "attempts":
                if level.attempts > 0:
                    raise Exception(
                        "Only one attempts per abilitylevel. (%s) %s "
                        "in file %s\n" % (child.tag, str(child), fname))
                else:
                    if child.text is not None:
                        level.attempts = int(child.text)

            elif tag == "failures":
                if level.failures > 0:
                    raise Exception(
                        "Only one masteryfailures per abilitylevel. (%s) %s\n"
                        % (child.tag, str(child)))
                else:
                    if child.text is not None:
                        level.failures = int(child.text)

            elif tag == "check":
                if level.check is not None:
                    raise Exception(
                        "Only one check per abilitylevel. (%s) %s\n" %
                        (child.tag, str(child)))
                else:
                    #level.check = get_text(child)
                    #level.check = node_to_string(child)
                    level.check = child.text

            elif tag == "damage":
                if level.damage is not None:
                    raise Exception(
                        "At most one damage per abilitylevel. (%s) %s\n" %
                        (child.tag, str(child)))
                else:
                    level.damage = child.text

            elif tag == "effect":
                if level.effect is not None:
                    raise Exception(
                        "At most one effect per abilitylevel. (%s) %s\n" %
                        (child.tag, str(child)))
                else:
                    level.effect = child.text

            elif tag == "levelnumber":
                if level.level_number is not None:
                    raise Exception(
                        "Only one levelnumber per abilitylevel. (%s) %s\n" %
                        (child.tag, str(child)))
                else:
                    level.level_number = int(child.text)

            elif tag == "leveldescription":
                if level.description is not None:
                    raise Exception(
                        "Only one description per ability-level. (%s) %s\n" %
                        (child.tag, str(child)))
                else:
                    level.description = children_to_string(child)

            elif tag == "prereqabilitylevel":

                ability_level_id = child.text
                if ability_level_id is not None:
                    prereq = AbilityLevelPrereq(ability_level_id)
                    level.ability_level_prereqs.append(prereq)
                    level.prerequisites.append(prereq)

            elif tag == "prereqtag":
                prerequisite_tag = child.text
                if prerequisite_tag is not None:
                    prereq = TagPrereq(prerequisite_tag)
                    level.prerequisite_tags.append(prereq)
                    level.prerequisites.append(prereq)

            elif tag == "prereqnottag":
                prerequisite_tag = child.text
                if prerequisite_tag is not None:
                    prereq = NotTagPrereq(prerequisite_tag)
                    level.prerequisite_tags.append(prereq)
                    level.prerequisites.append(prereq)

            elif tag == "prereqattr":
                prereq = AttrPrereq.parse_xml(child)
                level.prerequisite_attr.append(prereq)
                level.prerequisites.append(prereq)

            elif tag == "overcharge":
                overcharge = child.text.strip()
                if overcharge != "":
                    level.overcharge = overcharge

            elif tag is COMMENT:
                # ignore comments!
                pass

            else:
                #
                raise Exception("UNKNOWN (%s) %s\n" %
                                (child.tag, level.ability.fname))

        # add this ability level to the lookup table
        # (after we have an id)
        ability_level_lookup[level.get_id()] = level

        # check that if an ability requires successes or failures it has check
        if ((level.successes > 0 or level.attempts > 0 or level.failures > 0)
                and (level.check is None or level.check.strip() == "")):
            raise Exception(
                "Ability level %s (%s) requires mastery to level up but has "
                "no check." % (level.get_title(), level.get_id()))
        return level
コード例 #4
0
    def _load(self, ability_element):
        # handle all the children
        for child in list(ability_element):

            tag = child.tag
            if tag == "abilitytitle":
                if self.title is not None:
                    raise Exception(
                        "Only one abilitytitle per ability. (%s) %s\n" %
                        (child.tag, str(child)))
                else:
                    self.title = child.text

            elif tag == "abilityid":
                if self.ability_id is not None:
                    raise Exception(
                        "Only one abilityid per ability. (%s) %s\n" %
                        (child.tag, str(child)))
                else:
                    # check for duplicates!
                    ability_id = child.text
                    ability_location = self._get_location(child)
                    if ability_id in self._ids:
                        raise Exception(
                            "Ability id: %s appears in two places %s and %s" %
                            (ability_id, ability_location,
                             self._ids[ability_id]))
                    else:
                        self._ids[ability_id] = ability_location

                    # save the id!
                    self.ability_id = ability_id

            elif tag == "inborn":
                if self.inborn is not None:
                    raise Exception(
                        "Only one inborn element per ability. (%s) %s\n" %
                        (child.tag, str(child)))
                else:
                    self.inborn = convert_str_to_bool(child.text)

            elif tag == "gmgability":
                self.gmg_ability = True

            elif tag == "tag":
                self.tags.append(child.text)

            elif tag == "abilityclass":
                self.ability_class = AbilityClass.load(child.text)
                if self.ability_class == AbilityClass.NONE:
                    raise Exception("Unknown ability class: (%s) %s in %s\n" %
                                    (child.tag, child.text, self.fname))

            elif tag == "abilitylevels":
                if len(self.levels) > 0:  #  is not None:
                    raise Exception(
                        "Only one abilitylevels per ability. (%s) %s\n" %
                        (child.tag, str(child)))
                else:
                    self.load_ability_levels(child)

            elif tag == "abilitydescription":
                if self.description is not None:
                    raise Exception(
                        "Only one abilitydescription per ability. (%s) %s\n" %
                        (child.tag, str(child)))
                else:
                    self.description = children_to_string(child)

            elif tag == "abilityattrmodifiers":
                self._parse_attr_modifiers(child)

            elif tag == "keywords":
                self.keywords = self.parse_keywords(child)

            elif tag is COMMENT:
                # ignore comments!
                pass

            else:
                raise Exception("UNKNOWN (%s) in file %s\n" %
                                (child.tag, self.fname))

        # by default abilities are not inborn
        if self.inborn is None:
            self.inborn = False

        # sanity check.
        self.validate()
        return
コード例 #5
0
    def _load(self, monster_element):
        # handle all the children
        for child in list(monster_element):
            tag = child.tag
            if tag == "monstertitle":
                if self.title is not None:
                    raise Exception(
                        "Only one monstertitle per monster. (%s) %s\n" %
                        (child.tag, str(child)))
                else:
                    self.title = child.text

            elif tag == "monsterid":
                if self.monster_id is not None:
                    raise Exception(
                        "Only one monsterid per monster. (%s) %s\n" %
                        (child.tag, str(child)))
                else:
                    # check for duplicates!
                    monster_id = child.text
                    monster_location = self._get_location(child)
                    if monster_id in self._ids:
                        raise Exception(
                            "Monster id: %s appears in two places %s and %s" %
                            (monster_id, monster_location,
                             self._ids[monster_id]))
                    else:
                        self._ids[monster_id] = monster_location

                    # save the id!
                    self.monster_id = monster_id

            elif tag == "monstertag":
                self.tags.append(child.text)

            elif tag == "monstermove":
                self.move = convert_str_to_int(child.text)

            elif tag == "monsterhealth":
                self.health = convert_str_to_int(child.text)

            elif tag == "monsterstamina":
                self.stamina = convert_str_to_int(child.text)

            elif tag == "monsterresolve":
                self.resolve = child.text
                print "set resolve pool to [%s]" % self.resolve
                #sys.exit()

            elif tag == "monstermagic":
                self.magic_pool = child.text

            elif tag == "monsteraspect":
                self.aspects.append(child.text)

            elif tag == "monsterinitiativebonus":
                self.initiative_bonus = convert_str_to_int(child.text)

            elif tag == "ac":
                self.ac = convert_str_to_int(child.text)

            elif tag == "strength":
                if self.strength is not None:
                    raise Exception(
                        "Only one strength per monster. (%s) %s\n" %
                        (child.tag, str(child)))
                else:
                    self.strength = convert_str_to_int(child.text)

            elif tag == "endurance":
                if self.endurance is not None:
                    raise Exception(
                        "Only one endurance per monster. (%s) %s\n" %
                        (child.tag, str(child)))
                else:
                    self.endurance = convert_str_to_int(child.text)

            elif tag == "agility":
                if self.agility is not None:
                    raise Exception("Only one agility per monster. (%s) %s\n" %
                                    (child.tag, str(child)))
                else:
                    self.agility = convert_str_to_int(child.text)

            elif tag == "speed":
                if self.speed is not None:
                    raise Exception("Only one speed per monster. (%s) %s\n" %
                                    (child.tag, str(child)))
                else:
                    self.speed = convert_str_to_int(child.text)

            elif tag == "luck":
                if self.luck is not None:
                    raise Exception("Only one luck per monster. (%s) %s\n" %
                                    (child.tag, str(child)))
                else:
                    self.luck = convert_str_to_int(child.text)

            elif tag == "willpower":
                if self.willpower is not None:
                    raise Exception(
                        "Only one strength per monster. (%s) %s\n" %
                        (child.tag, str(child)))
                else:
                    self.willpower = convert_str_to_int(child.text)

            elif tag == "perception":
                if self.perception is not None:
                    raise Exception(
                        "Only one perception per monster. (%s) %s\n" %
                        (child.tag, str(child)))
                else:
                    self.perception = convert_str_to_int(child.text)

            elif tag == "abilitylevelid":
                ability_level_id = child.text
                self.ability_level_ids.append(ability_level_id)

            elif tag == "monsterclass":
                self.monster_class = MonsterClass.load(child.text)
                if self.monster_class == MonsterClass.NONE:
                    raise Exception("Unknown monster class: (%s) %s in %s\n" %
                                    (child.tag, child.text, self.fname))

            elif tag == "monsterdescription":
                if self.description is not None:
                    raise Exception(
                        "Only one monsterdescription per monster. (%s) %s\n" %
                        (child.tag, str(child)))
                else:
                    #self.description = get_text(child)
                    #self.description = node_to_string(child)
                    self.description = children_to_string(child)

            elif tag is COMMENT:
                # ignore comments!
                pass

            else:
                raise Exception("UNKNOWN (%s) in file %s\n" %
                                (child.tag, self.fname))
        self.validate()
        return