use of pcgen.core.PCAlignment in project pcgen by PCGen.
the class GlobalQualifyTest method testFromAlignment.
@Override
@Test
public void testFromAlignment() throws PersistenceLayerException {
PCAlignment source = create(PCAlignment.class, "Source");
ParseResult result = token.parseToken(context, source, "RACE|Dwarf");
assertFalse(result.passed());
}
use of pcgen.core.PCAlignment in project pcgen by PCGen.
the class CharacterFacadeImpl method validateAlignmentChange.
/**
* Validate the new alignment matches those allowed for the character's
* classes. If not offer the user a choice of backing out or making the
* classes into ex-classes.
*
* @param newAlign The alignment to be set
*/
private boolean validateAlignmentChange(AlignmentFacade newAlign) {
AlignmentFacade oldAlign = this.alignment.get();
if (oldAlign == null || newAlign.equals(oldAlign)) {
return true;
}
// We can't do any validation if the new alignment isn't a known class
if (!(newAlign instanceof PCAlignment)) {
return true;
}
//
// Get a list of classes that will become unqualified (and have an ex-class)
//
StringBuilder unqualified = new StringBuilder(100);
List<PCClass> classList = charDisplay.getClassList();
List<PCClass> exclassList = new ArrayList<>();
PCAlignment savedAlignmnet = charDisplay.getPCAlignment();
for (PCClass aClass : classList) {
theCharacter.setAlignment((PCAlignment) newAlign);
{
if (!theCharacter.isQualified(aClass)) {
if (aClass.containsKey(ObjectKey.EX_CLASS)) {
if (unqualified.length() > 0) {
//$NON-NLS-1$
unqualified.append(", ");
}
unqualified.append(aClass.getKeyName());
exclassList.add(aClass);
}
}
}
}
//
if (unqualified.length() > 0) {
if (!delegate.showWarningConfirm(Constants.APPLICATION_NAME, LanguageBundle.getString("in_sumExClassesWarning") + Constants.LINE_SEPARATOR + unqualified)) {
theCharacter.setAlignment(savedAlignmnet);
return false;
}
}
//
for (PCClass aClass : exclassList) {
theCharacter.makeIntoExClass(aClass);
}
// Update the facade and UI
refreshClassLevelModel();
return true;
}
use of pcgen.core.PCAlignment in project pcgen by PCGen.
the class KitAlignment method toString.
@Override
public String toString() {
if (alignments == null || alignments.isEmpty()) {
//CONSIDER can this ever happen and not be an error that should be caught at LST load?
return "";
}
if (alignments.size() == 1) {
return alignments.get(0).get().getDisplayName();
} else {
// Build the string list.
StringBuilder buf = new StringBuilder();
buf.append("One of (");
boolean needComma = false;
for (CDOMSingleRef<PCAlignment> alref : alignments) {
PCAlignment al = alref.get();
if (needComma) {
buf.append(", ");
}
needComma = true;
buf.append(al.getDisplayName());
}
buf.append(")");
return buf.toString();
}
}
use of pcgen.core.PCAlignment in project pcgen by PCGen.
the class DeityToken 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) {
String retString = "";
CharacterDisplay display = pc.getDisplay();
Deity deity = display.getDeity();
if (deity != null) {
StringTokenizer aTok = new StringTokenizer(tokenSource, ".", false);
String subTag = "OUTPUTNAME";
if (aTok.countTokens() > 1) {
aTok.nextToken();
subTag = aTok.nextToken();
}
if ("NAME".equals(subTag)) {
if (!display.getSuppressBioField(BiographyField.DEITY)) {
retString = deity.getDisplayName();
}
} else if ("OUTPUTNAME".equals(subTag)) {
if (!display.getSuppressBioField(BiographyField.DEITY)) {
retString = OutputNameFormatting.getOutputName(deity);
}
} else if ("DOMAINLIST".equals(subTag)) {
retString = getDomainListToken(deity);
} else if ("FOLLOWERALIGNMENT".equals(subTag)) {
Logging.errorPrint("Output Sheet uses DEITY.FOLLOWERALIGN: " + "Function has been removed from PCGen");
} else if ("ALIGNMENT".equals(subTag)) {
CDOMSingleRef<PCAlignment> al = deity.get(ObjectKey.ALIGNMENT);
retString = al == null ? "" : al.get().getKeyName();
} else if ("APPEARANCE".equals(subTag)) {
FactKey<String> fk = FactKey.valueOf("Appearance");
String str = deity.getResolved(fk);
retString = (str == null) ? "" : str;
} else if ("DESCRIPTION".equals(subTag)) {
retString = pc.getDescription(deity);
} else if ("HOLYITEM".equals(subTag)) {
FactKey<String> fk = FactKey.valueOf("Symbol");
String str = deity.getResolved(fk);
retString = (str == null) ? "" : str;
} else if ("FAVOREDWEAPON".equals(subTag)) {
List<CDOMReference<WeaponProf>> dwp = deity.getSafeListFor(ListKey.DEITYWEAPON);
retString = ReferenceUtilities.joinLstFormat(dwp, Constants.PIPE, true);
} else if ("PANTHEONLIST".equals(subTag)) {
FactSetKey<String> fk = FactSetKey.valueOf("Pantheon");
Set<String> pset = new TreeSet<>();
for (Indirect<String> indirect : deity.getSafeSetFor(fk)) {
pset.add(indirect.get());
}
retString = StringUtil.join(pset, ", ");
} else if ("SOURCE".equals(subTag)) {
retString = SourceFormat.getFormattedString(deity, Globals.getSourceDisplay(), true);
} else if ("SA".equals(subTag)) {
retString = getSAToken(deity, display);
} else if ("TITLE".equals(subTag)) {
FactKey<String> fk = FactKey.valueOf("Title");
String str = deity.getResolved(fk);
retString = (str == null) ? "" : str;
} else if ("WORSHIPPERS".equals(subTag)) {
FactKey<String> fk = FactKey.valueOf("Worshippers");
String str = deity.getResolved(fk);
retString = (str == null) ? "" : str;
}
}
return retString;
}
use of pcgen.core.PCAlignment in project pcgen by PCGen.
the class AlignTokenTest method setUp.
@Override
public void setUp() throws PersistenceLayerException, URISyntaxException {
super.setUp();
PCAlignment lg = BuildUtilities.createAlignment("Lawful Good", "LG");
primaryContext.getReferenceContext().importObject(lg);
PCAlignment slg = BuildUtilities.createAlignment("Lawful Good", "LG");
secondaryContext.getReferenceContext().importObject(slg);
TokenRegistration.register(ALIGN_TOKEN);
}
Aggregations