use of pcgen.core.Campaign in project pcgen by PCGen.
the class PCGVer2Parser method getCampaignList.
/**
* Retrieve a list of campaigns named on the supplied lines.
* @param lines The campaign lines from the PCG file.
* @param gameModeName The name of the charater's game mode.
* @return The list of campaigns.
* @throws PCGParseException
*/
private List<Campaign> getCampaignList(List<String> lines, String gameModeName) throws PCGParseException {
final List<Campaign> campaigns = new ArrayList<>();
for (final String line : lines) {
PCGTokenizer tokens;
try {
tokens = new PCGTokenizer(line);
} catch (PCGParseException pcgpex) {
/*
* Campaigns are critical for characters,
* need to stop the load process
*
* Thomas Behr 14-08-02
*/
throw new PCGParseException("parseCampaignLines", line, //$NON-NLS-1$
pcgpex.getMessage());
}
for (PCGElement element : tokens.getElements()) {
String sourceKey = SourceMigration.getNewSourceKey(element.getText(), pcgenVersion, gameModeName);
final Campaign aCampaign = Globals.getCampaignKeyed(sourceKey);
if (aCampaign != null) {
campaigns.add(aCampaign);
}
}
}
return campaigns;
}
use of pcgen.core.Campaign in project pcgen by PCGen.
the class ModifyLst method parseToken.
@Override
public ParseResult parseToken(LoadContext context, CDOMObject obj, String value) {
if (obj instanceof Campaign) {
return new ParseResult.Fail(getTokenName() + " may not be used in Campaign Files. " + "Please use the Global Modifier file", context);
}
ParsingSeparator sep = new ParsingSeparator(value, '|');
sep.addGroupingPair('[', ']');
sep.addGroupingPair('(', ')');
if (!sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " may not be empty", context);
}
String varName = sep.next();
if (!sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " needed 2nd argument: " + value, context);
}
String modIdentification = sep.next();
if (!sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " needed third argument: " + value, context);
}
String modInstructions = sep.next();
//Defaults to zero
int priorityNumber = 0;
if (sep.hasNext()) {
String priority = sep.next();
if (priority.length() < 10) {
return new ParseResult.Fail(getTokenName() + " was expecting PRIORITY= but got " + priority + " in " + value, context);
}
if ("PRIORITY=".equalsIgnoreCase(priority.substring(0, 9))) {
try {
priorityNumber = Integer.parseInt(priority.substring(9));
} catch (NumberFormatException e) {
return new ParseResult.Fail(getTokenName() + " requires Priority to be an integer: " + priority.substring(9) + " was not an integer");
}
if (priorityNumber < 0) {
return new ParseResult.Fail(getTokenName() + " Priority requires an integer >= 0. " + priorityNumber + " was not positive");
}
} else {
return new ParseResult.Fail(getTokenName() + " was expecting PRIORITY=x but got " + priority + " in " + value, context);
}
if (sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " had too many arguments: " + value, context);
}
}
ScopeInstance scopeInst = context.getActiveScope();
LegalScope scope = scopeInst.getLegalScope();
if (!context.getVariableContext().isLegalVariableID(scope, varName)) {
return new ParseResult.Fail(getTokenName() + " found invalid var name: " + varName + "(scope: " + scope.getName() + ") Modified on " + obj.getClass().getSimpleName() + ' ' + obj.getKeyName(), context);
}
FormatManager<?> format = context.getVariableContext().getVariableFormat(scope, varName);
return finishProcessing(context, obj, format, varName, modIdentification, modInstructions, priorityNumber);
}
use of pcgen.core.Campaign in project pcgen by PCGen.
the class PreCampaignTester method countCampaignByName.
/**
* Count the campaigns currently loaded or selected that match the
* supplied key name.
*
* @param key The key to be checked for
* @param includeSubCampaigns Should we count included sub campaigns that match
* @return The number of matching campaigns
*/
private int countCampaignByName(final String key, CDOMObject source, boolean includeSubCampaigns) {
int total = 0;
Campaign campaignToFind = Globals.getCampaignKeyedSilently(key);
if (campaignToFind != null) {
PersistenceManager pMan = PersistenceManager.getInstance();
List<URI> selCampaigns = pMan.getChosenCampaignSourcefiles();
for (URI element : selCampaigns) {
final Campaign aCampaign = Globals.getCampaignByURI(element, true);
if (includeSubCampaigns) {
List<Campaign> campList = getFullCampaignList(aCampaign);
for (Campaign camp : campList) {
if (camp.equals(campaignToFind)) {
++total;
}
}
} else {
if (aCampaign.equals(campaignToFind)) {
++total;
}
}
}
} else {
String sourceUri = (source == null ? "" : String.valueOf(source.getSourceURI()));
Logging.errorPrint(//$NON-NLS-1$
"Unable to find campaign " + key + " used in prereq for source " + source + //$NON-NLS-1$ //$NON-NLS-2$
" at " + sourceUri);
}
return total;
}
use of pcgen.core.Campaign in project pcgen by PCGen.
the class HiddenTypeFacet method loadCampaignHiddenTypes.
private void loadCampaignHiddenTypes(DataSetID id, Campaign c) {
loadHiddenTypes(id, ListKey.HIDDEN_Equipment, Equipment.class, c);
loadHiddenTypes(id, ListKey.HIDDEN_Ability, Ability.class, c);
loadHiddenTypes(id, ListKey.HIDDEN_Skill, Skill.class, c);
for (Campaign subCamp : c.getSubCampaigns()) {
loadCampaignHiddenTypes(id, subCamp);
}
}
Aggregations