use of pcgen.cdom.content.ChangeProf in project pcgen by PCGen.
the class ChangeProfFacet method getWeaponProfsInTarget.
/**
* For a given type of WeaponProf, returns a List of WeaponProf objects
* active for a Player Character after they are modified by the ChangeProf
* objects active on the Player Character.
*
* This method is value-semantic in that ownership of the returned List is
* transferred to the class calling this method. Modification of the
* returned List will not modify this ChangeProfFacet and modification of
* this ChangeProfFacet will not modify the returned List. Modifications to
* the returned List will also not modify any future or previous objects
* returned by this (or other) methods on ChangeProfFacet. If you wish to
* modify the information stored in this ChangeProfFacet, you must use the
* add*() and remove*() methods of ChangeProfFacet.
*
* @param id
* The CharID identifying the Player Character for which the List
* of WeaponProf objects will be returned
* @param master
* The original group of WeaponProf objects to be modified by any
* ChangeProf objects active on the Player Character.
* @return A List of WeaponProf objects active for a Player Character, after
* they are modified by the ChangeProf objects active on the Player
* Character
*/
public List<WeaponProf> getWeaponProfsInTarget(CharID id, CDOMGroupRef<WeaponProf> master) {
String type = master.getLSTformat(false);
if (!type.startsWith("TYPE=")) {
throw new IllegalArgumentException("Cannot get targets for: " + type);
}
AbstractReferenceContext ref = Globals.getContext().getReferenceContext();
List<WeaponProf> aList = new ArrayList<>();
// Can't use master because late called references may not have been
// initialized, see 2001287
Collection<WeaponProf> weaponProfsOfType = Globals.getPObjectsOfType(ref.getConstructedCDOMObjects(WeaponProf.class), type);
for (ChangeProf cp : getSet(id)) {
if (cp.getResult().equals(master)) {
aList.addAll(cp.getSource().getContainedObjects());
} else if (weaponProfsOfType != null) {
weaponProfsOfType.removeAll(cp.getSource().getContainedObjects());
}
}
aList.addAll(weaponProfsOfType);
return aList;
}
use of pcgen.cdom.content.ChangeProf in project pcgen by PCGen.
the class ChangeProfFacet method dataAdded.
/**
* Determines ChangeProf objects granted by CDOMObjects which are added to a
* Player Character.
*
* Triggered when one of the Facets to which ChangeProfFacet listens fires a
* DataFacetChangeEvent to indicate a CDOMObject was added to a Player
* Character.
*
* @param dfce
* The DataFacetChangeEvent containing the information about the
* change
*
* @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
*/
@Override
public void dataAdded(DataFacetChangeEvent<CharID, CDOMObject> dfce) {
CDOMObject cdo = dfce.getCDOMObject();
List<ChangeProf> list = cdo.getListFor(ListKey.CHANGEPROF);
if (list != null) {
addAll(dfce.getCharID(), list, cdo);
}
}
use of pcgen.cdom.content.ChangeProf in project pcgen by PCGen.
the class ChangeProfFacetTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
context = new RuntimeLoadContext(new RuntimeReferenceContext(), new ConsolidatedListCommitStrategy());
CDOMObject cdo1 = new PCTemplate();
cdo1.setName("Template1");
CDOMObject cdo2 = new Race();
cdo2.setName("Race1");
ChangeProf st1 = getObject();
ChangeProf st2 = getObject();
cdo1.addToListFor(ListKey.CHANGEPROF, st1);
cdo2.addToListFor(ListKey.CHANGEPROF, st2);
source = new CDOMObject[] { cdo1, cdo2 };
target = new ChangeProf[] { st1, st2 };
}
use of pcgen.cdom.content.ChangeProf in project pcgen by PCGen.
the class GlobalChangeProfTest method containsExpected.
@Override
protected boolean containsExpected() {
ChangeProf changeProf = changeProfFacet.getSet(id).iterator().next();
boolean sourceMatch = changeProf.getSource().equals(context.getReferenceContext().getCDOMReference(WeaponProf.class, "Axe"));
boolean targetMatch = changeProf.getResult().equals(context.getReferenceContext().getCDOMTypeReference(WeaponProf.class, "Martial"));
return sourceMatch && targetMatch;
}
use of pcgen.cdom.content.ChangeProf in project pcgen by PCGen.
the class ChangeprofLst method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
Changes<ChangeProf> changes = context.getObjectContext().getListChanges(obj, ListKey.CHANGEPROF);
Collection<ChangeProf> added = changes.getAdded();
if (added == null || added.isEmpty()) {
// Zero indicates no Token
return null;
}
HashMapToList<CDOMGroupRef<WeaponProf>, CDOMReference<WeaponProf>> m = new HashMapToList<>();
for (ChangeProf cp : added) {
CDOMReference<WeaponProf> source = cp.getSource();
CDOMGroupRef<WeaponProf> result = cp.getResult();
m.addToListFor(result, source);
}
SortedSet<CDOMReference<WeaponProf>> set = new TreeSet<>(ReferenceUtilities.REFERENCE_SORTER);
Set<String> returnSet = new TreeSet<>();
for (CDOMGroupRef<WeaponProf> result : m.getKeySet()) {
StringBuilder sb = new StringBuilder();
boolean needComma = false;
set.clear();
set.addAll(m.getListFor(result));
for (CDOMReference<WeaponProf> source : set) {
if (needComma) {
sb.append(Constants.COMMA);
}
needComma = true;
String sourceLst = source.getLSTformat(false);
if (sourceLst.startsWith(Constants.LST_TYPE_EQUAL)) {
sb.append(Constants.LST_TYPE_DOT);
sb.append(sourceLst.substring(5));
} else {
sb.append(sourceLst);
}
}
sb.append(Constants.EQUALS).append(result.getLSTformat(false).substring(5));
returnSet.add(sb.toString());
}
return new String[] { StringUtil.join(returnSet, Constants.PIPE) };
}
Aggregations