use of pcgen.core.Deity in project pcgen by PCGen.
the class DeityTokenTest method testUnparseSingle.
@Test
public void testUnparseSingle() throws PersistenceLayerException {
Deity wp1 = construct(primaryContext, "TestWP1");
primaryProf.addToListFor(ListKey.DEITY, CDOMDirectSingleRef.getRef(wp1));
String[] unparsed = getToken().unparse(primaryContext, primaryProf);
expectSingle(unparsed, getLegalValue());
}
use of pcgen.core.Deity in project pcgen by PCGen.
the class PCGVer2Creator method appendDeityLine.
/*
* ###############################################################
* Character Deity/Domain methods
* ###############################################################
*/
private void appendDeityLine(StringBuilder buffer) {
if (charDisplay.getDeity() != null) {
final Deity aDeity = charDisplay.getDeity();
buffer.append(IOConstants.TAG_DEITY).append(':');
buffer.append(EntityEncoder.encode(aDeity.getKeyName()));
/*
* currently unused information
*
* author: Thomas Behr 09-09-02
*/
buffer.append('|');
buffer.append(IOConstants.TAG_DEITYDOMAINS).append(':');
buffer.append('[');
String del = Constants.EMPTY_STRING;
for (CDOMReference<Domain> ref : aDeity.getSafeListMods(Deity.DOMAINLIST)) {
for (Domain d : ref.getContainedObjects()) {
buffer.append(del);
buffer.append(IOConstants.TAG_DOMAIN).append(':');
buffer.append(EntityEncoder.encode(d.getKeyName()));
//$NON-NLS-1$
del = "|";
}
}
buffer.append(']');
buffer.append('|');
buffer.append(IOConstants.TAG_ALIGNALLOW).append(':');
//TODO Need to clean this up?
for (final Description desc : aDeity.getSafeListFor(ListKey.DESCRIPTION)) {
buffer.append('|');
buffer.append(IOConstants.TAG_DESC).append(':');
buffer.append(desc.getPCCText());
}
buffer.append('|');
buffer.append(IOConstants.TAG_DEITYFAVWEAP).append(':');
buffer.append('[');
List<CDOMReference<WeaponProf>> dwp = aDeity.getListFor(ListKey.DEITYWEAPON);
if (dwp != null) {
del = Constants.EMPTY_STRING;
for (CDOMReference<WeaponProf> ref : dwp) {
buffer.append(del);
buffer.append(IOConstants.TAG_WEAPON).append(':');
buffer.append(EntityEncoder.encode(ref.getLSTformat(false)));
//$NON-NLS-1$
del = "|";
}
}
buffer.append(']');
buffer.append('|');
buffer.append(IOConstants.TAG_DEITYALIGN).append(':');
CDOMSingleRef<PCAlignment> al = aDeity.get(ObjectKey.ALIGNMENT);
if (al != null) {
buffer.append(al.getLSTformat(false));
}
buffer.append(IOConstants.LINE_SEP);
}
}
use of pcgen.core.Deity in project pcgen by PCGen.
the class PCGVer2Parser method parseDeityLine.
/**
* ###############################################################
* Character Deity/Domain methods
* ###############################################################
* @param line
**/
private void parseDeityLine(final String line) {
final PCGTokenizer tokens;
try {
tokens = new PCGTokenizer(line);
} catch (PCGParseException pcgpex) {
final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.IllegalDeity", line, pcgpex.getMessage());
warnings.add(msg);
return;
}
final String deityKey = EntityEncoder.decode(tokens.getElements().get(0).getText());
Deity aDeity = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Deity.class, deityKey);
if (aDeity != null) {
thePC.setDeity(aDeity);
} else if (!Constants.NONE.equals(deityKey)) {
// TODO
// create Deity object from information contained in pcg
// for now issue a warning
final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.DeityNotFound", deityKey);
warnings.add(msg);
}
}
use of pcgen.core.Deity in project pcgen by PCGen.
the class PreDeityDomainTester method passes.
/**
* @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
*/
@Override
public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) {
int runningTotal = 0;
Deity deity = display.getDeity();
if (deity != null) {
if (deity.hasObjectOnList(Deity.DOMAINLIST, Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Domain.class, prereq.getKey()))) {
runningTotal++;
}
}
return countedTotal(prereq, runningTotal);
}
use of pcgen.core.Deity in project pcgen by PCGen.
the class AbilityRefChoiceSet method addMultiplySelectableAbility.
private Collection<CNAbilitySelection> addMultiplySelectableAbility(final PlayerCharacter aPC, Ability ability, String subName) {
boolean isPattern = false;
String nameRoot = null;
if (subName != null) {
final int percIdx = subName.indexOf('%');
if (percIdx > -1) {
isPattern = true;
nameRoot = subName.substring(0, percIdx);
} else if (!subName.isEmpty()) {
nameRoot = subName;
}
}
ChooseInformation<?> chooseInfo = ability.get(ObjectKey.CHOOSE_INFO);
final List<String> availableList = getAvailableList(aPC, chooseInfo);
/*
* TODO Need a general solution for this special assignment in parens
*/
if ("DEITYWEAPON".equals(nameRoot) && (chooseInfo != null) && chooseInfo.getClassIdentity().getChoiceClass().equals(WeaponProf.class)) {
Deity deity = aPC.getDeity();
if (deity == null) {
availableList.clear();
} else {
List<CDOMReference<WeaponProf>> dwp = deity.getSafeListFor(ListKey.DEITYWEAPON);
Set<String> set = new HashSet<>();
for (CDOMReference<WeaponProf> ref : dwp) {
for (WeaponProf wp : ref.getContainedObjects()) {
set.add(wp.getKeyName());
}
}
availableList.retainAll(set);
}
} else if (nameRoot != null && !nameRoot.isEmpty()) {
for (int n = availableList.size() - 1; n >= 0; --n) {
final String aString = availableList.get(n);
if (!aString.startsWith(nameRoot)) {
availableList.remove(n);
}
}
if (isPattern && !availableList.isEmpty()) {
availableList.add(nameRoot);
}
}
List<CNAbilitySelection> returnList = new ArrayList<>(availableList.size());
for (String s : availableList) {
returnList.add(new CNAbilitySelection(CNAbilityFactory.getCNAbility(category.get(), nature, ability), s));
}
return returnList;
}
Aggregations