use of pcgen.core.Skill in project pcgen by PCGen.
the class SkillSitToken method getSkillPropValue.
/**
* Evaluate the property for the supplied skill and character. For
* properties such as ACP and the extended UNTRAINED property, the
* property text is required to be further parsed to pull out user
* defined text to be output in each case.
*
* @param skillSit The skill to be reported upon.
* @param property The property to be reported.
* @param propertyText The original text of the property.
* @param pc The character to be reported upon.
* @return The value of the property.
*/
private String getSkillPropValue(Object skillSit, int property, String propertyText, PlayerCharacter pc) {
StringBuilder retValue = new StringBuilder();
if (((property == SkillToken.SKILL_ABMOD) || (property == SkillToken.SKILL_MISC)) && //&& aSkill.get(ObjectKey.KEY_STAT) == null)
false) {
retValue.append("n/a");
} else {
Skill skill;
boolean isSituation;
String situation;
SkillSituation sit;
if (skillSit instanceof Skill) {
sit = null;
skill = (Skill) skillSit;
isSituation = false;
situation = "";
} else if (skillSit instanceof SkillSituation) {
sit = (SkillSituation) skillSit;
skill = sit.getSkill();
isSituation = true;
situation = sit.getSituation();
} else {
Logging.errorPrint("Internal Error: unexpected type: " + skillSit.getClass());
return "";
}
switch(property) {
case SkillToken.SKILL_NAME:
String name = QualifiedName.qualifiedName(pc, skill);
if (isSituation) {
name += " (" + situation + ')';
}
retValue.append(name);
break;
case SkillToken.SKILL_TOTAL:
int rank = SkillRankControl.getTotalRank(pc, skill).intValue() + SkillModifier.modifier(skill, pc).intValue();
if (isSituation) {
rank += sit.getSituationBonus();
}
if (SettingsHandler.getGame().hasSkillRankDisplayText()) {
retValue.append(SettingsHandler.getGame().getSkillRankDisplayText(rank));
} else {
retValue.append(Integer.toString(rank));
}
break;
case SkillToken.SKILL_RANK:
Float sRank = SkillRankControl.getTotalRank(pc, skill);
if (SettingsHandler.getGame().hasSkillRankDisplayText()) {
retValue.append(SettingsHandler.getGame().getSkillRankDisplayText(sRank.intValue()));
} else {
retValue.append(SkillRankControl.getTotalRank(pc, skill).toString());
}
break;
case SkillToken.SKILL_MOD:
int mod = SkillModifier.modifier(skill, pc).intValue();
if (isSituation) {
mod += sit.getSituationBonus();
}
retValue.append(Integer.toString(mod));
break;
case SkillToken.SKILL_ABILITY:
retValue.append(SkillInfoUtilities.getKeyStatFromStats(pc, skill));
break;
case SkillToken.SKILL_ABMOD:
retValue.append(Integer.toString(SkillModifier.getStatMod(skill, pc)));
break;
case SkillToken.SKILL_MISC:
int misc = SkillModifier.modifier(skill, pc).intValue();
if (isSituation) {
misc += sit.getSituationBonus();
}
misc -= SkillModifier.getStatMod(skill, pc);
retValue.append(Integer.toString(misc));
break;
case SkillToken.SKILL_UNTRAINED:
retValue.append(skill.getSafe(ObjectKey.USE_UNTRAINED) ? "Y" : "NO");
break;
case SkillToken.SKILL_EXCLUSIVE:
retValue.append(skill.getSafe(ObjectKey.EXCLUSIVE) ? "Y" : "N");
break;
case SkillToken.SKILL_UNTRAINED_EXTENDED:
retValue.append(SkillToken.getUntrainedOutput(skill, propertyText));
break;
case SkillToken.SKILL_ACP:
retValue.append(SkillToken.getAcpOutput(skill, propertyText));
break;
case SkillToken.SKILL_COST:
SkillCost cost = null;
for (PCClass pcc : pc.getDisplay().getClassSet()) {
if (cost == null) {
cost = pc.getSkillCostForClass(skill, pcc);
} else {
SkillCost newCost = pc.getSkillCostForClass(skill, pcc);
if (SkillCost.CLASS.equals(newCost) || SkillCost.EXCLUSIVE.equals(cost)) {
cost = newCost;
}
}
if (SkillCost.CLASS.equals(cost)) {
break;
}
}
retValue.append(cost.toString());
break;
case SkillToken.SKILL_EXCLUSIVE_TOTAL:
int etRank = SkillRankControl.getTotalRank(pc, skill).intValue();
boolean b = (skill.getSafe(ObjectKey.EXCLUSIVE) || !skill.getSafe(ObjectKey.USE_UNTRAINED)) && (etRank == 0);
if (b) {
retValue.append('0');
} else {
int mRank = etRank + SkillModifier.modifier(skill, pc).intValue();
if (isSituation) {
mRank += sit.getSituationBonus();
}
retValue.append(Integer.toString(mRank));
}
break;
case SkillToken.SKILL_TRAINED_TOTAL:
int tRank = SkillRankControl.getTotalRank(pc, skill).intValue();
boolean isNotTrained = !skill.getSafe(ObjectKey.USE_UNTRAINED) && (tRank == 0);
if (isNotTrained) {
retValue.append('0');
} else {
int mRank = tRank + SkillModifier.modifier(skill, pc).intValue();
if (isSituation) {
mRank += sit.getSituationBonus();
}
retValue.append(Integer.toString(mRank));
}
break;
case SkillToken.SKILL_EXPLANATION:
boolean shortFrom = !("_LONG".equals(propertyText.substring(7)));
String bonusDetails = SkillCostDisplay.getModifierExplanation(skill, pc, shortFrom);
if (isSituation) {
String sitDetails = SkillCostDisplay.getSituationModifierExplanation(skill, situation, pc, shortFrom);
retValue.append(bonusDetails + " situational: " + sitDetails);
} else {
retValue.append(bonusDetails);
}
break;
case SkillToken.SKILL_TYPE:
String type = skill.getType();
retValue.append(type);
break;
case SkillToken.SKILL_SIZE:
int i = (int) (pc.getSizeAdjustmentBonusTo("SKILL", skill.getKeyName()));
if (isSituation) {
i += pc.getSizeAdjustmentBonusTo("SITUATION", skill.getKeyName() + '=' + situation);
}
retValue.append(Integer.toString(i));
break;
case SkillToken.SKILL_CLASSES:
List<String> classes = new ArrayList<>();
for (PCClass aClass : pc.getClassList()) {
if (pc.getSkillCostForClass(skill, aClass) == SkillCost.CLASS) {
classes.add(aClass.getDisplayName());
}
}
retValue.append(StringUtils.join(classes, "."));
break;
default:
Logging.errorPrint("In ExportHandler._writeSkillProperty the propIdvalue " + property + " is not handled.");
break;
}
}
return retValue.toString();
}
use of pcgen.core.Skill in project pcgen by PCGen.
the class SkillSubsetToken method getSkill.
/**
* 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;
}
use of pcgen.core.Skill in project pcgen by PCGen.
the class PreSkillMultTester method passes.
/**
* @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
*/
@Override
public int passes(final Prerequisite prereq, final PlayerCharacter character, CDOMObject source) {
CharacterDisplay display = character.getDisplay();
int runningTotal = 0;
final int requiredRanks = Integer.parseInt(prereq.getOperand());
String requiredSkillKey = prereq.getKey().toUpperCase();
final boolean isType = //$NON-NLS-1$ //$NON-NLS-2$
(requiredSkillKey.startsWith("TYPE.") || requiredSkillKey.startsWith("TYPE="));
if (isType) {
requiredSkillKey = requiredSkillKey.substring(5);
}
final String skillKey = requiredSkillKey;
final int percentageSignPosition = skillKey.lastIndexOf('%');
boolean foundMatch = false;
for (Skill aSkill : display.getSkillSet()) {
final String aSkillKey = aSkill.getKeyName().toUpperCase();
if (isType) {
if (percentageSignPosition >= 0) {
for (Type type : aSkill.getTrueTypeList(false)) {
if (type.toString().toUpperCase().startsWith(skillKey.substring(0, percentageSignPosition))) {
foundMatch = true;
break;
}
}
} else if (aSkill.isType(skillKey)) {
foundMatch = true;
}
if (foundMatch) {
final int result = prereq.getOperator().compare(SkillRankControl.getTotalRank(character, aSkill).intValue(), requiredRanks);
if (result == 0) {
foundMatch = false;
} else {
runningTotal = result;
}
}
} else if (aSkillKey.equals(skillKey) || ((percentageSignPosition >= 0) && aSkillKey.startsWith(skillKey.substring(0, percentageSignPosition)))) {
final int result = prereq.getOperator().compare(SkillRankControl.getTotalRank(character, aSkill).intValue(), requiredRanks);
if (result > 0) {
foundMatch = true;
runningTotal = result;
}
}
if (foundMatch) {
break;
}
}
return countedTotal(prereq, runningTotal);
}
use of pcgen.core.Skill in project pcgen by PCGen.
the class PreSkillSitTester method getImitators.
private Map<Skill, Set<Skill>> getImitators(CharacterDisplay display) {
HashMap<Skill, Set<Skill>> serveAsSkills = new HashMap<>();
Set<Skill> skillSet = new HashSet<>(display.getSkillSet());
for (Skill aSkill : skillSet) {
Set<Skill> servesAs = new HashSet<>();
for (CDOMReference<Skill> ref : aSkill.getSafeListFor(ListKey.SERVES_AS_SKILL)) {
servesAs.addAll(ref.getContainedObjects());
}
if (servesAs.size() > 0) {
serveAsSkills.put(aSkill, servesAs);
}
}
return serveAsSkills;
}
use of pcgen.core.Skill in project pcgen by PCGen.
the class PreMultTest method setUp.
/**
* @see junit.framework.TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
super.setUp();
final PlayerCharacter character = getCharacter();
myClass = new PCClass();
myClass.setName("My Class");
knowledge = new Skill();
Globals.getContext().unconditionallyProcess(knowledge, "CLASSES", "My Class");
knowledge.setName("KNOWLEDGE (ARCANA)");
TestHelper.addType(knowledge, "KNOWLEDGE.INT");
SkillRankControl.modRanks(8.0, myClass, true, character, knowledge);
}
Aggregations