use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class SpellsLst method processAdds.
private Collection<? extends String> processAdds(LoadContext context, MapToList<CDOMReference<Spell>, AssociatedPrereqObject> mtl) {
TripleKeyMap<Set<Prerequisite>, Map<AssociationKey<?>, Object>, CDOMReference<Spell>, String> m = new TripleKeyMap<>();
for (CDOMReference<Spell> lw : mtl.getKeySet()) {
for (AssociatedPrereqObject assoc : mtl.getListFor(lw)) {
Map<AssociationKey<?>, Object> am = new HashMap<>();
String dc = null;
for (AssociationKey<?> ak : assoc.getAssociationKeys()) {
// else
if (AssociationKey.DC_FORMULA.equals(ak)) {
dc = assoc.getAssociation(AssociationKey.DC_FORMULA);
} else {
am.put(ak, assoc.getAssociation(ak));
}
}
m.put(new HashSet<>(assoc.getPrerequisiteList()), am, lw, dc);
}
}
Set<String> set = new TreeSet<>();
for (Set<Prerequisite> prereqs : m.getKeySet()) {
for (Map<AssociationKey<?>, Object> am : m.getSecondaryKeySet(prereqs)) {
StringBuilder sb = new StringBuilder();
sb.append(am.get(AssociationKey.SPELLBOOK));
Formula times = AssociationKey.TIMES_PER_UNIT.cast(am.get(AssociationKey.TIMES_PER_UNIT));
sb.append(Constants.PIPE).append("TIMES=").append(times);
String timeunit = AssociationKey.TIME_UNIT.cast(am.get(AssociationKey.TIME_UNIT));
if (timeunit != null) {
sb.append(Constants.PIPE).append("TIMEUNIT=").append(timeunit);
}
String casterLvl = AssociationKey.CASTER_LEVEL.cast(am.get(AssociationKey.CASTER_LEVEL));
if (casterLvl != null) {
sb.append(Constants.PIPE).append("CASTERLEVEL=").append(casterLvl);
}
Set<String> spellSet = new TreeSet<>();
for (CDOMReference<Spell> spell : m.getTertiaryKeySet(prereqs, am)) {
String spellString = spell.getLSTformat(false);
String dc = m.get(prereqs, am, spell);
if (dc != null) {
spellString += Constants.COMMA + dc;
}
spellSet.add(spellString);
}
sb.append(Constants.PIPE);
sb.append(StringUtil.join(spellSet, Constants.PIPE));
if (prereqs != null && !prereqs.isEmpty()) {
sb.append(Constants.PIPE);
sb.append(getPrerequisiteString(context, prereqs));
}
set.add(sb.toString());
}
}
return set;
}
use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class SrLst method parseToken.
@Override
public ParseResult parseToken(LoadContext context, CDOMObject obj, String value) {
if (obj instanceof Ungranted) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
}
if (Constants.LST_DOT_CLEAR.equals(value)) {
context.getObjectContext().remove(obj, ObjectKey.SR);
} else {
Formula formula = FormulaFactory.getFormulaFor(value);
if (!formula.isValid()) {
return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + formula.toString(), context);
}
context.getObjectContext().put(obj, ObjectKey.SR, new SpellResistance(formula));
}
return ParseResult.SUCCESS;
}
use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class KitLst method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
if (obj instanceof Ungranted) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
}
if (obj instanceof NonInteractive) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Non-Interactive object type: " + obj.getClass().getSimpleName(), context);
}
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
Formula count = FormulaFactory.getFormulaFor(tok.nextToken());
if (!count.isValid()) {
return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
}
if (!count.isStatic()) {
return new ParseResult.Fail("Count in " + getTokenName() + " must be a number", context);
}
if (count.resolveStatic().intValue() <= 0) {
return new ParseResult.Fail("Count in " + getTokenName() + " must be > 0", context);
}
if (!tok.hasMoreTokens()) {
return new ParseResult.Fail(getTokenName() + " must have a | separating " + "count from the list of possible values: " + value, context);
}
List<CDOMReference<Kit>> refs = new ArrayList<>();
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
CDOMReference<Kit> ref;
if (Constants.LST_ALL.equals(token)) {
ref = context.getReferenceContext().getCDOMAllReference(KIT_CLASS);
} else {
ref = context.getReferenceContext().getCDOMReference(KIT_CLASS, token);
}
refs.add(ref);
}
ReferenceChoiceSet<Kit> rcs = new ReferenceChoiceSet<>(refs);
if (!rcs.getGroupingState().isValid()) {
return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
}
ChoiceSet<Kit> cs = new ChoiceSet<>(getTokenName(), new QualifiedDecorator<>(rcs));
cs.setTitle("Kit Selection");
TransitionChoice<Kit> tc = new ConcreteTransitionChoice<>(cs, count);
context.getObjectContext().addToList(obj, ListKey.KIT_CHOICE, tc);
tc.setRequired(false);
tc.setChoiceActor(this);
return ParseResult.SUCCESS;
}
use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class RegionLst method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject pcc) {
TransitionChoice<Region> tc = context.getObjectContext().getObject(pcc, ObjectKey.REGION_CHOICE);
if (tc == null) {
// indicates no Token
return null;
}
StringBuilder sb = new StringBuilder();
Formula count = tc.getCount();
if (!FormulaFactory.ONE.equals(count)) {
sb.append(count);
sb.append(Constants.PIPE);
}
sb.append(tc.getChoices().getLSTformat().replaceAll(Constants.COMMA, Constants.PIPE));
return new String[] { sb.toString() };
}
use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class CharacterDisplay method getTemplateSR.
/**
* Get the Spell Resistance granted by the given template to a character at a
* given level (Class and Hit Dice). This will include the absolute
* adjustment made with {@literal SR:, LEVEL:<num>:SR and HD:<num>:SR tags}
*
* Note: unlike DR and CR, the value returned here includes the PCs own
* Spell Resistance.
*
* @param pct
* The PCTemplate for which the Spell Resistance will be returned.
* @param level
* The level to calculate the SR for
* @param hitdice
* The Hit dice to calculate the SR for
*
* @return the Spell Resistance granted by the given Template at the given level
* and HD
*/
public int getTemplateSR(PCTemplate pct, int level, int hitdice) {
String qualifiedKey = pct.getQualifiedKey();
Formula reduction = pct.getSafe(ObjectKey.SR).getReduction();
int aSR = formulaResolvingFacet.resolve(id, reduction, qualifiedKey).intValue();
for (PCTemplate rlt : pct.getSafeListFor(ListKey.REPEATLEVEL_TEMPLATES)) {
for (PCTemplate lt : rlt.getSafeListFor(ListKey.LEVEL_TEMPLATES)) {
if (lt.get(IntegerKey.LEVEL) <= level) {
Formula ltReduction = lt.getSafe(ObjectKey.SR).getReduction();
int ltSR = formulaResolvingFacet.resolve(id, ltReduction, qualifiedKey).intValue();
aSR = Math.max(aSR, ltSR);
}
}
}
for (PCTemplate lt : pct.getSafeListFor(ListKey.LEVEL_TEMPLATES)) {
if (lt.get(IntegerKey.LEVEL) <= level) {
Formula ltReduction = lt.getSafe(ObjectKey.SR).getReduction();
int ltSR = formulaResolvingFacet.resolve(id, ltReduction, qualifiedKey).intValue();
aSR = Math.max(aSR, ltSR);
}
}
for (PCTemplate lt : pct.getSafeListFor(ListKey.HD_TEMPLATES)) {
if (lt.get(IntegerKey.HD_MAX) <= hitdice && lt.get(IntegerKey.HD_MIN) >= hitdice) {
Formula ltReduction = lt.getSafe(ObjectKey.SR).getReduction();
int ltSR = formulaResolvingFacet.resolve(id, ltReduction, qualifiedKey).intValue();
aSR = Math.max(aSR, ltSR);
}
}
return aSR;
}
Aggregations