use of pcgen.core.Vision 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.core.Vision in project pcgen by PCGen.
the class VisionFacet method dataAdded.
/**
* Adds any granted Vision objects to this facet when a CDOMObject that
* grants Vision objects is added to a Player Character.
*
* Triggered when one of the Facets to which VisionFacet 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();
Collection<CDOMReference<Vision>> mods = cdo.getListMods(Vision.VISIONLIST);
if (mods != null) {
CharID id = dfce.getCharID();
for (CDOMReference<Vision> ref : mods) {
Collection<AssociatedPrereqObject> assoc = cdo.getListAssociations(Vision.VISIONLIST, ref);
for (AssociatedPrereqObject apo : assoc) {
List<Prerequisite> prereqs = apo.getPrerequisiteList();
for (Vision v : ref.getContainedObjects()) {
add(id, new QualifiedObject<>(v, prereqs), cdo);
}
}
}
}
}
use of pcgen.core.Vision in project pcgen by PCGen.
the class PreVisionTest method testVisionNotZeroTen.
/**
* @throws Exception
*/
public void testVisionNotZeroTen() throws Exception {
final PlayerCharacter character = getCharacter();
final PCTemplate template = new PCTemplate();
final Prerequisite prereq = new Prerequisite();
prereq.setKind("vision");
prereq.setKey("darkvision");
prereq.setOperator(PrerequisiteOperator.LT);
prereq.setOperand("0");
boolean passes = PrereqHandler.passes(prereq, character, null);
assertFalse(passes);
template.putToList(Vision.VISIONLIST, CDOMDirectSingleRef.getRef(new Vision(VisionType.getVisionType("Darkvision"), FormulaFactory.getFormulaFor(10))), new SimpleAssociatedObject());
character.addTemplate(template);
passes = PrereqHandler.passes(prereq, character, null);
assertFalse(passes);
}
use of pcgen.core.Vision in project pcgen by PCGen.
the class PreVisionTest method testVision2Pass.
/**
* @throws Exception
*/
public void testVision2Pass() throws Exception {
final PlayerCharacter character = getCharacter();
final PCTemplate template = new PCTemplate();
template.putToList(Vision.VISIONLIST, CDOMDirectSingleRef.getRef(new Vision(VisionType.getVisionType("Darkvision"), FormulaFactory.getFormulaFor(60))), new SimpleAssociatedObject());
character.addTemplate(template);
final PCTemplate template2 = new PCTemplate();
template2.putToList(Vision.VISIONLIST, CDOMDirectSingleRef.getRef(new Vision(VisionType.getVisionType("Low-Light"), FormulaFactory.getFormulaFor(30))), new SimpleAssociatedObject());
character.addTemplate(template2);
final Prerequisite prereq = new Prerequisite();
prereq.setKind("vision");
prereq.setKey("darkvision");
prereq.setOperator(PrerequisiteOperator.GTEQ);
prereq.setOperand("30");
final boolean passes = PrereqHandler.passes(prereq, character, null);
assertTrue(passes);
}
use of pcgen.core.Vision in project pcgen by PCGen.
the class PreVisionTest method testVisionNotPresentTen.
/**
* @throws Exception
*/
public void testVisionNotPresentTen() throws Exception {
final PlayerCharacter character = getCharacter();
final PCTemplate template = new PCTemplate();
final Prerequisite prereq = new Prerequisite();
prereq.setKind("vision");
prereq.setKey("darkvision");
prereq.setOperator(PrerequisiteOperator.LT);
prereq.setOperand("ANY");
boolean passes = PrereqHandler.passes(prereq, character, null);
assertTrue(passes);
template.putToList(Vision.VISIONLIST, CDOMDirectSingleRef.getRef(new Vision(VisionType.getVisionType("Darkvision"), FormulaFactory.getFormulaFor(10))), new SimpleAssociatedObject());
character.addTemplate(template);
passes = PrereqHandler.passes(prereq, character, null);
assertFalse(passes);
}
Aggregations