use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.
the class StatMaxValueFacet method getStatMaxValue.
/**
* Returns the numerical maximum value for the given PCStat which has had a
* max value set for the Player Character identified by the given CharID.
* Returns null if no max value StatLock exists on the Player Character for
* the given PCStat.
*
* @param id
* The CharID identifying the Player Character for which the
* maximum stat value is to be returned
* @param stat
* The PCStat for which the numerical lock value is to be
* returned
* @return The numerical value for the given PCStat which has been locked
* for the Player Character identified by the given CharID; null if
* no StatLock exists on the Player Character for the given PCStat
*/
public Number getStatMaxValue(CharID id, PCStat stat) {
Number max = Double.POSITIVE_INFINITY;
boolean hit = false;
Map<StatLock, Set<Object>> componentMap = getCachedMap(id);
if (componentMap != null) {
for (Entry<StatLock, Set<Object>> me : componentMap.entrySet()) {
Set<Object> set = me.getValue();
StatLock lock = me.getKey();
if (lock.getLockedStat().equals(stat)) {
for (Object source : set) {
String sourceString = (source instanceof CDOMObject) ? ((CDOMObject) source).getQualifiedKey() : "";
Number val = formulaResolvingFacet.resolve(id, lock.getLockValue(), sourceString);
if (val.doubleValue() < max.doubleValue()) {
hit = true;
max = val;
}
}
}
}
}
return hit ? max : null;
}
use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.
the class StatMinValueFacet method getStatMinValue.
/**
* Returns the numerical minimum value for the given PCStat which has had a
* min value set for the Player Character identified by the given CharID.
* Returns null if no min value StatLock exists on the Player Character for
* the given PCStat.
*
* @param id
* The CharID identifying the Player Character for which the
* minimum stat value is to be returned
* @param stat
* The PCStat for which the numerical lock value is to be
* returned
* @return The numerical value for the given PCStat which has been locked
* for the Player Character identified by the given CharID; null if
* no StatLock exists on the Player Character for the given PCStat
*/
public Number getStatMinValue(CharID id, PCStat stat) {
Number max = Double.NEGATIVE_INFINITY;
boolean hit = false;
Map<StatLock, Set<Object>> componentMap = getCachedMap(id);
if (componentMap != null) {
for (Iterator<Map.Entry<StatLock, Set<Object>>> it = componentMap.entrySet().iterator(); it.hasNext(); ) {
Entry<StatLock, Set<Object>> me = it.next();
Set<Object> set = me.getValue();
StatLock lock = me.getKey();
if (lock.getLockedStat().equals(stat)) {
for (Object source : set) {
String sourceString = (source instanceof CDOMObject) ? ((CDOMObject) source).getQualifiedKey() : "";
Number val = formulaResolvingFacet.resolve(id, lock.getLockValue(), sourceString);
if (val.doubleValue() > max.doubleValue()) {
hit = true;
max = val;
}
}
}
}
}
return hit ? max : null;
}
use of pcgen.cdom.base.CDOMObject 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;
}
use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.
the class MovementFacet method dataAdded.
/**
* Adds to this Facet the Movement objects contained within a CDOMObject
* granted to the Player Character.
*
* Triggered when one of the Facets to which MovementFacet 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();
/*
* TODO Should consider here whether this should get input from
* BaseMovementFacet vs. capturing these directly. The reason that this
* is done directly is that BaseMovementFacet would have to override
* methods to get this add done, so that is risky, then since this is
* already listening to the consolidated objectfacet, yet another class
* would be required to do the listening for Movement objects added into
* BaseMovementFacet. This is not unreasonable, though perhaps not pure
* in that this uses to ListKey objects.
*/
List<Movement> ml = cdo.getListFor(ListKey.BASE_MOVEMENT);
if (ml != null) {
addAll(dfce.getCharID(), ml, cdo);
}
ml = cdo.getListFor(ListKey.MOVEMENT);
if (ml != null) {
addAll(dfce.getCharID(), ml, cdo);
}
}
use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.
the class LocalSkillCostFacet method dataAdded.
/**
* Adds the SkillCost objects granted by CDOMObjects, as applied directly to
* a PCClass, when a CDOMObject is added to a Player Character.
*
* Triggered when one of the Facets to which LocalSkillCostFacet 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();
CharID id = dfce.getCharID();
PCClass owner;
if (cdo instanceof Domain) {
owner = domainFacet.getSource(id, (Domain) cdo).getPcclass();
} else if (cdo instanceof PCClassLevel) {
owner = (PCClass) cdo.get(ObjectKey.PARENT);
} else if (cdo instanceof PCClass) {
owner = (PCClass) cdo;
} else {
Logging.errorPrint(getClass().getSimpleName() + " was given " + cdo + " which is not an expected object type");
return;
}
for (CDOMReference<Skill> ref : cdo.getSafeListFor(ListKey.LOCALCSKILL)) {
for (Skill sk : ref.getContainedObjects()) {
add(id, owner, SkillCost.CLASS, sk, cdo);
}
}
for (CDOMReference<Skill> ref : cdo.getSafeListFor(ListKey.LOCALCCSKILL)) {
for (Skill sk : ref.getContainedObjects()) {
add(id, owner, SkillCost.CROSS_CLASS, sk, cdo);
}
}
}
Aggregations