gemwarrior 0.7.5 → 0.7.6

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.
@@ -2,5 +2,5 @@
2
2
  # Version of Gem Warrior
3
3
 
4
4
  module Gemwarrior
5
- VERSION = "0.7.5"
5
+ VERSION = "0.7.6"
6
6
  end
@@ -1,296 +1,297 @@
1
- # lib/gemwarrior/world.rb
2
- # World where the locations, monsters, items, etc. exist
3
-
4
- require 'yaml'
5
-
6
- require_relative 'entities/item'
7
- require_relative 'entities/location'
8
-
9
- module Gemwarrior
10
- class World
11
- # CONSTANTS
12
- LOCATION_DATA_FILE = "data/locations.yml"
13
- WORLD_DIM_WIDTH = 10
14
- WORLD_DIM_HEIGHT = 10
15
-
16
- ## ERRORS
17
- ERROR_LIST_PARAM_INVALID = 'That is not something that can be listed.'
18
- ERROR_LOCATION_DESCRIBE_ENTITY_INVALID = 'You do not see that here.'
19
-
20
- attr_accessor :monsters, :locations, :player, :debug_mode, :use_wordnik
21
-
22
- def initialize
23
- self.monsters = init_monsters
24
- self.locations = init_locations
25
- self.player = nil
26
- end
27
-
28
- def print_all_vars
29
- puts "======================\n"
30
- puts "All Variables in World\n"
31
- puts "======================\n"
32
- puts "#{list("players", true)}\n"
33
- puts "#{list("monsters", true)}\n\n"
34
- puts "#{list("items", true)}\n\n"
35
- puts "#{list("locations", true)}\n"
36
- end
37
-
38
- def print_map
39
- 0.upto(WORLD_DIM_HEIGHT-1) do |count_y|
40
- print ' '
41
- 0.upto(WORLD_DIM_WIDTH-1) do
42
- print '---'
43
- end
44
- print "\n"
45
- print "#{(WORLD_DIM_HEIGHT-1) - count_y} "
46
- 0.upto(WORLD_DIM_WIDTH-1) do |count_x|
47
- cur_map_coords = {:x => count_x, :y => (WORLD_DIM_HEIGHT-1) - count_y}
48
- if self.player.cur_coords.eql?(cur_map_coords)
49
- print '|O|'
50
- elsif location_by_coords(cur_map_coords)
51
- print '|X|'
52
- else
53
- print '| |'
54
- end
55
- end
56
- print "\n"
57
- end
58
- print ' '
59
- 0.upto(WORLD_DIM_WIDTH-1) do
60
- print '---'
61
- end
62
- puts
63
- print ' '
64
- 0.upto(WORLD_DIM_WIDTH-1) do |count_x|
65
- print "#{count_x} "
66
- end
67
- return
68
- end
69
-
70
- def list(param, details = false)
71
- case param
72
- when 'players'
73
- puts '[PLAYERS]'
74
- player.check_self(false)
75
- when 'monsters'
76
- puts "[MONSTERS](#{monsters.length})"
77
- if details
78
- monsters.map { |m| print m.describe unless m.is_boss}
79
- monsters.map { |m| print m.describe if m.is_boss }
80
- return
81
- else
82
- monster_text = ">> monsters: #{monsters.map(&:name).join(', ')}"
83
- end
84
- when 'items'
85
- item_count = 0
86
- locations.each do |l|
87
- l.items.each do |i|
88
- item_count = item_count + 1
89
- end
90
- end
91
- puts "[ITEMS](#{item_count})"
92
- if details
93
- locations.each do |l|
94
- l.items.map { |i| print i.status }
95
- end
96
- return
97
- else
98
- item_list = []
99
- locations.each do |l|
100
- l.items.map { |i| item_list << i.name }
101
- end
102
- ">> #{item_list.sort.join(', ')}"
103
- end
104
- when 'locations'
105
- puts "[LOCATIONS](#{locations.length})"
106
- if details
107
- locations.map { |l| print l.status(self.debug_mode) }
108
- return
109
- else
110
- ">> #{locations.map(&:name).join(', ')}"
111
- end
112
- else
113
- ERROR_LIST_PARAM_INVALID
114
- end
115
- end
116
-
117
- def location_by_coords(coords)
118
- locations.each do |l|
119
- if l.coords.eql?(coords)
120
- return l
121
- end
122
- end
123
- return nil
124
- end
125
-
126
- def location_coords_by_name(name)
127
- locations.each do |l|
128
- if l.name.downcase.eql?(name.downcase)
129
- return l.coords
130
- end
131
- end
132
- return nil
133
- end
134
-
135
- def describe(point)
136
- desc_text = ""
137
- desc_text << "[ #{point.name} ]".colorize(:green)
138
-
139
- if debug_mode
140
- desc_text << " DL[#{point.danger_level.to_s}] MLR[#{point.monster_level_range.to_s}]".colorize(:yellow)
141
- end
142
-
143
- desc_text << "\n"
144
- desc_text << point.description
145
-
146
- point.populate_monsters(self.monsters) unless point.checked_for_monsters?
147
-
148
- desc_text << "\n >> Curious object(s): #{point.list_items.join(', ')}" unless point.list_items.empty?
149
- desc_text << "\n >> Monster(s) abound: #{point.list_monsters.join(', ')}" unless point.list_monsters.empty?
150
- desc_text << "\n >> Boss(es) abound: #{point.list_bosses.join(', ')}" unless point.list_bosses.empty?
151
- desc_text << "\n >> Paths: #{point.list_paths.join(', ')}"
152
-
153
- if debug_mode
154
- desc_text << "\n >>> Actionable words: "
155
- desc_text << point.list_actionable_words.colorize(:white)
156
- end
157
-
158
- return desc_text
159
- end
160
-
161
- def describe_entity(point, entity_name)
162
- if point.list_items.map{|i| i.downcase}.include?(entity_name)
163
- point.items.each do |i|
164
- if i.name.downcase.eql?(entity_name.downcase)
165
- if debug_mode
166
- return i.status
167
- else
168
- return i.description
169
- end
170
- end
171
- end
172
- elsif
173
- if point.list_monsters.map{|m| m.downcase}.include?(entity_name)
174
- point.monsters_abounding.each do |m|
175
- if m.name.downcase.eql?(entity_name.downcase)
176
- if debug_mode
177
- return m.describe
178
- else
179
- return m.description
180
- end
181
- end
182
- end
183
- end
184
- elsif
185
- if point.list_bosses.map{|b| b.downcase}.include?(entity_name)
186
- point.bosses_abounding.each do |b|
187
- if b.name.downcase.eql?(entity_name.downcase)
188
- if debug_mode
189
- return b.describe
190
- else
191
- return b.description
192
- end
193
- end
194
- end
195
- end
196
- else
197
- ERROR_LOCATION_DESCRIBE_ENTITY_INVALID
198
- end
199
- end
200
-
201
- def can_move?(direction)
202
- location_by_coords(player.cur_coords).has_loc_to_the?(direction)
203
- end
204
-
205
- def has_monster_to_attack?(monster_name)
206
- possible_combatants = location_by_coords(player.cur_coords).monsters_abounding.map(&:name) | location_by_coords(player.cur_coords).bosses_abounding.map(&:name)
207
-
208
- possible_combatants.each do |combatant|
209
- if combatant.downcase.eql?(monster_name.downcase)
210
- return true
211
- end
212
- end
213
-
214
- return false
215
- end
216
-
217
- private
218
-
219
- def create_item_objects(item_names)
220
- items = []
221
- unless item_names.nil?
222
- item_names.each do |name|
223
- items.push(eval(name).new)
224
- end
225
- end
226
- return items
227
- end
228
-
229
- def create_boss_objects(bosses_names)
230
- bosses = []
231
- unless bosses_names.nil?
232
- bosses_names.each do |name|
233
- bosses.push(eval(name).new)
234
- end
235
- end
236
- return bosses
237
- end
238
-
239
- def init_monsters
240
- Dir.glob('lib/gemwarrior/entities/monsters/*.rb').each do |item|
241
- require_relative item[item.index('/', item.index('/')+1)+1..item.length]
242
- end
243
- Dir.glob('lib/gemwarrior/entities/monsters/bosses/*.rb').each do |item|
244
- require_relative item[item.index('/', item.index('/')+1)+1..item.length]
245
- end
246
-
247
- self.monsters = [
248
- Alexandrat.new,
249
- Amberoo.new,
250
- Amethystle.new,
251
- Apatiger.new,
252
- Aquamarine.new,
253
- Bloodstorm.new,
254
- Citrinaga.new,
255
- Coraliz.new,
256
- Cubicat.new,
257
- Diaman.new,
258
- Emerald.new,
259
- Garynetty.new
260
- ]
261
- end
262
-
263
- def init_locations
264
- Dir.glob('lib/gemwarrior/entities/items/*.rb').each do |item|
265
- require_relative item[item.index('/', item.index('/')+1)+1..item.length]
266
- end
267
-
268
- locations = []
269
-
270
- location_data = YAML.load_file(LOCATION_DATA_FILE)
271
-
272
- location_data.each {|l|
273
- locations.push(Location.new({
274
- :name => l["name"],
275
- :description => l["description"],
276
- :danger_level => l["danger_level"],
277
- :monster_level_range => l["monster_level_range"].nil? ? nil : l["monster_level_range"]["lo"]..l["monster_level_range"]["hi"],
278
- :coords => {
279
- :x => l["coords"]["x"],
280
- :y => l["coords"]["y"]
281
- },
282
- :locs_connected => {
283
- :north => l["locs_connected"]["north"],
284
- :east => l["locs_connected"]["east"],
285
- :south => l["locs_connected"]["south"],
286
- :west => l["locs_connected"]["west"]
287
- },
288
- :items => create_item_objects(l["items"]),
289
- :bosses_abounding => create_boss_objects(l["bosses_abounding"])
290
- }))
291
- }
292
-
293
- return locations
294
- end
295
- end
296
- end
1
+ # lib/gemwarrior/world.rb
2
+ # World where the locations, monsters, items, etc. exist
3
+
4
+ require 'yaml'
5
+
6
+ require_relative 'entities/item'
7
+ require_relative 'entities/location'
8
+
9
+ module Gemwarrior
10
+ class World
11
+ # CONSTANTS
12
+ LOCATION_DATA_FILE = "data/locations.yml"
13
+ WORLD_DIM_WIDTH = 10
14
+ WORLD_DIM_HEIGHT = 10
15
+
16
+ ## ERRORS
17
+ ERROR_LIST_PARAM_INVALID = 'That is not something that can be listed.'
18
+ ERROR_LOCATION_DESCRIBE_ENTITY_INVALID = 'You do not see that here.'
19
+
20
+ attr_accessor :monsters, :locations, :player, :debug_mode, :use_wordnik
21
+
22
+ def initialize
23
+ self.monsters = init_monsters
24
+ self.locations = init_locations
25
+ self.player = nil
26
+ end
27
+
28
+ def print_all_vars
29
+ puts "======================\n"
30
+ puts "All Variables in World\n"
31
+ puts "======================\n"
32
+ puts "#{list("players", true)}\n"
33
+ puts "#{list("monsters", true)}\n\n"
34
+ puts "#{list("items", true)}\n\n"
35
+ puts "#{list("locations", true)}\n"
36
+ end
37
+
38
+ def print_map
39
+ 0.upto(WORLD_DIM_HEIGHT-1) do |count_y|
40
+ print ' '
41
+ 0.upto(WORLD_DIM_WIDTH-1) do
42
+ print '---'
43
+ end
44
+ print "\n"
45
+ print "#{(WORLD_DIM_HEIGHT-1) - count_y} "
46
+ 0.upto(WORLD_DIM_WIDTH-1) do |count_x|
47
+ cur_map_coords = {:x => count_x, :y => (WORLD_DIM_HEIGHT-1) - count_y, :z => self.player.cur_coords[:z]}
48
+ if self.player.cur_coords.eql?(cur_map_coords)
49
+ print '|O|'
50
+ elsif location_by_coords(cur_map_coords)
51
+ print '|X|'
52
+ else
53
+ print '| |'
54
+ end
55
+ end
56
+ print "\n"
57
+ end
58
+ print ' '
59
+ 0.upto(WORLD_DIM_WIDTH-1) do
60
+ print '---'
61
+ end
62
+ puts
63
+ print ' '
64
+ 0.upto(WORLD_DIM_WIDTH-1) do |count_x|
65
+ print "#{count_x} "
66
+ end
67
+ return
68
+ end
69
+
70
+ def list(param, details = false)
71
+ case param
72
+ when 'players'
73
+ puts '[PLAYERS]'
74
+ player.check_self(false)
75
+ when 'monsters'
76
+ puts "[MONSTERS](#{monsters.length})"
77
+ if details
78
+ monsters.map { |m| print m.describe unless m.is_boss}
79
+ monsters.map { |m| print m.describe if m.is_boss }
80
+ return
81
+ else
82
+ monster_text = ">> monsters: #{monsters.map(&:name).join(', ')}"
83
+ end
84
+ when 'items'
85
+ item_count = 0
86
+ locations.each do |l|
87
+ l.items.each do |i|
88
+ item_count = item_count + 1
89
+ end
90
+ end
91
+ puts "[ITEMS](#{item_count})"
92
+ if details
93
+ locations.each do |l|
94
+ l.items.map { |i| print i.status }
95
+ end
96
+ return
97
+ else
98
+ item_list = []
99
+ locations.each do |l|
100
+ l.items.map { |i| item_list << i.name }
101
+ end
102
+ ">> #{item_list.sort.join(', ')}"
103
+ end
104
+ when 'locations'
105
+ puts "[LOCATIONS](#{locations.length})"
106
+ if details
107
+ locations.map { |l| print l.status(self.debug_mode) }
108
+ return
109
+ else
110
+ ">> #{locations.map(&:name).join(', ')}"
111
+ end
112
+ else
113
+ ERROR_LIST_PARAM_INVALID
114
+ end
115
+ end
116
+
117
+ def location_by_coords(coords)
118
+ locations.each do |l|
119
+ if l.coords.eql?(coords)
120
+ return l
121
+ end
122
+ end
123
+ return nil
124
+ end
125
+
126
+ def location_coords_by_name(name)
127
+ locations.each do |l|
128
+ if l.name.downcase.eql?(name.downcase)
129
+ return l.coords
130
+ end
131
+ end
132
+ return nil
133
+ end
134
+
135
+ def describe(point)
136
+ desc_text = ""
137
+ desc_text << "[ #{point.name} ]".colorize(:green)
138
+
139
+ if debug_mode
140
+ desc_text << " DL[#{point.danger_level.to_s}] MLR[#{point.monster_level_range.to_s}]".colorize(:yellow)
141
+ end
142
+
143
+ desc_text << "\n"
144
+ desc_text << point.description
145
+
146
+ point.populate_monsters(self.monsters) unless point.checked_for_monsters?
147
+
148
+ desc_text << "\n >> Curious object(s): #{point.list_items.join(', ')}" unless point.list_items.empty?
149
+ desc_text << "\n >> Monster(s) abound: #{point.list_monsters.join(', ')}" unless point.list_monsters.empty?
150
+ desc_text << "\n >> Boss(es) abound: #{point.list_bosses.join(', ')}" unless point.list_bosses.empty?
151
+ desc_text << "\n >> Paths: #{point.list_paths.join(', ')}"
152
+
153
+ if debug_mode
154
+ desc_text << "\n >>> Actionable words: "
155
+ desc_text << point.list_actionable_words.colorize(:white)
156
+ end
157
+
158
+ return desc_text
159
+ end
160
+
161
+ def describe_entity(point, entity_name)
162
+ if point.list_items.map{|i| i.downcase}.include?(entity_name)
163
+ point.items.each do |i|
164
+ if i.name.downcase.eql?(entity_name.downcase)
165
+ if debug_mode
166
+ return i.status
167
+ else
168
+ return i.description
169
+ end
170
+ end
171
+ end
172
+ elsif
173
+ if point.list_monsters.map{|m| m.downcase}.include?(entity_name)
174
+ point.monsters_abounding.each do |m|
175
+ if m.name.downcase.eql?(entity_name.downcase)
176
+ if debug_mode
177
+ return m.describe
178
+ else
179
+ return m.description
180
+ end
181
+ end
182
+ end
183
+ end
184
+ elsif
185
+ if point.list_bosses.map{|b| b.downcase}.include?(entity_name)
186
+ point.bosses_abounding.each do |b|
187
+ if b.name.downcase.eql?(entity_name.downcase)
188
+ if debug_mode
189
+ return b.describe
190
+ else
191
+ return b.description
192
+ end
193
+ end
194
+ end
195
+ end
196
+ else
197
+ ERROR_LOCATION_DESCRIBE_ENTITY_INVALID
198
+ end
199
+ end
200
+
201
+ def can_move?(direction)
202
+ location_by_coords(player.cur_coords).has_loc_to_the?(direction)
203
+ end
204
+
205
+ def has_monster_to_attack?(monster_name)
206
+ possible_combatants = location_by_coords(player.cur_coords).monsters_abounding.map(&:name) | location_by_coords(player.cur_coords).bosses_abounding.map(&:name)
207
+
208
+ possible_combatants.each do |combatant|
209
+ if combatant.downcase.eql?(monster_name.downcase)
210
+ return true
211
+ end
212
+ end
213
+
214
+ return false
215
+ end
216
+
217
+ private
218
+
219
+ def create_item_objects(item_names)
220
+ items = []
221
+ unless item_names.nil?
222
+ item_names.each do |name|
223
+ items.push(eval(name).new)
224
+ end
225
+ end
226
+ return items
227
+ end
228
+
229
+ def create_boss_objects(bosses_names)
230
+ bosses = []
231
+ unless bosses_names.nil?
232
+ bosses_names.each do |name|
233
+ bosses.push(eval(name).new)
234
+ end
235
+ end
236
+ return bosses
237
+ end
238
+
239
+ def init_monsters
240
+ Dir.glob('lib/gemwarrior/entities/monsters/*.rb').each do |item|
241
+ require_relative item[item.index('/', item.index('/')+1)+1..item.length]
242
+ end
243
+ Dir.glob('lib/gemwarrior/entities/monsters/bosses/*.rb').each do |item|
244
+ require_relative item[item.index('/', item.index('/')+1)+1..item.length]
245
+ end
246
+
247
+ self.monsters = [
248
+ Alexandrat.new,
249
+ Amberoo.new,
250
+ Amethystle.new,
251
+ Apatiger.new,
252
+ Aquamarine.new,
253
+ Bloodstorm.new,
254
+ Citrinaga.new,
255
+ Coraliz.new,
256
+ Cubicat.new,
257
+ Diaman.new,
258
+ Emerald.new,
259
+ Garynetty.new
260
+ ]
261
+ end
262
+
263
+ def init_locations
264
+ Dir.glob('lib/gemwarrior/entities/items/*.rb').each do |item|
265
+ require_relative item[item.index('/', item.index('/')+1)+1..item.length]
266
+ end
267
+
268
+ locations = []
269
+
270
+ location_data = YAML.load_file(LOCATION_DATA_FILE)
271
+
272
+ location_data.each {|l|
273
+ locations.push(Location.new({
274
+ :name => l["name"],
275
+ :description => l["description"],
276
+ :danger_level => l["danger_level"],
277
+ :monster_level_range => l["monster_level_range"].nil? ? nil : l["monster_level_range"]["lo"]..l["monster_level_range"]["hi"],
278
+ :coords => {
279
+ :x => l["coords"]["x"],
280
+ :y => l["coords"]["y"],
281
+ :z => l["coords"]["z"]
282
+ },
283
+ :locs_connected => {
284
+ :north => l["locs_connected"]["north"],
285
+ :east => l["locs_connected"]["east"],
286
+ :south => l["locs_connected"]["south"],
287
+ :west => l["locs_connected"]["west"]
288
+ },
289
+ :items => create_item_objects(l["items"]),
290
+ :bosses_abounding => create_boss_objects(l["bosses_abounding"])
291
+ }))
292
+ }
293
+
294
+ return locations
295
+ end
296
+ end
297
+ end