use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class StartfeatsToken method unparse.
@Override
public String[] unparse(LoadContext context, Race race) {
Changes<BonusObj> changes = context.getObjectContext().getListChanges(race, ListKey.BONUS);
if (changes == null || changes.isEmpty()) {
// Empty indicates no token present
return null;
}
// CONSIDER need to deal with removed...
Collection<BonusObj> added = changes.getAdded();
String tokenName = getTokenName();
Collection<String> bonusSet = new WeightedCollection<>(String.CASE_INSENSITIVE_ORDER);
for (BonusObj bonus : added) {
if (tokenName.equals(bonus.getTokenSource())) {
bonusSet.add(bonus.getValue());
}
}
if (bonusSet.isEmpty()) {
// This is okay - just no BONUSes from this token
return null;
}
return bonusSet.toArray(new String[bonusSet.size()]);
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class BonusToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, PointBuyMethod pbm, String value) {
BonusObj bon = Bonus.newBonus(context, value);
if (bon == null) {
return new ParseResult.Fail(getTokenName() + " was given invalid bonus: " + value, context);
}
bon.setTokenSource(getTokenName());
pbm.addBonus(bon);
return ParseResult.SUCCESS;
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class PreBaseSizeTest method testBaseSizePlusMod.
/**
* Tests to make sure the base size does not includ SIZEMOD adjustments
* @throws Exception
*/
public void testBaseSizePlusMod() throws Exception {
final PlayerCharacter character = getCharacter();
LoadContext context = Globals.getContext();
character.setRace(race);
final BonusObj sizeBonus = Bonus.newBonus(context, "SIZEMOD|NUMBER|1");
race.addToListFor(ListKey.BONUS, sizeBonus);
character.calcActiveBonuses();
Prerequisite prereq;
final PreParserFactory factory = PreParserFactory.getInstance();
prereq = factory.parse("PREBASESIZEEQ:Medium");
assertTrue("Character's base size should be equal to Medium", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREBASESIZELTEQ:Medium");
assertTrue("Character's base size should be <= to Medium", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREBASESIZEGTEQ:Medium");
assertTrue("Character's base size should be >= to Medium", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREBASESIZEGT:Small");
assertTrue("Character's base size should be > to Small", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREBASESIZELT:Large");
assertTrue("Character's base size should be < to Large", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREBASESIZELT:Medium");
assertFalse("Character's base size should not be < to Medium", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREBASESIZEGT:Medium");
assertFalse("Character's base size should not be > to Medium", PrereqHandler.passes(prereq, character, null));
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class PreCheckTest 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("PRECHECK:1,Fortitude=1");
assertTrue("Character's Fort save should be 1", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECHECK:1,Will=2");
assertTrue("Character's Will save should be 2", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECHECK:1,Fortitude=1,Will=3");
assertTrue("Character's Will save should be 2", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECHECK:2,Fortitude=2,Will=2");
assertFalse("Character's Fort save not 1", PrereqHandler.passes(prereq, character, null));
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class PreCheckTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
LoadContext context = Globals.getContext();
PCCheck obj = new PCCheck();
obj.setName("Fortitude");
Globals.getContext().getReferenceContext().importObject(obj);
obj = new PCCheck();
obj.setName("Reflex");
Globals.getContext().getReferenceContext().importObject(obj);
obj = new PCCheck();
obj.setName("Will");
Globals.getContext().getReferenceContext().importObject(obj);
myClass.setName("My Class");
myClass.put(FormulaKey.START_SKILL_POINTS, FormulaFactory.getFormulaFor(3));
final BonusObj fortRefBonus = Bonus.newBonus(context, "SAVE|BASE.Fortitude,BASE.Reflex|CL/3");
myClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, fortRefBonus);
final BonusObj willBonus = Bonus.newBonus(context, "SAVE|BASE.Will|CL/2+2");
myClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, willBonus);
Globals.getContext().getReferenceContext().importObject(myClass);
}
Aggregations