summaryrefslogtreecommitdiff
path: root/dice/src/main/java/bjc/dicelang/dicev2/PoolDiceMod.java
blob: 86855aa335c49794bd83c1365b7a6eecef0b9755 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package bjc.dicelang.dicev2;

import bjc.utils.funcutils.ListUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Converts a die pool into a single die.
 * 
 * @TODO Oct 5, 2020 - Ben Culkin - :CustomPool
 * Should there be a custom pool reduction operator?
 * 
 * @author Ben Culkin
 *
 */
public class PoolDiceMod extends Die {
	/**
	 * The die pool to roll.
	 */
	public Die[] dice;

	/**
	 * Create a new die pool converter.
	 * 
	 * @param dice The pool of dice.
	 */
	public PoolDiceMod(Die... dice) {
		super();

		this.dice = dice;
	}

	@Override
	public long[] roll() {
		List<Long> lst = new ArrayList<>(dice.length);

		for(Die die : dice) {
			for(long val : die.roll()) {
				lst.add(val);
			}
		}

		return ListUtils.toPrimitive(lst);
	}

	/* :NoSingleRolls */
	@Override
	public long rollSingle() {
		throw new UnsupportedOperationException("Pooled dice can't be rolled singly");
	}

	/* :UnoptimizableDice */
	@Override
	public boolean canOptimize() {
		return false;
	}

	@Override
	public long optimize() {
		throw new UnsupportedOperationException("Pooled dice can't be optimized");
	}
}