use of pcgen.cdom.helper.EqModRef 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.helper.EqModRef 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.helper.EqModRef in project pcgen by PCGen.
the class AlteqmodToken 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(2);
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.helper.EqModRef 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;
}
Aggregations