use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.
the class WeaponToken method getNewCritRangeString.
public static String getNewCritRangeString(PlayerCharacter pc, Equipment eq, String critRangeVar) {
StringBuilder sb = new StringBuilder();
boolean needSlash = false;
for (EquipmentHead head : eq.getEquipmentHeads()) {
if (needSlash) {
sb.append("/");
}
sb.append(getCritRangeHead(pc, head, critRangeVar));
needSlash = true;
}
return sb.toString();
}
use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.
the class NaturalattacksLst method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
Changes<Equipment> changes = context.getObjectContext().getListChanges(obj, ListKey.NATURAL_WEAPON);
Collection<Equipment> eqadded = changes.getAdded();
if (eqadded == null || eqadded.isEmpty()) {
return null;
}
StringBuilder sb = new StringBuilder();
boolean first = true;
for (Equipment lstw : eqadded) {
if (!first) {
sb.append(Constants.PIPE);
}
Equipment eq = Equipment.class.cast(lstw);
String name = eq.getDisplayName();
// TODO objcontext.getString(eq, StringKey.NAME);
if (name == null) {
context.addWriteMessage(getTokenName() + " expected Equipment to have a name");
return null;
}
sb.append(name).append(Constants.COMMA);
List<Type> type = eq.getListFor(ListKey.TYPE);
if (type == null || type.isEmpty()) {
context.addWriteMessage(getTokenName() + " expected Equipment to have a type");
return null;
}
sb.append(StringUtil.join(type, Constants.DOT));
sb.append(Constants.COMMA);
Boolean attProgress = eq.get(ObjectKey.ATTACKS_PROGRESS);
if (attProgress == null) {
context.addWriteMessage(getTokenName() + " expected Equipment to know ATTACKS_PROGRESS state");
return null;
} else if (!attProgress.booleanValue()) {
sb.append(Constants.CHAR_ASTERISK);
}
List<BonusObj> bonuses = eq.getListFor(ListKey.BONUS);
if (bonuses == null || bonuses.isEmpty()) {
sb.append('1');
} else {
if (bonuses.size() != 1) {
context.addWriteMessage(getTokenName() + " expected only one BONUS on Equipment: " + bonuses);
return null;
}
// TODO Validate BONUS type?
BonusObj extraAttacks = bonuses.iterator().next();
sb.append(Integer.parseInt(extraAttacks.getValue()) + 1);
}
sb.append(Constants.COMMA);
EquipmentHead head = eq.getEquipmentHeadReference(1);
if (head == null) {
context.addWriteMessage(getTokenName() + " expected an EquipmentHead on Equipment");
return null;
}
String damage = head.get(StringKey.DAMAGE);
if (damage == null) {
context.addWriteMessage(getTokenName() + " expected a Damage on EquipmentHead");
return null;
}
sb.append(damage);
Integer hands = eq.get(IntegerKey.SLOTS);
if (hands != null && hands != 0) {
sb.append(',').append(hands);
}
List<SpecialProperty> spropList = eq.getSafeListFor(ListKey.SPECIAL_PROPERTIES);
for (SpecialProperty sprop : spropList) {
sb.append(",SPROP=").append(sprop.toString());
}
first = false;
}
return new String[] { sb.toString() };
}
use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.
the class AlttypeToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Equipment eq, String value) {
EquipmentHead head = eq.getEquipmentHead(2);
if (value.startsWith(Constants.LST_DOT_CLEAR)) {
context.getObjectContext().removeList(head, ListKey.TYPE);
if (value.length() == 6) {
return ParseResult.SUCCESS;
} else if (value.charAt(6) == '.') {
value = value.substring(7);
if (isEmpty(value)) {
return new ParseResult.Fail(getTokenName() + "started with .CLEAR. but expected to have a Type after .: " + value, context);
}
} else {
return new ParseResult.Fail(getTokenName() + "started with .CLEAR but expected next character to be .: " + value, context);
}
}
ParseResult pr = checkForIllegalSeparator('.', value);
if (!pr.passed()) {
return pr;
}
StringTokenizer aTok = new StringTokenizer(value, Constants.DOT);
boolean bRemove = false;
boolean bAdd = false;
while (aTok.hasMoreTokens()) {
final String aType = aTok.nextToken();
if ("ADD".equals(aType)) {
if (bRemove) {
return new ParseResult.Fail("Non-sensical use of .REMOVE.ADD. in " + getTokenName() + ": " + value, context);
}
bRemove = false;
bAdd = true;
} else if ("REMOVE".equals(aType)) {
if (bAdd) {
return new ParseResult.Fail("Non-sensical use of .ADD.REMOVE. in " + getTokenName() + ": " + value, context);
}
bRemove = true;
} else if ("CLEAR".equals(aType)) {
return new ParseResult.Fail("Non-sensical use of .CLEAR in " + getTokenName() + ": " + value, context);
} else if (bRemove) {
Type type = Type.getConstant(aType);
context.getObjectContext().removeFromList(head, ListKey.TYPE, type);
bRemove = false;
} else {
Type type = Type.getConstant(aType);
context.getObjectContext().addToList(head, ListKey.TYPE, type);
bAdd = false;
}
}
if (bRemove) {
return new ParseResult.Fail(getTokenName() + "ended with REMOVE, so didn't have any Type to remove: " + value, context);
}
if (bAdd) {
return new ParseResult.Fail(getTokenName() + "ended with ADD, so didn't have any Type to add: " + value, context);
}
return ParseResult.SUCCESS;
}
use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.
the class AlttypeToken method unparse.
@Override
public String[] unparse(LoadContext context, Equipment eq) {
EquipmentHead head = eq.getEquipmentHead(2);
Changes<Type> changes = context.getObjectContext().getListChanges(head, ListKey.TYPE);
if (changes == null || changes.isEmpty()) {
return null;
}
StringBuilder sb = new StringBuilder();
Collection<?> added = changes.getAdded();
boolean globalClear = changes.includesGlobalClear();
if (globalClear) {
sb.append(Constants.LST_DOT_CLEAR);
}
if (added != null && !added.isEmpty()) {
if (globalClear) {
sb.append(Constants.DOT);
}
sb.append(StringUtil.join(added, Constants.DOT));
}
Collection<Type> removed = changes.getRemoved();
if (removed != null && !removed.isEmpty()) {
if (sb.length() > 0) {
sb.append(Constants.DOT);
}
sb.append("REMOVE.");
sb.append(StringUtil.join(removed, Constants.DOT));
}
if (sb.length() == 0) {
context.addWriteMessage(getTokenName() + " was expecting non-empty changes to include " + "added items or global clear");
return null;
}
return new String[] { sb.toString() };
}
use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.
the class CritmultToken method unparse.
@Override
public String[] unparse(LoadContext context, Equipment eq) {
EquipmentHead head = eq.getEquipmentHeadReference(1);
if (head == null) {
return null;
}
Integer mult = context.getObjectContext().getInteger(head, IntegerKey.CRIT_MULT);
if (mult == null) {
return null;
}
int multInt = mult.intValue();
String retString;
if (multInt == -1) {
retString = "-";
} else if (multInt <= 0) {
context.addWriteMessage(getTokenName() + " cannot be <= 0");
return null;
} else {
retString = "x" + multInt;
}
return new String[] { retString };
}
Aggregations