Search in sources :

Example 66 with Spell

use of pcgen.core.spell.Spell in project pcgen by PCGen.

the class KnownspellsToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass pcc, String value) {
    StringTokenizer pipeTok = new StringTokenizer(value, Constants.PIPE);
    boolean firstToken = true;
    while (pipeTok.hasMoreTokens()) {
        String totalFilter = pipeTok.nextToken();
        if (Constants.LST_DOT_CLEAR_ALL.equals(totalFilter)) {
            if (!firstToken) {
                return new ParseResult.Fail("Non-sensical situation was " + "encountered while parsing " + getTokenName() + ": When used, .CLEARALL must be the first argument", context);
            }
            context.getObjectContext().removeList(pcc, ListKey.KNOWN_SPELLS);
            continue;
        }
        ParseResult pr = checkForIllegalSeparator(',', totalFilter);
        if (!pr.passed()) {
            return pr;
        }
        StringTokenizer commaTok = new StringTokenizer(totalFilter, Constants.COMMA);
        /*
			 * This is a rather interesting situation - this takes items that
			 * are ALLOWED and converts them to GRANTS. Therefore, this must be
			 * done as a post-manufacturing run on the Graph.
			 * 
			 * As there is no guarantee when the factory is added that the list
			 * is complete, this resolution of known MUST be performed as a
			 * query against the PC, not stored in the graph as Grants edges.
			 */
        // must satisfy all elements in a comma delimited list
        Integer levelLim = null;
        CDOMReference<Spell> sp = null;
        while (commaTok.hasMoreTokens()) {
            String filterString = commaTok.nextToken();
            if (filterString.startsWith("LEVEL=")) {
                if (levelLim != null) {
                    return new ParseResult.Fail("Cannot have more than one Level limit in " + getTokenName() + ": " + value, context);
                }
                // the desired spellLevel
                try {
                    levelLim = Integer.valueOf(filterString.substring(6));
                    if (levelLim < 0) {
                        ComplexParseResult cpr = new ComplexParseResult();
                        cpr.addErrorMessage("Invalid Number in " + getTokenName() + ": " + value);
                        cpr.addErrorMessage("  Level must be >= 0");
                        return cpr;
                    }
                } catch (NumberFormatException e) {
                    ComplexParseResult cpr = new ComplexParseResult();
                    cpr.addErrorMessage("Invalid Number in " + getTokenName() + ": " + value);
                    cpr.addErrorMessage("  Level must be " + "a non-negative integer");
                    return cpr;
                }
            } else {
                if (sp != null) {
                    return new ParseResult.Fail("Cannot have more than one Type/Spell limit in " + getTokenName() + ": " + value, context);
                }
                sp = TokenUtilities.getTypeOrPrimitive(context, SPELL_CLASS, filterString);
                if (sp == null) {
                    return new ParseResult.Fail("  encountered Invalid limit in " + getTokenName() + ": " + value, context);
                }
            }
            firstToken = false;
        }
        if (sp == null) {
            /*
				 * There is no need to check for an invalid construction here
				 * (meaning levelLim is null as well) as that was implicitly
				 * checked by ensuring || did not occur.
				 */
            sp = context.getReferenceContext().getCDOMAllReference(SPELL_CLASS);
        }
        KnownSpellIdentifier ksi = new KnownSpellIdentifier(sp, levelLim);
        context.getObjectContext().addToList(pcc, ListKey.KNOWN_SPELLS, ksi);
    }
    return ParseResult.SUCCESS;
}
Also used : StringTokenizer(java.util.StringTokenizer) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) ParseResult(pcgen.rules.persistence.token.ParseResult) KnownSpellIdentifier(pcgen.cdom.content.KnownSpellIdentifier) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) Spell(pcgen.core.spell.Spell)

Example 67 with Spell

use of pcgen.core.spell.Spell in project pcgen by PCGen.

the class PreSpellDescriptorTest method additionalSetUp.

/*
	 * (non-Javadoc)
	 * 
	 * @see junit.framework.TestCase#setUp()
	 */
@Override
protected void additionalSetUp() throws Exception {
    LoadContext context = Globals.getContext();
    wiz = context.getReferenceContext().constructCDOMObject(PCClass.class, "Wizard");
    BuildUtilities.setFact(wiz, "SpellType", "Arcane");
    context.unconditionallyProcess(wiz, "KNOWNSPELLS", "LEVEL=1|LEVEL=2");
    context.unconditionallyProcess(wiz.getOriginalClassLevel(1), "CAST", "1,1");
    context.unconditionallyProcess(wiz.getOriginalClassLevel(2), "CAST", "2,2,1");
    cle = context.getReferenceContext().constructCDOMObject(PCClass.class, "Cleric");
    BuildUtilities.setFact(cle, "SpellType", "Divine");
    context.unconditionallyProcess(cle, "KNOWNSPELLS", "LEVEL=1|LEVEL=2");
    context.unconditionallyProcess(cle.getOriginalClassLevel(1), "CAST", "1,1");
    context.unconditionallyProcess(cle.getOriginalClassLevel(2), "CAST", "1,1,1");
    fireball = new Spell();
    fireball.setName("Fireball");
    context.getReferenceContext().importObject(fireball);
    context.unconditionallyProcess(fireball, "CLASSES", "Wizard=2");
    context.unconditionallyProcess(fireball, "DESCRIPTOR", "Fire");
    lightning = new Spell();
    lightning.setName("Lightning Bolt");
    context.getReferenceContext().importObject(lightning);
    context.unconditionallyProcess(lightning, "CLASSES", "Wizard=2");
    context.unconditionallyProcess(lightning, "DESCRIPTOR", "Useful");
    burning = new Spell();
    burning.setName("Burning Hands");
    context.getReferenceContext().importObject(burning);
    context.unconditionallyProcess(burning, "CLASSES", "Wizard=1");
    context.unconditionallyProcess(burning, "DESCRIPTOR", "Fire");
    heal = new Spell();
    heal.setName("Heal");
    context.getReferenceContext().importObject(heal);
    context.unconditionallyProcess(heal, "CLASSES", "Cleric=2");
    context.unconditionallyProcess(heal, "DESCRIPTOR", "Useful");
    cure = new Spell();
    cure.setName("Cure Light Wounds");
    context.getReferenceContext().importObject(cure);
    context.unconditionallyProcess(cure, "CLASSES", "Cleric=1");
    context.unconditionallyProcess(cure, "DESCRIPTOR", "Useful");
}
Also used : LoadContext(pcgen.rules.context.LoadContext) PCClass(pcgen.core.PCClass) Spell(pcgen.core.spell.Spell)

Example 68 with Spell

use of pcgen.core.spell.Spell in project pcgen by PCGen.

the class PreSpellSchoolTest method additionalSetUp.

/*
	 * (non-Javadoc)
	 * 
	 * @see junit.framework.TestCase#setUp()
	 */
@Override
protected void additionalSetUp() throws Exception {
    LoadContext context = Globals.getContext();
    wiz = context.getReferenceContext().constructCDOMObject(PCClass.class, "Wizard");
    BuildUtilities.setFact(wiz, "SpellType", "Arcane");
    context.unconditionallyProcess(wiz, "KNOWNSPELLS", "LEVEL=1|LEVEL=2");
    context.unconditionallyProcess(wiz.getOriginalClassLevel(1), "CAST", "1,1");
    context.unconditionallyProcess(wiz.getOriginalClassLevel(2), "CAST", "2,2,1");
    cle = context.getReferenceContext().constructCDOMObject(PCClass.class, "Cleric");
    BuildUtilities.setFact(cle, "SpellType", "Divine");
    context.unconditionallyProcess(cle, "KNOWNSPELLS", "LEVEL=1|LEVEL=2");
    context.unconditionallyProcess(cle.getOriginalClassLevel(1), "CAST", "1,1");
    context.unconditionallyProcess(cle.getOriginalClassLevel(2), "CAST", "1,1,1");
    fireball = new Spell();
    fireball.setName("Fireball");
    context.getReferenceContext().importObject(fireball);
    context.unconditionallyProcess(fireball, "CLASSES", "Wizard=2");
    context.unconditionallyProcess(fireball, "SCHOOL", "Fire");
    lightning = new Spell();
    lightning.setName("Lightning Bolt");
    context.getReferenceContext().importObject(lightning);
    context.unconditionallyProcess(lightning, "CLASSES", "Wizard=2");
    context.unconditionallyProcess(lightning, "SCHOOL", "Useful");
    burning = new Spell();
    burning.setName("Burning Hands");
    context.getReferenceContext().importObject(burning);
    context.unconditionallyProcess(burning, "CLASSES", "Wizard=1");
    context.unconditionallyProcess(burning, "SCHOOL", "Fire");
    heal = new Spell();
    heal.setName("Heal");
    context.getReferenceContext().importObject(heal);
    context.unconditionallyProcess(heal, "CLASSES", "Cleric=2");
    context.unconditionallyProcess(heal, "SCHOOL", "Useful");
    cure = new Spell();
    cure.setName("Cure Light Wounds");
    context.getReferenceContext().importObject(cure);
    context.unconditionallyProcess(cure, "CLASSES", "Cleric=1");
    context.unconditionallyProcess(cure, "SCHOOL", "Useful");
}
Also used : LoadContext(pcgen.rules.context.LoadContext) PCClass(pcgen.core.PCClass) Spell(pcgen.core.spell.Spell)

Example 69 with Spell

use of pcgen.core.spell.Spell in project pcgen by PCGen.

the class PreSpellSubSchoolTest method additionalSetUp.

/*
	 * (non-Javadoc)
	 * 
	 * @see junit.framework.TestCase#setUp()
	 */
@Override
protected void additionalSetUp() throws Exception {
    LoadContext context = Globals.getContext();
    wiz = context.getReferenceContext().constructCDOMObject(PCClass.class, "Wizard");
    BuildUtilities.setFact(wiz, "SpellType", "Arcane");
    context.unconditionallyProcess(wiz, "KNOWNSPELLS", "LEVEL=1|LEVEL=2");
    context.unconditionallyProcess(wiz.getOriginalClassLevel(1), "CAST", "1,1");
    context.unconditionallyProcess(wiz.getOriginalClassLevel(2), "CAST", "2,2,1");
    cle = context.getReferenceContext().constructCDOMObject(PCClass.class, "Cleric");
    BuildUtilities.setFact(cle, "SpellType", "Divine");
    context.unconditionallyProcess(cle, "KNOWNSPELLS", "LEVEL=1|LEVEL=2");
    context.unconditionallyProcess(cle.getOriginalClassLevel(1), "CAST", "1,1");
    context.unconditionallyProcess(cle.getOriginalClassLevel(2), "CAST", "1,1,1");
    fireball = new Spell();
    fireball.setName("Fireball");
    context.getReferenceContext().importObject(fireball);
    context.unconditionallyProcess(fireball, "CLASSES", "Wizard=2");
    context.unconditionallyProcess(fireball, "SUBSCHOOL", "Fire");
    lightning = new Spell();
    lightning.setName("Lightning Bolt");
    context.getReferenceContext().importObject(lightning);
    context.unconditionallyProcess(lightning, "CLASSES", "Wizard=2");
    context.unconditionallyProcess(lightning, "SUBSCHOOL", "Useful");
    burning = new Spell();
    burning.setName("Burning Hands");
    context.getReferenceContext().importObject(burning);
    context.unconditionallyProcess(burning, "CLASSES", "Wizard=1");
    context.unconditionallyProcess(burning, "SUBSCHOOL", "Fire");
    heal = new Spell();
    heal.setName("Heal");
    context.getReferenceContext().importObject(heal);
    context.unconditionallyProcess(heal, "CLASSES", "Cleric=2");
    context.unconditionallyProcess(heal, "SUBSCHOOL", "Useful");
    cure = new Spell();
    cure.setName("Cure Light Wounds");
    context.getReferenceContext().importObject(cure);
    context.unconditionallyProcess(cure, "CLASSES", "Cleric=1");
    context.unconditionallyProcess(cure, "SUBSCHOOL", "Useful");
}
Also used : LoadContext(pcgen.rules.context.LoadContext) PCClass(pcgen.core.PCClass) Spell(pcgen.core.spell.Spell)

Example 70 with Spell

use of pcgen.core.spell.Spell in project pcgen by PCGen.

the class SpellsTokenTest method testRoundRobinType.

@Test
public void testRoundRobinType() throws PersistenceLayerException {
    Spell a = primaryContext.getReferenceContext().constructCDOMObject(Spell.class, "Fireball");
    a.addToListFor(ListKey.TYPE, Type.getConstant("Foo"));
    Spell b = secondaryContext.getReferenceContext().constructCDOMObject(Spell.class, "Fireball");
    b.addToListFor(ListKey.TYPE, Type.getConstant("Foo"));
    runRoundRobin("TYPE.Foo=2");
}
Also used : Spell(pcgen.core.spell.Spell) Test(org.junit.Test)

Aggregations

Spell (pcgen.core.spell.Spell)87 CharacterSpell (pcgen.core.character.CharacterSpell)35 ArrayList (java.util.ArrayList)25 PCClass (pcgen.core.PCClass)24 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)16 CDOMReference (pcgen.cdom.base.CDOMReference)15 Ability (pcgen.core.Ability)15 LoadContext (pcgen.rules.context.LoadContext)13 CDOMList (pcgen.cdom.base.CDOMList)12 CDOMObject (pcgen.cdom.base.CDOMObject)11 Test (org.junit.Test)10 KnownSpellIdentifier (pcgen.cdom.content.KnownSpellIdentifier)9 AvailableSpell (pcgen.cdom.helper.AvailableSpell)8 StringTokenizer (java.util.StringTokenizer)7 CNAbility (pcgen.cdom.content.CNAbility)7 ClassSpellList (pcgen.cdom.list.ClassSpellList)7 DomainSpellList (pcgen.cdom.list.DomainSpellList)7 Formula (pcgen.base.formula.Formula)6 Domain (pcgen.core.Domain)6 PObject (pcgen.core.PObject)6