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.
- checksums.yaml +4 -4
- data/bin/gemwarrior +0 -0
- data/data/locations.yml +980 -600
- data/lib/gemwarrior/battle.rb +1 -1
- data/lib/gemwarrior/entities/items/ladder.rb +31 -0
- data/lib/gemwarrior/entities/items/rope.rb +29 -0
- data/lib/gemwarrior/entities/items/snowman.rb +28 -0
- data/lib/gemwarrior/entities/items/tent.rb +4 -0
- data/lib/gemwarrior/entities/location.rb +5 -1
- data/lib/gemwarrior/entities/player.rb +265 -249
- data/lib/gemwarrior/evaluator.rb +402 -393
- data/lib/gemwarrior/misc/version.rb +1 -1
- data/lib/gemwarrior/world.rb +297 -296
- metadata +9 -4
data/lib/gemwarrior/evaluator.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
157
|
-
|
158
|
-
world.player.
|
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
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
world.
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
world.player.
|
267
|
-
|
268
|
-
|
269
|
-
return
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
when 'quit
|
341
|
-
puts
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
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
|