1 /*
2 * Copyright (c) 2022 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.LookupTable;
21 import de.kaiserpfalzedv.rpg.core.dice.mat.DieResult;
22 import de.kaiserpfalzedv.rpg.torg.BonusChart;
23 import lombok.EqualsAndHashCode;
24 import lombok.ToString;
25
26 import jakarta.enterprise.context.Dependent;
27 import java.util.ArrayList;
28 import java.util.Optional;
29
30 /**
31 * This is an exploding D20 with no minimum value when exploding.
32 * <p>
33 * Every 10 and 20 is rerolled until no 10 or 20 is rolled any more.
34 *
35 * @author rlichti {@literal <rlichti@kaiserpfalz-edv.de>}
36 * @since 2021-01-02
37 */
38 @Dependent
39 @ToString
40 @EqualsAndHashCode(callSuper = true)
41 public class T20 extends TorgD20Base {
42 @Override
43 public DieResult roll() {
44 int total = 0;
45 ArrayList<String> rolls = new ArrayList<>(5);
46
47 int roll;
48 do {
49 roll = rollSingle();
50
51 total += roll;
52 rolls.add(Integer.toString(roll, 10));
53 } while (roll == 10 || roll == 20);
54
55 return DieResult.builder()
56 .die(this)
57 .total(Integer.toString(total, 10))
58 .rolls(rolls.toArray(new String[0]))
59 .build();
60 }
61
62 @Override
63 public Optional<LookupTable> getLookupTable() {
64 return Optional.of(new BonusChart());
65 }
66 }