use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.
the class AbstractCNASEnforcingFacetTest method getMultObject.
protected CNAbilitySelection getMultObject(String tgt) {
Ability a1 = new Ability();
a1.setName("Abil");
a1.setCDOMCategory(AbilityCategory.FEAT);
a1.put(ObjectKey.MULTIPLE_ALLOWED, true);
return new CNAbilitySelection(CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.VIRTUAL, a1), tgt);
}
use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.
the class AbstractCNASEnforcingFacetTest method testTypeAddSingleSourceTwiceGet.
@Test
public void testTypeAddSingleSourceTwiceGet() {
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);
// Add same, still only once in set (and only one event)
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);
}
use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.
the class AbstractCNASEnforcingFacetTest method testCopyContents.
@Test
public void testCopyContents() {
Object source1 = new Object();
CNAbilitySelection t1 = getMultObject("English");
CNAbilitySelection t2 = getMultObject("German");
getFacet().add(id, t1, source1);
getFacet().add(id, t2, source1);
assertEquals(2, getFacet().getCount(id));
assertEquals(0, getFacet().getCount(altid));
getFacet().copyContents(id, altid);
assertEquals(2, getFacet().getCount(altid));
assertFalse(getFacet().isEmpty(altid));
Collection<CNAbilitySelection> setoftwo = getFacet().getSet(altid);
assertNotNull(setoftwo);
assertEquals(2, setoftwo.size());
assertTrue(setoftwo.contains(t1));
assertTrue(setoftwo.contains(t2));
// Prove independence (remove from id)
getFacet().remove(id, t1, source1);
assertEquals(1, getFacet().getCount(id));
assertFalse(getFacet().isEmpty(id));
Collection<CNAbilitySelection> setofone = getFacet().getSet(id);
assertNotNull(setofone);
assertEquals(1, setofone.size());
assertTrue(setofone.contains(t2));
assertEquals(2, getFacet().getCount(altid));
assertFalse(getFacet().isEmpty(altid));
setoftwo = getFacet().getSet(altid);
assertNotNull(setoftwo);
assertEquals(2, setoftwo.size());
assertTrue(setoftwo.contains(t1));
assertTrue(setoftwo.contains(t2));
// Prove Independence (remove from altid)
getFacet().remove(altid, t2, source1);
assertEquals(1, getFacet().getCount(id));
assertFalse(getFacet().isEmpty(id));
setofone = getFacet().getSet(id);
assertNotNull(setofone);
assertEquals(1, setofone.size());
assertTrue(setofone.contains(t2));
assertEquals(1, getFacet().getCount(altid));
assertFalse(getFacet().isEmpty(altid));
setofone = getFacet().getSet(altid);
assertNotNull(setofone);
assertEquals(1, setofone.size());
assertTrue(setofone.contains(t1));
}
use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.
the class AbstractCNASEnforcingFacetTest method testDifferentNature.
@Test
public void testDifferentNature() {
Object source1 = new Object();
assertTrue(getFacet().isEmpty(id));
assertEquals(0, getFacet().getCount(id));
CNAbility normal = CNAbilityFactory.getCNAbility(feat, Nature.NORMAL, nomult);
CNAbility virtual = CNAbilityFactory.getCNAbility(feat, Nature.VIRTUAL, nomult);
CNAbilitySelection cnas1 = new CNAbilitySelection(normal);
CNAbilitySelection cnas2 = new CNAbilitySelection(virtual);
assertFalse(CNAbilitySelectionUtilities.canCoExist(cnas1, cnas2));
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));
}
use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.
the class AbilityTargetSaveRestoreTest method remove.
@Override
protected void remove(Object o) {
Ability abil = (Ability) o;
CNAbility cna = CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.NORMAL, abil);
String assoc = null;
if (ChooseActivation.hasNewChooseToken(abil)) {
assoc = "Granted";
}
CNAbilitySelection cnas = new CNAbilitySelection(cna, assoc);
reloadedPC.removeAbility(cnas, UserSelection.getInstance(), UserSelection.getInstance());
//TODO These need to be moved into being core behaviors somehow
CDOMObjectUtilities.removeAdds(abil, reloadedPC);
CDOMObjectUtilities.restoreRemovals(abil, reloadedPC);
reloadedPC.adjustMoveRates();
}
Aggregations