Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added close command and support.

  • Loading branch information...
commit c840b0b97e74ad30a61674ef11a847d719d059a4 1 parent 3434b5d
Mike Cantelon authored
View
77 engine/class/game.class.rb
@@ -442,26 +442,38 @@ def transitions
def attempt_open_item(item, with_prop)
+ attempt_open_or_close_item(item, with_prop, 'open')
+ end
+
+ def attempt_close_item(item, with_prop)
+
+ attempt_open_or_close_item(item, with_prop, 'close')
+ end
+
+ def attempt_open_or_close_item(item, with_prop, open_or_close)
+
output = ''
item_object = (@props[item]) ? @props[item] : @doors[item]
if item_object.traits.has_key?('opened')
- if item_object.traits['opened']
- output << "It's already open.\n"
- elsif item_object.traits['opens_with']
+ if (item_object.traits['opened'] && open_or_close == 'open') ||
+ (!item_object.traits['opened'] && open_or_close == 'close')
+ state = (open_or_close == 'open') ? 'open' : 'closed'
+ output << "It's already " + state + ".\n"
+ elsif item_object.traits[open_or_close + '_with']
if with_prop
- if prop_located_at(with_prop, 'player') and item_object.traits['opens_with'].index(with_prop)
+ if prop_located_at(with_prop, 'player') and item_object.traits[open_or_close + '_with'].index(with_prop)
output << open(item)
end
else
- output << "It won't open. Maybe you need something to open it with?\n"
+ output << "It won't open. Maybe you need something to " + open_or_close + " it with?\n"
end
else
- return open(item)
+ return (open_or_close == 'open') ? open(item) : close(item)
end
else
- output << "You can't open the #{item}.\n"
+ output << "You can't " + open_or_close + " the #{item}.\n"
end
output
@@ -479,13 +491,24 @@ def open(item)
end
end
+ def close(item)
+
+ if @props[item]
+ prop_close(item)
+ elsif @doors[item]
+ door_close(item)
+ else
+ error("game.close called on item that isn't a prop or door.")
+ end
+ end
+
def door_open(door)
output = ''
if @doors[door]
- output << "You open the #{@doors[door].name}.\n"
+ output << "You open #{@doors[door].noun}.\n"
output << event(@doors[door], 'on_open')
@@ -497,6 +520,24 @@ def door_open(door)
end
+ def door_close(door)
+
+ output = ''
+
+ if @doors[door]
+
+ output << "You close #{@doors[door].noun}.\n"
+
+ output << event(@doors[door], 'on_close')
+
+ @doors[door].traits['opened'] = false
+
+ end
+
+ output
+
+ end
+
def prop_open(prop)
output = ''
@@ -520,6 +561,8 @@ def prop_open(prop)
@props[contained_prop].location = @player.location
end
end
+
+ @props[prop].traits['contains'] = false
end
output << event(@props[prop], 'on_open')
@@ -532,6 +575,24 @@ def prop_open(prop)
end
+ def prop_close(prop)
+
+ output = ''
+
+ if @props[prop]
+
+ output << "You close #{@props[prop].noun}.\n"
+
+ output << event(@props[prop], 'on_close')
+
+ @props[prop].traits['opened'] = false
+
+ end
+
+ output
+
+ end
+
def event(object, type)
if object.events && object.events[type]
View
1  game/commands/close.yaml
@@ -0,0 +1 @@
+# Look in standard_commands for this.
View
12 standard_commands/close.yaml
@@ -0,0 +1,12 @@
+---
+syntax:
+- "close <prop:item>"
+- "close <door:item>"
+
+logic: |
+
+ prop = arg['item']
+
+ # we should prolly change so just send the object, not id
+ @game.attempt_close_item(prop.id, nil)
+
Please sign in to comment.
Something went wrong with that request. Please try again.