use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.
the class AlteqmodToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Equipment eq, String value) {
StringTokenizer dotTok = new StringTokenizer(value, Constants.DOT);
EquipmentHead head = eq.getEquipmentHead(2);
while (dotTok.hasMoreTokens()) {
String modInfo = dotTok.nextToken();
if (modInfo.equalsIgnoreCase(Constants.NONE)) {
Logging.deprecationPrint("'NONE' EqMod in " + getTokenName() + " will be ignored", context);
continue;
}
ParseResult pr = checkForIllegalSeparator('|', modInfo);
if (!pr.passed()) {
return pr;
}
StringTokenizer aTok = new StringTokenizer(modInfo, Constants.PIPE);
// The type of EqMod, eg: ABILITYPLUS
String eqModKey = aTok.nextToken();
if (eqModKey.equals(EQMOD_WEIGHT)) {
if (aTok.hasMoreTokens()) {
context.getObjectContext().put(eq, ObjectKey.WEIGHT_MOD, new BigDecimal(aTok.nextToken().replace(',', '.')));
}
continue;
}
if (eqModKey.equals(EQMOD_DAMAGE)) {
if (aTok.hasMoreTokens()) {
context.getObjectContext().put(eq, StringKey.DAMAGE_OVERRIDE, aTok.nextToken());
}
continue;
}
CDOMSingleRef<EquipmentModifier> ref = context.getReferenceContext().getCDOMReference(EQMOD_CLASS, eqModKey);
EqModRef modref = new EqModRef(ref);
while (aTok.hasMoreTokens()) {
modref.addChoice(aTok.nextToken().replace('=', '|'));
}
context.getObjectContext().addToList(head, ListKey.EQMOD_INFO, modref);
}
return ParseResult.SUCCESS;
}
use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.
the class CritmultToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Equipment eq, String value) {
if (ControlUtilities.hasControlToken(context, CControl.CRITMULT)) {
return new ParseResult.Fail(getTokenName() + " is disabled when CRITMULT control is used: " + value, context);
}
Integer cm = null;
if ((!value.isEmpty()) && (value.charAt(0) == 'x')) {
try {
cm = Integer.valueOf(value.substring(1));
if (cm.intValue() <= 0) {
return new ParseResult.Fail(getTokenName() + " cannot be <= 0", context);
}
} catch (NumberFormatException nfe) {
return new ParseResult.Fail(getTokenName() + " was expecting an Integer: " + value, context);
}
} else if ("-".equals(value)) {
cm = -1;
}
if (cm == null) {
return new ParseResult.Fail(getTokenName() + " was expecting x followed by an integer " + "or the special value '-' (representing no value)", context);
}
EquipmentHead primHead = eq.getEquipmentHead(1);
context.getObjectContext().put(primHead, IntegerKey.CRIT_MULT, cm);
return ParseResult.SUCCESS;
}
use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.
the class EqModAttachment method finishEquipment.
public static void finishEquipment(Equipment eq) {
for (int i = 1; i <= 2; i++) {
EquipmentHead head = eq.getEquipmentHeadReference(i);
if (head == null) {
continue;
}
List<EqModRef> modInfoList = head.getListFor(ListKey.EQMOD_INFO);
if (modInfoList == null) {
continue;
}
for (EqModRef modRef : modInfoList) {
List<EquipmentModifier> modlist = head.getListFor(ListKey.EQMOD);
EquipmentModifier eqMod = modRef.getRef().get();
String eqModKey = eqMod.getKeyName();
EquipmentModifier curMod = null;
if (modlist != null) {
for (EquipmentModifier mod : modlist) {
if (mod.getKeyName().equals(eqModKey)) {
curMod = mod;
break;
}
}
}
// If not already attached, then add a new one
if (curMod == null) {
// add qualifiers to modifier
if (!eqMod.getSafe(StringKey.CHOICE_STRING).isEmpty()) {
eqMod = eqMod.clone();
}
eq.addToEqModifierList(eqMod, i == 1);
} else {
eqMod = curMod;
}
// Add the associated choices
if (!eqMod.getSafe(StringKey.CHOICE_STRING).isEmpty()) {
List<String> choices = modRef.getChoices();
for (String x : choices) {
Integer min = eqMod.get(IntegerKey.MIN_CHARGES);
if (min != null && min > 0 || (eqMod.getSafe(StringKey.CHOICE_STRING).startsWith("EQBUILDER"))) {
// We clear the associated info to avoid a
// buildup of info
// like number of charges.
eq.removeAllAssociations(eqMod);
}
eq.addAssociation(eqMod, x);
}
}
}
}
}
Aggregations