gemwarrior 0.7.5 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,393 +1,402 @@
1
- # lib/gemwarrior/evaluator.rb
2
- # Evaluates prompt input
3
-
4
- require 'pry'
5
-
6
- module Gemwarrior
7
- class Evaluator
8
- # CONSTANTS
9
- ## MESSAGES
10
- PROGRAM_NAME = 'Gem Warrior'
11
- QUIT_MESSAGE = 'Thanks for playing the game. Until next time...'.colorize(:yellow)
12
- RESUME_MESSAGE = 'Back to adventuring!'.colorize(:green)
13
-
14
- GO_PARAMS = 'Options: north, east, south, west'
15
- CHANGE_PARAMS = 'Options: name'
16
- DEBUG_LIST_PARAMS = 'Options: monsters, items, locations'
17
- DEBUG_STAT_PARAMS = 'Options: atk_lo, atk_hi, strength, dexterity'
18
-
19
- ## ERRORS
20
- ERROR_COMMAND_INVALID = 'That is not something the game yet understands.'
21
-
22
- ERROR_GO_PARAM_MISSING = 'Just wander aimlessly? A direction would be nice.'
23
- ERROR_GO_PARAM_INVALID = 'The place in that direction is far, far, FAR too dangerous. You should try a different way.'
24
- ERROR_ATTACK_PARAM_MISSING = 'You cannot just "attack". You gotta choose something to attack.'
25
- ERROR_ATTACK_PARAM_INVALID = 'That monster does not exist here or can\'t be attacked.'
26
- ERROR_TAKE_PARAM_MISSING = 'You cannot just "take". You gotta choose something to take.'
27
- ERROR_USE_PARAM_MISSING = 'You cannot just "use". You gotta choose something to use.'
28
- ERROR_USE_PARAM_INVALID = 'You cannot use that, as it does not exist here or in your inventory.'
29
- ERROR_USE_PARAM_UNUSEABLE = 'That object is not useable.'
30
- ERROR_DROP_PARAM_MISSING = 'You cannot just "drop". You gotta choose something to drop.'
31
- ERROR_EQUIP_PARAM_MISSING = 'You cannot just "equip". You gotta choose something to equip.'
32
- ERROR_UNEQUIP_PARAM_MISSING = 'You cannot just "unequip". You gotta choose something to unequip.'
33
- ERROR_CHANGE_PARAM_MISSING = 'You cannot just "change". You gotta choose something to change.'
34
- ERROR_CHANGE_PARAM_INVALID = 'You cannot change that...yet.'
35
- ERROR_LIST_PARAM_MISSING = 'You cannot just "list". You gotta choose something to list.'
36
- ERROR_LIST_PARAM_INVALID = 'You cannot list that...yet.'
37
- ERROR_DEBUG_STAT_PARAM_MISSING = 'You cannot just "change stats". You gotta choose a stat to change.'
38
- ERROR_DEBUG_STAT_PARAM_INVALID = 'You cannot change that stat...yet.'
39
- ERROR_DEBUG_TELEPORT_PARAMS_MISSING = 'You cannot just "teleport". You gotta choose somewhere to teleport to.'
40
- ERROR_DEBUG_TELEPORT_PARAMS_INVALID = 'You cannot teleport there...yet.'
41
-
42
- attr_accessor :world,
43
- :commands, :aliases, :extras, :cmd_descriptions,
44
- :devcommands, :devaliases, :devextras, :devcmd_descriptions
45
-
46
- def initialize(world)
47
- self.world = world
48
-
49
- self.devcommands = %w(god beast list vars map stat teleport)
50
- self.devaliases = %w(gd bs ls v m s tp)
51
- self.devextras = %w(st)
52
- self.devcmd_descriptions = [
53
- 'Toggle god mode (i.e. invincible)',
54
- 'Toggle beast mode (i.e. super strength)',
55
- 'List all instances of a specific entity type',
56
- 'List all the variables in the world',
57
- 'Show a map of the world',
58
- 'Change player stat',
59
- 'Teleport to coordinates (5 0) or location name (\'Home\')'
60
- ]
61
-
62
- self.commands = %w(character inventory rest look take use drop equip unequip go attack change help quit quit!)
63
- self.aliases = %w(c i r l t u d e ue g a ch h q qq)
64
- self.extras = %w(exit exit! x x)
65
- self.cmd_descriptions = [
66
- 'Display character information',
67
- 'Look in your inventory',
68
- 'Take a load off and regain HP',
69
- 'Look around your current location',
70
- 'Take item',
71
- 'Use item (in inventory or environment)',
72
- 'Drop item',
73
- 'Equip item',
74
- 'Unequip item',
75
- 'Go in a direction',
76
- 'Attack a monster',
77
- 'Change something',
78
- 'This help menu',
79
- 'Quit w/ confirmation (also exit/x)',
80
- 'Quit w/o confirmation (also exit!/xx)'
81
- ]
82
- end
83
-
84
- def evaluate(input)
85
- case input
86
- # Ctrl-D or empty command
87
- when nil, ""
88
- return
89
- # real command
90
- else
91
- tokens = input.split
92
- unless input_valid?(input)
93
- return ERROR_COMMAND_INVALID
94
- end
95
- end
96
-
97
- command = tokens.first.downcase
98
- param1 = tokens[1]
99
- param2 = tokens[2]
100
-
101
- # dev commands
102
- if world.debug_mode
103
- case command
104
- when 'god', 'gd'
105
- return world.player.god_mode = !world.player.god_mode
106
- when 'beast', 'bs'
107
- return world.player.beast_mode = !world.player.beast_mode
108
- when 'vars', 'v'
109
- world.print_all_vars
110
- when 'list', 'ls'
111
- if param1.nil?
112
- puts ERROR_LIST_PARAM_MISSING
113
- return DEBUG_LIST_PARAMS
114
- else
115
- return world.list(param1)
116
- end
117
- when 'map', 'm'
118
- world.print_map
119
- when 'stat', 'st', 's'
120
- if param1.nil?
121
- puts ERROR_DEBUG_STAT_PARAM_MISSING
122
- return DEBUG_STAT_PARAMS
123
- else
124
- case param1
125
- when 'hp_cur'
126
- unless param2.nil?
127
- param2 = param2.to_i
128
- if param2.is_a? Numeric
129
- if param2 > 0
130
- world.player.hp_cur = param2
131
- end
132
- end
133
- end
134
- when 'atk_lo'
135
- unless param2.nil?
136
- param2 = param2.to_i
137
- if param2.is_a? Numeric
138
- if param2 >= 0
139
- world.player.atk_lo = param2
140
- end
141
- end
142
- end
143
- when 'atk_hi'
144
- unless param2.nil?
145
- param2 = param2.to_i
146
- if param2.is_a? Numeric
147
- if param2 >= 0
148
- world.player.atk_hi = param2
149
- end
150
- end
151
- end
152
- when 'strength', 'str', 'st'
153
- unless param2.nil?
154
- param2 = param2.to_i
155
- if param2.is_a? Numeric
156
- if param2 >= 0
157
- world.player.atk_lo = param2
158
- world.player.atk_hi = param2
159
- end
160
- end
161
- end
162
- when 'dexterity', 'dex', 'd'
163
- unless param2.nil?
164
- param2 = param2.to_i
165
- if param2.is_a? Numeric
166
- if param2 >= 0
167
- world.player.dexterity = param2
168
- end
169
- end
170
- end
171
- else
172
- return ERROR_DEBUG_STAT_PARAM_INVALID
173
- end
174
- end
175
- when 'teleport', 'tp'
176
- if param1.nil?
177
- return ERROR_DEBUG_TELEPORT_PARAMS_MISSING
178
- else
179
- if (param1.to_i.to_s == param1) && (param2.to_i.to_s == param2)
180
- world.player.cur_coords = {:x => param1.to_i, :y => param2.to_i}
181
- else
182
- locations = []
183
- world.locations.each do |l|
184
- locations << l.name.downcase
185
- end
186
- if locations.include?(param1.downcase)
187
- world.player.cur_coords = world.location_coords_by_name(param1)
188
- else
189
- return ERROR_DEBUG_TELEPORT_PARAMS_INVALID
190
- end
191
- end
192
- Animation::run({:phrase => '** TELEPORT! **', :speed => :insane})
193
- return world.describe(world.location_by_coords(world.player.cur_coords))
194
- end
195
- end
196
- end
197
-
198
- # normal commands
199
- case command
200
- when 'character', 'c'
201
- world.player.check_self(world.debug_mode)
202
- when 'inventory', 'i'
203
- if param1
204
- world.player.inventory.describe_item(param1)
205
- else
206
- world.player.list_inventory
207
- end
208
- when 'rest', 'r'
209
- world.player.rest(world)
210
- when 'look', 'l'
211
- if param1
212
- world.describe_entity(world.location_by_coords(world.player.cur_coords), param1)
213
- else
214
- world.describe(world.location_by_coords(world.player.cur_coords))
215
- end
216
- when 'take', 't'
217
- if param1.nil?
218
- ERROR_TAKE_PARAM_MISSING
219
- else
220
- world.player.inventory.add_item(world.location_by_coords(world.player.cur_coords), param1)
221
- end
222
- when 'use', 'u'
223
- if param1.nil?
224
- ERROR_USE_PARAM_MISSING
225
- else
226
- item_name = param1
227
- result = nil
228
- location_inventory = world.location_by_coords(world.player.cur_coords).items
229
-
230
- if location_inventory.map(&:name).include?(item_name)
231
- location_inventory.each do |i|
232
- if i.name.eql?(item_name)
233
- if i.useable
234
- result = i.use(world.player.inventory)
235
- else
236
- return ERROR_USE_PARAM_UNUSEABLE
237
- end
238
- end
239
- end
240
- elsif
241
- player_inventory = world.player.inventory.items
242
- if player_inventory.map(&:name).include?(item_name)
243
- player_inventory.each do |i|
244
- if i.name.eql?(item_name)
245
- if i.useable
246
- result = i.use(world.player.inventory)
247
- else
248
- return ERROR_USE_PARAM_UNUSEABLE
249
- end
250
- end
251
- end
252
- end
253
- end
254
-
255
- if result.nil?
256
- ERROR_USE_PARAM_INVALID
257
- else
258
- case result[:type]
259
- when 'move'
260
- world.player.cur_coords = world.location_coords_by_name(result[:data])
261
- world.describe(world.location_by_coords(world.player.cur_coords))
262
- when 'dmg'
263
- world.player.take_damage(result[:data])
264
- return
265
- when 'rest', 'health'
266
- world.player.heal_damage(result[:data])
267
- return
268
- else
269
- return
270
- end
271
- end
272
- end
273
- when 'drop', 'd'
274
- if param1.nil?
275
- ERROR_DROP_PARAM_MISSING
276
- else
277
- world.player.inventory.remove_item(param1)
278
- end
279
- when 'equip', 'e'
280
- if param1.nil?
281
- ERROR_EQUIP_PARAM_MISSING
282
- else
283
- world.player.inventory.equip_item(param1)
284
- end
285
- when 'unequip', 'ue'
286
- if param1.nil?
287
- ERROR_UNEQUIP_PARAM_MISSING
288
- else
289
- world.player.inventory.unequip_item(param1)
290
- end
291
- when 'go', 'g'
292
- if param1.nil?
293
- puts ERROR_GO_PARAM_MISSING
294
- GO_PARAMS
295
- else
296
- direction = param1
297
- if world.can_move?(direction)
298
- world.player.go(world.locations, param1)
299
- world.location_by_coords(world.player.cur_coords).checked_for_monsters = false
300
- world.describe(world.location_by_coords(world.player.cur_coords))
301
- else
302
- ERROR_GO_PARAM_INVALID
303
- end
304
- end
305
- when 'attack', 'a'
306
- if param1.nil?
307
- ERROR_ATTACK_PARAM_MISSING
308
- else
309
- monster_name = param1
310
- if world.has_monster_to_attack?(monster_name)
311
- monster = world.location_by_coords(world.player.cur_coords).monster_by_name(monster_name)
312
- world.player.attack(world, monster)
313
- else
314
- ERROR_ATTACK_PARAM_INVALID
315
- end
316
- end
317
- when 'change', 'ch'
318
- if param1.nil?
319
- puts ERROR_CHANGE_PARAM_MISSING
320
- CHANGE_PARAMS
321
- else
322
- case param1
323
- when 'name'
324
- world.player.modify_name
325
- else
326
- ERROR_CHANGE_PARAM_INVALID
327
- end
328
- end
329
- when 'help', 'h'
330
- list_commands
331
- when 'quit', 'exit', 'q', 'x'
332
- puts "You sure you want to quit? (y/n): "
333
- response = gets.chomp.downcase
334
- if (response.eql?("y") || response.eql?("yes"))
335
- puts QUIT_MESSAGE
336
- exit(0)
337
- else
338
- puts RESUME_MESSAGE
339
- end
340
- when 'quit!', 'exit!', 'qq', 'xx'
341
- puts QUIT_MESSAGE
342
- exit(0)
343
- else
344
- return
345
- end
346
- end
347
-
348
- private
349
-
350
- def print_separator
351
- puts "=============================="
352
- end
353
-
354
- def list_commands
355
- i = 0
356
- print_separator
357
- commands.each do |cmd|
358
- puts " #{cmd.ljust(9)}, #{aliases[i].ljust(2)} -- #{cmd_descriptions[i]}"
359
- i = i + 1
360
- end
361
- print_separator
362
-
363
- if world.debug_mode
364
- puts " DEBUG COMMANDS"
365
- print_separator
366
- i = 0
367
- devcommands.each do |cmd|
368
- puts " #{cmd.ljust(9)}, #{devaliases[i].ljust(2)} -- #{devcmd_descriptions[i]}"
369
- i = i + 1
370
- end
371
- print_separator
372
- end
373
- end
374
-
375
- def input_valid?(input)
376
- tokens = input.split
377
- command = tokens[0]
378
- commands_and_aliases = commands | aliases | extras
379
-
380
- if world.debug_mode
381
- commands_and_aliases = commands_and_aliases | devcommands | devaliases | devextras
382
- end
383
-
384
- if commands_and_aliases.include?(command.downcase)
385
- if tokens.size.between?(1,4)
386
- return true
387
- end
388
- elsif tokens.empty?
389
- return true
390
- end
391
- end
392
- end
393
- end
1
+ # lib/gemwarrior/evaluator.rb
2
+ # Evaluates prompt input
3
+
4
+ require 'pry'
5
+
6
+ module Gemwarrior
7
+ class Evaluator
8
+ # CONSTANTS
9
+ ## MESSAGES
10
+ PROGRAM_NAME = 'Gem Warrior'
11
+ QUIT_MESSAGE = 'Thanks for playing the game. Until next time...'.colorize(:yellow)
12
+ RESUME_MESSAGE = 'Back to adventuring!'.colorize(:green)
13
+
14
+ GO_PARAMS = 'Options: north, east, south, west'
15
+ CHANGE_PARAMS = 'Options: name'
16
+ DEBUG_LIST_PARAMS = 'Options: monsters, items, locations'
17
+ DEBUG_STAT_PARAMS = 'Options: atk_lo, atk_hi, strength, dexterity'
18
+
19
+ ## ERRORS
20
+ ERROR_COMMAND_INVALID = 'That is not something the game yet understands.'
21
+
22
+ ERROR_GO_PARAM_MISSING = 'Just wander aimlessly? A direction would be nice.'
23
+ ERROR_GO_PARAM_INVALID = 'The place in that direction is far, far, FAR too dangerous. You should try a different way.'
24
+ ERROR_ATTACK_PARAM_MISSING = 'You cannot just "attack". You gotta choose something to attack.'
25
+ ERROR_ATTACK_PARAM_INVALID = 'That monster does not exist here or can\'t be attacked.'
26
+ ERROR_TAKE_PARAM_MISSING = 'You cannot just "take". You gotta choose something to take.'
27
+ ERROR_USE_PARAM_MISSING = 'You cannot just "use". You gotta choose something to use.'
28
+ ERROR_USE_PARAM_INVALID = 'You cannot use that, as it does not exist here or in your inventory.'
29
+ ERROR_USE_PARAM_UNUSEABLE = 'That object is not useable.'
30
+ ERROR_DROP_PARAM_MISSING = 'You cannot just "drop". You gotta choose something to drop.'
31
+ ERROR_EQUIP_PARAM_MISSING = 'You cannot just "equip". You gotta choose something to equip.'
32
+ ERROR_UNEQUIP_PARAM_MISSING = 'You cannot just "unequip". You gotta choose something to unequip.'
33
+ ERROR_CHANGE_PARAM_MISSING = 'You cannot just "change". You gotta choose something to change.'
34
+ ERROR_CHANGE_PARAM_INVALID = 'You cannot change that...yet.'
35
+ ERROR_LIST_PARAM_MISSING = 'You cannot just "list". You gotta choose something to list.'
36
+ ERROR_LIST_PARAM_INVALID = 'You cannot list that...yet.'
37
+ ERROR_DEBUG_STAT_PARAM_MISSING = 'You cannot just "change stats". You gotta choose a stat to change.'
38
+ ERROR_DEBUG_STAT_PARAM_INVALID = 'You cannot change that stat...yet.'
39
+ ERROR_DEBUG_TELEPORT_PARAMS_MISSING = 'You cannot just "teleport". You gotta choose somewhere to teleport to.'
40
+ ERROR_DEBUG_TELEPORT_PARAMS_INVALID = 'You cannot teleport there...yet.'
41
+
42
+ attr_accessor :world,
43
+ :commands, :aliases, :extras, :cmd_descriptions,
44
+ :devcommands, :devaliases, :devextras, :devcmd_descriptions
45
+
46
+ def initialize(world)
47
+ self.world = world
48
+
49
+ self.devcommands = %w(god beast list vars map stat teleport)
50
+ self.devaliases = %w(gd bs ls v m s tp)
51
+ self.devextras = %w(st)
52
+ self.devcmd_descriptions = [
53
+ 'Toggle god mode (i.e. invincible)',
54
+ 'Toggle beast mode (i.e. super strength)',
55
+ 'List all instances of a specific entity type',
56
+ 'List all the variables in the world',
57
+ 'Show a map of the world',
58
+ 'Change player stat',
59
+ 'Teleport to coordinates (5 0) or location name (\'Home\')'
60
+ ]
61
+
62
+ self.commands = %w(character inventory rest look take use drop equip unequip go attack change help quit quit!)
63
+ self.aliases = %w(c i r l t u d e ue g a ch h q qq)
64
+ self.extras = %w(exit exit! x x)
65
+ self.cmd_descriptions = [
66
+ 'Display character information',
67
+ 'Look in your inventory',
68
+ 'Take a load off and regain HP',
69
+ 'Look around your current location',
70
+ 'Take item',
71
+ 'Use item (in inventory or environment)',
72
+ 'Drop item',
73
+ 'Equip item',
74
+ 'Unequip item',
75
+ 'Go in a direction',
76
+ 'Attack a monster',
77
+ 'Change something',
78
+ 'This help menu',
79
+ 'Quit w/ confirmation (also exit/x)',
80
+ 'Quit w/o confirmation (also exit!/xx)'
81
+ ]
82
+ end
83
+
84
+ def evaluate(input)
85
+ case input
86
+ # Ctrl-D or empty command
87
+ when nil, ""
88
+ return
89
+ # real command
90
+ else
91
+ tokens = input.split
92
+ unless input_valid?(input)
93
+ return ERROR_COMMAND_INVALID
94
+ end
95
+ end
96
+
97
+ command = tokens.first.downcase
98
+ param1 = tokens[1]
99
+ param2 = tokens[2]
100
+ param3 = tokens[3]
101
+
102
+ # dev commands
103
+ if world.debug_mode
104
+ case command
105
+ when 'god', 'gd'
106
+ return world.player.god_mode = !world.player.god_mode
107
+ when 'beast', 'bs'
108
+ return world.player.beast_mode = !world.player.beast_mode
109
+ when 'vars', 'v'
110
+ world.print_all_vars
111
+ when 'list', 'ls'
112
+ if param1.nil?
113
+ puts ERROR_LIST_PARAM_MISSING
114
+ return DEBUG_LIST_PARAMS
115
+ else
116
+ return world.list(param1)
117
+ end
118
+ when 'map', 'm'
119
+ world.print_map
120
+ when 'stat', 'st', 's'
121
+ if param1.nil?
122
+ puts ERROR_DEBUG_STAT_PARAM_MISSING
123
+ return DEBUG_STAT_PARAMS
124
+ else
125
+ case param1
126
+ when 'hp_cur'
127
+ unless param2.nil?
128
+ param2 = param2.to_i
129
+ if param2.is_a? Numeric
130
+ if param2 > 0
131
+ world.player.hp_cur = param2
132
+ end
133
+ end
134
+ end
135
+ when 'atk_lo'
136
+ unless param2.nil?
137
+ param2 = param2.to_i
138
+ if param2.is_a? Numeric
139
+ if param2 >= 0
140
+ world.player.atk_lo = param2
141
+ end
142
+ end
143
+ end
144
+ when 'atk_hi'
145
+ unless param2.nil?
146
+ param2 = param2.to_i
147
+ if param2.is_a? Numeric
148
+ if param2 >= 0
149
+ world.player.atk_hi = param2
150
+ end
151
+ end
152
+ end
153
+ when 'strength', 'str', 'st'
154
+ unless param2.nil?
155
+ param2 = param2.to_i
156
+ if param2.is_a? Numeric
157
+ if param2 >= 0
158
+ world.player.atk_lo = param2
159
+ world.player.atk_hi = param2
160
+ end
161
+ end
162
+ end
163
+ when 'dexterity', 'dex', 'd'
164
+ unless param2.nil?
165
+ param2 = param2.to_i
166
+ if param2.is_a? Numeric
167
+ if param2 >= 0
168
+ world.player.dexterity = param2
169
+ end
170
+ end
171
+ end
172
+ else
173
+ return ERROR_DEBUG_STAT_PARAM_INVALID
174
+ end
175
+ end
176
+ when 'teleport', 'tp'
177
+ if param1.nil?
178
+ return ERROR_DEBUG_TELEPORT_PARAMS_MISSING
179
+ else
180
+ if (param1.to_i.to_s == param1) && (param2.to_i.to_s == param2)
181
+ world.player.cur_coords = {:x => param1.to_i, :y => param2.to_i, :z => param3.to_i}
182
+ else
183
+ locations = []
184
+ world.locations.each do |l|
185
+ locations << l.name.downcase
186
+ end
187
+ if locations.include?(param1.downcase)
188
+ world.player.cur_coords = world.location_coords_by_name(param1)
189
+ else
190
+ return ERROR_DEBUG_TELEPORT_PARAMS_INVALID
191
+ end
192
+ end
193
+ Animation::run({:phrase => '** TELEPORT! **', :speed => :insane})
194
+ return world.describe(world.location_by_coords(world.player.cur_coords))
195
+ end
196
+ end
197
+ end
198
+
199
+ # normal commands
200
+ case command
201
+ when 'character', 'c'
202
+ world.player.check_self(world.debug_mode)
203
+ when 'inventory', 'i'
204
+ if param1
205
+ world.player.inventory.describe_item(param1)
206
+ else
207
+ world.player.list_inventory
208
+ end
209
+ when 'rest', 'r'
210
+ world.player.rest(world)
211
+ when 'look', 'l'
212
+ if param1
213
+ world.describe_entity(world.location_by_coords(world.player.cur_coords), param1)
214
+ else
215
+ world.describe(world.location_by_coords(world.player.cur_coords))
216
+ end
217
+ when 'take', 't'
218
+ if param1.nil?
219
+ ERROR_TAKE_PARAM_MISSING
220
+ else
221
+ world.player.inventory.add_item(world.location_by_coords(world.player.cur_coords), param1)
222
+ end
223
+ when 'use', 'u'
224
+ if param1.nil?
225
+ ERROR_USE_PARAM_MISSING
226
+ else
227
+ item_name = param1
228
+ result = nil
229
+ location_inventory = world.location_by_coords(world.player.cur_coords).items
230
+
231
+ if location_inventory.map(&:name).include?(item_name)
232
+ location_inventory.each do |i|
233
+ if i.name.eql?(item_name)
234
+ if i.useable
235
+ result = i.use(world.player.inventory)
236
+ else
237
+ return ERROR_USE_PARAM_UNUSEABLE
238
+ end
239
+ end
240
+ end
241
+ elsif
242
+ player_inventory = world.player.inventory.items
243
+ if player_inventory.map(&:name).include?(item_name)
244
+ player_inventory.each do |i|
245
+ if i.name.eql?(item_name)
246
+ if i.useable
247
+ result = i.use(world.player.inventory)
248
+ else
249
+ return ERROR_USE_PARAM_UNUSEABLE
250
+ end
251
+ end
252
+ end
253
+ end
254
+ end
255
+
256
+ if result.nil?
257
+ ERROR_USE_PARAM_INVALID
258
+ else
259
+ case result[:type]
260
+ when 'move'
261
+ world.player.cur_coords = world.location_coords_by_name(result[:data])
262
+ world.describe(world.location_by_coords(world.player.cur_coords))
263
+ when 'move_dangerous'
264
+ world.player.take_damage(rand(0..2))
265
+ world.player.cur_coords = world.location_coords_by_name(result[:data])
266
+ world.describe(world.location_by_coords(world.player.cur_coords))
267
+ when 'dmg'
268
+ world.player.take_damage(result[:data])
269
+ return
270
+ when 'rest', 'health'
271
+ world.player.heal_damage(result[:data])
272
+ return
273
+ when 'action'
274
+ if result[:data].eql?('rest')
275
+ world.player.rest(world)
276
+ end
277
+ else
278
+ return
279
+ end
280
+ end
281
+ end
282
+ when 'drop', 'd'
283
+ if param1.nil?
284
+ ERROR_DROP_PARAM_MISSING
285
+ else
286
+ world.player.inventory.remove_item(param1)
287
+ end
288
+ when 'equip', 'e'
289
+ if param1.nil?
290
+ ERROR_EQUIP_PARAM_MISSING
291
+ else
292
+ world.player.inventory.equip_item(param1)
293
+ end
294
+ when 'unequip', 'ue'
295
+ if param1.nil?
296
+ ERROR_UNEQUIP_PARAM_MISSING
297
+ else
298
+ world.player.inventory.unequip_item(param1)
299
+ end
300
+ when 'go', 'g'
301
+ if param1.nil?
302
+ puts ERROR_GO_PARAM_MISSING
303
+ GO_PARAMS
304
+ else
305
+ direction = param1
306
+ if world.can_move?(direction)
307
+ world.player.go(world.locations, param1)
308
+ world.location_by_coords(world.player.cur_coords).checked_for_monsters = false
309
+ world.describe(world.location_by_coords(world.player.cur_coords))
310
+ else
311
+ ERROR_GO_PARAM_INVALID
312
+ end
313
+ end
314
+ when 'attack', 'a'
315
+ if param1.nil?
316
+ ERROR_ATTACK_PARAM_MISSING
317
+ else
318
+ monster_name = param1
319
+ if world.has_monster_to_attack?(monster_name)
320
+ monster = world.location_by_coords(world.player.cur_coords).monster_by_name(monster_name)
321
+ world.player.attack(world, monster)
322
+ else
323
+ ERROR_ATTACK_PARAM_INVALID
324
+ end
325
+ end
326
+ when 'change', 'ch'
327
+ if param1.nil?
328
+ puts ERROR_CHANGE_PARAM_MISSING
329
+ CHANGE_PARAMS
330
+ else
331
+ case param1
332
+ when 'name'
333
+ world.player.modify_name
334
+ else
335
+ ERROR_CHANGE_PARAM_INVALID
336
+ end
337
+ end
338
+ when 'help', 'h'
339
+ list_commands
340
+ when 'quit', 'exit', 'q', 'x'
341
+ puts "You sure you want to quit? (y/n): "
342
+ response = gets.chomp.downcase
343
+ if (response.eql?("y") || response.eql?("yes"))
344
+ puts QUIT_MESSAGE
345
+ exit(0)
346
+ else
347
+ puts RESUME_MESSAGE
348
+ end
349
+ when 'quit!', 'exit!', 'qq', 'xx'
350
+ puts QUIT_MESSAGE
351
+ exit(0)
352
+ else
353
+ return
354
+ end
355
+ end
356
+
357
+ private
358
+
359
+ def print_separator
360
+ puts "=============================="
361
+ end
362
+
363
+ def list_commands
364
+ i = 0
365
+ print_separator
366
+ commands.each do |cmd|
367
+ puts " #{cmd.ljust(9)}, #{aliases[i].ljust(2)} -- #{cmd_descriptions[i]}"
368
+ i = i + 1
369
+ end
370
+ print_separator
371
+
372
+ if world.debug_mode
373
+ puts " DEBUG COMMANDS"
374
+ print_separator
375
+ i = 0
376
+ devcommands.each do |cmd|
377
+ puts " #{cmd.ljust(9)}, #{devaliases[i].ljust(2)} -- #{devcmd_descriptions[i]}"
378
+ i = i + 1
379
+ end
380
+ print_separator
381
+ end
382
+ end
383
+
384
+ def input_valid?(input)
385
+ tokens = input.split
386
+ command = tokens[0]
387
+ commands_and_aliases = commands | aliases | extras
388
+
389
+ if world.debug_mode
390
+ commands_and_aliases = commands_and_aliases | devcommands | devaliases | devextras
391
+ end
392
+
393
+ if commands_and_aliases.include?(command.downcase)
394
+ if tokens.size.between?(1,4)
395
+ return true
396
+ end
397
+ elsif tokens.empty?
398
+ return true
399
+ end
400
+ end
401
+ end
402
+ end