stattr 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/stattr.rb +31 -20
- metadata +1 -1
data/lib/stattr.rb
CHANGED
@@ -1,21 +1,28 @@
|
|
1
|
-
Normstats = ['STR', 'DEX', 'CHA', 'INT', 'WIS', 'CON']
|
2
1
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
module Stattr
|
3
|
+
Normstats = ['STR', 'DEX', 'CHA', 'INT', 'WIS', 'CON']
|
4
|
+
|
5
|
+
class Dice
|
6
|
+
attr_accessor :sides, :count
|
7
|
+
def initialize(sides=6, count=1)
|
8
|
+
@sides = sides
|
9
|
+
@count = count
|
10
|
+
end
|
7
11
|
|
12
|
+
def self.roll(sides=6, count=1)
|
13
|
+
new(sides, count).roll
|
14
|
+
end
|
8
15
|
|
9
|
-
|
10
|
-
|
11
|
-
rolls = 0
|
12
|
-
(1..dice).each do |i|
|
13
|
-
rolls = rolls + rolld(sides)
|
16
|
+
def rolls
|
17
|
+
(1..count).map { |d| rand(sides) + 1 }
|
14
18
|
end
|
15
|
-
rolls
|
16
|
-
end
|
17
19
|
|
18
|
-
def
|
20
|
+
def roll
|
21
|
+
rolls.inject(0) { |total, d| total += d }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def modstat(r)
|
19
26
|
modlist = []
|
20
27
|
case r
|
21
28
|
when 3
|
@@ -48,7 +55,7 @@ end
|
|
48
55
|
def statroll
|
49
56
|
stathash = {}
|
50
57
|
Normstats.each do |stat|
|
51
|
-
stathash[stat] = modstat(
|
58
|
+
stathash[stat] = modstat(Stattr::Dice.roll(6,3))
|
52
59
|
end
|
53
60
|
stathash
|
54
61
|
end
|
@@ -63,12 +70,12 @@ attr_accessor :str, :dex, :cha, :con, :wis, :int
|
|
63
70
|
@@sides = 6
|
64
71
|
@@dicenum = 3
|
65
72
|
def initialize
|
66
|
-
@str = modstat(
|
67
|
-
@dex = modstat(
|
68
|
-
@cha = modstat(
|
69
|
-
@con = modstat(
|
70
|
-
@wis = modstat(
|
71
|
-
@int = modstat(
|
73
|
+
@str = modstat(Stattr::Dice.roll(@@sides, @@dicenum))
|
74
|
+
@dex = modstat(Stattr::Dice.roll(@@sides, @@dicenum))
|
75
|
+
@cha = modstat(Stattr::Dice.roll(@@sides, @@dicenum))
|
76
|
+
@con = modstat(Stattr::Dice.roll(@@sides, @@dicenum))
|
77
|
+
@wis = modstat(Stattr::Dice.roll(@@sides, @@dicenum))
|
78
|
+
@int = modstat(Stattr::Dice.roll(@@sides, @@dicenum))
|
72
79
|
end
|
73
80
|
end
|
74
81
|
|
@@ -80,3 +87,7 @@ attr_accessor :stats, :name
|
|
80
87
|
@stats = Statlist.new
|
81
88
|
end
|
82
89
|
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
|