Class: Roller

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/roller.rb

Instance Method Summary collapse

Instance Method Details

#ability_scoreObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/roller.rb', line 47

def ability_score
  roll = roll_ability_score

  if options.show_results
    print roll[:results].to_s + " = "
  end

  print roll[:total].to_s

  if options.bonus
    bonus = calculate_bonus res[:total], true
    print "\t(#{bonus})\n"
  else
    print "\n"
  end
end

#ability_scoresObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/roller.rb', line 70

def ability_scores
  6.times do
    res = roll_ability_score

    if options.show_results
      print res[:results].to_s + " = "
    end

    print res[:total]

    if options.bonuses
      bonus = calculate_bonus res[:total], true
      print "\t(#{bonus})\n"
    else
      print "\n"
    end
  end
end

#bonus(score) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/roller.rb', line 90

def bonus(score)

  begin
    score = score.to_i
  rescue
    say 'Score must be an integer!', :red
    exit 1
  end

  if score < 1
    say 'Score must be greater than 0!', :red
    exit 2
  end

  bonus = calculate_bonus score, true
  say bonus
end

#roll(ndn) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/roller.rb', line 22

def roll(ndn)
  match_reg = %r{(\d+)[dD](\d+)}
  matches   = match_reg.match ndn

  if matches.length === 3
    dice  = matches[1].to_i
    sides = matches[2].to_i

    rolls = roll_dice dice, sides
    total = rolls.reduce :+

    p rolls if options.show_results
    say total
  else
    say "Invalid input", :red
    exit
  end
end

#versionObject



16
17
18
19
# File 'lib/roller.rb', line 16

def version
  ver = File.read(File.join(File.dirname(__FILE__), '..', 'VERSION')).chomp!
  say "Character Roller v#{ver.to_s}"
end