use of pcgen.core.SpecialAbility in project pcgen by PCGen.
the class PreVarTest method test2856626.
public void test2856626() {
LoadContext context = Globals.getContext();
final PCClass warrior = new PCClass();
warrior.setName("Warrior");
context.getReferenceContext().importObject(warrior);
context.unconditionallyProcess(warrior, "SAB", "Test Works|PREVARGTEQ:CL,2");
assertTrue(context.getReferenceContext().resolveReferences(null));
PlayerCharacter character = this.getCharacter();
character.incrementClassLevel(1, warrior);
PCClassLoader loader = new PCClassLoader();
try {
CampaignSourceEntry se = new CampaignSourceEntry(new Campaign(), new URI("file://test"));
loader.completeObject(context, se, warrior);
PCClass notawarrior = loader.getCopy(context, "Warrior", "NotAWarrior", se);
List<SpecialAbility> sabList = notawarrior.getListFor(ListKey.SAB);
assertNotNull(sabList);
assertEquals(1, sabList.size());
SpecialAbility sab = sabList.get(0);
assertFalse(sab.qualifies(character, notawarrior));
character.incrementClassLevel(1, notawarrior);
assertFalse(sab.qualifies(character, notawarrior));
character.incrementClassLevel(1, notawarrior);
assertTrue(sab.qualifies(character, notawarrior));
} catch (URISyntaxException | PersistenceLayerException e) {
fail(e.getMessage());
}
}
use of pcgen.core.SpecialAbility in project pcgen by PCGen.
the class PreVarTest method test2856622.
public void test2856622() {
LoadContext context = Globals.getContext();
final PCClass warrior = new PCClass();
warrior.setName("Warrior");
PCClassLevel level1 = warrior.getOriginalClassLevel(1);
context.unconditionallyProcess(level1, "SAB", "Test Works|PREVARGTEQ:CL,3");
assertTrue(context.getReferenceContext().resolveReferences(null));
PlayerCharacter character = this.getCharacter();
character.incrementClassLevel(1, warrior);
PCClassLoader loader = new PCClassLoader();
try {
SourceEntry se = new CampaignSourceEntry(new Campaign(), new URI("file://test"));
loader.completeObject(context, se, warrior);
List<SpecialAbility> sabList = level1.getListFor(ListKey.SAB);
assertNotNull(sabList);
assertEquals(1, sabList.size());
SpecialAbility sab = sabList.get(0);
assertFalse(sab.qualifies(character, warrior));
character.incrementClassLevel(1, warrior);
assertFalse(sab.qualifies(character, warrior));
character.incrementClassLevel(1, warrior);
assertTrue(sab.qualifies(character, warrior));
} catch (URISyntaxException | PersistenceLayerException e) {
fail(e.getMessage());
}
}
use of pcgen.core.SpecialAbility in project pcgen by PCGen.
the class PCGVer2Parser method parseClassAbilitiesLevelLine.
private void parseClassAbilitiesLevelLine(final String line, final List<PCLevelInfo> pcLevelInfoList) {
final PCGTokenizer tokens;
try {
tokens = new PCGTokenizer(line);
} catch (PCGParseException pcgpex) {
final String message = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.IllegalClassAbility", line, pcgpex.getMessage());
warnings.add(message);
return;
}
int level = -1;
PCClass aPCClass = null;
PCGElement element;
PCLevelInfo pcl = null;
final Iterator<PCGElement> it = tokens.getElements().iterator();
// eg: Cleric=4
if (it.hasNext()) {
element = it.next();
final int index = element.getText().indexOf('=');
if (index < 0) {
final String message = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.InvalidClassLevel", element.getText());
warnings.add(message);
return;
}
final String classKeyName = EntityEncoder.decode(element.getText().substring(0, index));
aPCClass = thePC.getClassKeyed(classKeyName);
if (aPCClass == null) {
final String message = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.ClassNotFound", classKeyName);
warnings.add(message);
return;
}
try {
level = Integer.parseInt(element.getText().substring(index + 1));
} catch (NumberFormatException nfe) {
final String message = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.InvalidClassLevel", element.getText());
warnings.add(message);
return;
}
if (level < 1) {
final String message = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.InvalidClassLevel", element.getText());
warnings.add(message);
return;
}
for (PCLevelInfo info : pcLevelInfoList) {
if (classKeyName.equalsIgnoreCase(info.getClassKeyName()) && level == info.getClassLevel()) {
pcl = info;
break;
}
}
if (pcl == null) {
pcl = thePC.addLevelInfo(classKeyName);
pcl.setClassLevel(level);
} else {
thePC.addLevelInfo(pcl);
}
pcl.setSkillPointsRemaining(0);
}
while (it.hasNext()) {
element = it.next();
String tag = element.getName();
if (IOConstants.TAG_SUBSTITUTIONLEVEL.equals(tag)) {
final String substitutionClassKeyName = EntityEncoder.decode(element.getText());
SubstitutionClass aSubstitutionClass = aPCClass.getSubstitutionClassKeyed(substitutionClassKeyName);
if (aSubstitutionClass == null) {
final String message = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.ClassNotFound", substitutionClassKeyName);
warnings.add(message);
return;
}
SubstitutionLevelSupport.applyLevelArrayModsToLevel(aSubstitutionClass, aPCClass, level, thePC);
thePC.setSubstitutionClassName(thePC.getActiveClassLevel(aPCClass, level), substitutionClassKeyName);
} else if (IOConstants.TAG_HITPOINTS.equals(tag)) {
try {
PCClassLevel classLevel = thePC.getActiveClassLevel(aPCClass, level - 1);
thePC.setHP(classLevel, Integer.valueOf(element.getText()));
} catch (NumberFormatException nfe) {
final String message = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.InvalidHP", tag, element.getText());
warnings.add(message);
}
} else if (IOConstants.TAG_SAVES.equals(tag)) {
for (final PCGElement child : element.getChildren()) {
final String dString = EntityEncoder.decode(child.getText());
if (dString.startsWith(IOConstants.TAG_BONUS + IOConstants.TAG_SEPARATOR)) {
String bonusString = dString.substring(6);
int pipeLoc = bonusString.indexOf('|');
if (pipeLoc != -1) {
CDOMObject target = aPCClass;
String potentialInt = bonusString.substring(0, pipeLoc);
try {
int bonusLevel = Integer.parseInt(potentialInt);
if (bonusLevel > 0) {
target = thePC.getActiveClassLevel(aPCClass, bonusLevel);
}
bonusString = bonusString.substring(pipeLoc + 1);
} catch (NumberFormatException e) {
//OK (no level embedded in file)
if (level > 0) {
target = thePC.getActiveClassLevel(aPCClass, level);
}
}
BonusAddition.applyBonus(bonusString, "", thePC, target);
}
}
}
} else if (IOConstants.TAG_SPECIALTIES.equals(tag)) {
for (final PCGElement child : element.getChildren()) {
thePC.setAssoc(aPCClass, AssociationKey.SPECIALTY, EntityEncoder.decode(child.getText()));
}
} else if (IOConstants.TAG_SPECIALABILITIES.equals(tag)) {
for (PCGElement child : element.getChildren()) {
String specialAbilityName = EntityEncoder.decode(child.getText());
if (pcgenVersion[0] <= 5 && pcgenVersion[1] <= 5 && pcgenVersion[2] < 6) {
if (//$NON-NLS-1$
specialAbilityName.equals("Turn Undead")) {
//$NON-NLS-1$
parseFeatLine("FEAT:Turn Undead|TYPE:SPECIAL.TURNUNDEAD|DESC:");
continue;
} else if (//$NON-NLS-1$
specialAbilityName.equals("Rebuke Undead")) {
//$NON-NLS-1$
parseFeatLine("FEAT:Rebuke Undead|TYPE:SPECIAL.TURNUNDEAD|DESC:");
continue;
}
}
SpecialAbility specialAbility = new SpecialAbility(specialAbilityName);
CDOMObject target = aPCClass;
if (level > 0) {
target = thePC.getActiveClassLevel(aPCClass, level);
}
if (!thePC.hasSpecialAbility(specialAbilityName)) {
thePC.addUserSpecialAbility(specialAbility, target);
}
}
} else if (tag.equals(IOConstants.TAG_LEVELABILITY)) {
parseLevelAbilityInfo(element, aPCClass, level);
} else if (tag.equals(IOConstants.TAG_ADDTOKEN)) {
parseAddTokenInfo(element, thePC.getActiveClassLevel(aPCClass, level));
} else //
if (tag.equals(IOConstants.TAG_PRESTAT) || tag.equals(IOConstants.TAG_POSTSTAT)) {
boolean isPre = false;
if (tag.equals(IOConstants.TAG_PRESTAT)) {
isPre = true;
}
final int idx = element.getText().indexOf('=');
if (idx > 0) {
String statAbb = element.getText().substring(0, idx);
final PCStat pcstat = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCStat.class, statAbb);
if (pcstat != null) {
try {
thePC.saveStatIncrease(pcstat, Integer.parseInt(element.getText().substring(idx + 1)), isPre);
} catch (NumberFormatException nfe) {
final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.InvalidStatMod", tag, element.getText());
warnings.add(msg);
}
} else {
final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.UnknownStat", tag, element.getText());
warnings.add(msg);
}
} else {
final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.MissingEquals", tag, element.getText());
warnings.add(msg);
}
} else if ((pcl != null) && IOConstants.TAG_SKILLPOINTSGAINED.equals(tag)) {
pcl.setFixedSkillPointsGained(Integer.parseInt(element.getText()));
} else if ((pcl != null) && IOConstants.TAG_SKILLPOINTSREMAINING.equals(tag)) {
pcl.setSkillPointsRemaining(Integer.parseInt(element.getText()));
} else if (IOConstants.TAG_DATA.equals(tag)) {
// TODO
// for now it's ok to ignore it!
} else {
final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.UnknownTag", tag, element.getText());
warnings.add(msg);
}
}
// TODO:
// process data
//
// need to add some consistency checks here to avoid
// - duplicate entries for one and the same class/level pair
// - missing entries for a given class/level pair
}
use of pcgen.core.SpecialAbility in project pcgen by PCGen.
the class PCGIOHandler method buildSALIST.
public static void buildSALIST(String aChoice, List<String> aAvailable, List<String> aBonus, final PlayerCharacter currentPC) {
// SALIST:Smite|VAR|%|1
// SALIST:Turn ,Rebuke|VAR|%|1
String aString;
String aPost = "";
int iOffs = aChoice.indexOf('|', 7);
if (iOffs < 0) {
aString = aChoice;
} else {
aString = aChoice.substring(7, iOffs);
aPost = aChoice.substring(iOffs + 1);
}
final List<String> saNames = new ArrayList<>();
final StringTokenizer aTok = new StringTokenizer(aString, ",");
while (aTok.hasMoreTokens()) {
saNames.add(aTok.nextToken());
}
final List<SpecialAbility> aSAList = currentPC.getSpecialAbilityList();
for (String name : saNames) {
for (SpecialAbility sa : aSAList) {
String aSA = sa.getKeyName();
if (aSA.startsWith(aString)) {
String aVar = "";
//
// Trim off variable portion of SA, and save variable name
// (eg. "Smite Evil %/day|SmiteEvil" --> aSA = "Smite Evil", aVar = "SmiteEvil")
//
iOffs = aSA.indexOf('|');
if (iOffs >= 0) {
aVar = aSA.substring(iOffs + 1);
iOffs = aSA.indexOf('%');
if (iOffs >= 0) {
aSA = aSA.substring(0, iOffs).trim();
}
}
if (!aAvailable.contains(aSA)) {
aAvailable.add(aSA);
//
// Check for variable substitution
//
iOffs = aPost.indexOf('%');
if (iOffs >= 0) {
aVar = aPost.substring(0, iOffs) + aVar + aPost.substring(iOffs + 1);
}
aBonus.add(aSA + "|" + aVar);
}
}
}
}
}
use of pcgen.core.SpecialAbility in project pcgen by PCGen.
the class SabLst method parseTokenWithSeparator.
/**
* This method sets the special abilities granted by this [object]. For
* efficiency, avoid calling this method except from I/O routines.
*
* @param context
* @param obj
* the CDOMbject that is to receive the new SpecialAbility
* @param aString
* String of special abilities delimited by pipes
*/
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String aString) {
if (obj instanceof Ungranted) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
}
StringTokenizer tok = new StringTokenizer(aString, Constants.PIPE);
String firstToken = tok.nextToken();
if (looksLikeAPrerequisite(firstToken)) {
return new ParseResult.Fail("Cannot have only PRExxx subtoken in " + getTokenName(), context);
}
boolean foundClear = false;
if (Constants.LST_DOT_CLEAR.equals(firstToken)) {
context.getObjectContext().removeList(obj, ListKey.SAB);
if (!tok.hasMoreTokens()) {
return ParseResult.SUCCESS;
}
firstToken = tok.nextToken();
foundClear = true;
}
if (looksLikeAPrerequisite(firstToken)) {
return new ParseResult.Fail("Cannot use PREREQs when using .CLEAR in " + getTokenName(), context);
}
if (Constants.LST_DOT_CLEAR.equals(firstToken)) {
return new ParseResult.Fail("SA tag confused by redundant '.CLEAR'" + aString, context);
}
SpecialAbility sa = new SpecialAbility(firstToken.intern());
if (!tok.hasMoreTokens()) {
sa.setName(firstToken.intern());
context.getObjectContext().addToList(obj, ListKey.SAB, sa);
return ParseResult.SUCCESS;
}
StringBuilder saName = new StringBuilder(aString.length());
saName.append(firstToken);
String token = tok.nextToken();
while (true) {
if (Constants.LST_DOT_CLEAR.equals(token)) {
return new ParseResult.Fail("SA tag confused by '.CLEAR' as a " + "middle token: " + aString, context);
} else if (looksLikeAPrerequisite(token)) {
break;
} else {
saName.append(Constants.PIPE).append(token);
// sa.addVariable(FormulaFactory.getFormulaFor(token));
}
if (!tok.hasMoreTokens()) {
// No prereqs, so we're done
// CONSIDER This is a HACK and not the long term strategy of SA:
sa.setName(saName.toString());
context.getObjectContext().addToList(obj, ListKey.SAB, sa);
return ParseResult.SUCCESS;
}
token = tok.nextToken();
}
// CONSIDER This is a HACK and not the long term strategy of SA:
sa.setName(saName.toString());
if (foundClear) {
return new ParseResult.Fail("Cannot use PREREQs when using .CLEAR and a Special Ability in " + getTokenName(), context);
}
while (true) {
Prerequisite prereq = getPrerequisite(token);
if (prereq == null) {
return new ParseResult.Fail(" (Did you put Abilities after the " + "PRExxx tags in " + getTokenName() + ":?)", context);
}
sa.addPrerequisite(prereq);
if (!tok.hasMoreTokens()) {
break;
}
token = tok.nextToken();
}
context.getObjectContext().addToList(obj, ListKey.SAB, sa);
return ParseResult.SUCCESS;
}
Aggregations