use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.
the class EqmodToken method unparse.
@Override
public String[] unparse(LoadContext context, Equipment eq) {
AbstractObjectContext obj = context.getObjectContext();
String damage = obj.getString(eq, StringKey.DAMAGE_OVERRIDE);
Set<String> set = new TreeSet<>();
if (damage != null) {
set.add(EQMOD_DAMAGE + Constants.PIPE + damage);
}
BigDecimal weight = obj.getObject(eq, ObjectKey.WEIGHT_MOD);
if (weight != null) {
set.add(EQMOD_WEIGHT + Constants.PIPE + weight.toString().replace('.', ','));
}
EquipmentHead head = eq.getEquipmentHeadReference(1);
if (head != null) {
Changes<EqModRef> changes = obj.getListChanges(head, ListKey.EQMOD_INFO);
Collection<EqModRef> added = changes.getAdded();
if (added != null) {
for (EqModRef modRef : added) {
String key = modRef.getRef().getLSTformat(false);
StringBuilder sb = new StringBuilder();
sb.append(key);
for (String s : modRef.getChoices()) {
sb.append(Constants.PIPE);
sb.append(s.replace('|', '='));
}
set.add(sb.toString());
}
}
}
if (set.isEmpty()) {
return null;
}
return new String[] { StringUtil.join(set, Constants.DOT) };
}
use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.
the class EqmodToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Equipment eq, String value) {
StringTokenizer dotTok = new StringTokenizer(value, Constants.DOT);
EquipmentHead head = eq.getEquipmentHead(1);
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 AltcritmultToken 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 altHead = eq.getEquipmentHead(2);
context.getObjectContext().put(altHead, IntegerKey.CRIT_MULT, cm);
return ParseResult.SUCCESS;
}
use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.
the class AltcritrangeToken method unparse.
@Override
public String[] unparse(LoadContext context, Equipment eq) {
EquipmentHead head = eq.getEquipmentHeadReference(2);
if (head == null) {
return null;
}
Integer mult = context.getObjectContext().getInteger(head, IntegerKey.CRIT_RANGE);
if (mult == null) {
return null;
}
if (mult < 0) {
context.addWriteMessage(getTokenName() + " cannot be negative: " + mult);
return null;
}
return new String[] { mult.toString() };
}
use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.
the class PartToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Equipment eq, String value) {
int pipeLoc = value.indexOf('|');
if (pipeLoc == -1) {
return new ParseResult.Fail(getTokenName() + " requires <integer>|<token>");
}
String partNumString = value.substring(0, pipeLoc);
int partNumber;
try {
partNumber = Integer.parseInt(partNumString);
} catch (NumberFormatException e) {
return new ParseResult.Fail(getTokenName() + " requires <integer>|<token> ... " + partNumString + " was not an integer");
}
if (partNumber <= 0) {
return new ParseResult.Fail(getTokenName() + " requires a positive integer. " + partNumber + " was not positive");
}
EquipmentHead part = eq.getEquipmentHead(partNumber);
String partToken = value.substring(pipeLoc + 1);
int colonLoc = partToken.indexOf(':');
if (colonLoc == -1) {
return new ParseResult.Fail(getTokenName() + " requires <integer>|<token>:<token content>, but no colon was found in: " + value);
}
String tokenName = partToken.substring(0, colonLoc);
String tokenValue = partToken.substring(colonLoc + 1);
LoadContext subContext = context.dropIntoContext("EQUIPMENT.PART");
boolean processToken;
try {
processToken = subContext.processToken(part, tokenName, tokenValue);
} catch (PersistenceLayerException e) {
return new ParseResult.Fail(getTokenName() + " encountered an error (" + e.getMessage() + ") in the token content of: " + value);
}
if (processToken) {
return ParseResult.SUCCESS;
}
return new ParseResult.Fail(getTokenName() + " encountered an error in the token content of: " + value);
}
Aggregations