use of gmgen.io.VectorTable in project pcgen by PCGen.
the class EncounterPlugin method generateXofYEL.
/**
* Generates creatures for an encounter based on a specified Encounter
* Level and number of creatures.
* @param size the number of creatures needed for encounter.
* @param totalEL total experience level.
*/
private void generateXofYEL(String size, String totalEL) {
File f = new File(getDataDirectory() + File.separator + DIR_ENCOUNTER + File.separator + "4_1.xml");
ReadXML xml;
VectorTable table41;
Random roll = new Random(System.currentTimeMillis());
List<Race> critters = new ArrayList<>();
if (!f.exists()) {
//$NON-NLS-1$
Logging.errorPrintLocalised("in_plugin_encounter_error_missing", f);
return;
}
xml = new ReadXML(f);
if ((table41 = xml.getTable()) == null) {
Logging.errorPrint("ACK! error getting table41! " + f.toString());
return;
}
xml = null;
f = null;
// verrify values on the table.
String crs = (String) table41.crossReference(totalEL, size);
table41 = null;
if (crs == null) {
Logging.errorPrint("Tables do not match the given parameters (" + totalEL + ", " + size + ')');
return;
}
Formula crFormula = FormulaFactory.getFormulaFor(crs);
if (!crFormula.isValid()) {
Logging.errorPrint("CR Formula " + crs + " was not valid: " + crFormula.toString());
}
ChallengeRating cr = new ChallengeRating(crFormula);
// populate critters with a list of matching monsters with the right CR.
for (final Race race : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(Race.class)) {
if (cr.equals(race.get(ObjectKey.CHALLENGE_RATING))) {
critters.add(race);
}
}
int i = roll.nextInt(critters.size());
for (int x = 0; x < Integer.parseInt(size); x++) {
theModel.addElement(critters.get(i).toString());
}
}
use of gmgen.io.VectorTable in project pcgen by PCGen.
the class EncounterPlugin method handleGenerateEncounter.
/**
* Handles the <b>Generate Encounter</b> button.
* @param m the encounter model.
*/
public void handleGenerateEncounter(EncounterModel m) {
File f = new File(getDataDirectory() + File.separator + DIR_ENCOUNTER + File.separator + "environments.xml");
ReadXML xml;
if (f.exists()) {
xml = new ReadXML(f);
} else {
//$NON-NLS-1$
Logging.errorPrintLocalised("in_plugin_encounter_error_missing", f);
return;
}
VectorTable environments = xml.getTable();
theModel.clear();
if (theView.getEnvironment().getSelectedIndex() == 0) {
generateXofYEL(theView.getNumberOfCreatures().getText(), theView.getTargetEL());
} else {
generateXfromY(environments.crossReference(theView.getEnvironment().getSelectedItem().toString(), "File").toString());
}
updateUI();
}
use of gmgen.io.VectorTable in project pcgen by PCGen.
the class EnvironmentModel method update.
/**
* Update the model
*/
public void update() {
VectorTable table;
ReadXML reader;
//$NON-NLS-1$
File f = new File(dir, "environments.xml");
this.removeAllElements();
if (!f.exists()) {
// TODO Make it so that the view also indicate that the file is missing.
//$NON-NLS-1$
Logging.errorPrintLocalised("in_plugin_encounter_error_missing", f);
return;
}
reader = new ReadXML(f);
table = reader.getTable();
//$NON-NLS-1$
this.addElement(LanguageBundle.getString("in_plugin_encounter_generic"));
for (int x = 1; x < table.size(); x++) {
try {
this.addElement(((Vector) table.get(x)).firstElement());
} catch (NoSuchElementException e) {
break;
}
}
}
Aggregations