use of pcgen.cdom.list.CompanionList 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.cdom.list.CompanionList in project pcgen by PCGen.
the class PCGVer2Parser method parseFollowerLine.
/*
* ###############################################################
* Character Follower methods
* ###############################################################
*/
private void parseFollowerLine(final String line) {
final PCGTokenizer tokens;
try {
tokens = new PCGTokenizer(line);
} catch (PCGParseException pcgpex) {
final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.IllegalFollower", line, pcgpex.getMessage());
warnings.add(msg);
return;
}
final Follower aFollower = new Follower(Constants.EMPTY_STRING, Constants.EMPTY_STRING, null);
for (final PCGElement element : tokens.getElements()) {
final String tag = element.getName();
if (IOConstants.TAG_FOLLOWER.equals(tag)) {
aFollower.setName(EntityEncoder.decode(element.getText()));
} else if (IOConstants.TAG_TYPE.equals(tag)) {
String cType = EntityEncoder.decode(element.getText());
CompanionList cList = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(CompanionList.class, cType);
if (cList == null) {
Logging.errorPrint("Cannot find CompanionList: " + cType);
} else {
aFollower.setType(cList);
}
} else if (IOConstants.TAG_RACE.equals(tag)) {
String raceText = EntityEncoder.decode(element.getText());
Race r = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, raceText);
if (r == null) {
Logging.errorPrint("Cannot find Race: " + raceText);
} else {
aFollower.setRace(r);
}
} else if (IOConstants.TAG_HITDICE.equals(tag)) {
try {
aFollower.setUsedHD(Integer.parseInt(element.getText()));
} catch (NumberFormatException nfe) {
// nothing we can do about it
}
} else if (IOConstants.TAG_FILE.equals(tag)) {
String inputFileName = EntityEncoder.decode(element.getText());
String masterFileName = makeFilenameAbsolute(inputFileName);
if (masterFileName == null) {
final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.CantFindFollower", inputFileName);
warnings.add(msg);
} else {
aFollower.setFileName(masterFileName);
}
}
}
if (!Constants.EMPTY_STRING.equals(aFollower.getFileName()) && !Constants.EMPTY_STRING.equals(aFollower.getName()) && aFollower.getType() != null && !Constants.EMPTY_STRING.equals(aFollower.getType().toString())) {
thePC.addFollower(aFollower);
}
}
use of pcgen.cdom.list.CompanionList 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.list.CompanionList 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.list.CompanionList in project pcgen by PCGen.
the class PlayerCharacterTest method testGetAvailableFollowers.
/**
* Validate the getAvailableFollowers function.
*/
public void testGetAvailableFollowers() {
readyToRun();
Ability ab = TestHelper.makeAbility("Tester1", AbilityCategory.FEAT, "Empty Container");
Ability mab = TestHelper.makeAbility("Tester2", AbilityCategory.FEAT, "Mount Container");
Ability fab = TestHelper.makeAbility("Tester3", AbilityCategory.FEAT, "Familiar Container");
PlayerCharacter pc = getCharacter();
CharacterDisplay display = pc.getDisplay();
addAbility(AbilityCategory.FEAT, ab);
CDOMSingleRef<CompanionList> ref = new CDOMSimpleSingleRef<>(CompanionList.class, "Mount");
CDOMReference<Race> race = new CDOMDirectSingleRef<>(giantRace);
FollowerOption option = new FollowerOption(race, ref);
mab.addToListFor(ListKey.COMPANIONLIST, option);
ref = new CDOMSimpleSingleRef<>(CompanionList.class, "Familiar");
race = new CDOMDirectSingleRef<>(human);
option = new FollowerOption(race, ref);
fab.addToListFor(ListKey.COMPANIONLIST, option);
Set<FollowerOption> fo = display.getAvailableFollowers("Familiar", null).keySet();
assertTrue("Initially familiar list should be empty", fo.isEmpty());
fo = display.getAvailableFollowers("MOUNT", null).keySet();
assertTrue("Initially mount list should be empty", fo.isEmpty());
addAbility(AbilityCategory.FEAT, mab);
fo = display.getAvailableFollowers("Familiar", null).keySet();
assertTrue("Familiar list should still be empty", fo.isEmpty());
fo = display.getAvailableFollowers("MOUNT", null).keySet();
assertFalse("Mount list should not be empty anymore", fo.isEmpty());
assertEquals("Mount should be the giant race", giantRace.getKeyName(), fo.iterator().next().getRace().getKeyName());
assertEquals("Mount list should only have one entry", 1, fo.size());
addAbility(AbilityCategory.FEAT, fab);
fo = display.getAvailableFollowers("Familiar", null).keySet();
assertFalse("Familiar list should not be empty anymore", fo.isEmpty());
assertEquals("Familiar should be the human race", human.getKeyName(), fo.iterator().next().getRace().getKeyName());
assertEquals("Familiar list should only have one entry", 1, fo.size());
fo = display.getAvailableFollowers("MOUNT", null).keySet();
assertFalse("Mount list should not be empty anymore", fo.isEmpty());
assertEquals("Mount should be the giant race", giantRace.getKeyName(), fo.iterator().next().getRace().getKeyName());
assertEquals("Mount list should only have one entry", 1, fo.size());
}
Aggregations