Search in sources :

Example 6 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class Aspect method printAspect.

public static String printAspect(PlayerCharacter pc, AspectName key, List<CNAbility> abilities, boolean printName) {
    if (abilities.isEmpty()) {
        return "";
    }
    Ability sampleAbilityObject = abilities.get(0).getAbility();
    StringBuilder buff = new StringBuilder(50);
    List<Aspect> aspects = sampleAbilityObject.get(MapKey.ASPECT, key);
    Aspect aspect = lastPassingAspect(aspects, pc, sampleAbilityObject);
    if (aspect != null) {
        if (printName) {
            buff.append(aspect.getName()).append(": ");
        }
        buff.append(aspect.getAspectText(pc, abilities));
    }
    return buff.toString();
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility)

Example 7 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class CNAbilitySelectionUtilities method canCoExist.

public static boolean canCoExist(CNAbilitySelection cnas1, CNAbilitySelection cnas2) {
    CNAbility cna = cnas1.getCNAbility();
    Ability a = cna.getAbility();
    CNAbility ocna = cnas2.getCNAbility();
    if (!ocna.getAbilityCategory().getParentCategory().equals(cna.getAbilityCategory().getParentCategory())) {
        //This test is only required because Ability only checks key :/
        return true;
    }
    if (!ocna.getAbility().equals(a)) {
        //Different abilities, so doesn't matter...
        return true;
    }
    //Same ability here
    if (!a.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
        //If MULT:NO, then can't coexist...
        return false;
    }
    //MULT:YES here
    if (a.getSafe(ObjectKey.STACKS)) {
        //Allows stacking, so always true (give or take NUMCHOICES?)
        return true;
    }
    //STACK:NO here
    if (cnas1.getSelection().equals(cnas2.getSelection())) {
        //enforce STACK:NO
        return false;
    }
    return true;
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility)

Example 8 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class GrantedAbilityFacet method getPoolAbilities.

public Collection<CNAbility> getPoolAbilities(CharID id, Category<Ability> cat) {
    List<List<SourcedCNAS>> list = getList(id);
    List<CNAbility> returnList = new ArrayList<>();
    if (list != null) {
        for (List<SourcedCNAS> array : list) {
            CNAbility cna = array.get(0).cnas.getCNAbility();
            if (cna.getAbilityCategory().equals(cat)) {
                returnList.add(cna);
            }
        }
    }
    return returnList;
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class PCGVer2Parser method parseVFeatLine.

private void parseVFeatLine(final String line) {
    final PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String message = "Illegal VFeat line ignored: " + line + Constants.LINE_SEPARATOR + "Error: " + pcgpex.getMessage();
        warnings.add(message);
        return;
    }
    final Iterator<PCGElement> it = tokens.getElements().iterator();
    // the first element defines the Feat key name
    if (it.hasNext()) {
        final PCGElement element = it.next();
        final String abilityKey = EntityEncoder.decode(element.getText());
        Ability anAbility = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, AbilityCategory.FEAT, abilityKey);
        if (anAbility == null) {
            final String message = "Could not add vfeat: " + abilityKey;
            warnings.add(message);
            return;
        }
        CNAbility cna = CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.VIRTUAL, anAbility);
        parseFeatsHandleAppliedToAndSaveTags(it, cna);
        thePC.setDirty(true);
    }
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) SpecialAbility(pcgen.core.SpecialAbility) CNAbility(pcgen.cdom.content.CNAbility)

Example 10 with CNAbility

use of pcgen.cdom.content.CNAbility 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)

Aggregations

CNAbility (pcgen.cdom.content.CNAbility)131 Ability (pcgen.core.Ability)77 ArrayList (java.util.ArrayList)37 CNAbilitySelection (pcgen.cdom.helper.CNAbilitySelection)28 AbilityCategory (pcgen.core.AbilityCategory)26 Test (org.junit.Test)21 HashMapToList (pcgen.base.util.HashMapToList)16 List (java.util.List)15 PlayerCharacter (pcgen.core.PlayerCharacter)9 Language (pcgen.core.Language)7 HashSet (java.util.HashSet)5 Nature (pcgen.cdom.enumeration.Nature)5 SpecialAbility (pcgen.core.SpecialAbility)5 BonusObj (pcgen.core.bonus.BonusObj)5 BigDecimal (java.math.BigDecimal)4 CDOMObject (pcgen.cdom.base.CDOMObject)4 LoadContext (pcgen.rules.context.LoadContext)4 StringTokenizer (java.util.StringTokenizer)3 GenericMapToList (pcgen.base.util.GenericMapToList)3 PCClass (pcgen.core.PCClass)3