gamefic-standard 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -2
  3. data/gamefic-standard.gemspec +1 -1
  4. data/lib/gamefic-standard/actions/close.rb +14 -0
  5. data/lib/gamefic-standard/actions/drop.rb +9 -6
  6. data/lib/gamefic-standard/actions/enter.rb +4 -0
  7. data/lib/gamefic-standard/actions/go.rb +20 -15
  8. data/lib/gamefic-standard/actions/insert.rb +8 -0
  9. data/lib/gamefic-standard/actions/leave.rb +10 -0
  10. data/lib/gamefic-standard/actions/lock.rb +21 -0
  11. data/lib/gamefic-standard/actions/look.rb +11 -10
  12. data/lib/gamefic-standard/actions/nil.rb +7 -10
  13. data/lib/gamefic-standard/actions/open.rb +29 -0
  14. data/lib/gamefic-standard/actions/place.rb +6 -18
  15. data/lib/gamefic-standard/actions/search.rb +26 -0
  16. data/lib/gamefic-standard/actions/take.rb +0 -4
  17. data/lib/gamefic-standard/actions/talk.rb +1 -5
  18. data/lib/gamefic-standard/actions/unlock.rb +21 -0
  19. data/lib/gamefic-standard/actions.rb +5 -0
  20. data/lib/gamefic-standard/entities/character.rb +2 -11
  21. data/lib/gamefic-standard/entities/container.rb +6 -0
  22. data/lib/gamefic-standard/{door.rb → entities/door.rb} +0 -9
  23. data/lib/gamefic-standard/entities/room.rb +1 -15
  24. data/lib/gamefic-standard/entities/thing.rb +5 -62
  25. data/lib/gamefic-standard/entities.rb +2 -0
  26. data/lib/gamefic-standard/give.rb +15 -18
  27. data/lib/gamefic-standard/modules/lockable.rb +32 -0
  28. data/lib/gamefic-standard/modules/openable.rb +19 -0
  29. data/lib/gamefic-standard/modules/standardized.rb +59 -0
  30. data/lib/gamefic-standard/modules.rb +3 -0
  31. data/lib/gamefic-standard/pathfinder.rb +0 -2
  32. data/lib/gamefic-standard/queries.rb +2 -2
  33. data/lib/gamefic-standard/test.rb +0 -2
  34. data/lib/gamefic-standard/version.rb +1 -1
  35. data/lib/gamefic-standard.rb +0 -2
  36. metadata +14 -29
  37. data/lib/gamefic-standard/clothing/actions/doff.rb +0 -14
  38. data/lib/gamefic-standard/clothing/actions/drop.rb +0 -10
  39. data/lib/gamefic-standard/clothing/actions/inventory.rb +0 -16
  40. data/lib/gamefic-standard/clothing/actions/wear.rb +0 -21
  41. data/lib/gamefic-standard/clothing/actions.rb +0 -4
  42. data/lib/gamefic-standard/clothing/entities/clothing.rb +0 -5
  43. data/lib/gamefic-standard/clothing/entities/coat.rb +0 -3
  44. data/lib/gamefic-standard/clothing/entities/gloves.rb +0 -3
  45. data/lib/gamefic-standard/clothing/entities/hat.rb +0 -3
  46. data/lib/gamefic-standard/clothing/entities/pants.rb +0 -3
  47. data/lib/gamefic-standard/clothing/entities/shirt.rb +0 -3
  48. data/lib/gamefic-standard/clothing/entities/shoes.rb +0 -3
  49. data/lib/gamefic-standard/clothing/entities.rb +0 -7
  50. data/lib/gamefic-standard/clothing.rb +0 -4
  51. data/lib/gamefic-standard/container.rb +0 -27
  52. data/lib/gamefic-standard/edible.rb +0 -23
  53. data/lib/gamefic-standard/lockable.rb +0 -98
  54. data/lib/gamefic-standard/openable.rb +0 -54
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 755a0c99a63ecce4d48bbbf7381e744c0b7bba4afe57d63c77a8d7febbeba51c
4
- data.tar.gz: dcd68b55305fa872123273e76bec293bacf3b396608249291f483d3f01627bf9
3
+ metadata.gz: 4cec02b79dddf5d0d091572a1bcf1f02c3694d1185097ec4872a73575ff8eeb2
4
+ data.tar.gz: f12ca35e7714a573ae43dff154828a35e48123b839413f58bf267eb6a72e251d
5
5
  SHA512:
6
- metadata.gz: 19c17e7ae751826ef14a8533b406b2d9d978fbaad606949aebd2547f34a4a6ee7a901613e4d128694c784e8a8cf993b3c60d8cb6ba050de46a80e70455e0ff55
7
- data.tar.gz: f10f11412b6128ec91057c060ef418fd54789cd9d616c24178b4e2c070f00cf5c4c478f56e49fe07eea029d29114c11df14566c1826d00bb962f7e581702cb13
6
+ metadata.gz: c8924d8c3a38a2f8e828a5b3df4ede8fcad15af65f14abbddae13d3be0166e9490c5dc7767e5588a4ccf85f442acf5e780b189700ca3ea3d05a7ce6c27c85abb
7
+ data.tar.gz: '094c6956a318d684e1a8efee452333d376141848e7f1470af3dc168786aacfba2af375c6b3c9cbe5636fb53b2b51a66f47cb3b4d0c6b4ac8cc867abded9a7faf'
data/CHANGELOG.md CHANGED
@@ -1,8 +1,22 @@
1
- # 2.2.0 - June 21, 2021
1
+ ## 2.3.0 - September 4, 2021
2
+ - Use nil actions for untokenized arguments
3
+ - Fix response to closing closed entities
4
+ - Working give action
5
+ - Miscellaneous fixes for new specs
6
+ - Search action
7
+ - Separate actions from entities/modules
8
+ - Remove clothing
9
+ - Improve lockable behavior
10
+ - Remove edible
11
+ - Remove broken connect method
12
+ - Leave action opens entered containers
13
+ - Reduce entity inheritance
14
+
15
+ ## 2.2.0 - June 21, 2021
2
16
  - Insert, place, and wear try take first
3
17
  - Improved verb recognition
4
18
  - Openable doors
5
19
 
6
- # 2.1.0 - March 7, 2021
20
+ ## 2.1.0 - March 7, 2021
7
21
  - Remove sticky attribute
8
22
  - Use set_player_class
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
36
  spec.require_paths = ["lib"]
37
37
 
38
- spec.add_dependency 'gamefic', '~> 2.0', '>= 2.0.3'
38
+ spec.add_dependency 'gamefic', '~> 2.2'
39
39
 
40
40
  spec.add_development_dependency 'bundler', '~> 2.0'
41
41
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -0,0 +1,14 @@
1
+ Gamefic.script do
2
+ respond :close, Use.available do |actor, thing|
3
+ actor.tell "You can't close #{the thing}."
4
+ end
5
+
6
+ respond :close, Use.available(Openable) do |actor, thing|
7
+ if thing.open?
8
+ actor.tell "You close #{the thing}."
9
+ thing.open = false
10
+ else
11
+ actor.tell "#{The thing} is already closed."
12
+ end
13
+ end
14
+ end
@@ -1,10 +1,13 @@
1
1
  Gamefic.script do
2
- respond :drop, Use.family() do |actor, thing|
3
- if thing.parent != actor
4
- actor.tell "You're not carrying #{the thing}."
5
- else
6
- actor.proceed
7
- end
2
+ respond :drop, Use.available do |actor, thing|
3
+ actor.tell "You're not carrying #{the thing}."
4
+ end
5
+
6
+ respond :drop, Gamefic::Query::Descendants.new do |actor, thing|
7
+ actor.perform :take, thing
8
+ next unless thing.parent == actor
9
+ thing.parent = actor.parent
10
+ actor.tell "You drop #{the thing}."
8
11
  end
9
12
 
10
13
  respond :drop, Use.children do |actor, thing|
@@ -16,6 +16,10 @@ Gamefic.script do
16
16
  actor.tell "You're inside #{the supporter} already."
17
17
  end
18
18
 
19
+ respond :enter, Use.siblings(Container, :enterable?, :closed?) do |actor, container|
20
+ actor.tell "#{The container} is closed."
21
+ end
22
+
19
23
  interpret "get on :thing", "enter :thing"
20
24
  interpret "get in :thing", "enter :thing"
21
25
  end
@@ -1,27 +1,32 @@
1
1
  Gamefic.script do
2
2
  respond :go, Use.siblings(Portal) do |actor, portal|
3
- if actor.parent != actor.room
4
- actor.perform :leave
3
+ if portal.destination.nil?
4
+ actor.tell "That portal leads nowhere."
5
+ else
6
+ actor.parent = portal.destination
7
+ if !portal.direction.nil?
8
+ actor.tell "You go #{portal.direction}."
9
+ end
10
+ actor.perform :look
5
11
  end
12
+ end
13
+
14
+ respond :go, Use.text do |actor, text|
6
15
  if actor.parent == actor.room
7
- if portal.destination.nil?
8
- actor.tell "That portal leads nowhere."
16
+ actor.tell "I don't see any way to go \"#{text} from here."
17
+ else
18
+ actor.perform :leave
19
+ if actor.parent == actor.room
20
+ actor.perform "go #{text}"
9
21
  else
10
- actor.parent = portal.destination
11
- if !portal.direction.nil?
12
- actor.tell "You go #{portal.direction}."
13
- end
14
- actor.perform :look
22
+ actor.proceed
15
23
  end
16
24
  end
17
25
  end
18
26
 
19
- respond :go, Use.text do |actor, string|
20
- actor.tell "You don't see any exit \"#{string}\" from here."
21
- end
22
-
23
- respond :go do |actor|
24
- actor.tell "Where do you want to go?"
27
+ respond :go, Use.available(Door) do |actor, door|
28
+ actor.perform :open, door unless door.open?
29
+ actor.proceed if door.open?
25
30
  end
26
31
 
27
32
  interpret "north", "go north"
@@ -10,6 +10,14 @@ Gamefic.script do
10
10
  actor.tell "You put #{the thing} in #{the receptacle}."
11
11
  end
12
12
 
13
+ respond :insert, Use.available, Use.available(Container) do |actor, _thing, container|
14
+ if container.open?
15
+ actor.proceed
16
+ else
17
+ actor.tell "#{The container} is closed."
18
+ end
19
+ end
20
+
13
21
  interpret "drop :item in :container", "insert :item :container"
14
22
  interpret "put :item in :container", "insert :item :container"
15
23
  interpret "place :item in :container", "insert :item :container"
@@ -8,6 +8,11 @@ Gamefic.script do
8
8
  actor.parent = thing.parent
9
9
  end
10
10
 
11
+ respond :leave, Use.parent(Supporter, :enterable?) do |actor, thing|
12
+ actor.tell "You get off #{the thing}."
13
+ actor.parent = thing.parent
14
+ end
15
+
11
16
  respond :leave, Use.room do |actor, room|
12
17
  portals = room.children.that_are(Portal)
13
18
  if portals.length == 0
@@ -23,6 +28,11 @@ Gamefic.script do
23
28
  actor.perform :leave, actor.parent
24
29
  end
25
30
 
31
+ respond :leave, Use.parent(Container, :enterable?, :closed?) do |actor, container|
32
+ actor.perform :open, container
33
+ actor.proceed if container.open?
34
+ end
35
+
26
36
  interpret "exit", "leave"
27
37
  interpret "exit :supporter", "leave :supporter"
28
38
  interpret "get on :supporter", "enter :supporter"
@@ -0,0 +1,21 @@
1
+ Gamefic.script do
2
+ respond :lock, Use.available do |actor, thing|
3
+ actor.tell "You can't lock #{the thing}."
4
+ end
5
+
6
+ respond :lock, Use.available(Lockable, :has_lock_key?), Use.children do |actor, thing, key|
7
+ if thing.lock_key == key
8
+ thing.locked = true
9
+ actor.tell "You lock ##{the thing} with #{the key}."
10
+ else
11
+ actor.tell "You can't lock #{the thing} with #{the key}."
12
+ end
13
+ end
14
+
15
+ respond :lock, Use.available(Lockable, :has_lock_key?), Use.available do |actor, thing, key|
16
+ actor.perform :take, key if key.parent != actor
17
+ actor.proceed if key.parent == actor
18
+ end
19
+
20
+ interpret "lock :container with :key", "lock :container :key"
21
+ end
@@ -1,8 +1,4 @@
1
1
  Gamefic.script do
2
- respond :look, Use.text do |actor, string|
3
- actor.tell "You don't see any \"#{string}\" here."
4
- end
5
-
6
2
  respond :look, Use.text(/^here$/i) do |actor, _|
7
3
  actor.perform :look, actor.room
8
4
  end
@@ -14,9 +10,9 @@ Gamefic.script do
14
10
 
15
11
  respond :look, Use.available(Thing) do |actor, thing|
16
12
  actor.tell thing.description
17
- thing.children.that_are(:attached?).that_are(:itemized?).each { |item|
13
+ thing.children.that_are(:attached?).that_are(:itemized?).each do |item|
18
14
  actor.tell "#{An item} is attached to #{the thing}."
19
- }
15
+ end
20
16
  end
21
17
 
22
18
  respond :look, Use.available(Supporter) do |actor, thing|
@@ -40,6 +36,11 @@ Gamefic.script do
40
36
  actor.tell "You are currently on #{the supporter}."
41
37
  end
42
38
 
39
+ respond :look, Use.available(Thing, Openable) do |actor, thing|
40
+ actor.proceed
41
+ actor.tell "#{The thing} is #{thing.open? ? 'open' : 'closed'}."
42
+ end
43
+
43
44
  respond :look, Use.room do |actor, room|
44
45
  actor.tell "<strong>#{room.name.cap_first}</strong>"
45
46
  actor.tell room.description if room.has_description?
@@ -52,13 +53,13 @@ Gamefic.script do
52
53
  with_locales = []
53
54
  chars = room.children.that_are(Character).that_are(:itemized?) - [actor]
54
55
  charsum = []
55
- chars.each { |char|
56
+ chars.each do |char|
56
57
  if char.locale_description.nil?
57
58
  charsum.push char
58
59
  else
59
60
  with_locales.push char
60
61
  end
61
- }
62
+ end
62
63
  if charsum.length > 0
63
64
  actor.tell "#{charsum.join_and.cap_first} #{charsum.length == 1 ? 'is' : 'are'} here."
64
65
  end
@@ -85,9 +86,9 @@ Gamefic.script do
85
86
  actor.tell "There is an exit #{p.instruction}."
86
87
  else
87
88
  dirs = []
88
- portals.each { |p|
89
+ portals.each do |p|
89
90
  dirs.push p.instruction
90
- }
91
+ end
91
92
  actor.tell "There are exits #{dirs.join_and(', ')}."
92
93
  end
93
94
  end
@@ -7,7 +7,13 @@ Gamefic.script do
7
7
  if words.length > 1
8
8
  found = Gamefic::Query::Available.new.resolve(actor, words[1..-1].join(' ')).objects
9
9
  if found.empty?
10
- actor.tell %(I recognize "#{words[0]}" as a verb but could not understand the rest of your sentence.)
10
+ actions = []
11
+ actor.playbooks.reverse.each { |p| actions.concat p.actions_for(words[0].to_sym) }
12
+ if actions.any? { |a| a.queries.one? && !a.queries.first.is_a?(Gamefic::Query::Text) }
13
+ actor.tell %(I recognize "#{words[0]}" as a verb but don't know what you mean by "#{words[1..-1].join(' ')}.")
14
+ else
15
+ actor.tell %(I recognize "#{words[0]}" as a verb but could not understand the rest of your sentence.)
16
+ end
11
17
  elsif found.one?
12
18
  actor.tell %(I recognize "#{words[0]}" and "#{found.first.name}" but could not understand them together.)
13
19
  else
@@ -20,13 +26,4 @@ Gamefic.script do
20
26
  actor.tell %(I don't recognize "#{words[0]}" as a verb.)
21
27
  end
22
28
  end
23
-
24
- meta nil, Gamefic::Query::Text.new(/^it$/) do |actor, string|
25
- words = string.split_words
26
- if verbs(to_s: true).include?(words[0])
27
- actor.tell "I'm not sure what you mean by \"it.\""
28
- else
29
- actor.proceed
30
- end
31
- end
32
29
  end
@@ -0,0 +1,29 @@
1
+ Gamefic.script do
2
+ respond :open, Use.available do |actor, thing|
3
+ actor.tell "You can't open #{the thing}."
4
+ end
5
+
6
+ respond :open, Use.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
14
+
15
+ respond :open, Use.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
22
+
23
+ respond :open, Use.available(Lockable, :has_lock_key?), Use.available do |actor, thing, key|
24
+ actor.perform :unlock, thing, key
25
+ actor.perform :open, thing if thing.unlocked?
26
+ end
27
+
28
+ interpret 'open :thing with :key', 'open :thing :key'
29
+ end
@@ -15,22 +15,10 @@ Gamefic.script do
15
15
  actor.tell "You put #{the thing} on #{the supporter}."
16
16
  end
17
17
 
18
- respond :place, Use.visible, Use.text do |actor, _thing, supporter|
19
- actor.tell "You don't see anything called \"#{supporter}\" here."
20
- end
21
-
22
- respond :place, Use.text, Use.visible do |actor, thing, supporter|
23
- actor.tell "You don't see anything called \"#{thing}\" here."
24
- end
25
-
26
- respond :place, Use.text, Use.text do |actor, thing, supporter|
27
- actor.tell "I don't know what you mean by \"#{thing}\" or \"#{supporter}.\""
28
- end
29
-
30
- interpret "put :thing on :supporter", "place :thing :supporter"
31
- interpret "put :thing down on :supporter", "place :thing :supporter"
32
- interpret "set :thing on :supporter", "place :thing :supporter"
33
- interpret "set :thing down on :supporter", "place :thing :supporter"
34
- interpret "drop :thing on :supporter", "place :thing :supporter"
35
- interpret "place :thing on :supporter", "place :thing :supporter"
18
+ interpret 'put :thing on :supporter', 'place :thing :supporter'
19
+ interpret 'put :thing down on :supporter', 'place :thing :supporter'
20
+ interpret 'set :thing on :supporter', 'place :thing :supporter'
21
+ interpret 'set :thing down on :supporter', 'place :thing :supporter'
22
+ interpret 'drop :thing on :supporter', 'place :thing :supporter'
23
+ interpret 'place :thing on :supporter', 'place :thing :supporter'
36
24
  end
@@ -0,0 +1,26 @@
1
+ Gamefic.script do
2
+ respond :search, Use.available(Thing) do |actor, thing|
3
+ actor.perform :look, thing
4
+ end
5
+
6
+ respond :search, Use.available(Receptacle) do |actor, thing|
7
+ if thing.accessible?
8
+ itemized = thing.children.that_are_not(:attached?).that_are(:itemized?)
9
+ if itemized.empty?
10
+ actor.tell "There's nothing inside #{the thing}."
11
+ else
12
+ actor.tell "You see #{itemized.join_and} in #{the thing}." unless itemized.empty?
13
+ end
14
+ else
15
+ actor.tell "You can't see inside #{the thing}."
16
+ end
17
+ end
18
+
19
+ respond :search, Use.available(Container, :closed?) do |actor, container|
20
+ actor.perform :open, container
21
+ actor.proceed if container.open?
22
+ end
23
+
24
+ interpret 'look inside :thing', 'search :thing'
25
+ interpret 'look in :thing', 'search :thing'
26
+ end
@@ -1,8 +1,4 @@
1
1
  Gamefic.script do
2
- respond :take, Use.text do |actor, text|
3
- actor.tell "You don't see any \"#{text}\" here."
4
- end
5
-
6
2
  respond :take, Use.available do |actor, thing|
7
3
  if thing.parent == actor
8
4
  actor.tell "You're already carrying #{the thing}."
@@ -12,11 +12,7 @@ Gamefic.script do
12
12
  end
13
13
 
14
14
  respond :talk, Use.available(Character) do |actor, character|
15
- if actor == character
16
- actor.perform :talk
17
- else
18
- actor.tell "#{The character} has nothing to say."
19
- end
15
+ actor.tell "#{The character} has nothing to say."
20
16
  end
21
17
 
22
18
  interpret "talk to :character", "talk :character"
@@ -0,0 +1,21 @@
1
+ Gamefic.script do
2
+ respond :unlock, Use.available do |actor, thing|
3
+ actor.tell "You can't unlock #{the thing}."
4
+ end
5
+
6
+ respond :unlock, Use.available(Lockable, :has_lock_key?), Use.children do |actor, thing, key|
7
+ if thing.lock_key == key
8
+ thing.locked = false
9
+ actor.tell "You unlock ##{the thing} with #{the key}."
10
+ else
11
+ actor.tell "You can't unlock #{the thing} with #{the key}."
12
+ end
13
+ end
14
+
15
+ respond :unlock, Use.available(Lockable, :has_lock_key?), Use.available do |actor, _thing, key|
16
+ actor.perform :take, key if key.parent != actor
17
+ actor.proceed if key.parent == actor
18
+ end
19
+
20
+ interpret "unlock :container with :key", "unlock :container :key"
21
+ end
@@ -1,11 +1,16 @@
1
1
  require 'gamefic-standard/actions/nil'
2
2
  require 'gamefic-standard/actions/drop'
3
3
  require 'gamefic-standard/actions/enter'
4
+ require 'gamefic-standard/actions/open'
5
+ require 'gamefic-standard/actions/close'
6
+ require 'gamefic-standard/actions/lock'
7
+ require 'gamefic-standard/actions/unlock'
4
8
  require 'gamefic-standard/actions/go'
5
9
  require 'gamefic-standard/actions/insert'
6
10
  require 'gamefic-standard/actions/inventory'
7
11
  require 'gamefic-standard/actions/leave'
8
12
  require 'gamefic-standard/actions/look'
13
+ require 'gamefic-standard/actions/search'
9
14
  require 'gamefic-standard/actions/place'
10
15
  require 'gamefic-standard/actions/quit'
11
16
  require 'gamefic-standard/actions/take'
@@ -1,11 +1,2 @@
1
- class Character < Thing
2
- include Gamefic::Active
3
-
4
- def gender
5
- @gender ||= :other
6
- end
7
- end
8
-
9
- Gamefic.script do
10
- set_player_class Character
11
- end
1
+ Character = Gamefic::Actor
2
+ Character.set_default gender: :other
@@ -0,0 +1,6 @@
1
+ # An openable and lockable receptacle.
2
+ #
3
+ class Container < Receptacle
4
+ include Openable
5
+ include Lockable
6
+ end
@@ -1,5 +1,3 @@
1
- require 'gamefic-standard/openable'
2
-
3
1
  # An openable portal.
4
2
  #
5
3
  class Door < Portal
@@ -40,10 +38,3 @@ class Door < Portal
40
38
  rev.locked = locked?
41
39
  end
42
40
  end
43
-
44
- Gamefic.script do
45
- respond :go, Use.available(Door) do |actor, door|
46
- actor.perform :open, door unless door.open?
47
- actor.proceed if door.open?
48
- end
49
- end
@@ -8,9 +8,7 @@ class Room < Thing
8
8
  end
9
9
 
10
10
  def tell(message)
11
- children.each { |c|
12
- c.tell message
13
- }
11
+ children.each { |c| c.tell message }
14
12
  end
15
13
 
16
14
  def find_portal(direction)
@@ -61,15 +59,3 @@ module Gamefic::World
61
59
  portal
62
60
  end
63
61
  end
64
-
65
- Room.module_exec self do |plot|
66
- # Define the connect method dynamically so the plot is available
67
- define_method :connect do |destination, direction = nil, type: Portal, two_way: true|
68
- plot.connect self, destination, direction, type: Portal, two_way: true
69
- end
70
- end
71
- class Room
72
- # @!method connect destination, direction = nil, type: Portal, two_way: true
73
- # Create a portal to connect this room to a destination.
74
- # @return [Portal]
75
- end
@@ -1,64 +1,7 @@
1
- class Thing < Gamefic::Entity
1
+ class Gamefic::Entity
2
2
  include Grammar::Attributes
3
-
4
- # @return [Boolean]
5
- attr_writer :itemized
6
-
7
- # @return [Boolean]
8
- attr_writer :portable
9
-
10
- # An optional description to use when itemizing entities in room
11
- # descriptions. The locale_description will be used instead of adding
12
- # the entity's name to a list.
13
- #
14
- # @return [String, nil]
15
- attr_accessor :locale_description
16
-
17
- set_default itemized: true
18
- set_default portable: false
19
-
20
- # Itemized entities are automatically listed in room descriptions.
21
- #
22
- # @return [Boolean]
23
- def itemized?
24
- @itemized
25
- end
26
-
27
- # Portable entities can be taken with TAKE actions.
28
- #
29
- # @return [Boolean]
30
- def portable?
31
- @portable
32
- end
33
-
34
- # @return [Boolean]
35
- def attached?
36
- @attached ||= false
37
- end
38
-
39
- # @param bool [Boolean]
40
- def attached= bool
41
- @attached = if parent.nil?
42
- # @todo Log attachment failure
43
- false
44
- else
45
- bool
46
- end
47
- end
48
-
49
- def parent= new_parent
50
- self.attached = false unless new_parent == parent
51
- super
52
- end
53
-
54
- # The entity's parent room (i.e., the closest ascendant that is a Room).
55
- #
56
- # @return [Room]
57
- def room
58
- p = parent
59
- until p.is_a?(Room) or p.nil?
60
- p = p.parent
61
- end
62
- p
63
- end
3
+ include Standardized
64
4
  end
5
+
6
+ Thing = Gamefic::Entity
7
+ Thing.set_default itemized: true, portable: false
@@ -3,7 +3,9 @@ require 'gamefic-standard/entities/character'
3
3
  require 'gamefic-standard/entities/fixture'
4
4
  require 'gamefic-standard/entities/item'
5
5
  require 'gamefic-standard/entities/portal'
6
+ require 'gamefic-standard/entities/door'
6
7
  require 'gamefic-standard/entities/receptacle'
8
+ require 'gamefic-standard/entities/container'
7
9
  require 'gamefic-standard/entities/room'
8
10
  require 'gamefic-standard/entities/scenery'
9
11
  require 'gamefic-standard/entities/rubble'
@@ -1,23 +1,20 @@
1
- # @gamefic.script standard/give
2
-
3
- respond :give, Use.available, Gamefic::Query::Children.new do |actor, _character, gift|
4
- actor.tell "Nothing happens."
5
- end
1
+ Gamefic.script do
2
+ respond :give, Use.available, Gamefic::Query::Children.new do |actor, _character, _gift|
3
+ actor.tell 'Nothing happens.'
4
+ end
6
5
 
7
- respond :give, Use.available(Character), Use.available do |actor, character, gift|
8
- actor.tell "#{The character} doesn't want #{the gift}."
9
- end
6
+ respond :give, Use.available(Character), Use.available do |actor, character, gift|
7
+ actor.tell "#{The character} doesn't want #{the gift}."
8
+ end
10
9
 
11
- respond :give, Use.available(Character), Use.available do |actor, _character, gift|
12
- if gift.parent == actor
13
- actor.proceed
14
- else
15
- actor.tell "You don't have #{the gift}."
10
+ respond :give, Use.available(Character), Use.available do |actor, _character, gift|
11
+ if gift.parent != actor
12
+ actor.perform :take, gift
13
+ end
14
+ if gift.parent == actor
15
+ actor.proceed
16
+ end
16
17
  end
17
- end
18
18
 
19
- respond :give, Use.text, Use.available do |actor, character, _gift|
20
- actor.tell "You don't see any \"#{character}\" here."
19
+ interpret 'give :gift to :character', 'give :character :gift'
21
20
  end
22
-
23
- interpret "give :gift to :character", "give :character :gift"
@@ -0,0 +1,32 @@
1
+ # A module for entities that are both openable and lockable.
2
+ #
3
+ module Lockable
4
+ include Openable
5
+
6
+ attr_accessor :lock_key
7
+
8
+ def locked=(bool)
9
+ @locked = bool
10
+ if @locked == true
11
+ self.open = false
12
+ end
13
+ end
14
+
15
+ def open=(bool)
16
+ @open = bool
17
+ @locked = false if @open == true
18
+ end
19
+
20
+ def locked?
21
+ @locked ||= false
22
+ end
23
+
24
+ def unlocked?
25
+ !locked?
26
+ end
27
+
28
+ def lock_key?
29
+ !@lock_key.nil?
30
+ end
31
+ alias has_lock_key? lock_key?
32
+ end
@@ -0,0 +1,19 @@
1
+ # A module for entities that are openable.
2
+ #
3
+ module Openable
4
+ def open= bool
5
+ @open = bool
6
+ end
7
+
8
+ def open?
9
+ @open ||= false
10
+ end
11
+
12
+ def closed?
13
+ !open?
14
+ end
15
+
16
+ def accessible?
17
+ open?
18
+ end
19
+ end
@@ -0,0 +1,59 @@
1
+ module Standardized
2
+ # @return [Boolean]
3
+ attr_writer :itemized
4
+
5
+ # @return [Boolean]
6
+ attr_writer :portable
7
+
8
+ # An optional description to use when itemizing entities in room
9
+ # descriptions. The locale_description will be used instead of adding
10
+ # the entity's name to a list.
11
+ #
12
+ # @return [String, nil]
13
+ attr_accessor :locale_description
14
+
15
+ # Itemized entities are automatically listed in room descriptions.
16
+ #
17
+ # @return [Boolean]
18
+ def itemized?
19
+ @itemized
20
+ end
21
+
22
+ # Portable entities can be taken with TAKE actions.
23
+ #
24
+ # @return [Boolean]
25
+ def portable?
26
+ @portable
27
+ end
28
+
29
+ # @return [Boolean]
30
+ def attached?
31
+ @attached ||= false
32
+ end
33
+
34
+ # @param bool [Boolean]
35
+ def attached= bool
36
+ @attached = if parent.nil?
37
+ # @todo Log attachment failure
38
+ false
39
+ else
40
+ bool
41
+ end
42
+ end
43
+
44
+ def parent= new_parent
45
+ self.attached = false unless new_parent == parent
46
+ super
47
+ end
48
+
49
+ # The entity's parent room (i.e., the closest ascendant that is a Room).
50
+ #
51
+ # @return [Room]
52
+ def room
53
+ p = parent
54
+ until p.is_a?(Room) or p.nil?
55
+ p = p.parent
56
+ end
57
+ p
58
+ end
59
+ end
@@ -3,5 +3,8 @@
3
3
  # portals between rooms.
4
4
  #
5
5
 
6
+ require 'gamefic-standard/modules/standardized'
6
7
  require 'gamefic-standard/modules/use'
7
8
  require 'gamefic-standard/modules/enterable'
9
+ require 'gamefic-standard/modules/openable'
10
+ require 'gamefic-standard/modules/lockable'
@@ -1,9 +1,7 @@
1
- # @gamefic.script standard/pathfinder
2
1
  # Pathfinders provide the shortest route between two locations. The
3
2
  # destination needs to be accessible from the origin through portals. Note
4
3
  # that Pathfinders do not take into account portals that characters should
5
4
  # not be able to traverse, such as locked doors.
6
-
7
5
  class Pathfinder
8
6
  # @return [Room]
9
7
  attr_reader :origin
@@ -6,10 +6,10 @@ class Gamefic::Query::Available < Gamefic::Query::Base
6
6
  result.concat subquery_accessible(top)
7
7
  end
8
8
  result.delete subject
9
- subject.children.each { |c|
9
+ subject.children.each do |c|
10
10
  result.push c
11
11
  result.concat subquery_accessible(c)
12
- }
12
+ end
13
13
  result
14
14
  end
15
15
  end
@@ -1,5 +1,3 @@
1
- # @gamefic.script standard/test
2
-
3
1
  module Tester
4
2
  def test_procs
5
3
  @test_procs ||= Hash.new
@@ -1,5 +1,5 @@
1
1
  module Gamefic
2
2
  module Standard
3
- VERSION = '2.2.0'
3
+ VERSION = '2.3.0'
4
4
  end
5
5
  end
@@ -8,5 +8,3 @@ require 'gamefic-standard/modules'
8
8
  require 'gamefic-standard/direction'
9
9
  require 'gamefic-standard/entities'
10
10
  require 'gamefic-standard/actions'
11
- require 'gamefic-standard/container'
12
- require 'gamefic-standard/door'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamefic-standard
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-21 00:00:00.000000000 Z
11
+ date: 2021-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gamefic
@@ -16,20 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.0'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 2.0.3
19
+ version: '2.2'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '2.0'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 2.0.3
26
+ version: '2.2'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: bundler
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -108,40 +102,30 @@ files:
108
102
  - gamefic-standard.gemspec
109
103
  - lib/gamefic-standard.rb
110
104
  - lib/gamefic-standard/actions.rb
105
+ - lib/gamefic-standard/actions/close.rb
111
106
  - lib/gamefic-standard/actions/drop.rb
112
107
  - lib/gamefic-standard/actions/enter.rb
113
108
  - lib/gamefic-standard/actions/go.rb
114
109
  - lib/gamefic-standard/actions/insert.rb
115
110
  - lib/gamefic-standard/actions/inventory.rb
116
111
  - lib/gamefic-standard/actions/leave.rb
112
+ - lib/gamefic-standard/actions/lock.rb
117
113
  - lib/gamefic-standard/actions/look.rb
118
114
  - lib/gamefic-standard/actions/nil.rb
115
+ - lib/gamefic-standard/actions/open.rb
119
116
  - lib/gamefic-standard/actions/place.rb
120
117
  - lib/gamefic-standard/actions/quit.rb
118
+ - lib/gamefic-standard/actions/search.rb
121
119
  - lib/gamefic-standard/actions/take.rb
122
120
  - lib/gamefic-standard/actions/talk.rb
121
+ - lib/gamefic-standard/actions/unlock.rb
123
122
  - lib/gamefic-standard/actions/wait.rb
124
123
  - lib/gamefic-standard/articles.rb
125
- - lib/gamefic-standard/clothing.rb
126
- - lib/gamefic-standard/clothing/actions.rb
127
- - lib/gamefic-standard/clothing/actions/doff.rb
128
- - lib/gamefic-standard/clothing/actions/drop.rb
129
- - lib/gamefic-standard/clothing/actions/inventory.rb
130
- - lib/gamefic-standard/clothing/actions/wear.rb
131
- - lib/gamefic-standard/clothing/entities.rb
132
- - lib/gamefic-standard/clothing/entities/clothing.rb
133
- - lib/gamefic-standard/clothing/entities/coat.rb
134
- - lib/gamefic-standard/clothing/entities/gloves.rb
135
- - lib/gamefic-standard/clothing/entities/hat.rb
136
- - lib/gamefic-standard/clothing/entities/pants.rb
137
- - lib/gamefic-standard/clothing/entities/shirt.rb
138
- - lib/gamefic-standard/clothing/entities/shoes.rb
139
- - lib/gamefic-standard/container.rb
140
124
  - lib/gamefic-standard/direction.rb
141
- - lib/gamefic-standard/door.rb
142
- - lib/gamefic-standard/edible.rb
143
125
  - lib/gamefic-standard/entities.rb
144
126
  - lib/gamefic-standard/entities/character.rb
127
+ - lib/gamefic-standard/entities/container.rb
128
+ - lib/gamefic-standard/entities/door.rb
145
129
  - lib/gamefic-standard/entities/fixture.rb
146
130
  - lib/gamefic-standard/entities/item.rb
147
131
  - lib/gamefic-standard/entities/portal.rb
@@ -155,11 +139,12 @@ files:
155
139
  - lib/gamefic-standard/grammar.rb
156
140
  - lib/gamefic-standard/grammar/attributes.rb
157
141
  - lib/gamefic-standard/grammar/pronoun.rb
158
- - lib/gamefic-standard/lockable.rb
159
142
  - lib/gamefic-standard/modules.rb
160
143
  - lib/gamefic-standard/modules/enterable.rb
144
+ - lib/gamefic-standard/modules/lockable.rb
145
+ - lib/gamefic-standard/modules/openable.rb
146
+ - lib/gamefic-standard/modules/standardized.rb
161
147
  - lib/gamefic-standard/modules/use.rb
162
- - lib/gamefic-standard/openable.rb
163
148
  - lib/gamefic-standard/pathfinder.rb
164
149
  - lib/gamefic-standard/queries.rb
165
150
  - lib/gamefic-standard/test.rb
@@ -1,14 +0,0 @@
1
- Gamefic.script do
2
- respond :doff, Gamefic::Query::Children.new(Clothing) do |actor, clothing|
3
- if !clothing.attached?
4
- actor.tell "You're not wearing #{the clothing}."
5
- else
6
- clothing.attached = false
7
- actor.tell "You take off #{the clothing}."
8
- end
9
- end
10
-
11
- interpret "remove :clothing", "doff :clothing"
12
- interpret "take off :clothing", "doff :clothing"
13
- interpret "take :clothing off", "doff :clothing"
14
- end
@@ -1,10 +0,0 @@
1
- Gamefic.script do
2
- respond :drop, Gamefic::Query::Children.new(Clothing) do |actor, clothing|
3
- if clothing.attached?
4
- actor.perform :doff, clothing
5
- end
6
- if !clothing.attached?
7
- actor.proceed
8
- end
9
- end
10
- end
@@ -1,16 +0,0 @@
1
- Gamefic.script do
2
- respond :inventory do |actor|
3
- if actor.children.length > 0
4
- carried = actor.children.that_are_not(:attached?)
5
- worn = actor.children.that_are(:attached?)
6
- if carried.length > 0
7
- actor.tell "You are carrying #{carried.join_and}."
8
- end
9
- if worn.length > 0
10
- actor.tell "You are wearing #{worn.join_and}."
11
- end
12
- else
13
- actor.tell "You aren't carrying anything."
14
- end
15
- end
16
- end
@@ -1,21 +0,0 @@
1
- Gamefic.script do
2
- respond :wear, Use.available(Clothing) do |actor, clothing|
3
- actor.perform :take, clothing unless clothing.parent == actor
4
- next unless clothing.parent == actor
5
- if clothing.attached?
6
- actor.tell "You're already wearing #{the clothing}."
7
- else
8
- already = actor.children.that_are(clothing.class).that_are(:attached?)
9
- if already.length == 0
10
- clothing.attached = true
11
- actor.tell "You put on #{the clothing}."
12
- else
13
- actor.tell "You're already wearing #{an already[0]}."
14
- end
15
- end
16
- end
17
-
18
- interpret "put on :clothing", "wear :clothing"
19
- interpret "put :clothing on", "wear :clothing"
20
- interpret "don :clothing", "wear :clothing"
21
- end
@@ -1,4 +0,0 @@
1
- require 'gamefic-standard/clothing/actions/doff'
2
- require 'gamefic-standard/clothing/actions/drop'
3
- require 'gamefic-standard/clothing/actions/inventory'
4
- require 'gamefic-standard/clothing/actions/wear'
@@ -1,5 +0,0 @@
1
- class Clothing < Item
2
- def worn?
3
- self.parent.kind_of?(Character) and self.attached?
4
- end
5
- end
@@ -1,3 +0,0 @@
1
- class Coat < Clothing
2
-
3
- end
@@ -1,3 +0,0 @@
1
- class Gloves < Clothing
2
-
3
- end
@@ -1,3 +0,0 @@
1
- class Hat < Clothing
2
-
3
- end
@@ -1,3 +0,0 @@
1
- class Pants < Clothing
2
-
3
- end
@@ -1,3 +0,0 @@
1
- class Shirt < Clothing
2
-
3
- end
@@ -1,3 +0,0 @@
1
- class Shoes < Clothing
2
-
3
- end
@@ -1,7 +0,0 @@
1
- require 'gamefic-standard/clothing/entities/clothing'
2
- require 'gamefic-standard/clothing/entities/coat'
3
- require 'gamefic-standard/clothing/entities/gloves'
4
- require 'gamefic-standard/clothing/entities/hat'
5
- require 'gamefic-standard/clothing/entities/pants'
6
- require 'gamefic-standard/clothing/entities/shirt'
7
- require 'gamefic-standard/clothing/entities/shoes'
@@ -1,4 +0,0 @@
1
- # @gamefic.script standard/clothing
2
-
3
- require 'gamefic-standard/clothing/entities'
4
- require 'gamefic-standard/clothing/actions'
@@ -1,27 +0,0 @@
1
- require 'gamefic-standard/openable'
2
- require 'gamefic-standard/lockable'
3
-
4
- # An openable and lockable receptacle.
5
- #
6
- class Container < Receptacle
7
- include Openable
8
- include Lockable
9
- end
10
-
11
- Gamefic.script do
12
- respond :insert, Use.available, Use.available(Container) do |actor, _thing, container|
13
- if container.open?
14
- actor.proceed
15
- else
16
- actor.tell "#{The container} is closed."
17
- end
18
- end
19
-
20
- respond :leave, Use.parent(Container, :enterable?, :closed?) do |actor, container|
21
- actor.tell "#{The container} is closed."
22
- end
23
-
24
- respond :enter, Use.siblings(Container, :enterable?, :closed?) do |actor, container|
25
- actor.tell "#{The container} is closed."
26
- end
27
- end
@@ -1,23 +0,0 @@
1
- # @gamefic.script standard/edible
2
-
3
- module Edibility
4
- attr_writer :edible
5
- def edible?
6
- @edible ||= false
7
- end
8
- end
9
-
10
- class Thing
11
- include Edibility
12
- end
13
-
14
- Gamefic.script do
15
- respond :eat, Use.available do |actor, item|
16
- actor.tell "You can't eat #{the item}."
17
- end
18
-
19
- respond :eat, Use.available(:edible?) do |actor, item|
20
- actor.tell "You eat #{the item}."
21
- destroy item
22
- end
23
- end
@@ -1,98 +0,0 @@
1
- # @gamefic.script standard/lockable
2
-
3
- require 'gamefic-standard/openable'
4
-
5
- # A module for entities that are both openable and lockable.
6
- #
7
- module Lockable
8
- include Openable
9
-
10
- attr_accessor :lock_key
11
-
12
- def locked=(bool)
13
- @locked = bool
14
- if @locked == true
15
- self.open = false
16
- end
17
- end
18
-
19
- def open=(bool)
20
- @open = bool
21
- @locked = false if @open == true
22
- end
23
-
24
- def locked?
25
- @locked ||= false
26
- end
27
-
28
- def unlocked?
29
- !locked?
30
- end
31
-
32
- def lock_key?
33
- !@lock_key.nil?
34
- end
35
- alias has_lock_key? lock_key?
36
- end
37
-
38
- Gamefic.script do
39
- respond :lock, Use.available do |actor, thing|
40
- actor.tell "You can't lock #{the thing}."
41
- end
42
-
43
- respond :_toggle_lock, Use.available(Lockable, :has_lock_key?) do |actor, thing|
44
- verb = thing.locked? ? 'unlock' : 'lock'
45
- key = nil
46
- if thing.lock_key.parent == actor
47
- key = thing.lock_key
48
- end
49
- if key.nil?
50
- actor.tell "You don't have any way to #{verb} #{the thing}."
51
- else
52
- actor.tell "You #{verb} #{the thing} with #{the key}."
53
- thing.locked = !thing.locked?
54
- end
55
- end
56
-
57
- respond :lock, Use.available(Lockable, :has_lock_key?), Use.children do |actor, thing, key|
58
- if thing.lock_key == key
59
- actor.perform :_toggle_lock, thing
60
- else
61
- actor.tell "You can't unlock #{the thing} with #{the key}."
62
- end
63
- end
64
-
65
- respond :lock, Use.available(Lockable, :has_lock_key?), Use.available do |actor, thing, key|
66
- actor.perform :take, key if key.parent != actor
67
- actor.proceed if key.parent == actor
68
- end
69
-
70
- respond :unlock, Use.available do |actor, thing|
71
- actor.tell "You can't unlock #{the thing}."
72
- end
73
-
74
- respond :unlock, Use.available(Lockable, :has_lock_key?), Use.children do |actor, thing, key|
75
- if thing.lock_key == key
76
- actor.perform :_toggle_lock, thing
77
- else
78
- actor.tell "You can't unlock #{the thing} with #{the key}."
79
- end
80
- end
81
-
82
- respond :unlock, Use.available(Lockable, :has_lock_key?), Use.available do |actor, thing, key|
83
- actor.perform :take, key if key.parent != actor
84
- actor.proceed if key.parent == actor
85
- end
86
-
87
- respond :open, Use.available(Lockable) do |actor, thing|
88
- if thing.locked?
89
- actor.tell "#{The thing} is locked."
90
- else
91
- actor.proceed
92
- end
93
- end
94
-
95
- interpret "lock :container with :key", "lock :container :key"
96
- interpret "unlock :container with :key", "unlock :container :key"
97
- interpret "open :container with :key", "unlock :container :key"
98
- end
@@ -1,54 +0,0 @@
1
- # @gamefic.script standard/openable
2
-
3
- # A module for entities that are openable.
4
- #
5
- module Openable
6
- def open= bool
7
- @open = bool
8
- end
9
-
10
- def open?
11
- @open ||= false
12
- end
13
-
14
- def closed?
15
- !open?
16
- end
17
-
18
- def accessible?
19
- open?
20
- end
21
- end
22
-
23
- Gamefic.script do
24
- respond :open, Use.available do |actor, thing|
25
- actor.tell "You can't open #{the thing}."
26
- end
27
-
28
- respond :open, Use.available(Openable) do |actor, thing|
29
- if thing.open?
30
- actor.tell "#{The thing} is already open."
31
- else
32
- actor.tell "You open #{the thing}."
33
- thing.open = true
34
- end
35
- end
36
-
37
- respond :close, Use.available do |actor, thing|
38
- actor.tell "You can't close #{the thing}."
39
- end
40
-
41
- respond :close, Use.available(Openable) do |actor, thing|
42
- if thing.open?
43
- actor.tell "You close #{the thing}."
44
- thing.open = false
45
- else
46
- actor.tell "#{The thing} is already open."
47
- end
48
- end
49
-
50
- respond :look, Use.available(Thing, Openable) do |actor, thing|
51
- actor.proceed
52
- actor.tell "#{The thing} is #{thing.open? ? 'open' : 'closed'}."
53
- end
54
- end