3
* Copyright 2021 Gustav Hartvigsson <unknown@domain.org>
5
* This file is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU Lesser General Public License as
7
* published by the Free Software Foundation; either version 3 of the
8
* License, or (at your option) any later version.
10
* This file is distributed in the hope that it will be useful, but
11
* WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
18
* SPDX-License-Identifier: LGPL-3.0-or-later
3
namespace VQDR.Expression {
6
* A Simple Represetation of a dice.
9
public int times { get; set; }
10
public int faces { get; set; }
11
public int modifier { get; set; }
14
public Dice (int times = 1, int faces = 6, int modifier = 0) {
17
this.modifier = modifier;
24
* A Simple Represetation of a dice.
26
public class VQDR.Expression.Dice {
27
public int times { get; set; }
28
public int faces { get; set; }
29
public int modifier { get; set; }
32
public Dice (int times = 1, int faces = 6, int modifier = 0) {
35
this.modifier = modifier;
30
return times + modifier;
33
int retval = modifier;
34
for (size_t i = 1; i <= times; i++) {
35
int r = (VQDR.Common.Random.get_static_int () % faces).abs ();
43
public string to_string () {
44
if ((times == 0) && (faces == 0)) {
48
StringBuilder retval = new StringBuilder ();
51
retval.append (times.to_string ()).append_c ('d').append (faces.to_string ());
54
retval.append_c ('+').append (modifier.to_string ());
55
} else if (modifier < 0) {
56
retval.append (modifier.to_string ());
59
return (string) retval.data;
48
return times + modifier;
51
int retval = modifier;
52
for (size_t i = 1; i <= times; i++) {
53
int r = (VQDR.Common.Random.get_static_int () % faces).abs ();
61
public string to_string () {
62
if ((times == 0) && (faces == 0)) {
66
StringBuilder retval = new StringBuilder ();
69
retval.append (times.to_string ()).append_c ('d').append (faces.to_string ());
72
retval.append_c ('+').append (modifier.to_string ());
73
} else if (modifier < 0) {
74
retval.append (modifier.to_string ());
77
return (string) retval.data;