use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class PCToken method parseTokenWithSeparator.
@Override
public ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
final String v = value.replaceAll(Pattern.quote("<this>"), obj.getKeyName());
BonusObj bon = Bonus.newBonus(context, v);
if (bon == null) {
return new ParseResult.Fail(getFullTokenName() + " was given invalid type: " + value, context);
}
bon.setTokenSource(getFullTokenName());
context.getObjectContext().addToList(obj, ListKey.BONUS_PC, bon);
return ParseResult.SUCCESS;
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class PCToken method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
Changes<BonusObj> changes = context.getObjectContext().getListChanges(obj, ListKey.BONUS_PC);
Collection<BonusObj> added = changes.getAdded();
if (added == null || added.isEmpty()) {
// Zero indicates no Token (and no global clear, so nothing to do)
return null;
}
Set<String> bonusSet = new TreeSet<>();
for (BonusObj bonus : added) {
bonusSet.add(bonus.getLSTformat());
}
return bonusSet.toArray(new String[bonusSet.size()]);
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class PreCheckBaseTest method testBonus.
public void testBonus() throws Exception {
final PlayerCharacter character = getCharacter();
LoadContext context = Globals.getContext();
final BonusObj fortBonus = Bonus.newBonus(context, "SAVE|Fortitude|1");
myClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, fortBonus);
character.incrementClassLevel(1, myClass, true);
character.calcActiveBonuses();
Prerequisite prereq;
final PreParserFactory factory = PreParserFactory.getInstance();
prereq = factory.parse("PRECHECKBASE:1,Fortitude=1");
assertFalse("Character's base Fort save should be 0", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECHECKBASE:1,Will=2");
assertTrue("Character's Will save should be 2", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECHECKBASE:1,Fortitude=1,Will=3");
assertFalse("Character's Will save should be 2", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECHECKBASE:2,Fortitude=1,Will=2");
assertFalse("Character's base Fort save not 1", PrereqHandler.passes(prereq, character, null));
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class PreClassTest method testSpellcasterLevelsTwoClasses.
public void testSpellcasterLevelsTwoClasses() throws Exception {
final PCClass pcClass = new PCClass();
LoadContext context = Globals.getContext();
pcClass.setName("MyClass");
BuildUtilities.setFact(pcClass, "SpellType", "Arcane");
BonusObj aBonus = Bonus.newBonus(context, "CASTERLEVEL|MyClass|CL");
if (aBonus != null) {
pcClass.addToListFor(ListKey.BONUS, aBonus);
}
final PCClass pcClass2 = new PCClass();
pcClass2.setName("MyClass2");
BuildUtilities.setFact(pcClass2, "SpellType", "Divine");
aBonus = Bonus.newBonus(context, "CASTERLEVEL|MyClass2|CL");
if (aBonus != null) {
pcClass.addToListFor(ListKey.BONUS, aBonus);
}
final PlayerCharacter character = getCharacter();
final PreParserFactory factory = PreParserFactory.getInstance();
Prerequisite prereq = factory.parse("PRECLASS:2,SPELLCASTER=1");
character.incrementClassLevel(1, pcClass);
assertEquals(false, PrereqHandler.passes(prereq, character, null));
character.incrementClassLevel(1, pcClass2);
assertEquals(true, PrereqHandler.passes(prereq, character, null));
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class PreAttTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
LoadContext context = Globals.getContext();
myClass.setName("My Class");
myClass.put(FormulaKey.START_SKILL_POINTS, FormulaFactory.getFormulaFor(3));
final BonusObj babClassBonus = Bonus.newBonus(context, "COMBAT|BASEAB|CL+5");
myClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, babClassBonus);
Globals.getContext().getReferenceContext().importObject(myClass);
}
Aggregations