use of pcgen.cdom.enumeration.RaceType in project pcgen by PCGen.
the class PreRaceTester method passes.
/**
* @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
*/
@Override
public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) {
final int reqnumber = Integer.parseInt(prereq.getOperand());
final String requiredRace = prereq.getKey();
int runningTotal = 0;
final Race pcRace = display.getRace();
Set<Race> racesImitated = getRacesImitatedBy(pcRace);
if (//$NON-NLS-1$ //$NON-NLS-2$
requiredRace.startsWith("TYPE=") || requiredRace.startsWith("TYPE.")) {
StringTokenizer tok = new StringTokenizer(requiredRace.substring(5), ".");
String type;
boolean match = false;
int count = 0;
int matchCount = 0;
while (tok.hasMoreTokens()) {
count++;
match = false;
type = tok.nextToken();
if (pcRace.isType(type)) {
matchCount++;
match = true;
continue;
}
if (!match) {
for (Race mock : racesImitated) {
if (mock.isType(type)) {
matchCount++;
match = true;
break;
}
}
}
}
if (count == matchCount) {
++runningTotal;
}
} else if (//$NON-NLS-1$ //$NON-NLS-2$
requiredRace.startsWith("RACETYPE=") || requiredRace.startsWith("RACETYPE.")) {
String raceToMatch = requiredRace.substring(9);
String raceType = display.getRaceType();
boolean isMatchingRaceType = raceType.equalsIgnoreCase(requiredRace.substring(9)) ? true : false;
if (isMatchingRaceType) {
++runningTotal;
} else {
for (Race mock : racesImitated) {
RaceType mockRaceType = mock.get(ObjectKey.RACETYPE);
if (mockRaceType != null && mockRaceType.toString().equalsIgnoreCase(raceToMatch)) {
++runningTotal;
}
}
}
} else if (requiredRace.startsWith("RACESUBTYPE=") || requiredRace.startsWith("RACESUBTYPE.")) {
final String reqType = requiredRace.substring(12);
RaceSubType st = RaceSubType.getConstant(reqType);
if (display.containsRacialSubType(st)) {
++runningTotal;
}
if (runningTotal == 0) {
for (Race mock : racesImitated) {
if (mock.containsInList(ListKey.RACESUBTYPE, st)) {
++runningTotal;
break;
}
}
}
} else {
final String characterRace = pcRace == null ? Constants.NONESELECTED : pcRace.getKeyName();
final int wild = requiredRace.indexOf('%');
if (wild == 0) {
//
if (!characterRace.equalsIgnoreCase(Constants.NONESELECTED)) {
++runningTotal;
}
} else if (wild > 0) {
if (characterRace.regionMatches(true, 0, requiredRace, 0, wild)) {
++runningTotal;
} else {
runningTotal += checkForServesAsRaceWildcard(requiredRace, wild, racesImitated);
}
} else {
if (characterRace.equalsIgnoreCase(requiredRace)) {
++runningTotal;
} else {
for (Race mock : racesImitated) {
if (mock.getDisplayName().equalsIgnoreCase(requiredRace)) {
++runningTotal;
break;
}
}
}
}
}
if (runningTotal > reqnumber) {
runningTotal = reqnumber;
}
runningTotal = prereq.getOperator().compare(runningTotal, reqnumber);
return countedTotal(prereq, runningTotal);
}
use of pcgen.cdom.enumeration.RaceType in project pcgen by PCGen.
the class RaceTypeFacet method getRaceType.
/**
* Returns the RaceType of the Player Character represented by the given
* CharID.
*
* @param id
* The CharID representing the Player Character for which the
* RaceType will be returned
* @return The RaceType of the Player Character represented by the given
* CharID.
*/
public RaceType getRaceType(CharID id) {
RaceType raceType = null;
Race race = raceFacet.get(id);
if (race != null) {
RaceType rt = race.get(ObjectKey.RACETYPE);
if (rt != null) {
raceType = rt;
}
}
for (CompanionMod cm : companionModFacet.getSet(id)) {
RaceType rt = cm.get(ObjectKey.RACETYPE);
if (rt != null) {
raceType = rt;
}
}
for (PCTemplate t : templateFacet.getSet(id)) {
RaceType rt = t.get(ObjectKey.RACETYPE);
if (rt != null) {
raceType = rt;
}
}
return raceType;
}
use of pcgen.cdom.enumeration.RaceType in project pcgen by PCGen.
the class Gui2InfoFactory method getHTMLInfo.
/**
* @see pcgen.core.facade.InfoFactory#getHTMLInfo(pcgen.core.facade.RaceFacade)
*/
@Override
public String getHTMLInfo(RaceFacade raceFacade) {
if (!(raceFacade instanceof Race)) {
return EMPTY_STRING;
}
Race race = (Race) raceFacade;
final HtmlInfoBuilder infoText = new HtmlInfoBuilder();
if (!race.getKeyName().startsWith("<none")) {
infoText.appendTitleElement(OutputNameFormatting.piString(race, false));
infoText.appendLineBreak();
RaceType rt = race.get(ObjectKey.RACETYPE);
if (rt != null) {
//$NON-NLS-1$
infoText.appendI18nElement("in_irInfoRaceType", rt.toString());
}
List<RaceSubType> rst = race.getListFor(ListKey.RACESUBTYPE);
if (rst != null) {
infoText.appendSpacer();
//$NON-NLS-1$
infoText.appendI18nElement("in_irInfoSubType", StringUtil.join(rst, ", "));
}
if (!race.getType().isEmpty()) {
infoText.appendSpacer();
//$NON-NLS-1$
infoText.appendI18nElement("in_irInfoType", race.getType());
}
appendFacts(infoText, race);
infoText.appendLineBreak();
String size = race.getSize();
if (StringUtils.isNotEmpty(size)) {
//$NON-NLS-1$
infoText.appendI18nElement("in_size", size);
}
String movement = getMovement(raceFacade);
if (!movement.isEmpty()) {
infoText.appendSpacer();
//$NON-NLS-1$
infoText.appendI18nElement("in_movement", movement);
}
String vision = getVision(raceFacade);
if (!vision.isEmpty()) {
infoText.appendSpacer();
//$NON-NLS-1$
infoText.appendI18nElement("in_vision", vision);
}
String bString = PrerequisiteUtilities.preReqHTMLStringsForList(pc, null, race.getPrerequisiteList(), false);
if (!bString.isEmpty()) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nElement("in_requirements", bString);
}
String desc = pc.getDescription(race);
if (!desc.isEmpty()) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nFormattedElement(//$NON-NLS-1$
"in_InfoDescription", DescriptionFormatting.piWrapDesc(race, desc, false));
}
String statAdjustments = getStatAdjustments(raceFacade);
if (StringUtils.isNotEmpty(statAdjustments)) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nElement("in_irTableStat", statAdjustments);
}
LevelCommandFactory levelCommandFactory = race.get(ObjectKey.MONSTER_CLASS);
if (levelCommandFactory != null) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nFormattedElement(//$NON-NLS-1$
"in_irInfoMonsterClass", String.valueOf(levelCommandFactory.getLevelCount()), OutputNameFormatting.piString(levelCommandFactory.getPCClass(), false));
}
String favoredClass = getFavoredClass(raceFacade);
if (StringUtils.isNotEmpty(favoredClass)) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nElement("in_favoredClass", favoredClass);
}
bString = race.getSource();
if (!bString.isEmpty()) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nElement("in_sourceLabel", bString);
}
}
return infoText.toString();
}
use of pcgen.cdom.enumeration.RaceType in project pcgen by PCGen.
the class Gui2InfoFactory method getHTMLInfo.
/**
* @see pcgen.core.facade.InfoFactory#getHTMLInfo(pcgen.core.facade.TemplateFacade)
*/
@Override
public String getHTMLInfo(TemplateFacade templateFacade) {
if (templateFacade == null) {
return EMPTY_STRING;
}
PCTemplate template = (PCTemplate) templateFacade;
final HtmlInfoBuilder infoText = new HtmlInfoBuilder();
infoText.appendTitleElement(OutputNameFormatting.piString(template, false));
appendFacts(infoText, template);
RaceType rt = template.get(ObjectKey.RACETYPE);
if (rt != null) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nElement("in_irInfoRaceType", rt.toString());
}
if (!template.getType().isEmpty()) {
infoText.appendSpacer();
//$NON-NLS-1$
infoText.appendI18nElement("in_irInfoType", template.getType());
}
String aString = pc.getDescription(template);
if (!aString.isEmpty()) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nFormattedElement(//$NON-NLS-1$
"in_InfoDescription", aString);
}
aString = TemplateModifier.modifierString(template, pc);
if (!aString.isEmpty()) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nElement("in_modifier", aString);
}
aString = PrerequisiteUtilities.preReqHTMLStringsForList(pc, null, template.getPrerequisiteList(), false);
if (!aString.isEmpty()) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nElement("in_requirements", aString);
}
aString = template.getSource();
if (!aString.isEmpty()) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nElement("in_sourceLabel", aString);
}
return infoText.toString();
}
Aggregations