use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.
the class DirectAbilityFacet method removeAll.
public void removeAll(CharID id, Object source) {
if (source == null) {
throw new IllegalArgumentException("Attempt to remove object with null source from list");
}
List<List<SourcedCNAS>> list = getList(id);
if (list == null) {
return;
}
List<CNAbilitySelection> removed = new ArrayList<>();
List<CNAbilitySelection> added = new ArrayList<>();
for (Iterator<List<SourcedCNAS>> listIT = list.iterator(); listIT.hasNext(); ) {
List<SourcedCNAS> array = listIT.next();
int length = array.size();
//Iterate backwards, so that we remove harmless items first
for (int j = length - 1; j >= 0; j--) {
SourcedCNAS sc = array.get(j);
if (source.equals(sc.source)) {
//fix the array here
array.remove(j);
boolean needRemove = true;
if (!array.isEmpty()) {
CNAbilitySelection newPrimary = array.get(0).cnas;
//Only fire if the CNAS differs to avoid churn
if (!sc.cnas.equals(newPrimary) && (j == 0)) {
added.add(newPrimary);
} else {
needRemove = false;
}
}
if (needRemove) {
removed.add(sc.cnas);
}
}
}
if (array.isEmpty()) {
listIT.remove();
}
}
for (CNAbilitySelection cnas : removed) {
fireDataFacetChangeEvent(id, cnas, DataFacetChangeEvent.DATA_REMOVED);
}
for (CNAbilitySelection cnas : added) {
fireDataFacetChangeEvent(id, cnas, DataFacetChangeEvent.DATA_ADDED);
}
}
use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.
the class ConditionalAbilityFacet method getQualifiedSet.
/**
* Returns a non-null copy of the Set of objects the character qualifies for
* in this ConditionalAbilityFacet for the Player Character represented by
* the given CharID. This method returns an empty Collection if the Player
* Character identified by the given CharID qualifies for none of the
* objects in this ConditionalAbilityFacet.
*
* This method is value-semantic in that ownership of the returned
* Collection is transferred to the class calling this method. Modification
* of the returned Collection will not modify this ConditionalAbilityFacet
* and modification of this ConditionalAbilityFacet will not modify the
* returned Collection. Modifications to the returned Collection will also
* not modify any future or previous objects returned by this (or other)
* methods on ConditionalAbilityFacet. If you wish to modify the information
* stored in this ConditionalAbilityFacet, you must use the add*() and
* remove*() methods of ConditionalAbilityFacet.
*
* @param id
* The CharID representing the Player Character for which the
* items in this AbstractQualifiedListFacet should be returned.
* @return A non-null Set of objects the Player Character represented by the
* given CharID qualifies for in this AbstractQualifiedListFacet
*/
public Collection<CNAbilitySelection> getQualifiedSet(CharID id) {
List<CNAbilitySelection> set = new ArrayList<>();
Map<CNAbilitySelection, Object> cached = getCachedMap(id);
if (cached != null) {
for (Map.Entry<CNAbilitySelection, Object> me : cached.entrySet()) {
CNAbilitySelection cnas = me.getKey();
if (prerequisiteFacet.qualifies(id, cnas, me.getValue())) {
set.add(cnas);
}
}
}
return set;
}
use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.
the class AutoWeaponProfListTargetTest method testFromAbility.
@Test
public void testFromAbility() throws PersistenceLayerException {
Ability source = create(Ability.class, "Source");
context.getReferenceContext().reassociateCategory(AbilityCategory.FEAT, source);
Ability granted = createGrantedObject();
context.getReferenceContext().constructCDOMObject(Language.class, "English");
ParseResult result = new MultToken().parseToken(context, granted, "YES");
if (result != ParseResult.SUCCESS) {
result.printMessages();
fail("Test Setup Failed");
}
result = new MultToken().parseToken(context, source, "YES");
if (result != ParseResult.SUCCESS) {
result.printMessages();
fail("Test Setup Failed");
}
result = new LangToken().parseToken(context, granted, "ALL");
if (result != ParseResult.SUCCESS) {
result.printMessages();
fail("Test Setup Failed");
}
result = new LangToken().parseToken(context, source, "ALL");
if (result != ParseResult.SUCCESS) {
result.printMessages();
fail("Test Setup Failed");
}
result = token.parseToken(context, source, "FEAT|Granted (%LIST)");
if (result != ParseResult.SUCCESS) {
result.printMessages();
fail("Test Setup Failed");
}
finishLoad();
assertEquals(0, directAbilityFacet.getCount(id));
CNAbilitySelection cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.AUTOMATIC, source), "English");
directAbilityFacet.add(id, cas, UserSelection.getInstance());
assertTrue(containsExpected());
assertEquals(2, directAbilityFacet.getCount(id));
directAbilityFacet.remove(id, cas, UserSelection.getInstance());
assertEquals(0, directAbilityFacet.getCount(id));
}
use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.
the class AbstractAbilityGrantCheckTest method applyParent.
private void applyParent(Ability parent) {
CNAbility cna = CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.NORMAL, parent);
CNAbilitySelection cnas = new CNAbilitySelection(cna);
pc.addAbility(cnas, UserSelection.getInstance(), this);
}
use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.
the class PlayerCharacter method processAbilityList.
private void processAbilityList(CDOMObject cdo, CDOMReference<AbilityList> ref) {
Collection<CDOMReference<Ability>> mods = cdo.getListMods(ref);
for (CDOMReference<Ability> objref : mods) {
Collection<Ability> objs = objref.getContainedObjects();
Collection<AssociatedPrereqObject> assoc = cdo.getListAssociations(ref, objref);
for (Ability ab : objs) {
if (ab == null) {
Logging.log(Logging.LST_ERROR, "Missing object referenced in the ability list for '" + cdo + "' list is " + ref + ". Source " + cdo.getSourceURI());
continue;
}
for (AssociatedPrereqObject apo : assoc) {
Nature nature = apo.getAssociation(AssociationKey.NATURE);
CDOMSingleRef<AbilityCategory> acRef = apo.getAssociation(AssociationKey.CATEGORY);
AbilityCategory cat = acRef.get();
if (ab.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
List<String> choices = apo.getAssociation(AssociationKey.ASSOC_CHOICES);
if (choices == null) {
//CHOOSE:NOCHOICE can be unconditionally applied (must be STACK:YES)
CNAbilitySelection cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ab), "");
cas.addAllPrerequisites(apo.getPrerequisiteList());
applyAbility(cas, cdo);
} else {
for (final String choice : choices) {
CNAbilitySelection cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ab), choice);
cas.addAllPrerequisites(apo.getPrerequisiteList());
applyAbility(cas, cdo);
}
}
} else {
CNAbilitySelection cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ab));
cas.addAllPrerequisites(apo.getPrerequisiteList());
applyAbility(cas, cdo);
}
}
}
}
cabFacet.update(id);
}
Aggregations