use of pcgen.core.character.Follower in project pcgen by PCGen.
the class CompanionSupportFacadeImpl method removeCompanion.
@Override
public void removeCompanion(CompanionFacade companion) {
if (!(companion instanceof CompanionFacadeDelegate)) {
return;
}
File compFile = companion.getFileRef().get();
for (Follower follower : charDisplay.getFollowerList()) {
File followerFile = new File(follower.getFileName());
if (followerFile.equals(compFile)) {
theCharacter.delFollower(follower);
break;
}
}
companionList.removeElement((CompanionFacadeDelegate) companion);
updateCompanionTodo(companion.getCompanionType());
}
use of pcgen.core.character.Follower 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.core.character.Follower 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.core.character.Follower in project pcgen by PCGen.
the class CharacterFacadeImpl method getMaster.
@Override
public CharacterStubFacade getMaster() {
Follower master = charDisplay.getMaster();
if (master == null) {
return null;
}
CompanionNotLoaded stub = new CompanionNotLoaded(master.getName(), new File(master.getFileName()), master.getRace(), master.getType().getKeyName());
CharacterFacade masterFacade = CharacterManager.getCharacterMatching(stub);
if (masterFacade != null) {
return masterFacade;
}
return stub;
}
use of pcgen.core.character.Follower in project pcgen by PCGen.
the class FollowerToken method getToken.
/**
* @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
*/
@Override
public String getToken(String tokenSource, PlayerCharacter pc, ExportHandler eh) {
/* FOLLOWER%.subtag stuff handled in here*/
// New token syntax FOLLOWER.x instead of FOLLOWERx
StringTokenizer aTok = new StringTokenizer(tokenSource, ".");
// FOLLOWER
String fString = aTok.nextToken();
final int i;
if ("FOLLOWER".equals(fString)) {
i = Integer.parseInt(aTok.nextToken());
} else {
Logging.errorPrint("Old syntax FOLLOWERx will be replaced for FOLLOWER.x");
i = Integer.parseInt(tokenSource.substring(8, tokenSource.indexOf('.')));
}
StringBuilder restString = new StringBuilder();
while (aTok.hasMoreTokens()) {
restString.append(".").append(aTok.nextToken());
}
if (restString.indexOf(".") == 0) {
restString = restString.deleteCharAt(0);
}
String result = "";
final List<Follower> followers = new ArrayList<>(pc.getDisplay().getFollowerList());
if (i < followers.size()) {
result = FollowerToken.getFollowerOutput(eh, restString.toString(), followers.get(i));
}
return result;
}
Aggregations