Search in sources :

Example 66 with CNAbilitySelection

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

the class AbilityFromClassChoiceSet method getSet.

/**
	 * Returns a Set containing the Objects which this AbilityFromClassChoiceSet
	 * contains.
	 * 
	 * This method is value-semantic, meaning that ownership of the Set returned
	 * by this method will be transferred to the calling object. Modification of
	 * the returned Set will not modify the AbilityFromClassChoiceSet, and
	 * modifying the AbilityFromClassChoiceSet after the Set is returned will
	 * not modify the Set.
	 * 
	 * @param pc
	 *            The PlayerCharacter for which the choices in this
	 *            AbilityFromClassChoiceSet should be returned.
	 * @return A Set containing the Objects which this AbilityFromClassChoiceSet
	 *         contains.
	 */
@Override
public Set<CNAbilitySelection> getSet(PlayerCharacter pc) {
    PCClass aClass = pc.getClassKeyed(classRef.get().getKeyName());
    Set<CNAbilitySelection> set = new HashSet<>();
    if (aClass != null) {
        //TODO This is a bug -> it was not properly gathering before
        List<Ability> abilityList = Collections.emptyList();
        if (abilityList != null) {
            for (Ability aFeat : abilityList) {
                set.add(new CNAbilitySelection(CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.VIRTUAL, aFeat)));
            }
        }
        for (int lvl = 0; lvl < pc.getLevel(aClass); lvl++) {
            PCClassLevel pcl = pc.getActiveClassLevel(aClass, lvl);
            //TODO This is a bug -> it was not properly gathering before
            abilityList = Collections.emptyList();
            if (abilityList != null) {
                for (Ability aFeat : abilityList) {
                    set.add(new CNAbilitySelection(CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.VIRTUAL, aFeat)));
                }
            }
        }
    }
    return null;
}
Also used : Ability(pcgen.core.Ability) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) PCClass(pcgen.core.PCClass) HashSet(java.util.HashSet) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 67 with CNAbilitySelection

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

the class AbilityRefChoiceSet method addMultiplySelectableAbility.

private Collection<CNAbilitySelection> addMultiplySelectableAbility(final PlayerCharacter aPC, Ability ability, String subName) {
    boolean isPattern = false;
    String nameRoot = null;
    if (subName != null) {
        final int percIdx = subName.indexOf('%');
        if (percIdx > -1) {
            isPattern = true;
            nameRoot = subName.substring(0, percIdx);
        } else if (!subName.isEmpty()) {
            nameRoot = subName;
        }
    }
    ChooseInformation<?> chooseInfo = ability.get(ObjectKey.CHOOSE_INFO);
    final List<String> availableList = getAvailableList(aPC, chooseInfo);
    /*
		 * TODO Need a general solution for this special assignment in parens
		 */
    if ("DEITYWEAPON".equals(nameRoot) && (chooseInfo != null) && chooseInfo.getClassIdentity().getChoiceClass().equals(WeaponProf.class)) {
        Deity deity = aPC.getDeity();
        if (deity == null) {
            availableList.clear();
        } else {
            List<CDOMReference<WeaponProf>> dwp = deity.getSafeListFor(ListKey.DEITYWEAPON);
            Set<String> set = new HashSet<>();
            for (CDOMReference<WeaponProf> ref : dwp) {
                for (WeaponProf wp : ref.getContainedObjects()) {
                    set.add(wp.getKeyName());
                }
            }
            availableList.retainAll(set);
        }
    } else if (nameRoot != null && !nameRoot.isEmpty()) {
        for (int n = availableList.size() - 1; n >= 0; --n) {
            final String aString = availableList.get(n);
            if (!aString.startsWith(nameRoot)) {
                availableList.remove(n);
            }
        }
        if (isPattern && !availableList.isEmpty()) {
            availableList.add(nameRoot);
        }
    }
    List<CNAbilitySelection> returnList = new ArrayList<>(availableList.size());
    for (String s : availableList) {
        returnList.add(new CNAbilitySelection(CNAbilityFactory.getCNAbility(category.get(), nature, ability), s));
    }
    return returnList;
}
Also used : Deity(pcgen.core.Deity) ArrayList(java.util.ArrayList) WeaponProf(pcgen.core.WeaponProf) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) CDOMReference(pcgen.cdom.base.CDOMReference) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 68 with CNAbilitySelection

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

the class ConditionallyGrantedAbilityFacet method update.

/**
	 * Performs a global update of conditionally granted Abilities for a Player
	 * Character.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character for which a global
	 *            update of conditionally granted Abilities should be performed.
	 */
public void update(CharID id) {
    depth++;
    Collection<CNAbilitySelection> current = getSet(id);
    Collection<CNAbilitySelection> qualified = conditionalAbilityFacet.getQualifiedSet(id);
    List<CNAbilitySelection> toRemove = new ArrayList<>(current);
    toRemove.removeAll(qualified);
    List<CNAbilitySelection> toAdd = new ArrayList<>(qualified);
    toAdd.removeAll(current);
    if (!toAdd.isEmpty() || !toRemove.isEmpty()) {
        if (Logging.isDebugMode()) {
            Logging.debugPrint("CGAF at depth " + depth + " removing " + toRemove + " adding " + toAdd);
        }
    }
    for (CNAbilitySelection cas : toRemove) {
        // Things could have changed, so we make sure
        if (!conditionalAbilityFacet.isQualified(id, cas) && contains(id, cas)) {
            if (Logging.isDebugMode()) {
                Logging.debugPrint("CGAF at depth " + depth + " removing " + cas);
            }
            remove(id, cas);
        }
    }
    for (CNAbilitySelection cas : toAdd) {
        // Things could have changed, so we make sure
        if (conditionalAbilityFacet.isQualified(id, cas) && !contains(id, cas)) {
            if (Logging.isDebugMode()) {
                Logging.debugPrint("CGAF at depth " + depth + " adding " + cas);
            }
            add(id, cas);
        }
    }
    if (!toAdd.isEmpty() || !toRemove.isEmpty()) {
        if (Logging.isDebugMode()) {
            Logging.debugPrint("CGAF at depth " + depth + " completed.");
        }
    }
    depth--;
}
Also used : CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) ArrayList(java.util.ArrayList)

Example 69 with CNAbilitySelection

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

the class RemoveFeatToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    AbilityCategory category = AbilityCategory.FEAT;
    Nature nature = Nature.NORMAL;
    ParsingSeparator sep = new ParsingSeparator(value, '|');
    sep.addGroupingPair('[', ']');
    sep.addGroupingPair('(', ')');
    String activeValue = sep.next();
    Formula count;
    if (!sep.hasNext()) {
        count = FormulaFactory.ONE;
    } else {
        count = FormulaFactory.getFormulaFor(activeValue);
        if (!count.isValid()) {
            return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
        }
        if (!count.isValid()) {
            return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
        }
        if (count.isStatic() && count.resolveStatic().doubleValue() <= 0) {
            return new ParseResult.Fail("Count in " + getFullName() + " must be > 0", context);
        }
        activeValue = sep.next();
    }
    if (sep.hasNext()) {
        return new ParseResult.Fail(getFullName() + " had too many pipe separated items: " + value, context);
    }
    if (isEmpty(activeValue) || hasIllegalSeparator(',', activeValue)) {
        return ParseResult.INTERNAL_ERROR;
    }
    List<CDOMReference<Ability>> refs = new ArrayList<>();
    List<PrimitiveChoiceSet<CNAbilitySelection>> pcs = new ArrayList<>();
    ParsingSeparator tok = new ParsingSeparator(activeValue, ',');
    tok.addGroupingPair('[', ']');
    tok.addGroupingPair('(', ')');
    boolean foundAny = false;
    boolean foundOther = false;
    ReferenceManufacturer<Ability> rm = context.getReferenceContext().getManufacturer(ABILITY_CLASS, AbilityCategory.FEAT);
    while (tok.hasNext()) {
        CDOMReference<Ability> ab = null;
        String token = tok.next();
        if ("CHOICE".equals(token) || Constants.LST_ANY.equals(token)) {
            foundAny = true;
            ab = rm.getAllReference();
        } else if (token.startsWith(Constants.LST_CLASS_DOT) || token.startsWith(Constants.LST_CLASS_EQUAL)) {
            String className = token.substring(6);
            if (className.isEmpty()) {
                return new ParseResult.Fail(getTokenName() + " must have Class name after " + token, context);
            }
            CDOMSingleRef<PCClass> pcc = context.getReferenceContext().getCDOMReference(PCCLASS_CLASS, className);
            AbilityFromClassChoiceSet acs = new AbilityFromClassChoiceSet(pcc);
            pcs.add(acs);
        } else {
            foundOther = true;
            ab = TokenUtilities.getTypeOrPrimitive(rm, token);
            if (ab == null) {
                return new ParseResult.Fail("  Error was encountered while parsing " + getTokenName() + ": " + value + " had an invalid reference: " + token, context);
            }
        }
        if (ab != null) {
            refs.add(ab);
        }
    }
    if (foundAny && foundOther) {
        return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value, context);
    }
    if (!refs.isEmpty()) {
        AbilityRefChoiceSet rcs = new AbilityRefChoiceSet(CDOMDirectSingleRef.getRef(category), refs, nature);
        pcs.add(rcs);
    }
    if (pcs.isEmpty()) {
        return new ParseResult.Fail("Internal Error: " + getFullName() + " did not have any references: " + value, context);
    }
    PrimitiveChoiceSet<CNAbilitySelection> ascs;
    if (pcs.size() == 1) {
        ascs = pcs.get(0);
    } else {
        ascs = new CompoundOrChoiceSet<>(pcs, Constants.COMMA);
    }
    ChoiceSet<CNAbilitySelection> cs = new ChoiceSet<>(getTokenName(), ascs, true);
    cs.setTitle("Select for removal");
    PersistentTransitionChoice<CNAbilitySelection> tc = new ConcretePersistentTransitionChoice<>(cs, count);
    context.getObjectContext().addToList(obj, ListKey.REMOVE, tc);
    tc.allowStack(true);
    tc.setChoiceActor(this);
    return ParseResult.SUCCESS;
}
Also used : ArrayList(java.util.ArrayList) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) Formula(pcgen.base.formula.Formula) AbilityFromClassChoiceSet(pcgen.cdom.choiceset.AbilityFromClassChoiceSet) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) Nature(pcgen.cdom.enumeration.Nature) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) PrimitiveChoiceSet(pcgen.cdom.base.PrimitiveChoiceSet) ParseResult(pcgen.rules.persistence.token.ParseResult) AbilityRefChoiceSet(pcgen.cdom.choiceset.AbilityRefChoiceSet) AbilityFromClassChoiceSet(pcgen.cdom.choiceset.AbilityFromClassChoiceSet) CompoundOrChoiceSet(pcgen.cdom.choiceset.CompoundOrChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) PrimitiveChoiceSet(pcgen.cdom.base.PrimitiveChoiceSet) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) ParsingSeparator(pcgen.base.text.ParsingSeparator) AbilityCategory(pcgen.core.AbilityCategory) CDOMReference(pcgen.cdom.base.CDOMReference) AbilityRefChoiceSet(pcgen.cdom.choiceset.AbilityRefChoiceSet)

Example 70 with CNAbilitySelection

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

the class TemplateFeatToken method process.

@Override
public boolean process(LoadContext context, PCTemplate pct) {
    List<CDOMReference<Ability>> list = pct.getListFor(ListKey.FEAT_TOKEN_LIST);
    if (list != null && !list.isEmpty()) {
        AbilityRefChoiceSet rcs = new AbilityRefChoiceSet(CDOMDirectSingleRef.getRef(AbilityCategory.FEAT), list, Nature.NORMAL);
        ChoiceSet<CNAbilitySelection> cs = new ChoiceSet<>(getTokenName(), rcs);
        cs.setTitle("Feat Choice");
        PersistentTransitionChoice<CNAbilitySelection> tc = new ConcretePersistentTransitionChoice<>(cs, FormulaFactory.ONE);
        context.getObjectContext().put(pct, ObjectKey.TEMPLATE_FEAT, tc);
        tc.setChoiceActor(this);
    }
    return true;
}
Also used : AbilityRefChoiceSet(pcgen.cdom.choiceset.AbilityRefChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) CDOMReference(pcgen.cdom.base.CDOMReference) AbilityRefChoiceSet(pcgen.cdom.choiceset.AbilityRefChoiceSet) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice)

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