private void setAdditionalModelTemplates(
     Element generalElement, GenericCharacterTemplate characterTemplate)
     throws PersistenceException {
   Element additionalElement = generalElement.element(TAG_ADDITIONAL_TEMPLATES);
   if (additionalElement == null) {
     return;
   }
   List<Element> templateElements = ElementUtilities.elements(additionalElement, TAG_TEMPLATE);
   for (Element templateElement : templateElements) {
     String id = ElementUtilities.getRequiredAttrib(templateElement, ATTRIB_ID);
     IAdditionalTemplate template =
         additionModelTemplateParserRegistry.get(id).parse(templateElement);
     characterTemplate.addAdditionalTemplate(template);
   }
 }
 private void parseSpecialTraitTemplates(
     List<GenericRestrictedTraitTemplate> pool, Element element) throws PersistenceException {
   for (Element specialTraitElement : ElementUtilities.elements(element, TAG_SPECIAL_TRAIT)) {
     GenericTraitTemplate specialTraitTemplate =
         GenericTraitTemplateParser.parseTraitTemplateSoft(specialTraitElement);
     String traitTypeId = ElementUtilities.getRequiredAttrib(specialTraitElement, "id");
     pool.add(
         new GenericRestrictedTraitTemplate(
             specialTraitTemplate,
             new CasteMinimumRestriction(
                 caste, specialTraitTemplate.getMinimumValue(null), isFreebie),
             type.getById(traitTypeId)));
     specialTraitTemplate.setMinimumValue(0);
   }
 }
 private void loadCaste(Element parent, HeroConcept heroConcept, ICasteCollection casteCollection)
     throws PersistenceException {
   Element casteElement = parent.element(TAG_CASTE);
   if (casteElement == null) {
     return;
   }
   String casteTypeId = ElementUtilities.getRequiredAttrib(casteElement, ATTRIB_TYPE);
   heroConcept.getCaste().setType(casteCollection.getById(casteTypeId));
 }
Esempio n. 4
0
 private void readMerges(Element charmListElement, ICharm[] charms) {
   Element mergesElement = charmListElement.element(TAG_MERGES);
   if (mergesElement == null) {
     return;
   }
   for (Element mergedElement : ElementUtilities.elements(mergesElement, TAG_MERGED)) {
     readMerged(mergedElement, charms);
   }
 }
 @Override
 public void load(Element parent, IAdditionalModel model) throws PersistenceException {
   Element collegesElement = parent.element(TAG_COLLEGES);
   SiderealCollegeModel collegeModel = (SiderealCollegeModel) model;
   for (Element collegeElement : ElementUtilities.elements(collegesElement)) {
     String collegeTypeId = collegeElement.getName();
     CollegeType collegeType = CollegeType.valueOf(collegeTypeId);
     traitPersister.restoreTrait(collegeElement, collegeModel.getCollege(collegeType));
   }
 }
  private void updateTemplateType(Element element, GenericCharacterTemplate characterTemplate)
      throws PersistenceException {
    ITemplateType templateType = new TemplateTypeParser().parse(element);
    characterTemplate.setTemplateType(templateType);

    boolean isLegacy = ElementUtilities.getBooleanAttribute(element, TAG_LEGACY, false);
    characterTemplate.setLegacy(isLegacy);

    ICasteCollection casteCollection = casteCollectionRegistry.get(templateType.getCharacterType());
    if (casteCollection != null) characterTemplate.setCasteCollection(casteCollection);
  }
Esempio n. 7
0
 protected void buildRestrictionList(ComboRestrictions comboRules, Element restrictionElement)
     throws CharmException {
   List<Element> restrictedCharmList = ElementUtilities.elements(restrictionElement, TAG_CHARM);
   for (Element element : restrictedCharmList) {
     String charmId = element.attributeValue(ATTRIB_ID);
     comboRules.addRestrictedCharmId(charmId);
   }
   List<Element> restrictedCharmTypeList =
       ElementUtilities.elements(restrictionElement, TAG_CHARMTYPE);
   for (Element element : restrictedCharmTypeList) {
     String charmType = element.attributeValue(ATTRIB_TYPE);
     comboRules.addRestrictedCharmType(CharmType.valueOf(charmType));
   }
   List<Element> restrictedTraitTypeList =
       ElementUtilities.elements(restrictionElement, TAG_TRAIT_REFERENCE);
   for (Element element : restrictedTraitTypeList) {
     String traitType = element.attributeValue(ATTRIB_ID);
     comboRules.addRestrictedTraitType(traitUtils.getTraitTypeById(traitType));
   }
 }
 private void parseAlternateMinimumTraitTemplates(
     List<GenericRestrictedTraitTemplate> pool, Element element) throws PersistenceException {
   AlternateMinimumTraitTemplateParser parser = new AlternateMinimumTraitTemplateParser(type);
   for (Element specialTraitElement :
       ElementUtilities.elements(element, TAG_ALTERNATE_MINMUM_TRAITS)) {
     for (GenericRestrictedTraitTemplate template :
         parser.parseAlternateMinimumTraitsSoft(specialTraitElement)) {
       pool.add(
           new GenericRestrictedTraitTemplate(
               template.getTemplate(),
               new CasteMinimumRestriction(caste, template.getRestrictions().get(0), isFreebie),
               template.getTraitType()));
     }
   }
 }
Esempio n. 9
0
 @Override
 public IComboRestrictions buildComboRules(Element rulesElement) throws CharmException {
   Element comboElement = rulesElement.element(TAG_COMBO);
   if (comboElement == null) {
     return new ComboRestrictions();
   }
   Boolean allAbilities =
       ElementUtilities.getBooleanAttribute(comboElement, ATTRIB_ALL_ABILITIES, false);
   String selectAbilities = comboElement.attributeValue(ATTRIB_SELECT_ABILITIES, "");
   ComboRestrictions comboRules = new ComboRestrictions(allAbilities, selectAbilities);
   Element restrictionElement = comboElement.element(TAG_RESTRICTIONS);
   if (restrictionElement != null) {
     buildRestrictionList(comboRules, restrictionElement);
   }
   return comboRules;
 }
  public GenericRestrictedTraitTemplate[] parseCasteMinimumTraits(
      Element element, List<AllocationMinimumRestriction> list) {
    GenericRestrictedTraitTemplate[] templates;
    List<GenericRestrictedTraitTemplate> limits = new ArrayList<>();
    try {
      caste = element.attributeValue(ATTRIB_CASTE);
      isFreebie = ElementUtilities.getBooleanAttribute(element, TAG_FREEBIE, false);
      parseSpecialTraitTemplates(limits, element);
      parseAllocationMinimumTraitTemplates(limits, element, list);
      parseAlternateMinimumTraitTemplates(limits, element);

      templates = new GenericRestrictedTraitTemplate[limits.size()];
      limits.toArray(templates);
    } catch (PersistenceException e) {
      return new GenericRestrictedTraitTemplate[0];
    }
    return templates;
  }
Esempio n. 11
0
 private void readMerged(Element mergedElement, ICharm[] existingCharms) {
   List<Element> charmReferences = ElementUtilities.elements(mergedElement, TAG_CHARM_REFERENCE);
   Set<ICharm> charms = new HashSet<ICharm>(charmReferences.size());
   for (Element charmReference : charmReferences) {
     final String charmId = charmReference.attributeValue(ATTRIB_ID);
     ICharm charm =
         ArrayUtilities.getFirst(
             existingCharms,
             new IPredicate<ICharm>() {
               @Override
               public boolean evaluate(ICharm candidate) {
                 return candidate.getId().equals(charmId);
               }
             });
     Ensure.ensureNotNull("Charm not found " + charmId, charm); // $NON-NLS-1$
     charms.add(charm);
   }
   for (ICharm charm : charms) {
     ((Charm) charm).addMerged(charms);
   }
 }
 private void loadAge(Element parent, HeroConcept heroConcept) throws PersistenceException {
   int age = ElementUtilities.getIntAttrib(parent, ATTRIB_AGE, 0);
   heroConcept.getAge().setValue(age);
 }