Search in sources :

Example 56 with LoadContext

use of pcgen.rules.context.LoadContext in project pcgen by PCGen.

the class PreBaseSizeParser method parse.

/**
	 * Parse the pre req list
	 *
	 * @param kind The kind of the prerequisite (less the "PRE" prefix)
	 * @param formula The body of the prerequisite.
	 * @param invertResult Whether the prerequisite should invert the result.
	 * @param overrideQualify
	 *           if set true, this prerequisite will be enforced in spite
	 *           of any "QUALIFY" tag that may be present.
	 * @return PreReq
	 * @throws PersistenceLayerException
	 */
@Override
public Prerequisite parse(String kind, String formula, boolean invertResult, boolean overrideQualify) throws PersistenceLayerException {
    Prerequisite prereq = super.parse(kind, formula, invertResult, overrideQualify);
    try {
        prereq.setKind("basesize");
        // Get the comparator type BASESIZEGTEQ, BASESIZE, BASESIZENEQ etc.
        String compType = kind.substring(8);
        if (compType.isEmpty()) {
            compType = "gteq";
        }
        prereq.setOperator(compType);
        String abb = formula.substring(0, 1);
        LoadContext context = Globals.getContext();
        CDOMSingleRef<SizeAdjustment> ref = context.getReferenceContext().getCDOMReference(SizeAdjustment.class, abb);
        context.forgetMeNot(ref);
        prereq.setOperand(abb);
        if (invertResult) {
            prereq.setOperator(prereq.getOperator().invert());
        }
    } catch (PrerequisiteException pe) {
        throw new PersistenceLayerException("Unable to parse the prerequisite :'" + kind + ':' + formula + "'. " + pe.getLocalizedMessage());
    }
    return prereq;
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) LoadContext(pcgen.rules.context.LoadContext) SizeAdjustment(pcgen.core.SizeAdjustment) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 57 with LoadContext

use of pcgen.rules.context.LoadContext in project pcgen by PCGen.

the class PreVarTest method test2857848c.

public void test2857848c() {
    final PCClass warrior = new PCClass();
    warrior.setName("Warrior");
    LoadContext context = Globals.getContext();
    context.unconditionallyProcess(warrior, "DEFINE", "MyVar|0");
    context.unconditionallyProcess(warrior, "BONUS", "VAR|MyVar|2");
    final PCClass notawarrior = new PCClass();
    notawarrior.setName("NotAWarrior");
    context.unconditionallyProcess(notawarrior, "PREVARGTEQ", "MyVar,1");
    Skill concentration = context.getReferenceContext().constructCDOMObject(Skill.class, "Concentration");
    context.unconditionallyProcess(notawarrior, "CSKILL", "Concentration");
    context.unconditionallyProcess(notawarrior, "BONUS", "SKILL|Concentration|5");
    assertTrue(context.getReferenceContext().resolveReferences(null));
    PCClassLoader loader = new PCClassLoader();
    try {
        SourceEntry se = new CampaignSourceEntry(new Campaign(), new URI("file://test"));
        loader.completeObject(context, se, warrior);
        loader.completeObject(context, se, notawarrior);
        PlayerCharacter character = this.getCharacter();
        assertFalse(notawarrior.qualifies(character, notawarrior));
        //Fails
        character.incrementClassLevel(1, notawarrior);
        assertEquals(0, SkillModifier.modifier(concentration, character).intValue());
        character.incrementClassLevel(1, warrior);
        assertEquals(0, SkillModifier.modifier(concentration, character).intValue());
        assertTrue(notawarrior.qualifies(character, notawarrior));
        character.incrementClassLevel(1, notawarrior);
        assertEquals(5, SkillModifier.modifier(concentration, character).intValue());
    } catch (URISyntaxException | PersistenceLayerException e) {
        fail(e.getMessage());
    }
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Skill(pcgen.core.Skill) Campaign(pcgen.core.Campaign) PlayerCharacter(pcgen.core.PlayerCharacter) LoadContext(pcgen.rules.context.LoadContext) PCClassLoader(pcgen.persistence.lst.PCClassLoader) SourceEntry(pcgen.persistence.lst.SourceEntry) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) URISyntaxException(java.net.URISyntaxException) PCClass(pcgen.core.PCClass) URI(java.net.URI)

Example 58 with LoadContext

use of pcgen.rules.context.LoadContext in project pcgen by PCGen.

the class PreVarTest method test2857849and2862276.

public void test2857849and2862276() {
    LoadContext context = Globals.getContext();
    final PCClass spellcaster = new PCClass();
    spellcaster.setName("Spellcaster");
    context.getReferenceContext().importObject(spellcaster);
    context.unconditionallyProcess(spellcaster, "SPELLTYPE", "Arcane");
    context.unconditionallyProcess(spellcaster, "SPELLSTAT", "INT");
    context.unconditionallyProcess(spellcaster, "PREVARGTEQ", "BASESPELLSTAT,2");
    PCClassLoader loader = new PCClassLoader();
    try {
        SourceEntry se = new CampaignSourceEntry(new Campaign(), new URI("file://test"));
        loader.completeObject(context, se, spellcaster);
        context.getReferenceContext().resolveReferences(null);
        PlayerCharacter character = this.getCharacter();
        setPCStat(character, intel, 16);
        assertTrue(spellcaster.qualifies(character, spellcaster));
    } catch (URISyntaxException | PersistenceLayerException e) {
        fail(e.getMessage());
    }
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Campaign(pcgen.core.Campaign) PlayerCharacter(pcgen.core.PlayerCharacter) LoadContext(pcgen.rules.context.LoadContext) PCClassLoader(pcgen.persistence.lst.PCClassLoader) SourceEntry(pcgen.persistence.lst.SourceEntry) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) URISyntaxException(java.net.URISyntaxException) PCClass(pcgen.core.PCClass) URI(java.net.URI)

Example 59 with LoadContext

use of pcgen.rules.context.LoadContext in project pcgen by PCGen.

the class PreVarTest method test2857849a.

public void test2857849a() {
    final PCClass warrior = new PCClass();
    warrior.setName("Warrior");
    LoadContext context = Globals.getContext();
    context.unconditionallyProcess(warrior, "DEFINE", "MyVar|0");
    context.unconditionallyProcess(warrior, "BONUS", "VAR|MyVar|2");
    PCClassLoader loader = new PCClassLoader();
    try {
        SourceEntry se = new CampaignSourceEntry(new Campaign(), new URI("file://test"));
        final PCClass notawarrior = loader.parseLine(context, null, "CLASS:NotAWarrior\tPREVARGTEQ:MyVar,1", se);
        loader.completeObject(context, se, warrior);
        loader.completeObject(context, se, notawarrior);
        PlayerCharacter character = this.getCharacter();
        assertFalse(notawarrior.qualifies(character, notawarrior));
        character.incrementClassLevel(1, warrior);
        assertTrue(notawarrior.qualifies(character, notawarrior));
    } catch (URISyntaxException | PersistenceLayerException e) {
        fail(e.getMessage());
    }
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Campaign(pcgen.core.Campaign) PlayerCharacter(pcgen.core.PlayerCharacter) LoadContext(pcgen.rules.context.LoadContext) PCClassLoader(pcgen.persistence.lst.PCClassLoader) SourceEntry(pcgen.persistence.lst.SourceEntry) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) URISyntaxException(java.net.URISyntaxException) PCClass(pcgen.core.PCClass) URI(java.net.URI)

Example 60 with LoadContext

use of pcgen.rules.context.LoadContext in project pcgen by PCGen.

the class PreWeaponProfTest method testOneOption.

/**
	 * Test with a simple weapon proficiency
	 * @throws Exception
	 */
public void testOneOption() throws Exception {
    final PlayerCharacter character = getCharacter();
    PCTemplate pct = new PCTemplate();
    LoadContext context = Globals.getContext();
    context.unconditionallyProcess(pct, "AUTO", "WEAPONPROF|Longsword|Dagger");
    assertTrue(context.getReferenceContext().resolveReferences(null));
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PREWEAPONPROF:1,Longsword");
    assertFalse("Character has no proficiencies", PrereqHandler.passes(prereq, character, null));
    character.addTemplate(pct);
    assertTrue("Character has the Longsword proficiency.", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREWEAPONPROF:1,Longbow");
    assertFalse("Character does not have the Longbow proficiency", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREWEAPONPROF:1,Dagger");
    assertTrue("Character has the Dagger proficiency.", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) LoadContext(pcgen.rules.context.LoadContext) PCTemplate(pcgen.core.PCTemplate)

Aggregations

LoadContext (pcgen.rules.context.LoadContext)141 PlayerCharacter (pcgen.core.PlayerCharacter)58 BonusObj (pcgen.core.bonus.BonusObj)48 PCClass (pcgen.core.PCClass)32 URI (java.net.URI)25 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)25 URISyntaxException (java.net.URISyntaxException)20 Campaign (pcgen.core.Campaign)16 Race (pcgen.core.Race)16 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)16 Equipment (pcgen.core.Equipment)15 UnreachableError (pcgen.base.lang.UnreachableError)14 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)14 PCClassLoader (pcgen.persistence.lst.PCClassLoader)14 Spell (pcgen.core.spell.Spell)13 Ability (pcgen.core.Ability)12 PCTemplate (pcgen.core.PCTemplate)12 SizeAdjustment (pcgen.core.SizeAdjustment)10 FixedSizeFormula (pcgen.cdom.formula.FixedSizeFormula)9 Skill (pcgen.core.Skill)9