gamefic-sdk 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/html/core/engine.js +89 -20
  3. data/html/sinatra/engine.js +27 -13
  4. data/html/skins/hypertext/index.html +0 -2
  5. data/html/skins/standard/play.js +0 -66
  6. data/lib/gamefic-sdk.rb +2 -1
  7. data/lib/gamefic-sdk/build.rb +11 -19
  8. data/lib/gamefic-sdk/config.rb +126 -0
  9. data/lib/gamefic-sdk/platform.rb +12 -0
  10. data/lib/gamefic-sdk/platform/base.rb +35 -33
  11. data/lib/gamefic-sdk/platform/gfic.rb +5 -18
  12. data/lib/gamefic-sdk/platform/sinatra.rb +29 -31
  13. data/lib/gamefic-sdk/platform/web.rb +72 -65
  14. data/lib/gamefic-sdk/platform/web/app_config.rb +48 -48
  15. data/lib/gamefic-sdk/platform/web/engine.rb +10 -7
  16. data/lib/gamefic-sdk/platform/web/user.rb +3 -3
  17. data/lib/gamefic-sdk/server.rb +17 -19
  18. data/lib/gamefic-sdk/shell.rb +68 -16
  19. data/lib/gamefic-sdk/shell/init.rb +3 -19
  20. data/lib/gamefic-sdk/shell/test.rb +9 -14
  21. data/lib/gamefic-sdk/version.rb +1 -1
  22. data/scripts/save-restore-undo.plot.rb +25 -0
  23. data/scripts/snapshots.plot.rb +16 -14
  24. data/scripts/standard.plot.rb +3 -5
  25. data/scripts/standard/actions.plot.rb +1 -11
  26. data/scripts/standard/actions/drop.plot.rb +1 -1
  27. data/scripts/standard/actions/enter.plot.rb +4 -16
  28. data/scripts/standard/actions/go.plot.rb +2 -36
  29. data/scripts/standard/actions/insert.plot.rb +7 -21
  30. data/scripts/standard/actions/inventory.plot.rb +2 -1
  31. data/scripts/standard/actions/leave.plot.rb +7 -18
  32. data/scripts/standard/actions/look.plot.rb +45 -44
  33. data/scripts/standard/actions/nil.plot.rb +1 -1
  34. data/scripts/standard/actions/take.plot.rb +10 -28
  35. data/scripts/standard/actions/talk.plot.rb +9 -13
  36. data/scripts/standard/clothing.plot.rb +4 -0
  37. data/scripts/standard/clothing/actions.plot.rb +4 -0
  38. data/scripts/{clothing → standard/clothing}/actions/doff.plot.rb +0 -0
  39. data/scripts/{clothing → standard/clothing}/actions/drop.plot.rb +8 -8
  40. data/scripts/{clothing → standard/clothing}/actions/inventory.plot.rb +14 -14
  41. data/scripts/standard/clothing/actions/wear.plot.rb +20 -0
  42. data/scripts/standard/clothing/entities.plot.rb +7 -0
  43. data/scripts/{clothing → standard/clothing}/entities/clothing.plot.rb +0 -2
  44. data/scripts/standard/clothing/entities/coat.plot.rb +3 -0
  45. data/scripts/standard/clothing/entities/gloves.plot.rb +3 -0
  46. data/scripts/standard/clothing/entities/hat.plot.rb +3 -0
  47. data/scripts/standard/clothing/entities/pants.plot.rb +3 -0
  48. data/scripts/standard/clothing/entities/shirt.plot.rb +3 -0
  49. data/scripts/standard/clothing/entities/shoes.plot.rb +3 -0
  50. data/scripts/standard/container.plot.rb +28 -0
  51. data/scripts/{debug.plot.rb → standard/container/actions.plot.rb} +0 -0
  52. data/scripts/standard/container/entities.plot.rb +5 -0
  53. data/scripts/standard/direction.plot.rb +1 -2
  54. data/scripts/{edible.plot.rb → standard/edible.plot.rb} +5 -3
  55. data/scripts/standard/entities.plot.rb +3 -3
  56. data/scripts/standard/entities/character.plot.rb +9 -6
  57. data/scripts/standard/entities/fixture.plot.rb +1 -1
  58. data/scripts/standard/entities/item.plot.rb +2 -4
  59. data/scripts/standard/entities/portal.plot.rb +9 -5
  60. data/scripts/standard/entities/receptacle.plot.rb +1 -1
  61. data/scripts/standard/entities/room.plot.rb +5 -5
  62. data/scripts/standard/entities/scenery.plot.rb +2 -4
  63. data/scripts/standard/entities/supporter.plot.rb +4 -7
  64. data/scripts/standard/entities/thing.plot.rb +7 -0
  65. data/scripts/standard/{actions/give.plot.rb → give.plot.rb} +27 -25
  66. data/scripts/standard/lockable.plot.rb +79 -0
  67. data/scripts/standard/modules.plot.rb +2 -4
  68. data/scripts/standard/modules/attachable.plot.rb +1 -0
  69. data/scripts/standard/modules/locale_description.plot.rb +20 -0
  70. data/scripts/standard/{use.plot.rb → modules/use.plot.rb} +51 -47
  71. data/scripts/standard/openable.plot.rb +43 -0
  72. data/scripts/standard/pathfinder.plot.rb +11 -6
  73. data/scripts/standard/test.plot.rb +2 -0
  74. data/scripts/undo.plot.rb +13 -11
  75. metadata +30 -65
  76. data/lib/gamefic-sdk/plot_config.rb +0 -25
  77. data/scripts/ansi.plot.rb +0 -13
  78. data/scripts/autosuggest.plot.rb +0 -165
  79. data/scripts/clothing.plot.rb +0 -2
  80. data/scripts/clothing/actions.plot.rb +0 -4
  81. data/scripts/clothing/actions/wear.plot.rb +0 -19
  82. data/scripts/clothing/entities.plot.rb +0 -7
  83. data/scripts/clothing/entities/coat.plot.rb +0 -5
  84. data/scripts/clothing/entities/gloves.plot.rb +0 -5
  85. data/scripts/clothing/entities/hat.plot.rb +0 -5
  86. data/scripts/clothing/entities/pants.plot.rb +0 -5
  87. data/scripts/clothing/entities/shirt.plot.rb +0 -5
  88. data/scripts/clothing/entities/shoes.plot.rb +0 -5
  89. data/scripts/cover.plot.rb +0 -30
  90. data/scripts/furniture.plot.rb +0 -35
  91. data/scripts/hints.plot.rb +0 -31
  92. data/scripts/hypertext.plot.rb +0 -280
  93. data/scripts/media.plot.rb +0 -17
  94. data/scripts/multimedia.plot.rb +0 -41
  95. data/scripts/questions.plot.rb +0 -17
  96. data/scripts/room-modes.plot.rb +0 -48
  97. data/scripts/rough-sizes.plot.rb +0 -36
  98. data/scripts/save-restore.plot.rb +0 -22
  99. data/scripts/standard/actions/close.plot.rb +0 -16
  100. data/scripts/standard/actions/lock.plot.rb +0 -59
  101. data/scripts/standard/actions/look-under.plot.rb +0 -8
  102. data/scripts/standard/actions/open.plot.rb +0 -34
  103. data/scripts/standard/actions/read.plot.rb +0 -3
  104. data/scripts/standard/actions/search.plot.rb +0 -40
  105. data/scripts/standard/actions/show.plot.rb +0 -13
  106. data/scripts/standard/actions/unlock.plot.rb +0 -77
  107. data/scripts/standard/actions/use.plot.rb +0 -25
  108. data/scripts/standard/entities/container.plot.rb +0 -8
  109. data/scripts/standard/entities/door.plot.rb +0 -51
  110. data/scripts/standard/entities/entity.plot.rb +0 -12
  111. data/scripts/standard/entities/exterior.plot.rb +0 -5
  112. data/scripts/standard/modules/darkenable.plot.rb +0 -6
  113. data/scripts/standard/modules/lockable.plot.rb +0 -25
  114. data/scripts/standard/modules/openable.plot.rb +0 -15
  115. data/scripts/standard/modules/transparent.plot.rb +0 -6
  116. data/scripts/standard/plural.plot.rb +0 -2
  117. data/scripts/standard/plural/actions.plot.rb +0 -4
  118. data/scripts/standard/plural/actions/drop.plot.rb +0 -126
  119. data/scripts/standard/plural/actions/insert.plot.rb +0 -60
  120. data/scripts/standard/plural/actions/place.plot.rb +0 -37
  121. data/scripts/standard/plural/actions/take.plot.rb +0 -175
  122. data/scripts/standard/plural/queries.plot.rb +0 -5
  123. data/scripts/standard/plural/queries/ambiguous_visible.plot.rb +0 -13
  124. data/scripts/standard/plural/queries/any_expression.plot.rb +0 -17
  125. data/scripts/standard/plural/queries/many_visible.plot.rb +0 -13
  126. data/scripts/standard/plural/queries/not_expression.plot.rb +0 -16
  127. data/scripts/standard/plural/queries/plural_visible.plot.rb +0 -22
  128. data/scripts/suggestible.plot.rb +0 -54
@@ -1,25 +0,0 @@
1
- require 'yaml'
2
-
3
- module Gamefic::Sdk
4
-
5
- class PlotConfig
6
- attr_reader :author, :title, :script_paths, :media_paths
7
- def initialize filename = nil
8
- @script_paths = []
9
- @media_paths = []
10
- if !filename.nil?
11
- config = YAML.load_file filename
12
- base_dir = File.dirname(filename)
13
- @author = config['author']
14
- @title = config['title']
15
- config['script_paths'].each { |p|
16
- @script_paths.push File.absolute_path(p, base_dir)
17
- } if !config['script_paths'].nil?
18
- config['media_paths'].map! { |p|
19
- @media_paths.push File.absolute_path(p, base_dir)
20
- } if !config['media_paths'].nil?
21
- end
22
- end
23
- end
24
-
25
- end
data/scripts/ansi.plot.rb DELETED
@@ -1,13 +0,0 @@
1
- meta :ansi do |actor|
2
- actor.tell "Ansi is #{ansi ? 'ON' : 'OFF'}."
3
- end
4
-
5
- meta :ansi, Query::Text.new('on') do |actor, string|
6
- actor.ansi = true
7
- actor.tell "Ansi is ON."
8
- end
9
-
10
- meta :ansi, Query::Text.new('off') do |actor, string|
11
- actor.ansi = false
12
- actor.tell "Ansi is OFF."
13
- end
@@ -1,165 +0,0 @@
1
- script 'suggestible'
2
-
3
- module Gamefic::Autosuggest
4
- def suggest_from entity
5
- suggest_take_from entity
6
- suggest_examine_from entity
7
- end
8
- def suggest_take_from entity
9
- portables = entity.children.that_are(:portable?)
10
- portables.each { |p|
11
- suggest "take #{p.definitely}"
12
- }
13
- end
14
- def suggest_examine_from entity
15
- entity.children.that_are_not(Portal).that_are_not(self).each { |e|
16
- suggest "examine #{e.definitely}"
17
- }
18
- end
19
- end
20
-
21
- class Gamefic::Character
22
- include Autosuggest
23
- end
24
-
25
- # Suggestions get updated (future suggestions become current) in
26
- # on_player_ready. Autosuggest gathers suggestions in on_ready so it gets
27
- # done first.
28
- on_player_ready do |actor|
29
- if (actor.scene == default_scene and actor.next_scene.nil?) or actor.next_scene == default_scene
30
- actor.suggest "look around"
31
- actor.suggest "inventory"
32
- actor.room.children.that_are(Portal).each { |entity|
33
- if entity.direction
34
- actor.suggest "go #{entity.direction}"
35
- else
36
- actor.suggest "go to #{the entity.destination}"
37
- end
38
- }
39
- Use.visible.context_from(actor).that_are_not(Portal).each { |entity|
40
- actor.suggest "examine #{the entity}"
41
- }
42
- Use.visible.context_from(actor).that_are(:portable?).each { |entity|
43
- actor.suggest "take #{the entity}" unless entity.parent == actor
44
- }
45
- Use.visible.context_from(actor).that_are(Container).that_are_not(:open?).each { |entity|
46
- actor.suggest "close #{the entity}"
47
- }
48
- Use.visible.context_from(actor).that_are(Container).that_are(:open?).each { |entity|
49
- actor.suggest "search #{the entity}"
50
- actor.suggest "close #{the entity}"
51
- }
52
- Use.siblings.context_from(actor).that_are(Enterable).that_are(:enterable?).each { |entity|
53
- actor.suggest "#{entity.enter_verb} #{the entity}"
54
- }
55
- Use.siblings.context_from(actor).that_are(Character).that_are_not(actor).each { |entity|
56
- actor.suggest "talk to #{the entity}"
57
- }
58
- if (actor.parent != actor.room)
59
- actor.suggest "#{actor.parent.leave_verb} #{the actor.parent}"
60
- end
61
- vicinity = actor.parent.children.that_are_not(Portal)
62
- if actor.parent != actor.room
63
- vicinity.concat actor.room.children.that_are_not(Portal)
64
- end
65
- vicinity = vicinity - [actor]
66
- vicinity.each { |e|
67
- actor.suggest "examine #{the e}"
68
- }
69
- end
70
- end
71
-
72
- respond :look, Use.visible(Supporter) do |actor, supporter|
73
- actor.proceed
74
- actor.suggest_from supporter
75
- end
76
-
77
- respond :look, Use.visible(Receptacle) do |actor, receptacle|
78
- actor.proceed
79
- # Include suggestions from the receptacle if they're visible
80
- # (e.g., the receptacle is not a closed opaque container)
81
- available = Use.visible.context_from(actor) & receptacle.children
82
- if available.length > 0
83
- actor.suggest_from receptacle
84
- end
85
- end
86
-
87
- respond :look, Use.visible(Container) do |actor, container|
88
- actor.proceed
89
- if container.open?
90
- actor.suggest "close #{the container}"
91
- else
92
- if container.locked?
93
- actor.suggest "unlock #{the container}"
94
- else
95
- actor.suggest "open #{the container}"
96
- if !container.lock_key.nil?
97
- actor.suggest "lock #{the container}"
98
- end
99
- end
100
- end
101
- end
102
-
103
- respond :look, Use.visible(Character) do |actor, character|
104
- actor.proceed
105
- actor.suggest "talk to #{the character}"
106
- end
107
-
108
- respond :look, Use.room do |actor, room|
109
- actor.proceed
110
- actor.suggest_from room
111
- end
112
-
113
- respond :look, Use.visible(:portable?) do |actor, thing|
114
- actor.proceed
115
- actor.suggest "take #{the thing}" unless thing.parent == actor
116
- end
117
-
118
- respond :inventory do |actor|
119
- actor.proceed
120
- carried = actor.children.that_are_not(:attached?)
121
- carried.each { |e|
122
- actor.suggest "drop #{the e}"
123
- actor.suggest "examine #{the e}"
124
- }
125
- reachable = Use.reachable.context_from(actor)
126
- reachable.that_are(Supporter).each { |supporter|
127
- carried.each { |thing|
128
- actor.suggest "put #{the thing} on #{the supporter}"
129
- }
130
- }
131
- reachable.that_are(Receptacle).each { |receptacle|
132
- carried.each { |thing|
133
- actor.suggest "put #{the thing} in #{the receptacle}"
134
- }
135
- }
136
- end
137
-
138
- respond :drop, Use.children do |actor, thing|
139
- actor.proceed
140
- actor.quietly :inventory
141
- end
142
-
143
- respond :search, Use.reachable(Receptacle) do |actor, receptacle|
144
- actor.proceed
145
- actor.children.that_are_not(:attached?).each { |e|
146
- actor.suggest "put #{the e} in #{the receptacle}"
147
- }
148
- end
149
-
150
- respond :search, Use.reachable(Container) do |actor, container|
151
- if container.open?
152
- actor.proceed
153
- else
154
- if container.has_description?
155
- actor.tell container.description
156
- end
157
- if container.locked?
158
- actor.tell "#{The container} is locked."
159
- actor.suggest "unlock #{the container}"
160
- else
161
- actor.tell "#{The container} is closed."
162
- actor.suggest "open #{the container}"
163
- end
164
- end
165
- end
@@ -1,2 +0,0 @@
1
- script 'clothing/entities'
2
- script 'clothing/actions'
@@ -1,4 +0,0 @@
1
- script 'clothing/actions/doff'
2
- script 'clothing/actions/drop'
3
- script 'clothing/actions/inventory'
4
- script 'clothing/actions/wear'
@@ -1,19 +0,0 @@
1
- respond :wear, Use.family(Clothing) do |actor, clothing|
2
- if actor.auto_takes?(clothing)
3
- if clothing.attached?
4
- actor.tell "You're already wearing #{the clothing}."
5
- else
6
- already = actor.children.that_are(clothing.class).that_are(:attached?)
7
- if already.length == 0
8
- clothing.attached = true
9
- actor.tell "You put on #{the clothing}."
10
- else
11
- actor.tell "You're already wearing #{an already[0]}."
12
- end
13
- end
14
- end
15
- end
16
-
17
- xlate "put on :clothing", "wear :clothing"
18
- xlate "put :clothing on", "wear :clothing"
19
- xlate "don :clothing", "wear :clothing"
@@ -1,7 +0,0 @@
1
- script 'clothing/entities/clothing'
2
- script 'clothing/entities/coat'
3
- script 'clothing/entities/gloves'
4
- script 'clothing/entities/hat'
5
- script 'clothing/entities/pants'
6
- script 'clothing/entities/shirt'
7
- script 'clothing/entities/shoes'
@@ -1,5 +0,0 @@
1
- script 'clothing/entities/clothing'
2
-
3
- class Coat < Clothing
4
-
5
- end
@@ -1,5 +0,0 @@
1
- script 'clothing/entities/clothing'
2
-
3
- class Gloves < Clothing
4
-
5
- end
@@ -1,5 +0,0 @@
1
- script 'clothing/entities/clothing'
2
-
3
- class Hat < Clothing
4
-
5
- end
@@ -1,5 +0,0 @@
1
- script 'clothing/entities/clothing'
2
-
3
- class Pants < Clothing
4
-
5
- end
@@ -1,5 +0,0 @@
1
- script 'clothing/entities/clothing'
2
-
3
- class Shirt < Clothing
4
-
5
- end
@@ -1,5 +0,0 @@
1
- script 'clothing/entities/clothing'
2
-
3
- class Shoes < Clothing
4
-
5
- end
@@ -1,30 +0,0 @@
1
- script 'media'
2
-
3
- module Gamefic::CoverImageViewer
4
- attr_accessor :cover_image
5
- end
6
-
7
- class Gamefic::Character
8
- include CoverImageViewer
9
- end
10
-
11
- on_player_update do |actor|
12
- if !actor.cover_image.nil?
13
- actor.stream "<figure class=\"cover\"><img src=\"media/#{actor.cover_image}\" /></figure>"
14
- end
15
- actor.cover_image = nil
16
- end
17
-
18
- respond :look, Use.room do |actor, room|
19
- if !room.image.nil?
20
- actor.cover_image = room.image
21
- end
22
- actor.proceed
23
- end
24
-
25
- respond :look, Use.reachable do |actor, thing|
26
- if !thing.image.nil?
27
- actor.cover_image = thing.image
28
- end
29
- actor.proceed
30
- end
@@ -1,35 +0,0 @@
1
- class Gamefic::Seat < Gamefic::Entity
2
- include Enterable
3
- def initialize plot, args = {}
4
- self.enterable = true
5
- self.enter_verb = "sit on"
6
- self.leave_verb = "stand up from"
7
- self.inside_verb = "be sitting on"
8
- super
9
- end
10
- end
11
-
12
- respond :sit do |actor|
13
- seats = Use.reachable.context_from(actor).that_are(Seat)
14
- if seats.length == 1
15
- actor.perform :enter, seats[0]
16
- elsif seats.length > 1
17
- actor.tell "I don't know where you want to sit: #{seats.join_or}"
18
- else
19
- actor.tell "There's nowhere to sit here."
20
- end
21
- end
22
-
23
- respond :stand do |actor|
24
- if actor.parent == actor.room
25
- actor.tell "You're already standing."
26
- else
27
- actor.perform :leave, actor.parent
28
- end
29
- end
30
-
31
- interpret "sit :seat", "enter :seat"
32
- interpret "sit on :seat", "enter :seat"
33
- interpret "stand up from :seat", "leave :seat"
34
- interpret "sit down", "sit"
35
- interpret "stand up", "stand"
@@ -1,31 +0,0 @@
1
- class Character
2
- def hints
3
- @hints ||= []
4
- end
5
- def hint message
6
- hints.push message
7
- if self.is? :strongly_guided
8
- self.stream "<p class=\"hint\">#{message}</p>"
9
- end
10
- end
11
- end
12
-
13
- options Character, :lightly_guided, :strongly_guided, :never_guided
14
-
15
- finish_action :reset_hints do |actor|
16
- actor.hints.clear
17
- end
18
-
19
- meta :hint do |actor|
20
- if !actor.is? :never_guided
21
- if actor.hints.length > 0
22
- actor.hints.each { |hint|
23
- actor.tell hint
24
- }
25
- else
26
- actor.tell "There are no hints available right now."
27
- end
28
- else
29
- actor.tell "There are no hints available in this game."
30
- end
31
- end
@@ -1,280 +0,0 @@
1
- script 'clothing'
2
-
3
- module Gamefic::Hypertext
4
- def self.link command, text = nil
5
- "<a rel=\"gamefic\" href=\"#\" data-command=\"#{command}\">#{text || command}</a>"
6
- end
7
- end
8
-
9
- class Gamefic::Entity
10
- attr_writer :default_command
11
- def default_command
12
- @default_command || "examine #{definitely}"
13
- end
14
- end
15
-
16
- class Gamefic::Character
17
- def suggest command, text = nil
18
- stream "<nav class=\"suggestions\"><p>#{Hypertext.link(command, text)}</p></nav>"
19
- end
20
- end
21
-
22
- assert_action :clear_room_mode do |actor, action|
23
- actor[:looking_at_room] = false
24
- actor[:checking_inventory] = false
25
- true
26
- end
27
-
28
- respond :look, Query::Room.new(Room) do |actor, room|
29
- actor.tell "<strong>#{room.name.cap_first}</strong>"
30
- actor.tell room.description
31
- with_locales = []
32
- chars = room.children.that_are(Character) - [actor]
33
- charsum = []
34
- chars.each { |char|
35
- if char.locale_description != ""
36
- with_locales.push char
37
- else
38
- if charsum.length == 0
39
- charsum.push Hypertext.link char.default_command, char.indefinitely.cap_first
40
- else
41
- charsum.push Hypertext.link char.default_command, char.indefinitely
42
- end
43
- end
44
- }
45
- if charsum.length > 0
46
- actor.tell "#{charsum.join_and} #{charsum.length == 1 ? 'is' : 'are'} here."
47
- end
48
- items = room.children.that_are(:itemized) - [actor] - room.children.that_are(Character)
49
- itemsum = []
50
- items.each { |item|
51
- if item.locale_description != ""
52
- with_locales.push item
53
- else
54
- itemsum.push Hypertext.link item.default_command, item.indefinitely
55
- end
56
- }
57
- if itemsum.length > 0
58
- actor.tell "You see #{itemsum.join_and}."
59
- end
60
- with_locales.each { |entity|
61
- actor.tell entity.locale_description
62
- }
63
- if room.is? :explicit_with_exits
64
- portals = room.children.that_are(Portal)
65
- if portals.length > 0
66
- if portals.length == 1
67
- actor.tell "There is an exit #{Hypertext.link portals[0].default_command, portals[0].direction}."
68
- else
69
- dirs = []
70
- portals.each { |p|
71
- dirs.push Hypertext.link p.default_command, p.direction
72
- }
73
- actor.tell "There are exits #{dirs.join_and(', ')}."
74
- end
75
- end
76
- end
77
- if actor.is? :supported
78
- actor.tell "You are on #{the actor.parent}."
79
- actor.parent.children.that_are(:supported).that_are_not(actor).each { |s|
80
- actor.tell "#{Hypertext.link s.default_command, s.indefinitely.cap_first} is on #{the actor.parent}."
81
- }
82
- end
83
- actor[:looking_at_room] = true
84
- end
85
-
86
- respond :look, Query::Visible.new(Character) do |actor, character|
87
- actor.proceed
88
- actor.suggest "talk to #{the character}"
89
- end
90
-
91
- respond :look, Query::Visible.new do |actor, thing|
92
- actor.proceed
93
- if thing.is? :portable
94
- if thing.parent == actor
95
- actor.suggest "drop #{the thing}"
96
- else
97
- actor.suggest "take #{the thing}"
98
- end
99
- end
100
- objects = thing.children.that_are(:attached)
101
- actor.stream '<nav class="objects">'
102
- objects.each { |object|
103
- actor.tell Hypertext.link "look #{object}", object
104
- }
105
- actor.stream '</nav>'
106
- end
107
-
108
- respond :look, Query::Visible.new(Container) do |actor, container|
109
- actor.tell container.description
110
- container.children.that_are(:attached).that_are(:itemized).each { |item|
111
- actor.tell "#{An item} is attached to #{the container}."
112
- }
113
- if container.is? :openable
114
- actor.tell "#{The container} is #{container.is?(:open) ? 'open' : 'closed'}."
115
- end
116
- if container.is? :open
117
- contents = container.children.that_are(:contained)
118
- if contents.length > 0
119
- array = []
120
- contents.each { |entity|
121
- array.push Hypertext.link entity.default_command, entity.indefinitely
122
- }
123
- actor.tell "You see #{array.join_and} inside #{the container}."
124
- end
125
- end
126
- if container.is?(:lockable) and container.is?(:locked)
127
- actor.suggest "unlock #{the container}"
128
- elsif container.is?(:openable) and container.is?(:closed)
129
- actor.suggest "open #{the container}"
130
- else
131
- if container.is?(:openable) and container.is?(:open)
132
- actor.suggest "close #{the container}"
133
- end
134
- if container.is?(:open)
135
- actor.stream '<nav class="objects">'
136
- objects = container.children.that_are(:itemized)
137
- objects.each { |object|
138
- actor.stream Hypertext.link "look #{object}", object
139
- }
140
- actor.stream '</nav>'
141
- end
142
- end
143
- if container.is?(:enterable)
144
- actor.suggest "enter #{the container}"
145
- end
146
- end
147
-
148
- respond :look, Query::Children.new(Clothing) do |actor, clothing|
149
- actor.proceed
150
- if clothing.is?(:worn)
151
- actor.suggest "remove #{the clothing}"
152
- else
153
- actor.suggest "wear #{the clothing}"
154
- end
155
- end
156
-
157
- respond :open, Query::Visible.new(Container) do |actor, container|
158
- actor.proceed
159
- if container.is? :open
160
- actor.perform :look, container
161
- end
162
- end
163
-
164
- #respond :look, Query::Visible.new(Device) do |actor, device|
165
- # actor.proceed
166
- # if device.is? :on
167
- # actor.suggest "turn on #{the device}"
168
- # else
169
- # actor.suggest "turn off #{the device}"
170
- # end
171
- #end
172
-
173
- respond :inventory do |actor|
174
- if actor.children.length > 0
175
- carried = actor.children.that_are_not(:worn)
176
- worn = actor.children.that_are(:worn)
177
- if carried.length > 0
178
- array = []
179
- carried.each { |entity|
180
- array << "#{Hypertext.link(entity.default_command, entity.indefinitely)}"
181
- }
182
- actor.tell "You are carrying #{array.join_and}."
183
- end
184
- if worn.length > 0
185
- array = []
186
- worn.each { |entity|
187
- array << "#{Hypertext.link(entity.default_command, entity.indefinitely)}"
188
- }
189
- actor.tell "You are wearing #{array.join_and}."
190
- end
191
- actor.stream '<nav class="objects">'
192
- actor.children.each { |object|
193
- actor.tell Hypertext.link "look #{object}", object.definitely
194
- }
195
- actor.stream '</nav>'
196
- else
197
- actor.tell "You aren't carrying anything."
198
- end
199
- actor[:checking_inventory] = true
200
- end
201
-
202
- respond :go, Query::Reachable.new(Door, :locked) do |actor, door|
203
- actor.proceed
204
- if door.is? :locked
205
- actor.suggest "unlock #{the door}"
206
- end
207
- end
208
-
209
- respond :unlock, Query::Reachable.new(:lockable) do |actor, container|
210
- actor.proceed
211
- if container.is?(:closed)
212
- actor.suggest "open #{the container}"
213
- end
214
- end
215
-
216
- respond :take, Query::Reachable.new(Clothing) do |actor, clothing|
217
- actor.proceed
218
- if clothing.parent == actor
219
- actor.suggest "wear #{the clothing}"
220
- end
221
- end
222
-
223
- on_player_update do |actor|
224
- if actor.scene.key != :active and actor.scene.kind_of?(Gamefic::ActiveScene) == false
225
- next
226
- end
227
- if actor.parent != actor.room
228
- if actor.parent.kind_of?(Container)
229
- actor.suggest "exit", "leave #{the actor.parent}"
230
- else
231
- actor.suggest "exit", "get off #{the actor.parent}"
232
- end
233
- end
234
- if actor[:looking_at_room] != true
235
- actor.suggest "look around"
236
- end
237
- if actor[:checking_inventory] != true
238
- actor.suggest "inventory"
239
- end
240
- entities = Query::Siblings.new.context_from(actor)
241
- portals = entities.that_are(Portal)
242
- if portals.length > 0
243
- actor.stream '<nav class="portals">'
244
- actor.stream "Exits: "
245
- portals.each { |portal|
246
- actor.stream Hypertext.link("go #{portal.direction}", "#{portal.direction}") + " "
247
- }
248
- actor.stream '</nav>'
249
- end
250
- if actor.room.is? :dark
251
- next
252
- end
253
- characters = entities.that_are(Character) - [actor]
254
- if characters.length > 0
255
- actor.stream '<nav class="characters">'
256
- actor.stream "Characters: "
257
- characters.each { |entity|
258
- actor.stream Hypertext.link("examine #{the entity}", "#{the entity}") + " "
259
- }
260
- actor.stream '</nav>'
261
- end
262
- objects = entities.that_are(:itemized) - characters - [actor] - portals
263
- if objects.length > 0
264
- actor.stream '<nav class="objects">'
265
- actor.stream "Objects: "
266
- objects.each { |entity|
267
- actor.stream Hypertext.link(entity.default_command, "#{the entity}") + " "
268
- }
269
- actor.stream '</nav>'
270
- end
271
- extras = entities.that_are(:not_itemized) - characters - [actor] - portals
272
- if extras.length > 0
273
- actor.stream '<nav class="incidentals">'
274
- actor.stream "Incidentals: "
275
- extras.each { |entity|
276
- actor.stream Hypertext.link("examine #{the entity}", "#{the entity}") + " "
277
- }
278
- actor.stream '</nav>'
279
- end
280
- end