Search in sources :

Example 56 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class AbstractCNASEnforcingFacetTest method testTypeRemoveUselessSource.

@Test
public void testTypeRemoveUselessSource() {
    Object source1 = new Object();
    CNAbilitySelection t1 = getObject();
    getFacet().add(id, t1, source1);
    assertEquals(1, getFacet().getCount(id));
    assertFalse(getFacet().isEmpty(id));
    assertNotNull(getFacet().getSet(id));
    assertEquals(1, getFacet().getSet(id).size());
    assertEquals(t1, getFacet().getSet(id).iterator().next());
    assertEventCount(1, 0);
    Object source2 = new Object();
    getFacet().remove(id, t1, source2);
    // No change (wrong source)
    assertEquals(1, getFacet().getCount(id));
    assertFalse(getFacet().isEmpty(id));
    assertNotNull(getFacet().getSet(id));
    assertEquals(1, getFacet().getSet(id).size());
    assertEquals(t1, getFacet().getSet(id).iterator().next());
    assertEventCount(1, 0);
}
Also used : CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) Test(org.junit.Test)

Example 57 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class AbstractCNASEnforcingFacetTest method testDetectSameParentCategory.

@Test
public void testDetectSameParentCategory() {
    Object source1 = new Object();
    assertTrue(getFacet().isEmpty(id));
    assertEquals(0, getFacet().getCount(id));
    CNAbility n1 = CNAbilityFactory.getCNAbility(feat, Nature.NORMAL, nomult);
    CNAbility n2 = CNAbilityFactory.getCNAbility(fighterfeat, Nature.NORMAL, nomult);
    CNAbilitySelection cnas1 = new CNAbilitySelection(n1);
    CNAbilitySelection cnas2 = new CNAbilitySelection(n2);
    assertTrue(getFacet().add(id, cnas1, source1));
    assertFalse(getFacet().isEmpty(id));
    assertEquals(1, getFacet().getCount(id));
    assertFalse(getFacet().add(id, cnas2, source1));
    assertEquals(1, getFacet().getCount(id));
    //LIFO
    assertFalse(getFacet().remove(id, cnas2, source1));
    assertEquals(1, getFacet().getCount(id));
    assertFalse(getFacet().isEmpty(id));
    assertTrue(getFacet().remove(id, cnas1, source1));
    assertEquals(0, getFacet().getCount(id));
    assertTrue(getFacet().isEmpty(id));
    assertTrue(getFacet().add(id, cnas1, source1));
    assertFalse(getFacet().isEmpty(id));
    assertEquals(1, getFacet().getCount(id));
    assertFalse(getFacet().add(id, cnas2, source1));
    assertEquals(1, getFacet().getCount(id));
    //FIFO
    assertTrue(getFacet().remove(id, cnas1, source1));
    assertEquals(1, getFacet().getCount(id));
    assertFalse(getFacet().isEmpty(id));
    assertTrue(getFacet().remove(id, cnas2, source1));
    assertEquals(0, getFacet().getCount(id));
    assertTrue(getFacet().isEmpty(id));
    CNAbility virtual = CNAbilityFactory.getCNAbility(fighterfeat, Nature.VIRTUAL, nomult);
    CNAbilitySelection cnas3 = new CNAbilitySelection(virtual);
    assertTrue(getFacet().add(id, cnas1, source1));
    assertFalse(getFacet().isEmpty(id));
    assertEquals(1, getFacet().getCount(id));
    assertFalse(getFacet().add(id, cnas3, source1));
    assertEquals(1, getFacet().getCount(id));
    //LIFO
    assertFalse(getFacet().remove(id, cnas3, source1));
    assertEquals(1, getFacet().getCount(id));
    assertFalse(getFacet().isEmpty(id));
    assertTrue(getFacet().remove(id, cnas1, source1));
    assertEquals(0, getFacet().getCount(id));
    assertTrue(getFacet().isEmpty(id));
    assertTrue(getFacet().add(id, cnas1, source1));
    assertFalse(getFacet().isEmpty(id));
    assertEquals(1, getFacet().getCount(id));
    assertFalse(getFacet().add(id, cnas3, source1));
    assertEquals(1, getFacet().getCount(id));
    //FIFO
    assertTrue(getFacet().remove(id, cnas1, source1));
    assertEquals(1, getFacet().getCount(id));
    assertFalse(getFacet().isEmpty(id));
    assertTrue(getFacet().remove(id, cnas3, source1));
    assertEquals(0, getFacet().getCount(id));
    assertTrue(getFacet().isEmpty(id));
    //Three, Midoutfirst
    assertTrue(getFacet().add(id, cnas1, source1));
    assertFalse(getFacet().add(id, cnas2, source1));
    assertFalse(getFacet().add(id, cnas3, source1));
    assertFalse(getFacet().remove(id, cnas2, source1));
    assertEquals(1, getFacet().getCount(id));
    assertTrue(getFacet().remove(id, cnas1, source1));
    assertEquals(1, getFacet().getCount(id));
    assertTrue(getFacet().remove(id, cnas3, source1));
    assertEquals(0, getFacet().getCount(id));
    assertTrue(getFacet().isEmpty(id));
    //Test different source (LIFO)
    Object source2 = new Object();
    assertTrue(getFacet().add(id, cnas1, source1));
    assertFalse(getFacet().add(id, cnas1, source2));
    assertEquals(1, getFacet().getCount(id));
    assertFalse(getFacet().remove(id, cnas1, source2));
    assertEquals(1, getFacet().getCount(id));
    assertTrue(getFacet().remove(id, cnas1, source1));
    assertEquals(0, getFacet().getCount(id));
    assertTrue(getFacet().isEmpty(id));
    //Test different source (FIFO - counter-intuitive)
    assertTrue(getFacet().add(id, cnas1, source1));
    assertFalse(getFacet().add(id, cnas1, source2));
    assertEquals(1, getFacet().getCount(id));
    //Note: This is FALSE since the CNAS didn't change - don't want to fire an event
    assertFalse(getFacet().remove(id, cnas1, source1));
    assertEquals(1, getFacet().getCount(id));
    assertTrue(getFacet().remove(id, cnas1, source2));
    assertEquals(0, getFacet().getCount(id));
    assertTrue(getFacet().isEmpty(id));
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) Test(org.junit.Test)

Example 58 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class AbilityUtilities method driveChooseAndAdd.

public static void driveChooseAndAdd(CNAbility cna, PlayerCharacter pc, boolean toAdd) {
    Ability ability = cna.getAbility();
    if (!ability.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
        CNAbilitySelection cnas = new CNAbilitySelection(cna);
        if (toAdd) {
            pc.addAbility(cnas, UserSelection.getInstance(), UserSelection.getInstance());
        } else {
            pc.removeAbility(cnas, UserSelection.getInstance(), UserSelection.getInstance());
        }
    }
    AbilityCategory category = (AbilityCategory) cna.getAbilityCategory();
    // how many sub-choices to make
    ArrayList<String> reservedList = new ArrayList<>();
    ChoiceManagerList<?> aMan = ChooserUtilities.getConfiguredController(cna, pc, category, reservedList);
    if (aMan != null) {
        processSelection(pc, cna, aMan, toAdd);
        return;
    }
//TODO Log error? (or MULT:NO?)
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) ArrayList(java.util.ArrayList)

Example 59 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class AbstractCNASEnforcingFacetTest method testIdentity.

@Test
public void testIdentity() {
    Object source1 = new Object();
    assertTrue(getFacet().isEmpty(id));
    assertEquals(0, getFacet().getCount(id));
    CNAbility n1 = CNAbilityFactory.getCNAbility(feat, Nature.NORMAL, stackyes);
    CNAbility n2 = CNAbilityFactory.getCNAbility(feat, Nature.NORMAL, stackyes);
    CNAbility ff = CNAbilityFactory.getCNAbility(fighterfeat, Nature.NORMAL, stackyes);
    CNAbility virtual = CNAbilityFactory.getCNAbility(feat, Nature.VIRTUAL, stackyes);
    CNAbilitySelection cnas1 = new CNAbilitySelection(n1, "English");
    CNAbilitySelection cnas2 = new CNAbilitySelection(n2, "English");
    CNAbilitySelection cnas3 = new CNAbilitySelection(virtual, "English");
    CNAbilitySelection cnas4 = new CNAbilitySelection(ff, "English");
    //Check identity is .equals not ==
    assertTrue(getFacet().add(id, cnas1, source1));
    assertEquals(1, getFacet().getCount(id));
    //Avoid false positives;
    assertFalse(getFacet().remove(id, cnas3, source1));
    assertFalse(getFacet().remove(id, cnas4, source1));
    //Should succeed (.equals identity)
    assertTrue(getFacet().remove(id, cnas2, source1));
    assertEquals(0, getFacet().getCount(id));
    assertTrue(getFacet().isEmpty(id));
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) Test(org.junit.Test)

Example 60 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class AbstractCNASEnforcingFacetTest method testStack.

@Test
public void testStack() {
    Object source1 = new Object();
    assertTrue(getFacet().isEmpty(id));
    assertEquals(0, getFacet().getCount(id));
    CNAbility n1 = CNAbilityFactory.getCNAbility(feat, Nature.NORMAL, stackyes);
    CNAbility n2 = CNAbilityFactory.getCNAbility(feat, Nature.NORMAL, stackyes);
    CNAbilitySelection cnas1 = new CNAbilitySelection(n1, "English");
    CNAbilitySelection cnas2 = new CNAbilitySelection(n2, "English");
    assertTrue(getFacet().add(id, cnas1, source1));
    assertFalse(getFacet().isEmpty(id));
    assertEquals(1, getFacet().getCount(id));
    assertTrue(getFacet().add(id, cnas2, source1));
    assertEquals(2, getFacet().getCount(id));
    assertTrue(getFacet().remove(id, cnas2, source1));
    assertEquals(1, getFacet().getCount(id));
    assertFalse(getFacet().isEmpty(id));
    assertTrue(getFacet().remove(id, cnas1, source1));
    assertEquals(0, getFacet().getCount(id));
    assertTrue(getFacet().isEmpty(id));
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) Test(org.junit.Test)

Aggregations

CNAbilitySelection (pcgen.cdom.helper.CNAbilitySelection)70 CNAbility (pcgen.cdom.content.CNAbility)35 Test (org.junit.Test)28 Ability (pcgen.core.Ability)26 ArrayList (java.util.ArrayList)17 AbilityCategory (pcgen.core.AbilityCategory)7 CDOMReference (pcgen.cdom.base.CDOMReference)6 PlayerCharacter (pcgen.core.PlayerCharacter)6 ParseResult (pcgen.rules.persistence.token.ParseResult)6 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)5 AbilityRefChoiceSet (pcgen.cdom.choiceset.AbilityRefChoiceSet)5 Nature (pcgen.cdom.enumeration.Nature)5 PCTemplate (pcgen.core.PCTemplate)5 CharID (pcgen.cdom.enumeration.CharID)4 List (java.util.List)3 AbilityChoiceSet (pcgen.cdom.base.ChoiceSet.AbilityChoiceSet)3 SpecialAbility (pcgen.core.SpecialAbility)3 BonusObj (pcgen.core.bonus.BonusObj)3 AbstractTokenModelTest (tokenmodel.testsupport.AbstractTokenModelTest)3 HashSet (java.util.HashSet)2