Search in sources :

Example 1 with CDOMListObject

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

the class PCClass method inheritAttributesFrom.

/*
	 * REFACTOR Some derivative of this method will be in PCClass only as part
	 * of the factory creation of a PCClassLevel... or perhaps in PCClassLevel
	 * so it can steal some information from other PCClassLevels of that
	 * PCClass. Either way, this will be far from its current form in the final
	 * solution.
	 */
/*
	 * CONSIDER Why does this not inherit classSkillChoices?
	 */
public void inheritAttributesFrom(final PCClass otherClass) {
    Boolean hbss = otherClass.get(ObjectKey.HAS_BONUS_SPELL_STAT);
    if (hbss != null) {
        put(ObjectKey.HAS_BONUS_SPELL_STAT, hbss);
        CDOMSingleRef<PCStat> bss = otherClass.get(ObjectKey.BONUS_SPELL_STAT);
        if (bss != null) {
            put(ObjectKey.BONUS_SPELL_STAT, bss);
        }
    }
    Boolean usbs = otherClass.get(ObjectKey.USE_SPELL_SPELL_STAT);
    if (usbs != null) {
        put(ObjectKey.USE_SPELL_SPELL_STAT, usbs);
    }
    Boolean cwss = otherClass.get(ObjectKey.CASTER_WITHOUT_SPELL_STAT);
    if (cwss != null) {
        put(ObjectKey.CASTER_WITHOUT_SPELL_STAT, cwss);
    }
    CDOMSingleRef<PCStat> ss = otherClass.get(ObjectKey.SPELL_STAT);
    if (ss != null) {
        put(ObjectKey.SPELL_STAT, ss);
    }
    TransitionChoice<CDOMListObject<Spell>> slc = otherClass.get(ObjectKey.SPELLLIST_CHOICE);
    if (slc != null) {
        put(ObjectKey.SPELLLIST_CHOICE, slc);
    }
    List<QualifiedObject<CDOMReference<Equipment>>> e = otherClass.getListFor(ListKey.EQUIPMENT);
    if (e != null) {
        addAllToListFor(ListKey.EQUIPMENT, e);
    }
    List<WeaponProfProvider> wp = otherClass.getListFor(ListKey.WEAPONPROF);
    if (wp != null) {
        addAllToListFor(ListKey.WEAPONPROF, wp);
    }
    QualifiedObject<Boolean> otherWP = otherClass.get(ObjectKey.HAS_DEITY_WEAPONPROF);
    if (otherWP != null) {
        put(ObjectKey.HAS_DEITY_WEAPONPROF, otherWP);
    }
    List<ArmorProfProvider> ap = otherClass.getListFor(ListKey.AUTO_ARMORPROF);
    if (ap != null) {
        addAllToListFor(ListKey.AUTO_ARMORPROF, ap);
    }
    List<ShieldProfProvider> sp = otherClass.getListFor(ListKey.AUTO_SHIELDPROF);
    if (sp != null) {
        addAllToListFor(ListKey.AUTO_SHIELDPROF, sp);
    }
    List<BonusObj> bonusList = otherClass.getListFor(ListKey.BONUS);
    if (bonusList != null) {
        addAllToListFor(ListKey.BONUS, bonusList);
    }
    try {
        ownBonuses(this);
    } catch (CloneNotSupportedException ce) {
        // TODO Auto-generated catch block
        ce.printStackTrace();
    }
    for (VariableKey vk : otherClass.getVariableKeys()) {
        put(vk, otherClass.get(vk));
    }
    if (otherClass.containsListFor(ListKey.CSKILL)) {
        removeListFor(ListKey.CSKILL);
        addAllToListFor(ListKey.CSKILL, otherClass.getListFor(ListKey.CSKILL));
    }
    if (otherClass.containsListFor(ListKey.LOCALCCSKILL)) {
        removeListFor(ListKey.LOCALCCSKILL);
        addAllToListFor(ListKey.LOCALCCSKILL, otherClass.getListFor(ListKey.LOCALCCSKILL));
    }
    removeListFor(ListKey.KIT_CHOICE);
    addAllToListFor(ListKey.KIT_CHOICE, otherClass.getSafeListFor(ListKey.KIT_CHOICE));
    remove(ObjectKey.REGION_CHOICE);
    if (otherClass.containsKey(ObjectKey.REGION_CHOICE)) {
        put(ObjectKey.REGION_CHOICE, otherClass.get(ObjectKey.REGION_CHOICE));
    }
    removeListFor(ListKey.SAB);
    addAllToListFor(ListKey.SAB, otherClass.getSafeListFor(ListKey.SAB));
    /*
		 * TODO Does this need to have things from the Class Level objects?
		 * I don't think so based on deferred processing of levels...
		 */
    addAllToListFor(ListKey.DAMAGE_REDUCTION, otherClass.getListFor(ListKey.DAMAGE_REDUCTION));
    for (CDOMReference<Vision> ref : otherClass.getSafeListMods(Vision.VISIONLIST)) {
        for (AssociatedPrereqObject apo : otherClass.getListAssociations(Vision.VISIONLIST, ref)) {
            putToList(Vision.VISIONLIST, ref, apo);
        }
    }
    /*
		 * TODO This is a clone problem, but works for now - thpr 10/3/08
		 */
    if (otherClass instanceof SubClass) {
        levelMap.clear();
        copyLevelsFrom(otherClass);
    }
    addAllToListFor(ListKey.NATURAL_WEAPON, otherClass.getListFor(ListKey.NATURAL_WEAPON));
    put(ObjectKey.LEVEL_HITDIE, otherClass.get(ObjectKey.LEVEL_HITDIE));
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) CDOMListObject(pcgen.cdom.base.CDOMListObject) WeaponProfProvider(pcgen.cdom.helper.WeaponProfProvider) ArmorProfProvider(pcgen.cdom.helper.ArmorProfProvider) VariableKey(pcgen.cdom.enumeration.VariableKey) ShieldProfProvider(pcgen.cdom.helper.ShieldProfProvider) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 2 with CDOMListObject

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

the class SpellListTokenTest method testUnparseMultiple.

/*
	 * TODO Need to figure out who's responsibility this is!
	 */
// @Test
// public void testUnparseBadList() throws PersistenceLayerException
// {
// Language wp1 = construct(primaryContext, "TestWP1");
// ReferenceChoiceSet<Language> rcs = buildRCS(CDOMDirectSingleRef
// .getRef(wp1), primaryContext.ref
// .getCDOMAllReference(getTargetClass()));
// assertFalse(rcs.getGroupingState().isValid());
// PersistentTransitionChoice<Language> tc = buildTC(rcs);
// tc.setChoiceActor(subtoken);
// primaryProf.put(ObjectKey.CHOOSE_LANGAUTO, tc);
// assertBadUnparse();
// }
@Test
public void testUnparseMultiple() throws PersistenceLayerException {
    ClassSpellList wp1 = construct(primaryContext, "TestWP1");
    ClassSpellList wp2 = construct(primaryContext, "TestWP2");
    PersistentTransitionChoice<CDOMListObject<Spell>> tc = buildChoice(CDOMDirectSingleRef.getRef(wp1), CDOMDirectSingleRef.getRef(wp2));
    primaryProf.put(ObjectKey.SPELLLIST_CHOICE, tc);
    String[] unparsed = getToken().unparse(primaryContext, primaryProf);
    expectSingle(unparsed, "1|TestWP1|TestWP2");
}
Also used : ClassSpellList(pcgen.cdom.list.ClassSpellList) CDOMListObject(pcgen.cdom.base.CDOMListObject) Test(org.junit.Test)

Example 3 with CDOMListObject

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

the class SpelllistToken method unparse.

@Override
public String[] unparse(LoadContext context, PCClass pcc) {
    TransitionChoice<CDOMListObject<Spell>> grantChanges = context.getObjectContext().getObject(pcc, ObjectKey.SPELLLIST_CHOICE);
    if (grantChanges == null) {
        // Zero indicates no Token
        return null;
    }
    StringBuilder sb = new StringBuilder();
    Formula count = grantChanges.getCount();
    if (count == null) {
        context.addWriteMessage("Unable to find " + getTokenName() + " Count");
        return null;
    }
    sb.append(count);
    sb.append(Constants.PIPE);
    sb.append(grantChanges.getChoices().getLSTformat().replaceAll(Constants.COMMA, Constants.PIPE));
    return new String[] { sb.toString() };
}
Also used : Formula(pcgen.base.formula.Formula) CDOMListObject(pcgen.cdom.base.CDOMListObject)

Example 4 with CDOMListObject

use of pcgen.cdom.base.CDOMListObject 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 5 with CDOMListObject

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

the class SpellListTokenTest method testUnparseBadCount.

@Test
public void testUnparseBadCount() throws PersistenceLayerException {
    ClassSpellList wp1 = construct(primaryContext, "TestWP1");
    ReferenceChoiceSet<ClassSpellList> rcs = new ReferenceChoiceSet<>(Collections.singletonList(CDOMDirectSingleRef.getRef(wp1)));
    ChoiceSet<ClassSpellList> cs = new ChoiceSet<>(token.getTokenName(), rcs);
    cs.setTitle("Pick a ClassSpellList");
    PersistentTransitionChoice<CDOMListObject<Spell>> tc1 = new ConcretePersistentTransitionChoice<>(cs, null);
    primaryProf.put(ObjectKey.SPELLLIST_CHOICE, tc1);
    assertBadUnparse();
}
Also used : ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ClassSpellList(pcgen.cdom.list.ClassSpellList) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) CDOMListObject(pcgen.cdom.base.CDOMListObject) Test(org.junit.Test)

Aggregations

CDOMListObject (pcgen.cdom.base.CDOMListObject)8 Test (org.junit.Test)4 ClassSpellList (pcgen.cdom.list.ClassSpellList)4 Formula (pcgen.base.formula.Formula)2 ChoiceSet (pcgen.cdom.base.ChoiceSet)2 Spell (pcgen.core.spell.Spell)2 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)1 CDOMReference (pcgen.cdom.base.CDOMReference)1 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)1 ConcreteTransitionChoice (pcgen.cdom.base.ConcreteTransitionChoice)1 PrimitiveChoiceSet (pcgen.cdom.base.PrimitiveChoiceSet)1 ReferenceChoiceSet (pcgen.cdom.choiceset.ReferenceChoiceSet)1 SpellReferenceChoiceSet (pcgen.cdom.choiceset.SpellReferenceChoiceSet)1 VariableKey (pcgen.cdom.enumeration.VariableKey)1 ArmorProfProvider (pcgen.cdom.helper.ArmorProfProvider)1 ShieldProfProvider (pcgen.cdom.helper.ShieldProfProvider)1 WeaponProfProvider (pcgen.cdom.helper.WeaponProfProvider)1 PCClass (pcgen.core.PCClass)1