use of pcgen.core.character.Follower in project pcgen by PCGen.
the class FollowerTypeToken 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) {
// Handle FOLLOWERTYPE.<type>x.subtag stuff
// New token syntax FOLLOWERTYPE.<type>.x instead of FOLLOWERTYPE.<type>x
StringTokenizer aTok = new StringTokenizer(tokenSource, ".");
// FOLLOWERTYPE
aTok.nextToken();
String typeString = aTok.nextToken();
StringBuilder restString = new StringBuilder();
int followerIndex = -1;
if (aTok.hasMoreTokens()) {
String startString = aTok.nextToken();
// When removing old token syntax, remove the catch code
try {
followerIndex = Integer.parseInt(startString);
} catch (NumberFormatException exc) {
// Error, not debug. We want users to report
// use of the deprecated syntax so we can fix
// them as they are found.
Logging.errorPrint("Old syntax FOLLOWERTYPEx will be replaced for FOLLOWERTYPE.x");
restString.append(startString);
int numCharToRemove = 0;
for (int i = typeString.length() - 1; i > 0; i--) {
if ((typeString.charAt(i) >= '0') && (typeString.charAt(i) <= '9')) {
followerIndex = Integer.parseInt(typeString.substring(i));
numCharToRemove++;
} else {
i = 0;
}
}
if (numCharToRemove > 0) {
typeString = typeString.substring(0, typeString.length() - numCharToRemove);
}
}
while (aTok.hasMoreTokens()) {
restString.append('.').append(aTok.nextToken());
}
if (restString.indexOf(".") == 0) {
restString.deleteCharAt(0);
}
}
String result = "";
List<Follower> aList = getFollowersOfType(pc.getDisplay(), typeString);
if (followerIndex > -1 && followerIndex < aList.size()) {
result = FollowerToken.getFollowerOutput(eh, restString.toString(), aList.get(followerIndex));
}
return result;
}
use of pcgen.core.character.Follower in project pcgen by PCGen.
the class PlayerCharacter method clone.
/**
* Returns a deep copy of the PlayerCharacter. Note: This method does a
* shallow copy of many lists in here that seem to point to "system"
* objects. These copies should be validated before using this method.
*
* @return a new deep copy of the {@code PlayerCharacter}
*/
@Override
public PlayerCharacter clone() {
PlayerCharacter aClone = null;
// calling super.clone won't work because it will not create
// new data instances for all the final variables and I won't
// be able to reset them. Need to call new PlayerCharacter()
// aClone = (PlayerCharacter)super.clone();
aClone = new PlayerCharacter(campaignFacet.getSet(id));
//aClone.variableProcessor = new VariableProcessorPC(aClone);
try {
aClone.assocSupt = assocSupt.clone();
} catch (CloneNotSupportedException e) {
Logging.errorPrint("PlayerCharacter.clone failed", e);
}
Collection<AbstractStorageFacet> beans = SpringHelper.getStorageBeans();
for (AbstractStorageFacet bean : beans) {
bean.copyContents(id, aClone.id);
}
aClone.bonusManager = bonusManager.buildDeepClone(aClone);
for (PCClass cloneClass : aClone.classFacet.getSet(aClone.id)) {
cloneClass.addFeatPoolBonus(aClone);
}
Follower followerMaster = masterFacet.get(id);
if (followerMaster != null) {
aClone.masterFacet.set(id, followerMaster.clone());
} else {
aClone.masterFacet.remove(id);
}
aClone.equipSetFacet.removeAll(aClone.id);
for (EquipSet eqSet : equipSetFacet.getSet(id)) {
aClone.addEquipSet((EquipSet) eqSet.clone());
}
List<Equipment> equipmentMasterList = aClone.getEquipmentMasterList();
aClone.userEquipmentFacet.removeAll(aClone.id);
aClone.equipmentFacet.removeAll(aClone.id);
aClone.equippedFacet.removeAll(aClone.id);
FacetLibrary.getFacet(SourcedEquipmentFacet.class).removeAll(aClone.id);
for (Equipment equip : equipmentMasterList) {
aClone.addEquipment(equip.clone());
}
aClone.levelInfoFacet.removeAll(aClone.id);
for (PCLevelInfo info : getLevelInfo()) {
PCLevelInfo newLvlInfo = info.clone();
aClone.levelInfoFacet.add(aClone.id, newLvlInfo);
}
aClone.spellBookFacet.removeAll(aClone.id);
for (String book : spellBookFacet.getBookNames(id)) {
aClone.addSpellBook((SpellBook) spellBookFacet.getBookNamed(id, book).clone());
}
aClone.calcEquipSetId = calcEquipSetId;
aClone.tempBonusItemList.addAll(tempBonusItemList);
aClone.descriptionLst = descriptionLst;
aClone.autoKnownSpells = autoKnownSpells;
aClone.autoLoadCompanion = autoLoadCompanion;
aClone.autoSortGear = autoSortGear;
aClone.outputSheetHTML = outputSheetHTML;
aClone.outputSheetPDF = outputSheetPDF;
aClone.ageSetKitSelections = new boolean[10];
aClone.defaultDomainSource = defaultDomainSource;
System.arraycopy(ageSetKitSelections, 0, aClone.ageSetKitSelections, 0, ageSetKitSelections.length);
// Not sure what this is for
aClone.importing = false;
aClone.useTempMods = useTempMods;
aClone.costPool = costPool;
aClone.currentEquipSetNumber = currentEquipSetNumber;
aClone.poolAmount = poolAmount;
// order in which the skills will be output.
aClone.skillsOutputOrder = skillsOutputOrder;
aClone.spellLevelTemp = spellLevelTemp;
aClone.pointBuyPoints = pointBuyPoints;
aClone.adjustMoveRates();
//This mod set is necessary to trigger certain calculations to ensure correct output
//modSkillPointsBuffer = Integer.MIN_VALUE;
aClone.calcActiveBonuses();
//Just to be safe
aClone.equippedFacet.reset(aClone.id);
aClone.serial = serial;
return aClone;
}
use of pcgen.core.character.Follower 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.core.character.Follower 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.core.character.Follower 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