gamefic-standard 3.2.3 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/Rakefile +5 -2
  4. data/gamefic-standard.gemspec +13 -11
  5. data/lib/gamefic-standard/actions/attack.rb +23 -19
  6. data/lib/gamefic-standard/actions/close.rb +16 -10
  7. data/lib/gamefic-standard/actions/drop.rb +31 -16
  8. data/lib/gamefic-standard/actions/enter.rb +32 -26
  9. data/lib/gamefic-standard/actions/give.rb +41 -0
  10. data/lib/gamefic-standard/actions/go.rb +47 -43
  11. data/lib/gamefic-standard/actions/insert.rb +42 -28
  12. data/lib/gamefic-standard/actions/inventory.rb +13 -8
  13. data/lib/gamefic-standard/actions/leave.rb +44 -37
  14. data/lib/gamefic-standard/actions/lock.rb +22 -16
  15. data/lib/gamefic-standard/actions/look.rb +123 -104
  16. data/lib/gamefic-standard/actions/move.rb +18 -14
  17. data/lib/gamefic-standard/actions/nil.rb +62 -52
  18. data/lib/gamefic-standard/actions/open.rb +34 -24
  19. data/lib/gamefic-standard/actions/place.rb +35 -20
  20. data/lib/gamefic-standard/actions/pronouns.rb +26 -18
  21. data/lib/gamefic-standard/actions/quit.rb +17 -7
  22. data/lib/gamefic-standard/actions/repeat.rb +17 -9
  23. data/lib/gamefic-standard/actions/save-restore-undo.rb +19 -11
  24. data/lib/gamefic-standard/actions/search.rb +31 -21
  25. data/lib/gamefic-standard/actions/take.rb +47 -34
  26. data/lib/gamefic-standard/actions/talk.rb +45 -31
  27. data/lib/gamefic-standard/actions/unlock.rb +31 -21
  28. data/lib/gamefic-standard/actions/wait.rb +15 -5
  29. data/lib/gamefic-standard/actions.rb +33 -0
  30. data/lib/gamefic-standard/articles.rb +45 -40
  31. data/lib/gamefic-standard/enterable.rb +13 -0
  32. data/lib/gamefic-standard/entities/character.rb +3 -0
  33. data/lib/gamefic-standard/entities/container.rb +2 -2
  34. data/lib/gamefic-standard/entities/door.rb +13 -13
  35. data/lib/gamefic-standard/entities/portal.rb +1 -1
  36. data/lib/gamefic-standard/entities/receptacle.rb +1 -1
  37. data/lib/gamefic-standard/entities/room.rb +20 -5
  38. data/lib/gamefic-standard/entities/supporter.rb +1 -1
  39. data/lib/gamefic-standard/entities/thing.rb +1 -5
  40. data/lib/gamefic-standard/introduction.rb +14 -4
  41. data/lib/gamefic-standard/lockable.rb +36 -0
  42. data/lib/gamefic-standard/openable.rb +33 -0
  43. data/lib/gamefic-standard/pathfinder.rb +75 -55
  44. data/lib/gamefic-standard/standardized.rb +65 -0
  45. data/lib/gamefic-standard/version.rb +1 -1
  46. data/lib/gamefic-standard.rb +12 -3
  47. metadata +36 -13
  48. data/lib/gamefic-standard/give.rb +0 -21
  49. data/lib/gamefic-standard/grammar/attributes.rb +0 -37
  50. data/lib/gamefic-standard/grammar/pronoun.rb +0 -101
  51. data/lib/gamefic-standard/grammar.rb +0 -2
  52. data/lib/gamefic-standard/modules/enterable.rb +0 -9
  53. data/lib/gamefic-standard/modules/lockable.rb +0 -34
  54. data/lib/gamefic-standard/modules/openable.rb +0 -19
  55. data/lib/gamefic-standard/modules/standardized.rb +0 -57
  56. data/lib/gamefic-standard/modules.rb +0 -6
  57. data/spec-opal/spec_helper.rb +0 -32
@@ -1,50 +1,57 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gamefic
2
4
  module Standard
3
- script do
4
- respond :leave, parent do |actor, thing|
5
- actor.tell "There's no way out of #{the thing}."
6
- end
5
+ module Actions
6
+ module Leave
7
+ extend Gamefic::Scriptable
7
8
 
8
- respond :leave, parent(Enterable, proc(&:enterable?)) do |actor, thing|
9
- actor.tell "You leave #{the thing}."
10
- actor.parent = thing.parent
11
- end
9
+ respond :leave, parent do |actor, thing|
10
+ actor.tell "There's no way out of #{the thing}."
11
+ end
12
12
 
13
- respond :leave, parent(Supporter, proc(&:enterable?)) do |actor, thing|
14
- actor.tell "You get off #{the thing}."
15
- actor.parent = thing.parent
16
- end
13
+ respond :leave, parent(Enterable, proc(&:enterable?)) do |actor, thing|
14
+ actor.tell "You leave #{the thing}."
15
+ actor.parent = thing.parent
16
+ end
17
17
 
18
- respond :leave, room do |actor, room|
19
- portals = room.children.that_are(Portal)
20
- if portals.length == 0
21
- actor.tell "You don't see any obvious exits."
22
- elsif portals.length == 1
23
- actor.execute :go, portals[0]
24
- else
25
- actor.tell "I don't know which way you want to go: #{portals.map(&:definitely).join_or}."
18
+ respond :leave, parent(Supporter, proc(&:enterable?)) do |actor, thing|
19
+ actor.tell "You get off #{the thing}."
20
+ actor.parent = thing.parent
26
21
  end
27
- end
28
22
 
29
- respond :leave do |actor|
30
- if actor.parent
31
- actor.execute :leave, actor.parent
32
- else
33
- actor.tell "You don't see any obvious exits."
23
+ respond :leave, room do |actor, room|
24
+ portals = room.children.that_are(Portal)
25
+ if portals.length == 0
26
+ actor.tell "You don't see any obvious exits."
27
+ elsif portals.length == 1
28
+ actor.execute :go, portals[0]
29
+ else
30
+ actor.tell "I don't know which way you want to go: #{portals.map(&:instruction).join_or}."
31
+ end
34
32
  end
35
- end
36
33
 
37
- respond :leave, parent(Container, proc(&:enterable?), proc(&:closed?)) do |actor, container|
38
- actor.execute :open, container
39
- actor.proceed if container.open?
40
- end
34
+ respond :leave do |actor|
35
+ if actor.parent
36
+ actor.execute :leave, actor.parent
37
+ else
38
+ actor.tell "You don't see any obvious exits."
39
+ end
40
+ end
41
41
 
42
- interpret "exit", "leave"
43
- interpret "exit :supporter", "leave :supporter"
44
- interpret "get on :supporter", "enter :supporter"
45
- interpret "get off :supporter", "leave :supporter"
46
- interpret "get out :container", "leave :container"
47
- interpret "get out of :container", "leave :container"
42
+ respond :leave, parent(Container, proc(&:enterable?), proc(&:closed?)) do |actor, container|
43
+ actor.execute :open, container
44
+ actor.proceed if container.open?
45
+ end
46
+
47
+ interpret 'exit', 'leave'
48
+ interpret 'exit :supporter', 'leave :supporter'
49
+ interpret 'get on :supporter', 'enter :supporter'
50
+ interpret 'get off :supporter', 'leave :supporter'
51
+ interpret 'get out :container', 'leave :container'
52
+ interpret 'get out of :container', 'leave :container'
53
+ interpret 'out', 'leave'
54
+ end
48
55
  end
49
56
  end
50
57
  end
@@ -1,25 +1,31 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gamefic
2
4
  module Standard
3
- script do
4
- respond :lock, available do |actor, thing|
5
- actor.tell "You can't lock #{the thing}."
6
- end
5
+ module Actions
6
+ module Lock
7
+ extend Gamefic::Scriptable
7
8
 
8
- respond :lock, available(Lockable, proc(&:has_lock_key?)), children do |actor, thing, key|
9
- if thing.lock_key == key
10
- thing.locked = true
11
- actor.tell "You lock ##{the thing} with #{the key}."
12
- else
13
- actor.tell "You can't lock #{the thing} with #{the key}."
9
+ respond :lock, available do |actor, thing|
10
+ actor.tell "You can't lock #{the thing}."
14
11
  end
15
- end
16
12
 
17
- respond :lock, available(Lockable, proc(&:has_lock_key?)), available do |actor, thing, key|
18
- actor.execute :take, key if key.parent != actor
19
- actor.proceed if key.parent == actor
20
- end
13
+ respond :lock, available(Lockable, proc(&:has_lock_key?)), children do |actor, thing, key|
14
+ if thing.lock_key == key
15
+ thing.locked = true
16
+ actor.tell "You lock ##{the thing} with #{the key}."
17
+ else
18
+ actor.tell "You can't lock #{the thing} with #{the key}."
19
+ end
20
+ end
21
+
22
+ respond :lock, available(Lockable, proc(&:has_lock_key?)), available do |actor, thing, key|
23
+ actor.execute :take, key if key.parent != actor
24
+ actor.proceed if key.parent == actor
25
+ end
21
26
 
22
- interpret "lock :container with :key", "lock :container :key"
27
+ interpret "lock :container with :key", "lock :container :key"
28
+ end
23
29
  end
24
30
  end
25
31
  end
@@ -1,133 +1,152 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gamefic
2
4
  module Standard
3
- script do
4
- respond :look do |actor|
5
- actor.execute :look, actor.room
6
- end
5
+ module Actions
6
+ module Look
7
+ extend Gamefic::Scriptable
7
8
 
8
- respond :look, myself do |actor, _|
9
- actor.tell actor.description
10
- actor.execute :inventory
11
- end
9
+ respond :look do |actor|
10
+ actor.execute :look, actor.room
11
+ end
12
12
 
13
- respond :look, available(Thing) do |actor, thing|
14
- actor.tell thing.description
15
- thing.children.that_are(proc(&:attached?)).that_are(proc(&:itemized?)).each do |item|
16
- actor.tell "#{An item} is attached to #{the thing}."
13
+ respond :look, myself do |actor, _|
14
+ actor.tell actor.description
15
+ actor.execute :inventory
17
16
  end
18
- end
19
17
 
20
- respond :look, available(Supporter) do |actor, thing|
21
- itemized = thing.children.that_are_not(proc(&:attached?)).that_are(proc(&:itemized?))
22
- # If the supporter does not have a description but it does contain
23
- # itemized things, avoid saying there's nothing special about it.
24
- actor.proceed if thing.has_description? || itemized.empty?
25
- actor.tell "You see #{itemized.join_and} on #{the thing}." unless itemized.empty?
26
- end
18
+ respond :look, available(Thing) do |actor, thing|
19
+ actor.tell thing.description
20
+ thing.children.that_are(proc(&:attached?)).that_are(proc(&:itemized?)).each do |item|
21
+ actor.tell "#{An item} is attached to #{the thing}."
22
+ end
23
+ end
27
24
 
28
- respond :look, available(Receptacle) do |actor, thing|
29
- actor.proceed
30
- if thing.accessible?
25
+ respond :look, available(Supporter) do |actor, thing|
31
26
  itemized = thing.children.that_are_not(proc(&:attached?)).that_are(proc(&:itemized?))
32
- actor.tell "You see #{itemized.join_and} in #{the thing}." unless itemized.empty?
27
+ # If the supporter does not have a description but it does contain
28
+ # itemized things, avoid saying there's nothing special about it.
29
+ actor.proceed if thing.has_description? || itemized.empty?
30
+ actor.tell "You see #{itemized.join_and} on #{the thing}." unless itemized.empty?
33
31
  end
34
- end
35
32
 
36
- respond :look, parent(Supporter, proc(&:enterable?)) do |actor, supporter|
37
- actor.proceed
38
- actor.tell "You are currently on #{the supporter}."
39
- end
33
+ respond :look, available(Receptacle) do |actor, thing|
34
+ actor.proceed
35
+ actor.tell "You're currently in #{the thing}." if actor.parent == thing
36
+ next unless actor.parent == thing || thing.accessible?
40
37
 
41
- respond :look, available(Thing, Openable) do |actor, thing|
42
- actor.tell thing.description if thing.has_description?
43
- actor.tell "#{The thing} is #{thing.open? ? 'open' : 'closed'}."
44
- next if thing.closed? || thing.children.empty?
38
+ itemized = thing.children.that_are_not(actor, proc(&:attached?)).that_are(proc(&:itemized?))
39
+ next if itemized.empty?
45
40
 
46
- actor.tell "You see #{thing.children.join_and}."
47
- end
48
-
49
- respond :look, room do |actor, room|
50
- actor.execute :_describe_room
51
- end
41
+ if actor.parent == thing
42
+ actor.tell "You see #{itemized.join_and} here." unless itemized.empty?
43
+ else
44
+ actor.tell "You see #{itemized.join_and} in #{the thing}." unless itemized.empty?
45
+ end
46
+ end
52
47
 
53
- meta :_describe_room do |actor|
54
- next unless actor.room
48
+ respond :look, parent(Supporter, proc(&:enterable?)) do |actor, supporter|
49
+ actor.proceed
50
+ actor.tell "You are currently on #{the supporter}."
51
+ end
55
52
 
56
- actor.tell "<strong>#{actor.room.name.cap_first}</strong>"
57
- actor.tell actor.room.description if actor.room.has_description?
58
- actor.execute :_itemize_room
59
- end
53
+ respond :look, available(Thing, Openable) do |actor, thing|
54
+ actor.tell thing.description if thing.has_description?
55
+ actor.tell "#{The thing} is #{thing.open? ? 'open' : 'closed'}."
56
+ next if thing.closed? || thing.children.empty?
60
57
 
61
- meta :_itemize_room do |actor|
62
- room = actor.room
63
- next unless room
58
+ actor.tell "You see #{thing.children.join_and}."
59
+ end
64
60
 
65
- with_locales = []
66
- chars = room.children.that_are(Character).that_are(proc(&:itemized?)) - [actor]
67
- charsum = []
68
- chars.each do |char|
69
- if char.locale_description.nil?
70
- charsum.push char
71
- else
72
- with_locales.push char
73
- end
61
+ respond :look, room do |actor, _room|
62
+ actor.execute :_describe_room
74
63
  end
75
- if charsum.length > 0
76
- actor.tell "#{charsum.join_and.cap_first} #{charsum.length == 1 ? 'is' : 'are'} here."
64
+
65
+ meta :_describe_room do |actor|
66
+ next unless actor.room
67
+
68
+ actor.tell "<strong>#{actor.room.name.cap_first}</strong>"
69
+ actor.tell actor.room.description if actor.room.has_description?
70
+ actor.execute :_itemize_room
77
71
  end
78
- items = room.children.that_are(proc(&:itemized?)) - [actor] - room.children.that_are(Character) - room.children.that_are(Portal)
79
- itemsum = []
80
- items.each do |item|
81
- if item.locale_description.nil?
82
- itemsum.push item
83
- else
84
- with_locales.push item
72
+
73
+ meta :_itemize_room do |actor|
74
+ room = actor.room
75
+ next unless room
76
+
77
+ with_locales = []
78
+ chars = room.children.that_are(Character).that_are(proc(&:itemized?)) - [actor]
79
+ charsum = []
80
+ chars.each do |char|
81
+ if char.locale_description.nil?
82
+ charsum.push char
83
+ else
84
+ with_locales.push char
85
+ end
85
86
  end
86
- end
87
- if itemsum.length > 0
88
- actor.tell "You see #{itemsum.join_and}."
89
- end
90
- with_locales.each { |entity|
91
- actor.tell entity.locale_description
92
- }
93
- if room.explicit_exits?
94
- portals = room.children.that_are(Portal).that_are(proc(&:itemized?))
95
- if portals.length > 0
96
- if portals.length == 1
97
- p = portals[0]
98
- actor.tell "There is an exit #{p.instruction}."
87
+ if charsum.length > 0
88
+ actor.tell "#{charsum.join_and.cap_first} #{charsum.length == 1 ? 'is' : 'are'} here."
89
+ end
90
+ items = room.children.that_are(proc(&:itemized?)) - [actor] - room.children.that_are(Character) - room.children.that_are(Portal)
91
+ itemsum = []
92
+ items.each do |item|
93
+ if item.locale_description.nil?
94
+ itemsum.push item
99
95
  else
100
- dirs = []
101
- portals.each do |p|
102
- dirs.push p.instruction
96
+ with_locales.push item
97
+ end
98
+ end
99
+ actor.tell "You see #{itemsum.join_and}." if itemsum.length > 0
100
+ with_locales.each do |entity|
101
+ actor.tell entity.locale_description
102
+ end
103
+ if room.explicit_exits?
104
+ portals = room.children.that_are(Portal).that_are(proc(&:itemized?))
105
+ if portals.length > 0
106
+ if portals.length == 1
107
+ p = portals[0]
108
+ actor.tell "There is an exit #{p.instruction}."
109
+ else
110
+ dirs = []
111
+ portals.each do |p|
112
+ dirs.push p.instruction
113
+ end
114
+ order = %w[north northeast east southeast south southwest west northwest up
115
+ down]
116
+ dirs.sort! { |a, b| (order.index(a.to_s) || order.length) <=> (order.index(b.to_s) || order.length) }
117
+ actor.tell "There are exits #{dirs.join_and(', ')}."
103
118
  end
104
- order = ['north', 'northeast', 'east', 'southeast', 'south', 'southwest', 'west', 'northwest', 'up', 'down']
105
- dirs.sort! { |a, b| (order.index(a.to_s) || order.length) <=> (order.index(b.to_s) || order.length) }
106
- actor.tell "There are exits #{dirs.join_and(', ')}."
107
119
  end
108
120
  end
121
+ actor.execute :_look_parent_from_room
109
122
  end
110
- if actor.parent.is_a?(Supporter)
111
- actor.tell "You are on #{the actor.parent}."
112
- actor.parent.children.that_are_not(actor).each { |s|
113
- actor.tell "#{A s} is on #{the actor.parent}."
114
- }
123
+
124
+ meta :_look_parent_from_room do |actor|
125
+ next unless actor.parent.is_a?(Supporter) || actor.parent.is_a?(Receptacle)
126
+
127
+ preposition = actor.parent.is_a?(Supporter) ? 'on' : 'in'
128
+ siblings = actor.parent.children.that_are_not(actor)
129
+ if siblings.empty?
130
+ actor.tell "You're #{preposition} #{the actor.parent}."
131
+ else
132
+ actor.tell "You're #{preposition} #{the actor.parent}, along with #{siblings.join_and}."
133
+ end
115
134
  end
116
- end
117
135
 
118
- interpret 'look around', 'look'
119
- interpret 'look here', 'look'
120
- interpret 'l', 'look'
121
-
122
- interpret 'look at :thing', 'look :thing'
123
- interpret 'look on :thing', 'look :thing'
124
- interpret 'look under :thing', 'look :thing'
125
- interpret 'look beneath :thing', 'look :thing'
126
- interpret 'look around :thing', 'look :thing'
127
- interpret 'l :thing', 'look :thing'
128
- interpret 'examine :thing', 'look :thing'
129
- interpret 'x :thing', 'look :thing'
130
- interpret 'inspect :thing', 'look :thing'
136
+ interpret 'look around', 'look'
137
+ interpret 'look here', 'look'
138
+ interpret 'l', 'look'
139
+
140
+ interpret 'look at :thing', 'look :thing'
141
+ interpret 'look on :thing', 'look :thing'
142
+ interpret 'look under :thing', 'look :thing'
143
+ interpret 'look beneath :thing', 'look :thing'
144
+ interpret 'look around :thing', 'look :thing'
145
+ interpret 'l :thing', 'look :thing'
146
+ interpret 'examine :thing', 'look :thing'
147
+ interpret 'x :thing', 'look :thing'
148
+ interpret 'inspect :thing', 'look :thing'
149
+ end
131
150
  end
132
151
  end
133
152
  end
@@ -2,23 +2,27 @@
2
2
 
3
3
  module Gamefic
4
4
  module Standard
5
- script do
6
- respond :move, Thing do |actor, thing|
7
- if thing.portable?
8
- actor.tell "Maybe you want to <em>take</em> it?"
9
- else
10
- actor.tell "You can't move #{the thing}."
5
+ module Actions
6
+ module Move
7
+ extend Gamefic::Scriptable
8
+
9
+ respond :move, Thing do |actor, thing|
10
+ if thing.portable?
11
+ actor.tell 'Maybe you want to <em>take</em> it?'
12
+ else
13
+ actor.tell "You can't move #{the thing}."
14
+ end
11
15
  end
12
- end
13
16
 
14
- respond :move, children(Thing) do |actor, thing|
15
- actor.tell "You're already carrying #{the thing}."
16
- end
17
+ respond :move, children(Thing) do |actor, thing|
18
+ actor.tell "You're already carrying #{the thing}."
19
+ end
17
20
 
18
- interpret "push :thing", "move :thing"
19
- interpret "pull :thing", "move :thing"
20
- interpret "drag :thing", "move :thing"
21
- interpret "lift :thing", "move :thing"
21
+ interpret 'push :thing', 'move :thing'
22
+ interpret 'pull :thing', 'move :thing'
23
+ interpret 'drag :thing', 'move :thing'
24
+ interpret 'lift :thing', 'move :thing'
25
+ end
22
26
  end
23
27
  end
24
28
  end
@@ -1,60 +1,70 @@
1
- Gamefic::Standard.script do
2
- meta nil, plaintext do |actor, string|
3
- next if string.strip.empty?
1
+ # frozen_string_literal: true
4
2
 
5
- words = string.keywords
6
- list = actor.epic.synonyms
7
- if list.include?(words[0]&.to_sym)
8
- if words.length > 1
9
- result = myself.query(actor, words[1..-1].join(' '))
10
- found = [result.match].compact
11
- avail = available(ambiguous: true)
12
- result = avail.query(actor, result.remainder)
13
- until result.match.nil?
14
- found.concat result.match
15
- result = avail.query(actor, result.remainder)
16
- end
17
- if found.empty?
18
- verbs = actor.epic
19
- .syntaxes
20
- .select { |syn| syn.synonym == words[0].to_sym }
21
- .map(&:verb)
22
- resps = actor.epic.responses_for(*verbs)
23
- if resps.any? { |resp| !resp.queries.empty? }
24
- actor.tell %(I recognize "#{words[0]}" as a verb but don't know what you mean by "#{words[1..-1].join(' ')}.")
25
- else
26
- actor.tell %[I recognize "#{words[0]}" but not with the rest of your sentence. (Maybe it's a one-word command?)]
27
- end
28
- elsif result.remainder != ''
29
- actor.tell %(I recognize "#{words[0]}" as a verb but was confused by "#{result.remainder}.")
30
- elsif found.one?
31
- verbs = actor.epic
32
- .syntaxes
33
- .select { |syn| syn.synonym == words[0].to_sym }
34
- .map(&:verb)
35
- resps = actor.epic.responses_for(*verbs)
36
- if resps.any? { |resp| !resp.queries.empty? }
37
- actor.tell %(I recognize "#{words[0]}" and "#{found.first.name}" but could not understand them together.)
38
- else
39
- actor.tell %[I recognize "#{words[0]}" and "#{found.first.name}" but could not understand them together. (Maybe "#{words[0]}" is a one-word command?)]
40
- end
41
- else
42
- verbs = actor.epic
43
- .syntaxes
44
- .select { |syn| syn.synonym == words[0].to_sym }
45
- .map(&:verb)
46
- resps = actor.epic.responses_for(*verbs)
47
- if resps.any? { |resp| !resp.queries.empty? }
48
- actor.tell %(I recognize "#{words[0]}" but I'm not sure if "#{words[1..-1].join(' ')}" means #{found.map(&:definitely).join_or}.)
3
+ module Gamefic
4
+ module Standard
5
+ module Actions
6
+ module Nil
7
+ extend Gamefic::Scriptable
8
+
9
+ meta nil, plaintext do |actor, string|
10
+ next if string.strip.empty?
11
+
12
+ words = string.keywords
13
+ list = actor.epic.synonyms
14
+ if list.include?(words[0]&.to_sym)
15
+ if words.length > 1
16
+ result = myself.query(actor, words[1..-1].join(' '))
17
+ found = [result.match].compact
18
+ avail = available(ambiguous: true)
19
+ result = avail.query(actor, result.remainder)
20
+ until result.match.nil?
21
+ found.concat result.match
22
+ result = avail.query(actor, result.remainder)
23
+ end
24
+ if found.empty?
25
+ verbs = actor.epic
26
+ .syntaxes
27
+ .select { |syn| syn.synonym == words[0].to_sym }
28
+ .map(&:verb)
29
+ resps = actor.epic.responses_for(*verbs)
30
+ if resps.any? { |resp| !resp.queries.empty? }
31
+ actor.tell %(I recognize "#{words[0]}" as a verb but don't know what you mean by "#{words[1..-1].join(' ')}.")
32
+ else
33
+ actor.tell %[I recognize "#{words[0]}" but not with the rest of your sentence. (Maybe it's a one-word command?)]
34
+ end
35
+ elsif result.remainder != ''
36
+ actor.tell %(I recognize "#{string.sub(/#{result.remainder}$/, '').strip}" as a command but was confused by "#{result.remainder}.")
37
+ elsif found.one?
38
+ verbs = actor.epic
39
+ .syntaxes
40
+ .select { |syn| syn.synonym == words[0].to_sym }
41
+ .map(&:verb)
42
+ resps = actor.epic.responses_for(*verbs)
43
+ if resps.any? { |resp| !resp.queries.empty? }
44
+ actor.tell %(I recognize "#{words[0]}" and "#{found.first.name}" but could not understand them together.)
45
+ else
46
+ actor.tell %[I recognize "#{words[0]}" and "#{found.first.name}" but could not understand them together. (Maybe "#{words[0]}" is a one-word command?)]
47
+ end
48
+ else
49
+ verbs = actor.epic
50
+ .syntaxes
51
+ .select { |syn| syn.synonym == words[0].to_sym }
52
+ .map(&:verb)
53
+ resps = actor.epic.responses_for(*verbs)
54
+ if resps.any? { |resp| !resp.queries.empty? }
55
+ actor.tell %(I recognize "#{words[0]}" but I'm not sure if "#{words[1..-1].join(' ')}" means #{found.map(&:definitely).join_or}.)
56
+ else
57
+ actor.tell %[I recognize "#{words[0]}" but not with the rest of your sentence. (Maybe it's a one-word command?)]
58
+ end
59
+ end
60
+ else
61
+ actor.tell %(I recognize "#{words[0]}" as a verb but could not understand it in this context.)
62
+ end
49
63
  else
50
- actor.tell %[I recognize "#{words[0]}" but not with the rest of your sentence. (Maybe it's a one-word command?)]
64
+ actor.tell %(I don't recognize "#{words[0]}" as a verb.)
51
65
  end
52
66
  end
53
- else
54
- actor.tell %(I recognize "#{words[0]}" as a verb but could not understand it in this context.)
55
67
  end
56
- else
57
- actor.tell %(I don't recognize "#{words[0]}" as a verb.)
58
68
  end
59
69
  end
60
70
  end
@@ -1,29 +1,39 @@
1
- Gamefic::Standard.script do
2
- respond :open, available do |actor, thing|
3
- actor.tell "You can't open #{the thing}."
4
- end
1
+ # frozen_string_literal: true
5
2
 
6
- respond :open, available(Openable) do |actor, thing|
7
- if thing.open?
8
- actor.tell "#{The thing} is already open."
9
- else
10
- actor.tell "You open #{the thing}."
11
- thing.open = true
12
- end
13
- end
3
+ module Gamefic
4
+ module Standard
5
+ module Actions
6
+ module Open
7
+ extend Gamefic::Scriptable
14
8
 
15
- respond :open, available(Lockable) do |actor, thing|
16
- if thing.locked?
17
- actor.tell "#{The thing} is locked."
18
- else
19
- actor.proceed
20
- end
21
- end
9
+ respond :open, available do |actor, thing|
10
+ actor.tell "You can't open #{the thing}."
11
+ end
22
12
 
23
- respond :open, available(Lockable, proc(&:has_lock_key?)), available do |actor, thing, key|
24
- actor.execute :unlock, thing, key
25
- actor.execute :open, thing if thing.unlocked?
26
- end
13
+ respond :open, available(Openable) do |actor, thing|
14
+ if thing.open?
15
+ actor.tell "#{The thing} is already open."
16
+ else
17
+ actor.tell "You open #{the thing}."
18
+ thing.open = true
19
+ end
20
+ end
21
+
22
+ respond :open, available(Lockable) do |actor, thing|
23
+ if thing.locked?
24
+ actor.tell "#{The thing} is locked."
25
+ else
26
+ actor.proceed
27
+ end
28
+ end
29
+
30
+ respond :open, available(Lockable, proc(&:has_lock_key?)), available do |actor, thing, key|
31
+ actor.execute :unlock, thing, key
32
+ actor.execute :open, thing if thing.unlocked?
33
+ end
27
34
 
28
- interpret 'open :thing with :key', 'open :thing :key'
35
+ interpret 'open :thing with :key', 'open :thing :key'
36
+ end
37
+ end
38
+ end
29
39
  end