diff options
Diffstat (limited to 'dice/src/example/java/bjc/dicelang/neodice/commands/RollCommand.java')
| -rw-r--r-- | dice/src/example/java/bjc/dicelang/neodice/commands/RollCommand.java | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/dice/src/example/java/bjc/dicelang/neodice/commands/RollCommand.java b/dice/src/example/java/bjc/dicelang/neodice/commands/RollCommand.java index cec7c48..275c53e 100644 --- a/dice/src/example/java/bjc/dicelang/neodice/commands/RollCommand.java +++ b/dice/src/example/java/bjc/dicelang/neodice/commands/RollCommand.java @@ -18,26 +18,26 @@ public class RollCommand implements Command { public StatementValue execute(Iterator<String> words, DieBoxCLI state) { if (!words.hasNext()) { throw new DieBoxException("Roll must be provided an argument to roll"); - } else { - StatementValue toRoll = state.runStatement(words); + } + + StatementValue toRoll = state.runStatement(words); + + if (toRoll.type == DIE) { + DieStatementValue die = (DieStatementValue) toRoll; + + return die.value.roll(state.rng); + } else if (toRoll.type == DIEPOOL) { + DiePoolStatementValue pool = (DiePoolStatementValue) toRoll; - if (toRoll.type == DIE) { - DieStatementValue die = (DieStatementValue) toRoll; - - return die.value.roll(state.rng); - } else if (toRoll.type == DIEPOOL) { - DiePoolStatementValue pool = (DiePoolStatementValue) toRoll; - - StatementValue[] values = pool.value - .roll(state.rng) - .toArray((sz) -> new StatementValue[sz]); - - return new ArrayStatementValue<>(pool.elementType, - values); - } else { - throw new DieBoxException("Roll was provided something that wasn't rollable (only DIE and DIEPOOL objects are rollable) (was %s, of type %s)", - toRoll, toRoll.type); - } + StatementValue[] values = pool.value + .roll(state.rng) + .toArray((sz) -> new StatementValue[sz]); + + return new ArrayStatementValue<>(pool.elementType, + values); + } else { + throw new DieBoxException("Roll was provided something that wasn't rollable (only DIE and DIEPOOL objects are rollable) (was %s, of type %s)", + toRoll, toRoll.type); } } |
