Search in sources :

Example 1 with SpellResistance

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);
    }
}
Also used : SpellResistance(pcgen.cdom.content.SpellResistance) CDOMObject(pcgen.cdom.base.CDOMObject)

Example 2 with SpellResistance

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()]);
}
Also used : SpellResistance(pcgen.cdom.content.SpellResistance) LinkedList(java.util.LinkedList)

Example 3 with SpellResistance

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;
}
Also used : Formula(pcgen.base.formula.Formula) SpellResistance(pcgen.cdom.content.SpellResistance) Ungranted(pcgen.cdom.base.Ungranted)

Example 4 with SpellResistance

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 };
}
Also used : Formula(pcgen.base.formula.Formula) SpellResistance(pcgen.cdom.content.SpellResistance) CDOMObject(pcgen.cdom.base.CDOMObject) Race(pcgen.core.Race) PCTemplate(pcgen.core.PCTemplate) PCStat(pcgen.core.PCStat)

Aggregations

SpellResistance (pcgen.cdom.content.SpellResistance)4 Formula (pcgen.base.formula.Formula)2 CDOMObject (pcgen.cdom.base.CDOMObject)2 LinkedList (java.util.LinkedList)1 Ungranted (pcgen.cdom.base.Ungranted)1 PCStat (pcgen.core.PCStat)1 PCTemplate (pcgen.core.PCTemplate)1 Race (pcgen.core.Race)1