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);
}
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));
}
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?)
}
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));
}
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));
}
Aggregations