Search in sources :

Example 76 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class PreHPParser 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 {
        int minHitPoints = Integer.parseInt(formula);
        prereq.setOperator(PrerequisiteOperator.GTEQ);
        prereq.setOperand(Integer.toString(minHitPoints));
    } catch (NumberFormatException nfe) {
        throw new PersistenceLayerException("PREHP formula must be an integer '" + formula + "' is not valid.");
    }
    if (invertResult) {
        prereq.setOperator(prereq.getOperator().invert());
    }
    return prereq;
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 77 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException 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 78 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class PreFactParser 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);
    if (prereq.isCountMultiples()) {
        throw new PersistenceLayerException("PREFACT does not support CHECKMULT");
    }
    prereq.setOverrideQualify(overrideQualify);
    return prereq;
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 79 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class PreReachParser 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 {
    if (ControlUtilities.hasControlToken(Globals.getContext(), CControl.PCREACH)) {
        throw new PersistenceLayerException("PREREACH is disabled when CREATEUREREACH control is used");
    }
    Prerequisite prereq = super.parse(kind, formula, invertResult, overrideQualify);
    try {
        prereq.setKind("reach");
        // Get the comparator type SIZEGTEQ, BSIZE, SIZENEQ etc.
        String compType = kind.substring(5);
        if (compType.isEmpty()) {
            compType = "gteq";
        }
        prereq.setOperator(compType);
        prereq.setOperand(formula);
        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 : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) PrerequisiteException(pcgen.core.prereq.PrerequisiteException) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 80 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException 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)

Aggregations

PersistenceLayerException (pcgen.persistence.PersistenceLayerException)180 IOException (java.io.IOException)74 Prerequisite (pcgen.core.prereq.Prerequisite)62 StringWriter (java.io.StringWriter)17 StringTokenizer (java.util.StringTokenizer)17 ArrayList (java.util.ArrayList)16 Test (org.junit.Test)15 LoadContext (pcgen.rules.context.LoadContext)14 URI (java.net.URI)12 Campaign (pcgen.core.Campaign)11 ParseResult (pcgen.rules.persistence.token.ParseResult)11 PCClass (pcgen.core.PCClass)10 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)10 PrerequisiteWriterInterface (pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface)10 URISyntaxException (java.net.URISyntaxException)8 TreeSet (java.util.TreeSet)8 CDOMReference (pcgen.cdom.base.CDOMReference)8 PlayerCharacter (pcgen.core.PlayerCharacter)8 PrerequisiteException (pcgen.core.prereq.PrerequisiteException)8 PCClassLoader (pcgen.persistence.lst.PCClassLoader)8