use of pcgen.core.FollowerOption in project pcgen by PCGen.
the class GlobalCompanionListTest method containsExpected.
@Override
protected boolean containsExpected() {
/*
* TODO This indicates that FollowerOptionFacet is not really pure
* content - it is doing filtering as well
*/
Map<FollowerOption, CDOMObject> available = foFacet.getAvailableFollowers(id, "Animal Companion", null);
if (available.size() != 1) {
return false;
}
FollowerOption entry = available.keySet().iterator().next();
boolean raceMatches = entry.getRaceRef().equals(context.getReferenceContext().getCDOMReference(Race.class, "Ape"));
boolean listMatches = entry.getListRef().equals(context.getReferenceContext().getCDOMReference(CompanionList.class, "Animal Companion"));
boolean adjMatches = entry.getAdjustment() == -3;
return raceMatches && listMatches && adjMatches;
}
use of pcgen.core.FollowerOption in project pcgen by PCGen.
the class CompanionSupportFacadeImpl method initCompData.
/**
* Initialisation of the character's companion data.
* @param rebuildCompanionList Should the list of the character;s companions be rebuilt?
*/
private void initCompData(boolean rebuildCompanionList) {
List<CompanionStub> companions = new ArrayList<>();
for (CompanionList compList : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(CompanionList.class)) {
keyToCompanionListMap.put(compList.getKeyName(), compList);
Map<FollowerOption, CDOMObject> fMap = charDisplay.getAvailableFollowers(compList.getKeyName(), null);
for (FollowerOption followerOpt : fMap.keySet()) {
if (followerOpt.getRace() != Globals.s_EMPTYRACE && followerOpt.qualifies(theCharacter, null)) {
companions.add(new CompanionStub(followerOpt.getRace(), compList.getKeyName()));
}
}
int maxVal = theCharacter.getMaxFollowers(compList);
if (maxVal == 0) {
maxCompanionsMap.removeKey(compList.toString());
} else {
maxCompanionsMap.putValue(compList.toString(), maxVal);
}
}
availCompList.updateContents(companions);
if (rebuildCompanionList) {
for (Follower follower : charDisplay.getFollowerList()) {
CompanionFacade comp = new CompanionNotLoaded(follower.getName(), new File(follower.getFileName()), follower.getRace(), follower.getType().toString());
CompanionFacadeDelegate delegate = new CompanionFacadeDelegate();
delegate.setCompanionFacade(comp);
companionList.addElement(delegate);
}
}
//Logging.debugPrint("Companion list " + companionList);
for (CompanionList compList : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(CompanionList.class)) {
updateCompanionTodo(compList.toString());
}
}
use of pcgen.core.FollowerOption in project pcgen by PCGen.
the class FollowerOptionFacet method getAvailableFollowers.
/**
* Returns a non-null copy of the available FollowerOptions of a given type
* for the Player Character represented by the given CharID. This method
* returns an empty Map if no objects are in this FollowerOptionFacet for
* the Player Character identified by the given CharID.
*
* This method is value-semantic in that ownership of the returned Map is
* transferred to the class calling this method. Modification of the
* returned Map will not modify this FollowerOptionFacet and modification of
* this FollowerOptionFacet will not modify the returned Map. Modifications
* to the returned Set will also not modify any future or previous objects
* returned by this (or other) methods on FollowerOptionFacet. If you wish
* to modify the information stored in this FollowerOptionFacet, you must
* use the add*() and remove*() methods of FollowerOptionFacet.
*
* @param id
* The CharID representing the Player Character for which the
* items in this FollowerOptionFacet should be returned
* @param type
* The type of FollowerOption that should be returned
* @param comp
* An optional Comparator to be used to sort the FollowerOption
* objects in the returned Map. null is a legal value, and will
* result in the FollowerOptions being sorted by their type
* @return A non-null copy of the Map of FollowerOptions in this
* FollowerOptionFacet for the Player Character represented by the
* given CharID
*/
public Map<FollowerOption, CDOMObject> getAvailableFollowers(CharID id, String type, Comparator<FollowerOption> comp) {
CaseInsensitiveMap<Map<FollowerOption, Set<CDOMObject>>> componentMap = getCachedMap(id);
if (componentMap == null) {
return Collections.emptyMap();
}
Map<FollowerOption, Set<CDOMObject>> foMap = componentMap.get(type);
if (foMap == null) {
return Collections.emptyMap();
}
Map<FollowerOption, CDOMObject> ret = new TreeMap<>(comp);
for (Map.Entry<FollowerOption, Set<CDOMObject>> me : foMap.entrySet()) {
FollowerOption fo = me.getKey();
Set<CDOMObject> target = me.getValue();
Collection<FollowerOption> expanded = fo.getExpandedOptions();
for (CDOMObject source : target) {
for (FollowerOption efo : expanded) {
/*
* TODO This is a bug, and will overwrite the first source
* :(
*/
ret.put(efo, source);
}
}
}
return ret;
}
use of pcgen.core.FollowerOption in project pcgen by PCGen.
the class CompanionSupportFacadeImplTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
uiDelegate = new MockUIDelegate();
todoManager = new TodoManager();
ListFacade<CampaignFacade> campaigns = new DefaultListFacade<>();
dataSetFacade = new DataSet(Globals.getContext(), SettingsHandler.getGame(), campaigns);
masterRace = TestHelper.makeRace("Wood Elf");
companionRace = TestHelper.makeRace("Weasel");
CDOMReference<Race> race = new CDOMDirectSingleRef<>(companionRace);
CDOMSingleRef<CompanionList> ref = new CDOMSimpleSingleRef<>(CompanionList.class, companionList.getKeyName());
FollowerOption option = new FollowerOption(race, ref);
masterRace.addToListFor(ListKey.COMPANIONLIST, option);
}
use of pcgen.core.FollowerOption in project pcgen by PCGen.
the class CompanionListLst method finish.
private void finish(LoadContext context, CDOMObject obj, String companionType, Set<CDOMReference<Race>> races, Integer followerAdjustment, List<Prerequisite> prereqs) {
context.getReferenceContext().constructIfNecessary(CompanionList.class, companionType);
CDOMSingleRef<CompanionList> ref = context.getReferenceContext().getCDOMReference(CompanionList.class, companionType);
for (CDOMReference<Race> race : races) {
final FollowerOption option = new FollowerOption(race, ref);
if (prereqs != null && !prereqs.isEmpty()) {
option.addAllPrerequisites(prereqs);
}
if (followerAdjustment != null && followerAdjustment != 0) {
option.setAdjustment(followerAdjustment.intValue());
}
context.getObjectContext().addToList(obj, ListKey.COMPANIONLIST, option);
}
}
Aggregations