Search in sources :

Example 11 with Vision

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));
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) VisionType(pcgen.util.enumeration.VisionType) Formula(pcgen.base.formula.Formula) QualifiedObject(pcgen.core.QualifiedObject) Vision(pcgen.core.Vision) CDOMObject(pcgen.cdom.base.CDOMObject) QualifiedObject(pcgen.core.QualifiedObject) CDOMObject(pcgen.cdom.base.CDOMObject) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with Vision

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);
                }
            }
        }
    }
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) Vision(pcgen.core.Vision) CharID(pcgen.cdom.enumeration.CharID) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 13 with Vision

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);
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Vision(pcgen.core.Vision) PCTemplate(pcgen.core.PCTemplate) SimpleAssociatedObject(pcgen.cdom.base.SimpleAssociatedObject)

Example 14 with Vision

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);
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Vision(pcgen.core.Vision) PCTemplate(pcgen.core.PCTemplate) SimpleAssociatedObject(pcgen.cdom.base.SimpleAssociatedObject)

Example 15 with Vision

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);
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Vision(pcgen.core.Vision) PCTemplate(pcgen.core.PCTemplate) SimpleAssociatedObject(pcgen.cdom.base.SimpleAssociatedObject)

Aggregations

Vision (pcgen.core.Vision)20 SimpleAssociatedObject (pcgen.cdom.base.SimpleAssociatedObject)12 PCTemplate (pcgen.core.PCTemplate)12 PlayerCharacter (pcgen.core.PlayerCharacter)11 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)5 CDOMObject (pcgen.cdom.base.CDOMObject)4 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 TreeSet (java.util.TreeSet)3 CDOMReference (pcgen.cdom.base.CDOMReference)3 QualifiedObject (pcgen.core.QualifiedObject)3 Prerequisite (pcgen.core.prereq.Prerequisite)3 VisionType (pcgen.util.enumeration.VisionType)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 StringTokenizer (java.util.StringTokenizer)2 Formula (pcgen.base.formula.Formula)2 CDOMDirectSingleRef (pcgen.cdom.reference.CDOMDirectSingleRef)2 HashSet (java.util.HashSet)1 HashMapToList (pcgen.base.util.HashMapToList)1