use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class BonusManagerTest method testStackingNegativeFirst.
/**
* Validate that the setActiveBonusStack method will correctly calculate the value of
* a negative bonus followed by a positive bonus to a non-stackable value.
*/
@Test
public void testStackingNegativeFirst() {
PCTemplate testObj = TestHelper.makeTemplate("PostiveFirst");
LoadContext context = Globals.getContext();
final BonusObj negBonus = Bonus.newBonus(context, "COMBAT|AC|-2|TYPE=Armor");
testObj.addToListFor(ListKey.BONUS, negBonus);
final BonusObj posBonus = Bonus.newBonus(context, "COMBAT|AC|5|TYPE=Armor");
testObj.addToListFor(ListKey.BONUS, posBonus);
PlayerCharacter pc = getCharacter();
pc.addTemplate(testObj);
// Run the check a few times to ensure no randomness issues
for (int i = 0; i < 10; i++) {
pc.calcActiveBonuses();
assertEquals("Incorrect bonus total", 3.0, pc.getTotalBonusTo("COMBAT", "AC"), 0.0001);
}
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class EquipmentModifierTest method test885958B.
/**
* Test -2 and +13
*/
public void test885958B() {
LoadContext context = Globals.getContext();
final EquipmentModifier eqMod = new EquipmentModifier();
final BonusObj aBonus = Bonus.newBonus(context, "WEAPON|TOHIT|-2|PREVARGT:%CHOICE,STR");
final Equipment e = new Equipment();
e.addAssociation(eqMod, "+13");
eqMod.addToListFor(ListKey.BONUS, aBonus);
for (BonusObj bonusObj : eqMod.getBonusList(e)) {
assertEquals("-2", bonusObj.getValue());
final Prerequisite prereq = bonusObj.getPrerequisiteList().get(0);
assertEquals("+13", prereq.getKey());
assertEquals("STR", prereq.getOperand());
}
assertEquals("-2", aBonus.getValue());
final Prerequisite prereq = aBonus.getPrerequisiteList().get(0);
assertEquals("%CHOICE", prereq.getKey());
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class BonusLst method process.
@Override
public boolean process(LoadContext context, CDOMObject obj) {
List<BonusObj> bonusList = obj.getListFor(ListKey.BONUS);
boolean returnValue = true;
if (bonusList != null) {
for (BonusObj bonus : bonusList) {
String bonusName = bonus.getBonusName();
if ("ABILITYPOOL".equalsIgnoreCase(bonusName)) {
for (Object o : bonus.getBonusInfoList()) {
if (context.getReferenceContext().silentlyGetConstructedCDOMObject(ABILITY_CATEGORY_CLASS, o.toString()) == null) {
LoadContext dummyCtx = new RuntimeLoadContext(context.getReferenceContext(), new ConsolidatedListCommitStrategy());
dummyCtx.setSourceURI(obj.getSourceURI());
Logging.errorPrint("BONUS: " + bonus + " in " + obj.getClass().getSimpleName() + ' ' + obj.getKeyName() + " contained an invalid AbilityCategory " + o.toString(), dummyCtx);
returnValue = false;
}
}
} else if ("UDAM".equals(bonusName)) {
for (Object o : bonus.getBonusInfoList()) {
String classKey = o.toString();
final PCClass aClass = context.getReferenceContext().silentlyGetConstructedCDOMObject(PCCLASS_CLASS, classKey);
if (aClass == null) {
Logging.errorPrint("Could not find class '" + classKey + "' for UDAM token", context);
}
}
}
}
}
try {
obj.ownBonuses(obj);
} catch (CloneNotSupportedException e) {
Logging.errorPrint(e.getLocalizedMessage());
return false;
}
return returnValue;
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class BonusLst method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
if (obj instanceof EquipmentModifier) {
// EquipmentModifier bonuses are handled by plugin.lsttokens.equipmentmodifier.BonusToken
return null;
}
Changes<BonusObj> changes = context.getObjectContext().getListChanges(obj, 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();
Set<String> bonusSet = new TreeSet<>();
for (BonusObj bonus : added) {
if (tokenName.equals(bonus.getTokenSource())) {
String bonusString = bonus.getLSTformat();
bonusSet.add(bonusString);
}
}
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 BonusLst method parseToken.
@Override
public ParseResult parseToken(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 (value.indexOf("PREAPPLY:") != -1) {
return new ParseResult.Fail("Use of PREAPPLY prohibited on a BONUS , " + "please use TEMPBONUS with: " + value);
}
final String v = value.replaceAll(Pattern.quote("<this>"), obj.getKeyName());
BonusObj bon = Bonus.newBonus(context, v);
if (bon == null) {
return new ParseResult.Fail(getTokenName() + " was given invalid bonus: " + value, context);
}
bon.setTokenSource(getTokenName());
context.getObjectContext().addToList(obj, ListKey.BONUS, bon);
return ParseResult.SUCCESS;
}
Aggregations