use of gmgen.io.ReadXML in project pcgen by PCGen.
the class ExperienceAdjusterModel method getCombatantExperience.
/**
* Get combatant experience
* @param cbt
* @return combatant experience
*/
private int getCombatantExperience(Combatant cbt) {
float enemyCR;
int tableCR;
int experience = 0;
File experienceFolder = new File(dir, "experience_tables");
File experienceFile = new File(experienceFolder, "7_1.xml");
// Lets not load the massive XML file more than we have to
if (experienceTable == null) {
experienceTable = new ReadXML(experienceFile);
}
for (int i = 0; i < enemies.size(); i++) {
ExperienceListItem item = (ExperienceListItem) enemies.get(i);
enemyCR = item.getCombatant().getCR();
if (enemyCR < 1) {
tableCR = 1;
} else {
tableCR = (int) enemyCR;
}
String xp = (String) experienceTable.getTable().crossReference(Integer.toString((int) cbt.getCR()), Integer.toString(tableCR));
try {
if (enemyCR < 1) {
experience += (int) (Float.parseFloat(xp) * enemyCR);
} else {
experience += Integer.parseInt(xp);
}
} catch (Exception e) {
Logging.errorPrint("Experience Value: '" + xp + "' Not a number");
Logging.errorPrint(e.getMessage(), e);
}
}
return new Double((experience * multiplier) / party.size()).intValue();
}
Aggregations