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 a minimum of 10 when exploding.
32 * <p>
33 * Every 10 and 20 is rerolled and added until no 10 or 20 is rolled. If the last roll is less than 10, then at least 10
34 * is added.
35 *
36 * @author rlichti {@literal <rlichti@kaiserpfalz-edv.de>}
37 * @since 2021-01-02
38 */
39 @Dependent
40 @ToString(callSuper = true)
41 @EqualsAndHashCode(callSuper = true)
42 public class T20M extends TorgD20Base {
43 @Override
44 public DieResult roll() {
45 int total = 0;
46 ArrayList<String> rolls = new ArrayList<>(5);
47
48 int roll;
49 do {
50 roll = rollSingle();
51
52 if (total > 0 && roll < 10) {
53 total += (10 - roll);
54 }
55
56 total += roll;
57 rolls.add(Integer.toString(roll, 10));
58 } while (roll == 10 || roll == 20);
59
60 return DieResult.builder()
61 .die(this)
62 .total(Integer.toString(total, 10))
63 .rolls(rolls.toArray(new String[0]))
64 .build();
65 }
66
67 @Override
68 public Optional<LookupTable> getLookupTable() {
69 return Optional.of(new BonusChart());
70 }
71 }