use of pcgen.core.GameMode in project pcgen by PCGen.
the class AbstractCharacterUsingTestCase method setUpPC.
protected void setUpPC() throws PersistenceLayerException {
TokenRegistration.register(AUTO_LANG_TOKEN);
TokenRegistration.register(ABILITY_VISIBLE_TOKEN);
TokenRegistration.register(AUTO_TOKEN);
TokenRegistration.register(CHOOSE_TOKEN);
TokenRegistration.register(CHOOSE_LANG_TOKEN);
TokenRegistration.register(ABILITY_MULT_TOKEN);
TokenRegistration.register(EQUIP_TYPE_TOKEN);
TokenRegistration.register(EQUIP_PROFICIENCY_TOKEN);
TokenRegistration.register(LANGBONUS_PRIM);
TokenRegistration.register(PC_QUAL);
Globals.createEmptyRace();
Globals.setUseGUI(false);
Globals.emptyLists();
GameMode gamemode = SettingsHandler.getGame();
str = BuildUtilities.createStat("Strength", "STR");
str.put(VariableKey.getConstant("LOADSCORE"), FormulaFactory.getFormulaFor("STRSCORE"));
str.put(VariableKey.getConstant("OFFHANDLIGHTBONUS"), FormulaFactory.getFormulaFor(2));
dex = BuildUtilities.createStat("Dexterity", "DEX");
PCStat con = BuildUtilities.createStat("Constitution", "CON");
intel = BuildUtilities.createStat("Intelligence", "INT");
wis = BuildUtilities.createStat("Wisdom", "WIS");
cha = BuildUtilities.createStat("Charisma", "CHA");
AbstractReferenceContext ref = Globals.getContext().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"));
gamemode.setBonusFeatLevels("3|3");
SettingsHandler.setGame("3.5");
ref.importObject(str);
ref.importObject(dex);
ref.importObject(con);
ref.importObject(intel);
ref.importObject(wis);
ref.importObject(cha);
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);
universal = ref.constructCDOMObject(Language.class, "Universal");
other = ref.constructCDOMObject(Language.class, "Other");
SourceFileLoader.createLangBonusObject(Globals.getContext());
}
use of pcgen.core.GameMode in project pcgen by PCGen.
the class RunConvertPanel method performAnalysis.
/**
* @see pcgen.gui2.converter.panel.ConvertSubPanel#performAnalysis(pcgen.cdom.base.CDOMObject)
*/
@Override
public boolean performAnalysis(final CDOMObject pc) {
logSummary(pc);
final File rootDir = pc.get(ObjectKey.DIRECTORY);
final File outDir = pc.get(ObjectKey.WRITE_DIRECTORY);
totalCampaigns = new ArrayList<>(pc.getSafeListFor(ListKey.CAMPAIGN));
for (Campaign campaign : pc.getSafeListFor(ListKey.CAMPAIGN)) {
// Add all sub-files to the main campaign, regardless of exclusions
for (CampaignSourceEntry fName : campaign.getSafeListFor(ListKey.FILE_PCC)) {
URI uri = fName.getURI();
if (PCGFile.isPCGenCampaignFile(uri)) {
Campaign c = Globals.getCampaignByURI(uri, false);
if (c != null) {
totalCampaigns.add(c);
}
}
}
}
sortCampaignsByRank(totalCampaigns);
new Thread(new Runnable() {
@Override
public void run() {
Logging.registerHandler(getHandler());
SettingsHandler.setGame(pc.get(ObjectKey.GAME_MODE).getName());
GameMode mode = SettingsHandler.getGame();
//Necessary for "good" behavior
mode.resolveInto(context.getReferenceContext());
//Necessary for those still using Globals.getContext
mode.resolveInto(mode.getContext().getReferenceContext());
LSTConverter converter;
Writer changeLogWriter;
try {
changeLogWriter = new FileWriter(changeLogFile);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String startTime = simpleDateFormat.format(new Date());
changeLogWriter.append("PCGen Data Converter v" + PCGenPropBundle.getVersionNumber() + " - conversion started at " + startTime + "\n");
changeLogWriter.append("Outputting files to " + outDir.getAbsolutePath() + "\n");
} catch (IOException e1) {
Logging.errorPrint("Failed to initialise LSTConverter", e1);
return;
}
converter = new LSTConverter(context, rootDir, outDir.getAbsolutePath(), RunConvertPanel.this, changeLogWriter);
converter.addObserver(RunConvertPanel.this);
int numFiles = 0;
for (Campaign campaign : totalCampaigns) {
numFiles += converter.getNumFilesInCampaign(campaign);
}
setTotalFileCount(numFiles);
converter.initCampaigns(totalCampaigns);
for (Campaign campaign : totalCampaigns) {
converter.processCampaign(campaign);
}
ObjectInjector oi = new ObjectInjector(context, outDir, rootDir, converter);
try {
oi.writeInjectedObjects(totalCampaigns);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
changeLogWriter.close();
} catch (IOException e) {
Logging.errorPrint("LSTConverter.wrapUp failed", e);
}
converter.deleteObserver(RunConvertPanel.this);
Logging.removeHandler(getHandler());
try {
// Wait for any left over messages to catch up
Thread.sleep(1000);
} catch (InterruptedException e) {
// Ignore exception
}
setCurrentFilename("");
addMessage("\nConversion complete.");
if (getHandler().getNumErrors() > 0) {
JOptionPane.showMessageDialog(null, LanguageBundle.getFormattedString(//$NON-NLS-1$
"in_lstConvErrorsFound", getHandler().getNumErrors()), LanguageBundle.getString(//$NON-NLS-1$
"in_lstConvErrorsTitle"), JOptionPane.ERROR_MESSAGE);
}
progressBar.setValue(progressBar.getMaximum());
fireProgressEvent(ProgressEvent.AUTO_ADVANCE);
}
}).start();
return true;
}
use of pcgen.core.GameMode in project pcgen by PCGen.
the class SkillTokenTest method setUp.
/**
* @see pcgen.AbstractCharacterTestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
super.setUp();
PlayerCharacter character = getCharacter();
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);
LoadContext context = Globals.getContext();
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);
context.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);
context.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);
context.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);
aBonus = Bonus.newBonus(context, "SKILL|Balance|2|PRESKILL:1,Tumble=5|TYPE=Synergy.STACK");
if (aBonus != null) {
balance.addToListFor(ListKey.BONUS, aBonus);
}
context.getReferenceContext().importObject(balance);
SkillRankControl.modRanks(4.0, myClass, true, character, balance);
context.getReferenceContext().buildDerivedObjects();
context.getReferenceContext().resolveReferences(null);
character.calcActiveBonuses();
}
use of pcgen.core.GameMode in project pcgen by PCGen.
the class PCGVer2Creator method appendRollMethodLine.
private void appendRollMethodLine(StringBuilder buffer) {
final GameMode game = getGameMode();
buffer.append(IOConstants.TAG_ROLLMETHOD).append(':');
buffer.append(game.getRollMethod());
buffer.append('|');
buffer.append(IOConstants.TAG_EXPRESSION).append(':');
switch(game.getRollMethod()) {
case Constants.CHARACTER_STAT_METHOD_ALL_THE_SAME:
buffer.append(game.getAllStatsValue());
break;
case Constants.CHARACTER_STAT_METHOD_PURCHASE:
buffer.append(game.getPurchaseModeMethodName());
break;
case Constants.CHARACTER_STAT_METHOD_ROLLED:
buffer.append(game.getRollMethodExpression());
break;
default:
buffer.append(0);
break;
}
buffer.append(IOConstants.LINE_SEP);
}
use of pcgen.core.GameMode in project pcgen by PCGen.
the class ExportHandler method exportCharacterUsingFreemarker.
/**
* Produce an output file for a character using a FreeMarker template.
*
* @param aPC The character being output.
* @param outputWriter The destination for the output.
* @throws ExportException If the export fails.
*/
private void exportCharacterUsingFreemarker(PlayerCharacter aPC, BufferedWriter outputWriter) throws ExportException {
try {
// Set Directory for templates
Configuration cfg = new Configuration();
cfg.setDirectoryForTemplateLoading(templateFile.getParentFile());
cfg.setIncompatibleImprovements(new Version("2.3.20"));
// load template
Template template = cfg.getTemplate(templateFile.getName());
// Configure our custom directives and functions.
cfg.setSharedVariable("pcstring", new PCStringDirective(aPC, this));
cfg.setSharedVariable("pcvar", new PCVarFunction(aPC));
cfg.setSharedVariable("pcboolean", new PCBooleanFunction(aPC, this));
cfg.setSharedVariable("pchasvar", new PCHasVarFunction(aPC, this));
cfg.setSharedVariable("loop", new LoopDirective());
cfg.setSharedVariable("equipsetloop", new EquipSetLoopDirective(aPC));
GameMode gamemode = SettingsHandler.getGame();
// data-model
Map<String, Object> pc = OutputDB.buildDataModel(aPC.getCharID());
Map<String, Object> mode = OutputDB.buildModeDataModel(gamemode);
Map<String, Object> input = new HashMap<>();
input.put("pcgen", OutputDB.getGlobal());
input.put("pc", ObjectWrapper.DEFAULT_WRAPPER.wrap(pc));
input.put("gamemode", mode);
input.put("gamemodename", gamemode.getName());
// Process the template
template.process(input, outputWriter);
} catch (IOException | TemplateException exc) {
String message = "Error exporting character using template " + templateFile;
Logging.errorPrint(message, exc);
throw new ExportException(message + " : " + exc.getLocalizedMessage(), exc);
} finally {
if (outputWriter != null) {
try {
outputWriter.flush();
} catch (Exception ignored) {
}
}
}
}
Aggregations