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);
}
}
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);
}
}
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()]);
}
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));
}
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 };
}
Aggregations