use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class BonusTest method testVarBonus.
/**
* Test the processing of bonusing variables using both
* abilities and equipment.
*/
public void testVarBonus() {
LoadContext context = Globals.getContext();
Ability dummyFeat = new Ability();
dummyFeat.setName("DummyFeat");
dummyFeat.setCDOMCategory(AbilityCategory.FEAT);
final PlayerCharacter pc = getCharacter();
// Create a variable
dummyFeat.put(VariableKey.getConstant("NegLevels"), FormulaFactory.ZERO);
// Create a bonus to it
Ability dummyFeat2 = new Ability();
dummyFeat2.setName("DummyFeat2");
dummyFeat2.setCDOMCategory(AbilityCategory.FEAT);
BonusObj aBonus = Bonus.newBonus(context, "VAR|NegLevels|7");
if (aBonus != null) {
dummyFeat2.addToListFor(ListKey.BONUS, aBonus);
}
Equipment equip = new Equipment();
equip.setName("DummyEquip");
aBonus = Bonus.newBonus(context, "VAR|NegLevels|2");
if (aBonus != null) {
equip.addToListFor(ListKey.BONUS, aBonus);
}
assertEquals("Variable value", 0.0, pc.getVariableValue("NegLevels", "").doubleValue(), 0.05);
addAbility(AbilityCategory.FEAT, dummyFeat);
assertEquals("Variable value", 0.0, pc.getVariableValue("NegLevels", "").doubleValue(), 0.05);
assertEquals("Variable value", -0.0, pc.getVariableValue("-1*NegLevels", "").doubleValue(), 0.05);
// Add a bonus to it
addAbility(AbilityCategory.FEAT, dummyFeat2);
assertEquals("Variable value", 7.0, pc.getVariableValue("NegLevels", "").doubleValue(), 0.05);
assertEquals("Variable value", -7.0, pc.getVariableValue("-1*NegLevels", "").doubleValue(), 0.05);
// Add the equipment that gives a bonus to NegLevels
EquipSet def = new EquipSet("0.1", "Default");
pc.addEquipSet(def);
final EquipSet eqSet = new EquipSet("0.1.1", "Equipped", "Test", equip);
pc.addEquipSet(eqSet);
pc.setCalcEquipmentList();
pc.calcActiveBonuses();
BonusActivation.activateBonuses(dummyFeat, pc);
assertEquals("Variable value", 9.0, pc.getVariableValue("NegLevels", "").doubleValue(), 0.05);
assertEquals("Variable value", -9.0, pc.getVariableValue("-1*NegLevels", "").doubleValue(), 0.05);
}
use of pcgen.rules.context.LoadContext 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.rules.context.LoadContext 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.rules.context.LoadContext 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.rules.context.LoadContext in project pcgen by PCGen.
the class BonusTest method testBonuswithLISTValueTwoAssocInfoList.
public void testBonuswithLISTValueTwoAssocInfoList() {
final PlayerCharacter character = getCharacter();
LoadContext context = Globals.getContext();
setPCStat(character, intel, 18);
setPCStat(character, str, 16);
BonusObj bonus = Bonus.newBonus(context, "STAT|%LIST|%LIST+1");
List<BonusObj> bonusList = new ArrayList<>();
bonusList.add(bonus);
Ability testBonus = new Ability();
testBonus.setName("TB2AssocList");
testBonus.setCDOMCategory(AbilityCategory.FEAT);
Globals.getContext().unconditionallyProcess(testBonus, "CHOOSE", "PCSTAT|ALL");
Globals.getContext().unconditionallyProcess(testBonus, "MULT", "YES");
testBonus.addToListFor(ListKey.BONUS, bonus);
CNAbility cna = AbstractCharacterTestCase.applyAbility(character, AbilityCategory.FEAT, testBonus, "INT");
testBonus = cna.getAbility();
AbstractCharacterTestCase.applyAbility(character, AbilityCategory.FEAT, testBonus, "STR");
character.calcActiveBonuses();
bonus = testBonus.getSafeListFor(ListKey.BONUS).get(0);
List<BonusPair> bonusPairs = character.getStringListFromBonus(bonus);
assertEquals(2, bonusPairs.size());
for (BonusPair bp : bonusPairs) {
if (bp.fullyQualifiedBonusType.equals("STAT.INT")) {
assertEquals(5, bp.resolve(character).intValue());
} else {
assertEquals(4, bp.resolve(character).intValue());
}
}
}
Aggregations