use of pcgen.util.enumeration.VisionType in project pcgen by PCGen.
the class VisionFacet method getActiveVision.
/**
* Returns a non-null copy of the Collection of Vision objects which are
* active on the Player Character identified by the given CharID.
*
* This method is value-semantic in that ownership of the returned
* Collection is transferred to the class calling this method. Modification
* of the returned Collection will not modify this VisionFacet and
* modification of this VisionFacet will not modify the returned Collection.
* Modifications to the returned Collection will also not modify any future
* or previous objects returned by this (or other) methods on VisionFacet.
* If you wish to modify the information stored in this VisionFacet, you
* must use the add*() and remove*() methods of VisionFacet.
*
* @param id
* The CharID identifying the Player Character for which the
* active Vision objects is to be returned
* @return a non-null copy of the Collection of Vision objects which are
* active on the Player Character identified by the given CharID
*/
public Collection<Vision> getActiveVision(CharID id) {
Map<QualifiedObject<Vision>, Set<Object>> componentMap = getCachedMap(id);
if (componentMap == null) {
return Collections.emptyList();
}
Map<VisionType, Integer> map = new HashMap<>();
for (Map.Entry<QualifiedObject<Vision>, Set<Object>> me : componentMap.entrySet()) {
QualifiedObject<Vision> qo = me.getKey();
for (Object source : me.getValue()) {
if (prerequisiteFacet.qualifies(id, qo, source)) {
String sourceString = (source instanceof CDOMObject) ? ((CDOMObject) source).getQualifiedKey() : "";
Vision v = qo.getRawObject();
Formula distance = v.getDistance();
int a = formulaResolvingFacet.resolve(id, distance, sourceString).intValue();
VisionType visType = v.getType();
Integer current = map.get(visType);
if (current == null || current < a) {
map.put(visType, a);
}
}
}
}
/*
* parse through the global list of vision tags and see if this PC has
* any BONUS:VISION tags which will create a new visionMap entry, and
* add any BONUS to existing entries in the map
*/
for (VisionType vType : VisionType.getAllVisionTypes()) {
int aVal = (int) bonusCheckingFacet.getBonus(id, "VISION", vType.toString());
if (aVal > 0) {
Integer current = map.get(vType);
map.put(vType, aVal + (current == null ? 0 : current));
}
}
TreeSet<Vision> returnSet = new TreeSet<>();
for (Map.Entry<VisionType, Integer> me : map.entrySet()) {
returnSet.add(new Vision(me.getKey(), FormulaFactory.getFormulaFor(me.getValue())));
}
return returnSet;
}
use of pcgen.util.enumeration.VisionType in project pcgen by PCGen.
the class VisionFacet method getActiveVision.
/**
* Returns a Vision object for the given VisionType for the Player Character
* identified by the given CharID.
*
* For a Player Character that is not changed between calls to this method,
* this method does not guarantee returning a Vision object of the same
* identity for the same given VisionType. While the two Vision objects will
* pass object equality (.equals()), they are not guaranteed to pass (or
* guaranteed to fail) instance identity (a == b). This allows VisionFacet
* to reserve the right to cache results, but does not require it.
*
* @param id
* The CharID identifying the Player Character for which the
* Vision of the given VisionType is to be returned
* @param type
* The VisionType for which the Vision is to be returned
* @return A Vision object for the given VisionType for the Player Character
* identified by the given CharID.
*/
public Vision getActiveVision(CharID id, VisionType type) {
Map<QualifiedObject<Vision>, Set<Object>> componentMap = getCachedMap(id);
if (componentMap == null) {
return null;
}
Integer i = null;
for (Map.Entry<QualifiedObject<Vision>, Set<Object>> me : componentMap.entrySet()) {
QualifiedObject<Vision> qo = me.getKey();
Vision v = qo.getRawObject();
VisionType visType = v.getType();
if (type.equals(visType)) {
for (Object source : me.getValue()) {
if (prerequisiteFacet.qualifies(id, qo, source)) {
String sourceString = (source instanceof CDOMObject) ? ((CDOMObject) source).getQualifiedKey() : "";
Formula distance = v.getDistance();
int a = formulaResolvingFacet.resolve(id, distance, sourceString).intValue();
if (i == null || i < a) {
i = a;
}
}
}
}
}
/*
* parse through the global list of vision tags and see if this PC has
* any BONUS:VISION tags which will create a new visionMap entry, and
* add any BONUS to existing entries in the map
*/
int a = (int) bonusCheckingFacet.getBonus(id, "VISION", type.toString());
if (a > 0) {
if (i == null || i < a) {
i = a;
}
}
if (i == null) {
return null;
}
return new Vision(type, FormulaFactory.getFormulaFor(i));
}
use of pcgen.util.enumeration.VisionType in project pcgen by PCGen.
the class PreVisionTester method passes.
/**
* @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
*/
@Override
public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) {
String range = prereq.getOperand();
VisionType requiredVisionType = VisionType.getVisionType(prereq.getKey());
int runningTotal = 0;
if (range.equals("ANY")) {
Vision v = display.getVision(requiredVisionType);
if (v == null) {
runningTotal += prereq.getOperator().compare(0, 1);
} else {
runningTotal += prereq.getOperator().compare(1, 0);
}
} else {
int requiredRange = Integer.parseInt(range);
Vision v = display.getVision(requiredVisionType);
if (v == null) {
runningTotal += prereq.getOperator().compare(0, requiredRange);
} else {
int visionRange = Integer.parseInt(v.getDistance().toString());
runningTotal += prereq.getOperator().compare(visionRange, requiredRange);
}
}
return countedTotal(prereq, runningTotal);
}
Aggregations