Search in sources :

Example 71 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class AbstractJunit4CharacterTestCase method applyAbility.

public static CNAbility applyAbility(PlayerCharacter character, AbilityCategory cat, Ability a, String assoc) {
    if (a.getCDOMCategory() == null) {
        fail("Attempt to apply an Ability " + a.getKeyName() + " that never received a Category");
    }
    CNAbility cna = CNAbilityFactory.getCNAbility(cat, Nature.NORMAL, a);
    CNAbilitySelection cnas = new CNAbilitySelection(cna, assoc);
    character.addAbility(cnas, UserSelection.getInstance(), UserSelection.getInstance());
    return cna;
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection)

Example 72 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class AspectTest method testSimpleListReplacement.

/**
	 * Tests simple %LIST replacement.
	 */
public void testSimpleListReplacement() {
    final Ability pobj = TestHelper.makeAbility("dummy", AbilityCategory.FEAT, "Foo");
    Globals.getContext().unconditionallyProcess(pobj, "CHOOSE", "LANG|ALL");
    Globals.getContext().unconditionallyProcess(pobj, "MULT", "YES");
    Globals.getContext().getReferenceContext().constructCDOMObject(Language.class, "Foo");
    PlayerCharacter pc = getCharacter();
    final Aspect aspect = new Aspect(ASPECT_NAME, "%1");
    aspect.addVariable("%LIST");
    assertEquals("", aspect.getAspectText(pc, buildMap(pobj, AbilityCategory.FEAT, Nature.NORMAL)));
    AbilityCategory category = AbilityCategory.FEAT;
    CNAbility cna = pcgenFinalize(pobj, "Foo", pc, category);
    assertEquals("Foo", aspect.getAspectText(pc, Collections.singletonList(cna)));
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) PlayerCharacter(pcgen.core.PlayerCharacter) AbilityCategory(pcgen.core.AbilityCategory)

Example 73 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class AspectTest method testComplexVariableReplacement.

/**
	 * Test complex replacements.
	 */
public void testComplexVariableReplacement() {
    final Ability dummy = TestHelper.makeAbility("dummy", AbilityCategory.FEAT, "Foo");
    Globals.getContext().unconditionallyProcess(dummy, "CHOOSE", "LANG|ALL");
    Globals.getContext().unconditionallyProcess(dummy, "MULT", "YES");
    Globals.getContext().getReferenceContext().constructCDOMObject(Language.class, "Associated 1");
    Globals.getContext().getReferenceContext().constructCDOMObject(Language.class, "Associated 2");
    Globals.getContext().getReferenceContext().constructCDOMObject(Language.class, "Associated 3");
    dummy.put(VariableKey.getConstant("TestVar"), FormulaFactory.getFormulaFor(2));
    PlayerCharacter pc = getCharacter();
    final Aspect aspect = new Aspect(ASPECT_NAME, "%1 test %2");
    aspect.addVariable("TestVar");
    assertEquals("0 test ", aspect.getAspectText(pc, buildMap(dummy, AbilityCategory.FEAT, Nature.NORMAL)));
    CNAbility cna = pcgenFinalize(dummy, "Associated 1", pc, AbilityCategory.FEAT);
    pcgenFinalize(dummy, "Associated 2", pc, AbilityCategory.FEAT);
    assertEquals("2 test ", aspect.getAspectText(pc, Collections.singletonList(cna)));
    aspect.addVariable("%LIST");
    assertEquals("Replacement of %LIST failed", "2 test Associated 1 and Associated 2", aspect.getAspectText(pc, Collections.singletonList(cna)));
    pcgenFinalize(dummy, "Associated 3", pc, AbilityCategory.FEAT);
    aspect.addVariable("%LIST");
    assertEquals("Replacement of %LIST failed", "2 test Associated 1, Associated 2, Associated 3", aspect.getAspectText(pc, Collections.singletonList(cna)));
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) PlayerCharacter(pcgen.core.PlayerCharacter)

Example 74 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class AbilitySelector method applyChoice.

@Override
public void applyChoice(ChooseDriver obj, AbilitySelection as, PlayerCharacter pc) {
    CNAbility cna = CNAbilityFactory.getCNAbility(category.get(), nature, as.getObject());
    CNAbilitySelection cnas = new CNAbilitySelection(cna, as.getSelection());
    pc.associateSelection(as, cnas);
    pc.addAbility(cnas, obj, this);
}
Also used : CNAbility(pcgen.cdom.content.CNAbility)

Example 75 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class CNAbilitySelection method getAbilitySelectionFromPersistentFormat.

public static CNAbilitySelection getAbilitySelectionFromPersistentFormat(String persistentFormat) {
    StringTokenizer st = new StringTokenizer(persistentFormat, Constants.PIPE);
    String catString = st.nextToken();
    if (!catString.startsWith("CATEGORY=")) {
        throw new IllegalArgumentException("String in getAbilitySelectionFromPersistentFormat " + "must start with CATEGORY=, found: " + persistentFormat);
    }
    String cat = catString.substring(9);
    AbilityCategory ac = SettingsHandler.getGame().getAbilityCategory(cat);
    if (ac == null) {
        throw new IllegalArgumentException("Category in getAbilitySelectionFromPersistentFormat " + "must exist found: " + cat);
    }
    String natureString = st.nextToken();
    if (!natureString.startsWith("NATURE=")) {
        throw new IllegalArgumentException("Second argument in String in getAbilitySelectionFromPersistentFormat " + "must start with NATURE=, found: " + persistentFormat);
    }
    String natString = natureString.substring(7);
    Nature nat = Nature.valueOf(natString);
    String ab = st.nextToken();
    Ability a = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, ac, ab);
    if (a == null) {
        throw new IllegalArgumentException("Third argument in String in getAbilitySelectionFromPersistentFormat " + "must be an Ability, but it was not found: " + persistentFormat);
    }
    String sel = null;
    if (st.hasMoreTokens()) {
        /*
			 * No need to check for MULT:YES/NO here, as that is checked
			 * implicitly in the construction of AbilitySelection below
			 */
        sel = st.nextToken();
    } else if (persistentFormat.endsWith(Constants.PIPE)) {
        // Handle the StringTokenizer ignoring blank tokens at the end
        sel = "";
    }
    if (st.hasMoreTokens()) {
        throw new IllegalArgumentException("String in getAbilitySelectionFromPersistentFormat " + "must have 3 or 4 arguments, but found more: " + persistentFormat);
    }
    CNAbility cna = CNAbilityFactory.getCNAbility(ac, nat, a);
    return new CNAbilitySelection(cna, sel);
}
Also used : Nature(pcgen.cdom.enumeration.Nature) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) StringTokenizer(java.util.StringTokenizer) 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