Search in sources :

Example 6 with DamageReduction

use of pcgen.cdom.content.DamageReduction in project pcgen by PCGen.

the class DrLst method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
    if (obj instanceof Ungranted) {
        return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
    }
    if (Constants.LST_DOT_CLEAR.equals(value)) {
        context.getObjectContext().removeList(obj, ListKey.DAMAGE_REDUCTION);
        return ParseResult.SUCCESS;
    }
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    String drString = tok.nextToken();
    ParseResult pr = checkForIllegalSeparator('/', drString);
    if (!pr.passed()) {
        return pr;
    }
    String[] values = drString.split("/");
    if (values.length != 2) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage(getTokenName() + " failed to build DamageReduction with value " + value);
        cpr.addErrorMessage("  ...expected a String with one / as a separator");
        return cpr;
    }
    Formula formula = FormulaFactory.getFormulaFor(values[0]);
    if (!formula.isValid()) {
        return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + formula.toString(), context);
    }
    DamageReduction dr = new DamageReduction(formula, values[1]);
    if (tok.hasMoreTokens()) {
        String currentToken = tok.nextToken();
        Prerequisite prereq = getPrerequisite(currentToken);
        if (prereq == null) {
            return ParseResult.INTERNAL_ERROR;
        }
        dr.addPrerequisite(prereq);
    }
    context.getObjectContext().addToList(obj, ListKey.DAMAGE_REDUCTION, dr);
    return ParseResult.SUCCESS;
}
Also used : Formula(pcgen.base.formula.Formula) StringTokenizer(java.util.StringTokenizer) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) ParseResult(pcgen.rules.persistence.token.ParseResult) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) Ungranted(pcgen.cdom.base.Ungranted) DamageReduction(pcgen.cdom.content.DamageReduction) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 7 with DamageReduction

use of pcgen.cdom.content.DamageReduction in project pcgen by PCGen.

the class PObjectTest method testDR.

/**
	 * Test DR
	 * @throws Exception
	 */
public void testDR() throws Exception {
    Race race = new Race();
    LoadContext context = Globals.getContext();
    race.setName("Race");
    PCTemplate template = new PCTemplate();
    race.setName("Template");
    //		race.setDR("5/Good");
    race.addToListFor(ListKey.DAMAGE_REDUCTION, new DamageReduction(FormulaFactory.getFormulaFor(5), "Good"));
    assertEquals("Basic DR set.", "5/Good", race.getListFor(ListKey.DAMAGE_REDUCTION).get(0).toString());
    race.removeListFor(ListKey.DAMAGE_REDUCTION);
    //		race.setDR("0/-");
    race.addToListFor(ListKey.DAMAGE_REDUCTION, new DamageReduction(FormulaFactory.getFormulaFor(0), "-"));
    assertEquals("Basic DR set.", "0/-", race.getListFor(ListKey.DAMAGE_REDUCTION).get(0).toString());
    //		template.setDR("0/-");
    template.addToListFor(ListKey.DAMAGE_REDUCTION, new DamageReduction(FormulaFactory.getFormulaFor(0), "-"));
    final BonusObj aBonus = Bonus.newBonus(context, "DR|-|1");
    if (aBonus != null) {
        template.addToListFor(ListKey.BONUS, aBonus);
    }
    PlayerCharacter pc = getCharacter();
    pc.setRace(race);
    pc.addTemplate(template);
    pc.calcActiveBonuses();
    assertEquals("Basic DR set.", "1/-", pc.getDisplay().calcDR());
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext) DamageReduction(pcgen.cdom.content.DamageReduction)

Example 8 with DamageReduction

use of pcgen.cdom.content.DamageReduction in project pcgen by PCGen.

the class PreDRTest method testMultiAnd.

public void testMultiAnd() throws Exception {
    final PlayerCharacter character = getCharacter();
    character.setRace(race);
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PREDR:2,+1=10,+2=5");
    assertFalse("Character has no DR", PrereqHandler.passes(prereq, character, null));
    race.addToListFor(ListKey.DAMAGE_REDUCTION, drPlus1);
    character.setRace(race);
    assertFalse("Character DR not 10", PrereqHandler.passes(prereq, character, null));
    DamageReduction drPlus2_5 = new DamageReduction(FormulaFactory.getFormulaFor(5), "+2");
    race.addToListFor(ListKey.DAMAGE_REDUCTION, drPlus2_5);
    //This weirdness is because we are altering the race after application (no-no at runtime)
    character.setRace(null);
    character.setRace(race);
    assertFalse("Character has DR 5/+2", PrereqHandler.passes(prereq, character, null));
    DamageReduction drPlus1_10 = new DamageReduction(FormulaFactory.getFormulaFor(10), "+1");
    race.addToListFor(ListKey.DAMAGE_REDUCTION, drPlus1_10);
    //This weirdness is because we are altering the race after application (no-no at runtime)
    character.setRace(null);
    character.setRace(race);
    assertTrue("Character has DR 10/+1 and 5/+2", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) DamageReduction(pcgen.cdom.content.DamageReduction)

Example 9 with DamageReduction

use of pcgen.cdom.content.DamageReduction in project pcgen by PCGen.

the class PreDRTest method testDR.

/**
	 * Test basic functionality
	 * @throws Exception
	 */
public void testDR() throws Exception {
    final PlayerCharacter character = getCharacter();
    character.setRace(race);
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PREDR:1,+1=10");
    assertFalse("Character has no DR", PrereqHandler.passes(prereq, character, null));
    race.addToListFor(ListKey.DAMAGE_REDUCTION, drPlus1);
    //This weirdness is because we are altering the race after application (no-no at runtime)
    character.setRace(null);
    character.setRace(race);
    assertFalse("Character DR not 10", PrereqHandler.passes(prereq, character, null));
    DamageReduction drPlus1_10 = new DamageReduction(FormulaFactory.getFormulaFor(10), "+1");
    race.addToListFor(ListKey.DAMAGE_REDUCTION, drPlus1_10);
    //This weirdness is because we are altering the race after application (no-no at runtime)
    character.setRace(null);
    character.setRace(race);
    assertTrue("Character has DR 10/+1", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) DamageReduction(pcgen.cdom.content.DamageReduction)

Example 10 with DamageReduction

use of pcgen.cdom.content.DamageReduction in project pcgen by PCGen.

the class PreDRTest method testMultiOr.

/**
	 * Make sure or case works
	 * @throws Exception
	 */
public void testMultiOr() throws Exception {
    final PlayerCharacter character = getCharacter();
    character.setRace(race);
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PREDR:1,+1=10,+2=5");
    assertFalse("Character has no DR", PrereqHandler.passes(prereq, character, null));
    race.addToListFor(ListKey.DAMAGE_REDUCTION, drPlus1);
    //This weirdness is because we are altering the race after application (no-no at runtime)
    character.setRace(null);
    character.setRace(race);
    assertFalse("Character DR not 10", PrereqHandler.passes(prereq, character, null));
    DamageReduction drPlus2_5 = new DamageReduction(FormulaFactory.getFormulaFor(5), "+2");
    race.addToListFor(ListKey.DAMAGE_REDUCTION, drPlus2_5);
    //This weirdness is because we are altering the race after application (no-no at runtime)
    character.setRace(null);
    character.setRace(race);
    assertTrue("Character has DR 5/+2", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) DamageReduction(pcgen.cdom.content.DamageReduction)

Aggregations

DamageReduction (pcgen.cdom.content.DamageReduction)13 CDOMObject (pcgen.cdom.base.CDOMObject)4 Set (java.util.Set)3 PlayerCharacter (pcgen.core.PlayerCharacter)3 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 IdentityHashMap (java.util.IdentityHashMap)2 TreeSet (java.util.TreeSet)2 CharID (pcgen.cdom.enumeration.CharID)2 PCTemplate (pcgen.core.PCTemplate)2 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 Formula (pcgen.base.formula.Formula)1 CaseInsensitiveMap (pcgen.base.util.CaseInsensitiveMap)1 Ungranted (pcgen.cdom.base.Ungranted)1 PCStat (pcgen.core.PCStat)1 Race (pcgen.core.Race)1 BonusObj (pcgen.core.bonus.BonusObj)1 Prerequisite (pcgen.core.prereq.Prerequisite)1