From eda9a86d8d48758e9982cfffd470c3b38a0a4b0b Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Sat, 21 Nov 2020 23:11:43 -0500 Subject: Make dice generic Convert dice from dealing exclusively with ints, to deal with objects of arbitrary types --- .../example/java/bjc/dicelang/neodice/commands/RollCommand.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'dice/src/example/java/bjc/dicelang/neodice/commands/RollCommand.java') 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 eb7b597..eb8beda 100644 --- a/dice/src/example/java/bjc/dicelang/neodice/commands/RollCommand.java +++ b/dice/src/example/java/bjc/dicelang/neodice/commands/RollCommand.java @@ -18,11 +18,16 @@ public class RollCommand implements Command { if (toRoll.type == DIE) { DieStatementValue die = (DieStatementValue) toRoll; - return new IntegerStatementValue(die.value.roll(state.rng)); + return die.value.roll(state.rng); } else if (toRoll.type == DIEPOOL) { DiePoolStatementValue pool = (DiePoolStatementValue) toRoll; - return new IntArrayStatementValue(pool.value.roll(state.rng)); + 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); -- cgit v1.2.3