Search in sources :

Example 6 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class TemplateFeatFacet method dataRemoved.

/**
	 * Removes all of the feats granted by FEAT: on the PCTemplate removed
	 * 
	 * Triggered when one of the Facets to which ConditionalTemplateFacet
	 * listens fires a DataFacetChangeEvent to indicate a PCTemplate was removed
	 * from a Player Character.
	 * 
	 * @param dfce
	 *            The DataFacetChangeEvent containing the information about the
	 *            change
	 * 
	 * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataRemoved(pcgen.cdom.facet.event.DataFacetChangeEvent)
	 */
@Override
public void dataRemoved(DataFacetChangeEvent<CharID, PCTemplate> dfce) {
    CharID id = dfce.getCharID();
    PCTemplate source = dfce.getCDOMObject();
    PersistentTransitionChoice<CNAbilitySelection> choice = source.get(ObjectKey.TEMPLATE_FEAT);
    if (choice != null) {
        PlayerCharacter pc = trackingFacet.getPC(id);
        choice.remove(source, pc);
    }
    removeAll(id, source);
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) PCTemplate(pcgen.core.PCTemplate) CharID(pcgen.cdom.enumeration.CharID)

Example 7 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class TemplateFeatFacet method dataAdded.

/**
	 * Adds all of the feats to the Player Character triggered by the FEAT token'
	 * on the given PCTemplate
	 * 
	 * Triggered when one of the Facets to which ConditionalTemplateFacet
	 * listens fires a DataFacetChangeEvent to indicate a PCTemplate was added
	 * to a Player Character.
	 * 
	 * @param dfce
	 *            The DataFacetChangeEvent containing the information about the
	 *            change
	 * 
	 * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
	 */
@Override
public void dataAdded(DataFacetChangeEvent<CharID, PCTemplate> dfce) {
    CharID id = dfce.getCharID();
    PCTemplate source = dfce.getCDOMObject();
    if (!containsFrom(id, source)) {
        PersistentTransitionChoice<CNAbilitySelection> choice = source.get(ObjectKey.TEMPLATE_FEAT);
        if (choice != null) {
            PlayerCharacter pc = trackingFacet.getPC(id);
            Collection<? extends CNAbilitySelection> result = choice.driveChoice(pc);
            choice.act(result, source, pc);
            for (CNAbilitySelection cas : result) {
                add(id, cas, source);
            }
        }
    }
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) PCTemplate(pcgen.core.PCTemplate) CharID(pcgen.cdom.enumeration.CharID)

Example 8 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class PCGVer2Creator method appendAbilityLines.

/*
	 * ###############################################################
	 * Character Ability methods
	 * ###############################################################
	 */
private void appendAbilityLines(StringBuilder buffer) {
    ArrayList<AbilityCategory> categories = new ArrayList<>(getGameMode().getAllAbilityCategories());
    categories.add(AbilityCategory.LANGBONUS);
    Collection<CNAbilitySelection> virtSave = thePC.getSaveAbilities();
    categories.sort(new Comparator<AbilityCategory>() {

        @Override
        public int compare(AbilityCategory a, AbilityCategory b) {
            return a.getKeyName().compareTo(b.getKeyName());
        }
    });
    for (final AbilityCategory cat : categories) {
        final List<CNAbility> normalAbilitiesToSave = new ArrayList<>(thePC.getPoolAbilities(cat, Nature.NORMAL));
        // ABILITY:FEAT|NORMAL|Feat Key|APPLIEDTO:xxx|TYPE:xxx|SAVE:xxx|DESC:xxx
        Collections.sort(normalAbilitiesToSave);
        for (final CNAbility ability : normalAbilitiesToSave) {
            writeAbilityToBuffer(buffer, ability);
        }
        boolean hasVirt = false;
        for (final CNAbilitySelection ability : virtSave) {
            CNAbility cnAbility = ability.getCNAbility();
            if (cnAbility.getAbilityCategory().equals(cat)) {
                //TODO Need to write each CNAbility only once :/
                writeAbilityToBuffer(buffer, cnAbility);
                hasVirt = true;
            }
        }
        if (!normalAbilitiesToSave.isEmpty() || hasVirt || thePC.getUserPoolBonus(cat) != 0.0) {
            buffer.append(IOConstants.TAG_USERPOOL).append(IOConstants.TAG_END);
            buffer.append(EntityEncoder.encode(cat.getKeyName())).append(IOConstants.TAG_SEPARATOR);
            buffer.append(IOConstants.TAG_POOLPOINTS).append(IOConstants.TAG_END);
            buffer.append(thePC.getUserPoolBonus(cat));
            buffer.append(IOConstants.LINE_SEP);
        }
    }
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) ArrayList(java.util.ArrayList) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) AbilityCategory(pcgen.core.AbilityCategory)

Example 9 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class PCGVer2Creator method writeTemplateFeat.

private void writeTemplateFeat(StringBuilder aString, PCTemplate pct, List<? extends CNAbilitySelection> featList) {
    for (CNAbilitySelection s : featList) {
        if (aString.length() != 0) {
            aString.append('|');
        }
        String featKey = Compatibility.getKeyFor(pct);
        aString.append(IOConstants.TAG_CHOSENFEAT).append(':');
        aString.append('[');
        aString.append(IOConstants.TAG_MAPKEY).append(':').append(EntityEncoder.encode(featKey)).append('|');
        aString.append(IOConstants.TAG_MAPVALUE).append(':').append(EntityEncoder.encode(s.getPersistentFormat()));
        aString.append(']');
    }
}
Also used : CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection)

Example 10 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class PCGVer2Parser method parseTemplateLine.

/*
	 * ###############################################################
	 * Character Templates methods
	 * ###############################################################
	 */
private void parseTemplateLine(final String line) throws PCGParseException {
    if (line.charAt(IOConstants.TAG_TEMPLATESAPPLIED.length() + 1) == '[') {
        final PCGTokenizer tokens;
        try {
            tokens = new PCGTokenizer(line);
        } catch (PCGParseException pcgpex) {
            final String message = "Illegal Template line ignored: " + line + Constants.LINE_SEPARATOR + "Error: " + pcgpex.getMessage();
            warnings.add(message);
            return;
        }
        PCTemplate aPCTemplate = null;
        Iterator<PCGElement> it = tokens.getElements().iterator();
        if (it.hasNext()) {
            final PCGElement element = it.next();
            String assoc = null;
            //Must deal with APPLIEDTO first (before item is added to the PC)
            for (final PCGElement child : element.getChildren()) {
                String childTag = child.getName();
                if (IOConstants.TAG_NAME.equals(childTag)) {
                    aPCTemplate = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, EntityEncoder.decode(child.getText()));
                    if (aPCTemplate == null) {
                        break;
                    }
                } else if (IOConstants.TAG_APPLIEDTO.equals(childTag)) {
                    assoc = child.getText();
                }
            }
            for (final PCGElement child : element.getChildren()) {
                final String childTag = child.getName();
                if (IOConstants.TAG_NAME.equals(childTag)) {
                    if (aPCTemplate == null) {
                        break;
                    }
                    addKeyedTemplate(aPCTemplate, assoc);
                } else if (IOConstants.TAG_CHOSENFEAT.equals(childTag)) {
                    String mapKey = null;
                    String mapValue = null;
                    for (PCGElement subChild : child.getChildren()) {
                        final String subChildTag = subChild.getName();
                        if (IOConstants.TAG_MAPKEY.equals(subChildTag)) {
                            mapKey = subChild.getText();
                        } else if (IOConstants.TAG_MAPVALUE.equals(subChildTag)) {
                            mapValue = subChild.getText();
                        }
                    }
                    if ((mapKey != null) && (mapValue != null)) {
                        String feat = EntityEncoder.decode(mapValue);
                        PCTemplate subt = Compatibility.getTemplateFor(aPCTemplate, EntityEncoder.decode(mapKey), feat);
                        if (subt != null) {
                            CNAbilitySelection as = CNAbilitySelection.getAbilitySelectionFromPersistentFormat(feat);
                            thePC.addTemplateFeat(subt, as);
                        }
                    }
                } else if (IOConstants.TAG_CHOSENTEMPLATE.equals(childTag)) {
                    for (PCGElement subChild : child.getChildren()) {
                        final String subChildTag = subChild.getName();
                        if (IOConstants.TAG_NAME.equals(subChildTag)) {
                            final String ownedTemplateKey = EntityEncoder.decode(subChild.getText());
                            final PCTemplate ownedTemplate = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, ownedTemplateKey);
                            if (ownedTemplate != null) {
                                thePC.setTemplatesAdded(aPCTemplate, ownedTemplate);
                            }
                        }
                    }
                } else //Add handled below, AppliedTo handled in the first loop
                if (!IOConstants.TAG_ADDTOKEN.equals(childTag) && !IOConstants.TAG_APPLIEDTO.equals(childTag)) {
                    final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
                    "Warnings.PCGenParser.UnknownTemplateInfo", childTag + ":" + child.getText());
                    warnings.add(msg);
                }
            }
        }
        //Must process ADD after Template is added to the PC
        for (PCGElement e : new PCGTokenizer(line).getElements()) {
            String tag = e.getName();
            if (tag.equals(IOConstants.TAG_ADDTOKEN)) {
                parseAddTokenInfo(e, aPCTemplate);
            }
        }
    } else {
        String key = EntityEncoder.decode(line.substring(IOConstants.TAG_TEMPLATESAPPLIED.length() + 1));
        PCTemplate aPCTemplate = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, key);
        addKeyedTemplate(aPCTemplate, null);
    }
}
Also used : CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) PCTemplate(pcgen.core.PCTemplate)

Aggregations

CNAbilitySelection (pcgen.cdom.helper.CNAbilitySelection)70 CNAbility (pcgen.cdom.content.CNAbility)35 Test (org.junit.Test)28 Ability (pcgen.core.Ability)26 ArrayList (java.util.ArrayList)17 AbilityCategory (pcgen.core.AbilityCategory)7 CDOMReference (pcgen.cdom.base.CDOMReference)6 PlayerCharacter (pcgen.core.PlayerCharacter)6 ParseResult (pcgen.rules.persistence.token.ParseResult)6 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)5 AbilityRefChoiceSet (pcgen.cdom.choiceset.AbilityRefChoiceSet)5 Nature (pcgen.cdom.enumeration.Nature)5 PCTemplate (pcgen.core.PCTemplate)5 CharID (pcgen.cdom.enumeration.CharID)4 List (java.util.List)3 AbilityChoiceSet (pcgen.cdom.base.ChoiceSet.AbilityChoiceSet)3 SpecialAbility (pcgen.core.SpecialAbility)3 BonusObj (pcgen.core.bonus.BonusObj)3 AbstractTokenModelTest (tokenmodel.testsupport.AbstractTokenModelTest)3 HashSet (java.util.HashSet)2