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;
}
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());
}
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));
}
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));
}
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));
}
Aggregations