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