use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.
the class RemoveFeatToken method applyChoice.
@Override
public void applyChoice(CDOMObject owner, CNAbilitySelection choice, PlayerCharacter pc) {
CNAbility cna = choice.getCNAbility();
Ability anAbility = cna.getAbility();
boolean result = false;
// adjust the associated List
if (anAbility.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
ChoiceManagerList cm = ChooserUtilities.getChoiceManager(cna, pc);
remove(cm, pc, cna, choice.getSelection());
result = pc.hasAssociations(cna);
}
// then remove the Feat
if (!result) {
pc.removeAbility(choice, UserSelection.getInstance(), UserSelection.getInstance());
CDOMObjectUtilities.removeAdds(anAbility, pc);
CDOMObjectUtilities.restoreRemovals(anAbility, pc);
}
pc.adjustMoveRates();
double cost = cna.getAbility().getSafe(ObjectKey.SELECTION_COST).doubleValue();
pc.adjustAbilities(AbilityCategory.FEAT, new BigDecimal(-cost));
}
use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.
the class PObjectTest method testAssociatedBonus.
/**
* Test the function of adding a bonus each time an associated value is chosen.
*/
public void testAssociatedBonus() {
Ability pObj = new Ability();
pObj.setCDOMCategory(AbilityCategory.FEAT);
pObj.setName("My PObject");
pObj.setCDOMCategory(AbilityCategory.FEAT);
Globals.getContext().unconditionallyProcess(pObj, "CHOOSE", "LANG|ALL");
Globals.getContext().unconditionallyProcess(pObj, "MULT", "YES");
Globals.getContext().unconditionallyProcess(pObj, "STACK", "YES");
Globals.getContext().getReferenceContext().constructCDOMObject(Language.class, "TestPsion 1");
PlayerCharacter aPC = getCharacter();
CNAbility cna = AbstractCharacterTestCase.applyAbility(aPC, AbilityCategory.FEAT, pObj, "TestPsion 1");
pObj = cna.getAbility();
BonusAddition.applyBonus("SPELLKNOWN|CLASS=TestPsion;LEVEL=1|1", "TestPsion 1", aPC, pObj);
aPC.calcActiveBonuses();
assertEquals("Should get 1 bonus known spells", 1, (int) aPC.getTotalBonusTo("SPELLKNOWN", "CLASS.TestPsion;LEVEL.1"));
AbstractCharacterTestCase.applyAbility(aPC, AbilityCategory.FEAT, pObj, "TestPsion 1");
BonusAddition.applyBonus("SPELLKNOWN|CLASS=TestPsion;LEVEL=1|1", "TestPsion 1", aPC, pObj);
aPC.calcActiveBonuses();
assertEquals("Should get 4 bonus known spells", (2 * 2), (int) aPC.getTotalBonusTo("SPELLKNOWN", "CLASS.TestPsion;LEVEL.1"));
AbstractCharacterTestCase.applyAbility(aPC, AbilityCategory.FEAT, pObj, "TestPsion 1");
BonusAddition.applyBonus("SPELLKNOWN|CLASS=TestPsion;LEVEL=1|1", "TestPsion 1", aPC, pObj);
aPC.calcActiveBonuses();
assertEquals("Should get 9 bonus known spells", (3 * 3), (int) aPC.getTotalBonusTo("SPELLKNOWN", "CLASS.TestPsion;LEVEL.1"));
}
use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.
the class BonusTest method testBonuswithLISTValueTwoAssoc.
public void testBonuswithLISTValueTwoAssoc() {
final PlayerCharacter character = getCharacter();
LoadContext context = Globals.getContext();
setPCStat(character, intel, 18);
setPCStat(character, str, 16);
BonusObj bonus = Bonus.newBonus(context, "VISION|Darkvision|%LIST+10|TYPE=Magical Boon");
List<BonusObj> bonusList = new ArrayList<>();
bonusList.add(bonus);
Ability testBonus = new Ability();
testBonus.setName("TB2Assoc");
testBonus.setCDOMCategory(AbilityCategory.FEAT);
testBonus.addToListFor(ListKey.BONUS, bonus);
Globals.getContext().unconditionallyProcess(testBonus, "CHOOSE", "PCSTAT|ALL");
Globals.getContext().unconditionallyProcess(testBonus, "MULT", "YES");
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());
int totalBonus = 0;
BonusPair bp = bonusPairs.get(0);
assertEquals("VISION.DARKVISION:MAGICAL BOON", bp.fullyQualifiedBonusType);
totalBonus += bp.resolve(character).intValue();
bp = bonusPairs.get(1);
assertEquals("VISION.DARKVISION:MAGICAL BOON", bp.fullyQualifiedBonusType);
totalBonus += bp.resolve(character).intValue();
assertEquals(27, totalBonus);
}
use of pcgen.cdom.content.CNAbility 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());
}
}
}
use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.
the class FeatAllListToken method getAbilityList.
/**
* @see pcgen.io.exporttoken.AbilityListToken#getAbilityList(pcgen.core.PlayerCharacter, pcgen.core.AbilityCategory)
*/
@Override
protected MapToList<Ability, CNAbility> getAbilityList(PlayerCharacter pc, final AbilityCategory aCategory) {
final MapToList<Ability, CNAbility> listOfAbilities = new HashMapToList<>();
Collection<AbilityCategory> allCats = SettingsHandler.getGame().getAllAbilityCategories();
for (AbilityCategory aCat : allCats) {
if (aCat.getParentCategory().equals(aCategory)) {
for (CNAbility cna : pc.getPoolAbilities(aCat, Nature.NORMAL)) {
listOfAbilities.addToListFor(cna.getAbility(), cna);
}
for (CNAbility cna : pc.getPoolAbilities(aCat, Nature.AUTOMATIC)) {
listOfAbilities.addToListFor(cna.getAbility(), cna);
}
for (CNAbility cna : pc.getPoolAbilities(aCat, Nature.VIRTUAL)) {
listOfAbilities.addToListFor(cna.getAbility(), cna);
}
}
}
return listOfAbilities;
}
Aggregations