/** * @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, * pcgen.io.ExportHandler) */ @Override public String getToken(String tokenSource, PlayerCharacter pc, ExportHandler eh) { SkillDetails details = buildSkillDetails(tokenSource); if (details.getPropertyCount() < 2) { return ""; } Skill aSkill = getSkill(tokenSource, pc, details, eh); return getSkillProperty(aSkill, details.getProperty(1), pc); }
/** * Select the target skill based on the supplied critieria. Searches through the characters skill * list selecting those that start with the value in details.properties[0] and then uses the index * in details.skillId to select the skill. * * @param tokenSource The token being processed. Used for error reporting. * @param pc The character being processed. * @param details The parsed details of the token. * @param eh The ExportHandler * @return The matching skill, or null if none match. */ private Skill getSkill( String tokenSource, PlayerCharacter pc, SkillDetails details, ExportHandler eh) { int skillIndex; // Get the index try { skillIndex = Integer.parseInt(details.getSkillId()); } catch (NumberFormatException exc) { Logging.errorPrint("Error replacing SKILLSUBSET." + tokenSource, exc); return null; } // Build the list of matching skills String skillPrefix = details.getProperty(0); int prefixLength = skillPrefix.length(); List<Skill> skillSubset = new ArrayList<>(); final List<Skill> skills = SkillDisplay.getSkillListInOutputOrder( pc, pc.getDisplay().getPartialSkillList(View.VISIBLE_EXPORT)); for (Skill bSkill : skills) { if (skillPrefix.regionMatches(true, 0, bSkill.getKeyName(), 0, prefixLength)) { skillSubset.add(bSkill); } } // Select the skill if ((skillIndex >= (skillSubset.size() - 1)) && eh != null && eh.getExistsOnly()) { eh.setNoMoreItems(true); } Skill aSkill = null; if (skillIndex <= (skillSubset.size() - 1)) { aSkill = skillSubset.get(skillIndex); } return aSkill; }