Search in sources :

Example 6 with LevelCommandFactory

use of pcgen.cdom.content.LevelCommandFactory in project pcgen by PCGen.

the class EncounterPlugin method handleTransferToTracker.

/**
	 * Handles the <b>Begin Combat</b> button.
	 */
public void handleTransferToTracker() {
    int i;
    PlayerCharacter aPC;
    JFrame oldRoot = Globals.getRootFrame();
    Globals.setRootFrame(GMGenSystem.inst);
    theModel.setPCs(theModel.size());
    try {
        for (i = 0; i < theModel.size(); i++) {
            aPC = theModel.getPCs()[i];
            aPC.setImporting(false);
            if (!handleRace(aPC, i)) {
                continue;
            }
            LevelCommandFactory lcf = aPC.getDisplay().getRace().get(ObjectKey.MONSTER_CLASS);
            if (lcf != null) {
                handleMonster(aPC, lcf);
            } else {
                handleNonMonster(aPC);
            }
            handleEquipment(aPC);
            aPC.setPCAttribute(PCAttribute.PLAYERSNAME, "Enemy");
            theList.add(new PcgCombatant(aPC, "Enemy", messageHandler));
        }
        JOptionPane.showMessageDialog(null, "You will now be returned to PCGen so that you can finalise your selected combatants.\nOnce they are finalised, return to the GMGen Initiative tab to begin the combat!", "Combatant Setup Complete", JOptionPane.INFORMATION_MESSAGE);
        messageHandler.handleMessage(new TransmitInitiativeValuesBetweenComponentsMessage(this, theList));
        removeAll();
    } catch (Throwable e) {
        e.printStackTrace();
    }
    Globals.setRootFrame(oldRoot);
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) LevelCommandFactory(pcgen.cdom.content.LevelCommandFactory) PcgCombatant(gmgen.plugin.PcgCombatant) JFrame(javax.swing.JFrame) TransmitInitiativeValuesBetweenComponentsMessage(pcgen.pluginmgr.messages.TransmitInitiativeValuesBetweenComponentsMessage)

Example 7 with LevelCommandFactory

use of pcgen.cdom.content.LevelCommandFactory in project pcgen by PCGen.

the class AddLevelToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, PCTemplate template, String value) {
    ParsingSeparator sep = new ParsingSeparator(value, '|');
    sep.addGroupingPair('[', ']');
    sep.addGroupingPair('(', ')');
    String classString = sep.next();
    if (classString.isEmpty()) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage("Empty Class found in " + getTokenName());
        cpr.addErrorMessage("  " + getTokenName() + " requires at format: Class|LevelCount");
        return cpr;
    }
    if (!sep.hasNext()) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage("No | found in " + getTokenName());
        cpr.addErrorMessage("  " + getTokenName() + " requires at format: Class|LevelCount");
        return cpr;
    }
    String numLevels = sep.next();
    if (numLevels.isEmpty()) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage("Empty Level Count found in " + getTokenName());
        cpr.addErrorMessage("  " + getTokenName() + " requires at format: Class|LevelCount");
        return cpr;
    }
    if (sep.hasNext()) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage("Two | found in " + getTokenName());
        cpr.addErrorMessage("  " + getTokenName() + " requires at format: Class|LevelCount");
        return cpr;
    }
    CDOMSingleRef<PCClass> cl = context.getReferenceContext().getCDOMReference(PCClass.class, classString);
    Formula f;
    try {
        int lvls = Integer.parseInt(numLevels);
        if (lvls <= 0) {
            return new ParseResult.Fail("Number of Levels granted in " + getTokenName() + " must be greater than zero", context);
        }
        f = FormulaFactory.getFormulaFor(lvls);
    } catch (NumberFormatException nfe) {
        f = FormulaFactory.getFormulaFor(numLevels);
    }
    if (!f.isValid()) {
        return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + f.toString(), context);
    }
    LevelCommandFactory cf = new LevelCommandFactory(cl, f);
    context.getObjectContext().addToList(template, ListKey.ADD_LEVEL, cf);
    return ParseResult.SUCCESS;
}
Also used : Formula(pcgen.base.formula.Formula) LevelCommandFactory(pcgen.cdom.content.LevelCommandFactory) ParsingSeparator(pcgen.base.text.ParsingSeparator) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) PCClass(pcgen.core.PCClass)

Example 8 with LevelCommandFactory

use of pcgen.cdom.content.LevelCommandFactory in project pcgen by PCGen.

the class AddLevelTokenTest method testUnparseMultiple.

@Test
public void testUnparseMultiple() throws PersistenceLayerException {
    primaryContext.getReferenceContext().constructCDOMObject(PCClass.class, "Fighter");
    primaryContext.getReferenceContext().constructCDOMObject(PCClass.class, "Cleric");
    CDOMSingleRef<PCClass> fi = primaryContext.getReferenceContext().getCDOMReference(PCClass.class, "Fighter");
    primaryProf.addToListFor(ListKey.ADD_LEVEL, new LevelCommandFactory(fi, FormulaFactory.getFormulaFor(2)));
    CDOMSingleRef<PCClass> cl = primaryContext.getReferenceContext().getCDOMReference(PCClass.class, "Cleric");
    primaryProf.addToListFor(ListKey.ADD_LEVEL, new LevelCommandFactory(cl, FormulaFactory.getFormulaFor("Formula")));
    String[] unparsed = getToken().unparse(primaryContext, primaryProf);
    assertNotNull(unparsed);
    assertEquals(2, unparsed.length);
    List<String> upList = Arrays.asList(unparsed);
    assertTrue(upList.contains("Fighter|2"));
    assertTrue(upList.contains("Cleric|Formula"));
}
Also used : LevelCommandFactory(pcgen.cdom.content.LevelCommandFactory) PCClass(pcgen.core.PCClass) Test(org.junit.Test)

Example 9 with LevelCommandFactory

use of pcgen.cdom.content.LevelCommandFactory in project pcgen by PCGen.

the class PlayerCharacterTest method setUp.

//	/**
//	 * @return Test
//	 */
//	public static Test suite()
//	{
//		return new TestSuite(PlayerCharacterTest.class);
//	}
/**
	 * @see junit.framework.TestCase#setUp()
	 */
@Override
protected void setUp() throws Exception {
    super.setUp();
    LoadContext context = Globals.getContext();
    // Giant Class
    giantClass = new PCClass();
    giantClass.setName("Giant");
    BuildUtilities.setFact(giantClass, "ClassType", "Monster");
    final BonusObj babClassBonus = Bonus.newBonus(context, "COMBAT|BASEAB|CL*3/4");
    giantClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, babClassBonus);
    context.getReferenceContext().importObject(giantClass);
    // Human
    human = new Race();
    final BonusObj humanRaceFeatBonus = Bonus.newBonus(context, "FEAT|POOL|2");
    human.addToListFor(ListKey.BONUS, humanRaceFeatBonus);
    human.ownBonuses(human);
    // Giant Race
    giantRace = new Race();
    giantRace.setName("Ogre");
    giantRace.put(ObjectKey.MONSTER_CLASS, new LevelCommandFactory(CDOMDirectSingleRef.getRef(giantClass), FormulaFactory.getFormulaFor(4)));
    giantRace.addToListFor(ListKey.HITDICE_ADVANCEMENT, 100);
    final BonusObj giantRaceFeatBonus = Bonus.newBonus(context, "FEAT|POOL|1");
    giantRace.addToListFor(ListKey.BONUS, giantRaceFeatBonus);
    giantRace.ownBonuses(giantRace);
    context.getReferenceContext().importObject(giantRace);
    // Create the monster class type
    SettingsHandler.getGame().addClassType("Monster		CRFORMULA:0			ISMONSTER:YES	XPPENALTY:NO");
    pcClass = new PCClass();
    pcClass.setName("MyClass");
    BuildUtilities.setFact(pcClass, "SpellType", "Arcane");
    context.getReferenceContext().importObject(pcClass);
    classMemDivine = new PCClass();
    classMemDivine.setName("MemDivine");
    BuildUtilities.setFact(classMemDivine, "SpellType", "Divine");
    classMemDivine.put(ObjectKey.MEMORIZE_SPELLS, true);
    context.unconditionallyProcess(classMemDivine, "SPELLSTAT", "WIS");
    context.unconditionallyProcess(classMemDivine.getOriginalClassLevel(1), "CAST", "3,2,2");
    context.unconditionallyProcess(classMemDivine, "BONUS", "DOMAIN|NUMBER|1");
    context.getReferenceContext().importObject(classMemDivine);
    classWarmind = new PCClass();
    classWarmind.setName("Warmind");
    context.getReferenceContext().importObject(classWarmind);
    class2LpfM = new PCClass();
    class2LpfM.setName("2LpfM");
    BuildUtilities.setFact(class2LpfM, "ClassType", "Monster");
    class2LpfM.put(IntegerKey.LEVELS_PER_FEAT, 2);
    class2LpfM.put(StringKey.LEVEL_TYPE, "MONSTER");
    context.getReferenceContext().importObject(class2LpfM);
    class3LpfM = new PCClass();
    class3LpfM.setName("3LpfM");
    BuildUtilities.setFact(class3LpfM, "ClassType", "Monster");
    class3LpfM.put(IntegerKey.LEVELS_PER_FEAT, 3);
    class3LpfM.put(StringKey.LEVEL_TYPE, "MONSTER");
    context.getReferenceContext().importObject(class3LpfM);
    class3LpfBlank = new PCClass();
    class3LpfBlank.setName("3LpfBlank");
    BuildUtilities.setFact(class3LpfBlank, "ClassType", "Foo");
    class3LpfBlank.put(IntegerKey.LEVELS_PER_FEAT, 3);
    context.getReferenceContext().importObject(class3LpfBlank);
    toughness = new Ability();
    toughness.setName("Toughness");
    toughness.put(ObjectKey.MULTIPLE_ALLOWED, Boolean.TRUE);
    toughness.put(ObjectKey.STACKS, Boolean.TRUE);
    context.unconditionallyProcess(toughness, "CHOOSE", "NOCHOICE");
    toughness.setCDOMCategory(AbilityCategory.FEAT);
    final BonusObj aBonus = Bonus.newBonus(context, "HP|CURRENTMAX|3");
    if (aBonus != null) {
        toughness.addToListFor(ListKey.BONUS, aBonus);
    }
    context.getReferenceContext().importObject(toughness);
    Ability exoticWpnProf = TestHelper.makeAbility("Exotic Weapon Proficiency", AbilityCategory.FEAT, "General.Fighter");
    exoticWpnProf.put(ObjectKey.MULTIPLE_ALLOWED, Boolean.TRUE);
    context.unconditionallyProcess(exoticWpnProf, "CHOOSE", "WEAPONPROFICIENCY|!PC[TYPE.Exotic]");
    context.unconditionallyProcess(exoticWpnProf, "AUTO", "WEAPONPROF|%LIST");
    WeaponProf wpnProfTestA = new WeaponProf();
    wpnProfTestA.setName("Weapon A");
    wpnProfTestA.put(StringKey.KEY_NAME, "Weapon A");
    wpnProfTestA.addToListFor(ListKey.TYPE, Type.getConstant("Exotic"));
    context.getReferenceContext().importObject(wpnProfTestA);
    WeaponProf wpnProfTestB = new WeaponProf();
    wpnProfTestB.setName("Weapon B");
    wpnProfTestB.put(StringKey.KEY_NAME, "Weapon B");
    wpnProfTestB.addToListFor(ListKey.TYPE, Type.getConstant("Exotic"));
    context.getReferenceContext().importObject(wpnProfTestB);
    WeaponProf wpnProfTestC = new WeaponProf();
    wpnProfTestC.setName("Weapon C");
    wpnProfTestC.put(StringKey.KEY_NAME, "Weapon C");
    wpnProfTestC.addToListFor(ListKey.TYPE, Type.getConstant("Exotic"));
    context.getReferenceContext().importObject(wpnProfTestC);
    UIPropertyContext.setSingleChoiceAction(Constants.CHOOSER_SINGLE_CHOICE_METHOD_SELECT_EXIT);
    ChooserFactory.pushChooserClassname(RandomChooser.class.getName());
    context.unconditionallyProcess(pcClass.getOriginalClassLevel(1), "ADD", "FEAT|KEY_Exotic Weapon Proficiency (Weapon B)");
    context.unconditionallyProcess(pcClass.getOriginalClassLevel(2), "ADD", "FEAT|KEY_Exotic Weapon Proficiency (Weapon A)");
    context.unconditionallyProcess(pcClass.getOriginalClassLevel(3), "ADD", "FEAT|KEY_Exotic Weapon Proficiency (Weapon C)");
    specialFeatCat = Globals.getContext().getReferenceContext().constructNowIfNecessary(AbilityCategory.class, "Special Feat");
    specialFeatCat.setAbilityCategory(CDOMDirectSingleRef.getRef(AbilityCategory.FEAT));
    specialAbilityCat = Globals.getContext().getReferenceContext().constructNowIfNecessary(AbilityCategory.class, "Special Ability");
    luckDomain = TestHelper.makeDomain("Luck");
    context.getReferenceContext().buildDerivedObjects();
    luckDomainLvl1Spell = TestHelper.makeSpell("true strike");
    luckDomainLvl2Spell = TestHelper.makeSpell("aid");
    TestHelper.makeSpell("protection from energy");
    context.unconditionallyProcess(luckDomain, "SPELLLEVEL", "DOMAIN|Luck=1|KEY_True Strike|Luck=2|KEY_Aid|Luck=3|KEY_Protection from Energy");
}
Also used : LevelCommandFactory(pcgen.cdom.content.LevelCommandFactory) BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext) RandomChooser(pcgen.util.chooser.RandomChooser)

Example 10 with LevelCommandFactory

use of pcgen.cdom.content.LevelCommandFactory in project pcgen by PCGen.

the class PCRacialHDSizeTermEvaluatorTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    Campaign customCampaign = new Campaign();
    customCampaign.setName("Unit Test");
    customCampaign.setName("KEY_Unit Test");
    customCampaign.addToListFor(ListKey.DESCRIPTION, new Description("Unit Test data"));
    CampaignSourceEntry source = new CampaignSourceEntry(customCampaign, new URI("file:/" + getClass().getName() + ".java"));
    LoadContext context = Globals.getContext();
    PCClassLoader classLoader = new PCClassLoader();
    // Create the humanoid monster class
    final String humanoidClassLine = "CLASS:Humanoid	KEY:KEY_Humanoid	HD:8	TYPE:Monster	CLASSTYPE:Monster	" + "STARTSKILLPTS:2	MODTOSKILLS:YES";
    humanoidClass = classLoader.parseLine(context, null, humanoidClassLine, source);
    context.getReferenceContext().importObject(humanoidClass);
    // Create the pc class
    final String pcClassLine = "CLASS:TestPCClass	TYPE:PC		HD:10";
    pcClass = classLoader.parseLine(context, null, pcClassLine, source);
    context.getReferenceContext().importObject(pcClass);
    CDOMDirectSingleRef<SizeAdjustment> mediumRef = CDOMDirectSingleRef.getRef(medium);
    // Create the BugBear race
    bugbearRace.setName("Bugbear");
    bugbearRace.put(StringKey.KEY_NAME, "KEY_Bugbear");
    bugbearRace.put(FormulaKey.SIZE, new FixedSizeFormula(mediumRef));
    bugbearRace.addToListFor(ListKey.HITDICE_ADVANCEMENT, Integer.MAX_VALUE);
    bugbearRace.put(ObjectKey.MONSTER_CLASS, new LevelCommandFactory(CDOMDirectSingleRef.getRef(humanoidClass), FormulaFactory.getFormulaFor(3)));
    context.getReferenceContext().importObject(bugbearRace);
    // Create the human race
    humanRace.setName("Human");
    humanRace.put(StringKey.KEY_NAME, "KEY_Human");
    humanRace.put(FormulaKey.SIZE, new FixedSizeFormula(mediumRef));
    context.getReferenceContext().importObject(humanRace);
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) Campaign(pcgen.core.Campaign) Description(pcgen.core.Description) LevelCommandFactory(pcgen.cdom.content.LevelCommandFactory) LoadContext(pcgen.rules.context.LoadContext) PCClassLoader(pcgen.persistence.lst.PCClassLoader) URI(java.net.URI) SizeAdjustment(pcgen.core.SizeAdjustment) FixedSizeFormula(pcgen.cdom.formula.FixedSizeFormula)

Aggregations

LevelCommandFactory (pcgen.cdom.content.LevelCommandFactory)25 PCClass (pcgen.core.PCClass)10 PlayerCharacter (pcgen.core.PlayerCharacter)7 CharID (pcgen.cdom.enumeration.CharID)4 FixedSizeFormula (pcgen.cdom.formula.FixedSizeFormula)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Race (pcgen.core.Race)3 SizeAdjustment (pcgen.core.SizeAdjustment)3 LoadContext (pcgen.rules.context.LoadContext)3 URI (java.net.URI)2 ParsingSeparator (pcgen.base.text.ParsingSeparator)2 CDOMObject (pcgen.cdom.base.CDOMObject)2 PCTemplate (pcgen.core.PCTemplate)2 BonusObj (pcgen.core.bonus.BonusObj)2 PCLevelInfo (pcgen.core.pclevelinfo.PCLevelInfo)2 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)2 PCClassLoader (pcgen.persistence.lst.PCClassLoader)2 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)2 PcgCombatant (gmgen.plugin.PcgCombatant)1