Search in sources :

Example 36 with CDOMSingleRef

use of pcgen.cdom.reference.CDOMSingleRef 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 37 with CDOMSingleRef

use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.

the class CompanionMod method getLevelApplied.

public int getLevelApplied(PCClass cl) {
    int result = -1;
    Map<CDOMSingleRef<? extends PCClass>, Integer> ac = getMapFor(MapKey.APPLIED_CLASS);
    if (ac != null) {
        for (Map.Entry<CDOMSingleRef<? extends PCClass>, Integer> me : ac.entrySet()) {
            PCClass pcclass = me.getKey().get();
            if (pcclass.getKeyName().equalsIgnoreCase(cl.getKeyName())) {
                result = me.getValue();
            }
        }
    }
    return result;
}
Also used : PCClass(pcgen.core.PCClass) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) Map(java.util.Map)

Example 38 with CDOMSingleRef

use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.

the class DomainApplication method removeDomainsForLevel.

public static void removeDomainsForLevel(PCClass cl, final int removedLevel, final PlayerCharacter aPC) {
    /*
		 * Note this uses ALL of the domains up to and including this level,
		 * because there is the possibility (albeit strange) that the PC was
		 * qualified at a previous level change, but the PlayerCharacter is now
		 * not qualified for the given Domain. Even this has quirks, since it is
		 * only applied at the time of level increase, but I think that quirk
		 * should be resolved by a CDOM system around 6.0 - thpr 10/23/06
		 */
    for (QualifiedObject<CDOMSingleRef<Domain>> qo : cl.getSafeListFor(ListKey.DOMAIN)) {
        CDOMSingleRef<Domain> ref = qo.getObject(aPC, cl);
        if (ref == null) {
            ref = qo.getRawObject();
            aPC.removeDomain(ref.get());
        }
    }
    for (int i = 0; i <= removedLevel; i++) {
        // TODO This stinks for really high level characters - can this ever
        // get null back?
        PCClassLevel pcl = aPC.getActiveClassLevel(cl, i);
        for (QualifiedObject<CDOMSingleRef<Domain>> qo : pcl.getSafeListFor(ListKey.DOMAIN)) {
            CDOMSingleRef<Domain> ref = qo.getObject(aPC, cl);
            if ((ref == null) || (i == removedLevel)) {
                ref = qo.getRawObject();
                aPC.removeDomain(ref.get());
            }
        }
    }
}
Also used : Domain(pcgen.core.Domain) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Aggregations

CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)38 ArrayList (java.util.ArrayList)13 Ability (pcgen.core.Ability)10 Domain (pcgen.core.Domain)10 Prerequisite (pcgen.core.prereq.Prerequisite)10 StringTokenizer (java.util.StringTokenizer)9 QualifiedObject (pcgen.core.QualifiedObject)9 PCStat (pcgen.core.PCStat)6 List (java.util.List)4 Map (java.util.Map)4 TreeSet (java.util.TreeSet)4 CDOMObject (pcgen.cdom.base.CDOMObject)4 CDOMReference (pcgen.cdom.base.CDOMReference)4 KnownSpellIdentifier (pcgen.cdom.content.KnownSpellIdentifier)4 CharID (pcgen.cdom.enumeration.CharID)4 AbilityCategory (pcgen.core.AbilityCategory)4 PCClass (pcgen.core.PCClass)4 ParseResult (pcgen.rules.persistence.token.ParseResult)4 HashMap (java.util.HashMap)3 Formula (pcgen.base.formula.Formula)3