use of pcgen.core.Vision 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.core.Vision in project pcgen by PCGen.
the class VisionLst method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
if (obj instanceof Ungranted) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
}
StringTokenizer aTok = new StringTokenizer(value, Constants.PIPE);
String visionString = aTok.nextToken();
if (looksLikeAPrerequisite(visionString)) {
return new ParseResult.Fail("Cannot have only PRExxx subtoken in " + getTokenName() + ": " + value, context);
}
ArrayList<AssociatedPrereqObject> edgeList = new ArrayList<>();
boolean foundClear = false;
while (true) {
if (Constants.LST_DOT_CLEAR.equals(visionString)) {
context.getListContext().removeAllFromList(getTokenName(), obj, Vision.VISIONLIST);
foundClear = true;
} else if (visionString.startsWith(Constants.LST_DOT_CLEAR_DOT)) {
try {
Vision vis = Vision.getVision(visionString.substring(7));
context.getListContext().removeFromList(getTokenName(), obj, Vision.VISIONLIST, new CDOMDirectSingleRef<>(vis));
} catch (IllegalArgumentException e) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Bad Syntax for Cleared Vision in " + getTokenName());
cpr.addErrorMessage(e.getMessage());
return cpr;
}
foundClear = true;
} else if (looksLikeAPrerequisite(visionString)) {
break;
} else {
try {
Vision vision = Vision.getVision(visionString);
AssociatedPrereqObject edge = context.getListContext().addToList(getTokenName(), obj, Vision.VISIONLIST, new CDOMDirectSingleRef<>(vision));
edgeList.add(edge);
} catch (IllegalArgumentException e) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Bad Syntax for Vision in " + getTokenName());
cpr.addErrorMessage(e.getMessage());
return cpr;
}
}
if (!aTok.hasMoreTokens()) {
return ParseResult.SUCCESS;
}
visionString = aTok.nextToken();
}
if (foundClear) {
return new ParseResult.Fail("Cannot use PREREQs when using .CLEAR or .CLEAR. in " + getTokenName(), context);
}
while (true) {
Prerequisite prereq = getPrerequisite(visionString);
if (prereq == null) {
return new ParseResult.Fail(" (Did you put vision after the " + "PRExxx tags in " + getTokenName() + ":?)", context);
}
for (AssociatedPrereqObject edge : edgeList) {
edge.addPrerequisite(prereq);
}
if (!aTok.hasMoreTokens()) {
break;
}
visionString = aTok.nextToken();
}
return ParseResult.SUCCESS;
}
use of pcgen.core.Vision in project pcgen by PCGen.
the class VisionFacetTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
CDOMObject cdo1 = new PCTemplate();
cdo1.setName("Template1");
CDOMObject cdo2 = new Race();
cdo2.setName("Race1");
Vision vision1 = new Vision(VisionType.getVisionType("Normal"), FormulaFactory.getFormulaFor(30));
Vision vision2 = new Vision(VisionType.getVisionType("Darkvision"), FormulaFactory.getFormulaFor(20));
CDOMDirectSingleRef<Vision> ref1 = new CDOMDirectSingleRef<>(vision1);
SimpleAssociatedObject apo1 = new SimpleAssociatedObject();
cdo1.putToList(Vision.VISIONLIST, ref1, apo1);
CDOMDirectSingleRef<Vision> ref2 = new CDOMDirectSingleRef<>(vision2);
SimpleAssociatedObject apo2 = new SimpleAssociatedObject();
cdo2.putToList(Vision.VISIONLIST, ref2, apo2);
QualifiedObject<Vision> st1 = new QualifiedObject<>(vision1);
QualifiedObject<Vision> st2 = new QualifiedObject<>(vision2);
source = new CDOMObject[] { cdo1, cdo2 };
target = new QualifiedObject[] { st1, st2 };
}
use of pcgen.core.Vision in project pcgen by PCGen.
the class PreVisionTest method testVisionNotPresentZero.
/**
* @throws Exception
*/
public void testVisionNotPresentZero() 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.ZERO)), 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 testVisionNotZeroZero.
/**
* @throws Exception
*/
public void testVisionNotZeroZero() 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.ZERO)), new SimpleAssociatedObject());
character.addTemplate(template);
passes = PrereqHandler.passes(prereq, character, null);
assertFalse(passes);
}
Aggregations