Search in sources :

Example 41 with GameMode

use of pcgen.core.GameMode in project pcgen by PCGen.

the class CharacterFacadeImpl method refreshAvailableTempBonuses.

void refreshAvailableTempBonuses() {
    List<TempBonusFacadeImpl> tempBonuses = new ArrayList<>();
    // first objects on the PC
    for (CDOMObject cdo : theCharacter.getCDOMObjectList()) {
        scanForTempBonuses(tempBonuses, cdo);
    }
    //
    // next do all abilities to get TEMPBONUS:ANYPC only
    GameMode game = (GameMode) dataSet.getGameMode();
    for (AbilityCategory cat : game.getAllAbilityCategories()) {
        if (cat.getParentCategory() == cat) {
            for (Ability aFeat : Globals.getContext().getReferenceContext().getManufacturer(Ability.class, cat).getAllObjects()) {
                scanForAnyPcTempBonuses(tempBonuses, aFeat);
            }
        }
    }
    // Do all the PC's spells
    for (Spell aSpell : theCharacter.aggregateSpellList("", "", "", 0, 9)) {
        scanForTempBonuses(tempBonuses, aSpell);
    }
    // Do all the pc's innate spells.
    Collection<CharacterSpell> innateSpells = theCharacter.getCharacterSpells(charDisplay.getRace(), Constants.INNATE_SPELL_BOOK_NAME);
    for (CharacterSpell aCharacterSpell : innateSpells) {
        if (aCharacterSpell == null) {
            continue;
        }
        scanForTempBonuses(tempBonuses, aCharacterSpell.getSpell());
    }
    // Next do all spells to get TEMPBONUS:ANYPC or TEMPBONUS:EQUIP
    for (Spell spell : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(Spell.class)) {
        scanForNonPcTempBonuses(tempBonuses, spell);
    }
    // do all Templates to get TEMPBONUS:ANYPC or TEMPBONUS:EQUIP
    for (PCTemplate aTemp : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(PCTemplate.class)) {
        scanForNonPcTempBonuses(tempBonuses, aTemp);
    }
    Collections.sort(tempBonuses);
    availTempBonuses.updateContents(tempBonuses);
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) GameMode(pcgen.core.GameMode) CDOMObject(pcgen.cdom.base.CDOMObject) ArrayList(java.util.ArrayList) CharacterSpell(pcgen.core.character.CharacterSpell) PCTemplate(pcgen.core.PCTemplate) AbilityCategory(pcgen.core.AbilityCategory) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 42 with GameMode

use of pcgen.core.GameMode in project pcgen by PCGen.

the class VariableReport method runReport.

/**
	 * Produce the variable report in the requested formats.
	 * 
	 * @param reportNameMap A map of formats to be output and the names of 
	 * the files to contain the report for the format. 
	 * @throws IOException If the template cannot be accessed or the file cannot be written to.
	 * @throws TemplateException If there is an error in processing the template.
	 */
public void runReport(Map<ReportFormat, String> reportNameMap) throws IOException, TemplateException {
    List<GameMode> games = SystemCollections.getUnmodifiableGameModeList();
    Map<String, List<VarDefine>> gameModeVarMap = new TreeMap<>();
    Map<String, Integer> gameModeVarCountMap = new TreeMap<>();
    for (GameMode gameMode : games) {
        List<VarDefine> varList = new ArrayList<>();
        Map<String, Integer> varCountMap = new HashMap<>();
        Set<File> processedLstFiles = new HashSet<>();
        List<Campaign> campaignsForGameMode = getCampaignsForGameMode(gameMode);
        for (Campaign campaign : campaignsForGameMode) {
            processCampaign(campaign, varList, varCountMap, processedLstFiles);
        }
        Collections.sort(varList);
        gameModeVarMap.put(gameMode.getName(), varList);
        gameModeVarCountMap.put(gameMode.getName(), varCountMap.size());
    }
    for (Entry<ReportFormat, String> reportRequest : reportNameMap.entrySet()) {
        Writer file = new FileWriter(new File(reportRequest.getValue()));
        try {
            outputReport(gameModeVarMap, gameModeVarCountMap, reportRequest.getKey(), file);
        } finally {
            IOUtils.closeQuietly(file);
        }
    }
}
Also used : HashMap(java.util.HashMap) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) GameMode(pcgen.core.GameMode) Campaign(pcgen.core.Campaign) ArrayList(java.util.ArrayList) List(java.util.List) PCGFile(pcgen.io.PCGFile) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer) HashSet(java.util.HashSet)

Example 43 with GameMode

use of pcgen.core.GameMode in project pcgen by PCGen.

the class ClassLevelCommand method run.

/**
	 * Runs classlevel on the inStack. The parameter is popped
	 * off the {@code inStack}, and the variable's value is
	 * pushed back to the top of {@code inStack}.
	 * @param inStack the jep stack
	 * @throws ParseException
	 */
//Uses JEP, which doesn't use generics
@SuppressWarnings("unchecked")
@Override
public void run(final Stack inStack) throws ParseException {
    // check the stack
    checkStack(inStack);
    // get the parameter from the stack
    int paramCount = curNumberOfParameters;
    String applied = null;
    String className = null;
    if (paramCount > 2) {
        throw new ParseException("Invalid number of parameters");
    }
    if (paramCount >= 2) {
        String p2 = inStack.pop().toString();
        if (p2.startsWith("APPLIEDAS=")) {
            applied = p2.substring(10);
        }
    }
    if (paramCount >= 1) {
        String p1 = inStack.pop().toString();
        if (p1.startsWith("APPLIEDAS=")) {
            if (applied != null) {
                throw new ParseException("Formula had two APPLIEDAS= entries");
            }
            applied = p1.substring(10);
        } else {
            //Should be a class name
            className = p1;
        }
    }
    /*
		 * If there was no parameter showing the class, and this is used in a
		 * CLASS file, then use the class name
		 */
    if (className == null) {
        String src = variableSource;
        if (src.startsWith("CLASS:")) {
            className = src.substring(6);
        }
    }
    if (className == null) {
        throw new ParseException("Unable to determine class name");
    }
    PlayerCharacter pc = getPC();
    String cl = className;
    if (applied != null) {
        if ("NONEPIC".equalsIgnoreCase(applied)) {
            GameMode mode = SettingsHandler.getGame();
            //Add 1 since game mode is inclusive, but BEFORELEVEL is not!
            int limit = mode.getMaxNonEpicLevel() + 1;
            if (limit == Integer.MAX_VALUE) {
                throw new ParseException("Game Mode has no EPIC limit");
            }
            cl += ";BEFORELEVEL=" + limit;
        } else {
            throw new ParseException("Did not understand APPLIEDAS=" + applied);
        }
    }
    Double result = new Double(pc.getClassLevelString(cl, false));
    inStack.push(result);
}
Also used : GameMode(pcgen.core.GameMode) PlayerCharacter(pcgen.core.PlayerCharacter) ParseException(org.nfunk.jep.ParseException)

Example 44 with GameMode

use of pcgen.core.GameMode in project pcgen by PCGen.

the class PrerequisiteWriterTest method setUp.

@Override
protected void setUp() throws Exception {
    TestHelper.loadPlugins();
    Globals.setUseGUI(false);
    Globals.emptyLists();
    GameMode gamemode = new GameMode("3.5");
    SystemCollections.addToGameModeList(gamemode);
    GameModeFileLoader.addDefaultTabInfo(gamemode);
    SettingsHandler.setGame("3.5");
    Alignment.createAllAlignments();
    TestHelper.makeSizeAdjustments();
    FactKey.getConstant("IsPC", STR_MGR);
    FactKey.getConstant("LEGS", STR_MGR);
    FactSetKey.getConstant("PANTHEONS", STR_MGR);
}
Also used : GameMode(pcgen.core.GameMode)

Example 45 with GameMode

use of pcgen.core.GameMode in project pcgen by PCGen.

the class PreAlignParserTest method setUp.

@Before
public void setUp() throws Exception {
    Globals.setUseGUI(false);
    Globals.emptyLists();
    GameMode gamemode = new GameMode("3.5");
    GameModeFileLoader.addDefaultTabInfo(gamemode);
    SystemCollections.addToGameModeList(gamemode);
    SettingsHandler.setGame("3.5");
    Alignment.createAllAlignments();
}
Also used : GameMode(pcgen.core.GameMode) Before(org.junit.Before)

Aggregations

GameMode (pcgen.core.GameMode)58 PCStat (pcgen.core.PCStat)10 PlayerCharacter (pcgen.core.PlayerCharacter)8 File (java.io.File)7 Campaign (pcgen.core.Campaign)7 LoadContext (pcgen.rules.context.LoadContext)7 LevelInfo (pcgen.core.LevelInfo)6 Race (pcgen.core.Race)6 AbstractReferenceContext (pcgen.rules.context.AbstractReferenceContext)6 ArrayList (java.util.ArrayList)5 PCClass (pcgen.core.PCClass)5 BonusObj (pcgen.core.bonus.BonusObj)4 Before (org.junit.Before)3 Equipment (pcgen.core.Equipment)3 CampaignFacade (pcgen.facade.core.CampaignFacade)3 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 Writer (java.io.Writer)2 HashMap (java.util.HashMap)2 JLabel (javax.swing.JLabel)2