Search in sources :

Example 1 with FollowerOption

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;
}
Also used : FollowerOption(pcgen.core.FollowerOption) CDOMObject(pcgen.cdom.base.CDOMObject) CompanionList(pcgen.cdom.list.CompanionList) Race(pcgen.core.Race)

Example 2 with FollowerOption

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());
    }
}
Also used : FollowerOption(pcgen.core.FollowerOption) CompanionList(pcgen.cdom.list.CompanionList) ArrayList(java.util.ArrayList) Follower(pcgen.core.character.Follower) CompanionFacade(pcgen.facade.core.CompanionFacade) CDOMObject(pcgen.cdom.base.CDOMObject) File(java.io.File)

Example 3 with FollowerOption

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;
}
Also used : Set(java.util.Set) WrappedMapSet(pcgen.base.util.WrappedMapSet) FollowerOption(pcgen.core.FollowerOption) CDOMObject(pcgen.cdom.base.CDOMObject) TreeMap(java.util.TreeMap) IdentityHashMap(java.util.IdentityHashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) CaseInsensitiveMap(pcgen.base.util.CaseInsensitiveMap)

Example 4 with FollowerOption

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);
}
Also used : CDOMDirectSingleRef(pcgen.cdom.reference.CDOMDirectSingleRef) DataSet(pcgen.core.DataSet) FollowerOption(pcgen.core.FollowerOption) CompanionList(pcgen.cdom.list.CompanionList) CDOMSimpleSingleRef(pcgen.cdom.reference.CDOMSimpleSingleRef) CampaignFacade(pcgen.facade.core.CampaignFacade) Race(pcgen.core.Race) DefaultListFacade(pcgen.facade.util.DefaultListFacade)

Example 5 with FollowerOption

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);
    }
}
Also used : FollowerOption(pcgen.core.FollowerOption) CompanionList(pcgen.cdom.list.CompanionList) Race(pcgen.core.Race)

Aggregations

FollowerOption (pcgen.core.FollowerOption)10 CompanionList (pcgen.cdom.list.CompanionList)6 CDOMObject (pcgen.cdom.base.CDOMObject)5 Race (pcgen.core.Race)4 File (java.io.File)3 Follower (pcgen.core.character.Follower)3 Set (java.util.Set)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 CaseInsensitiveMap (pcgen.base.util.CaseInsensitiveMap)1 TripleKeyMapToList (pcgen.base.util.TripleKeyMapToList)1 WrappedMapSet (pcgen.base.util.WrappedMapSet)1 CDOMList (pcgen.cdom.base.CDOMList)1 CDOMReference (pcgen.cdom.base.CDOMReference)1 CDOMDirectSingleRef (pcgen.cdom.reference.CDOMDirectSingleRef)1 CDOMSimpleSingleRef (pcgen.cdom.reference.CDOMSimpleSingleRef)1