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;
}
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);
}
}
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;
}
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()]);
}
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);
}
Aggregations