Search in sources :

Example 51 with CNAbility

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));
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) ChoiceManagerList(pcgen.core.chooser.ChoiceManagerList) BigDecimal(java.math.BigDecimal)

Example 52 with CNAbility

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"));
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility)

Example 53 with CNAbility

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);
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) PlayerCharacter(pcgen.core.PlayerCharacter) ArrayList(java.util.ArrayList) LoadContext(pcgen.rules.context.LoadContext)

Example 54 with CNAbility

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());
        }
    }
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) PlayerCharacter(pcgen.core.PlayerCharacter) ArrayList(java.util.ArrayList) LoadContext(pcgen.rules.context.LoadContext)

Example 55 with CNAbility

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;
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) HashMapToList(pcgen.base.util.HashMapToList) AbilityCategory(pcgen.core.AbilityCategory)

Aggregations

CNAbility (pcgen.cdom.content.CNAbility)131 Ability (pcgen.core.Ability)77 ArrayList (java.util.ArrayList)37 CNAbilitySelection (pcgen.cdom.helper.CNAbilitySelection)28 AbilityCategory (pcgen.core.AbilityCategory)26 Test (org.junit.Test)21 HashMapToList (pcgen.base.util.HashMapToList)16 List (java.util.List)15 PlayerCharacter (pcgen.core.PlayerCharacter)9 Language (pcgen.core.Language)7 HashSet (java.util.HashSet)5 Nature (pcgen.cdom.enumeration.Nature)5 SpecialAbility (pcgen.core.SpecialAbility)5 BonusObj (pcgen.core.bonus.BonusObj)5 BigDecimal (java.math.BigDecimal)4 CDOMObject (pcgen.cdom.base.CDOMObject)4 LoadContext (pcgen.rules.context.LoadContext)4 StringTokenizer (java.util.StringTokenizer)3 GenericMapToList (pcgen.base.util.GenericMapToList)3 PCClass (pcgen.core.PCClass)3