use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.
the class PrereqHandler method passes.
/**
* Returns true if the character passes the prereq.
* @param prereq The prerequisite to test.
* @param aPC The character to test against
* @param caller The CDOMObject that is calling this method
* @return true if the character passes the prereq
*/
public static boolean passes(final Prerequisite prereq, final PlayerCharacter aPC, final Object caller) {
if (aPC == null && prereq.isCharacterRequired()) {
return true;
}
final PrerequisiteTestFactory factory = PrerequisiteTestFactory.getInstance();
final PrerequisiteTest test = factory.getTest(prereq.getKind());
if (test == null) {
Logging.errorPrintLocalised("PrereqHandler.Unable_to_find_implementation", //$NON-NLS-1$
prereq.toString());
return false;
}
final boolean overrideQualify = prereq.isOverrideQualify();
boolean autoQualifies = false;
int total = 0;
if (caller instanceof CDOMObject && aPC != null && aPC.checkQualifyList((CDOMObject) caller) && (!overrideQualify)) {
autoQualifies = true;
}
if (autoQualifies) {
return true;
}
try {
CDOMObject cdomCaller = (caller instanceof CDOMObject) ? (CDOMObject) caller : null;
total = test.passes(prereq, aPC, cdomCaller);
} catch (PrerequisiteException pe) {
//$NON-NLS-1$
Logging.errorPrintLocalised("PrereqHandler.Exception_in_test", pe);
} catch (Exception e) {
final String callerString = (caller != null) ? " for " + String.valueOf(caller) : Constants.EMPTY_STRING;
Logging.errorPrint("Problem encountered when testing PREREQ " + String.valueOf(prereq) + callerString + ". See following trace for details.", e);
}
return total > 0;
}
use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.
the class PlayerCharacter method getDC.
/**
* Returns DC for a spell and SpellInfo.
* @param sp the spell
* @param cs TODO
* @param si the spell info
* @return DC for a spell and SpellInfo
*/
public int getDC(final Spell sp, CharacterSpell cs, final SpellInfo si) {
CDOMObject ow = null;
int spellLevel = 0;
int metaDC = 0;
spellLevel = si.getActualLevel();
ow = cs.getOwner();
String fixedDC = si.getFixedDC();
/*
* TODO Need to evaluate how duplicative this logic is and what is
* really necessary
*/
if (fixedDC != null && "INNATE".equalsIgnoreCase(si.getBook())) {
return getVariableValue(fixedDC, "").intValue();
}
// Check for a non class based fixed DC
if (fixedDC != null && ow != null && !(ow instanceof PCClass)) {
return getVariableValue(fixedDC, "").intValue();
}
if (si.getFeatList() != null) {
for (Ability metaFeat : si.getFeatList()) {
spellLevel -= metaFeat.getSafe(IntegerKey.ADD_SPELL_LEVEL);
metaDC = (int) (metaDC + BonusCalc.charBonusTo(metaFeat, "DC", "FEATBONUS", this));
}
}
return getDC(sp, null, spellLevel, metaDC, ow);
}
use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.
the class PlayerCharacter method getConcentration.
/**
* Returns concentration bonus for a spell and SpellInfo.
* @param sp the spell
* @param cs TODO
* @param si the spell info
* @return concentration bonus for a spell and SpellInfo
*/
public int getConcentration(final Spell sp, CharacterSpell cs, final SpellInfo si) {
CDOMObject ow = null;
int spellLevel = 0;
int metaConcentration = 0;
spellLevel = si.getActualLevel();
ow = cs.getOwner();
if (si.getFeatList() != null) {
for (Ability metaFeat : si.getFeatList()) {
spellLevel -= metaFeat.getSafe(IntegerKey.ADD_SPELL_LEVEL);
metaConcentration = (int) (metaConcentration + BonusCalc.charBonusTo(metaFeat, "CONCENTRATION", "FEATBONUS", this));
}
}
return getConcentration(sp, cs, null, spellLevel, metaConcentration, ow);
}
use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.
the class PlayerCharacter method getPObjectWithCostBonusTo.
/**
* Returns a bonus.
*
* @param aList
* @param aType
* @param aName
* @return double
*/
private double getPObjectWithCostBonusTo(final Collection<? extends CDOMObject> aList, final String aType, final String aName) {
double iBonus = 0;
if (aList.isEmpty()) {
return iBonus;
}
for (CDOMObject anObj : aList) {
final List<BonusObj> tempList = BonusUtilities.getBonusFromList(anObj.getBonusList(this), aType, aName);
iBonus += calcBonusWithCostFromList(tempList);
}
return iBonus;
}
use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.
the class SpellsFacet method dataAdded.
/**
* Adds a SpellLikeAbility to this facet if the CDOMObject added to a Player
* Character contains a SPELLS entry.
*
* Triggered when one of the Facets to which SpellsFacet 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) {
CharID id = dfce.getCharID();
CDOMObject cdo = dfce.getCDOMObject();
Collection<CDOMReference<Spell>> mods = cdo.getListMods(Spell.SPELLS);
if (mods == null) {
return;
}
for (CDOMReference<Spell> ref : mods) {
Collection<AssociatedPrereqObject> assocs = cdo.getListAssociations(Spell.SPELLS, ref);
Collection<Spell> spells = ref.getContainedObjects();
for (AssociatedPrereqObject apo : assocs) {
Formula times = apo.getAssociation(AssociationKey.TIMES_PER_UNIT);
String timeunit = apo.getAssociation(AssociationKey.TIME_UNIT);
// The timeunit needs to default to day as per the docs
if (timeunit == null) {
timeunit = "Day";
}
String casterlevel = apo.getAssociation(AssociationKey.CASTER_LEVEL);
String dcformula = apo.getAssociation(AssociationKey.DC_FORMULA);
String book = apo.getAssociation(AssociationKey.SPELLBOOK);
String ident = cdo.getQualifiedKey();
for (Spell sp : spells) {
SpellLikeAbility sla = new SpellLikeAbility(sp, times, timeunit, book, casterlevel, dcformula, ident);
sla.addAllPrerequisites(apo.getPrerequisiteList());
add(id, sla, cdo);
}
}
}
}
Aggregations