use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class PrerequisiteWriter method getPrereqString.
private String getPrereqString(Collection<Prerequisite> prereqs, String separator) throws PersistenceLayerException {
String prereqString = null;
if (prereqs != null && !prereqs.isEmpty()) {
TreeSet<String> list = new TreeSet<>();
for (Prerequisite p : prereqs) {
StringWriter swriter = new StringWriter();
write(swriter, p);
list.add(swriter.toString());
}
prereqString = StringUtil.join(list, separator);
}
return prereqString;
}
use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class KnownSpellInputFacet method processList.
private void processList(CharID id, CDOMList<Spell> spelllist, CDOMReference<? extends CDOMList<?>> listref, CDOMObject cdo) {
for (CDOMReference<Spell> objref : cdo.getListMods((CDOMReference<? extends CDOMList<Spell>>) listref)) {
for (AssociatedPrereqObject apo : cdo.getListAssociations(listref, objref)) {
Boolean known = apo.getAssociation(AssociationKey.KNOWN);
if ((known == null) || !known.booleanValue()) {
continue;
}
Collection<Spell> spells = objref.getContainedObjects();
Integer lvl = apo.getAssociation(AssociationKey.SPELL_LEVEL);
if (apo.hasPrerequisites()) {
List<Prerequisite> prereqs = apo.getPrerequisiteList();
for (Spell spell : spells) {
AvailableSpell as = new AvailableSpell(spelllist, spell, lvl);
as.addAllPrerequisites(prereqs);
conditionallyKnownSpellFacet.add(id, as, cdo);
}
} else {
for (Spell spell : spells) {
knownSpellFacet.add(id, spelllist, lvl, spell, cdo);
}
}
}
}
}
use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class PCClass method getBonusTo.
/**
* Returns the total bonus to the specified bonus type and name.
*
* <p>
* This method checks only bonuses associated with the class. It makes sure
* to return bonuses that are active only to the max level specified. What
* that means is that bonuses specified on class level lines will have a
* level parameter associated with them. Only bonuses specified on the level
* specified or lower will be totalled.
*
* @param argType
* Bonus type e.g. <code>BONUS:<b>DOMAIN</b></code>
* @param argMname
* Bonus name e.g. <code>BONUS:DOMAIN|<b>NUMBER</b></code>
* @param asLevel
* The maximum level to apply bonuses for.
* @param aPC
* The <tt>PlayerCharacter</tt> bonuses are being calculated
* for.
*
* @return Total bonus value.
*/
/*
* REFACTOR There is potentially redundant information here - level and PC...
* is this ever out of sync or can this method be removed/made private??
*/
public double getBonusTo(final String argType, final String argMname, final int asLevel, final PlayerCharacter aPC) {
double i = 0;
List<BonusObj> rawBonusList = getRawBonusList(aPC);
for (int lvl = 1; lvl < asLevel; lvl++) {
rawBonusList.addAll(aPC.getActiveClassLevel(this, lvl).getRawBonusList(aPC));
}
if ((asLevel == 0) || rawBonusList.isEmpty()) {
return 0;
}
final String type = argType.toUpperCase();
final String mname = argMname.toUpperCase();
for (final BonusObj bonus : rawBonusList) {
final StringTokenizer breakOnPipes = new StringTokenizer(bonus.toString().toUpperCase(), Constants.PIPE, false);
final String theType = breakOnPipes.nextToken();
if (!theType.equals(type)) {
continue;
}
final String str = breakOnPipes.nextToken();
final StringTokenizer breakOnCommas = new StringTokenizer(str, Constants.COMMA, false);
while (breakOnCommas.hasMoreTokens()) {
final String theName = breakOnCommas.nextToken();
if (theName.equals(mname)) {
final String aString = breakOnPipes.nextToken();
final List<Prerequisite> localPreReqList = new ArrayList<>();
if (bonus.hasPrerequisites()) {
localPreReqList.addAll(bonus.getPrerequisiteList());
}
// as the prereqs are processed by the bonus loading code.
while (breakOnPipes.hasMoreTokens()) {
final String bString = breakOnPipes.nextToken();
if (PreParserFactory.isPreReqString(bString)) {
Logging.debugPrint(//$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
"Why is this prerequisite '" + bString + "' parsed in '" + getClass().getName() + ".getBonusTo(String,String,int)' rather than in the persistence layer?");
try {
final PreParserFactory factory = PreParserFactory.getInstance();
localPreReqList.add(factory.parse(bString));
} catch (PersistenceLayerException ple) {
Logging.errorPrint(ple.getMessage(), ple);
}
}
}
// be referenced in Qualifies statements?
if (PrereqHandler.passesAll(localPreReqList, aPC, null)) {
final double j = aPC.getVariableValue(aString, getQualifiedKey()).doubleValue();
i += j;
}
}
}
}
return i;
}
use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class EquipmentModifier method getBonusList.
private List<BonusObj> getBonusList(List<BonusObj> bonusList, List<String> associations) {
ArrayList<BonusObj> myBonusList = new ArrayList<>(bonusList);
for (int i = myBonusList.size() - 1; i > -1; i--) {
final BonusObj aBonus = myBonusList.get(i);
final String aString = aBonus.toString();
final int idx = aString.indexOf("%CHOICE");
if (idx >= 0) {
// Add an entry for each of the associated list entries
for (String assoc : associations) {
final BonusObj newBonus = Bonus.newBonus(Globals.getContext(), aString.replaceAll(PERCENT_CHOICE_PATTERN, assoc));
if (aBonus.hasPrerequisites()) {
newBonus.clearPrerequisiteList();
for (Prerequisite prereq : aBonus.getPrerequisiteList()) {
try {
newBonus.addPrerequisite(prereq.specify(assoc));
} catch (CloneNotSupportedException e) {
// TODO Handle this?
}
}
}
myBonusList.add(newBonus);
}
myBonusList.remove(aBonus);
}
}
return myBonusList;
}
use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class PreCompatibilityToken method unparse.
@Override
public String[] unparse(LoadContext context, ConcretePrereqObject obj) {
Changes<Prerequisite> changes = context.getObjectContext().getPrerequisiteChanges(obj);
if (changes == null || changes.isEmpty()) {
return null;
}
Set<String> set = new TreeSet<>();
for (Prerequisite p : changes.getAdded()) {
String kind = p.getKind();
final StringWriter capture = new StringWriter();
try {
PrerequisiteWriterInterface writer = factory.getWriter(kind);
writer.write(capture, p);
} catch (PersistenceLayerException e) {
Logging.errorPrint("Error in Compatibility Token", e);
}
String output = capture.toString();
int colonLoc = output.indexOf(':');
boolean outInvert = output.startsWith("!");
if (invert ^ outInvert) {
continue;
}
String key = output.substring(0, colonLoc);
if (tokenName.equalsIgnoreCase(key)) {
set.add(output.substring(colonLoc + 1));
}
}
if (set.isEmpty()) {
return null;
}
return set.toArray(new String[set.size()]);
}
Aggregations