use of pcgen.core.VariableProcessor in project pcgen by PCGen.
the class CharBonusToCommand method run.
/**
* Runs charbonusto on the inStack. The parameter is popped
* off the {@code inStack}, and the variable's value is
* pushed back to the top of {@code inStack}.
* @param inStack the jep stack
* @throws ParseException
*/
//Uses JEP, which doesn't use generics
@SuppressWarnings("unchecked")
@Override
public void run(final Stack inStack) throws ParseException {
// check the stack
checkStack(inStack);
// get the parameter from the stack
final Object param1;
final Object param2;
//
if (curNumberOfParameters == 1) {
param2 = inStack.pop();
param1 = "PCLEVEL";
} else if (curNumberOfParameters == 2) {
param2 = inStack.pop();
param1 = inStack.pop();
} else {
throw new ParseException("Invalid parameter count");
}
if ((param1 instanceof String) && (param2 instanceof String)) {
PlayerCharacter pc = null;
if (parent instanceof VariableProcessor) {
pc = ((VariableProcessor) parent).getPc();
} else if (parent instanceof PlayerCharacter) {
pc = (PlayerCharacter) parent;
}
if (pc == null) {
throw new ParseException("Invalid parent (no PC): " + parent.getClass().getName());
}
final Object result = pc.getTotalBonusTo((String) param1, (String) param2);
inStack.push(result);
} else {
throw new ParseException("Invalid parameter type");
}
}
use of pcgen.core.VariableProcessor in project pcgen by PCGen.
the class ClassLevelCommand method updateVariables.
@Override
public boolean updateVariables(final PJEP jep) {
boolean updated = false;
if (jep.removeVariable("CL") != null) {
updated = true;
}
String src = variableSource;
if ((src == null) || !src.startsWith("CLASS:")) {
return updated;
}
src = src.substring(6);
PlayerCharacter pc = null;
if (parent instanceof VariableProcessor) {
pc = ((VariableProcessor) parent).getPc();
} else if (parent instanceof PlayerCharacter) {
pc = (PlayerCharacter) parent;
}
if (pc == null) {
return updated;
}
final Number result = new Double(pc.getClassLevelString(src, false));
jep.addVariable("CL", result.doubleValue());
return true;
}
use of pcgen.core.VariableProcessor in project pcgen by PCGen.
the class SkillInfoCommand method run.
/**
* Runs skill on the inStack. The parameter is popped
* off the {@code inStack}, and the variable's value is
* pushed back to the top of {@code inStack}.
* @param inStack the jep stack
* @throws ParseException
*/
//Uses JEP, which doesn't use generics
@SuppressWarnings("unchecked")
@Override
public void run(final Stack inStack) throws ParseException {
// check the stack
checkStack(inStack);
// get the parameters from the stack
//
// have to do this in reverse order...this is a stack afterall
//
final Object param2 = inStack.pop();
final Object param1 = inStack.pop();
if ((param1 instanceof String) && (param2 instanceof String)) {
PlayerCharacter pc = null;
if (parent instanceof VariableProcessor) {
pc = ((VariableProcessor) parent).getPc();
} else if (parent instanceof PlayerCharacter) {
pc = (PlayerCharacter) parent;
}
if (pc == null) {
throw new ParseException("Invalid parent (no PC): " + parent.getClass().getName());
}
Skill aSkill = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, param2.toString());
Object result = null;
if (aSkill != null && pc.getDisplay().hasSkill(aSkill)) {
if ("modifier".equalsIgnoreCase((String) param1)) {
// aSkill.modifier() returns Integer
result = (double) SkillModifier.modifier(aSkill, pc).intValue();
} else if ("rank".equalsIgnoreCase((String) param1)) {
// aSkill.getRank() returns Float
result = pc.getDisplay().getRank(aSkill).doubleValue();
} else if ("total".equalsIgnoreCase((String) param1)) {
result = (double) SkillRankControl.getTotalRank(pc, aSkill).intValue() + SkillModifier.modifier(aSkill, pc);
} else if ("totalrank".equalsIgnoreCase((String) param1)) {
// aSkill.getTotalRank() returns Float
result = SkillRankControl.getTotalRank(pc, aSkill).doubleValue();
} else if ("stat".equalsIgnoreCase((String) param1)) {
result = (double) SkillModifier.getStatMod(aSkill, pc);
} else if ("misc".equalsIgnoreCase((String) param1)) {
result = (double) (SkillModifier.modifier(aSkill, pc).intValue() - SkillModifier.getStatMod(aSkill, pc));
} else {
Logging.log(Logging.LST_ERROR, "Ignoring unknown parameter '" + param1 + "' in Skillinfo call: skillinfo(\"" + param1 + "\",\"" + param2 + "\")");
result = (double) 0;
}
} else {
result = (double) 0;
}
inStack.push(result);
} else {
throw new ParseException("Invalid parameter type");
}
}
Aggregations