stattr 0.0.7 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/stattr.rb +165 -78
- metadata +22 -42
data/lib/stattr.rb
CHANGED
@@ -1,93 +1,180 @@
|
|
1
|
+
# Stattr includes some basic functions that could be used in a Tabletop RPG application
|
2
|
+
#
|
3
|
+
# @author Alex Jarvis
|
1
4
|
|
2
5
|
module Stattr
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
+
|
7
|
+
# How many sides the most common die has - rewrite to fit your game.
|
8
|
+
#
|
9
|
+
DICE_SIDES = 6
|
10
|
+
|
11
|
+
# Represents a single instance of the result of a dice roll
|
12
|
+
#
|
13
|
+
class DiceRoll
|
14
|
+
|
15
|
+
# @attribute sides [Integer] The number of sides the dice in this roll have.
|
16
|
+
#
|
17
|
+
# @attribute count [Integer] The number of die being rolled.
|
18
|
+
#
|
6
19
|
attr_accessor :sides, :count
|
7
|
-
|
20
|
+
|
21
|
+
# New instance of DiceRoll.
|
22
|
+
#
|
23
|
+
# @param [Integer] sides
|
24
|
+
#
|
25
|
+
# @param [Integer] count
|
26
|
+
#
|
27
|
+
# @return [Object] DiceRoll object
|
28
|
+
#
|
29
|
+
def initialize(sides=DICE_SIDES, count=1)
|
8
30
|
@sides = sides
|
9
31
|
@count = count
|
10
|
-
end
|
11
|
-
|
12
|
-
|
32
|
+
end #initialize
|
33
|
+
|
34
|
+
# Roll a new die.
|
35
|
+
#
|
36
|
+
# @param [Integer] sides
|
37
|
+
#
|
38
|
+
# @param [Integer] count
|
39
|
+
#
|
40
|
+
# @return [Object] DiceRoll object
|
41
|
+
#
|
42
|
+
def self.new_roll(sides = DICE_SIDES, count=1)
|
43
|
+
# make a new dice object, then roll it.
|
13
44
|
new(sides, count).roll
|
14
|
-
end
|
15
|
-
|
45
|
+
end #self.roll
|
46
|
+
|
47
|
+
# From 1 to count, that many [sides] sided die.
|
48
|
+
#
|
49
|
+
# @return [Integer] Gives each outcome to Roll.
|
50
|
+
#
|
16
51
|
def rolls
|
17
52
|
(1..count).map { |d| rand(sides) + 1 }
|
18
|
-
end
|
19
|
-
|
53
|
+
end #rolls
|
54
|
+
|
55
|
+
# Adds the rolls from rolls together.
|
56
|
+
#
|
57
|
+
# @return [Integer] combined rolls
|
58
|
+
#
|
20
59
|
def roll
|
21
60
|
rolls.inject(0) { |total, d| total += d }
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
|
26
|
-
|
61
|
+
end #roll
|
62
|
+
end #DiceRoll
|
27
63
|
|
28
|
-
#
|
29
|
-
|
30
|
-
|
31
|
-
Normstats.each do |stat|
|
32
|
-
stathash[stat] = modstat(Stattr::Dice.roll(6,3))
|
33
|
-
end
|
34
|
-
stathash
|
35
|
-
end
|
64
|
+
# Represents the list of Statistics that a player has.
|
65
|
+
#
|
66
|
+
class StatList
|
36
67
|
|
68
|
+
# A list of all stats. Currently locked into D+D style stats.
|
69
|
+
#
|
70
|
+
attr_accessor :str, :dex, :cha, :con, :wis, :int
|
37
71
|
|
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
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
else
|
76
|
-
puts "nothing"
|
77
|
-
end
|
78
|
-
modlist
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
class Playerchar
|
83
|
-
attr_accessor :stats, :name
|
84
|
-
|
85
|
-
def initialize(name)
|
86
|
-
@name = name
|
87
|
-
@stats = Statlist.new
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
72
|
+
# Create a new Statlist.
|
73
|
+
#
|
74
|
+
# @param [Array] str
|
75
|
+
#
|
76
|
+
# @param [Array] dex
|
77
|
+
#
|
78
|
+
# @param [Array] cha
|
79
|
+
#
|
80
|
+
# @param [Array] con
|
81
|
+
#
|
82
|
+
# @param [Array] wis
|
83
|
+
#
|
84
|
+
# @param [Array] int
|
85
|
+
#
|
86
|
+
def initialize(str=10, dex=10, cha=10, con=10, wis=10, int=10)
|
87
|
+
@str = modstat(str)
|
88
|
+
@dex = modstat(dex)
|
89
|
+
@cha = modstat(cha)
|
90
|
+
@con = modstat(con)
|
91
|
+
@wis = modstat(wis)
|
92
|
+
@int = modstat(int)
|
93
|
+
end #initialize
|
94
|
+
|
95
|
+
# Takes a given value of a stat and creates a D+D style modifier.
|
96
|
+
#
|
97
|
+
# @return [Array] modlist. [0] is the stat, [1] is the modifier.
|
98
|
+
#
|
99
|
+
def modstat(r)
|
100
|
+
modr = ((r-10)/2).to_int
|
101
|
+
modlist = [r, modr]
|
102
|
+
modlist
|
103
|
+
end #modstat
|
104
|
+
end #StatList
|
105
|
+
|
106
|
+
# CharacterSheet of a given PlayerCharacter.
|
107
|
+
#
|
108
|
+
class CharacterSheet
|
92
109
|
|
110
|
+
# @attribute stats [Object] A StatList object
|
111
|
+
#
|
112
|
+
# @attribute name [String] The Player Character's name
|
113
|
+
#
|
114
|
+
attr_accessor :stats, :name
|
93
115
|
|
116
|
+
# new instance of CharacterSheet
|
117
|
+
#
|
118
|
+
# @param [String] name
|
119
|
+
#
|
120
|
+
def initialize(name) # :notnew:
|
121
|
+
@name = name
|
122
|
+
# creates StatList object with '10' as a default for each.
|
123
|
+
@stats = StatList.new(10,10,10,10,10,10)
|
124
|
+
end #initialize
|
125
|
+
|
126
|
+
# This is how you roll a brand new random character.
|
127
|
+
#
|
128
|
+
# @param [String] name
|
129
|
+
#
|
130
|
+
# @return [Object] New Charactersheet
|
131
|
+
#
|
132
|
+
def self.roll_char(name)
|
133
|
+
char = CharacterSheet.new(name)
|
134
|
+
char.stats = StatList.new(
|
135
|
+
DiceRoll.new_roll(DICE_SIDES, 3),
|
136
|
+
DiceRoll.new_roll(DICE_SIDES, 3),
|
137
|
+
DiceRoll.new_roll(DICE_SIDES, 3),
|
138
|
+
DiceRoll.new_roll(DICE_SIDES, 3),
|
139
|
+
DiceRoll.new_roll(DICE_SIDES, 3),
|
140
|
+
DiceRoll.new_roll(DICE_SIDES, 3)
|
141
|
+
)
|
142
|
+
char
|
143
|
+
end # self.roll_char
|
144
|
+
end #CharacterSheet
|
145
|
+
|
146
|
+
# Player class represents a human, who may have multiple character sheets.
|
147
|
+
#
|
148
|
+
class Player
|
149
|
+
|
150
|
+
# @attribute fname [String] The First Name of the Player
|
151
|
+
#
|
152
|
+
# @attribute lname [String] The last Name of the Player
|
153
|
+
#
|
154
|
+
# @attribute characters [Array] An array containing Charactersheet objects
|
155
|
+
#
|
156
|
+
attr_accessor :fname, :lname, :characters
|
157
|
+
|
158
|
+
# Create new Player object
|
159
|
+
#
|
160
|
+
# @param [String] fname
|
161
|
+
#
|
162
|
+
# @param [String] lname
|
163
|
+
#
|
164
|
+
def initialize(fname, lname)
|
165
|
+
@fname = fname
|
166
|
+
@lname = lname
|
167
|
+
@characters = []
|
168
|
+
end #initialize
|
169
|
+
|
170
|
+
# Creates a new randomly generated character associated with Player
|
171
|
+
#
|
172
|
+
# @param [String] name
|
173
|
+
#
|
174
|
+
def new_char(name)
|
175
|
+
new_char = CharacterSheet.roll_char(name)
|
176
|
+
self.characters << new_char
|
177
|
+
end #roll_char
|
178
|
+
end #Player
|
179
|
+
|
180
|
+
end #Stattr
|
metadata
CHANGED
@@ -1,67 +1,47 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: stattr
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 7
|
10
|
-
version: 0.0.7
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Alex Jarvis
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2012-05-07 00:00:00 -04:00
|
19
|
-
default_executable:
|
12
|
+
date: 2012-05-24 00:00:00.000000000 Z
|
20
13
|
dependencies: []
|
21
|
-
|
22
|
-
|
14
|
+
description: Stattr is a Gem that includes a number of useful functions for rolling
|
15
|
+
dice in a game like Dungeons and Dragons.
|
23
16
|
email: alxjrvs@gmail.com
|
24
17
|
executables: []
|
25
|
-
|
26
18
|
extensions: []
|
27
|
-
|
28
19
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
files:
|
20
|
+
files:
|
31
21
|
- lib/stattr.rb
|
32
|
-
has_rdoc: true
|
33
22
|
homepage: https://github.com/alxjrvs/Stattr
|
34
23
|
licenses: []
|
35
|
-
|
36
24
|
post_install_message:
|
37
25
|
rdoc_options: []
|
38
|
-
|
39
|
-
require_paths:
|
26
|
+
require_paths:
|
40
27
|
- lib
|
41
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
29
|
none: false
|
43
|
-
requirements:
|
44
|
-
- -
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
|
47
|
-
|
48
|
-
- 0
|
49
|
-
version: "0"
|
50
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
35
|
none: false
|
52
|
-
requirements:
|
53
|
-
- -
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
|
56
|
-
segments:
|
57
|
-
- 0
|
58
|
-
version: "0"
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
59
40
|
requirements: []
|
60
|
-
|
61
41
|
rubyforge_project:
|
62
|
-
rubygems_version: 1.
|
42
|
+
rubygems_version: 1.8.24
|
63
43
|
signing_key:
|
64
44
|
specification_version: 3
|
65
45
|
summary: Stattr; Because rolling dice is hard.
|
66
46
|
test_files: []
|
67
|
-
|
47
|
+
has_rdoc:
|