use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class PreCheckBaseTest 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);
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class NaturalattacksLst method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
Changes<Equipment> changes = context.getObjectContext().getListChanges(obj, ListKey.NATURAL_WEAPON);
Collection<Equipment> eqadded = changes.getAdded();
if (eqadded == null || eqadded.isEmpty()) {
return null;
}
StringBuilder sb = new StringBuilder();
boolean first = true;
for (Equipment lstw : eqadded) {
if (!first) {
sb.append(Constants.PIPE);
}
Equipment eq = Equipment.class.cast(lstw);
String name = eq.getDisplayName();
// TODO objcontext.getString(eq, StringKey.NAME);
if (name == null) {
context.addWriteMessage(getTokenName() + " expected Equipment to have a name");
return null;
}
sb.append(name).append(Constants.COMMA);
List<Type> type = eq.getListFor(ListKey.TYPE);
if (type == null || type.isEmpty()) {
context.addWriteMessage(getTokenName() + " expected Equipment to have a type");
return null;
}
sb.append(StringUtil.join(type, Constants.DOT));
sb.append(Constants.COMMA);
Boolean attProgress = eq.get(ObjectKey.ATTACKS_PROGRESS);
if (attProgress == null) {
context.addWriteMessage(getTokenName() + " expected Equipment to know ATTACKS_PROGRESS state");
return null;
} else if (!attProgress.booleanValue()) {
sb.append(Constants.CHAR_ASTERISK);
}
List<BonusObj> bonuses = eq.getListFor(ListKey.BONUS);
if (bonuses == null || bonuses.isEmpty()) {
sb.append('1');
} else {
if (bonuses.size() != 1) {
context.addWriteMessage(getTokenName() + " expected only one BONUS on Equipment: " + bonuses);
return null;
}
// TODO Validate BONUS type?
BonusObj extraAttacks = bonuses.iterator().next();
sb.append(Integer.parseInt(extraAttacks.getValue()) + 1);
}
sb.append(Constants.COMMA);
EquipmentHead head = eq.getEquipmentHeadReference(1);
if (head == null) {
context.addWriteMessage(getTokenName() + " expected an EquipmentHead on Equipment");
return null;
}
String damage = head.get(StringKey.DAMAGE);
if (damage == null) {
context.addWriteMessage(getTokenName() + " expected a Damage on EquipmentHead");
return null;
}
sb.append(damage);
Integer hands = eq.get(IntegerKey.SLOTS);
if (hands != null && hands != 0) {
sb.append(',').append(hands);
}
List<SpecialProperty> spropList = eq.getSafeListFor(ListKey.SPECIAL_PROPERTIES);
for (SpecialProperty sprop : spropList) {
sb.append(",SPROP=").append(sprop.toString());
}
first = false;
}
return new String[] { sb.toString() };
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class AnyPCToken method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
Changes<BonusObj> changes = context.getObjectContext().getListChanges(obj, ListKey.BONUS_ANYPC);
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 EQToken method parseTokenWithSeparator.
@Override
public ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
int pipeLoc = value.indexOf(Constants.PIPE);
if (pipeLoc == -1) {
return new ParseResult.Fail("Expected " + getFullTokenName() + ":<type>|<conditions>|BONUS but did not find a second pipe");
}
String constraints = value.substring(0, pipeLoc);
String bonus = value.substring(pipeLoc + 1);
final String v = bonus.replaceAll(Pattern.quote("<this>"), obj.getKeyName());
BonusObj bon = Bonus.newBonus(context, v);
if (bon == null) {
return new ParseResult.Fail(getFullTokenName() + " was given invalid type: " + bonus, context);
}
bon.setTokenSource(getFullTokenName());
EquipBonus eb = new EquipBonus(bon, constraints);
context.getObjectContext().addToList(obj, ListKey.BONUS_EQUIP, eb);
return ParseResult.SUCCESS;
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class BonusManagerTest method testStackingPositiveFirst.
/**
* Validate that the setActiveBonusStack method will correctly calculate the value of
* a positive bonus followed by a negative bonus to a non-stackable value.
*/
@Test
public void testStackingPositiveFirst() {
PCTemplate testObj = TestHelper.makeTemplate("PostiveFirst");
LoadContext context = Globals.getContext();
final BonusObj posBonus = Bonus.newBonus(context, "COMBAT|AC|5|TYPE=Armor");
testObj.addToListFor(ListKey.BONUS, posBonus);
final BonusObj negBonus = Bonus.newBonus(context, "COMBAT|AC|-2|TYPE=Armor");
testObj.addToListFor(ListKey.BONUS, negBonus);
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);
}
}
Aggregations