use of pcgen.core.display.CharacterDisplay in project pcgen by PCGen.
the class TemplateToken method getToken.
/**
* @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) {
String retString = "";
PCTemplate template;
CharacterDisplay display = pc.getDisplay();
List<PCTemplate> tl = display.getOutputVisibleTemplateList();
StringTokenizer aTok = new StringTokenizer(tokenSource, ".");
aTok.nextToken();
int indexOfTemplate;
indexOfTemplate = Integer.parseInt(aTok.nextToken());
String aLabel = (aTok.hasMoreTokens()) ? aTok.nextToken() : "NAME";
if ((indexOfTemplate > -1) && (indexOfTemplate < tl.size())) {
template = tl.get(indexOfTemplate);
if ("NAME".equals(aLabel)) {
retString = getOutputNameToken(template);
} else if ("OUTPUTNAME".equals(aLabel)) {
retString = getOutputNameToken(template);
} else if ("APPLIEDNAME".equals(aLabel)) {
retString = getAppliedName(template);
} else if ("SA".equals(aLabel)) {
retString = getSAToken(template, pc);
} else if ("FEAT".equals(aLabel)) {
retString = getFeatToken(template, pc);
} else if ("SR".equals(aLabel)) {
retString = Integer.toString(getSRToken(template, display));
} else if ("CR".equals(aLabel)) {
// If the CR ends in .0, remove that for display purposes
retString = Float.toString(getCRToken(template, display));
String decimalPlaceValue = retString.substring(retString.length() - 2);
if (decimalPlaceValue.equals(".0")) {
retString = retString.substring(0, retString.length() - 2);
}
return retString;
} else if ("DR".equals(aLabel)) {
retString = display.calcDR();
} else {
retString = getModToken(pc, template, aLabel);
}
}
return retString;
}
use of pcgen.core.display.CharacterDisplay in project pcgen by PCGen.
the class ClassToken method getToken.
/**
* @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) {
StringTokenizer aTok = new StringTokenizer(tokenSource, ".");
aTok.nextToken();
int i = 0;
if (aTok.hasMoreTokens()) {
i = Integer.parseInt(aTok.nextToken());
}
CharacterDisplay display = pc.getDisplay();
if (aTok.hasMoreTokens()) {
String subToken = aTok.nextToken();
if ("LEVEL".equals(subToken)) {
int level = getLevelToken(display, i);
if (level > 0) {
return Integer.toString(level);
}
return "";
} else if ("SALIST".equals(subToken)) {
return getSAListToken(pc, i);
} else if ("TYPE".equals(subToken)) {
return getType(display, i);
} else if ("CLASSTYPE".equals(subToken)) {
return getClassType(display, i);
} else if ("ISMONSTER".equals(subToken)) {
return isMonster(display, i);
}
}
return getClassToken(display, i);
}
use of pcgen.core.display.CharacterDisplay in project pcgen by PCGen.
the class ExportHandler method dealWithFilteredTokens.
/**
* Helper method for replaceToken, deals with the filter tokens e.g. %DOMAIN, basically
* returns 0 if we should not be writing something out, e.g. It's filtered out
*
* @param aString
* @param aPC
* @return 0 If we should not be writing something out
*/
private int dealWithFilteredTokens(String aString, PlayerCharacter aPC) {
// Start by stating that we are allowed to write
canWrite = true;
// Get the merge strategy for equipment for later use
int merge = getEquipmentMergingStrategy(aString);
// Filter out on GAMEMODE
if (aString.substring(1).startsWith("GAMEMODE:")) {
if (aString.substring(10).endsWith(GameModeToken.getGameModeToken())) {
canWrite = false;
}
return 0;
}
// Filter out REGION
CharacterDisplay display = aPC.getDisplay();
if ("REGION".equals(aString.substring(1))) {
if (display.getRegionString().equals(Constants.NONE)) {
canWrite = false;
}
return 0;
}
// Filter out NOTES
if ("NOTES".equals(aString.substring(1))) {
if (aPC.getDisplay().getNotesCount() <= 0) {
canWrite = false;
}
return 0;
}
// Filter out SKILLPOINTS
if ("SKILLPOINTS".equals(aString.substring(1))) {
if (SkillpointsToken.getUnusedSkillPoints(aPC) == 0) {
canWrite = false;
}
return 0;
}
// Filter out TEMPLATE
if (aString.substring(1).startsWith("TEMPLATE")) {
// New token syntax |%TEMPLATE.x| instead of |%TEMPLATEx|
final StringTokenizer aTok = new StringTokenizer(aString.substring(1), ".");
final List<PCTemplate> tList = new ArrayList<>(aPC.getTemplateSet());
String fString = aTok.nextToken();
final int index;
if (aTok.hasMoreTokens()) {
index = Integer.parseInt(aTok.nextToken());
} else {
// When removing old syntax, remove the else and leave the if
if ("TEMPLATE".equals(fString)) {
if (tList.isEmpty()) {
canWrite = false;
}
return 0;
}
Logging.errorPrint("Old syntax %TEMPLATEx will be replaced for %TEMPLATE.x");
index = Integer.parseInt(aString.substring(9));
}
if (index >= tList.size()) {
canWrite = false;
return 0;
}
final PCTemplate template = tList.get(index);
if (!template.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.VISIBLE_EXPORT)) {
canWrite = false;
}
return 0;
}
// Filter out FOLLOWER
if ("FOLLOWER".equals(aString.substring(1))) {
if (!aPC.hasFollowers()) {
canWrite = false;
}
return 0;
}
// Filter out FOLLOWEROF
if ("FOLLOWEROF".equals(aString.substring(1))) {
if (aPC.getMasterPC() == null) {
canWrite = false;
}
return 0;
}
// Filter out FOLLOWERTYPE.
if (aString.substring(1).startsWith("FOLLOWERTYPE.")) {
List<Follower> aList = new ArrayList<>();
for (Follower follower : aPC.getFollowerList()) {
// Otherwise the stats a zero
for (PlayerCharacter pc : Globals.getPCList()) {
if (pc.getFileName().equals(follower.getFileName())) {
aList.add(follower);
}
}
}
StringTokenizer aTok = new StringTokenizer(aString, ".");
// FOLLOWERTYPE
aTok.nextToken();
String typeString = aTok.nextToken();
for (int i = aList.size() - 1; i >= 0; --i) {
final Follower fol = aList.get(i);
if (!fol.getType().getKeyName().equalsIgnoreCase(typeString)) {
aList.remove(i);
}
}
if (aList.isEmpty()) {
canWrite = false;
}
return 0;
}
// Filter out PROHIBITEDLIST
if ("PROHIBITEDLIST".equals(aString.substring(1))) {
for (PCClass pcClass : aPC.getClassSet()) {
if (aPC.getLevel(pcClass) > 0) {
if (pcClass.containsListFor(ListKey.PROHIBITED_SPELLS) || aPC.containsProhibitedSchools(pcClass)) {
return 0;
}
}
}
canWrite = false;
return 0;
}
// Filter out CATCHPHRASE
if ("CATCHPHRASE".equals(aString.substring(1))) {
String catchPhrase = display.getCatchPhrase();
if (catchPhrase.equals(Constants.NONE)) {
canWrite = false;
} else if (catchPhrase.trim().isEmpty()) {
canWrite = false;
}
return 0;
}
// Filter out LOCATION
if ("LOCATION".equals(aString.substring(1))) {
String location = display.getLocation();
if (location.equals(Constants.NONE)) {
canWrite = false;
} else if (location.trim().isEmpty()) {
canWrite = false;
}
return 0;
}
// Filter out RESIDENCE
if ("RESIDENCE".equals(aString.substring(1))) {
String residence = aPC.getSafeStringFor(PCStringKey.RESIDENCE);
if (residence.equals(Constants.NONE)) {
canWrite = false;
} else if (residence.trim().isEmpty()) {
canWrite = false;
}
return 0;
}
// Filter out PHOBIAS
if ("PHOBIAS".equals(aString.substring(1))) {
String phobias = display.getSafeStringFor(PCStringKey.PHOBIAS);
;
if (phobias.equals(Constants.NONE)) {
canWrite = false;
} else if (phobias.trim().isEmpty()) {
canWrite = false;
}
return 0;
}
// Filter out INTERESTS
if ("INTERESTS".equals(aString.substring(1))) {
String interests = display.getInterests();
if (interests.equals(Constants.NONE)) {
canWrite = false;
} else if (interests.trim().isEmpty()) {
canWrite = false;
}
return 0;
}
// Filter out SPEECHTENDENCY
if ("SPEECHTENDENCY".equals(aString.substring(1))) {
String speechTendency = display.getSpeechTendency();
if (speechTendency.equals(Constants.NONE)) {
canWrite = false;
} else if (speechTendency.trim().isEmpty()) {
canWrite = false;
}
return 0;
}
// Filter out PERSONALITY1
if ("PERSONALITY1".equals(aString.substring(1))) {
String trait1 = display.getTrait1();
if (trait1.equals(Constants.NONE)) {
canWrite = false;
} else if (trait1.trim().isEmpty()) {
canWrite = false;
}
return 0;
}
// Filter out PERSONALITY2
if ("PERSONALITY2".equals(aString.substring(1))) {
String trait2 = display.getTrait2();
if (trait2.equals(Constants.NONE)) {
canWrite = false;
} else if (trait2.trim().isEmpty()) {
canWrite = false;
}
return 0;
}
// Filter out MISC.FUNDS
if ("MISC.FUNDS".equals(aString.substring(1))) {
if (aPC.getSafeStringFor(PCStringKey.ASSETS).equals(Constants.NONE)) {
canWrite = false;
} else if ((aPC.getSafeStringFor(PCStringKey.ASSETS)).trim().isEmpty()) {
canWrite = false;
}
return 0;
}
// Filter out MISC.COMPANIONS and COMPANIONS
if ("COMPANIONS".equals(aString.substring(1)) || "MISC.COMPANIONS".equals(aString.substring(1))) {
if (aPC.getSafeStringFor(PCStringKey.COMPANIONS).equals(Constants.NONE)) {
canWrite = false;
} else if (aPC.getSafeStringFor(PCStringKey.COMPANIONS).trim().isEmpty()) {
canWrite = false;
}
return 0;
}
// Filter out MISC.MAGIC
if ("MISC.MAGIC".equals(aString.substring(1))) {
if (aPC.getSafeStringFor(PCStringKey.MAGIC).equals(Constants.NONE)) {
canWrite = false;
} else if (aPC.getSafeStringFor(PCStringKey.MAGIC).trim().isEmpty()) {
canWrite = false;
}
return 0;
}
// Filter out DESC
if ("DESC".equals(aString.substring(1))) {
String description = display.getSafeStringFor(PCStringKey.DESCRIPTION);
if (description.equals(Constants.NONE)) {
canWrite = false;
} else if (description.trim().isEmpty()) {
canWrite = false;
}
return 0;
}
// Filter out BIO
if ("BIO".equals(aString.substring(1))) {
String bio = display.getBio();
if (bio.equals(Constants.NONE)) {
canWrite = false;
} else if (bio.trim().isEmpty()) {
canWrite = false;
}
return 0;
}
// Filter out SUBREGION
if ("SUBREGION".equals(aString.substring(1))) {
if (display.getSubRegion().equals(Constants.NONE)) {
canWrite = false;
}
return 0;
}
// Filter out TEMPBONUS.
if (aString.substring(1).startsWith("TEMPBONUS.")) {
StringTokenizer aTok = new StringTokenizer(aString.substring(1), ".");
// discard first one
aTok.nextToken();
int index = -1;
if (aTok.hasMoreTokens()) {
index = Integer.parseInt(aTok.nextToken());
}
if (index > aPC.getNamedTempBonusList().size()) {
canWrite = false;
return 0;
}
if (aPC.getUseTempMods()) {
canWrite = true;
return 1;
}
}
// Filter out ARMOR.ITEM
if (aString.substring(1).startsWith("ARMOR.ITEM")) {
// New token syntax |%ARMOR.ITEM.x| instead of |%ARMOR.ITEMx|
final StringTokenizer aTok = new StringTokenizer(aString.substring(1), ".");
// ARMOR
aTok.nextToken();
String fString = aTok.nextToken();
final Collection<Equipment> aArrayList = new ArrayList<>();
for (Equipment eq : aPC.getEquipmentListInOutputOrder()) {
if (eq.altersAC(aPC) && (!eq.isArmor() && !eq.isShield())) {
aArrayList.add(eq);
}
}
// When removing old syntax, remove the else and leave the if
final int count;
if (aTok.hasMoreTokens()) {
count = Integer.parseInt(aTok.nextToken());
} else {
Logging.errorPrint("Old syntax %ARMOR.ITEMx will be replaced for %ARMOR.ITEM.x");
count = Integer.parseInt(fString.substring(fString.length() - 1));
}
if (count > aArrayList.size()) {
canWrite = false;
}
return 0;
}
// Filter out ARMOR.SHIELD
if (aString.substring(1).startsWith("ARMOR.SHIELD")) {
// New token syntax |%ARMOR.SHIELD.x| instead of |%ARMOR.SHIELDx|
final StringTokenizer aTok = new StringTokenizer(aString.substring(1), ".");
// ARMOR
aTok.nextToken();
String fString = aTok.nextToken();
final int count;
final List<Equipment> aArrayList = aPC.getEquipmentOfTypeInOutputOrder("SHIELD", 3);
// When removing old syntax, remove the else and leave the if
if (aTok.hasMoreTokens()) {
count = Integer.parseInt(aTok.nextToken());
} else {
Logging.errorPrint("Old syntax %ARMOR.SHIELDx will be replaced for %ARMOR.SHIELD.x");
count = Integer.parseInt(fString.substring(fString.length() - 1));
}
if (count > aArrayList.size()) {
canWrite = false;
}
return 0;
}
// Filter out ARMOR
if (aString.substring(1).startsWith("ARMOR")) {
// New token syntax |%ARMOR.x| instead of |%ARMORx|
final StringTokenizer aTok = new StringTokenizer(aString.substring(1), ".");
String fString = aTok.nextToken();
List<Equipment> aArrayList = aPC.getEquipmentOfTypeInOutputOrder("ARMOR", 3);
//Get list of shields. Remove any from list of armor
//Since shields are included in the armor list they will appear twice and they really shouldn't be in the list of armor
List<Equipment> shieldList = aPC.getEquipmentOfTypeInOutputOrder("SHIELD", 3);
int z = 0;
while (z < shieldList.size()) {
aArrayList.remove(shieldList.get(z));
z++;
}
// When removing old syntax, remove the else and leave the if
final int count;
if (aTok.hasMoreTokens()) {
count = Integer.parseInt(aTok.nextToken());
} else {
Logging.errorPrint("Old syntax %ARMORx will be replaced for %ARMOR.x");
count = Integer.parseInt(fString.substring(fString.length() - 1));
}
if (count > aArrayList.size()) {
canWrite = false;
}
return 0;
}
// Filter out WEAPONPROF
if ("WEAPONPROF".equals(aString.substring(1))) {
if (!SettingsHandler.getWeaponProfPrintout()) {
canWrite = false;
}
return 0;
}
// Filter out WEAPON
if (aString.substring(1).startsWith("WEAPON")) {
// New token syntax |%WEAPON.x| instead of |%WEAPONx|
final StringTokenizer aTok = new StringTokenizer(aString.substring(1), ".");
String fString = aTok.nextToken();
final List<Equipment> aArrayList = aPC.getExpandedWeapons(merge);
int count;
// When removing old syntax, remove the else and leave the if
if (aTok.hasMoreTokens()) {
count = Integer.parseInt(aTok.nextToken());
} else {
Logging.errorPrint("Old syntax %WEAPONx will be replaced for %WEAPON.x");
count = Integer.parseInt(fString.substring(fString.length() - 1));
}
if (count >= aArrayList.size()) {
canWrite = false;
}
return 0;
}
// Filter out DOMAIN
if (aString.substring(1).startsWith("DOMAIN")) {
// New token syntax |%DOMAIN.x| instead of |%DOMAINx|
final StringTokenizer aTok = new StringTokenizer(aString.substring(1), ".");
String fString = aTok.nextToken();
final int index;
// When removing old syntax, remove the else and leave the if
if (aTok.hasMoreTokens()) {
index = Integer.parseInt(aTok.nextToken());
} else {
Logging.errorPrint("Old syntax %DOMAINx will be replaced for %DOMAIN.x");
index = Integer.parseInt(fString.substring(6));
}
canWrite = (index <= display.getDomainCount());
return 0;
}
// Filter out SPELLLISTBOOK
if (aString.substring(1).startsWith("SPELLLISTBOOK")) {
if (SettingsHandler.getPrintSpellsWithPC()) {
// New token syntax |%SPELLLISTBOOK.x| instead of |%SPELLLISTBOOKx|
// To remove old syntax, replace i with 15
int i;
if (aString.charAt(14) == '.') {
i = 15;
} else {
i = 14;
}
return replaceTokenSpellListBook(aString.substring(i), aPC);
}
canWrite = false;
return 0;
}
// Filter out VAR.
if (aString.substring(1).startsWith("VAR.")) {
replaceTokenVar(aString, aPC);
return 0;
}
// Filter out COUNT[
if (aString.substring(1).startsWith("COUNT[")) {
if (getVarValue(aString.substring(1), aPC) > 0) {
canWrite = true;
return 1;
}
canWrite = false;
return 0;
}
// finally, check for classes
final StringTokenizer aTok = new StringTokenizer(aString.substring(1), ",", false);
boolean found = false;
while (aTok.hasMoreTokens()) {
String cString = aTok.nextToken();
StringTokenizer bTok = new StringTokenizer(cString, "=", false);
String bString = bTok.nextToken();
int i = 0;
if (bTok.hasMoreTokens()) {
i = Integer.parseInt(bTok.nextToken());
}
PCClass aClass = aPC.getClassKeyed(bString);
found = aClass != null;
if (aClass == null) {
canWrite = false;
} else {
canWrite = (aPC.getLevel(aClass) >= i);
}
// Filter out SPELLLISTCLASS
if (bString.startsWith("SPELLLISTCLASS")) {
// To remove old syntax, keep the if and remove the else
if (bString.charAt(14) == '.') {
bString = bString.substring(15);
} else {
bString = bString.substring(14);
}
found = true;
CDOMObject aObject = aPC.getSpellClassAtIndex(Integer.parseInt(bString));
canWrite = (aObject != null);
}
}
if (found) {
inLabel = true;
return 0;
}
canWrite = false;
inLabel = true;
Logging.debugPrint("Return 0 (don't write/no replacement) for an undetermined filter token.");
return 0;
}
use of pcgen.core.display.CharacterDisplay in project pcgen by PCGen.
the class FollowerListToken method getFollowerListToken.
/**
* Get FOLLOWERLIST Token
*
* @param display The character to be queried
* @return The list of followers.
*/
public static String getFollowerListToken(CharacterDisplay display) {
StringBuilder buf = new StringBuilder();
boolean needComma = false;
for (Follower aF : display.getFollowerList()) {
for (PlayerCharacter nPC : Globals.getPCList()) {
CharacterDisplay nDisplay = nPC.getDisplay();
if (aF.getFileName().equals(nDisplay.getFileName())) {
if (needComma) {
buf.append(", ");
}
buf.append(FileAccess.filterString(nDisplay.getName()));
needComma = true;
}
}
}
return buf.toString();
}
use of pcgen.core.display.CharacterDisplay in project pcgen by PCGen.
the class HitDiceToken method getMediumToken.
/**
* Get the HITDICE token
* @param pc
* @return the HITDICE token
*/
public static String getMediumToken(PlayerCharacter pc) {
StringBuilder ret = new StringBuilder();
String del = "";
Integer total = 0;
HashMap<Integer, Integer> hdMap = new LinkedHashMap<>();
CharacterDisplay display = pc.getDisplay();
for (PCClass pcClass : display.getClassSet()) {
for (int i = 0; i < display.getLevel(pcClass); i++) {
int hitDie = display.getLevelHitDie(pcClass, i + 1).getDie();
if (hitDie != 0) {
Integer num = hdMap.get(hitDie);
if (num == null) {
hdMap.put(hitDie, 1);
} else {
hdMap.put(hitDie, num.intValue() + 1);
}
}
}
}
Set<Integer> keys = hdMap.keySet();
if (keys.size() > 1) {
ret.append(getShortToken(display));
ret.append(" HD; ");
}
for (int key : keys) {
Integer value = hdMap.get(key);
ret.append(del);
ret.append(value).append('d').append(key);
total += value;
del = "+";
}
// Get CON bonus contribution to hitpoint total
int temp = (int) display.getStatBonusTo("HP", "BONUS") * display.getTotalLevels();
// Add in feat bonus
temp += (int) pc.getTotalBonusTo("HP", "CURRENTMAX");
if (temp != 0) {
ret.append(Delta.toString(temp));
}
return ret.toString();
}
Aggregations