use of pcgen.core.Movement in project pcgen by PCGen.
the class MovecloneLst method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
Changes<Movement> changes = context.getObjectContext().getListChanges(obj, ListKey.MOVEMENT);
Collection<Movement> added = changes.getAdded();
if (added == null || added.isEmpty()) {
// Zero indicates no Token
return null;
}
WeightedCollection<String> set = new WeightedCollection<>(String.CASE_INSENSITIVE_ORDER);
for (Movement m : added) {
if (m.getMoveRatesFlag() == 2) {
StringBuilder sb = new StringBuilder();
m.addTokenContents(sb);
set.add(sb.toString());
}
}
if (set.isEmpty()) {
return null;
}
return set.toArray(new String[set.size()]);
}
use of pcgen.core.Movement in project pcgen by PCGen.
the class MoveToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Race obj, String value) {
StringTokenizer moves = new StringTokenizer(value, Constants.COMMA);
Movement cm;
if (moves.countTokens() == 1) {
cm = new Movement(1);
String mod = moves.nextToken();
ParseResult pr = validateMove(value, mod);
if (!pr.passed()) {
return pr;
}
cm.assignMovement(0, "Walk", mod);
} else {
cm = new Movement(moves.countTokens() / 2);
int x = 0;
while (moves.countTokens() > 1) {
String type = moves.nextToken();
String mod = moves.nextToken();
ParseResult pr = validateMove(value, mod);
if (!pr.passed()) {
return pr;
}
cm.assignMovement(x++, type, mod);
}
if (moves.countTokens() != 0) {
return new ParseResult.Fail("Badly formed MOVE token " + "(extra value at end of list): " + value, context);
}
}
cm.setMoveRatesFlag(0);
context.getObjectContext().addToList(obj, ListKey.BASE_MOVEMENT, cm);
return ParseResult.SUCCESS;
}
use of pcgen.core.Movement in project pcgen by PCGen.
the class BaseMovementFacet method dataAdded.
/**
* Adds to this Facet the Movement objects contained within a CDOMObject
* granted to the Player Character.
*
* Triggered when one of the Facets to which BaseMovementFacet listens fires
* a DataFacetChangeEvent to indicate a CDOMObject was added to a Player
* Character.
*
* @param dfce
* The DataFacetChangeEvent containing the information about the
* change
*
* @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
*/
@Override
public void dataAdded(DataFacetChangeEvent<CharID, CDOMObject> dfce) {
CDOMObject cdo = dfce.getCDOMObject();
List<Movement> ml = cdo.getListFor(ListKey.BASE_MOVEMENT);
if (ml != null) {
addAll(dfce.getCharID(), ml, cdo);
}
}
use of pcgen.core.Movement in project pcgen by PCGen.
the class MovecloneLst 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);
}
StringTokenizer moves = new StringTokenizer(value, Constants.COMMA);
if (moves.countTokens() != 3) {
return new ParseResult.Fail("Invalid Version of MOVECLONE detected: " + value + "\n MOVECLONE has 3 arguments: " + "SourceMove,DestinationMove,Modifier", context);
}
String oldType = moves.nextToken();
String newType = moves.nextToken();
String formulaString = moves.nextToken();
if (formulaString.startsWith("/")) {
try {
int denom = Integer.parseInt(formulaString.substring(1));
if (denom <= 0) {
return new ParseResult.Fail(getTokenName() + " was expecting a Positive Integer " + "for dividing Movement, was : " + formulaString.substring(1), context);
}
} catch (NumberFormatException e) {
return new ParseResult.Fail(getTokenName() + " was expecting an integer to follow /, was : " + formulaString, context);
}
} else if (formulaString.startsWith("*")) {
try {
float mult = Float.parseFloat(formulaString.substring(1));
if (mult < 0.0) {
return new ParseResult.Fail(getTokenName() + " was expecting a " + "Float >= 0 for multiplying Movement, was : " + formulaString.substring(1), context);
}
} catch (NumberFormatException e) {
return new ParseResult.Fail(getTokenName() + " was expecting an integer to follow *, was : " + formulaString, context);
}
} else if (formulaString.startsWith("+")) {
try {
int add = Integer.parseInt(formulaString.substring(1));
if (add < 0) {
return new ParseResult.Fail(getTokenName() + " was expecting a Non-Negative " + "Integer for adding Movement, was : " + formulaString.substring(1), context);
}
} catch (NumberFormatException e) {
return new ParseResult.Fail(getTokenName() + " was expecting an integer to follow +, was : " + formulaString, context);
}
} else {
try {
Integer.parseInt(formulaString);
} catch (NumberFormatException e) {
return new ParseResult.Fail(getTokenName() + " was expecting a Formula as the final value, was : " + formulaString, context);
}
}
Movement cm = new Movement(2);
cm.assignMovement(0, oldType, "0");
cm.assignMovement(1, newType, formulaString);
cm.setMoveRatesFlag(2);
context.getObjectContext().addToList(obj, ListKey.MOVEMENT, cm);
return ParseResult.SUCCESS;
}
Aggregations