use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.
the class TemplateFeatFacet method dataRemoved.
/**
* Removes all of the feats granted by FEAT: on the PCTemplate removed
*
* Triggered when one of the Facets to which ConditionalTemplateFacet
* listens fires a DataFacetChangeEvent to indicate a PCTemplate was removed
* from a Player Character.
*
* @param dfce
* The DataFacetChangeEvent containing the information about the
* change
*
* @see pcgen.cdom.facet.event.DataFacetChangeListener#dataRemoved(pcgen.cdom.facet.event.DataFacetChangeEvent)
*/
@Override
public void dataRemoved(DataFacetChangeEvent<CharID, PCTemplate> dfce) {
CharID id = dfce.getCharID();
PCTemplate source = dfce.getCDOMObject();
PersistentTransitionChoice<CNAbilitySelection> choice = source.get(ObjectKey.TEMPLATE_FEAT);
if (choice != null) {
PlayerCharacter pc = trackingFacet.getPC(id);
choice.remove(source, pc);
}
removeAll(id, source);
}
use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.
the class TemplateFeatFacet method dataAdded.
/**
* Adds all of the feats to the Player Character triggered by the FEAT token'
* on the given PCTemplate
*
* Triggered when one of the Facets to which ConditionalTemplateFacet
* listens fires a DataFacetChangeEvent to indicate a PCTemplate 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, PCTemplate> dfce) {
CharID id = dfce.getCharID();
PCTemplate source = dfce.getCDOMObject();
if (!containsFrom(id, source)) {
PersistentTransitionChoice<CNAbilitySelection> choice = source.get(ObjectKey.TEMPLATE_FEAT);
if (choice != null) {
PlayerCharacter pc = trackingFacet.getPC(id);
Collection<? extends CNAbilitySelection> result = choice.driveChoice(pc);
choice.act(result, source, pc);
for (CNAbilitySelection cas : result) {
add(id, cas, source);
}
}
}
}
use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.
the class PCGVer2Creator method appendAbilityLines.
/*
* ###############################################################
* Character Ability methods
* ###############################################################
*/
private void appendAbilityLines(StringBuilder buffer) {
ArrayList<AbilityCategory> categories = new ArrayList<>(getGameMode().getAllAbilityCategories());
categories.add(AbilityCategory.LANGBONUS);
Collection<CNAbilitySelection> virtSave = thePC.getSaveAbilities();
categories.sort(new Comparator<AbilityCategory>() {
@Override
public int compare(AbilityCategory a, AbilityCategory b) {
return a.getKeyName().compareTo(b.getKeyName());
}
});
for (final AbilityCategory cat : categories) {
final List<CNAbility> normalAbilitiesToSave = new ArrayList<>(thePC.getPoolAbilities(cat, Nature.NORMAL));
// ABILITY:FEAT|NORMAL|Feat Key|APPLIEDTO:xxx|TYPE:xxx|SAVE:xxx|DESC:xxx
Collections.sort(normalAbilitiesToSave);
for (final CNAbility ability : normalAbilitiesToSave) {
writeAbilityToBuffer(buffer, ability);
}
boolean hasVirt = false;
for (final CNAbilitySelection ability : virtSave) {
CNAbility cnAbility = ability.getCNAbility();
if (cnAbility.getAbilityCategory().equals(cat)) {
//TODO Need to write each CNAbility only once :/
writeAbilityToBuffer(buffer, cnAbility);
hasVirt = true;
}
}
if (!normalAbilitiesToSave.isEmpty() || hasVirt || thePC.getUserPoolBonus(cat) != 0.0) {
buffer.append(IOConstants.TAG_USERPOOL).append(IOConstants.TAG_END);
buffer.append(EntityEncoder.encode(cat.getKeyName())).append(IOConstants.TAG_SEPARATOR);
buffer.append(IOConstants.TAG_POOLPOINTS).append(IOConstants.TAG_END);
buffer.append(thePC.getUserPoolBonus(cat));
buffer.append(IOConstants.LINE_SEP);
}
}
}
use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.
the class PCGVer2Creator method writeTemplateFeat.
private void writeTemplateFeat(StringBuilder aString, PCTemplate pct, List<? extends CNAbilitySelection> featList) {
for (CNAbilitySelection s : featList) {
if (aString.length() != 0) {
aString.append('|');
}
String featKey = Compatibility.getKeyFor(pct);
aString.append(IOConstants.TAG_CHOSENFEAT).append(':');
aString.append('[');
aString.append(IOConstants.TAG_MAPKEY).append(':').append(EntityEncoder.encode(featKey)).append('|');
aString.append(IOConstants.TAG_MAPVALUE).append(':').append(EntityEncoder.encode(s.getPersistentFormat()));
aString.append(']');
}
}
use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.
the class PCGVer2Parser method parseTemplateLine.
/*
* ###############################################################
* Character Templates methods
* ###############################################################
*/
private void parseTemplateLine(final String line) throws PCGParseException {
if (line.charAt(IOConstants.TAG_TEMPLATESAPPLIED.length() + 1) == '[') {
final PCGTokenizer tokens;
try {
tokens = new PCGTokenizer(line);
} catch (PCGParseException pcgpex) {
final String message = "Illegal Template line ignored: " + line + Constants.LINE_SEPARATOR + "Error: " + pcgpex.getMessage();
warnings.add(message);
return;
}
PCTemplate aPCTemplate = null;
Iterator<PCGElement> it = tokens.getElements().iterator();
if (it.hasNext()) {
final PCGElement element = it.next();
String assoc = null;
//Must deal with APPLIEDTO first (before item is added to the PC)
for (final PCGElement child : element.getChildren()) {
String childTag = child.getName();
if (IOConstants.TAG_NAME.equals(childTag)) {
aPCTemplate = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, EntityEncoder.decode(child.getText()));
if (aPCTemplate == null) {
break;
}
} else if (IOConstants.TAG_APPLIEDTO.equals(childTag)) {
assoc = child.getText();
}
}
for (final PCGElement child : element.getChildren()) {
final String childTag = child.getName();
if (IOConstants.TAG_NAME.equals(childTag)) {
if (aPCTemplate == null) {
break;
}
addKeyedTemplate(aPCTemplate, assoc);
} else if (IOConstants.TAG_CHOSENFEAT.equals(childTag)) {
String mapKey = null;
String mapValue = null;
for (PCGElement subChild : child.getChildren()) {
final String subChildTag = subChild.getName();
if (IOConstants.TAG_MAPKEY.equals(subChildTag)) {
mapKey = subChild.getText();
} else if (IOConstants.TAG_MAPVALUE.equals(subChildTag)) {
mapValue = subChild.getText();
}
}
if ((mapKey != null) && (mapValue != null)) {
String feat = EntityEncoder.decode(mapValue);
PCTemplate subt = Compatibility.getTemplateFor(aPCTemplate, EntityEncoder.decode(mapKey), feat);
if (subt != null) {
CNAbilitySelection as = CNAbilitySelection.getAbilitySelectionFromPersistentFormat(feat);
thePC.addTemplateFeat(subt, as);
}
}
} else if (IOConstants.TAG_CHOSENTEMPLATE.equals(childTag)) {
for (PCGElement subChild : child.getChildren()) {
final String subChildTag = subChild.getName();
if (IOConstants.TAG_NAME.equals(subChildTag)) {
final String ownedTemplateKey = EntityEncoder.decode(subChild.getText());
final PCTemplate ownedTemplate = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, ownedTemplateKey);
if (ownedTemplate != null) {
thePC.setTemplatesAdded(aPCTemplate, ownedTemplate);
}
}
}
} else //Add handled below, AppliedTo handled in the first loop
if (!IOConstants.TAG_ADDTOKEN.equals(childTag) && !IOConstants.TAG_APPLIEDTO.equals(childTag)) {
final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.UnknownTemplateInfo", childTag + ":" + child.getText());
warnings.add(msg);
}
}
}
//Must process ADD after Template is added to the PC
for (PCGElement e : new PCGTokenizer(line).getElements()) {
String tag = e.getName();
if (tag.equals(IOConstants.TAG_ADDTOKEN)) {
parseAddTokenInfo(e, aPCTemplate);
}
}
} else {
String key = EntityEncoder.decode(line.substring(IOConstants.TAG_TEMPLATESAPPLIED.length() + 1));
PCTemplate aPCTemplate = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, key);
addKeyedTemplate(aPCTemplate, null);
}
}
Aggregations