-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdnd.rb
More file actions
71 lines (62 loc) · 1.44 KB
/
Copy pathdnd.rb
File metadata and controls
71 lines (62 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
module DnD
CRIT_SET = [20]
def self.roll(die_string)
die_string.downcase!
die_string.chomp!
number, die = die_string.split("d").map(&:to_i)
number.times.map { (1..die).to_a.sample }.inject(&:+)
end
def self.stat
4.times.map {
roll("1d6")
}.max(3).inject(&:+)
end
def self.stats_array
6.times.map { stat }
end
def self.roll_attack(mod, status=:normal)
result = case status
when :normal
roll("1d20")
when :advantage
2.times.map {
roll("1d20")
}.max
when :disadvantage
2.times.map {
roll("1d20")
}.min
end
if CRIT_SET.include?(result)
"CRITICAL HIT!!"
elsif result == 1
"CRITICAL MISS!"
else
result + mod
end
end
def self.roll_check(mod, status=:normal)
result = case status
when :normal
roll("1d20")
when :advantage
2.times.map {
roll("1d20")
}.max
when :disadvantage
2.times.map {
roll("1d20")
}.min
end
result + mod
end
def self.roll_damage(die, mod)
roll(die) + mod
end
def self.ability_score_for(stat)
if stat < 1 || stat > 30
raise ArgumentError, "must be within 1-30"
end
( ( stat - 10.0) / 2 ).floor
end
end