Search in sources :

Example 61 with CDOMReference

use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.

the class SpelllistToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass pcc, String value) {
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    Formula count = FormulaFactory.getFormulaFor(tok.nextToken());
    if (!count.isValid()) {
        return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
    }
    if (!count.isStatic() || count.resolveStatic().intValue() <= 0) {
        return new ParseResult.Fail("Count in " + getTokenName() + " must be > 0", context);
    }
    if (!tok.hasMoreTokens()) {
        return new ParseResult.Fail(getTokenName() + " must have a | separating " + "count from the list of possible values: " + value, context);
    }
    List<CDOMReference<? extends CDOMListObject<Spell>>> refs = new ArrayList<>();
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        CDOMReference<? extends CDOMListObject<Spell>> ref;
        if (Constants.LST_ALL.equals(token)) {
            ref = context.getReferenceContext().getCDOMAllReference(SPELLLIST_CLASS);
        } else if (token.startsWith("DOMAIN.")) {
            ref = context.getReferenceContext().getCDOMReference(DOMAINSPELLLIST_CLASS, token.substring(7));
        } else {
            ref = context.getReferenceContext().getCDOMReference(SPELLLIST_CLASS, token);
        }
        refs.add(ref);
    }
    PrimitiveChoiceSet<CDOMListObject<Spell>> rcs = new SpellReferenceChoiceSet(refs);
    if (!rcs.getGroupingState().isValid()) {
        return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
    }
    ChoiceSet<? extends CDOMListObject<Spell>> cs = new ChoiceSet<>(getTokenName(), rcs);
    cs.setTitle("Select class whose list of spells this class will use");
    TransitionChoice<CDOMListObject<Spell>> tc = new ConcreteTransitionChoice<>(cs, count);
    context.getObjectContext().put(pcc, ObjectKey.SPELLLIST_CHOICE, tc);
    tc.setRequired(false);
    return ParseResult.SUCCESS;
}
Also used : ConcreteTransitionChoice(pcgen.cdom.base.ConcreteTransitionChoice) SpellReferenceChoiceSet(pcgen.cdom.choiceset.SpellReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) PrimitiveChoiceSet(pcgen.cdom.base.PrimitiveChoiceSet) ArrayList(java.util.ArrayList) Spell(pcgen.core.spell.Spell) CDOMListObject(pcgen.cdom.base.CDOMListObject) Formula(pcgen.base.formula.Formula) StringTokenizer(java.util.StringTokenizer) CDOMReference(pcgen.cdom.base.CDOMReference) SpellReferenceChoiceSet(pcgen.cdom.choiceset.SpellReferenceChoiceSet)

Example 62 with CDOMReference

use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.

the class FavclassToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Race race, String value) {
    context.getObjectContext().remove(race, ObjectKey.ANY_FAVORED_CLASS);
    context.getObjectContext().removeList(race, ListKey.FAVORED_CLASS);
    context.getObjectContext().removeFromList(race, ListKey.NEW_CHOOSE_ACTOR, this);
    boolean foundAny = false;
    boolean foundOther = false;
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        if (Constants.HIGHEST_LEVEL_CLASS.equalsIgnoreCase(token)) {
            foundAny = true;
            context.getObjectContext().put(race, ObjectKey.ANY_FAVORED_CLASS, true);
        } else if (Constants.LST_PERCENT_LIST.equalsIgnoreCase(token)) {
            foundOther = true;
            context.getObjectContext().addToList(race, ListKey.NEW_CHOOSE_ACTOR, this);
        } else {
            CDOMReference<? extends PCClass> ref;
            foundOther = true;
            int dotLoc = token.indexOf('.');
            if (dotLoc == -1) {
                // Primitive
                ref = context.getReferenceContext().getCDOMReference(PCCLASS_CLASS, token);
            } else {
                ParseResult pr = checkForIllegalSeparator('.', value);
                if (!pr.passed()) {
                    return pr;
                }
                // SubClass
                String parent = token.substring(0, dotLoc);
                String subclass = token.substring(dotLoc + 1);
                SubClassCategory scc = SubClassCategory.getConstant(parent);
                ref = context.getReferenceContext().getCDOMReference(SUBCLASS_CLASS, scc, subclass);
            }
            context.getObjectContext().addToList(race, ListKey.FAVORED_CLASS, ref);
        }
    }
    if (foundAny && foundOther) {
        return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains " + Constants.HIGHEST_LEVEL_CLASS + " and a specific reference: " + value);
    }
    return ParseResult.SUCCESS;
}
Also used : SubClassCategory(pcgen.cdom.enumeration.SubClassCategory) StringTokenizer(java.util.StringTokenizer) ParseResult(pcgen.rules.persistence.token.ParseResult) PCClass(pcgen.core.PCClass) CDOMReference(pcgen.cdom.base.CDOMReference) CategorizedCDOMReference(pcgen.cdom.reference.CategorizedCDOMReference)

Example 63 with CDOMReference

use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.

the class PCClassTest method testAddAbility.

/**
	 * Test the definition and application of abilities. 
	 * @throws PersistenceLayerException 
	 */
public void testAddAbility() throws PersistenceLayerException {
    LoadContext context = Globals.getContext();
    // Create some abilities to be added
    AbilityCategory cat = context.getReferenceContext().constructCDOMObject(AbilityCategory.class, "TestCat");
    Ability ab1 = new Ability();
    ab1.setName("Ability1");
    ab1.setCDOMCategory(cat);
    context.getReferenceContext().importObject(ab1);
    Ability ab2 = new Ability();
    ab2.setName("Ability2");
    ab2.setCDOMCategory(cat);
    context.getReferenceContext().importObject(ab2);
    // Link them to a template
    CampaignSourceEntry source;
    try {
        source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
    } catch (URISyntaxException e) {
        throw new UnreachableError(e);
    }
    String classPCCText = "CLASS:Cleric	HD:8		CLASSTYPE:PC	TYPE:Base.PC	ABB:Clr	ABILITY:TestCat|AUTOMATIC|Ability1\n" + "CLASS:Cleric	STARTSKILLPTS:2\n" + "2	ABILITY:TestCat|AUTOMATIC|Ability2";
    PCClass pcclass = parsePCClassText(classPCCText, source);
    ab1.setCDOMCategory(cat);
    ab2.setCDOMCategory(cat);
    context.getReferenceContext().importObject(ab1);
    context.getReferenceContext().importObject(ab2);
    CDOMSingleRef<AbilityCategory> acRef = context.getReferenceContext().getCDOMReference(AbilityCategory.class, "TestCat");
    assertTrue(context.getReferenceContext().resolveReferences(null));
    CDOMReference<AbilityList> autoList = AbilityList.getAbilityListReference(acRef, Nature.AUTOMATIC);
    Collection<CDOMReference<Ability>> mods = pcclass.getListMods(autoList);
    assertEquals(1, mods.size());
    CDOMReference<Ability> ref = mods.iterator().next();
    Collection<Ability> abilities = ref.getContainedObjects();
    assertEquals(1, abilities.size());
    assertEquals(ab1, abilities.iterator().next());
    Collection<AssociatedPrereqObject> assocs = pcclass.getListAssociations(autoList, ref);
    assertEquals(1, assocs.size());
    PCClassLevel level = pcclass.getOriginalClassLevel(2);
    mods = level.getListMods(autoList);
    assertEquals(1, mods.size());
    ref = mods.iterator().next();
    abilities = ref.getContainedObjects();
    assertEquals(1, abilities.size());
    assertEquals(ab2, abilities.iterator().next());
    assocs = level.getListAssociations(autoList, ref);
    assertEquals(1, assocs.size());
    // Add the class to the character
    PlayerCharacter pc = getCharacter();
    pc.incrementClassLevel(1, pcclass, true);
    assertTrue("Character should have ability1.", hasAbility(pc, cat, Nature.AUTOMATIC, ab1));
    assertFalse("Character should not have ability2.", hasAbility(pc, cat, Nature.AUTOMATIC, ab2));
    pc.incrementClassLevel(1, pcclass, true);
    assertTrue("Character should have ability1.", hasAbility(pc, cat, Nature.AUTOMATIC, ab1));
    assertTrue("Character should have ability2.", hasAbility(pc, cat, Nature.AUTOMATIC, ab2));
}
Also used : AbilityList(pcgen.cdom.list.AbilityList) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) URI(java.net.URI) PCClassLevel(pcgen.cdom.inst.PCClassLevel) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) LoadContext(pcgen.rules.context.LoadContext) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 64 with CDOMReference

use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.

the class DeityWeaponToken method getCollection.

@Override
public <R> Collection<R> getCollection(PlayerCharacter pc, Converter<WeaponProf, R> c) {
    Deity deity = pc.getDisplay().getDeity();
    if (deity == null) {
        return Collections.emptySet();
    }
    HashSet<R> set = new HashSet<>();
    List<CDOMReference<WeaponProf>> dwp = deity.getSafeListFor(ListKey.DEITYWEAPON);
    for (CDOMReference<WeaponProf> ref : dwp) {
        set.addAll(c.convert(ref));
    }
    return set;
}
Also used : Deity(pcgen.core.Deity) WeaponProf(pcgen.core.WeaponProf) CDOMReference(pcgen.cdom.base.CDOMReference) HashSet(java.util.HashSet)

Example 65 with CDOMReference

use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.

the class DeityToken method getCollection.

@Override
public <R> Collection<R> getCollection(PlayerCharacter pc, Converter<Domain, R> c) {
    HashSet<R> returnSet = new HashSet<>();
    Deity deity = pc.getDisplay().getDeity();
    if (deity == null) {
        return returnSet;
    }
    CDOMReference<DomainList> list = Deity.DOMAINLIST;
    Collection<CDOMReference<Domain>> mods = deity.getListMods(list);
    for (CDOMReference<Domain> ref : mods) {
        Collection<AssociatedPrereqObject> assoc = deity.getListAssociations(list, ref);
        for (AssociatedPrereqObject apo : assoc) {
            if (PrereqHandler.passesAll(apo.getPrerequisiteList(), pc, deity)) {
                returnSet.addAll(c.convert(ref));
                break;
            }
        }
    }
    return returnSet;
}
Also used : Deity(pcgen.core.Deity) DomainList(pcgen.cdom.list.DomainList) Domain(pcgen.core.Domain) CDOMReference(pcgen.cdom.base.CDOMReference) HashSet(java.util.HashSet) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Aggregations

CDOMReference (pcgen.cdom.base.CDOMReference)125 ArrayList (java.util.ArrayList)57 StringTokenizer (java.util.StringTokenizer)40 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)35 ParseResult (pcgen.rules.persistence.token.ParseResult)30 Skill (pcgen.core.Skill)24 ChoiceSet (pcgen.cdom.base.ChoiceSet)22 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)21 ReferenceChoiceSet (pcgen.cdom.choiceset.ReferenceChoiceSet)19 Prerequisite (pcgen.core.prereq.Prerequisite)18 Formula (pcgen.base.formula.Formula)16 CDOMObject (pcgen.cdom.base.CDOMObject)15 Spell (pcgen.core.spell.Spell)15 TreeSet (java.util.TreeSet)14 Test (org.junit.Test)14 ClassSkillChoiceActor (pcgen.cdom.helper.ClassSkillChoiceActor)12 CharID (pcgen.cdom.enumeration.CharID)11 ObjectMatchingReference (pcgen.cdom.reference.ObjectMatchingReference)11 ParsingSeparator (pcgen.base.text.ParsingSeparator)10 CDOMList (pcgen.cdom.base.CDOMList)10