View Javadoc
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.core.dice.mat;
19  
20  import com.fasterxml.jackson.annotation.JsonInclude;
21  import de.kaiserpfalzedv.rpg.core.dice.Die;
22  import lombok.*;
23  import lombok.extern.jackson.Jacksonized;
24  import org.eclipse.microprofile.openapi.annotations.media.Schema;
25  
26  import java.io.Serializable;
27  import java.util.Arrays;
28  import java.util.StringJoiner;
29  
30  /**
31   * DieResult -- The technical result of a single die.
32   *
33   * The result may carry technical information about the die roll. That may be very information when rolling a numbered
34   * die. But "exploding" dice add some more information and there may be special die like FATE or HeXXen, that are not
35   * displayed as numbers at all.
36   *
37   * @author klenkes74 {@literal <rlichti@kaiserpfalz-edv.de>}
38   * @since 1.0.0 2021-01-09
39   */
40  @Jacksonized
41  @Builder(toBuilder = true)
42  @AllArgsConstructor
43  @RequiredArgsConstructor
44  @Getter
45  @ToString
46  @EqualsAndHashCode
47  @JsonInclude(JsonInclude.Include.NON_ABSENT)
48  @Schema(name = "DieResult", description = "A generic result of a single die roll.")
49  public class DieResult implements Serializable {
50      private String total;
51      private String[] rolls;
52      private Die die;
53  
54      /**
55       * @return a pure text display of the die roll.
56       */
57      public String getDisplay() {
58          String rolls = "";
59  
60          if (getRolls().length >= 2) {
61              StringJoiner sj = new StringJoiner(",", "[", "]");
62              Arrays.stream(getRolls()).forEach(sj::add);
63              rolls = sj.toString();
64          }
65  
66          return getTotal() + rolls;
67      }
68  
69      /**
70       * @return the most terse display of the die roll.
71       */
72      public String getShortDisplay() {
73          return getTotal();
74      }
75  }