Skip to content

Commit

Permalink
Added close command and support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Cantelon committed Aug 27, 2010
1 parent 3434b5d commit c840b0b
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 8 deletions.
77 changes: 69 additions & 8 deletions engine/class/game.class.rb
Expand Up @@ -442,26 +442,38 @@ def transitions


def attempt_open_item(item, with_prop) 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 = '' output = ''


item_object = (@props[item]) ? @props[item] : @doors[item] item_object = (@props[item]) ? @props[item] : @doors[item]


if item_object.traits.has_key?('opened') if item_object.traits.has_key?('opened')
if item_object.traits['opened'] if (item_object.traits['opened'] && open_or_close == 'open') ||
output << "It's already open.\n" (!item_object.traits['opened'] && open_or_close == 'close')
elsif item_object.traits['opens_with'] 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 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) output << open(item)
end end
else 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 end
else else
return open(item) return (open_or_close == 'open') ? open(item) : close(item)
end end
else else
output << "You can't open the #{item}.\n" output << "You can't " + open_or_close + " the #{item}.\n"
end end


output output
Expand All @@ -479,13 +491,24 @@ def open(item)
end end
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) def door_open(door)


output = '' output = ''


if @doors[door] if @doors[door]


output << "You open the #{@doors[door].name}.\n" output << "You open #{@doors[door].noun}.\n"


output << event(@doors[door], 'on_open') output << event(@doors[door], 'on_open')


Expand All @@ -497,6 +520,24 @@ def door_open(door)


end 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) def prop_open(prop)


output = '' output = ''
Expand All @@ -520,6 +561,8 @@ def prop_open(prop)
@props[contained_prop].location = @player.location @props[contained_prop].location = @player.location
end end
end end

@props[prop].traits['contains'] = false
end end


output << event(@props[prop], 'on_open') output << event(@props[prop], 'on_open')
Expand All @@ -532,6 +575,24 @@ def prop_open(prop)


end 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) def event(object, type)


if object.events && object.events[type] if object.events && object.events[type]
Expand Down
1 change: 1 addition & 0 deletions game/commands/close.yaml
@@ -0,0 +1 @@
# Look in standard_commands for this.
12 changes: 12 additions & 0 deletions 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)

0 comments on commit c840b0b

Please sign in to comment.