use of pcgen.cdom.enumeration.RaceSubType in project pcgen by PCGen.
the class RacesubtypeToken method unparse.
@Override
public String[] unparse(LoadContext context, PCTemplate pct) {
Changes<RaceSubType> addedChanges = context.getObjectContext().getListChanges(pct, ListKey.RACESUBTYPE);
Changes<RaceSubType> removedChanges = context.getObjectContext().getListChanges(pct, ListKey.REMOVED_RACESUBTYPE);
Collection<RaceSubType> added = addedChanges.getAdded();
Collection<RaceSubType> removed = removedChanges.getAdded();
if (added == null && removed == null) {
return null;
}
StringBuilder sb = new StringBuilder();
boolean needPipe = false;
if (removed != null) {
for (RaceSubType rst : removed) {
if (needPipe) {
sb.append(Constants.PIPE);
}
sb.append(".REMOVE.").append(rst.toString());
needPipe = true;
}
}
if (added != null) {
for (RaceSubType rst : added) {
if (needPipe) {
sb.append(Constants.PIPE);
}
sb.append(rst.toString());
needPipe = true;
}
}
return new String[] { sb.toString() };
}
use of pcgen.cdom.enumeration.RaceSubType 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.RaceSubType in project pcgen by PCGen.
the class Race method getRaceSubTypes.
@Override
public List<String> getRaceSubTypes() {
List<String> subTypeNames = new ArrayList<>();
List<RaceSubType> rst = getListFor(ListKey.RACESUBTYPE);
if (rst != null) {
for (RaceSubType subtype : rst) {
subTypeNames.add(subtype.toString());
}
}
return subTypeNames;
}
use of pcgen.cdom.enumeration.RaceSubType in project pcgen by PCGen.
the class RacialSubTypesFacet method getRacialSubTypes.
/**
* Returns a non-null Collection of the Racial Sub Types for the Player
* Character represented by the given CharID.
*
* This method is value-semantic in that ownership of the returned
* Collection is transferred to the class calling this method. Modification
* of the returned Collection will not modify this RacialSubTypesFacet and
* modification of this RacialSubTypesFacet will not modify the returned
* Collection. Modifications to the returned Collection will also not modify
* any future or previous objects returned by this (or other) methods on
* RacialSubTypesFacet.
*
* @param id
* The CharID representing the Player Character for which the
* Racial Sub Types should be returned
* @return A non-null Collection of the Racial Sub Types for the Player
* Character represented by the given CharID
*/
public Collection<RaceSubType> getRacialSubTypes(CharID id) {
List<RaceSubType> racialSubTypes = new ArrayList<>();
Race race = raceFacet.get(id);
if (race != null) {
racialSubTypes.addAll(race.getSafeListFor(ListKey.RACESUBTYPE));
}
Collection<PCTemplate> templates = templateFacet.getSet(id);
if (!templates.isEmpty()) {
List<RaceSubType> added = new ArrayList<>();
List<RaceSubType> removed = new ArrayList<>();
for (PCTemplate aTemplate : templates) {
added.addAll(aTemplate.getSafeListFor(ListKey.RACESUBTYPE));
removed.addAll(aTemplate.getSafeListFor(ListKey.REMOVED_RACESUBTYPE));
}
racialSubTypes.addAll(added);
racialSubTypes.removeAll(removed);
}
return Collections.unmodifiableList(racialSubTypes);
}
use of pcgen.cdom.enumeration.RaceSubType in project pcgen by PCGen.
the class RaceSubTypeToken method getToken.
/**
* @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
*/
@Override
public String getToken(String tokenSource, CharacterDisplay display, ExportHandler eh) {
StringTokenizer aTok = new StringTokenizer(tokenSource, ".");
aTok.nextToken();
int i = 0;
if (aTok.hasMoreTokens()) {
try {
i = Integer.parseInt(aTok.nextToken());
} catch (NumberFormatException notUsed) {
// This is an error. We will return the first item
}
}
RaceSubType rst = getRaceSubTypeToken(display, i);
return rst == null ? Constants.EMPTY_STRING : rst.toString();
}
Aggregations