/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-05-30 18:46:35 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20220530184635-d8k8pofyyifu017d
Woops.

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 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) {
 
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) {
33
33
    this.times = times;
34
34
    this.faces = faces;
35
35
    this.modifier = modifier;
36
36
  }
37
37
  
38
 
  public Dice.single (int32 faces) {
 
38
  public Dice.singel (int faces) {
39
39
    this.times = 1;
40
40
    this.faces = faces;
41
41
    this.modifier = 0;
42
42
  }
43
43
  
44
 
  public uint32 roll () {
 
44
  public int roll () {
45
45
    if (faces <= 0) {
46
46
      return modifier;
47
47
    }
54
54
      return times + modifier;
55
55
    }
56
56
    
57
 
    uint32 retval = modifier;
 
57
    int retval = modifier;
58
58
    for (size_t i = 1; i <= times; i++) {
59
 
      uint32 r = Vee.Random.get_static_int () % faces;
 
59
      int r = (Utils.Random.get_static_int () % faces).abs ();
60
60
      
61
61
      retval += r;
62
62
    }
72
72
    StringBuilder retval = new StringBuilder ();
73
73
    
74
74
    if (times > 0) {
75
 
      retval.append (times.to_string ())
76
 
            .append_c ('d')
77
 
            .append (faces.to_string ());
 
75
      retval.append (times.to_string ()).append_c ('d').append (faces.to_string ());
78
76
    }
79
77
    if (modifier > 0) {
80
78
        retval.append_c ('+').append (modifier.to_string ());