Search in sources :

Example 6 with ReadXML

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();
}
Also used : File(java.io.File) ReadXML(gmgen.io.ReadXML)

Aggregations

ReadXML (gmgen.io.ReadXML)6 File (java.io.File)6 VectorTable (gmgen.io.VectorTable)3 Random (java.util.Random)2 Race (pcgen.core.Race)2 ArrayList (java.util.ArrayList)1 NoSuchElementException (java.util.NoSuchElementException)1 Vector (java.util.Vector)1 Formula (pcgen.base.formula.Formula)1 ChallengeRating (pcgen.cdom.content.ChallengeRating)1