Search in sources :

Example 26 with CDOMObject

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

Example 27 with CDOMObject

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

Example 28 with CDOMObject

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

Example 29 with CDOMObject

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

Example 30 with CDOMObject

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);
            }
        }
    }
}
Also used : Formula(pcgen.base.formula.Formula) CDOMObject(pcgen.cdom.base.CDOMObject) SpellLikeAbility(pcgen.cdom.content.SpellLikeAbility) CharID(pcgen.cdom.enumeration.CharID) CDOMReference(pcgen.cdom.base.CDOMReference) Spell(pcgen.core.spell.Spell) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Aggregations

CDOMObject (pcgen.cdom.base.CDOMObject)235 Test (org.junit.Test)68 CharID (pcgen.cdom.enumeration.CharID)53 PCTemplate (pcgen.core.PCTemplate)30 ArrayList (java.util.ArrayList)22 PCClass (pcgen.core.PCClass)18 DataFacetChangeEvent (pcgen.cdom.facet.event.DataFacetChangeEvent)17 Race (pcgen.core.Race)17 Equipment (pcgen.core.Equipment)15 PlayerCharacter (pcgen.core.PlayerCharacter)15 Map (java.util.Map)14 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)14 CDOMReference (pcgen.cdom.base.CDOMReference)14 BonusObj (pcgen.core.bonus.BonusObj)14 IdentityHashMap (java.util.IdentityHashMap)12 Set (java.util.Set)12 VariableKey (pcgen.cdom.enumeration.VariableKey)11 HashMap (java.util.HashMap)10 CNAbility (pcgen.cdom.content.CNAbility)10 Spell (pcgen.core.spell.Spell)9