Search in sources :

Example 11 with StatLock

use of pcgen.cdom.helper.StatLock in project pcgen by PCGen.

the class StatMaxValueFacet method dataAdded.

/**
	 * Adds max value StatLock objects granted by a CDOMObject which has been 
	 * added to a Player Character.
	 * 
	 * Triggered when one of the Facets to which StatLockFacet 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<StatLock> locks = cdo.getListFor(ListKey.STAT_MAXVALUE);
    if (locks != null) {
        addAll(dfce.getCharID(), locks, cdo);
    }
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) StatLock(pcgen.cdom.helper.StatLock)

Example 12 with StatLock

use of pcgen.cdom.helper.StatLock in project pcgen by PCGen.

the class StatMinValueFacet method dataAdded.

/**
	 * Adds min value StatLock objects granted by a CDOMObject which has been 
	 * added to a Player Character.
	 * 
	 * Triggered when one of the Facets to which StatLockFacet 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<StatLock> locks = cdo.getListFor(ListKey.STAT_MINVALUE);
    if (locks != null) {
        addAll(dfce.getCharID(), locks, cdo);
    }
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) StatLock(pcgen.cdom.helper.StatLock)

Example 13 with StatLock

use of pcgen.cdom.helper.StatLock in project pcgen by PCGen.

the class DefineStatLst method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    Changes<StatLock> lockChanges = context.getObjectContext().getListChanges(obj, ListKey.STAT_LOCKS);
    Changes<CDOMSingleRef<PCStat>> ulchanges = context.getObjectContext().getListChanges(obj, ListKey.UNLOCKED_STATS);
    Changes<CDOMSingleRef<PCStat>> nonStatChanges = context.getObjectContext().getListChanges(obj, ListKey.NONSTAT_STATS);
    Changes<CDOMSingleRef<PCStat>> nonStatToStatChanges = context.getObjectContext().getListChanges(obj, ListKey.NONSTAT_TO_STAT_STATS);
    Changes<StatLock> minValueChanges = context.getObjectContext().getListChanges(obj, ListKey.STAT_MINVALUE);
    Changes<StatLock> maxValueChanges = context.getObjectContext().getListChanges(obj, ListKey.STAT_MAXVALUE);
    TreeSet<String> set = new TreeSet<>();
    if (lockChanges != null && !lockChanges.isEmpty()) {
        if (lockChanges.includesGlobalClear()) {
            context.addWriteMessage("DEFINE:LOCK does not support .CLEAR");
            return null;
        }
        if (lockChanges.hasAddedItems()) {
            for (StatLock sl : lockChanges.getAdded()) {
                set.add("LOCK|" + sl.getLSTformat() + Constants.PIPE + sl.getLockValue());
            }
        }
    }
    if (ulchanges != null && !ulchanges.isEmpty()) {
        if (ulchanges.includesGlobalClear()) {
            context.addWriteMessage("DEFINE:UNLOCK " + "does not support .CLEAR");
            return null;
        }
        if (ulchanges.hasAddedItems()) {
            for (CDOMSingleRef<PCStat> st : ulchanges.getAdded()) {
                set.add("UNLOCK|" + st.getLSTformat(false));
            }
        }
    }
    if (nonStatChanges != null && !nonStatChanges.isEmpty()) {
        if (nonStatChanges.hasAddedItems()) {
            for (CDOMSingleRef<PCStat> st : nonStatChanges.getAdded()) {
                set.add("NONSTAT|" + st.getLSTformat(false));
            }
        }
    }
    if (nonStatToStatChanges != null && !nonStatToStatChanges.isEmpty()) {
        if (nonStatToStatChanges.hasAddedItems()) {
            for (CDOMSingleRef<PCStat> st : nonStatToStatChanges.getAdded()) {
                set.add("STAT|" + st.getLSTformat(false));
            }
        }
    }
    if (minValueChanges != null && !minValueChanges.isEmpty()) {
        if (minValueChanges.hasAddedItems()) {
            for (StatLock sl : minValueChanges.getAdded()) {
                set.add("MINVALUE|" + sl.getLSTformat() + Constants.PIPE + sl.getLockValue());
            }
        }
    }
    if (maxValueChanges != null && !maxValueChanges.isEmpty()) {
        if (maxValueChanges.hasAddedItems()) {
            for (StatLock sl : maxValueChanges.getAdded()) {
                set.add("MAXVALUE|" + sl.getLSTformat() + Constants.PIPE + sl.getLockValue());
            }
        }
    }
    if (set.isEmpty()) {
        return null;
    }
    return set.toArray(new String[set.size()]);
}
Also used : TreeSet(java.util.TreeSet) PCStat(pcgen.core.PCStat) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) StatLock(pcgen.cdom.helper.StatLock)

Example 14 with StatLock

use of pcgen.cdom.helper.StatLock in project pcgen by PCGen.

the class StatListTest method testMinValueStat.

/**
	 * Test out the output of stats where a min value is in place. 
	 */
public void testMinValueStat() {
    PlayerCharacter pc = getCharacter();
    assertEquals("Starting STR should be 6", 6, pc.getTotalStatFor(str));
    assertEquals("Starting STR mod", -2, pc.getStatModFor(str));
    // With template lock
    PCTemplate statMinValTemplate = new PCTemplate();
    statMinValTemplate.setName("minval");
    statMinValTemplate.addToListFor(ListKey.STAT_MINVALUE, new StatLock(CDOMDirectSingleRef.getRef(str), FormulaFactory.getFormulaFor(8)));
    pc.addTemplate(statMinValTemplate);
    assertEquals("STR now has minimum value", 8, pc.getTotalStatFor(str));
    assertEquals("Starting STR mod", -1, pc.getStatModFor(str));
    pc.removeTemplate(statMinValTemplate);
    assertEquals("STR no longer has minimum value", 6, pc.getTotalStatFor(str));
    assertEquals("Starting STR mod", -2, pc.getStatModFor(str));
}
Also used : StatLock(pcgen.cdom.helper.StatLock)

Example 15 with StatLock

use of pcgen.cdom.helper.StatLock in project pcgen by PCGen.

the class StatLockFacetTest method setUp.

@Override
public void setUp() throws Exception {
    facet = new StatLockFacet();
    super.setUp();
    facet.setFormulaResolvingFacet(new FormulaResolvingFacet());
    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");
    StatLock st1 = new StatLock(CDOMDirectSingleRef.getRef(pcs1), FormulaFactory.getFormulaFor(4));
    StatLock st2 = new StatLock(CDOMDirectSingleRef.getRef(pcs2), FormulaFactory.getFormulaFor(2));
    cdo1.addToListFor(ListKey.STAT_LOCKS, st1);
    cdo2.addToListFor(ListKey.STAT_LOCKS, st2);
    source = new CDOMObject[] { cdo1, cdo2 };
    target = new StatLock[] { st1, st2 };
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) Race(pcgen.core.Race) PCTemplate(pcgen.core.PCTemplate) PCStat(pcgen.core.PCStat) FormulaResolvingFacet(pcgen.cdom.facet.FormulaResolvingFacet) StatLock(pcgen.cdom.helper.StatLock)

Aggregations

StatLock (pcgen.cdom.helper.StatLock)15 CDOMObject (pcgen.cdom.base.CDOMObject)8 PCStat (pcgen.core.PCStat)5 Set (java.util.Set)3 Entry (java.util.Map.Entry)2 PCTemplate (pcgen.core.PCTemplate)2 BonusObj (pcgen.core.bonus.BonusObj)2 LoadContext (pcgen.rules.context.LoadContext)2 TreeSet (java.util.TreeSet)1 Test (org.junit.Test)1 Formula (pcgen.base.formula.Formula)1 ParsingSeparator (pcgen.base.text.ParsingSeparator)1 Ungranted (pcgen.cdom.base.Ungranted)1 FormulaResolvingFacet (pcgen.cdom.facet.FormulaResolvingFacet)1 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)1 AbstractExtractingFacetTest (pcgen.cdom.testsupport.AbstractExtractingFacetTest)1 Equipment (pcgen.core.Equipment)1 Race (pcgen.core.Race)1 Spell (pcgen.core.spell.Spell)1 ParseResult (pcgen.rules.persistence.token.ParseResult)1