use of pcgen.cdom.content.LevelCommandFactory in project pcgen by PCGen.
the class AddLevelToken method unparse.
@Override
public String[] unparse(LoadContext context, PCTemplate pct) {
Changes<LevelCommandFactory> changes = context.getObjectContext().getListChanges(pct, ListKey.ADD_LEVEL);
Collection<LevelCommandFactory> added = changes.getAdded();
if (added == null || added.isEmpty()) {
return null;
}
List<String> list = new ArrayList<>();
for (LevelCommandFactory lcf : added) {
StringBuilder sb = new StringBuilder();
sb.append(lcf.getLSTformat()).append(Constants.PIPE).append(lcf.getLevelCount().toString());
list.add(sb.toString());
}
return list.toArray(new String[list.size()]);
}
use of pcgen.cdom.content.LevelCommandFactory in project pcgen by PCGen.
the class AddLevelFacet method dataAdded.
/**
* Drives the necessary results of an ADDLEVEL: token to apply the results
* to a Player Character.
*
* Triggered when one of the Facets to which AddLevelFacet listens fires a
* DataFacetChangeEvent to indicate a CDOMObject 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) {
PCTemplate template = dfce.getCDOMObject();
CharID id = dfce.getCharID();
PlayerCharacter pc = trackingFacet.getPC(id);
// character so don't apply them again.
if (!pc.isImporting()) {
for (LevelCommandFactory lcf : template.getSafeListFor(ListKey.ADD_LEVEL)) {
add(lcf.getLevelCount(), lcf.getPCClass(), pc);
}
}
}
use of pcgen.cdom.content.LevelCommandFactory in project pcgen by PCGen.
the class Gui2InfoFactory method getHTMLInfo.
/**
* @see pcgen.core.facade.InfoFactory#getHTMLInfo(pcgen.core.facade.RaceFacade)
*/
@Override
public String getHTMLInfo(RaceFacade raceFacade) {
if (!(raceFacade instanceof Race)) {
return EMPTY_STRING;
}
Race race = (Race) raceFacade;
final HtmlInfoBuilder infoText = new HtmlInfoBuilder();
if (!race.getKeyName().startsWith("<none")) {
infoText.appendTitleElement(OutputNameFormatting.piString(race, false));
infoText.appendLineBreak();
RaceType rt = race.get(ObjectKey.RACETYPE);
if (rt != null) {
//$NON-NLS-1$
infoText.appendI18nElement("in_irInfoRaceType", rt.toString());
}
List<RaceSubType> rst = race.getListFor(ListKey.RACESUBTYPE);
if (rst != null) {
infoText.appendSpacer();
//$NON-NLS-1$
infoText.appendI18nElement("in_irInfoSubType", StringUtil.join(rst, ", "));
}
if (!race.getType().isEmpty()) {
infoText.appendSpacer();
//$NON-NLS-1$
infoText.appendI18nElement("in_irInfoType", race.getType());
}
appendFacts(infoText, race);
infoText.appendLineBreak();
String size = race.getSize();
if (StringUtils.isNotEmpty(size)) {
//$NON-NLS-1$
infoText.appendI18nElement("in_size", size);
}
String movement = getMovement(raceFacade);
if (!movement.isEmpty()) {
infoText.appendSpacer();
//$NON-NLS-1$
infoText.appendI18nElement("in_movement", movement);
}
String vision = getVision(raceFacade);
if (!vision.isEmpty()) {
infoText.appendSpacer();
//$NON-NLS-1$
infoText.appendI18nElement("in_vision", vision);
}
String bString = PrerequisiteUtilities.preReqHTMLStringsForList(pc, null, race.getPrerequisiteList(), false);
if (!bString.isEmpty()) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nElement("in_requirements", bString);
}
String desc = pc.getDescription(race);
if (!desc.isEmpty()) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nFormattedElement(//$NON-NLS-1$
"in_InfoDescription", DescriptionFormatting.piWrapDesc(race, desc, false));
}
String statAdjustments = getStatAdjustments(raceFacade);
if (StringUtils.isNotEmpty(statAdjustments)) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nElement("in_irTableStat", statAdjustments);
}
LevelCommandFactory levelCommandFactory = race.get(ObjectKey.MONSTER_CLASS);
if (levelCommandFactory != null) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nFormattedElement(//$NON-NLS-1$
"in_irInfoMonsterClass", String.valueOf(levelCommandFactory.getLevelCount()), OutputNameFormatting.piString(levelCommandFactory.getPCClass(), false));
}
String favoredClass = getFavoredClass(raceFacade);
if (StringUtils.isNotEmpty(favoredClass)) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nElement("in_favoredClass", favoredClass);
}
bString = race.getSource();
if (!bString.isEmpty()) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nElement("in_sourceLabel", bString);
}
}
return infoText.toString();
}
use of pcgen.cdom.content.LevelCommandFactory in project pcgen by PCGen.
the class Gui2InfoFactory method getNumMonsterClassLevels.
@Override
public int getNumMonsterClassLevels(RaceFacade raceFacade) {
if (!(raceFacade instanceof Race)) {
return 0;
}
Race race = (Race) raceFacade;
LevelCommandFactory levelCommandFactory = race.get(ObjectKey.MONSTER_CLASS);
if (levelCommandFactory == null) {
return 0;
}
return levelCommandFactory.getLevelCount().resolve(pc, EMPTY_STRING).intValue();
}
use of pcgen.cdom.content.LevelCommandFactory in project pcgen by PCGen.
the class AddLevelTokenTest method testUnparseSingle.
@Test
public void testUnparseSingle() throws PersistenceLayerException {
primaryContext.getReferenceContext().constructCDOMObject(PCClass.class, "Fighter");
CDOMSingleRef<PCClass> cl = primaryContext.getReferenceContext().getCDOMReference(PCClass.class, "Fighter");
primaryProf.addToListFor(ListKey.ADD_LEVEL, new LevelCommandFactory(cl, FormulaFactory.getFormulaFor(4)));
String[] unparsed = getToken().unparse(primaryContext, primaryProf);
expectSingle(unparsed, "Fighter|4");
}
Aggregations