Module: Gamefic::Standard::Actions::Look
- Extended by:
- Gamefic::Scriptable
- Included in:
- Gamefic::Standard::Actions
- Defined in:
- lib/gamefic/standard/actions/look.rb
Constant Summary collapse
- RELATION_PHRASES =
{ in: 'inside', on: 'on top of' }.freeze
Instance Method Summary collapse
- #itemize_explicit_portals(actor) ⇒ Object
- #itemize_parent(actor) ⇒ Object
- #itemize_room(actor) ⇒ Object
Instance Method Details
#itemize_explicit_portals(actor) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/gamefic/standard/actions/look.rb', line 38 def itemize_explicit_portals(actor) return unless actor.room&.explicit_exits? siblings = actor.room.children.select(&:itemized?).that_are_not(actor) earlier = siblings.select(&:locale_description).that_are(Portal).any? siblings.that_are(Portal) .reject(&:locale_description) .tap do |portals| next if portals.empty? if portals.one? actor.tell "There is#{earlier ? ' also ' : ' '}an exit #{portals.first.instruction}." else order = %w[north northeast east southeast south southwest west northwest up down] dirs = portals.map(&:instruction) .map(&:to_s) .sort { |a, b| order.index(a) || 0 <=> order.index(b) || 1 } actor.tell "There are#{earlier ? ' also ' : ' '}exits #{dirs.join_and}." end end end |
#itemize_parent(actor) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/gamefic/standard/actions/look.rb', line 60 def itemize_parent(actor) parent = actor.parent if parent != actor.room return unless parent siblings = parent.children.that_are_not(actor) if siblings.empty? actor.tell "You're #{RELATION_PHRASES[actor.relation]} #{the parent}." else actor.tell "You're #{RELATION_PHRASES[actor.relation]} #{the parent}, along with #{siblings.join_and}." end end |
#itemize_room(actor) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gamefic/standard/actions/look.rb', line 14 def itemize_room(actor) return unless (room = actor.room) siblings = room.children.select(&:itemized?).that_are_not(actor) siblings.that_are(Character) .reject(&:locale_description) .tap do |list| list.empty? or actor.tell "#{list.join_and.cap_first} #{list.one? ? 'is' : 'are'} here." end siblings.that_are_not(Character, Portal) .reject(&:locale_description) .tap do |list| list.empty? or actor.tell "You see #{list.join_and}." end siblings.select(&:locale_description) .each { |thing| actor.tell thing.locale_description } itemize_explicit_portals(actor) itemize_parent(actor) end |