Search in sources :

Example 81 with Campaign

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;
}
Also used : Campaign(pcgen.core.Campaign) ArrayList(java.util.ArrayList)

Example 82 with Campaign

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);
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) Campaign(pcgen.core.Campaign) ParsingSeparator(pcgen.base.text.ParsingSeparator) ParseResult(pcgen.rules.persistence.token.ParseResult) LegalScope(pcgen.base.formula.base.LegalScope)

Example 83 with Campaign

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;
}
Also used : Campaign(pcgen.core.Campaign) PersistenceManager(pcgen.persistence.PersistenceManager) URI(java.net.URI)

Example 84 with Campaign

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);
    }
}
Also used : Campaign(pcgen.core.Campaign)

Aggregations

Campaign (pcgen.core.Campaign)84 URI (java.net.URI)49 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)44 URISyntaxException (java.net.URISyntaxException)17 BeforeClass (org.junit.BeforeClass)16 LoadContext (pcgen.rules.context.LoadContext)16 ArrayList (java.util.ArrayList)14 PlayerCharacter (pcgen.core.PlayerCharacter)11 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)11 File (java.io.File)10 PCClass (pcgen.core.PCClass)10 PCClassLoader (pcgen.persistence.lst.PCClassLoader)10 UnreachableError (pcgen.base.lang.UnreachableError)9 Ability (pcgen.core.Ability)9 GameMode (pcgen.core.GameMode)7 SourceEntry (pcgen.persistence.lst.SourceEntry)7 Test (org.junit.Test)6 HashSet (java.util.HashSet)5 CampaignFacade (pcgen.facade.core.CampaignFacade)5 PCGFile (pcgen.io.PCGFile)5