Search in sources :

Example 1 with VariableKey

use of pcgen.cdom.enumeration.VariableKey in project pcgen by PCGen.

the class VariableFacet method dataAdded.

/**
	 * Adds variables and their Formulas when a variable is granted by a
	 * CDOMObject which is added to a Player Character.
	 * 
	 * Triggered when one of the Facets to which VariableFacet 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();
    Set<VariableKey> keys = cdo.getVariableKeys();
    CharID id = dfce.getCharID();
    for (VariableKey vk : keys) {
        add(id, vk, cdo.get(vk), cdo);
    }
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) VariableKey(pcgen.cdom.enumeration.VariableKey) CharID(pcgen.cdom.enumeration.CharID)

Example 2 with VariableKey

use of pcgen.cdom.enumeration.VariableKey in project pcgen by PCGen.

the class PCClass method inheritAttributesFrom.

/*
	 * REFACTOR Some derivative of this method will be in PCClass only as part
	 * of the factory creation of a PCClassLevel... or perhaps in PCClassLevel
	 * so it can steal some information from other PCClassLevels of that
	 * PCClass. Either way, this will be far from its current form in the final
	 * solution.
	 */
/*
	 * CONSIDER Why does this not inherit classSkillChoices?
	 */
public void inheritAttributesFrom(final PCClass otherClass) {
    Boolean hbss = otherClass.get(ObjectKey.HAS_BONUS_SPELL_STAT);
    if (hbss != null) {
        put(ObjectKey.HAS_BONUS_SPELL_STAT, hbss);
        CDOMSingleRef<PCStat> bss = otherClass.get(ObjectKey.BONUS_SPELL_STAT);
        if (bss != null) {
            put(ObjectKey.BONUS_SPELL_STAT, bss);
        }
    }
    Boolean usbs = otherClass.get(ObjectKey.USE_SPELL_SPELL_STAT);
    if (usbs != null) {
        put(ObjectKey.USE_SPELL_SPELL_STAT, usbs);
    }
    Boolean cwss = otherClass.get(ObjectKey.CASTER_WITHOUT_SPELL_STAT);
    if (cwss != null) {
        put(ObjectKey.CASTER_WITHOUT_SPELL_STAT, cwss);
    }
    CDOMSingleRef<PCStat> ss = otherClass.get(ObjectKey.SPELL_STAT);
    if (ss != null) {
        put(ObjectKey.SPELL_STAT, ss);
    }
    TransitionChoice<CDOMListObject<Spell>> slc = otherClass.get(ObjectKey.SPELLLIST_CHOICE);
    if (slc != null) {
        put(ObjectKey.SPELLLIST_CHOICE, slc);
    }
    List<QualifiedObject<CDOMReference<Equipment>>> e = otherClass.getListFor(ListKey.EQUIPMENT);
    if (e != null) {
        addAllToListFor(ListKey.EQUIPMENT, e);
    }
    List<WeaponProfProvider> wp = otherClass.getListFor(ListKey.WEAPONPROF);
    if (wp != null) {
        addAllToListFor(ListKey.WEAPONPROF, wp);
    }
    QualifiedObject<Boolean> otherWP = otherClass.get(ObjectKey.HAS_DEITY_WEAPONPROF);
    if (otherWP != null) {
        put(ObjectKey.HAS_DEITY_WEAPONPROF, otherWP);
    }
    List<ArmorProfProvider> ap = otherClass.getListFor(ListKey.AUTO_ARMORPROF);
    if (ap != null) {
        addAllToListFor(ListKey.AUTO_ARMORPROF, ap);
    }
    List<ShieldProfProvider> sp = otherClass.getListFor(ListKey.AUTO_SHIELDPROF);
    if (sp != null) {
        addAllToListFor(ListKey.AUTO_SHIELDPROF, sp);
    }
    List<BonusObj> bonusList = otherClass.getListFor(ListKey.BONUS);
    if (bonusList != null) {
        addAllToListFor(ListKey.BONUS, bonusList);
    }
    try {
        ownBonuses(this);
    } catch (CloneNotSupportedException ce) {
        // TODO Auto-generated catch block
        ce.printStackTrace();
    }
    for (VariableKey vk : otherClass.getVariableKeys()) {
        put(vk, otherClass.get(vk));
    }
    if (otherClass.containsListFor(ListKey.CSKILL)) {
        removeListFor(ListKey.CSKILL);
        addAllToListFor(ListKey.CSKILL, otherClass.getListFor(ListKey.CSKILL));
    }
    if (otherClass.containsListFor(ListKey.LOCALCCSKILL)) {
        removeListFor(ListKey.LOCALCCSKILL);
        addAllToListFor(ListKey.LOCALCCSKILL, otherClass.getListFor(ListKey.LOCALCCSKILL));
    }
    removeListFor(ListKey.KIT_CHOICE);
    addAllToListFor(ListKey.KIT_CHOICE, otherClass.getSafeListFor(ListKey.KIT_CHOICE));
    remove(ObjectKey.REGION_CHOICE);
    if (otherClass.containsKey(ObjectKey.REGION_CHOICE)) {
        put(ObjectKey.REGION_CHOICE, otherClass.get(ObjectKey.REGION_CHOICE));
    }
    removeListFor(ListKey.SAB);
    addAllToListFor(ListKey.SAB, otherClass.getSafeListFor(ListKey.SAB));
    /*
		 * TODO Does this need to have things from the Class Level objects?
		 * I don't think so based on deferred processing of levels...
		 */
    addAllToListFor(ListKey.DAMAGE_REDUCTION, otherClass.getListFor(ListKey.DAMAGE_REDUCTION));
    for (CDOMReference<Vision> ref : otherClass.getSafeListMods(Vision.VISIONLIST)) {
        for (AssociatedPrereqObject apo : otherClass.getListAssociations(Vision.VISIONLIST, ref)) {
            putToList(Vision.VISIONLIST, ref, apo);
        }
    }
    /*
		 * TODO This is a clone problem, but works for now - thpr 10/3/08
		 */
    if (otherClass instanceof SubClass) {
        levelMap.clear();
        copyLevelsFrom(otherClass);
    }
    addAllToListFor(ListKey.NATURAL_WEAPON, otherClass.getListFor(ListKey.NATURAL_WEAPON));
    put(ObjectKey.LEVEL_HITDIE, otherClass.get(ObjectKey.LEVEL_HITDIE));
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) CDOMListObject(pcgen.cdom.base.CDOMListObject) WeaponProfProvider(pcgen.cdom.helper.WeaponProfProvider) ArmorProfProvider(pcgen.cdom.helper.ArmorProfProvider) VariableKey(pcgen.cdom.enumeration.VariableKey) ShieldProfProvider(pcgen.cdom.helper.ShieldProfProvider) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 3 with VariableKey

use of pcgen.cdom.enumeration.VariableKey in project pcgen by PCGen.

the class VariableFacet method getVariableValue.

/**
	 * Returns the numeric variable value for the given VariableKey on the
	 * Player Character identified by the given CharID. If a variable has more
	 * than one value, the given isMax argument is used to determine if this
	 * method returns the maximum (true) or minimum (false) of the calculated
	 * values.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character for which the
	 *            numeric variable value is to be returned
	 * @param key
	 *            The VariableKey identifying the variable which the value
	 *            is to be returned
	 * @param isMax
	 *            Used to determine if this method returns the maximum (true) or
	 *            minimum (false) of the calculated values when the Player
	 *            Character contains more than one value for the given
	 *            VariableKey
	 * @return The numeric variable value for the given VariableKey on the
	 *         Player Character identified by the given CharID
	 */
public Double getVariableValue(CharID id, VariableKey key, boolean isMax) {
    Map<VariableKey, Map<Formula, Set<CDOMObject>>> vkMap = getCachedMap(id);
    if (vkMap == null) {
        return null;
    }
    Map<Formula, Set<CDOMObject>> fMap = vkMap.get(key);
    if (fMap == null) {
        return null;
    }
    Double returnValue = null;
    for (Map.Entry<Formula, Set<CDOMObject>> me : fMap.entrySet()) {
        Formula f = me.getKey();
        Set<CDOMObject> sources = me.getValue();
        for (CDOMObject source : sources) {
            double newVal = formulaResolvingFacet.resolve(id, f, source.getQualifiedKey()).doubleValue();
            if (returnValue == null) {
                returnValue = newVal;
            } else if ((returnValue > newVal) ^ isMax) {
                returnValue = newVal;
            }
        }
    }
    return returnValue;
}
Also used : Formula(pcgen.base.formula.Formula) Set(java.util.Set) WrappedMapSet(pcgen.base.util.WrappedMapSet) VariableKey(pcgen.cdom.enumeration.VariableKey) CDOMObject(pcgen.cdom.base.CDOMObject) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with VariableKey

use of pcgen.cdom.enumeration.VariableKey in project pcgen by PCGen.

the class PlayerCharacter method getVariable.

/**
	 * Evaluates the variable string passed in and returns its value.
	 *
	 * This should probably be refactored to return a String instead.
	 *
	 * @param variableString the variable to evaluate
	 * @param isMax if multiple values are stored, whether to return the largest value
	 * found or the first.
	 * @return the value of the variable.
	 */
public Float getVariable(final String variableString, final boolean isMax) {
    double value = 0.0;
    boolean found = false;
    if (lastVariable != null) {
        if (lastVariable.equals(variableString)) {
            if (Logging.isDebugMode()) {
                final String sb = "This is a deliberate warning message, not an error - " + "Avoiding infinite loop in getVariable: repeated lookup " + "of \"" + lastVariable + "\" at " + value;
                Logging.debugPrint(sb);
            }
            lastVariable = null;
            return new Float(value);
        }
    }
    try {
        VariableKey vk = VariableKey.valueOf(variableString);
        Double val = variableFacet.getVariableValue(id, vk, isMax);
        if (val != null) {
            value = val;
            found = true;
        }
    } catch (IllegalArgumentException e) {
    //This variable is not in the data - must be builtin?
    }
    boolean includeBonus = true;
    if (!found) {
        lastVariable = variableString;
        value = getVariableValue(variableString, Constants.EMPTY_STRING);
        includeBonus = false;
        found = true;
        lastVariable = null;
    }
    if (found && includeBonus) {
        value += getTotalBonusTo("VAR", variableString);
    }
    return new Float(value);
}
Also used : VariableKey(pcgen.cdom.enumeration.VariableKey)

Example 5 with VariableKey

use of pcgen.cdom.enumeration.VariableKey in project pcgen by PCGen.

the class VariableFacetTest method testAddEmptyObject.

@Test
public void testAddEmptyObject() {
    Object source = new Object();
    CDOMObject t1 = new PCTemplate();
    DataFacetChangeEvent<CharID, CDOMObject> dfce = new DataFacetChangeEvent<>(id, t1, source, DataFacetChangeEvent.DATA_ADDED);
    getFacet().dataAdded(dfce);
    VariableKey vk = VariableKey.getConstant("Var1");
    assertFalse(getFacet().contains(id, vk));
}
Also used : DataFacetChangeEvent(pcgen.cdom.facet.event.DataFacetChangeEvent) CDOMObject(pcgen.cdom.base.CDOMObject) VariableKey(pcgen.cdom.enumeration.VariableKey) CDOMObject(pcgen.cdom.base.CDOMObject) PCTemplate(pcgen.core.PCTemplate) CharID(pcgen.cdom.enumeration.CharID) Test(org.junit.Test)

Aggregations

VariableKey (pcgen.cdom.enumeration.VariableKey)14 CDOMObject (pcgen.cdom.base.CDOMObject)11 CharID (pcgen.cdom.enumeration.CharID)9 Test (org.junit.Test)8 DataFacetChangeEvent (pcgen.cdom.facet.event.DataFacetChangeEvent)8 PCTemplate (pcgen.core.PCTemplate)8 URI (java.net.URI)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 Formula (pcgen.base.formula.Formula)1 WrappedMapSet (pcgen.base.util.WrappedMapSet)1 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)1 CDOMListObject (pcgen.cdom.base.CDOMListObject)1 ConcretePrereqObject (pcgen.cdom.base.ConcretePrereqObject)1 FormulaKey (pcgen.cdom.enumeration.FormulaKey)1 IntegerKey (pcgen.cdom.enumeration.IntegerKey)1 StringKey (pcgen.cdom.enumeration.StringKey)1