Search in sources :

Example 6 with PreVariableParser

use of plugin.pretokens.parser.PreVariableParser in project pcgen by PCGen.

the class PCClassTest method testBypassClassPrereqsDeprecated.

/**
	 * Test the interaction of prerequisites on PCClasses and bonuses and the
	 * Bypass Class Prereqs flag.
	 * @throws Exception
	 */
public void testBypassClassPrereqsDeprecated() throws Exception {
    LoadContext context = Globals.getContext();
    // Setup class with prereqs and var based abilities with prereqs.
    final PreVariableParser parser = new PreVariableParser();
    final Prerequisite aPrereq = parser.parse("VARGTEQ", "Foo,1", false, false);
    final GameMode gameMode = SettingsHandler.getGame();
    RuleCheck aClassPreRule = gameMode.getModeContext().getReferenceContext().silentlyGetConstructedCDOMObject(RuleCheck.class, "CLASSPRE");
    if (aClassPreRule == null) {
        aClassPreRule = new RuleCheck();
        aClassPreRule.setName("CLASSPRE");
        gameMode.getModeContext().getReferenceContext().importObject(aClassPreRule);
    }
    aClassPreRule.setDefault(false);
    final PCClass aPrClass = new PCClass();
    aPrClass.setName("PreReqClass");
    aPrClass.put(StringKey.KEY_NAME, "KEY_PreReqClass");
    final BonusObj aBonus = Bonus.newBonus(context, "MISC|SR|10|PREVARGTEQ:Foo,2");
    if (aBonus != null) {
        aPrClass.addToListFor(ListKey.BONUS, aBonus);
    }
    aPrClass.addPrerequisite(aPrereq);
    final PCClass aQClass = new PCClass();
    aQClass.setName("QualClass");
    aQClass.put(StringKey.KEY_NAME, "KEY_QualClass");
    CDOMDirectSingleRef<PCClass> ref = CDOMDirectSingleRef.getRef(aPrClass);
    aQClass.addToListFor(ListKey.QUALIFY, new Qualifier(PCClass.class, ref));
    final PCClass aNqClass = new PCClass();
    aNqClass.setName("NonQualClass");
    aNqClass.put(StringKey.KEY_NAME, "KEY_NonQualClass");
    aNqClass.put(VariableKey.getConstant("Foo"), FormulaFactory.ONE);
    aNqClass.getOriginalClassLevel(2).put(VariableKey.getConstant("Foo"), FormulaFactory.getFormulaFor(2));
    // Setup character without prereqs
    final PlayerCharacter character = getCharacter();
    // Test no prereqs and no bypass fails class and var
    assertFalse("PC with no prereqs should fail class qual test.", aPrClass.qualifies(character, aPrClass));
    assertEquals("PC with no prereqs should fail var qual test.", 0.0, aPrClass.getBonusTo("MISC", "SR", 1, character), 0.1);
    // Test no prereqs and bypass passes class and fails var
    aClassPreRule.setDefault(true);
    assertTrue("PC with no prereqs should pass class qual test when bypassing prereqs is on.", aPrClass.qualifies(character, aPrClass));
    assertEquals("PC with no prereqs should fail var qual test when bypass prereqs is on.", 0.0, aPrClass.getBonusTo("MISC", "SR", 1, character), 0.1);
    // Test prereqs and bypass pass class and var
    character.incrementClassLevel(1, aNqClass);
    assertTrue("PC with prereqs and bypass should pass class qual test.", aPrClass.qualifies(character, aPrClass));
    character.incrementClassLevel(1, aNqClass);
    assertEquals("PC with prereqs and bypass should pass var qual test.", 10.0, aPrClass.getBonusTo("MISC", "SR", 1, character), 0.1);
    // Test prereqs and no bypass passes class and var
    aClassPreRule.setDefault(false);
    assertTrue("PC with prereqs and no bypass should pass class qual test.", aPrClass.qualifies(character, aPrClass));
    assertEquals("PC with prereqs and no bypass should pass var qual test.", 10.0, aPrClass.getBonusTo("MISC", "SR", 1, character), 0.1);
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) PreVariableParser(plugin.pretokens.parser.PreVariableParser) LoadContext(pcgen.rules.context.LoadContext) Qualifier(pcgen.cdom.reference.Qualifier) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 7 with PreVariableParser

use of plugin.pretokens.parser.PreVariableParser in project pcgen by PCGen.

the class GlobalSpellKnownTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    knownSpellFacet = FacetLibrary.getFacet(KnownSpellFacet.class);
    wizardSpellList = context.getReferenceContext().constructNowIfNecessary(ClassSpellList.class, "Wizard");
    fb = context.getReferenceContext().constructNowIfNecessary(Spell.class, "Fireball");
    TokenRegistration.register(new PreVariableParser());
    classSetUp();
}
Also used : ClassSpellList(pcgen.cdom.list.ClassSpellList) PreVariableParser(plugin.pretokens.parser.PreVariableParser) KnownSpellFacet(pcgen.cdom.facet.KnownSpellFacet) Spell(pcgen.core.spell.Spell)

Example 8 with PreVariableParser

use of plugin.pretokens.parser.PreVariableParser in project pcgen by PCGen.

the class WeildIntegrationTest method setUp.

@Override
public void setUp() throws PersistenceLayerException, URISyntaxException {
    super.setUp();
    TokenRegistration.register(new PreVariableParser());
    TokenRegistration.register(new PreVariableWriter());
    GameModeFileLoader.addDefaultWieldCategories(primaryContext);
    GameModeFileLoader.addDefaultWieldCategories(secondaryContext);
}
Also used : PreVariableWriter(plugin.pretokens.writer.PreVariableWriter) PreVariableParser(plugin.pretokens.parser.PreVariableParser)

Example 9 with PreVariableParser

use of plugin.pretokens.parser.PreVariableParser in project pcgen by PCGen.

the class PreVarTest method testMutiplePositive.

public void testMutiplePositive() throws Exception {
    final PlayerCharacter character = getCharacter();
    setPCStat(character, str, 10);
    setPCStat(character, dex, 14);
    character.calcActiveBonuses();
    PreVariableParser parser = new PreVariableParser();
    Prerequisite prereq = parser.parse("VAR", "abs(STR),1,abs(DEX),3", false, false);
    assertFalse("Test matches with no stats passing", PrereqHandler.passes(prereq, character, null));
    setPCStat(character, str, 12);
    character.calcActiveBonuses();
    assertFalse("Test matches with no stats passing", PrereqHandler.passes(prereq, character, null));
    setPCStat(character, dex, 16);
    character.calcActiveBonuses();
    assertTrue("Test should match now both stats pass", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreVariableParser(plugin.pretokens.parser.PreVariableParser)

Example 10 with PreVariableParser

use of plugin.pretokens.parser.PreVariableParser in project pcgen by PCGen.

the class PreVarTest method testVarPass.

/**
	 * @throws Exception
	 */
public void testVarPass() throws Exception {
    final PlayerCharacter character = getCharacter();
    PreVariableParser parser = new PreVariableParser();
    Prerequisite prereq = parser.parse("vareq", "1,count(\"ABILITIES\",\"CATEGORY=BARDIC\",\"NAME=Dancer\")", false, false);
    assertFalse("Test matches with no abilities.", PrereqHandler.passes(prereq, character, null));
    Ability ab2 = TestHelper.makeAbility("Dancer", "BARDIC", "General.Bardic");
    ab2.put(ObjectKey.MULTIPLE_ALLOWED, Boolean.FALSE);
    addAbility(TestHelper.getAbilityCategory(ab2), ab2);
    assertTrue("Test fails with ability present.", PrereqHandler.passes(prereq, character, null));
}
Also used : Ability(pcgen.core.Ability) SpecialAbility(pcgen.core.SpecialAbility) PlayerCharacter(pcgen.core.PlayerCharacter) PreVariableParser(plugin.pretokens.parser.PreVariableParser)

Aggregations

PreVariableParser (plugin.pretokens.parser.PreVariableParser)11 Qualifier (pcgen.cdom.reference.Qualifier)3 PlayerCharacter (pcgen.core.PlayerCharacter)3 BonusObj (pcgen.core.bonus.BonusObj)3 Prerequisite (pcgen.core.prereq.Prerequisite)3 LoadContext (pcgen.rules.context.LoadContext)3 PreVariableWriter (plugin.pretokens.writer.PreVariableWriter)3 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Test (org.junit.Test)1 UnreachableError (pcgen.base.lang.UnreachableError)1 LevelCommandFactory (pcgen.cdom.content.LevelCommandFactory)1 KnownSpellFacet (pcgen.cdom.facet.KnownSpellFacet)1 FixedSizeFormula (pcgen.cdom.formula.FixedSizeFormula)1 ClassSpellList (pcgen.cdom.list.ClassSpellList)1 Ability (pcgen.core.Ability)1 SpecialAbility (pcgen.core.SpecialAbility)1 Spell (pcgen.core.spell.Spell)1 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)1 PCClassLoader (pcgen.persistence.lst.PCClassLoader)1