Search in sources :

Example 1 with DamageReduction

use of pcgen.cdom.content.DamageReduction in project pcgen by PCGen.

the class DamageReductionFacet method dataAdded.

/**
	 * Extracts DamageReduction objects from CDOMObjects granted to a Player
	 * Character. The DamageReduction objects are granted to the Player
	 * Character.
	 * 
	 * Triggered when one of the Facets to which DamageReductionFacet 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<DamageReduction> drs = cdo.getListFor(ListKey.DAMAGE_REDUCTION);
    if (drs != null) {
        addAll(dfce.getCharID(), drs, cdo);
    }
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) DamageReduction(pcgen.cdom.content.DamageReduction)

Example 2 with DamageReduction

use of pcgen.cdom.content.DamageReduction in project pcgen by PCGen.

the class PreDRTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    drPlus1 = new DamageReduction(FormulaFactory.getFormulaFor(5), "+1");
}
Also used : DamageReduction(pcgen.cdom.content.DamageReduction)

Example 3 with DamageReduction

use of pcgen.cdom.content.DamageReduction in project pcgen by PCGen.

the class DamageReductionFacetTest method testGetDRString.

/**
	 * Test the retrieval of the DR String
	 */
public void testGetDRString() {
    DamageReductionFacet drFacet = new DamageReductionFacet();
    drFacet.setPrerequisiteFacet(new PrerequisiteFacet());
    drFacet.setFormulaResolvingFacet(new FormulaResolvingFacet());
    drFacet.setBonusCheckingFacet(new BonusCheckingFacet() {

        @Override
        public double getBonus(CharID id, String bonusType, String bonusName) {
            return 0.0d;
        }
    });
    Map<DamageReduction, Set<Object>> drList = new IdentityHashMap<>();
    String listResult = drFacet.getDRString(id, drList);
    assertEquals("", listResult);
    Set<Object> sourceSet = new HashSet<>();
    sourceSet.add(new Object());
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("10/magic"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("10/good and magic"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("10/good and magic"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(5), "good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("10/good and magic"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("10/good and magic"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(5), "good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("10/good and magic"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(15), "Good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(5), "good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic and good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(5), "evil"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic or good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic or good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(5), "good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic and good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(5), "magic and good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic or good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(5), "magic and good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/Good; 10/magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic or good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/good; 10/magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(15), "magic"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/good and magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic or good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/good and magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(15), "magic and good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/good and magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic or lawful"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/good and magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(15), "magic and good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/good and magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic and good"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/good and magic; 5/evil"));
    drList.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "magic and lawful"), sourceSet);
    listResult = drFacet.getDRString(id, drList);
    assertTrue(listResult.equalsIgnoreCase("15/good and magic; 10/lawful; 5/evil"));
    Map<DamageReduction, Set<Object>> drList1 = new IdentityHashMap<>();
    drList1.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "epic"), sourceSet);
    drList1.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "lawful or good"), sourceSet);
    listResult = drFacet.getDRString(id, drList1);
    assertTrue(listResult.equalsIgnoreCase("10/epic; 10/lawful or good"));
    drList1.clear();
    drList1.put(new DamageReduction(FormulaFactory.getFormulaFor(10), "epic and good or epic and lawful"), sourceSet);
    listResult = drFacet.getDRString(id, drList1);
    assertTrue(listResult.equalsIgnoreCase("10/epic and good or epic and lawful"));
// TODO Better consolidation: Can't handle this case at the moment.
// drList1.add(new DamageReduction(FormulaFactory.getFormulaFor(10),
// "lawful"));
// listResult = drFacet.getDRString(null, drList1);
// System.out.println("DR List: " + drList1.toString() + " = " +
// listResult);
// assertTrue(listResult.equalsIgnoreCase("10/epic and lawful");
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IdentityHashMap(java.util.IdentityHashMap) CharID(pcgen.cdom.enumeration.CharID) DamageReduction(pcgen.cdom.content.DamageReduction) CDOMObject(pcgen.cdom.base.CDOMObject) HashSet(java.util.HashSet)

Example 4 with DamageReduction

use of pcgen.cdom.content.DamageReduction in project pcgen by PCGen.

the class DrLst method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    Changes<DamageReduction> changes = context.getObjectContext().getListChanges(obj, ListKey.DAMAGE_REDUCTION);
    Collection<DamageReduction> added = changes.getAdded();
    List<String> list = new ArrayList<>();
    if (changes.includesGlobalClear()) {
        list.add(Constants.LST_DOT_CLEAR);
    } else if (added == null || added.isEmpty()) {
        // Zero indicates no Token (and no global clear, so nothing to do)
        return null;
    }
    Set<String> set = new TreeSet<>();
    if (added != null) {
        for (DamageReduction lw : added) {
            StringBuilder sb = new StringBuilder();
            sb.append(lw.getLSTformat());
            if (lw.hasPrerequisites()) {
                sb.append(Constants.PIPE);
                sb.append(context.getPrerequisiteString(lw.getPrerequisiteList()));
            }
            set.add(sb.toString());
        }
    }
    list.addAll(set);
    return list.toArray(new String[list.size()]);
}
Also used : TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) DamageReduction(pcgen.cdom.content.DamageReduction)

Example 5 with DamageReduction

use of pcgen.cdom.content.DamageReduction in project pcgen by PCGen.

the class DamageReductionFacetTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    CDOMObject cdo1 = new PCTemplate();
    cdo1.setName("Templ");
    CDOMObject cdo2 = new Race();
    cdo2.setName("Race");
    DamageReduction dr1 = new DamageReduction(FormulaFactory.getFormulaFor(4), "good");
    DamageReduction dr2 = new DamageReduction(FormulaFactory.getFormulaFor(2), "bad");
    cdo1.addToListFor(ListKey.DAMAGE_REDUCTION, dr1);
    cdo2.addToListFor(ListKey.DAMAGE_REDUCTION, dr2);
    source = new CDOMObject[] { cdo1, cdo2 };
    target = new DamageReduction[] { dr1, dr2 };
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) Race(pcgen.core.Race) PCTemplate(pcgen.core.PCTemplate) DamageReduction(pcgen.cdom.content.DamageReduction)

Aggregations

DamageReduction (pcgen.cdom.content.DamageReduction)13 CDOMObject (pcgen.cdom.base.CDOMObject)4 Set (java.util.Set)3 PlayerCharacter (pcgen.core.PlayerCharacter)3 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 IdentityHashMap (java.util.IdentityHashMap)2 TreeSet (java.util.TreeSet)2 CharID (pcgen.cdom.enumeration.CharID)2 PCTemplate (pcgen.core.PCTemplate)2 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 Formula (pcgen.base.formula.Formula)1 CaseInsensitiveMap (pcgen.base.util.CaseInsensitiveMap)1 Ungranted (pcgen.cdom.base.Ungranted)1 PCStat (pcgen.core.PCStat)1 Race (pcgen.core.Race)1 BonusObj (pcgen.core.bonus.BonusObj)1 Prerequisite (pcgen.core.prereq.Prerequisite)1