use of pcgen.cdom.content.SpellResistance in project pcgen by PCGen.
the class CharacterSpellResistanceFacet method dataAdded.
/**
* Captures any SpellResistance objects granted by CDOMObjects added to the
* Player Character and adds those SpellResisteance objects to this
* CharacterSpellResistanceFacet for the Player Character.
*
* Triggered when one of the Facets to which CharacterSpellResistanceFacet
* 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();
SpellResistance sr = cdo.get(ObjectKey.SR);
if (sr != null) {
add(dfce.getCharID(), sr.getReduction(), cdo);
}
}
use of pcgen.cdom.content.SpellResistance in project pcgen by PCGen.
the class SrLst method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
SpellResistance sr = context.getObjectContext().getObject(obj, ObjectKey.SR);
boolean b = context.getObjectContext().wasRemoved(obj, ObjectKey.SR);
List<String> list = new LinkedList<>();
if (b) {
list.add(Constants.LST_DOT_CLEAR);
}
if (sr != null) {
list.add(sr.getLSTformat());
}
if (list.isEmpty()) {
return null;
}
return list.toArray(new String[list.size()]);
}
use of pcgen.cdom.content.SpellResistance in project pcgen by PCGen.
the class SrLst method parseToken.
@Override
public ParseResult parseToken(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);
}
if (Constants.LST_DOT_CLEAR.equals(value)) {
context.getObjectContext().remove(obj, ObjectKey.SR);
} else {
Formula formula = FormulaFactory.getFormulaFor(value);
if (!formula.isValid()) {
return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + formula.toString(), context);
}
context.getObjectContext().put(obj, ObjectKey.SR, new SpellResistance(formula));
}
return ParseResult.SUCCESS;
}
use of pcgen.cdom.content.SpellResistance in project pcgen by PCGen.
the class CharacterSpellResistanceFacetTest 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");
Formula st1 = FormulaFactory.getFormulaFor(4);
Formula st2 = FormulaFactory.getFormulaFor(2);
cdo1.put(ObjectKey.SR, new SpellResistance(st1));
cdo2.put(ObjectKey.SR, new SpellResistance(st2));
source = new CDOMObject[] { cdo1, cdo2 };
target = new Formula[] { st1, st2 };
}
Aggregations