Search in sources :

Example 1 with LevelInfo

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

the class LevelLoader method parseLine.

/**
	 * Parse the line from the level.lst file, populating the
	 * levelInfo object with the info found.
	 *
	 * @param gameMode  the game mode 
	 * @param inputLine  The line to be parsed
	 * @param lineNum    The number of the line being parsed.
	 */
public static String parseLine(GameMode gameMode, String inputLine, int lineNum, URI source, String xpTable) {
    if (gameMode == null) {
        return "";
    }
    // Deal with the start of a new XPTable definition
    if (inputLine.startsWith("XPTABLE:")) {
        String value = inputLine.substring(8);
        if (value.indexOf("\t") >= 0) {
            value = value.substring(0, value.indexOf("\t"));
        }
        value = value.trim();
        if (value.equals("")) {
            Logging.errorPrint("Error parsing level line \"" + inputLine + "\": empty XPTABLE value.");
        } else {
            value = value.intern();
            gameMode.addXPTableName(value);
            return value;
        }
    }
    // Provide a default fallback table name for backwards compatibility
    if (xpTable.equals("")) {
        xpTable = "Default";
        gameMode.addXPTableName(xpTable);
    }
    final LevelInfo levelInfo = new LevelInfo();
    final StringTokenizer colToken = new StringTokenizer(inputLine, SystemLoader.TAB_DELIM);
    Map<String, LstToken> tokenMap = TokenStore.inst().getTokenMap(LevelLstToken.class);
    while (colToken.hasMoreTokens()) {
        final String colString = colToken.nextToken().trim();
        final int idxColon = colString.indexOf(':');
        String key = "";
        try {
            key = colString.substring(0, idxColon);
        } catch (StringIndexOutOfBoundsException e) {
        // TODO Handle Exception
        }
        LevelLstToken token = (LevelLstToken) tokenMap.get(key);
        if (token != null) {
            final String value = colString.substring(idxColon + 1).intern();
            LstUtils.deprecationCheck(token, levelInfo.getLevelString(), source, value);
            if (!token.parse(levelInfo, value)) {
                Logging.errorPrint("LevelLoader got invalid " + key + " value of '" + value + "' in '" + inputLine + "' at line " + lineNum + " of " + source + ". Token ignored.");
            }
        } else {
            Logging.errorPrint("LevelLoader got unexpected token of '" + colString + "' at line " + lineNum + ". Token ignored.");
        }
    }
    if (validateLevelInfo(gameMode, xpTable, levelInfo, inputLine, lineNum, source)) {
        gameMode.addLevelInfo(xpTable, levelInfo);
    }
    return xpTable;
}
Also used : StringTokenizer(java.util.StringTokenizer) LevelInfo(pcgen.core.LevelInfo)

Example 2 with LevelInfo

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

the class ExportHandlerTest method setUp.

/**
	 * @see pcgen.AbstractCharacterTestCase#setUp()
	 */
@Override
protected void setUp() throws Exception {
    super.setUp();
    PlayerCharacter character = getCharacter();
    LoadContext context = Globals.getContext();
    final LevelInfo levelInfo = new LevelInfo();
    levelInfo.setLevelString("LEVEL");
    levelInfo.setMaxClassSkillString("LEVEL+3");
    levelInfo.setMaxCrossClassSkillString("(LEVEL+3)/2");
    GameMode gamemode = SettingsHandler.getGame();
    gamemode.addLevelInfo("Default", levelInfo);
    //Stats
    setPCStat(character, dex, 16);
    setPCStat(character, intel, 17);
    BonusObj aBonus = Bonus.newBonus(context, "MODSKILLPOINTS|NUMBER|INT");
    if (aBonus != null) {
        intel.addToListFor(ListKey.BONUS, aBonus);
    }
    // Race
    Race testRace = new Race();
    testRace.setName("TestRace");
    character.setRace(testRace);
    // Class
    PCClass myClass = new PCClass();
    myClass.setName("My Class");
    myClass.put(FormulaKey.START_SKILL_POINTS, FormulaFactory.getFormulaFor(3));
    character.incrementClassLevel(5, myClass, true);
    // Skills
    knowledge = new Skill[2];
    knowledge[0] = new Skill();
    context.unconditionallyProcess(knowledge[0], "CLASSES", "MyClass");
    knowledge[0].setName("KNOWLEDGE (ARCANA)");
    TestHelper.addType(knowledge[0], "KNOWLEDGE.INT");
    CDOMDirectSingleRef<PCStat> intelRef = CDOMDirectSingleRef.getRef(intel);
    knowledge[0].put(ObjectKey.KEY_STAT, intelRef);
    character.setSkillOrder(knowledge[0], 2);
    Globals.getContext().getReferenceContext().importObject(knowledge[0]);
    SkillRankControl.modRanks(8.0, myClass, true, character, knowledge[0]);
    knowledge[1] = new Skill();
    context.unconditionallyProcess(knowledge[1], "CLASSES", "MyClass");
    knowledge[1].setName("KNOWLEDGE (RELIGION)");
    TestHelper.addType(knowledge[1], "KNOWLEDGE.INT");
    knowledge[1].put(ObjectKey.KEY_STAT, intelRef);
    character.setSkillOrder(knowledge[1], 3);
    Globals.getContext().getReferenceContext().importObject(knowledge[1]);
    SkillRankControl.modRanks(5.0, myClass, true, character, knowledge[1]);
    tumble = new Skill();
    context.unconditionallyProcess(tumble, "CLASSES", "MyClass");
    tumble.setName("Tumble");
    tumble.addToListFor(ListKey.TYPE, Type.getConstant("DEX"));
    CDOMDirectSingleRef<PCStat> dexRef = CDOMDirectSingleRef.getRef(dex);
    tumble.put(ObjectKey.KEY_STAT, dexRef);
    character.setSkillOrder(tumble, 4);
    Globals.getContext().getReferenceContext().importObject(tumble);
    SkillRankControl.modRanks(7.0, myClass, true, character, tumble);
    balance = new Skill();
    context.unconditionallyProcess(balance, "CLASSES", "MyClass");
    balance.setName("Balance");
    balance.addToListFor(ListKey.TYPE, Type.getConstant("DEX"));
    balance.put(ObjectKey.KEY_STAT, dexRef);
    character.setSkillOrder(balance, 1);
    aBonus = Bonus.newBonus(context, "SKILL|Balance|2|PRESKILL:1,Tumble=5|TYPE=Synergy.STACK");
    if (aBonus != null) {
        balance.addToListFor(ListKey.BONUS, aBonus);
    }
    Globals.getContext().getReferenceContext().importObject(balance);
    SkillRankControl.modRanks(4.0, myClass, true, character, balance);
    character.calcActiveBonuses();
    weapon = new Equipment();
    weapon.setName("TestWpn");
    weapon.addToListFor(ListKey.TYPE, Type.WEAPON);
    gem = new Equipment();
    gem.setName("TestGem");
    gem.addToListFor(ListKey.TYPE, Type.getConstant("gem"));
    gem.setQty(1);
    armor = new Equipment();
    armor.setName("TestArmorSuit");
    TestHelper.addType(armor, "armor.suit");
    context.getReferenceContext().buildDerivedObjects();
    context.getReferenceContext().resolveReferences(null);
}
Also used : GameMode(pcgen.core.GameMode) Skill(pcgen.core.Skill) PlayerCharacter(pcgen.core.PlayerCharacter) BonusObj(pcgen.core.bonus.BonusObj) Equipment(pcgen.core.Equipment) LevelInfo(pcgen.core.LevelInfo) Race(pcgen.core.Race) LoadContext(pcgen.rules.context.LoadContext) PCClass(pcgen.core.PCClass) PCStat(pcgen.core.PCStat)

Example 3 with LevelInfo

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

the class XPTableFacetTest method testGetLevelInfoWrongLevel.

@Test
public void testGetLevelInfoWrongLevel() {
    XPTable t1 = getItem();
    LevelInfo li = new LevelInfo();
    t1.addLevelInfo("2", li);
    CharID id = getCharID();
    facet.set(id, t1);
    LevelInfo xpt = facet.getLevelInfo(id, 1);
    assertNull(xpt);
}
Also used : XPTable(pcgen.core.XPTable) LevelInfo(pcgen.core.LevelInfo) CharID(pcgen.cdom.enumeration.CharID) AbstractItemFacetTest(pcgen.cdom.testsupport.AbstractItemFacetTest) Test(org.junit.Test)

Example 4 with LevelInfo

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

the class XPTableFacetTest method testGetLevelInfoLevel.

@Test
public void testGetLevelInfoLevel() {
    XPTable t1 = getItem();
    LevelInfo li = new LevelInfo();
    t1.addLevelInfo("LEVEL", li);
    CharID id = getCharID();
    facet.set(id, t1);
    LevelInfo xpt = facet.getLevelInfo(id, 1);
    assertNotNull(xpt);
    assertSame(li, xpt);
}
Also used : XPTable(pcgen.core.XPTable) LevelInfo(pcgen.core.LevelInfo) CharID(pcgen.cdom.enumeration.CharID) AbstractItemFacetTest(pcgen.cdom.testsupport.AbstractItemFacetTest) Test(org.junit.Test)

Example 5 with LevelInfo

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

the class AbstractJunit4CharacterTestCase method setUp.

/**
	 * Sets up the absolute minimum amount of data to create a PlayerCharacter
	 * Object.
	 * @throws Exception
	 */
@Before
public void setUp() throws Exception {
    TestHelper.loadPlugins();
    final GameMode gamemode = new GameMode("3.5");
    gamemode.setBonusFeatLevels("3|3");
    gamemode.setAlignmentText("Alignment");
    final LevelInfo levelInfo = new LevelInfo();
    levelInfo.setLevelString("LEVEL");
    levelInfo.setMaxClassSkillString("LEVEL+3");
    levelInfo.setMaxCrossClassSkillString("(LEVEL+3)/2");
    gamemode.addLevelInfo("Normal", levelInfo);
    gamemode.addXPTableName("Normal");
    gamemode.setDefaultXPTableName("Normal");
    LoadInfo loadable = gamemode.getModeContext().getReferenceContext().constructNowIfNecessary(LoadInfo.class, gamemode.getName());
    loadable.addLoadScoreValue(0, BigDecimal.ONE);
    GameModeFileLoader.addDefaultTabInfo(gamemode);
    SystemCollections.addToGameModeList(gamemode);
    SettingsHandler.setGame("3.5");
    Globals.setUseGUI(false);
    Globals.emptyLists();
    str = BuildUtilities.createStat("Strength", "STR");
    str.put(VariableKey.getConstant("LOADSCORE"), FormulaFactory.getFormulaFor("STRSCORE"));
    str.put(VariableKey.getConstant("OFFHANDLIGHTBONUS"), FormulaFactory.getFormulaFor(2));
    str.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
    str.put(VariableKey.getConstant("MAXLEVELSTAT=" + str.getKeyName()), FormulaFactory.getFormulaFor(str.getKeyName() + "SCORE-10"));
    dex = BuildUtilities.createStat("Dexterity", "DEX");
    dex.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
    dex.put(VariableKey.getConstant("MAXLEVELSTAT=" + dex.getKeyName()), FormulaFactory.getFormulaFor(dex.getKeyName() + "SCORE-10"));
    PCStat con = BuildUtilities.createStat("Constitution", "CON");
    con.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
    con.put(VariableKey.getConstant("MAXLEVELSTAT=" + con.getKeyName()), FormulaFactory.getFormulaFor(con.getKeyName() + "SCORE-10"));
    intel = BuildUtilities.createStat("Intelligence", "INT");
    intel.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
    intel.put(VariableKey.getConstant("MAXLEVELSTAT=" + intel.getKeyName()), FormulaFactory.getFormulaFor(intel.getKeyName() + "SCORE-10"));
    wis = BuildUtilities.createStat("Wisdom", "WIS");
    wis.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
    wis.put(VariableKey.getConstant("MAXLEVELSTAT=" + wis.getKeyName()), FormulaFactory.getFormulaFor(wis.getKeyName() + "SCORE-10"));
    cha = BuildUtilities.createStat("Charisma", "CHA");
    cha.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
    cha.put(VariableKey.getConstant("MAXLEVELSTAT=" + cha.getKeyName()), FormulaFactory.getFormulaFor(cha.getKeyName() + "SCORE-10"));
    gamemode.setBonusFeatLevels("3|3");
    SettingsHandler.setGame("3.5");
    LoadContext context = Globals.getContext();
    AbstractReferenceContext ref = context.getReferenceContext();
    lg = BuildUtilities.createAlignment("Lawful Good", "LG");
    ref.importObject(lg);
    ln = BuildUtilities.createAlignment("Lawful Neutral", "LN");
    ref.importObject(ln);
    le = BuildUtilities.createAlignment("Lawful Evil", "LE");
    ref.importObject(le);
    ng = BuildUtilities.createAlignment("Neutral Good", "NG");
    ref.importObject(ng);
    tn = BuildUtilities.createAlignment("True Neutral", "TN");
    ref.importObject(tn);
    ne = BuildUtilities.createAlignment("Neutral Evil", "NE");
    ref.importObject(ne);
    cg = BuildUtilities.createAlignment("Chaotic Good", "CG");
    ref.importObject(cg);
    cn = BuildUtilities.createAlignment("Chaotic Neutral", "CN");
    ref.importObject(cn);
    ce = BuildUtilities.createAlignment("Chaotic Evil", "CE");
    ref.importObject(ce);
    ref.importObject(BuildUtilities.createAlignment("None", "NONE"));
    ref.importObject(BuildUtilities.createAlignment("Deity's", "Deity"));
    GameModeFileLoader.addDefaultWieldCategories(context);
    ref.importObject(str);
    ref.importObject(dex);
    ref.importObject(con);
    ref.importObject(intel);
    ref.importObject(wis);
    ref.importObject(cha);
    ref.constructCDOMObject(Language.class, "All Language For Test");
    BuildUtilities.createFact(context, "ClassType", PCClass.class);
    FactDefinition<?, String> fd = BuildUtilities.createFact(context, "SpellType", PCClass.class);
    fd.setSelectable(true);
    fine = BuildUtilities.createSize("Fine", 0);
    diminutive = BuildUtilities.createSize("Diminutive", 1);
    tiny = BuildUtilities.createSize("Tiny", 2);
    small = BuildUtilities.createSize("Small", 3);
    medium = BuildUtilities.createSize("Medium", 4);
    medium.put(ObjectKey.IS_DEFAULT_SIZE, true);
    large = BuildUtilities.createSize("Large", 5);
    huge = BuildUtilities.createSize("Huge", 6);
    gargantuan = BuildUtilities.createSize("Gargantuan", 7);
    colossal = BuildUtilities.createSize("Colossal", 8);
    SourceFileLoader.createLangBonusObject(context);
    GameModeFileLoader.addDefaultUnitSet(SettingsHandler.getGame());
    SettingsHandler.getGame().selectDefaultUnitSet();
    ref.importObject(AbilityCategory.FEAT);
    SourceFileLoader.processFactDefinitions(context);
    additionalSetUp();
    if (!ref.resolveReferences(null)) {
        fail("Unconstructed References");
    }
    context.resolvePostValidationTokens();
    context.resolvePostDeferredTokens();
    context.loadCampaignFacets();
    character = new PlayerCharacter();
}
Also used : GameMode(pcgen.core.GameMode) LoadInfo(pcgen.core.system.LoadInfo) PlayerCharacter(pcgen.core.PlayerCharacter) AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext) LevelInfo(pcgen.core.LevelInfo) LoadContext(pcgen.rules.context.LoadContext) PCStat(pcgen.core.PCStat) Before(org.junit.Before)

Aggregations

LevelInfo (pcgen.core.LevelInfo)11 GameMode (pcgen.core.GameMode)6 XPTable (pcgen.core.XPTable)5 PCStat (pcgen.core.PCStat)4 PlayerCharacter (pcgen.core.PlayerCharacter)4 LoadContext (pcgen.rules.context.LoadContext)4 Test (org.junit.Test)3 CharID (pcgen.cdom.enumeration.CharID)3 AbstractItemFacetTest (pcgen.cdom.testsupport.AbstractItemFacetTest)3 PCClass (pcgen.core.PCClass)3 Race (pcgen.core.Race)3 Skill (pcgen.core.Skill)3 BonusObj (pcgen.core.bonus.BonusObj)3 LoadInfo (pcgen.core.system.LoadInfo)2 StringTokenizer (java.util.StringTokenizer)1 Before (org.junit.Before)1 Equipment (pcgen.core.Equipment)1 PCLevelInfo (pcgen.core.pclevelinfo.PCLevelInfo)1 AbstractReferenceContext (pcgen.rules.context.AbstractReferenceContext)1