Search in sources :

Example 16 with CNAbility

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

the class GeneralSaveRestoreTest method testTemplateFeat.

public void testTemplateFeat() {
    //Represents CODE-2547
    TokenRegistration.register(new plugin.lsttokens.deprecated.TemplateFeatToken());
    TokenRegistration.register(new plugin.lsttokens.ability.StackToken());
    TokenRegistration.register(new plugin.exporttokens.deprecated.TemplateToken());
    Language lang = context.getReferenceContext().constructCDOMObject(Language.class, "English");
    Ability a = context.getReferenceContext().constructCDOMObject(Ability.class, "Ab");
    context.getReferenceContext().reassociateCategory(AbilityCategory.FEAT, a);
    PCTemplate pct = context.getReferenceContext().constructCDOMObject(PCTemplate.class, "Templ");
    try {
        assertTrue(context.processToken(a, "MULT", "YES"));
        assertTrue(context.processToken(a, "STACK", "YES"));
        assertTrue(context.processToken(a, "CHOOSE", "LANG|English"));
        assertTrue(context.processToken(a, "AUTO", "LANG|%LIST"));
        assertTrue(context.processToken(pct, "FEAT", "Ab"));
    } catch (PersistenceLayerException e) {
        fail(e.getMessage());
    }
    finishLoad();
    pc.addTemplate(pct);
    assertTrue(pc.hasLanguage(lang));
    runRoundRobin(null);
    assertTrue(reloadedPC.hasLanguage(lang));
    List<CNAbility> cnaList = pc.getMatchingCNAbilities(a);
    assertEquals(1, cnaList.size());
    List<String> assocs = pc.getAssociationList(cnaList.get(0));
    assertEquals(1, assocs.size());
    assertEquals("English", assocs.get(0));
    cnaList = reloadedPC.getMatchingCNAbilities(a);
    assertEquals(1, cnaList.size());
    assocs = reloadedPC.getAssociationList(cnaList.get(0));
    assertEquals(1, assocs.size());
    assertEquals("English", assocs.get(0));
    assertEquals("Ab(English)", ExportHandler.getTokenString(pc, "TEMPLATE.0.FEAT"));
    assertEquals("Ab(English)", ExportHandler.getTokenString(reloadedPC, "TEMPLATE.0.FEAT"));
    reloadedPC.removeTemplate(pct);
    assertFalse(reloadedPC.hasLanguage(lang));
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) CNAbility(pcgen.cdom.content.CNAbility) Language(pcgen.core.Language) PCTemplate(pcgen.core.PCTemplate)

Example 17 with CNAbility

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

the class AddAbilityVirtualTest method testMult.

@Test
public void testMult() throws PersistenceLayerException {
    TokenRegistration.register(new NoChoiceToken());
    TokenRegistration.register(new StackToken());
    Domain source = create(Domain.class, "Source");
    PCClass pcc = create(PCClass.class, "Class");
    Ability a = createGrantedObject();
    context.unconditionallyProcess(a, "MULT", "YES");
    context.unconditionallyProcess(a, "STACK", "YES");
    context.unconditionallyProcess(a, "CHOOSE", "NOCHOICE");
    runToken(source);
    processToken(source);
    assocCheck = new AssocCheck() {

        public boolean check(CNAbility g) {
            if (pc.getDetailedAssociationCount(g) == 2) {
                return true;
            } else {
                System.err.println("Incorrect Association Count");
                return false;
            }
        }
    };
    assertEquals(0, getCount());
    ClassSource classSource = new ClassSource(pcc);
    domainFacet.add(id, source, classSource);
    assertTrue(containsExpected(a));
    assertEquals(2, getCount());
    domainFacet.remove(id, source);
    assertEquals(0, getCount());
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) NoChoiceToken(plugin.lsttokens.choose.NoChoiceToken) StackToken(plugin.lsttokens.ability.StackToken) Domain(pcgen.core.Domain) PCClass(pcgen.core.PCClass) AssocCheck(tokenmodel.testsupport.AssocCheck) ClassSource(pcgen.cdom.helper.ClassSource) Test(org.junit.Test) AbstractAddListTokenTest(tokenmodel.testsupport.AbstractAddListTokenTest)

Example 18 with CNAbility

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

the class AddAbilityNormalTest method testMult.

//TODO this appears to be a bug - is only applied once?
@Test
public void testMult() throws PersistenceLayerException {
    TokenRegistration.register(new NoChoiceToken());
    TokenRegistration.register(new StackToken());
    Domain source = create(Domain.class, "Source");
    PCClass pcc = create(PCClass.class, "Class");
    Ability a = createGrantedObject();
    context.unconditionallyProcess(a, "MULT", "YES");
    context.unconditionallyProcess(a, "STACK", "YES");
    context.unconditionallyProcess(a, "CHOOSE", "NOCHOICE");
    runToken(source);
    processToken(source);
    assocCheck = new AssocCheck() {

        public boolean check(CNAbility g) {
            if (pc.getDetailedAssociationCount(g) == 2) {
                return true;
            } else {
                System.err.println("Incorrect Association Count");
                return false;
            }
        }
    };
    assertEquals(0, getCount());
    ClassSource classSource = new ClassSource(pcc);
    domainFacet.add(id, source, classSource);
    assertTrue(containsExpected(a));
    assertEquals(2, getCount());
    domainFacet.remove(id, source);
    assertEquals(0, getCount());
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) NoChoiceToken(plugin.lsttokens.choose.NoChoiceToken) StackToken(plugin.lsttokens.ability.StackToken) Domain(pcgen.core.Domain) PCClass(pcgen.core.PCClass) AssocCheck(tokenmodel.testsupport.AssocCheck) ClassSource(pcgen.cdom.helper.ClassSource) Test(org.junit.Test) AbstractAddListTokenTest(tokenmodel.testsupport.AbstractAddListTokenTest)

Example 19 with CNAbility

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

the class AddAbilityNormalTest method containsExpected.

@Override
protected boolean containsExpected(Ability granted) {
    Collection<CNAbility> abilities = getTargetFacet().getPoolAbilities(id, AbilityCategory.FEAT, Nature.NORMAL);
    if (abilities.isEmpty()) {
        System.err.println("No Abilities");
        return false;
    }
    for (CNAbility a : abilities) {
        boolean abilityExpected = a.getAbility().equals(context.getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, AbilityCategory.FEAT, "Granted"));
        if (abilityExpected) {
            boolean c = assocCheck.check(a);
            if (!c) {
                System.err.println("Incorrect Associations");
            }
            return c;
        }
    }
    System.err.println("Did not find Ability: Granted");
    return false;
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility)

Example 20 with CNAbility

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

the class AddAbilityVirtualTest method containsExpected.

@Override
protected boolean containsExpected(Ability granted) {
    Collection<CNAbility> abilities = getTargetFacet().getPoolAbilities(id, AbilityCategory.FEAT, Nature.VIRTUAL);
    for (CNAbility a : abilities) {
        boolean abilityExpected = a.getAbility().equals(context.getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, AbilityCategory.FEAT, "Granted"));
        if (abilityExpected) {
            boolean c = assocCheck.check(a);
            if (!c) {
                System.err.println("Incorrect Associations");
            }
            return c;
        }
    }
    System.err.println("Did not find Ability");
    return false;
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility)

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