/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk

« back to all changes in this revision

Viewing changes to src/libvqdr/dice.vala

  • Committer: Gustav Hartvigsson
  • Date: 2022-06-01 12:30:01 UTC
  • mfrom: (52.1.3 int64)
  • Revision ID: gustav.hartvigsson@gmail.com-20220601123001-b5xs60wwym810hg1
Merged: lp:~gustav.hartvigsson/vqdr/int64

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 * A Simple Represetation of a dice.
25
25
 */
26
26
public class VQDR.Expression.Dice {
27
 
  public int times { get; set; }
28
 
  public int faces { get; set; }
29
 
  public int modifier { get; set; }
30
 
  
31
 
  
32
 
  public Dice (int times = 1, int faces = 6, int modifier = 0) {
 
27
  public uint32 times { get; set; }
 
28
  public uint32 faces { get; set; }
 
29
  public int32 modifier { get; set; }
 
30
  
 
31
  
 
32
  public Dice (uint32 times = 1, uint32 faces = 6, int32 modifier = 0) {
33
33
    this.times = times;
34
34
    this.faces = faces;
35
35
    this.modifier = modifier;
36
36
  }
37
37
  
38
 
  public Dice.singel (int faces) {
 
38
  public Dice.singel (int32 faces) {
39
39
    this.times = 1;
40
40
    this.faces = faces;
41
41
    this.modifier = 0;
42
42
  }
43
43
  
44
 
  public int roll () {
 
44
  public int32 roll () {
45
45
    if (faces <= 0) {
46
46
      return modifier;
47
47
    }
51
51
    }
52
52
    
53
53
    if (faces == 1) {
54
 
      return times + modifier;
 
54
      return ((int32) times) + modifier;
55
55
    }
56
56
    
57
 
    int retval = modifier;
 
57
    int32 retval = modifier;
58
58
    for (size_t i = 1; i <= times; i++) {
59
 
      int r = (Utils.Random.get_static_int () % faces).abs ();
 
59
      // we have to do this ugly mess, as int32 is missing the abs () method.
 
60
      // bug: https://gitlab.gnome.org/GNOME/vala/-/issues/1328
 
61
      int32 r = ((int)(Utils.Random.get_static_int () % (int)faces)).abs ();
60
62
      
61
63
      retval += r;
62
64
    }