The run command for the JEP framework. This receives the arguments to the operator as a stack, pops off the two it needs, does type checking, rolls the dice on the randomizer, and pushes the result back onto the stack. Logging is performed if it is turned on.
(final Stack stack)
| 243 | * Logging is performed if it is turned on.</p> |
| 244 | */ |
| 245 | @SuppressWarnings("UseOfObsoleteCollectionType") |
| 246 | @Override |
| 247 | public void run(final Stack stack) throws ParseException |
| 248 | { |
| 249 | // check the stack |
| 250 | checkStack(stack); |
| 251 | if (curNumberOfParameters < 2) |
| 252 | { |
| 253 | throw new ParseException("Too few parameters"); |
| 254 | } |
| 255 | if (curNumberOfParameters > 4) |
| 256 | { |
| 257 | throw new ParseException("Too many parameters"); |
| 258 | } |
| 259 | |
| 260 | int numToKeep = 0; |
| 261 | int[] keep = null; |
| 262 | int reroll = 0; |
| 263 | while (curNumberOfParameters > 2) |
| 264 | { |
| 265 | final Object param = stack.pop(); |
| 266 | if ((param instanceof Top.TopRolls) && (numToKeep == 0)) |
| 267 | { |
| 268 | numToKeep = ((Top.TopRolls) param).getRolls(); |
| 269 | } |
| 270 | else if ((param instanceof Reroll.Rerolls) && (reroll == 0)) |
| 271 | { |
| 272 | reroll = ((Reroll.Rerolls) param).getRolls(); |
| 273 | } |
| 274 | else if ((param instanceof final Vector vec) && (curNumberOfParameters == 3)) |
| 275 | { |
| 276 | if (numToKeep != 0) |
| 277 | { |
| 278 | throw new ParseException("Redundant Arugments"); |
| 279 | } |
| 280 | if (reroll != 0) |
| 281 | { |
| 282 | throw new ParseException( |
| 283 | "Reroll not compatable with " + "older syntax, use top(NUMBER) instead"); |
| 284 | } |
| 285 | keep = new int[vec.size()]; |
| 286 | for (int x = 0; x < vec.size(); x++) |
| 287 | { |
| 288 | keep[x] = ((int) Math.round((Double) vec.get(x))) - 1; |
| 289 | } |
| 290 | } |
| 291 | else |
| 292 | { |
| 293 | throw new ParseException("Invalid parameter type"); |
| 294 | } |
| 295 | curNumberOfParameters--; |
| 296 | } |
| 297 | |
| 298 | // get the parameter from the stack |
| 299 | Object faces = stack.pop(); |
| 300 | final Object numberOfRolls = stack.pop(); |
| 301 | if (faces instanceof Vector) |
| 302 | { |