Class: Roller

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

Constant Summary collapse

JSONIP_URL =
"http://jsonip.com/"

Instance Method Summary collapse

Instance Method Details

#ability_scoreObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/roller.rb', line 54

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 roll[:total], true
    print "\t(#{bonus})\n"
  else
    print "\n"
  end
end

#ability_scoresObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/roller.rb', line 77

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



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/roller.rb', line 97

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



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/roller.rb', line 29

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



23
24
25
26
# File 'lib/roller.rb', line 23

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