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);
}
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;
}
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"));
}
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");
}
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);
}
Aggregations