1 /*
2 * Copyright (c) 2021 Kaiserpfalz EDV-Service, Roland T. Lichti.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18 package de.kaiserpfalzedv.rpg.torg.dice;
19
20 import de.kaiserpfalzedv.rpg.core.dice.Die;
21 import de.kaiserpfalzedv.rpg.core.dice.mat.DieResult;
22 import lombok.ToString;
23
24 import java.util.ArrayList;
25
26 /**
27 * TorgD20Base --
28 *
29 * @author klenkes74 {@literal <rlichti@kaiserpfalz-edv.de>}
30 * @since 0.3.0 2021-05-12
31 */
32 @ToString
33 public abstract class TorgD20Base implements Die {
34 /**
35 * The die roll itself.
36 *
37 * @return the numeric result of the roll of this die.
38 */
39 protected int rollSingle() {
40 return (int) (Math.random() * 21);
41 }
42
43 public final DieResult[] roll(final int number) {
44 ArrayList<DieResult> results = new ArrayList<>(number);
45
46 for (int i = 1; i <= number; i++) {
47 results.add(roll());
48 }
49
50 return results.toArray(new DieResult[0]);
51 }
52
53 @Override
54 public String getDieType() {
55 return getClass().getSimpleName();
56 }
57
58 @Override
59 public boolean isNumericDie() {
60 return true;
61 }
62 }