MCPcopy Create free account
hub / github.com/PCGen/pcgen / evaluateExpression

Method evaluateExpression

code/src/java/pcgen/io/ExportHandler.java:416–623  ·  view source on GitHub ↗

Helper method to evaluate an expression, used by OIF and IIF tokens @param expr Expression to evaluate @param aPC PC containing values to help evaluate the expression @return true if the expression was evaluated successfully, else false

(final String expr, final PlayerCharacter aPC)

Source from the content-addressed store, hash-verified

414 * @return true if the expression was evaluated successfully, else false
415 */
416 private boolean evaluateExpression(final String expr, final PlayerCharacter aPC)
417 {
418 // Deal with the AND case
419 if (expr.indexOf(".AND.") > 0)
420 {
421 final String part1 = expr.substring(0, expr.indexOf(".AND."));
422 final String part2 = expr.substring(expr.indexOf(".AND.") + 5);
423
424 return (evaluateExpression(part1, aPC) && evaluateExpression(part2, aPC));
425 }
426
427 // Deal with the OR case
428 if (expr.indexOf(".OR.") > 0)
429 {
430 final String part1 = expr.substring(0, expr.indexOf(".OR."));
431 final String part2 = expr.substring(expr.indexOf(".OR.") + 4);
432
433 return (evaluateExpression(part1, aPC) || evaluateExpression(part2, aPC));
434 }
435
436 /*
437 * Deal with objects held in the loopVariables and loopParameters
438 * sets, e.g. replace the key place holder with the actual value
439 */
440 String expr1 = expr;
441 expr1 = replaceVariables(expr1, loopParameters);
442 expr1 = replaceVariables(expr1, loopVariables);
443
444 // Deal with HASVAR:
445 if (expr1.startsWith("HASVAR:"))
446 {
447 expr1 = expr1.substring(7).trim();
448 return (aPC.getVariableValue(expr1, "").intValue() > 0);
449 }
450
451 // Deal with HASFEAT:
452 if (expr1.startsWith("HASFEAT:"))
453 {
454 expr1 = expr1.substring(8).trim();
455 return (aPC.hasAbilityKeyed(AbilityCategory.FEAT, expr1));
456 }
457
458 // Deal with HASSA:
459 if (expr1.startsWith("HASSA:"))
460 {
461 expr1 = expr1.substring(6).trim();
462 return (aPC.hasSpecialAbility(expr1));
463 }
464
465 // Deal with HASEQUIP:
466 if (expr1.startsWith("HASEQUIP:"))
467 {
468 expr1 = expr1.substring(9).trim();
469 return (aPC.getEquipmentNamed(expr1) != null);
470 }
471
472 if (expr1.startsWith("SPELLCASTER:"))
473 {

Callers 2

evaluateIIFMethod · 0.95
replaceTokenOIFMethod · 0.95

Calls 15

replaceVariablesMethod · 0.95
errorPrintMethod · 0.95
replaceTokenMethod · 0.95
isDebugModeMethod · 0.95
debugPrintMethod · 0.95
trimMethod · 0.80
intValueMethod · 0.80
hasSpecialAbilityMethod · 0.80
getEquipmentNamedMethod · 0.80
parseIntMethod · 0.80

Tested by

no test coverage detected