Search in sources :

Example 1 with FollowerLimit

use of pcgen.cdom.helper.FollowerLimit in project pcgen by PCGen.

the class FollowerLimitFacet method getMaxFollowers.

/**
	 * Returns the maximum number of Followers of a given CompanionList for the
	 * Player Character identified by the given CharID.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character for which the
	 *            maximum number of Followers will be returned
	 * @param cl
	 *            The CompanionList for which the maximum number of Followers
	 *            will be returned
	 * @return The maximum number of Followers of a given CompanionList for the
	 *         Player Character identified by the given CharID.
	 */
public int getMaxFollowers(CharID id, CompanionList cl) {
    Map<CompanionList, Map<FollowerLimit, Set<CDOMObject>>> componentMap = getCachedMap(id);
    if (componentMap == null) {
        return -1;
    }
    Map<FollowerLimit, Set<CDOMObject>> foMap = componentMap.get(cl);
    if (foMap == null) {
        return -1;
    }
    int ret = -1;
    for (Map.Entry<FollowerLimit, Set<CDOMObject>> me : foMap.entrySet()) {
        FollowerLimit fl = me.getKey();
        Set<CDOMObject> set = me.getValue();
        for (CDOMObject source : set) {
            int val = formulaResolvingFacet.resolve(id, fl.getValue(), source.getQualifiedKey()).intValue();
            ret = Math.max(ret, val);
        }
    }
    if (ret != -1) {
        ret += bonusCheckingFacet.getBonus(id, "FOLLOWERS", cl.getKeyName().toUpperCase());
    }
    return ret;
}
Also used : Set(java.util.Set) WrappedMapSet(pcgen.base.util.WrappedMapSet) CompanionList(pcgen.cdom.list.CompanionList) CDOMObject(pcgen.cdom.base.CDOMObject) FollowerLimit(pcgen.cdom.helper.FollowerLimit) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with FollowerLimit

use of pcgen.cdom.helper.FollowerLimit in project pcgen by PCGen.

the class FollowerLimitFacet method dataAdded.

/**
	 * Adds the FollowerLimit objects granted by CDOMObjects added to the Player
	 * Character to this FollowerLimitFacet.
	 * 
	 * Triggered when one of the Facets to which FollowerOptionFacet listens
	 * fires a DataFacetChangeEvent to indicate a FollowerOption 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<FollowerLimit> followers = cdo.getListFor(ListKey.FOLLOWERS);
    if (followers != null) {
        addAll(dfce.getCharID(), followers, cdo);
    }
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) FollowerLimit(pcgen.cdom.helper.FollowerLimit)

Example 3 with FollowerLimit

use of pcgen.cdom.helper.FollowerLimit in project pcgen by PCGen.

the class FollowersLst method parseToken.

@Override
public ParseResult parseToken(LoadContext context, CDOMObject obj, String value) {
    if (obj instanceof Ungranted) {
        return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
    }
    if ((value == null) || value.isEmpty()) {
        return new ParseResult.Fail("Argument in " + getTokenName() + " cannot be empty", context);
    }
    ParsingSeparator sep = new ParsingSeparator(value, '|');
    sep.addGroupingPair('[', ']');
    sep.addGroupingPair('(', ')');
    String followerType = sep.next();
    if (followerType.isEmpty()) {
        return new ParseResult.Fail("Follower Type in " + getTokenName() + " cannot be empty", context);
    }
    if (!sep.hasNext()) {
        return new ParseResult.Fail(getTokenName() + " has no PIPE character: " + "Must be of the form <follower type>|<formula>", context);
    }
    String followerNumber = sep.next();
    if (sep.hasNext()) {
        return new ParseResult.Fail(getTokenName() + " has too many PIPE characters: " + "Must be of the form <follower type>|<formula", context);
    }
    if (followerNumber.isEmpty()) {
        return new ParseResult.Fail("Follower Count in " + getTokenName() + " cannot be empty", context);
    }
    CDOMSingleRef<CompanionList> cl = context.getReferenceContext().getCDOMReference(CompanionList.class, followerType);
    Formula num = FormulaFactory.getFormulaFor(followerNumber);
    if (!num.isValid()) {
        return new ParseResult.Fail("Number of Followers in " + getTokenName() + " was not valid: " + num.toString(), context);
    }
    context.getObjectContext().addToList(obj, ListKey.FOLLOWERS, new FollowerLimit(cl, num));
    return ParseResult.SUCCESS;
}
Also used : Formula(pcgen.base.formula.Formula) ParsingSeparator(pcgen.base.text.ParsingSeparator) CompanionList(pcgen.cdom.list.CompanionList) FollowerLimit(pcgen.cdom.helper.FollowerLimit) Ungranted(pcgen.cdom.base.Ungranted)

Example 4 with FollowerLimit

use of pcgen.cdom.helper.FollowerLimit in project pcgen by PCGen.

the class FollowersLst method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    Changes<FollowerLimit> changes = context.getObjectContext().getListChanges(obj, ListKey.FOLLOWERS);
    if (changes == null || changes.isEmpty()) {
        return null;
    }
    TreeSet<String> returnSet = new TreeSet<>();
    for (FollowerLimit fl : changes.getAdded()) {
        String followerType = fl.getCompanionList().getLSTformat(false);
        Formula followerNumber = fl.getValue();
        returnSet.add(followerType + Constants.PIPE + followerNumber.toString());
    }
    return returnSet.toArray(new String[returnSet.size()]);
}
Also used : Formula(pcgen.base.formula.Formula) TreeSet(java.util.TreeSet) FollowerLimit(pcgen.cdom.helper.FollowerLimit)

Example 5 with FollowerLimit

use of pcgen.cdom.helper.FollowerLimit in project pcgen by PCGen.

the class FollowerLimitFacet method add.

private void add(CharID id, FollowerLimit fo, CDOMObject cdo) {
    if (fo == null) {
        throw new IllegalArgumentException("Object to add may not be null");
    }
    CompanionList cl = fo.getCompanionList().get();
    Map<FollowerLimit, Set<CDOMObject>> foMap = getConstructingCachedMap(id, cl);
    Set<CDOMObject> set = foMap.get(fo);
    if (set == null) {
        set = new WrappedMapSet<>(IdentityHashMap.class);
        foMap.put(fo, set);
    }
    set.add(cdo);
}
Also used : Set(java.util.Set) WrappedMapSet(pcgen.base.util.WrappedMapSet) CompanionList(pcgen.cdom.list.CompanionList) CDOMObject(pcgen.cdom.base.CDOMObject) IdentityHashMap(java.util.IdentityHashMap) FollowerLimit(pcgen.cdom.helper.FollowerLimit)

Aggregations

FollowerLimit (pcgen.cdom.helper.FollowerLimit)5 CDOMObject (pcgen.cdom.base.CDOMObject)3 CompanionList (pcgen.cdom.list.CompanionList)3 IdentityHashMap (java.util.IdentityHashMap)2 Set (java.util.Set)2 Formula (pcgen.base.formula.Formula)2 WrappedMapSet (pcgen.base.util.WrappedMapSet)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 ParsingSeparator (pcgen.base.text.ParsingSeparator)1 Ungranted (pcgen.cdom.base.Ungranted)1