twisty 0.1.0 → 0.1.1
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/lib/twisty/engine.rb +67 -125
- data/lib/twisty.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b0ea8c345e6ea4ed78af2a8e810b9a1e14e089c2476ec856fc1296235788d9a
|
4
|
+
data.tar.gz: 1f660ec8ef3648c85773938d64aee14e0e7226a5c9e09ff565faa224b9b93c06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 318c11d11366ed2ff2038bac20a6a74aa34a28987fe66cceff1adcdbd0fc7bff9f329341e15673da457981074239a274b8e68fe0ce1b8280e4c4caebe802538c
|
7
|
+
data.tar.gz: 4ab0d97ff5d71a4d38bfa8d6d7c64a803fad446abe98e6fa785f2af1c26bc0d32733fdc9bfb8a88a0a870c17b87eb11293fc8956145e8c09e31d1f9aabd632d9
|
data/lib/twisty/engine.rb
CHANGED
@@ -216,57 +216,65 @@ class Engine
|
|
216
216
|
@inventory
|
217
217
|
end
|
218
218
|
|
219
|
-
|
220
|
-
#
|
221
|
-
##########################
|
222
|
-
rtype [String] => nil
|
223
|
-
#The "take item" command. Probably best not to call directly
|
219
|
+
rtype [String] => Symbol
|
220
|
+
#(+Symbol+)
|
224
221
|
#
|
225
|
-
#
|
226
|
-
def
|
222
|
+
#Returns Index of the Item of the same name in the current room
|
223
|
+
def find_in_current_room(name)
|
227
224
|
current_items.each do |id|
|
228
225
|
if @items.has_key? id
|
229
226
|
if @items[id].name.downcase == name.downcase
|
230
|
-
|
231
|
-
return nil
|
227
|
+
return id
|
232
228
|
end
|
233
229
|
else
|
234
230
|
raise GameError.new "Invalid Item #{id} in #{@current_room}"
|
235
231
|
end
|
236
232
|
end
|
237
233
|
|
238
|
-
#
|
239
|
-
raise PlayError.new "
|
240
|
-
return nil
|
234
|
+
#Could not be found
|
235
|
+
raise PlayError.new "I see no #{name}"
|
236
|
+
return :nil #Never reached
|
241
237
|
end
|
242
238
|
|
243
|
-
rtype [
|
244
|
-
#
|
239
|
+
rtype [String] => Symbol
|
240
|
+
#(+Symbol+)
|
245
241
|
#
|
246
|
-
#
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
if @items[id].fixed
|
253
|
-
raise PlayError.new "You can not move that"
|
254
|
-
else
|
255
|
-
if @items[id].take_event
|
256
|
-
current_room.items.delete id
|
257
|
-
@inventory << id
|
258
|
-
end
|
259
|
-
|
260
|
-
return nil
|
242
|
+
#Returns Index of the Item of the same name in the inventory
|
243
|
+
def find_in_inventory(name)
|
244
|
+
inventory.each do |id|
|
245
|
+
if @items.has_key? id
|
246
|
+
if @items[id].name.downcase == name.downcase
|
247
|
+
return id
|
261
248
|
end
|
262
249
|
else
|
263
|
-
raise GameError.new "
|
250
|
+
raise GameError.new "Invalid Item #{id} in inventory"
|
264
251
|
end
|
265
|
-
else
|
266
|
-
raise GameError.new "Invalid Item #{id} in #{@current_room}"
|
267
252
|
end
|
268
253
|
|
269
|
-
|
254
|
+
#Could not be found
|
255
|
+
raise PlayError.new "You are not carrying that"
|
256
|
+
return :nil
|
257
|
+
end
|
258
|
+
|
259
|
+
##########################
|
260
|
+
# Game play commands #
|
261
|
+
##########################
|
262
|
+
rtype [String] => nil
|
263
|
+
#The "take item" command. Probably best not to call directly
|
264
|
+
#
|
265
|
+
#name:: (+String+) Name of an Item the player has typed in
|
266
|
+
def take_item(name)
|
267
|
+
id = find_in_current_room(name)
|
268
|
+
if @items[id].fixed
|
269
|
+
raise PlayError.new "You can not move that"
|
270
|
+
else
|
271
|
+
if @items[id].take_event
|
272
|
+
current_room.items.delete id
|
273
|
+
@inventory << id
|
274
|
+
end
|
275
|
+
|
276
|
+
return nil
|
277
|
+
end
|
270
278
|
end
|
271
279
|
|
272
280
|
rtype [String, String] => nil
|
@@ -276,39 +284,24 @@ class Engine
|
|
276
284
|
# inventory
|
277
285
|
#container:: (+String+) Name of an Item that the player is looking to
|
278
286
|
# remove added to the another Item from
|
279
|
-
def
|
280
|
-
|
281
|
-
if @items[id].name.downcase == container
|
282
|
-
return take_from_by_name_id(item, id)
|
283
|
-
end
|
284
|
-
end
|
287
|
+
def take_from(item, container)
|
288
|
+
cId = find_in_current_room(container) #Container ID
|
285
289
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
+
@items[cId].contents.each do |iId|
|
291
|
+
if @items.has_key? iId
|
292
|
+
if @items[iId].name.downcase == item.downcase
|
293
|
+
if @items[cId].take_content_event(iId) and @items[iId].take_event
|
294
|
+
@items[cId].del_item iId
|
295
|
+
@inventory << iId
|
290
296
|
|
291
|
-
|
292
|
-
|
293
|
-
#
|
294
|
-
#item:: (+String+) Name that the player has typed for an item to be
|
295
|
-
# added to the inventory
|
296
|
-
#container:: (+Symbol+) Key for the containing Item as found by
|
297
|
-
# Engine.take_from_by_name_name
|
298
|
-
def take_from_by_name_id(item, container)
|
299
|
-
@items[container].contents.each do |id|
|
300
|
-
if @items[id].name.downcase == item
|
301
|
-
if @items[container].take_content_event(id) and @items[id].take_event
|
302
|
-
@items[container].del_item id
|
303
|
-
@inventory << id
|
297
|
+
return nil
|
298
|
+
end
|
304
299
|
end
|
305
|
-
|
306
|
-
|
300
|
+
else
|
301
|
+
raise GameError.new "Invalid Item in container #{cId}"
|
307
302
|
end
|
308
303
|
end
|
309
304
|
|
310
|
-
#Implicit Error
|
311
|
-
raise PlayError.new "I see no #{item} in the #{@items[container].name}"
|
312
305
|
return nil
|
313
306
|
end
|
314
307
|
|
@@ -317,44 +310,19 @@ class Engine
|
|
317
310
|
#
|
318
311
|
#item:: (+String+) Name that the player has typed for an item to be
|
319
312
|
# added to a container
|
320
|
-
def
|
321
|
-
|
322
|
-
|
323
|
-
return put_item_by_id_name(id, container)
|
324
|
-
end
|
325
|
-
end
|
313
|
+
def put_item(item, container)
|
314
|
+
iId = find_in_inventory(item)
|
315
|
+
cId = find_in_current_room(container)
|
326
316
|
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
end
|
331
|
-
|
332
|
-
rtype [Symbol, String] => nil
|
333
|
-
#Called by Engine.put_item_by_name_name. Probably best not to call
|
334
|
-
#directly
|
335
|
-
#
|
336
|
-
#item:: (+Symbol+) Key in Engine.items of the item to be placed in the
|
337
|
-
# container as found by Engine.put_item_by_name_name
|
338
|
-
#container:: (+String+) Name that the player has typed for the Item
|
339
|
-
# to act as a container
|
340
|
-
def put_item_by_id_name(item, container)
|
341
|
-
current_items.each do |id|
|
342
|
-
if @items[id].name.downcase == container
|
343
|
-
if @items[id].storage == 0
|
344
|
-
raise PlayError.new "It won't fit in there"
|
345
|
-
end
|
346
|
-
|
347
|
-
if @items[id].put_content_event(item) and @items[item].drop_event
|
348
|
-
@items[id].add_item(item)
|
349
|
-
@inventory.delete item
|
350
|
-
end
|
317
|
+
if @items[cId].storage == 0
|
318
|
+
raise PlayError.new "It won't fit in there"
|
319
|
+
end
|
351
320
|
|
352
|
-
|
353
|
-
|
321
|
+
if @items[cId].put_content_event(id) and @items[iId].drop_event
|
322
|
+
@items[cId].add_item(iId)
|
323
|
+
@inventory.delete iId
|
354
324
|
end
|
355
325
|
|
356
|
-
#Implicit Error
|
357
|
-
raise PlayError.new "I see no #{item}"
|
358
326
|
return nil
|
359
327
|
end
|
360
328
|
|
@@ -363,42 +331,16 @@ class Engine
|
|
363
331
|
#
|
364
332
|
#name:: (+String+) The name, typed by the player, of the item to be
|
365
333
|
#dropped
|
366
|
-
def
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
return nil
|
373
|
-
end
|
374
|
-
else
|
375
|
-
raise GameError.new "Invalid Item: #{id}"
|
376
|
-
end
|
334
|
+
def drop_item(name)
|
335
|
+
id = find_in_inventory(name)
|
336
|
+
if @items[id].drop_event
|
337
|
+
current_room.items << id
|
338
|
+
@inventory.delete id
|
377
339
|
end
|
378
340
|
|
379
|
-
#Implicit error condition
|
380
|
-
raise PlayError.new "You are not carrying that"
|
381
341
|
return nil
|
382
342
|
end
|
383
343
|
|
384
|
-
rtype [Symbol] => nil
|
385
|
-
#Called by Engine.drop_item_by_name. Probably best not to call directly
|
386
|
-
#
|
387
|
-
#id:: (+Symbol+) Key in Engine.items of the item to be dropped as found
|
388
|
-
#by Engine.drop_item_by_name
|
389
|
-
def drop_item_by_id(id)
|
390
|
-
if @items.has_key? id
|
391
|
-
if @items[id].drop_event
|
392
|
-
current_room.items << id
|
393
|
-
@inventory.delete id
|
394
|
-
end
|
395
|
-
|
396
|
-
return nil
|
397
|
-
else
|
398
|
-
raise GameError.new "Invalid item: #{id} in inventory"
|
399
|
-
end
|
400
|
-
end
|
401
|
-
|
402
344
|
rtype [Symbol] => nil
|
403
345
|
#Called by the "walk door" command. Unlike current_room=(id) this
|
404
346
|
#triggers events and only moves the player if said events run
|
data/lib/twisty.rb
CHANGED
@@ -63,25 +63,25 @@ Engine.instance.define_command(
|
|
63
63
|
/^take \w+$/,
|
64
64
|
"take object",
|
65
65
|
"Take an object and carry it in your inventory") do |tokens|
|
66
|
-
engine.
|
66
|
+
engine.take_item(tokens[1])
|
67
67
|
end
|
68
68
|
Engine.instance.define_command(
|
69
69
|
/^take \w+ from \w+$/,
|
70
70
|
"take object from container",
|
71
71
|
"Take an object out of a container and carry it your inventory") do |tokens|
|
72
|
-
engine.
|
72
|
+
engine.take_from(tokens[1], tokens[3])
|
73
73
|
end
|
74
74
|
Engine.instance.define_command(
|
75
75
|
/^drop \w+$/,
|
76
76
|
"drop object",
|
77
77
|
"Remove an object from your inventory and leave it in the room") do |tokens|
|
78
|
-
engine.
|
78
|
+
engine.drop_item(tokens[1])
|
79
79
|
end
|
80
80
|
Engine.instance.define_command(
|
81
81
|
/^put \w+ in \w+$/,
|
82
82
|
"put item in container",
|
83
83
|
"Remove an object from your inventory and leave it in a container") do |tokens|
|
84
|
-
engine.
|
84
|
+
engine.put_item(tokens[1], tokens[3])
|
85
85
|
end
|
86
86
|
Engine.instance.define_command(
|
87
87
|
/^walk \w+$/,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twisty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan McCoskrie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rtype-native
|