gemwarrior 0.3.1 → 0.3.2
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.
- checksums.yaml +4 -4
- data/bin/gemwarrior +0 -0
- data/lib/gemwarrior/creature.rb +53 -47
- data/lib/gemwarrior/{constants.rb → defaults.rb} +103 -158
- data/lib/gemwarrior/evaluator.rb +165 -151
- data/lib/gemwarrior/game.rb +52 -42
- data/lib/gemwarrior/inventory.rb +65 -61
- data/lib/gemwarrior/item.rb +24 -28
- data/lib/gemwarrior/location.rb +110 -101
- data/lib/gemwarrior/monster.rb +44 -48
- data/lib/gemwarrior/player.rb +193 -185
- data/lib/gemwarrior/repl.rb +95 -92
- data/lib/gemwarrior/version.rb +1 -1
- data/lib/gemwarrior/world.rb +328 -269
- metadata +4 -6
data/lib/gemwarrior/monster.rb
CHANGED
@@ -1,48 +1,44 @@
|
|
1
|
-
# lib/gemwarrior/monster.rb
|
2
|
-
# Monster creature
|
3
|
-
|
4
|
-
require_relative '
|
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
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|
1
|
+
# lib/gemwarrior/monster.rb
|
2
|
+
# Monster creature
|
3
|
+
|
4
|
+
require_relative 'creature'
|
5
|
+
|
6
|
+
module Gemwarrior
|
7
|
+
class Monster < Creature
|
8
|
+
attr_accessor :xp, :atk_hi, :atk_lo, :rox
|
9
|
+
|
10
|
+
def initialize(
|
11
|
+
id,
|
12
|
+
name,
|
13
|
+
description,
|
14
|
+
face,
|
15
|
+
hands,
|
16
|
+
mood,
|
17
|
+
level,
|
18
|
+
hp_cur,
|
19
|
+
hp_max,
|
20
|
+
atk_lo,
|
21
|
+
atk_hi,
|
22
|
+
inventory,
|
23
|
+
rox
|
24
|
+
)
|
25
|
+
self.id = id
|
26
|
+
self.name = name
|
27
|
+
self.description = description
|
28
|
+
self.face = face
|
29
|
+
self.hands = hands
|
30
|
+
self.mood = mood
|
31
|
+
|
32
|
+
self.level = level
|
33
|
+
self.hp_cur = hp_cur
|
34
|
+
self.hp_max = hp_max
|
35
|
+
|
36
|
+
self.atk_lo = atk_lo
|
37
|
+
self.atk_hi = atk_hi
|
38
|
+
|
39
|
+
self.inventory = inventory
|
40
|
+
self.rox = rox
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
data/lib/gemwarrior/player.rb
CHANGED
@@ -1,185 +1,193 @@
|
|
1
|
-
# lib/gemwarrior/player.rb
|
2
|
-
# Player creature
|
3
|
-
|
4
|
-
require_relative '
|
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
|
-
end
|
62
|
-
|
63
|
-
def
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
end
|
157
|
-
|
158
|
-
def
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
end
|
184
|
-
|
185
|
-
|
1
|
+
# lib/gemwarrior/player.rb
|
2
|
+
# Player creature
|
3
|
+
|
4
|
+
require_relative 'creature'
|
5
|
+
|
6
|
+
module Gemwarrior
|
7
|
+
class Player < Creature
|
8
|
+
# CONSTANTS
|
9
|
+
## ATTRIBUTE POOLS
|
10
|
+
CHAR_UPPER_POOL = (65..90).map{ |i| i.chr }
|
11
|
+
CHAR_LOWER_POOL = (97..122).map{ |i| i.chr }
|
12
|
+
CHAR_LOWER_VOWEL_POOL = ['a','e','i','o','u','y']
|
13
|
+
|
14
|
+
FACE_DESC = ['smooth', 'tired', 'ruddy', 'moist', 'shocked', 'handsome', '5 o\'clock-shadowed']
|
15
|
+
HANDS_DESC = ['worn', 'balled into fists', 'relaxed', 'cracked', 'tingly', 'mom\'s spaghetti']
|
16
|
+
MOOD_DESC = ['calm', 'excited', 'depressed', 'tense', 'lackadaisical', 'angry', 'positive']
|
17
|
+
|
18
|
+
## PLAYER DEFAULTS
|
19
|
+
PLYR_DESC_DEFAULT = 'Picked to do battle against a wizened madman for a shiny something or other for world-saving purposes, you\'re actually fairly able, as long as you\'ve had breakfast first.'
|
20
|
+
|
21
|
+
## ERRORS
|
22
|
+
ERROR_GO_PARAM_INVALID = 'The place in that direction is far, far, FAR too dangerous. You should try a different way.'
|
23
|
+
|
24
|
+
attr_accessor :xp, :stam_cur, :stam_max, :atk_hi, :atk_lo, :rox, :cur_loc
|
25
|
+
|
26
|
+
def initialize(
|
27
|
+
level,
|
28
|
+
xp,
|
29
|
+
hp_cur,
|
30
|
+
hp_max,
|
31
|
+
stam_cur,
|
32
|
+
stam_max,
|
33
|
+
atk_lo,
|
34
|
+
atk_hi,
|
35
|
+
inventory,
|
36
|
+
rox,
|
37
|
+
cur_loc
|
38
|
+
)
|
39
|
+
generate_player_identity
|
40
|
+
|
41
|
+
self.level = level
|
42
|
+
self.xp = xp
|
43
|
+
|
44
|
+
self.hp_cur = hp_cur
|
45
|
+
self.hp_max = hp_max
|
46
|
+
self.stam_cur = stam_cur
|
47
|
+
self.stam_max = stam_max
|
48
|
+
|
49
|
+
self.atk_lo = atk_lo
|
50
|
+
self.atk_hi = atk_hi
|
51
|
+
|
52
|
+
self.inventory = inventory
|
53
|
+
self.rox = rox
|
54
|
+
|
55
|
+
self.cur_loc = cur_loc
|
56
|
+
end
|
57
|
+
|
58
|
+
def check_self
|
59
|
+
print_char_pic
|
60
|
+
return "You check yourself. Currently breathing, wearing clothing, and with a few specific characteristics: face is #{@face}, hands are #{@hands}, and general mood is #{@mood}.\n"
|
61
|
+
end
|
62
|
+
|
63
|
+
def rest
|
64
|
+
hours = rand(1..23)
|
65
|
+
minutes = rand(1..59)
|
66
|
+
seconds = rand(1..59)
|
67
|
+
|
68
|
+
hours_text = hours == 1 ? "hour" : "hours"
|
69
|
+
mins_text = minutes == 1 ? "minute" : "minutes"
|
70
|
+
secs_text = seconds == 1 ? "second" : "seconds"
|
71
|
+
|
72
|
+
return "You lie down somewhere quasi-flat and after a few moments, due to extreme exhaustion, you fall into a deep slumber. Approximately #{hours} #{hours_text}, #{minutes} #{mins_text}, and #{seconds} #{secs_text} later, you wake up with a start, look around you, notice nothing in particular, and get back up, ready to go again."
|
73
|
+
end
|
74
|
+
|
75
|
+
def stamina_dec
|
76
|
+
stam_cur = stam_cur - 1
|
77
|
+
end
|
78
|
+
|
79
|
+
def modify_name
|
80
|
+
print "Enter new name: "
|
81
|
+
new_name = gets.chomp!
|
82
|
+
if new_name.length < 3 || new_name.length > 10
|
83
|
+
return "'#{new_name}' is an invalid length. Make it between 3 and 10 characters, please."
|
84
|
+
else
|
85
|
+
name_to_add = ""
|
86
|
+
name_to_add << new_name[0].upcase
|
87
|
+
name_to_add << new_name[1..new_name.length-1].downcase
|
88
|
+
self.name = name_to_add
|
89
|
+
return "New name, '#{name}', accepted."
|
90
|
+
end
|
91
|
+
return nil
|
92
|
+
end
|
93
|
+
|
94
|
+
def list_inventory
|
95
|
+
inventory.list_contents
|
96
|
+
end
|
97
|
+
|
98
|
+
def loc_by_id(locations, id)
|
99
|
+
locations.each do |loc|
|
100
|
+
if loc.id.to_i.equal? id
|
101
|
+
return loc
|
102
|
+
end
|
103
|
+
end
|
104
|
+
return nil
|
105
|
+
end
|
106
|
+
|
107
|
+
def can_move?(direction)
|
108
|
+
cur_loc.has_loc_to_the?(direction)
|
109
|
+
end
|
110
|
+
|
111
|
+
def go(locations, direction)
|
112
|
+
case direction
|
113
|
+
when "n"
|
114
|
+
direction = "north"
|
115
|
+
when "e"
|
116
|
+
direction = "east"
|
117
|
+
when "s"
|
118
|
+
direction = "south"
|
119
|
+
when "w"
|
120
|
+
direction = "west"
|
121
|
+
end
|
122
|
+
unless direction.nil?
|
123
|
+
if can_move?(direction)
|
124
|
+
new_loc_id = cur_loc.locs_connected[direction.to_sym]
|
125
|
+
cur_loc = loc_by_id(locations, new_loc_id)
|
126
|
+
print_traveling_text
|
127
|
+
cur_loc.checked_for_monsters = false
|
128
|
+
cur_loc.describe
|
129
|
+
else
|
130
|
+
ERROR_GO_PARAM_INVALID
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
private
|
136
|
+
|
137
|
+
def print_traveling_text
|
138
|
+
loc = Thread.new do
|
139
|
+
print "* "
|
140
|
+
print "#{Matrext::process({ :phrase => ">>>", :sl => true })}"
|
141
|
+
print " *\n"
|
142
|
+
end
|
143
|
+
loc.join
|
144
|
+
end
|
145
|
+
|
146
|
+
def print_char_pic
|
147
|
+
char_pic = ""
|
148
|
+
char_pic << "**********\n"
|
149
|
+
char_pic << "* () *\n"
|
150
|
+
char_pic << "* \\-||-/ *\n"
|
151
|
+
char_pic << "* -- *\n"
|
152
|
+
char_pic << "* || *\n"
|
153
|
+
char_pic << "* _||_ *\n"
|
154
|
+
char_pic << "**********\n"
|
155
|
+
puts char_pic
|
156
|
+
end
|
157
|
+
|
158
|
+
def generate_name
|
159
|
+
name = []
|
160
|
+
letter_max = rand(5..10)
|
161
|
+
name[0] = CHAR_UPPER_POOL[rand(0..25)]
|
162
|
+
name[1] = CHAR_LOWER_VOWEL_POOL[rand(0..5)]
|
163
|
+
2.upto(letter_max) do |i|
|
164
|
+
name[i] = CHAR_LOWER_POOL[rand(0..25)]
|
165
|
+
end
|
166
|
+
return name.join
|
167
|
+
end
|
168
|
+
|
169
|
+
def generate_desc
|
170
|
+
PLYR_DESC_DEFAULT
|
171
|
+
end
|
172
|
+
|
173
|
+
def generate_face
|
174
|
+
FACE_DESC[rand(0..FACE_DESC.length-1)]
|
175
|
+
end
|
176
|
+
|
177
|
+
def generate_hands
|
178
|
+
HANDS_DESC[rand(0..HANDS_DESC.length-1)]
|
179
|
+
end
|
180
|
+
|
181
|
+
def generate_mood
|
182
|
+
MOOD_DESC[rand(0..MOOD_DESC.length-1)]
|
183
|
+
end
|
184
|
+
|
185
|
+
def generate_player_identity
|
186
|
+
self.name = generate_name
|
187
|
+
self.description = generate_desc
|
188
|
+
self.face = generate_face
|
189
|
+
self.hands = generate_hands
|
190
|
+
self.mood = generate_mood
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|