script 'clothing'
module Gamefic::Hypertext
def self.link command, text = nil
"#{text || command}"
end
end
class Gamefic::Entity
attr_writer :default_command
def default_command
@default_command || "examine #{definitely}"
end
end
class Gamefic::Character
def suggest command, text = nil
stream ""
end
end
assert_action :clear_room_mode do |actor, action|
actor[:looking_at_room] = false
actor[:checking_inventory] = false
true
end
respond :look, Query::Room.new(Room) do |actor, room|
actor.tell "#{room.name.cap_first}"
actor.tell room.description
with_locales = []
chars = room.children.that_are(Character) - [actor]
charsum = []
chars.each { |char|
if char.locale_description != ""
with_locales.push char
else
if charsum.length == 0
charsum.push Hypertext.link char.default_command, char.indefinitely.cap_first
else
charsum.push Hypertext.link char.default_command, char.indefinitely
end
end
}
if charsum.length > 0
actor.tell "#{charsum.join_and} #{charsum.length == 1 ? 'is' : 'are'} here."
end
items = room.children.that_are(:itemized) - [actor] - room.children.that_are(Character)
itemsum = []
items.each { |item|
if item.locale_description != ""
with_locales.push item
else
itemsum.push Hypertext.link item.default_command, item.indefinitely
end
}
if itemsum.length > 0
actor.tell "You see #{itemsum.join_and}."
end
with_locales.each { |entity|
actor.tell entity.locale_description
}
if room.is? :explicit_with_exits
portals = room.children.that_are(Portal)
if portals.length > 0
if portals.length == 1
actor.tell "There is an exit #{Hypertext.link portals[0].default_command, portals[0].direction}."
else
dirs = []
portals.each { |p|
dirs.push Hypertext.link p.default_command, p.direction
}
actor.tell "There are exits #{dirs.join_and(', ')}."
end
end
end
if actor.is? :supported
actor.tell "You are on #{the actor.parent}."
actor.parent.children.that_are(:supported).that_are_not(actor).each { |s|
actor.tell "#{Hypertext.link s.default_command, s.indefinitely.cap_first} is on #{the actor.parent}."
}
end
actor[:looking_at_room] = true
end
respond :look, Query::Visible.new(Character) do |actor, character|
actor.proceed
actor.suggest "talk to #{the character}"
end
respond :look, Query::Visible.new do |actor, thing|
actor.proceed
if thing.is? :portable
if thing.parent == actor
actor.suggest "drop #{the thing}"
else
actor.suggest "take #{the thing}"
end
end
objects = thing.children.that_are(:attached)
actor.stream ''
end
respond :look, Query::Visible.new(Container) do |actor, container|
actor.tell container.description
container.children.that_are(:attached).that_are(:itemized).each { |item|
actor.tell "#{An item} is attached to #{the container}."
}
if container.is? :openable
actor.tell "#{The container} is #{container.is?(:open) ? 'open' : 'closed'}."
end
if container.is? :open
contents = container.children.that_are(:contained)
if contents.length > 0
array = []
contents.each { |entity|
array.push Hypertext.link entity.default_command, entity.indefinitely
}
actor.tell "You see #{array.join_and} inside #{the container}."
end
end
if container.is?(:lockable) and container.is?(:locked)
actor.suggest "unlock #{the container}"
elsif container.is?(:openable) and container.is?(:closed)
actor.suggest "open #{the container}"
else
if container.is?(:openable) and container.is?(:open)
actor.suggest "close #{the container}"
end
if container.is?(:open)
actor.stream ''
end
end
if container.is?(:enterable)
actor.suggest "enter #{the container}"
end
end
respond :look, Query::Children.new(Clothing) do |actor, clothing|
actor.proceed
if clothing.is?(:worn)
actor.suggest "remove #{the clothing}"
else
actor.suggest "wear #{the clothing}"
end
end
respond :open, Query::Visible.new(Container) do |actor, container|
actor.proceed
if container.is? :open
actor.perform :look, container
end
end
#respond :look, Query::Visible.new(Device) do |actor, device|
# actor.proceed
# if device.is? :on
# actor.suggest "turn on #{the device}"
# else
# actor.suggest "turn off #{the device}"
# end
#end
respond :inventory do |actor|
if actor.children.length > 0
carried = actor.children.that_are_not(:worn)
worn = actor.children.that_are(:worn)
if carried.length > 0
array = []
carried.each { |entity|
array << "#{Hypertext.link(entity.default_command, entity.indefinitely)}"
}
actor.tell "You are carrying #{array.join_and}."
end
if worn.length > 0
array = []
worn.each { |entity|
array << "#{Hypertext.link(entity.default_command, entity.indefinitely)}"
}
actor.tell "You are wearing #{array.join_and}."
end
actor.stream ''
else
actor.tell "You aren't carrying anything."
end
actor[:checking_inventory] = true
end
respond :go, Query::Reachable.new(Door, :locked) do |actor, door|
actor.proceed
if door.is? :locked
actor.suggest "unlock #{the door}"
end
end
respond :unlock, Query::Reachable.new(:lockable) do |actor, container|
actor.proceed
if container.is?(:closed)
actor.suggest "open #{the container}"
end
end
respond :take, Query::Reachable.new(Clothing) do |actor, clothing|
actor.proceed
if clothing.parent == actor
actor.suggest "wear #{the clothing}"
end
end
on_player_update do |actor|
if actor.scene.key != :active and actor.scene.kind_of?(Gamefic::ActiveScene) == false
next
end
if actor.parent != actor.room
if actor.parent.kind_of?(Container)
actor.suggest "exit", "leave #{the actor.parent}"
else
actor.suggest "exit", "get off #{the actor.parent}"
end
end
if actor[:looking_at_room] != true
actor.suggest "look around"
end
if actor[:checking_inventory] != true
actor.suggest "inventory"
end
entities = Query::Siblings.new.context_from(actor)
portals = entities.that_are(Portal)
if portals.length > 0
actor.stream ''
end
if actor.room.is? :dark
next
end
characters = entities.that_are(Character) - [actor]
if characters.length > 0
actor.stream ''
end
objects = entities.that_are(:itemized) - characters - [actor] - portals
if objects.length > 0
actor.stream ''
end
extras = entities.that_are(:not_itemized) - characters - [actor] - portals
if extras.length > 0
actor.stream ''
end
end