use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class PreArmorProfWriter method specialCase.
@Override
public boolean specialCase(Writer writer, Prerequisite prereq) throws IOException {
PrerequisiteOperator po = getConsolidateMethod(kindHandled(), prereq, false);
if (po == null) {
return false;
}
if (!po.equals(prereq.getOperator())) {
writer.write('!');
}
writer.write("PRE" + kindHandled().toUpperCase() + ':' + (prereq.isOverrideQualify() ? "Q:" : ""));
writer.write(po.equals(PrerequisiteOperator.GTEQ) ? prereq.getOperand() : "1");
for (Prerequisite p : prereq.getPrerequisites()) {
writer.write(',');
writer.write(p.getKey());
}
return true;
}
use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class PreVariableTester method passes.
/**
* @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.prereq.Prerequisite, pcgen.core.Equipment)
*/
@Override
public int passes(final Prerequisite prereq, final Equipment equipment, PlayerCharacter aPC) throws PrerequisiteException {
if (aPC == null) {
return 0;
}
//$NON-NLS-1$
final String eqVar = "EQ:" + equipment.getNonHeadedName();
final float aVar = //$NON-NLS-1$
equipment.getVariableValue(prereq.getKey(), eqVar, aPC);
final float aTarget = //$NON-NLS-1$
equipment.getVariableValue(prereq.getOperand(), eqVar, aPC);
float runningTotal = prereq.getOperator().compare(aVar, aTarget);
if (CoreUtility.doublesEqual(runningTotal, 0.0)) {
return 0;
}
for (Prerequisite element : prereq.getPrerequisites()) {
final PrerequisiteTestFactory factory = PrerequisiteTestFactory.getInstance();
final PrerequisiteTest test = factory.getTest(element.getKind());
if (test != null) {
// all of the tests must pass, so just
// assign the value here, don't add
runningTotal = test.passes(element, equipment, aPC);
if (CoreUtility.doublesEqual(runningTotal, 0.0)) {
return 0;
}
}
}
// as the total could be negative, and isn't running...
return countedTotal(prereq, 1);
}
use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class PreAlignWriter method specialCase.
@Override
public boolean specialCase(Writer writer, Prerequisite prereq) throws IOException {
// If this is NOT a PREMULT... fail
if (prereq.getKind() != null) {
return false;
}
PrerequisiteOperator oper = null;
for (Prerequisite p : prereq.getPrerequisites()) {
//
if (!"1".equals(p.getOperand())) {
return false;
}
//
if (!kindHandled().equalsIgnoreCase(p.getKind())) {
return false;
}
//
if (oper == null) {
oper = p.getOperator();
} else {
if (!oper.equals(p.getOperator())) {
return false;
}
}
}
String count = prereq.getOperand();
if (PrerequisiteOperator.NEQ.equals(oper)) {
try {
int i = Integer.parseInt(count);
if (prereq.getPrerequisiteCount() != i) {
return false;
}
} catch (NumberFormatException e) {
return false;
}
} else if (!PrerequisiteOperator.EQ.equals(oper)) {
return false;
}
if (oper.equals(PrerequisiteOperator.EQ) && !"1".equals(prereq.getOperand())) {
return false;
}
if (!PrerequisiteOperator.GTEQ.equals(prereq.getOperator()) ^ !PrerequisiteOperator.EQ.equals(oper)) {
writer.write('!');
}
writer.write("PRE" + kindHandled().toUpperCase() + ':' + (prereq.isOverrideQualify() ? "Q:" : ""));
boolean first = true;
for (Prerequisite p : prereq.getPrerequisites()) {
if (!first) {
writer.write(',');
}
writer.write(p.getKey());
first = false;
}
return true;
}
use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class AbilityTokenTest method setUp.
/*
* @see TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
super.setUp();
PlayerCharacter character = getCharacter();
// Make some ability categories and add them to the game mode
Ability ab1 = TestHelper.makeAbility("Perform (Dance)", AbilityCategory.FEAT, "General.Fighter");
ab1.put(ObjectKey.MULTIPLE_ALLOWED, Boolean.FALSE);
ab1.put(ObjectKey.VISIBILITY, Visibility.DEFAULT);
List<Aspect> colourList = new ArrayList<>();
colourList.add(new Aspect("Colour", "Green"));
ab1.addToMapFor(MapKey.ASPECT, AspectName.getConstant("Colour"), colourList);
List<Aspect> sizeList = new ArrayList<>();
sizeList.add(new Aspect("Size", "L"));
ab1.addToMapFor(MapKey.ASPECT, AspectName.getConstant("Size"), sizeList);
List<Aspect> shapeList = new ArrayList<>();
Aspect cube = new Aspect("Shape", "Cube");
Prerequisite prereq = new Prerequisite();
prereq.setKind("ALIGN");
prereq.setKey("LG");
prereq.setOperator(PrerequisiteOperator.EQ);
cube.addPrerequisite(prereq);
shapeList.add(cube);
shapeList.add(new Aspect("Shape", "Icosahedron"));
ab1.addToMapFor(MapKey.ASPECT, AspectName.getConstant("Shape"), shapeList);
List<Aspect> sidesList = new ArrayList<>();
sidesList.add(new Aspect("Sides", "20"));
ab1.addToMapFor(MapKey.ASPECT, AspectName.getConstant("Sides"), sidesList);
List<Aspect> ageList = new ArrayList<>();
ageList.add(new Aspect("Age In Years", "2000"));
ab1.addToMapFor(MapKey.ASPECT, AspectName.getConstant("Age In Years"), ageList);
addAbility(AbilityCategory.FEAT, ab1);
TestHelper.makeSkill("Bluff", "Charisma", cha, true, SkillArmorCheck.NONE);
TestHelper.makeSkill("Listen", "Wisdom", wis, true, SkillArmorCheck.NONE);
skillFocus = TestHelper.makeAbility("Skill Focus", AbilityCategory.FEAT, "General");
BonusObj aBonus = Bonus.newBonus(Globals.getContext(), "SKILL|LIST|3");
if (aBonus != null) {
skillFocus.addToListFor(ListKey.BONUS, aBonus);
}
skillFocus.put(ObjectKey.MULTIPLE_ALLOWED, true);
Globals.getContext().unconditionallyProcess(skillFocus, "CHOOSE", "SKILL|ALL");
AbstractCharacterTestCase.applyAbility(character, AbilityCategory.FEAT, skillFocus, "KEY_Bluff");
AbstractCharacterTestCase.applyAbility(character, AbilityCategory.FEAT, skillFocus, "KEY_Listen");
character.calcActiveBonuses();
}
use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class AbstractPreRoundRobin method runSimpleRoundRobin.
public static void runSimpleRoundRobin(String s, String d) {
try {
Prerequisite p = PreParserFactory.getInstance().parse(s);
PrerequisiteWriterInterface writer = PrerequisiteWriterFactory.getInstance().getWriter(p.getKind());
if (writer == null) {
fail("Could not find Writer for: " + p.getKind());
}
StringWriter w = new StringWriter();
writer.write(w, p);
assertEquals(d, w.toString());
/*
* Now try new system
*/
LoadContext context = new EditorLoadContext();
CDOMObject obj = new ObjectCache();
int colonLoc = s.indexOf(':');
String key = s.substring(0, colonLoc);
String value = s.substring(colonLoc + 1);
if (context.processToken(obj, key, value)) {
context.commit();
} else {
context.rollback();
Logging.replayParsedMessages();
fail();
}
Logging.clearParseMessages();
Collection<String> output = context.unparse(obj);
if (output == null || output.isEmpty()) {
// Uh Oh
fail("Unable to unparse: " + key + ":" + value);
}
assertEquals(1, output.size());
assertEquals(d, output.iterator().next());
} catch (PersistenceLayerException e) {
e.printStackTrace();
fail(e.getLocalizedMessage());
}
}
Aggregations