use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class PlayerCharacterTest method testGetVariableValue1.
/**
* Tests getVariableValue
* @throws Exception
*/
public void testGetVariableValue1() throws Exception {
readyToRun();
LoadContext context = Globals.getContext();
//Logging.setDebugMode(true);
Logging.debugPrint("\n\n\ntestGetVariableValue1()");
giantRace.put(VariableKey.getConstant("GiantVar1"), FormulaFactory.ZERO);
final BonusObj raceBonus = Bonus.newBonus(context, "VAR|GiantVar1|7+HD");
giantClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, raceBonus);
giantClass.getOriginalClassLevel(1).put(VariableKey.getConstant("GiantClass1"), FormulaFactory.ZERO);
final BonusObj babClassBonus = Bonus.newBonus(context, "VAR|GiantClass1|CL=Giant");
giantClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, babClassBonus);
final PlayerCharacter character = new PlayerCharacter();
// NOTE: This will add 4 levels of giantClass to the character
character.setRace(giantRace);
character.incrementClassLevel(4, giantClass, true);
assertEquals(new Float(15.0), character.getVariableValue("GiantVar1", "CLASS:Giant"));
assertEquals(new Float(8.0), character.getVariableValue("GiantClass1", "CLASS:Giant"));
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class PlayerCharacterTest method testCheckSkillModChangeWithBonus.
/**
* Validate the checkSkillModChange correctly handles SKILLPOOL bonuses
*/
public void testCheckSkillModChangeWithBonus() {
readyToRun();
PlayerCharacter character = getCharacter();
character.setRace(human);
character.setStat(intel, 10);
PCTemplate template = TestHelper.makeTemplate("grantsskills");
LoadContext context = Globals.getContext();
final BonusObj skillBonusLvl1 = Bonus.newBonus(context, "SKILLPOOL|CLASS=MyClass;LEVEL=1|2");
assertNotNull("Failed to create bonus", skillBonusLvl1);
template.addToListFor(ListKey.BONUS, skillBonusLvl1);
character.addTemplate(template);
character.incrementClassLevel(2, pcClass, true);
List<PCLevelInfo> levelInfoList = new ArrayList<>(character.getLevelInfo());
assertEquals("Level number lvl 1", 1, levelInfoList.get(0).getClassLevel());
assertEquals("Level number lvl 2", 2, levelInfoList.get(1).getClassLevel());
assertEquals("Skills gained lvl 1", 3, levelInfoList.get(0).getSkillPointsGained(character));
assertEquals("Skills remaining lvl 1", 3, levelInfoList.get(0).getSkillPointsRemaining());
assertEquals("Skills gained lvl 2", 1, levelInfoList.get(1).getSkillPointsGained(character));
assertEquals("Skills remaining lvl 2", 1, levelInfoList.get(1).getSkillPointsRemaining());
character.checkSkillModChange();
character.checkSkillModChange();
assertEquals("Skills gained lvl 1", 3, levelInfoList.get(0).getSkillPointsGained(character));
assertEquals("Skills remaining lvl 1", 3, levelInfoList.get(0).getSkillPointsRemaining());
assertEquals("Skills gained lvl 2", 1, levelInfoList.get(1).getSkillPointsGained(character));
assertEquals("Skills remaining lvl 2", 1, levelInfoList.get(1).getSkillPointsRemaining());
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class PlayerCharacterTest method testAdjustMoveRates.
/**
* Test the processing and order of operations of the adjustMoveRates method.
*/
public void testAdjustMoveRates() {
Ability quickFlySlowSwim = TestHelper.makeAbility("quickFlySlowSwim", AbilityCategory.FEAT.getKeyName(), "Foo");
PCTemplate template = TestHelper.makeTemplate("slowFlyQuickSwim");
PCTemplate template2 = TestHelper.makeTemplate("dig");
LoadContext context = Globals.getContext();
final BonusObj digBonus = Bonus.newBonus(context, "MOVEADD|TYPE.Dig|60");
assertNotNull("Failed to create bonus", digBonus);
template2.addToListFor(ListKey.BONUS, digBonus);
//template.addm
context.getReferenceContext().importObject(quickFlySlowSwim);
context.getReferenceContext().importObject(template2);
context.unconditionallyProcess(human, "MOVE", "Walk,30");
context.unconditionallyProcess(quickFlySlowSwim, "MOVE", "Swim,10,Fly,30");
context.unconditionallyProcess(template, "MOVE", "Swim,30,Fly,10");
readyToRun();
GameMode game = SettingsHandler.getGame();
LoadInfo li = game.getModeContext().getReferenceContext().constructNowIfNecessary(LoadInfo.class, game.getName());
li.addLoadScoreValue(0, new BigDecimal("100.0"));
li.addLoadScoreValue(10, new BigDecimal("100.0"));
li.addLoadMultiplier("LIGHT", new Float(100), "100", 0);
PlayerCharacter pc = getCharacter();
setPCStat(pc, str, 10);
pc.setRace(human);
pc.calcActiveBonuses();
pc.adjustMoveRates();
CharacterDisplay display = pc.getDisplay();
assertEquals(0.0, display.movementOfType("Swim"), 0.1);
assertEquals(0.0, display.movementOfType("Fly"), 0.1);
addAbility(AbilityCategory.FEAT, quickFlySlowSwim);
pc.calcActiveBonuses();
pc.adjustMoveRates();
assertEquals(10.0, display.movementOfType("Swim"), 0.1);
assertEquals(30.0, display.movementOfType("Fly"), 0.1);
pc.addTemplate(template);
pc.adjustMoveRates();
assertEquals(30.0, display.movementOfType("Swim"), 0.1);
assertEquals(30.0, display.movementOfType("Fly"), 0.1);
pc.addTemplate(template2);
pc.adjustMoveRates();
assertEquals(30.0, display.movementOfType("Swim"), 0.1);
assertEquals(30.0, display.movementOfType("Fly"), 0.1);
assertEquals(60.0, display.movementOfType("Dig"), 0.1);
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class BonusToken method unparse.
@Override
public String[] unparse(LoadContext context, EquipmentModifier mod) {
Changes<BonusObj> changes = context.getObjectContext().getListChanges(mod, 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 BonusToken method parseToken.
@Override
public ParseResult parseToken(LoadContext context, EquipmentModifier mod, 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());
context.getObjectContext().addToList(mod, ListKey.BONUS, bon);
return ParseResult.SUCCESS;
}
Aggregations