Search in sources :

Example 1 with Movement

use of pcgen.core.Movement in project pcgen by PCGen.

the class MovementFacet 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 MovementFacet 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();
    /*
		 * TODO Should consider here whether this should get input from
		 * BaseMovementFacet vs. capturing these directly. The reason that this
		 * is done directly is that BaseMovementFacet would have to override
		 * methods to get this add done, so that is risky, then since this is
		 * already listening to the consolidated objectfacet, yet another class
		 * would be required to do the listening for Movement objects added into
		 * BaseMovementFacet. This is not unreasonable, though perhaps not pure
		 * in that this uses to ListKey objects.
		 */
    List<Movement> ml = cdo.getListFor(ListKey.BASE_MOVEMENT);
    if (ml != null) {
        addAll(dfce.getCharID(), ml, cdo);
    }
    ml = cdo.getListFor(ListKey.MOVEMENT);
    if (ml != null) {
        addAll(dfce.getCharID(), ml, cdo);
    }
}
Also used : Movement(pcgen.core.Movement) CDOMObject(pcgen.cdom.base.CDOMObject)

Example 2 with Movement

use of pcgen.core.Movement in project pcgen by PCGen.

the class MoveToken method unparse.

@Override
public String[] unparse(LoadContext context, Race obj) {
    Changes<Movement> changes = context.getObjectContext().getListChanges(obj, ListKey.BASE_MOVEMENT);
    Collection<Movement> added = changes.getAdded();
    if (added == null || added.isEmpty()) {
        // Zero indicates no Token
        return null;
    }
    Set<String> set = new TreeSet<>();
    for (Movement m : added) {
        if (m.getMoveRatesFlag() == 0) {
            StringBuilder sb = new StringBuilder();
            m.addTokenContents(sb);
            set.add(sb.toString());
        }
    }
    if (set.isEmpty()) {
        return null;
    }
    return set.toArray(new String[set.size()]);
}
Also used : Movement(pcgen.core.Movement) TreeSet(java.util.TreeSet)

Example 3 with Movement

use of pcgen.core.Movement in project pcgen by PCGen.

the class MovementFacetTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    CDOMObject cdo1 = new PCTemplate();
    cdo1.setName("Templ");
    CDOMObject cdo2 = new Race();
    cdo2.setName("Race");
    PCStat pcs1 = new PCStat();
    pcs1.setName("Stat1");
    PCStat pcs2 = new PCStat();
    pcs2.setName("Stat2");
    Movement st1 = new Movement(1);
    Movement st2 = new Movement(1);
    cdo1.addToListFor(ListKey.MOVEMENT, st1);
    cdo2.addToListFor(ListKey.MOVEMENT, st2);
    source = new CDOMObject[] { cdo1, cdo2 };
    target = new Movement[] { st1, st2 };
}
Also used : Movement(pcgen.core.Movement) CDOMObject(pcgen.cdom.base.CDOMObject) Race(pcgen.core.Race) PCTemplate(pcgen.core.PCTemplate) PCStat(pcgen.core.PCStat)

Example 4 with Movement

use of pcgen.core.Movement in project pcgen by PCGen.

the class MoveLst 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;
    }
    Set<String> set = new TreeSet<>();
    for (Movement m : added) {
        if (m.getMoveRatesFlag() == 0) {
            StringBuilder sb = new StringBuilder();
            m.addTokenContents(sb);
            set.add(sb.toString());
        }
    }
    if (set.isEmpty()) {
        return null;
    }
    return set.toArray(new String[set.size()]);
}
Also used : Movement(pcgen.core.Movement) TreeSet(java.util.TreeSet)

Example 5 with Movement

use of pcgen.core.Movement in project pcgen by PCGen.

the class MoveLst 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);
    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.MOVEMENT, cm);
    return ParseResult.SUCCESS;
}
Also used : StringTokenizer(java.util.StringTokenizer) Movement(pcgen.core.Movement) ParseResult(pcgen.rules.persistence.token.ParseResult) Ungranted(pcgen.cdom.base.Ungranted)

Aggregations

Movement (pcgen.core.Movement)9 StringTokenizer (java.util.StringTokenizer)3 CDOMObject (pcgen.cdom.base.CDOMObject)3 ParseResult (pcgen.rules.persistence.token.ParseResult)3 TreeSet (java.util.TreeSet)2 Ungranted (pcgen.cdom.base.Ungranted)2 WeightedCollection (pcgen.base.util.WeightedCollection)1 PCStat (pcgen.core.PCStat)1 PCTemplate (pcgen.core.PCTemplate)1 Race (pcgen.core.Race)1