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 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);
}
}
use of pcgen.cdom.list.CompanionList in project pcgen by PCGen.
the class PlayerCharacter method setCalcFollowerBonus.
/**
* Apply the bonus from a follower to the master pc.
*/
public void setCalcFollowerBonus() {
setDirty(true);
for (Follower aF : getFollowerList()) {
final CompanionList cList = aF.getType();
final String rType = cList.getKeyName();
final Race fRace = aF.getRace();
for (CompanionMod cm : Globals.getContext().getReferenceContext().getManufacturer(CompanionMod.class, cList).getAllObjects()) {
final String aType = cm.getType();
if (aType.equalsIgnoreCase(rType) && cm.appliesToRace(fRace)) {
// Found race and type of follower
// so add bonus to the master
companionModFacet.add(id, cm);
}
}
}
}
use of pcgen.cdom.list.CompanionList in project pcgen by PCGen.
the class CompanionSupportFacadeImpl method linkCompanion.
/**
* Adds a newly opened character into the existing
* companion framework. This character will replace
* the dummy CompanionFacade that has the same
* file name. This should typically be called
* when a character is opened from one of the follower stubs
* @param character the character to link
*/
private void linkCompanion(CharacterFacade character) {
for (CompanionFacadeDelegate delegate : companionList) {
File file = delegate.getFileRef().get();
String name = delegate.getNameRef().get();
RaceFacade race = delegate.getRaceRef().get();
if (file.equals(character.getFileRef().get()) && name.equals(character.getNameRef().get()) && (race == null || race.equals(character.getRaceRef().get()))) {
String companionType = delegate.getCompanionType();
delegate.setCompanionFacade(character);
// Note: When creating a companion we leave the linking to the create code.
if (character.getMaster() == null && character.getRaceRef().get() != null && !Constants.NONESELECTED.equals(character.getRaceRef().get().getKeyName())) {
CompanionList compList = keyToCompanionListMap.get(companionType);
final Follower newMaster = new Follower(charDisplay.getFileName(), charDisplay.getName(), compList);
FollowerOption followerOpt = getFollowerOpt(compList, (Race) character.getRaceRef().get());
if (followerOpt != null) {
newMaster.setAdjustment(followerOpt.getAdjustment());
} else {
Logging.log(Logging.WARNING, "Failed to find FollowerOption for complist " + compList + " and race " + character.getRaceRef().get());
}
((CharacterFacadeImpl) character).getTheCharacter().setMaster(newMaster);
}
return;
}
}
}
use of pcgen.cdom.list.CompanionList in project pcgen by PCGen.
the class CompanionSupportFacadeImpl method addCompanion.
@Override
public void addCompanion(CharacterFacade companion, String companionType) {
if (companion == null || !(companion instanceof CharacterFacadeImpl)) {
return;
}
CharacterFacadeImpl compFacadeImpl = (CharacterFacadeImpl) companion;
CompanionList compList = keyToCompanionListMap.get(companionType);
Race compRace = (Race) compFacadeImpl.getRaceRef().get();
FollowerOption followerOpt = getFollowerOpt(compList, compRace);
if (followerOpt == null) {
Logging.errorPrint(//$NON-NLS-1$
"Unable to find follower option for companion " + companion + " of race " + //$NON-NLS-1$
compRace);
return;
}
if (!followerOpt.qualifies(theCharacter, null)) {
Logging.errorPrint(//$NON-NLS-1$
"Not qualified to take companion " + companion + " of race " + //$NON-NLS-1$
compRace);
return;
}
// Update the companion with the master details
Logging.log(Logging.INFO, //$NON-NLS-1$
"Setting master to " + charDisplay.getName() + " for character " + //$NON-NLS-1$
compFacadeImpl);
final Follower newMaster = new Follower(charDisplay.getFileName(), charDisplay.getName(), compList);
newMaster.setAdjustment(followerOpt.getAdjustment());
compFacadeImpl.getTheCharacter().setMaster(newMaster);
compFacadeImpl.refreshClassLevelModel();
compFacadeImpl.postLevellingUpdates();
// Update the master with the new companion
File compFile = compFacadeImpl.getFileRef().get();
String compFilename = StringUtils.isEmpty(compFile.getPath()) ? "" : compFile.getAbsolutePath();
Follower follower = new Follower(compFilename, compFacadeImpl.getNameRef().get(), compList);
follower.setRace(compRace);
theCharacter.addFollower(follower);
theCharacter.setCalcFollowerBonus();
theCharacter.calcActiveBonuses();
pcFacade.postLevellingUpdates();
CompanionFacadeDelegate delegate = new CompanionFacadeDelegate();
delegate.setCompanionFacade(companion);
companionList.addElement(delegate);
// Watch companion file name and character name to update follower record
companion.getFileRef().addReferenceListener(new DelegateFileListener(follower));
companion.getNameRef().addReferenceListener(new DelegateNameListener(follower));
updateCompanionTodo(companionType);
}
Aggregations